Added optional custom names to labels in pseudocode

This commit is contained in:
Svetlana Isakova
2012-12-07 20:00:24 +04:00
parent 3ac45ecca7
commit 28f1d288cf
4 changed files with 20 additions and 5 deletions
@@ -33,6 +33,8 @@ public interface JetControlFlowBuilder {
// General label management // General label management
@NotNull @NotNull
Label createUnboundLabel(); Label createUnboundLabel();
@NotNull
Label createUnboundLabel(@NotNull String name);
void bindLabel(@NotNull Label label); void bindLabel(@NotNull Label label);
void allowDead(); void allowDead();
@@ -48,6 +48,13 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
return builder.createUnboundLabel(); return builder.createUnboundLabel();
} }
@NotNull
@Override
public Label createUnboundLabel(@NotNull String name) {
assert builder != null;
return builder.createUnboundLabel(name);
}
@Override @Override
public void bindLabel(@NotNull Label label) { public void bindLabel(@NotNull Label label) {
assert builder != null; assert builder != null;
@@ -368,26 +368,26 @@ public class JetControlFlowProcessor {
final boolean hasCatches = !catchClauses.isEmpty(); final boolean hasCatches = !catchClauses.isEmpty();
Label onException = null; Label onException = null;
if (hasCatches) { if (hasCatches) {
onException = builder.createUnboundLabel(); onException = builder.createUnboundLabel("onException");
builder.nondeterministicJump(onException); builder.nondeterministicJump(onException);
} }
Label onExceptionToFinallyBlock = null; Label onExceptionToFinallyBlock = null;
if (finallyBlock != null) { if (finallyBlock != null) {
onExceptionToFinallyBlock = builder.createUnboundLabel(); onExceptionToFinallyBlock = builder.createUnboundLabel("onExceptionToFinallyBlock");
builder.nondeterministicJump(onExceptionToFinallyBlock); builder.nondeterministicJump(onExceptionToFinallyBlock);
} }
value(expression.getTryBlock(), inCondition); value(expression.getTryBlock(), inCondition);
if (hasCatches) { if (hasCatches) {
builder.allowDead(); builder.allowDead();
Label afterCatches = builder.createUnboundLabel(); Label afterCatches = builder.createUnboundLabel("afterCatches");
builder.jump(afterCatches); builder.jump(afterCatches);
builder.bindLabel(onException); builder.bindLabel(onException);
LinkedList<Label> catchLabels = Lists.newLinkedList(); LinkedList<Label> catchLabels = Lists.newLinkedList();
int catchClausesSize = catchClauses.size(); int catchClausesSize = catchClauses.size();
for (int i = 0; i < catchClausesSize - 1; i++) { for (int i = 0; i < catchClausesSize - 1; i++) {
catchLabels.add(builder.createUnboundLabel()); catchLabels.add(builder.createUnboundLabel("catch " + i));
} }
builder.nondeterministicJump(catchLabels); builder.nondeterministicJump(catchLabels);
boolean isFirst = true; boolean isFirst = true;
@@ -420,7 +420,7 @@ public class JetControlFlowProcessor {
if (finallyBlock != null) { if (finallyBlock != null) {
builder.exitTryFinally(); builder.exitTryFinally();
Label skipFinallyToErrorBlock = builder.createUnboundLabel(); Label skipFinallyToErrorBlock = builder.createUnboundLabel("skipFinallyToErrorBlock");
builder.jump(skipFinallyToErrorBlock); builder.jump(skipFinallyToErrorBlock);
builder.bindLabel(onExceptionToFinallyBlock); builder.bindLabel(onExceptionToFinallyBlock);
value(finallyBlock.getFinalExpression(), inCondition); value(finallyBlock.getFinalExpression(), inCondition);
@@ -104,6 +104,12 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
return pseudocode.createLabel("l" + labelCount++); return pseudocode.createLabel("l" + labelCount++);
} }
@NotNull
@Override
public Label createUnboundLabel(@NotNull String name) {
return pseudocode.createLabel("l" + labelCount++ + " [" + name + "]");
}
@Override @Override
public final LoopInfo enterLoop(@NotNull JetExpression expression, Label loopExitPoint, Label conditionEntryPoint) { public final LoopInfo enterLoop(@NotNull JetExpression expression, Label loopExitPoint, Label conditionEntryPoint) {
Label label = createUnboundLabel(); Label label = createUnboundLabel();