diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java index 94d05a20cb1..da91552bb9c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java @@ -63,9 +63,9 @@ public interface JetControlFlowBuilder { void exitTryFinally(); // Subroutines - void enterSubroutine(@NotNull JetDeclaration subroutine); + void enterSubroutine(@NotNull JetElement subroutine); - Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine); + Pseudocode exitSubroutine(@NotNull JetElement subroutine); @NotNull JetElement getCurrentSubroutine(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java index 7843518933d..ffed5f0fbe7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java @@ -147,13 +147,13 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder { } @Override - public void enterSubroutine(@NotNull JetDeclaration subroutine) { + public void enterSubroutine(@NotNull JetElement subroutine) { assert builder != null; builder.enterSubroutine(subroutine); } @Override - public Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine) { + public Pseudocode exitSubroutine(@NotNull JetElement subroutine) { assert builder != null; return builder.exitSubroutine(subroutine); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 9486dd32525..1628bd295fd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowInstructionsGenerator import org.jetbrains.jet.lang.cfg.pseudocode.LocalDeclarationInstruction; import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode; import org.jetbrains.jet.lang.cfg.pseudocode.PseudocodeImpl; +import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; @@ -58,16 +59,16 @@ public class JetControlFlowProcessor { this.trace = trace; } - public Pseudocode generatePseudocode(@NotNull JetDeclaration subroutine) { + public Pseudocode generatePseudocode(@NotNull JetElement subroutine) { Pseudocode pseudocode = generate(subroutine); - ((PseudocodeImpl)pseudocode).postProcess(); + ((PseudocodeImpl) pseudocode).postProcess(); for (LocalDeclarationInstruction localDeclarationInstruction : pseudocode.getLocalDeclarations()) { ((PseudocodeImpl)localDeclarationInstruction.getBody()).postProcess(); } return pseudocode; } - private Pseudocode generate(@NotNull JetDeclaration subroutine) { + private Pseudocode generate(@NotNull JetElement subroutine) { builder.enterSubroutine(subroutine); CFPVisitor cfpVisitor = new CFPVisitor(false); if (subroutine instanceof JetDeclarationWithBody) { @@ -80,12 +81,6 @@ public class JetControlFlowProcessor { if (bodyExpression != null) { bodyExpression.accept(cfpVisitor); } - } - else if (subroutine instanceof JetProperty) { - JetExpression initializer = ((JetProperty) subroutine).getInitializer(); - if (initializer != null) { - initializer.accept(cfpVisitor); - } } else { subroutine.accept(cfpVisitor); } @@ -911,13 +906,8 @@ public class JetControlFlowProcessor { generateInstructions(specifier, inCondition); } List declarations = classOrObject.getDeclarations(); - List properties = Lists.newArrayList(); for (JetDeclaration declaration : declarations) { - if (declaration instanceof JetProperty) { - generateInstructions(declaration, inCondition); - properties.add((JetProperty) declaration); - } - else if (declaration instanceof JetClassInitializer) { + if (declaration instanceof JetProperty || declaration instanceof JetClassInitializer) { generateInstructions(declaration, inCondition); } } @@ -945,6 +935,15 @@ public class JetControlFlowProcessor { generateInstructions(specifier.getDelegateExpression(), inCondition); } + @Override + public void visitJetFile(JetFile file) { + for (JetDeclaration declaration : file.getDeclarations()) { + if (declaration instanceof JetProperty) { + generateInstructions(declaration, inCondition); + } + } + } + @Override public void visitJetElement(JetElement element) { builder.unsupported(element); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index a53db9604ed..68da00a20d3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -56,13 +56,13 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; */ public class JetFlowInformationProvider { - private final JetDeclaration subroutine; + private final JetElement subroutine; private final Pseudocode pseudocode; private final PseudocodeVariablesData pseudocodeVariablesData; private BindingTrace trace; public JetFlowInformationProvider( - @NotNull JetDeclaration declaration, + @NotNull JetElement declaration, @NotNull BindingTrace trace) { subroutine = declaration; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java index a1ff34953dc..fd5ca6156f3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java @@ -55,7 +55,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd } @Override - public void enterSubroutine(@NotNull JetDeclaration subroutine) { + public void enterSubroutine(@NotNull JetElement subroutine) { if (builder != null && subroutine instanceof JetFunctionLiteral) { pushBuilder(subroutine, builder.getReturnSubroutine()); } @@ -67,7 +67,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd } @Override - public Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine) { + public Pseudocode exitSubroutine(@NotNull JetElement subroutine) { super.exitSubroutine(subroutine); JetControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine); if (!builders.empty()) { @@ -143,7 +143,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd } @Override - public void enterSubroutine(@NotNull JetDeclaration subroutine) { + public void enterSubroutine(@NotNull JetElement subroutine) { Label entryPoint = createUnboundLabel(); BreakableBlockInfo blockInfo = new BreakableBlockInfo(subroutine, entryPoint, createUnboundLabel()); // subroutineInfo.push(blockInfo); @@ -201,7 +201,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd } @Override - public Pseudocode exitSubroutine(@NotNull JetDeclaration subroutine) { + public Pseudocode exitSubroutine(@NotNull JetElement subroutine) { bindLabel(getExitPoint(subroutine)); pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, "")); bindLabel(error); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/LocalDeclarationInstruction.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/LocalDeclarationInstruction.java index a409565b2b7..3223b3bc977 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/LocalDeclarationInstruction.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/LocalDeclarationInstruction.java @@ -32,7 +32,7 @@ public class LocalDeclarationInstruction extends InstructionWithNext { private final Pseudocode body; private Instruction sink; - public LocalDeclarationInstruction(@NotNull JetDeclaration element, Pseudocode body) { + public LocalDeclarationInstruction(@NotNull JetElement element, Pseudocode body) { super(element); this.body = body; } @@ -41,12 +41,6 @@ public class LocalDeclarationInstruction extends InstructionWithNext { return body; } - @NotNull - @Override - public JetDeclaration getElement() { - return (JetDeclaration) super.getElement(); - } - @NotNull @Override public Collection getNextInstructions() {