Subroutine exit knows when it's an error

This commit is contained in:
Andrey Breslav
2013-12-05 16:13:56 +04:00
parent 2197c7e8c6
commit d2a31d88cd
2 changed files with 11 additions and 7 deletions
@@ -219,9 +219,9 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
@Override
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
bindLabel(getExitPoint(subroutine));
pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, "<END>"));
pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, false));
bindLabel(error);
pseudocode.addErrorInstruction(new SubroutineExitInstruction(subroutine, "<ERROR>"));
pseudocode.addErrorInstruction(new SubroutineExitInstruction(subroutine, true));
bindLabel(sink);
pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, "<SINK>"));
elementToBlockInfo.remove(subroutine);
@@ -24,18 +24,22 @@ import java.util.Collections;
public class SubroutineExitInstruction extends InstructionImpl {
private final JetElement subroutine;
private final String debugLabel;
private final boolean isError;
private SubroutineSinkInstruction sinkInstruction;
public SubroutineExitInstruction(@NotNull JetElement subroutine, @NotNull String debugLabel) {
public SubroutineExitInstruction(@NotNull JetElement subroutine, boolean isError) {
this.subroutine = subroutine;
this.debugLabel = debugLabel;
this.isError = isError;
}
public JetElement getSubroutine() {
return subroutine;
}
public boolean isError() {
return isError;
}
public void setSink(SubroutineSinkInstruction instruction) {
sinkInstruction = (SubroutineSinkInstruction) outgoingEdgeTo(instruction);
}
@@ -59,12 +63,12 @@ public class SubroutineExitInstruction extends InstructionImpl {
@Override
public String toString() {
return debugLabel;
return isError ? "<ERROR>" : "<END>";
}
@NotNull
@Override
protected Instruction createCopy() {
return new SubroutineExitInstruction(subroutine, debugLabel);
return new SubroutineExitInstruction(subroutine, isError);
}
}