diff --git a/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java b/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java index ad740c1e790..03e660fc711 100644 --- a/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java +++ b/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java @@ -73,10 +73,12 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd private class JetControlFlowInstructionsGeneratorWorker implements JetControlFlowBuilder { private final Pseudocode pseudocode; + private final Label error; private final JetElement currentSubroutine; private JetControlFlowInstructionsGeneratorWorker(@NotNull JetElement scopingElement, @NotNull JetElement currentSubroutine) { this.pseudocode = new Pseudocode(scopingElement); + this.error = pseudocode.createLabel("error"); this.currentSubroutine = currentSubroutine; } @@ -176,7 +178,9 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd @Override public void exitSubroutine(@NotNull JetElement subroutine, boolean functionLiteral) { bindLabel(getExitPoint(subroutine)); - add(new SubroutineExitInstruction(subroutine)); + pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, "")); + bindLabel(error); + add(new SubroutineExitInstruction(subroutine, "")); elementToBlockInfo.remove(subroutine); allBlocks.pop(); } @@ -241,7 +245,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd @Override public void jumpToError(@NotNull JetThrowExpression expression) { -// add(new UnconditionalJumpInstruction(error)); + add(new UnconditionalJumpInstruction(error)); } @Override diff --git a/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java b/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java index ae19f0c54ca..9b31e457368 100644 --- a/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java +++ b/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java @@ -74,14 +74,15 @@ public class Pseudocode { return instructions; } + public void addExitInstruction(SubroutineExitInstruction exitInstruction) { + addInstruction(exitInstruction); + assert this.exitInstruction == null; + this.exitInstruction = exitInstruction; + } + public void addInstruction(Instruction instruction) { instructions.add(instruction); instruction.setOwner(this); - if (instruction instanceof SubroutineExitInstruction) { - SubroutineExitInstruction exitInstruction = (SubroutineExitInstruction) instruction; - assert this.exitInstruction == null; - this.exitInstruction = exitInstruction; - } } @NotNull diff --git a/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineExitInstruction.java b/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineExitInstruction.java index 56570b3b5c5..0a6e5621aa0 100644 --- a/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineExitInstruction.java +++ b/idea/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineExitInstruction.java @@ -11,9 +11,11 @@ import java.util.Collections; */ public class SubroutineExitInstruction extends InstructionImpl { private final JetElement subroutine; + private final String debugLabel; - public SubroutineExitInstruction(@NotNull JetElement subroutine) { + public SubroutineExitInstruction(@NotNull JetElement subroutine, @NotNull String debugLabel) { this.subroutine = subroutine; + this.debugLabel = debugLabel; } public JetElement getSubroutine() { @@ -33,6 +35,6 @@ public class SubroutineExitInstruction extends InstructionImpl { @Override public String toString() { - return ""; + return debugLabel; } } diff --git a/idea/testData/cfg/Assignments.instructions b/idea/testData/cfg/Assignments.instructions index 4fae5a8e674..b487e0ca4d8 100644 --- a/idea/testData/cfg/Assignments.instructions +++ b/idea/testData/cfg/Assignments.instructions @@ -41,4 +41,6 @@ l5: w(z) l1: +error: + ===================== diff --git a/idea/testData/cfg/Basic.instructions b/idea/testData/cfg/Basic.instructions index 71f22395150..d08fd61f141 100644 --- a/idea/testData/cfg/Basic.instructions +++ b/idea/testData/cfg/Basic.instructions @@ -6,6 +6,8 @@ l2: r(1) l3: +error: + ===================== == f == fun f(a : Boolean) : Unit { @@ -67,11 +69,15 @@ l5: r(a || false) l1: +error: + l2: r(1) l3: +error: + ===================== == foo == fun foo(a : Boolean, b : Int) : Unit {} @@ -80,6 +86,8 @@ l0: l1: +error: + ===================== == genfun == fun genfun() : Unit {} @@ -88,6 +96,8 @@ l0: l1: +error: + ===================== == flfun == fun flfun(f : {() : Any}) : Unit {} @@ -96,4 +106,6 @@ l0: l1: +error: + ===================== diff --git a/idea/testData/cfg/EmptyFunction.instructions b/idea/testData/cfg/EmptyFunction.instructions index 599845fcbfb..78e2b0a1173 100644 --- a/idea/testData/cfg/EmptyFunction.instructions +++ b/idea/testData/cfg/EmptyFunction.instructions @@ -5,4 +5,6 @@ l0: l1: +error: + ===================== diff --git a/idea/testData/cfg/FailFunction.instructions b/idea/testData/cfg/FailFunction.instructions new file mode 100644 index 00000000000..f566a464e76 --- /dev/null +++ b/idea/testData/cfg/FailFunction.instructions @@ -0,0 +1,14 @@ +== fail == +fun fail() : Nothing { + throw new java.lang.RuntimeException() +} +--------------------- +l0: + + r(new java.lang.RuntimeException()) + jmp(error) +l1: + +error: + +===================== diff --git a/idea/testData/cfg/FailFunction.jet b/idea/testData/cfg/FailFunction.jet new file mode 100644 index 00000000000..6ac8f8e3561 --- /dev/null +++ b/idea/testData/cfg/FailFunction.jet @@ -0,0 +1,3 @@ +fun fail() : Nothing { + throw new java.lang.RuntimeException() +} \ No newline at end of file diff --git a/idea/testData/cfg/Finally.instructions b/idea/testData/cfg/Finally.instructions index ff612f410fc..ba202616f56 100644 --- a/idea/testData/cfg/Finally.instructions +++ b/idea/testData/cfg/Finally.instructions @@ -15,6 +15,8 @@ l2: r(2) l1: +error: + ===================== == t3 == fun t3() { @@ -47,6 +49,8 @@ l4: r(2) l1: +error: + ===================== == anonymous_0 == { () => @@ -69,6 +73,8 @@ l5: l4: l6: +error: + ===================== == t3 == fun t3() { @@ -97,6 +103,8 @@ l2: r(2) l1: +error: + l3: r(2) @@ -111,6 +119,8 @@ l5: l4: l6: +error: + ===================== == anonymous_1 == { () => @@ -143,6 +153,8 @@ l6: r(2) l3: +error: + ===================== == t3 == fun t3() { @@ -172,6 +184,8 @@ l0: }) l1: +error: + l2: jmp?(l4) @@ -191,6 +205,8 @@ l6: r(2) l3: +error: + ===================== == t3 == fun t3() { @@ -231,6 +247,8 @@ l2: read (Unit) l1: +error: + ===================== == t3 == fun t3() { @@ -272,6 +290,8 @@ l2: r(2) l1: +error: + ===================== == t3 == fun t3() { @@ -311,6 +331,8 @@ l2: r(2) l1: +error: + ===================== == t3 == fun t3(a : Int) { @@ -354,6 +376,8 @@ l2: read (Unit) l1: +error: + ===================== == t3 == fun t3(a : Int) { @@ -398,6 +422,8 @@ l2: r(2) l1: +error: + ===================== == t3 == fun t3(a : Int) { @@ -440,6 +466,8 @@ l2: r(2) l1: +error: + ===================== == tf == fun tf() { @@ -463,4 +491,6 @@ l2: ret(*) l1 l1: +error: + ===================== diff --git a/idea/testData/cfg/LazyBooleans.instructions b/idea/testData/cfg/LazyBooleans.instructions index 4b3f69e0e8e..d5aaf8eed74 100644 --- a/idea/testData/cfg/LazyBooleans.instructions +++ b/idea/testData/cfg/LazyBooleans.instructions @@ -67,4 +67,6 @@ l13: r(14) l1: +error: + ===================== diff --git a/idea/testData/cfg/Nonlocals.instructions b/idea/testData/cfg/Nonlocals.instructions index baf838b0132..ba6a27c536e 100644 --- a/idea/testData/cfg/Nonlocals.instructions +++ b/idea/testData/cfg/Nonlocals.instructions @@ -16,6 +16,8 @@ l8: l7: l9: +error: + ===================== == anonymous_0 == {a => @@ -35,6 +37,8 @@ l4: ret(*) l5 l5: +error: + ===================== == nonlocals1 == fun nonlocals1(a : Boolean, b : Boolean) : Any? { @@ -80,6 +84,8 @@ l3: r(1.lng) l1: +error: + l4: r(2) @@ -87,4 +93,6 @@ l4: ret(*) l5 l5: +error: + ===================== diff --git a/idea/testData/cfg/OnlyWhileInFunctionBody.instructions b/idea/testData/cfg/OnlyWhileInFunctionBody.instructions index 23c5c2fbee5..907bcb116d3 100644 --- a/idea/testData/cfg/OnlyWhileInFunctionBody.instructions +++ b/idea/testData/cfg/OnlyWhileInFunctionBody.instructions @@ -19,6 +19,8 @@ l2: read (Unit) l1: +error: + ===================== == dowhile == fun dowhile() { @@ -39,4 +41,6 @@ l2: read (Unit) l1: +error: + ===================== diff --git a/idea/testData/cfg/ReturnFromExpression.instructions b/idea/testData/cfg/ReturnFromExpression.instructions index 43f3284ac47..fb3a770b768 100644 --- a/idea/testData/cfg/ReturnFromExpression.instructions +++ b/idea/testData/cfg/ReturnFromExpression.instructions @@ -13,4 +13,6 @@ l2: r(false || (return false)) l1: +error: + ===================== diff --git a/idea/testData/cfg/ShortFunction.instructions b/idea/testData/cfg/ShortFunction.instructions index 588f17b443e..c3bdcaf3778 100644 --- a/idea/testData/cfg/ShortFunction.instructions +++ b/idea/testData/cfg/ShortFunction.instructions @@ -6,4 +6,6 @@ l0: r(1) l1: +error: + =====================