From ee561708ddf43f3030ff423fca6ed63df10f875d Mon Sep 17 00:00:00 2001 From: svtk Date: Fri, 21 Oct 2011 15:39:52 +0400 Subject: [PATCH] Added local declaration instruction to pseudocode --- .../FunctionLiteralValueInstruction.java | 34 -------------- .../cfg/pseudocode/InstructionVisitor.java | 4 +- .../JetControlFlowInstructionsGenerator.java | 36 ++++++++------- .../LocalDeclarationInstruction.java | 44 +++++++++++++++++++ .../jetbrains/jet/cfg/JetControlFlowTest.java | 27 ++++++------ 5 files changed, 80 insertions(+), 65 deletions(-) delete mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/FunctionLiteralValueInstruction.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/LocalDeclarationInstruction.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/FunctionLiteralValueInstruction.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/FunctionLiteralValueInstruction.java deleted file mode 100644 index f83c5bf6c1e..00000000000 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/FunctionLiteralValueInstruction.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.jetbrains.jet.lang.cfg.pseudocode; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression; - -/** -* @author abreslav -*/ -public class FunctionLiteralValueInstruction extends ReadValueInstruction { - - private Pseudocode body; - - public FunctionLiteralValueInstruction(@NotNull JetFunctionLiteralExpression expression) { - super(expression); - } - - public Pseudocode getBody() { - return body; - } - - public void setBody(Pseudocode body) { - this.body = body; - } - - @Override - public void accept(InstructionVisitor visitor) { - visitor.visitFunctionLiteralValue(this); - } - - @Override - public String toString() { - return "rf(" + element.getText() + ")"; - } -} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionVisitor.java index 3356be8f18f..29c047bf731 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionVisitor.java @@ -8,7 +8,7 @@ public class InstructionVisitor { visitInstructionWithNext(instruction); } - public void visitFunctionLiteralValue(FunctionLiteralValueInstruction instruction) { + public void visitFunctionLiteralValue(LocalDeclarationInstruction instruction) { visitReadValue(instruction); } @@ -29,7 +29,7 @@ public class InstructionVisitor { } public void visitNondeterministicJump(NondeterministicJumpInstruction instruction) { - visitJump(instruction); + visitInstruction(instruction); } public void visitUnsupportedElementInstruction(UnsupportedElementInstruction instruction) { 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 0014eaa70be..f6edfb38f22 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 @@ -2,10 +2,7 @@ package org.jetbrains.jet.lang.cfg.pseudocode; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.cfg.*; -import org.jetbrains.jet.lang.psi.JetElement; -import org.jetbrains.jet.lang.psi.JetExpression; -import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression; -import org.jetbrains.jet.lang.psi.JetThrowExpression; +import org.jetbrains.jet.lang.psi.*; import java.util.*; @@ -25,7 +22,6 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd private final JetPseudocodeTrace trace; public JetControlFlowInstructionsGenerator(JetPseudocodeTrace trace) { - super(null); this.trace = trace; } @@ -41,28 +37,31 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd if (!builders.isEmpty()) { builder = builders.peek(); } + else { + builder = null; + } return worker; } @Override - public void enterSubroutine(@NotNull JetElement subroutine, boolean isFunctionLiteral) { - if (isFunctionLiteral) { + public void enterSubroutine(@NotNull JetDeclaration subroutine) { + if (builder != null) { pushBuilder(subroutine, builder.getCurrentSubroutine()); } else { pushBuilder(subroutine, subroutine); } - builder.enterSubroutine(subroutine, false); + assert builder != null; + builder.enterSubroutine(subroutine); } @Override - public void exitSubroutine(@NotNull JetElement subroutine, boolean functionLiteral) { - super.exitSubroutine(subroutine, functionLiteral); + public void exitSubroutine(@NotNull JetDeclaration subroutine) { + super.exitSubroutine(subroutine); JetControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine); - if (functionLiteral) { + if (!builders.empty()) { JetControlFlowInstructionsGeneratorWorker builder = builders.peek(); - FunctionLiteralValueInstruction instruction = new FunctionLiteralValueInstruction((JetFunctionLiteralExpression) subroutine); - instruction.setBody(worker.getPseudocode()); + LocalDeclarationInstruction instruction = new LocalDeclarationInstruction(subroutine, worker.getPseudocode()); builder.add(instruction); } } @@ -128,7 +127,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd } @Override - public void enterSubroutine(@NotNull JetElement subroutine, boolean isFunctionLiteral) { + public void enterSubroutine(@NotNull JetDeclaration subroutine) { Label entryPoint = createUnboundLabel(); BreakableBlockInfo blockInfo = new BreakableBlockInfo(subroutine, entryPoint, createUnboundLabel()); // subroutineInfo.push(blockInfo); @@ -179,7 +178,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd } @Override - public void exitSubroutine(@NotNull JetElement subroutine, boolean functionLiteral) { + public void exitSubroutine(@NotNull JetDeclaration subroutine) { bindLabel(getExitPoint(subroutine)); pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, "")); bindLabel(error); @@ -246,6 +245,13 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd add(new NondeterministicJumpInstruction(label)); } + @Override + public void nondeterministicJump(List