Pseudocode: don't write full label name when jump on it
This commit is contained in:
+15
-15
@@ -117,8 +117,8 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
|
||||
private JetControlFlowInstructionsGeneratorWorker(@NotNull JetElement scopingElement, @NotNull JetElement returnSubroutine) {
|
||||
this.pseudocode = new PseudocodeImpl(scopingElement);
|
||||
this.error = pseudocode.createLabel("error");
|
||||
this.sink = pseudocode.createLabel("sink");
|
||||
this.error = pseudocode.createLabel("error", null);
|
||||
this.sink = pseudocode.createLabel("sink", null);
|
||||
this.returnSubroutine = returnSubroutine;
|
||||
}
|
||||
|
||||
@@ -133,29 +133,28 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
@NotNull
|
||||
@Override
|
||||
public final Label createUnboundLabel() {
|
||||
return pseudocode.createLabel("L" + labelCount++);
|
||||
return pseudocode.createLabel("L" + labelCount++, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Label createUnboundLabel(@NotNull String name) {
|
||||
return pseudocode.createLabel("L" + labelCount++ + " [" + name + "]");
|
||||
return pseudocode.createLabel("L" + labelCount++, name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final LoopInfo enterLoop(@NotNull JetLoopExpression expression) {
|
||||
Label loopEntryLabel = createUnboundLabel("loop entry point");
|
||||
bindLabel(loopEntryLabel);
|
||||
LoopInfo blockInfo = new LoopInfo(
|
||||
LoopInfo info = new LoopInfo(
|
||||
expression,
|
||||
loopEntryLabel,
|
||||
createUnboundLabel("loop entry point"),
|
||||
createUnboundLabel("loop exit point"),
|
||||
createUnboundLabel("body entry point"),
|
||||
createUnboundLabel("body exit point"),
|
||||
createUnboundLabel("condition entry point"));
|
||||
elementToBlockInfo.put(expression, blockInfo);
|
||||
return blockInfo;
|
||||
bindLabel(info.getEntryPoint());
|
||||
elementToBlockInfo.put(expression, info);
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,12 +180,13 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
|
||||
@Override
|
||||
public void enterSubroutine(@NotNull JetElement subroutine) {
|
||||
Label entryPoint = createUnboundLabel();
|
||||
BreakableBlockInfo blockInfo = new BreakableBlockInfo(subroutine, entryPoint, createUnboundLabel());
|
||||
// subroutineInfo.push(blockInfo);
|
||||
BreakableBlockInfo blockInfo = new BreakableBlockInfo(
|
||||
subroutine,
|
||||
/* entry point */ createUnboundLabel(),
|
||||
/* exit point */ createUnboundLabel());
|
||||
elementToBlockInfo.put(subroutine, blockInfo);
|
||||
allBlocks.push(blockInfo);
|
||||
bindLabel(entryPoint);
|
||||
bindLabel(blockInfo.getEntryPoint());
|
||||
add(new SubroutineEnterInstruction(subroutine, getCurrentScope()));
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
|
||||
@Override
|
||||
public void repeatPseudocode(@NotNull Label startLabel, @NotNull Label finishLabel) {
|
||||
pseudocode.repeatPart(startLabel, finishLabel);
|
||||
labelCount = pseudocode.repeatPart(startLabel, finishLabel, labelCount);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,7 +23,6 @@ import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.cfg.Label;
|
||||
import org.jetbrains.jet.lang.cfg.LoopInfo;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.*;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.MergeInstruction;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.jumps.AbstractJumpInstruction;
|
||||
@@ -35,7 +34,6 @@ import org.jetbrains.jet.lang.cfg.pseudocode.instructions.special.SubroutineExit
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.special.SubroutineSinkInstruction;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.PseudocodeTraverserPackage;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -46,11 +44,13 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
|
||||
public class PseudocodeLabel implements Label {
|
||||
private final String name;
|
||||
private final String comment;
|
||||
private Integer targetInstructionIndex;
|
||||
|
||||
|
||||
private PseudocodeLabel(String name) {
|
||||
private PseudocodeLabel(@NotNull String name, @Nullable String comment) {
|
||||
this.name = name;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -61,7 +61,7 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
return comment == null ? name : (name + " [" + comment + "]");
|
||||
}
|
||||
|
||||
public Integer getTargetInstructionIndex() {
|
||||
@@ -83,8 +83,8 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
return mutableInstructionList.get(targetInstructionIndex);
|
||||
}
|
||||
|
||||
public Label copy() {
|
||||
return new PseudocodeLabel("copy " + name);
|
||||
public PseudocodeLabel copy(int newLabelIndex) {
|
||||
return new PseudocodeLabel("L" + newLabelIndex, "copy of " + name + ", " + comment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,8 +161,8 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
return this;
|
||||
}
|
||||
|
||||
/*package*/ PseudocodeLabel createLabel(String name) {
|
||||
PseudocodeLabel label = new PseudocodeLabel(name);
|
||||
/*package*/ PseudocodeLabel createLabel(@NotNull String name, @Nullable String comment) {
|
||||
PseudocodeLabel label = new PseudocodeLabel(name, comment);
|
||||
labels.add(label);
|
||||
return label;
|
||||
}
|
||||
@@ -454,7 +454,7 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
return mutableInstructionList.get(targetPosition);
|
||||
}
|
||||
|
||||
public void repeatPart(@NotNull Label startLabel, @NotNull Label finishLabel) {
|
||||
public int repeatPart(@NotNull Label startLabel, @NotNull Label finishLabel, int labelCount) {
|
||||
Integer startIndex = ((PseudocodeLabel) startLabel).getTargetInstructionIndex();
|
||||
assert startIndex != null;
|
||||
Integer finishIndex = ((PseudocodeLabel) finishLabel).getTargetInstructionIndex();
|
||||
@@ -468,7 +468,7 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
if (label == startLabel || label == finishLabel) continue;
|
||||
|
||||
if (startIndex <= index && index <= finishIndex) {
|
||||
originalToCopy.put(label, label.copy());
|
||||
originalToCopy.put(label, label.copy(labelCount++));
|
||||
originalLabelsForInstruction.put(getJumpTarget(label), label);
|
||||
}
|
||||
}
|
||||
@@ -478,6 +478,7 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
addInstruction(copyInstruction(originalInstruction, originalToCopy));
|
||||
}
|
||||
repeatLabelsBindingForInstruction(mutableInstructionList.get(finishIndex), originalToCopy, originalLabelsForInstruction);
|
||||
return labelCount;
|
||||
}
|
||||
|
||||
private void repeatLabelsBindingForInstruction(
|
||||
|
||||
Reference in New Issue
Block a user