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 @Override
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) { public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
bindLabel(getExitPoint(subroutine)); bindLabel(getExitPoint(subroutine));
pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, "<END>")); pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, false));
bindLabel(error); bindLabel(error);
pseudocode.addErrorInstruction(new SubroutineExitInstruction(subroutine, "<ERROR>")); pseudocode.addErrorInstruction(new SubroutineExitInstruction(subroutine, true));
bindLabel(sink); bindLabel(sink);
pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, "<SINK>")); pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, "<SINK>"));
elementToBlockInfo.remove(subroutine); elementToBlockInfo.remove(subroutine);
@@ -24,18 +24,22 @@ 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; private final boolean isError;
private SubroutineSinkInstruction sinkInstruction; private SubroutineSinkInstruction sinkInstruction;
public SubroutineExitInstruction(@NotNull JetElement subroutine, @NotNull String debugLabel) { public SubroutineExitInstruction(@NotNull JetElement subroutine, boolean isError) {
this.subroutine = subroutine; this.subroutine = subroutine;
this.debugLabel = debugLabel; this.isError = isError;
} }
public JetElement getSubroutine() { public JetElement getSubroutine() {
return subroutine; return subroutine;
} }
public boolean isError() {
return isError;
}
public void setSink(SubroutineSinkInstruction instruction) { public void setSink(SubroutineSinkInstruction instruction) {
sinkInstruction = (SubroutineSinkInstruction) outgoingEdgeTo(instruction); sinkInstruction = (SubroutineSinkInstruction) outgoingEdgeTo(instruction);
} }
@@ -59,12 +63,12 @@ public class SubroutineExitInstruction extends InstructionImpl {
@Override @Override
public String toString() { public String toString() {
return debugLabel; return isError ? "<ERROR>" : "<END>";
} }
@NotNull @NotNull
@Override @Override
protected Instruction createCopy() { protected Instruction createCopy() {
return new SubroutineExitInstruction(subroutine, debugLabel); return new SubroutineExitInstruction(subroutine, isError);
} }
} }