From 5b3bc7f83989e6f2cd56f6969b0191f9d088af22 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Wed, 4 Dec 2013 16:07:50 +0400 Subject: [PATCH] Print instructions for functions in classes --- .../cfg/DelegatedProperty.instructions | 17 ++++++++++++ compiler/testData/cfg/MultiDecl.instructions | 26 +++++++++++++++++++ .../cfg/ObjectExpression.instructions | 25 ++++++++++++++++++ .../cfg/arrayAccessExpression.instructions | 12 +++++++++ .../jet/cfg/AbstractControlFlowTest.java | 23 ++++++++++++---- 5 files changed, 98 insertions(+), 5 deletions(-) diff --git a/compiler/testData/cfg/DelegatedProperty.instructions b/compiler/testData/cfg/DelegatedProperty.instructions index 75147d933f2..bde85a89eb3 100644 --- a/compiler/testData/cfg/DelegatedProperty.instructions +++ b/compiler/testData/cfg/DelegatedProperty.instructions @@ -12,6 +12,23 @@ error: sink: PREV:[, ] ===================== +== get == +fun get(_this: Any, p: PropertyMetadata): Int = 0 +--------------------- +L0: + + v(_this: Any) + w(_this) + v(p: PropertyMetadata) + w(p) + r(0) +L1: + NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== == a == val a = Delegate() --------------------- diff --git a/compiler/testData/cfg/MultiDecl.instructions b/compiler/testData/cfg/MultiDecl.instructions index b67f1ce172e..24feb88a7a0 100644 --- a/compiler/testData/cfg/MultiDecl.instructions +++ b/compiler/testData/cfg/MultiDecl.instructions @@ -13,6 +13,32 @@ error: sink: PREV:[, ] ===================== +== component1 == +fun component1() = 1 +--------------------- +L0: + + r(1) +L1: + NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== +== component2 == +fun component2() = 2 +--------------------- +L0: + + r(2) +L1: + NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== == test == fun test(c: C) { val (a, b) = c diff --git a/compiler/testData/cfg/ObjectExpression.instructions b/compiler/testData/cfg/ObjectExpression.instructions index 1e08335dd15..6f03c120bf3 100644 --- a/compiler/testData/cfg/ObjectExpression.instructions +++ b/compiler/testData/cfg/ObjectExpression.instructions @@ -12,6 +12,18 @@ error: sink: PREV:[, ] ===================== +== foo == +fun foo() : Int +--------------------- +L0: + +L1: + NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== == B == class B : A { override fun foo() = 10 @@ -28,6 +40,19 @@ sink: PREV:[, ] ===================== == foo == +override fun foo() = 10 +--------------------- +L0: + + r(10) +L1: + NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== +== foo == fun foo(b: B) : Int { val o = object : A by b {} return o.foo() diff --git a/compiler/testData/cfg/arrayAccessExpression.instructions b/compiler/testData/cfg/arrayAccessExpression.instructions index 17da1da28a4..3f5bc439770 100644 --- a/compiler/testData/cfg/arrayAccessExpression.instructions +++ b/compiler/testData/cfg/arrayAccessExpression.instructions @@ -12,6 +12,18 @@ error: sink: PREV:[, ] ===================== +== getArray == +abstract fun getArray() : Array +--------------------- +L0: + +L1: + NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== == test == fun test(ab: Ab) { ab.getArray()[1] diff --git a/compiler/tests/org/jetbrains/jet/cfg/AbstractControlFlowTest.java b/compiler/tests/org/jetbrains/jet/cfg/AbstractControlFlowTest.java index aebb66607bb..7d1b5ae2b8b 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/AbstractControlFlowTest.java +++ b/compiler/tests/org/jetbrains/jet/cfg/AbstractControlFlowTest.java @@ -55,11 +55,15 @@ public abstract class AbstractControlFlowTest extends KotlinTestWithEnvironment List declarations = jetFile.getDeclarations(); BindingContext bindingContext = analyzeExhaust.getBindingContext(); for (JetDeclaration declaration : declarations) { - Pseudocode pseudocode = PseudocodeUtil.generatePseudocode(declaration, bindingContext); - data.put(declaration, pseudocode); - for (LocalFunctionDeclarationInstruction instruction : pseudocode.getLocalDeclarations()) { - Pseudocode localPseudocode = instruction.getBody(); - data.put(localPseudocode.getCorrespondingElement(), localPseudocode); + addDeclaration(data, bindingContext, declaration); + + if (declaration instanceof JetDeclarationContainer) { + for (JetDeclaration member : ((JetDeclarationContainer) declaration).getDeclarations()) { + // Properties and initializers are processed elsewhere + if (member instanceof JetNamedFunction) { + addDeclaration(data, bindingContext, member); + } + } } } @@ -76,6 +80,15 @@ public abstract class AbstractControlFlowTest extends KotlinTestWithEnvironment } } + private void addDeclaration(Map data, BindingContext bindingContext, JetDeclaration declaration) { + Pseudocode pseudocode = PseudocodeUtil.generatePseudocode(declaration, bindingContext); + data.put(declaration, pseudocode); + for (LocalFunctionDeclarationInstruction instruction : pseudocode.getLocalDeclarations()) { + Pseudocode localPseudocode = instruction.getBody(); + data.put(localPseudocode.getCorrespondingElement(), localPseudocode); + } + } + private void processCFData(File file, Map data) throws IOException { Collection pseudocodes = data.values();