check deeply inner local declarations added

This commit is contained in:
Svetlana Isakova
2012-05-28 15:21:40 +04:00
parent b4f765bd76
commit 84d60b8baa
3 changed files with 25 additions and 8 deletions
@@ -54,7 +54,6 @@ public class JetControlFlowProcessor {
this.trace = trace; this.trace = trace;
} }
//todo
public Pseudocode generatePseudocode(@NotNull JetDeclaration subroutine) { public Pseudocode generatePseudocode(@NotNull JetDeclaration subroutine) {
Pseudocode pseudocode = generate(subroutine); Pseudocode pseudocode = generate(subroutine);
((PseudocodeImpl)pseudocode).postProcess(); ((PseudocodeImpl)pseudocode).postProcess();
@@ -64,7 +63,7 @@ public class JetControlFlowProcessor {
return pseudocode; return pseudocode;
} }
public Pseudocode generate(@NotNull JetDeclaration subroutine) { private Pseudocode generate(@NotNull JetDeclaration subroutine) {
builder.enterSubroutine(subroutine); builder.enterSubroutine(subroutine);
if (subroutine instanceof JetDeclarationWithBody) { if (subroutine instanceof JetDeclarationWithBody) {
JetDeclarationWithBody declarationWithBody = (JetDeclarationWithBody) subroutine; JetDeclarationWithBody declarationWithBody = (JetDeclarationWithBody) subroutine;
@@ -108,12 +108,18 @@ public class PseudocodeImpl implements Pseudocode {
@Override @Override
public Set<LocalDeclarationInstruction> getLocalDeclarations() { public Set<LocalDeclarationInstruction> getLocalDeclarations() {
if (localDeclarations == null) { if (localDeclarations == null) {
localDeclarations = Sets.newLinkedHashSet(); localDeclarations = getLocalDeclarations(this);
//todo look recursively inside local declarations }
for (Instruction instruction : instructions) { return localDeclarations;
if (instruction instanceof LocalDeclarationInstruction) { }
localDeclarations.add((LocalDeclarationInstruction) instruction);
} @NotNull
private static Set<LocalDeclarationInstruction> getLocalDeclarations(@NotNull Pseudocode pseudocode) {
Set<LocalDeclarationInstruction> localDeclarations = Sets.newHashSet();
for (Instruction instruction : pseudocode.getInstructions()) {
if (instruction instanceof LocalDeclarationInstruction) {
localDeclarations.add((LocalDeclarationInstruction) instruction);
localDeclarations.addAll(getLocalDeclarations(((LocalDeclarationInstruction)instruction).getBody()));
} }
} }
return localDeclarations; return localDeclarations;
@@ -0,0 +1,12 @@
package c
fun test() {
val x = 10
fun inner1() {
fun inner2() {
fun inner3() {
val <!UNUSED_VARIABLE!>y<!> = x
}
}
}
}