CF for throw

This commit is contained in:
Andrey Breslav
2011-04-14 20:26:54 +04:00
parent 1d01d519b9
commit c2f8ea6893
14 changed files with 97 additions and 9 deletions
@@ -73,10 +73,12 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
private class JetControlFlowInstructionsGeneratorWorker implements JetControlFlowBuilder { private class JetControlFlowInstructionsGeneratorWorker implements JetControlFlowBuilder {
private final Pseudocode pseudocode; private final Pseudocode pseudocode;
private final Label error;
private final JetElement currentSubroutine; private final JetElement currentSubroutine;
private JetControlFlowInstructionsGeneratorWorker(@NotNull JetElement scopingElement, @NotNull JetElement currentSubroutine) { private JetControlFlowInstructionsGeneratorWorker(@NotNull JetElement scopingElement, @NotNull JetElement currentSubroutine) {
this.pseudocode = new Pseudocode(scopingElement); this.pseudocode = new Pseudocode(scopingElement);
this.error = pseudocode.createLabel("error");
this.currentSubroutine = currentSubroutine; this.currentSubroutine = currentSubroutine;
} }
@@ -176,7 +178,9 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
@Override @Override
public void exitSubroutine(@NotNull JetElement subroutine, boolean functionLiteral) { public void exitSubroutine(@NotNull JetElement subroutine, boolean functionLiteral) {
bindLabel(getExitPoint(subroutine)); bindLabel(getExitPoint(subroutine));
add(new SubroutineExitInstruction(subroutine)); pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, "<END>"));
bindLabel(error);
add(new SubroutineExitInstruction(subroutine, "<ERROR>"));
elementToBlockInfo.remove(subroutine); elementToBlockInfo.remove(subroutine);
allBlocks.pop(); allBlocks.pop();
} }
@@ -241,7 +245,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
@Override @Override
public void jumpToError(@NotNull JetThrowExpression expression) { public void jumpToError(@NotNull JetThrowExpression expression) {
// add(new UnconditionalJumpInstruction(error)); add(new UnconditionalJumpInstruction(error));
} }
@Override @Override
@@ -74,14 +74,15 @@ public class Pseudocode {
return instructions; return instructions;
} }
public void addExitInstruction(SubroutineExitInstruction exitInstruction) {
addInstruction(exitInstruction);
assert this.exitInstruction == null;
this.exitInstruction = exitInstruction;
}
public void addInstruction(Instruction instruction) { public void addInstruction(Instruction instruction) {
instructions.add(instruction); instructions.add(instruction);
instruction.setOwner(this); instruction.setOwner(this);
if (instruction instanceof SubroutineExitInstruction) {
SubroutineExitInstruction exitInstruction = (SubroutineExitInstruction) instruction;
assert this.exitInstruction == null;
this.exitInstruction = exitInstruction;
}
} }
@NotNull @NotNull
@@ -11,9 +11,11 @@ import java.util.Collections;
*/ */
public class SubroutineExitInstruction extends InstructionImpl { public class SubroutineExitInstruction extends InstructionImpl {
private final JetElement subroutine; 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.subroutine = subroutine;
this.debugLabel = debugLabel;
} }
public JetElement getSubroutine() { public JetElement getSubroutine() {
@@ -33,6 +35,6 @@ public class SubroutineExitInstruction extends InstructionImpl {
@Override @Override
public String toString() { public String toString() {
return "<END>"; return debugLabel;
} }
} }
@@ -41,4 +41,6 @@ l5:
w(z) w(z)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
+12
View File
@@ -6,6 +6,8 @@ l2:
r(1) r(1)
l3: l3:
<END> <END>
error:
<ERROR>
===================== =====================
== f == == f ==
fun f(a : Boolean) : Unit { fun f(a : Boolean) : Unit {
@@ -67,11 +69,15 @@ l5:
r(a || false) r(a || false)
l1: l1:
<END> <END>
error:
<ERROR>
l2: l2:
<START> <START>
r(1) r(1)
l3: l3:
<END> <END>
error:
<ERROR>
===================== =====================
== foo == == foo ==
fun foo(a : Boolean, b : Int) : Unit {} fun foo(a : Boolean, b : Int) : Unit {}
@@ -80,6 +86,8 @@ l0:
<START> <START>
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== genfun == == genfun ==
fun genfun<T>() : Unit {} fun genfun<T>() : Unit {}
@@ -88,6 +96,8 @@ l0:
<START> <START>
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== flfun == == flfun ==
fun flfun(f : {() : Any}) : Unit {} fun flfun(f : {() : Any}) : Unit {}
@@ -96,4 +106,6 @@ l0:
<START> <START>
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
@@ -5,4 +5,6 @@ l0:
<START> <START>
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
@@ -0,0 +1,14 @@
== fail ==
fun fail() : Nothing {
throw new java.lang.RuntimeException()
}
---------------------
l0:
<START>
r(new java.lang.RuntimeException())
jmp(error)
l1:
<END>
error:
<ERROR>
=====================
+3
View File
@@ -0,0 +1,3 @@
fun fail() : Nothing {
throw new java.lang.RuntimeException()
}
+30
View File
@@ -15,6 +15,8 @@ l2:
r(2) r(2)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== t3 == == t3 ==
fun t3() { fun t3() {
@@ -47,6 +49,8 @@ l4:
r(2) r(2)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== anonymous_0 == == anonymous_0 ==
{ () => { () =>
@@ -69,6 +73,8 @@ l5:
l4: l4:
l6: l6:
<END> <END>
error:
<ERROR>
===================== =====================
== t3 == == t3 ==
fun t3() { fun t3() {
@@ -97,6 +103,8 @@ l2:
r(2) r(2)
l1: l1:
<END> <END>
error:
<ERROR>
l3: l3:
<START> <START>
r(2) r(2)
@@ -111,6 +119,8 @@ l5:
l4: l4:
l6: l6:
<END> <END>
error:
<ERROR>
===================== =====================
== anonymous_1 == == anonymous_1 ==
{ () => { () =>
@@ -143,6 +153,8 @@ l6:
r(2) r(2)
l3: l3:
<END> <END>
error:
<ERROR>
===================== =====================
== t3 == == t3 ==
fun t3() { fun t3() {
@@ -172,6 +184,8 @@ l0:
}) })
l1: l1:
<END> <END>
error:
<ERROR>
l2: l2:
<START> <START>
jmp?(l4) jmp?(l4)
@@ -191,6 +205,8 @@ l6:
r(2) r(2)
l3: l3:
<END> <END>
error:
<ERROR>
===================== =====================
== t3 == == t3 ==
fun t3() { fun t3() {
@@ -231,6 +247,8 @@ l2:
read (Unit) read (Unit)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== t3 == == t3 ==
fun t3() { fun t3() {
@@ -272,6 +290,8 @@ l2:
r(2) r(2)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== t3 == == t3 ==
fun t3() { fun t3() {
@@ -311,6 +331,8 @@ l2:
r(2) r(2)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== t3 == == t3 ==
fun t3(a : Int) { fun t3(a : Int) {
@@ -354,6 +376,8 @@ l2:
read (Unit) read (Unit)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== t3 == == t3 ==
fun t3(a : Int) { fun t3(a : Int) {
@@ -398,6 +422,8 @@ l2:
r(2) r(2)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== t3 == == t3 ==
fun t3(a : Int) { fun t3(a : Int) {
@@ -440,6 +466,8 @@ l2:
r(2) r(2)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== tf == == tf ==
fun tf() { fun tf() {
@@ -463,4 +491,6 @@ l2:
ret(*) l1 ret(*) l1
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
@@ -67,4 +67,6 @@ l13:
r(14) r(14)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
+8
View File
@@ -16,6 +16,8 @@ l8:
l7: l7:
l9: l9:
<END> <END>
error:
<ERROR>
===================== =====================
== anonymous_0 == == anonymous_0 ==
{a => {a =>
@@ -35,6 +37,8 @@ l4:
ret(*) l5 ret(*) l5
l5: l5:
<END> <END>
error:
<ERROR>
===================== =====================
== nonlocals1 == == nonlocals1 ==
fun nonlocals1(a : Boolean, b : Boolean) : Any? { fun nonlocals1(a : Boolean, b : Boolean) : Any? {
@@ -80,6 +84,8 @@ l3:
r(1.lng) r(1.lng)
l1: l1:
<END> <END>
error:
<ERROR>
l4: l4:
<START> <START>
r(2) r(2)
@@ -87,4 +93,6 @@ l4:
ret(*) l5 ret(*) l5
l5: l5:
<END> <END>
error:
<ERROR>
===================== =====================
@@ -19,6 +19,8 @@ l2:
read (Unit) read (Unit)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
== dowhile == == dowhile ==
fun dowhile() { fun dowhile() {
@@ -39,4 +41,6 @@ l2:
read (Unit) read (Unit)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
@@ -13,4 +13,6 @@ l2:
r(false || (return false)) r(false || (return false))
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================
@@ -6,4 +6,6 @@ l0:
r(1) r(1)
l1: l1:
<END> <END>
error:
<ERROR>
===================== =====================