Rearranged declarations, added missing annotations in JetControlFlowBuilder

This commit is contained in:
Andrey Breslav
2013-11-29 15:20:54 +04:00
parent 8b0eea76ef
commit 47ea25dbc2
3 changed files with 44 additions and 35 deletions
@@ -21,14 +21,31 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode;
import org.jetbrains.jet.lang.psi.*;
import java.util.Collection;
import java.util.List;
public interface JetControlFlowBuilder {
void read(@NotNull JetElement element);
void readUnit(@NotNull JetExpression expression);
// Subroutines
void enterSubroutine(@NotNull JetElement subroutine);
// General label management
@NotNull
Pseudocode exitSubroutine(@NotNull JetElement subroutine);
@NotNull
JetElement getCurrentSubroutine();
@Nullable
JetElement getReturnSubroutine();
// Entry/exit points
@NotNull
Label getEntryPoint(@NotNull JetElement labelElement);
@NotNull
Label getExitPoint(@NotNull JetElement labelElement);
// Declarations
void declare(@NotNull JetParameter parameter);
void declare(@NotNull JetVariableDeclaration property);
// Labels
@NotNull
Label createUnboundLabel();
@NotNull
@@ -40,13 +57,14 @@ public interface JetControlFlowBuilder {
void jump(@NotNull Label label);
void jumpOnFalse(@NotNull Label label);
void jumpOnTrue(@NotNull Label label);
void nondeterministicJump(Label label); // Maybe, jump to label
void nondeterministicJump(List<Label> label);
void nondeterministicJump(@NotNull Label label); // Maybe, jump to label
void nondeterministicJump(@NotNull List<Label> label);
void jumpToError();
// Entry/exit points
Label getEntryPoint(@NotNull JetElement labelElement);
Label getExitPoint(@NotNull JetElement labelElement);
void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine);
void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine);
void throwException(@NotNull JetThrowExpression throwExpression);
// Loops
LoopInfo enterLoop(@NotNull JetExpression expression, @Nullable Label loopExitPoint, @Nullable Label conditionEntryPoint);
@@ -55,33 +73,17 @@ public interface JetControlFlowBuilder {
@Nullable
JetElement getCurrentLoop();
// Finally
// Try-Finally
void enterTryFinally(@NotNull GenerationTrigger trigger);
void exitTryFinally();
// Subroutines
void enterSubroutine(@NotNull JetElement subroutine);
Pseudocode exitSubroutine(@NotNull JetElement subroutine);
@NotNull
JetElement getCurrentSubroutine();
@Nullable
JetElement getReturnSubroutine();
void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine);
void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine);
void throwException(@NotNull JetThrowExpression throwExpression);
void repeatPseudocode(@NotNull Label startLabel, @NotNull Label finishLabel);
// Reading values
void readUnit(@NotNull JetExpression expression);
void read(@NotNull JetElement element);
void write(@NotNull JetElement assignment, @NotNull JetElement lValue);
void declare(@NotNull JetParameter parameter);
void declare(@NotNull JetVariableDeclaration property);
// Other
void unsupported(JetElement element);
void repeatPseudocode(@NotNull Label startLabel, @NotNull Label finishLabel);
}
@@ -78,13 +78,13 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
}
@Override
public void nondeterministicJump(Label label) {
public void nondeterministicJump(@NotNull Label label) {
assert builder != null;
builder.nondeterministicJump(label);
}
@Override
public void nondeterministicJump(List<Label> labels) {
public void nondeterministicJump(@NotNull List<Label> labels) {
assert builder != null;
builder.nondeterministicJump(labels);
}
@@ -101,11 +101,13 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
builder.throwException(throwExpression);
}
@NotNull
public Label getEntryPoint(@NotNull JetElement labelElement) {
assert builder != null;
return builder.getEntryPoint(labelElement);
}
@NotNull
@Override
public Label getExitPoint(@NotNull JetElement labelElement) {
assert builder != null;
@@ -149,6 +151,7 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
builder.enterSubroutine(subroutine);
}
@NotNull
@Override
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
assert builder != null;
@@ -67,6 +67,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
builder.enterSubroutine(subroutine);
}
@NotNull
@Override
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
super.exitSubroutine(subroutine);
@@ -165,11 +166,13 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
return returnSubroutine;// subroutineInfo.empty() ? null : subroutineInfo.peek().getElement();
}
@NotNull
@Override
public Label getEntryPoint(@NotNull JetElement labelElement) {
return elementToBlockInfo.get(labelElement).getEntryPoint();
}
@NotNull
@Override
public Label getExitPoint(@NotNull JetElement labelElement) {
BreakableBlockInfo blockInfo = elementToBlockInfo.get(labelElement);
@@ -201,6 +204,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
}
}
@NotNull
@Override
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
bindLabel(getExitPoint(subroutine));
@@ -211,7 +215,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, "<SINK>"));
elementToBlockInfo.remove(subroutine);
allBlocks.pop();
return null;
return pseudocode;
}
@Override
@@ -277,13 +281,13 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
}
@Override
public void nondeterministicJump(Label label) {
public void nondeterministicJump(@NotNull Label label) {
handleJumpInsideTryFinally(label);
add(new NondeterministicJumpInstruction(label));
}
@Override
public void nondeterministicJump(List<Label> labels) {
public void nondeterministicJump(@NotNull List<Label> labels) {
//todo
//handleJumpInsideTryFinally(label);
add(new NondeterministicJumpInstruction(labels));