Added LexicalScope.
Each instruction has a reference to a lexical scope it was generated in. The lexical scope is: block, for loop, catch clause, a declaration of: function, function literal, class/object, etc.
This commit is contained in:
@@ -39,6 +39,10 @@ public interface JetControlFlowBuilder {
|
|||||||
@Nullable
|
@Nullable
|
||||||
JetElement getReturnSubroutine();
|
JetElement getReturnSubroutine();
|
||||||
|
|
||||||
|
// Lexical scopes
|
||||||
|
void enterLexicalScope(@NotNull JetElement element);
|
||||||
|
void exitLexicalScope(@NotNull JetElement element);
|
||||||
|
|
||||||
// Entry/exit points
|
// Entry/exit points
|
||||||
@NotNull
|
@NotNull
|
||||||
Label getEntryPoint(@NotNull JetElement labelElement);
|
Label getEntryPoint(@NotNull JetElement labelElement);
|
||||||
|
|||||||
@@ -239,4 +239,14 @@ public abstract class JetControlFlowBuilderAdapter implements JetControlFlowBuil
|
|||||||
public void mark(@NotNull JetElement element) {
|
public void mark(@NotNull JetElement element) {
|
||||||
getDelegateBuilder().mark(element);
|
getDelegateBuilder().mark(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enterLexicalScope(@NotNull JetElement element) {
|
||||||
|
getDelegateBuilder().enterLexicalScope(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exitLexicalScope(@NotNull JetElement element) {
|
||||||
|
getDelegateBuilder().exitLexicalScope(element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -507,6 +507,7 @@ public class JetControlFlowProcessor {
|
|||||||
}
|
}
|
||||||
boolean isFirst = true;
|
boolean isFirst = true;
|
||||||
for (JetCatchClause catchClause : catchClauses) {
|
for (JetCatchClause catchClause : catchClauses) {
|
||||||
|
builder.enterLexicalScope(catchClause);
|
||||||
if (!isFirst) {
|
if (!isFirst) {
|
||||||
builder.bindLabel(catchLabels.remove());
|
builder.bindLabel(catchLabels.remove());
|
||||||
}
|
}
|
||||||
@@ -523,6 +524,7 @@ public class JetControlFlowProcessor {
|
|||||||
generateInstructions(catchBody, NOT_IN_CONDITION);
|
generateInstructions(catchBody, NOT_IN_CONDITION);
|
||||||
}
|
}
|
||||||
builder.jump(afterCatches);
|
builder.jump(afterCatches);
|
||||||
|
builder.exitLexicalScope(catchClause);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.bindLabel(afterCatches);
|
builder.bindLabel(afterCatches);
|
||||||
@@ -578,6 +580,7 @@ public class JetControlFlowProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitDoWhileExpressionVoid(@NotNull JetDoWhileExpression expression, CFPContext context) {
|
public void visitDoWhileExpressionVoid(@NotNull JetDoWhileExpression expression, CFPContext context) {
|
||||||
|
builder.enterLexicalScope(expression);
|
||||||
mark(expression);
|
mark(expression);
|
||||||
LoopInfo loopInfo = builder.enterLoop(expression, null, null);
|
LoopInfo loopInfo = builder.enterLoop(expression, null, null);
|
||||||
|
|
||||||
@@ -594,10 +597,12 @@ public class JetControlFlowProcessor {
|
|||||||
builder.jumpOnTrue(loopInfo.getEntryPoint());
|
builder.jumpOnTrue(loopInfo.getEntryPoint());
|
||||||
builder.exitLoop(expression);
|
builder.exitLoop(expression);
|
||||||
builder.loadUnit(expression);
|
builder.loadUnit(expression);
|
||||||
|
builder.exitLexicalScope(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitForExpressionVoid(@NotNull JetForExpression expression, CFPContext context) {
|
public void visitForExpressionVoid(@NotNull JetForExpression expression, CFPContext context) {
|
||||||
|
builder.enterLexicalScope(expression);
|
||||||
mark(expression);
|
mark(expression);
|
||||||
JetExpression loopRange = expression.getLoopRange();
|
JetExpression loopRange = expression.getLoopRange();
|
||||||
if (loopRange != null) {
|
if (loopRange != null) {
|
||||||
@@ -630,6 +635,7 @@ public class JetControlFlowProcessor {
|
|||||||
builder.nondeterministicJump(loopInfo.getEntryPoint());
|
builder.nondeterministicJump(loopInfo.getEntryPoint());
|
||||||
builder.exitLoop(expression);
|
builder.exitLoop(expression);
|
||||||
builder.loadUnit(expression);
|
builder.loadUnit(expression);
|
||||||
|
builder.exitLexicalScope(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -731,6 +737,10 @@ public class JetControlFlowProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitBlockExpressionVoid(@NotNull JetBlockExpression expression, CFPContext context) {
|
public void visitBlockExpressionVoid(@NotNull JetBlockExpression expression, CFPContext context) {
|
||||||
|
boolean declareLexicalScope = !isBlockInDoWhile(expression);
|
||||||
|
if (declareLexicalScope) {
|
||||||
|
builder.enterLexicalScope(expression);
|
||||||
|
}
|
||||||
mark(expression);
|
mark(expression);
|
||||||
List<JetElement> statements = expression.getStatements();
|
List<JetElement> statements = expression.getStatements();
|
||||||
for (JetElement statement : statements) {
|
for (JetElement statement : statements) {
|
||||||
@@ -739,6 +749,15 @@ public class JetControlFlowProcessor {
|
|||||||
if (statements.isEmpty()) {
|
if (statements.isEmpty()) {
|
||||||
builder.loadUnit(expression);
|
builder.loadUnit(expression);
|
||||||
}
|
}
|
||||||
|
if (declareLexicalScope) {
|
||||||
|
builder.exitLexicalScope(expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlockInDoWhile(@NotNull JetBlockExpression expression) {
|
||||||
|
PsiElement parent = expression.getParent();
|
||||||
|
if (parent == null) return false;
|
||||||
|
return parent.getParent() instanceof JetDoWhileExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+5
-4
@@ -26,7 +26,8 @@ public abstract class AbstractJumpInstruction extends InstructionImpl {
|
|||||||
private final Label targetLabel;
|
private final Label targetLabel;
|
||||||
private Instruction resolvedTarget;
|
private Instruction resolvedTarget;
|
||||||
|
|
||||||
public AbstractJumpInstruction(Label targetLabel) {
|
public AbstractJumpInstruction(Label targetLabel, LexicalScope lexicalScope) {
|
||||||
|
super(lexicalScope);
|
||||||
this.targetLabel = targetLabel;
|
this.targetLabel = targetLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,15 +49,15 @@ public abstract class AbstractJumpInstruction extends InstructionImpl {
|
|||||||
this.resolvedTarget = outgoingEdgeTo(resolvedTarget);
|
this.resolvedTarget = outgoingEdgeTo(resolvedTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract AbstractJumpInstruction createCopy(@NotNull Label newLabel);
|
protected abstract AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope);
|
||||||
|
|
||||||
final public Instruction copy(@NotNull Label newLabel) {
|
final public Instruction copy(@NotNull Label newLabel) {
|
||||||
return updateCopyInfo(createCopy(newLabel));
|
return updateCopyInfo(createCopy(newLabel, lexicalScope));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
return createCopy(targetLabel);
|
return createCopy(targetLabel, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -27,8 +27,8 @@ public class ConditionalJumpInstruction extends AbstractJumpInstruction {
|
|||||||
private Instruction nextOnTrue;
|
private Instruction nextOnTrue;
|
||||||
private Instruction nextOnFalse;
|
private Instruction nextOnFalse;
|
||||||
|
|
||||||
public ConditionalJumpInstruction(boolean onTrue, Label targetLabel) {
|
public ConditionalJumpInstruction(boolean onTrue, LexicalScope lexicalScope, Label targetLabel) {
|
||||||
super(targetLabel);
|
super(targetLabel, lexicalScope);
|
||||||
this.onTrue = onTrue;
|
this.onTrue = onTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ public class ConditionalJumpInstruction extends AbstractJumpInstruction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||||
return new ConditionalJumpInstruction(onTrue, newLabel);
|
return new ConditionalJumpInstruction(onTrue, lexicalScope, newLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,4 +37,7 @@ public interface Instruction {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Collection<Instruction> getCopies();
|
Collection<Instruction> getCopies();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
LexicalScope getLexicalScope();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,13 @@ public abstract class InstructionImpl implements Instruction {
|
|||||||
private Pseudocode owner;
|
private Pseudocode owner;
|
||||||
private final Collection<Instruction> previousInstructions = new LinkedHashSet<Instruction>();
|
private final Collection<Instruction> previousInstructions = new LinkedHashSet<Instruction>();
|
||||||
private final Collection<Instruction> copies = Sets.newHashSet();
|
private final Collection<Instruction> copies = Sets.newHashSet();
|
||||||
|
@NotNull
|
||||||
|
protected final LexicalScope lexicalScope;
|
||||||
private Instruction original;
|
private Instruction original;
|
||||||
protected boolean isDead = false;
|
protected boolean isDead = false;
|
||||||
|
|
||||||
protected InstructionImpl() {
|
protected InstructionImpl(@NotNull LexicalScope lexicalScope) {
|
||||||
|
this.lexicalScope = lexicalScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,6 +99,12 @@ public abstract class InstructionImpl implements Instruction {
|
|||||||
this.original = original;
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public LexicalScope getLexicalScope() {
|
||||||
|
return lexicalScope;
|
||||||
|
}
|
||||||
|
|
||||||
protected Instruction updateCopyInfo(@NotNull Instruction instruction) {
|
protected Instruction updateCopyInfo(@NotNull Instruction instruction) {
|
||||||
addCopy(instruction);
|
addCopy(instruction);
|
||||||
((InstructionImpl)instruction).setOriginal(this);
|
((InstructionImpl)instruction).setOriginal(this);
|
||||||
|
|||||||
+2
-2
@@ -25,8 +25,8 @@ import java.util.Collections;
|
|||||||
public abstract class InstructionWithNext extends JetElementInstructionImpl {
|
public abstract class InstructionWithNext extends JetElementInstructionImpl {
|
||||||
private Instruction next;
|
private Instruction next;
|
||||||
|
|
||||||
protected InstructionWithNext(@NotNull JetElement element) {
|
protected InstructionWithNext(@NotNull JetElement element, @NotNull LexicalScope lexicalScope) {
|
||||||
super(element);
|
super(element, lexicalScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Instruction getNext() {
|
public Instruction getNext() {
|
||||||
|
|||||||
+48
-24
@@ -36,6 +36,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
private JetControlFlowBuilder builder = null;
|
private JetControlFlowBuilder builder = null;
|
||||||
|
|
||||||
private final Stack<BreakableBlockInfo> loopInfo = new Stack<BreakableBlockInfo>();
|
private final Stack<BreakableBlockInfo> loopInfo = new Stack<BreakableBlockInfo>();
|
||||||
|
private final Stack<LexicalScope> lexicalScopes = new Stack<LexicalScope>();
|
||||||
private final Map<JetElement, BreakableBlockInfo> elementToBlockInfo = new HashMap<JetElement, BreakableBlockInfo>();
|
private final Map<JetElement, BreakableBlockInfo> elementToBlockInfo = new HashMap<JetElement, BreakableBlockInfo>();
|
||||||
private int labelCount = 0;
|
private int labelCount = 0;
|
||||||
private int allowDeadLabelCount = 0;
|
private int allowDeadLabelCount = 0;
|
||||||
@@ -76,6 +77,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
pushBuilder(subroutine, subroutine);
|
pushBuilder(subroutine, subroutine);
|
||||||
}
|
}
|
||||||
assert builder != null;
|
assert builder != null;
|
||||||
|
builder.enterLexicalScope(subroutine);
|
||||||
builder.enterSubroutine(subroutine);
|
builder.enterSubroutine(subroutine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +85,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
@Override
|
@Override
|
||||||
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
|
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
|
||||||
super.exitSubroutine(subroutine);
|
super.exitSubroutine(subroutine);
|
||||||
|
builder.exitLexicalScope(subroutine);
|
||||||
JetControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine);
|
JetControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine);
|
||||||
if (!builders.empty()) {
|
if (!builders.empty()) {
|
||||||
JetControlFlowInstructionsGeneratorWorker builder = builders.peek();
|
JetControlFlowInstructionsGeneratorWorker builder = builders.peek();
|
||||||
@@ -163,7 +166,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
elementToBlockInfo.put(subroutine, blockInfo);
|
elementToBlockInfo.put(subroutine, blockInfo);
|
||||||
allBlocks.push(blockInfo);
|
allBlocks.push(blockInfo);
|
||||||
bindLabel(entryPoint);
|
bindLabel(entryPoint);
|
||||||
add(new SubroutineEnterInstruction(subroutine));
|
add(new SubroutineEnterInstruction(subroutine, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -191,7 +194,28 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
return blockInfo.getExitPoint();
|
return blockInfo.getExitPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
@NotNull
|
||||||
|
private LexicalScope getCurrentScope() {
|
||||||
|
return lexicalScopes.peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enterLexicalScope(@NotNull JetElement element) {
|
||||||
|
LexicalScope current = lexicalScopes.isEmpty() ? null : getCurrentScope();
|
||||||
|
LexicalScope scope = new LexicalScope(current, element);
|
||||||
|
lexicalScopes.push(scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exitLexicalScope(@NotNull JetElement element) {
|
||||||
|
LexicalScope currentScope = getCurrentScope();
|
||||||
|
assert currentScope.getElement() == element : "Exit from not the current lexical scope.\n" +
|
||||||
|
"Current scope is for: " + currentScope.getElement() + ".\n" +
|
||||||
|
"Exit from the scope for: " + element.getText();
|
||||||
|
lexicalScopes.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private void handleJumpInsideTryFinally(Label jumpTarget) {
|
private void handleJumpInsideTryFinally(Label jumpTarget) {
|
||||||
List<TryFinallyBlockInfo> finallyBlocks = new ArrayList<TryFinallyBlockInfo>();
|
List<TryFinallyBlockInfo> finallyBlocks = new ArrayList<TryFinallyBlockInfo>();
|
||||||
@@ -219,11 +243,11 @@ 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, false));
|
pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, getCurrentScope(), false));
|
||||||
bindLabel(error);
|
bindLabel(error);
|
||||||
pseudocode.addErrorInstruction(new SubroutineExitInstruction(subroutine, true));
|
pseudocode.addErrorInstruction(new SubroutineExitInstruction(subroutine, getCurrentScope(), true));
|
||||||
bindLabel(sink);
|
bindLabel(sink);
|
||||||
pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, "<SINK>"));
|
pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, getCurrentScope(), "<SINK>"));
|
||||||
elementToBlockInfo.remove(subroutine);
|
elementToBlockInfo.remove(subroutine);
|
||||||
allBlocks.pop();
|
allBlocks.pop();
|
||||||
return pseudocode;
|
return pseudocode;
|
||||||
@@ -231,64 +255,64 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mark(@NotNull JetElement element) {
|
public void mark(@NotNull JetElement element) {
|
||||||
add(new MarkInstruction(element));
|
add(new MarkInstruction(element, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine) {
|
public void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine) {
|
||||||
Label exitPoint = getExitPoint(subroutine);
|
Label exitPoint = getExitPoint(subroutine);
|
||||||
handleJumpInsideTryFinally(exitPoint);
|
handleJumpInsideTryFinally(exitPoint);
|
||||||
add(new ReturnValueInstruction(returnExpression, exitPoint));
|
add(new ReturnValueInstruction(returnExpression, getCurrentScope(), exitPoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine) {
|
public void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine) {
|
||||||
Label exitPoint = getExitPoint(subroutine);
|
Label exitPoint = getExitPoint(subroutine);
|
||||||
handleJumpInsideTryFinally(exitPoint);
|
handleJumpInsideTryFinally(exitPoint);
|
||||||
add(new ReturnNoValueInstruction(returnExpression, exitPoint));
|
add(new ReturnNoValueInstruction(returnExpression, getCurrentScope(), exitPoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull JetElement assignment, @NotNull JetElement lValue) {
|
public void write(@NotNull JetElement assignment, @NotNull JetElement lValue) {
|
||||||
add(new WriteValueInstruction(assignment, lValue));
|
add(new WriteValueInstruction(assignment, lValue, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void declareParameter(@NotNull JetParameter parameter) {
|
public void declareParameter(@NotNull JetParameter parameter) {
|
||||||
add(new VariableDeclarationInstruction(parameter));
|
add(new VariableDeclarationInstruction(parameter, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void declareVariable(@NotNull JetVariableDeclaration property) {
|
public void declareVariable(@NotNull JetVariableDeclaration property) {
|
||||||
add(new VariableDeclarationInstruction(property));
|
add(new VariableDeclarationInstruction(property, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void declareFunction(@NotNull JetElement subroutine, @NotNull Pseudocode pseudocode) {
|
public void declareFunction(@NotNull JetElement subroutine, @NotNull Pseudocode pseudocode) {
|
||||||
add(new LocalFunctionDeclarationInstruction(subroutine, pseudocode));
|
add(new LocalFunctionDeclarationInstruction(subroutine, pseudocode, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadUnit(@NotNull JetExpression expression) {
|
public void loadUnit(@NotNull JetExpression expression) {
|
||||||
add(new LoadUnitValueInstruction(expression));
|
add(new LoadUnitValueInstruction(expression, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void jump(@NotNull Label label) {
|
public void jump(@NotNull Label label) {
|
||||||
handleJumpInsideTryFinally(label);
|
handleJumpInsideTryFinally(label);
|
||||||
add(new UnconditionalJumpInstruction(label));
|
add(new UnconditionalJumpInstruction(label, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void jumpOnFalse(@NotNull Label label) {
|
public void jumpOnFalse(@NotNull Label label) {
|
||||||
handleJumpInsideTryFinally(label);
|
handleJumpInsideTryFinally(label);
|
||||||
add(new ConditionalJumpInstruction(false, label));
|
add(new ConditionalJumpInstruction(false, getCurrentScope(), label));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void jumpOnTrue(@NotNull Label label) {
|
public void jumpOnTrue(@NotNull Label label) {
|
||||||
handleJumpInsideTryFinally(label);
|
handleJumpInsideTryFinally(label);
|
||||||
add(new ConditionalJumpInstruction(true, label));
|
add(new ConditionalJumpInstruction(true, getCurrentScope(), label));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -299,20 +323,20 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
@Override
|
@Override
|
||||||
public void nondeterministicJump(@NotNull Label label) {
|
public void nondeterministicJump(@NotNull Label label) {
|
||||||
handleJumpInsideTryFinally(label);
|
handleJumpInsideTryFinally(label);
|
||||||
add(new NondeterministicJumpInstruction(label));
|
add(new NondeterministicJumpInstruction(label, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void nondeterministicJump(@NotNull List<Label> labels) {
|
public void nondeterministicJump(@NotNull List<Label> labels) {
|
||||||
//todo
|
//todo
|
||||||
//handleJumpInsideTryFinally(label);
|
//handleJumpInsideTryFinally(label);
|
||||||
add(new NondeterministicJumpInstruction(labels));
|
add(new NondeterministicJumpInstruction(labels, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void jumpToError() {
|
public void jumpToError() {
|
||||||
handleJumpInsideTryFinally(error);
|
handleJumpInsideTryFinally(error);
|
||||||
add(new UnconditionalJumpInstruction(error));
|
add(new UnconditionalJumpInstruction(error, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -323,7 +347,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
@Override
|
@Override
|
||||||
public void throwException(@NotNull JetThrowExpression expression) {
|
public void throwException(@NotNull JetThrowExpression expression) {
|
||||||
handleJumpInsideTryFinally(error);
|
handleJumpInsideTryFinally(error);
|
||||||
add(new ThrowExceptionInstruction(expression, error));
|
add(new ThrowExceptionInstruction(expression, getCurrentScope(), error));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exitTryFinally() {
|
public void exitTryFinally() {
|
||||||
@@ -333,7 +357,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unsupported(JetElement element) {
|
public void unsupported(JetElement element) {
|
||||||
add(new UnsupportedElementInstruction(element));
|
add(new UnsupportedElementInstruction(element, getCurrentScope()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -373,7 +397,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(@NotNull JetExpression expression, @NotNull ResolvedCall<?> resolvedCall) {
|
public void call(@NotNull JetExpression expression, @NotNull ResolvedCall<?> resolvedCall) {
|
||||||
add(new CallInstruction(expression, resolvedCall));
|
add(new CallInstruction(expression, getCurrentScope(), resolvedCall));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -383,11 +407,11 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void compilationError(@NotNull JetElement element, @NotNull String message) {
|
public void compilationError(@NotNull JetElement element, @NotNull String message) {
|
||||||
add(new CompilationErrorInstruction(element, message));
|
add(new CompilationErrorInstruction(element, getCurrentScope(), message));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void read(@NotNull JetElement element) {
|
private void read(@NotNull JetElement element) {
|
||||||
add(new ReadValueInstruction(element));
|
add(new ReadValueInstruction(element, getCurrentScope()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -24,7 +24,8 @@ public abstract class JetElementInstructionImpl extends InstructionImpl implemen
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected final JetElement element;
|
protected final JetElement element;
|
||||||
|
|
||||||
public JetElementInstructionImpl(@NotNull JetElement element) {
|
public JetElementInstructionImpl(@NotNull JetElement element, LexicalScope lexicalScope) {
|
||||||
|
super(lexicalScope);
|
||||||
this.element = element;
|
this.element = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.lang.cfg.pseudocode
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.psi.JetElement
|
||||||
|
|
||||||
|
public class LexicalScope(val parentScope: LexicalScope?, val element: JetElement) {
|
||||||
|
//todo remove after KT-4126
|
||||||
|
private val _d = (parentScope?.depth ?: 0) + 1
|
||||||
|
val depth: Int get() = _d
|
||||||
|
}
|
||||||
+3
-3
@@ -21,8 +21,8 @@ import org.jetbrains.jet.lang.psi.JetExpression;
|
|||||||
|
|
||||||
public class LoadUnitValueInstruction extends InstructionWithNext {
|
public class LoadUnitValueInstruction extends InstructionWithNext {
|
||||||
|
|
||||||
public LoadUnitValueInstruction(@NotNull JetExpression expression) {
|
public LoadUnitValueInstruction(@NotNull JetExpression expression, LexicalScope lexicalScope) {
|
||||||
super(expression);
|
super(expression, lexicalScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -43,6 +43,6 @@ public class LoadUnitValueInstruction extends InstructionWithNext {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
return new LoadUnitValueInstruction((JetExpression) element);
|
return new LoadUnitValueInstruction((JetExpression) element, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -28,8 +28,8 @@ public class LocalFunctionDeclarationInstruction extends InstructionWithNext {
|
|||||||
private final Pseudocode body;
|
private final Pseudocode body;
|
||||||
private Instruction sink;
|
private Instruction sink;
|
||||||
|
|
||||||
public LocalFunctionDeclarationInstruction(@NotNull JetElement element, @NotNull Pseudocode body) {
|
public LocalFunctionDeclarationInstruction(@NotNull JetElement element, @NotNull Pseudocode body, LexicalScope lexicalScope) {
|
||||||
super(element);
|
super(element, lexicalScope);
|
||||||
this.body = body;
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +71,6 @@ public class LocalFunctionDeclarationInstruction extends InstructionWithNext {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
return new LocalFunctionDeclarationInstruction(element, body);
|
return new LocalFunctionDeclarationInstruction(element, body, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -28,13 +28,14 @@ public class NondeterministicJumpInstruction extends InstructionImpl{
|
|||||||
private final List<Label> targetLabels;
|
private final List<Label> targetLabels;
|
||||||
private final Map<Label, Instruction> resolvedTargets;
|
private final Map<Label, Instruction> resolvedTargets;
|
||||||
|
|
||||||
public NondeterministicJumpInstruction(List<Label> targetLabels) {
|
public NondeterministicJumpInstruction(List<Label> targetLabels, LexicalScope lexicalScope) {
|
||||||
|
super(lexicalScope);
|
||||||
this.targetLabels = Lists.newArrayList(targetLabels);
|
this.targetLabels = Lists.newArrayList(targetLabels);
|
||||||
resolvedTargets = Maps.newLinkedHashMap();
|
resolvedTargets = Maps.newLinkedHashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NondeterministicJumpInstruction(Label targetLabel) {
|
public NondeterministicJumpInstruction(Label targetLabel, LexicalScope lexicalScope) {
|
||||||
this(Lists.newArrayList(targetLabel));
|
this(Lists.newArrayList(targetLabel), lexicalScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Label> getTargetLabels() {
|
public List<Label> getTargetLabels() {
|
||||||
@@ -102,6 +103,6 @@ public class NondeterministicJumpInstruction extends InstructionImpl{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Instruction createCopy(@NotNull List<Label> newTargetLabels) {
|
private Instruction createCopy(@NotNull List<Label> newTargetLabels) {
|
||||||
return new NondeterministicJumpInstruction(newTargetLabels);
|
return new NondeterministicJumpInstruction(newTargetLabels, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -21,8 +21,8 @@ import org.jetbrains.jet.lang.psi.JetElement;
|
|||||||
|
|
||||||
public class ReadValueInstruction extends InstructionWithNext {
|
public class ReadValueInstruction extends InstructionWithNext {
|
||||||
|
|
||||||
public ReadValueInstruction(@NotNull JetElement element) {
|
public ReadValueInstruction(@NotNull JetElement element, @NotNull LexicalScope lexicalScope) {
|
||||||
super(element);
|
super(element, lexicalScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -43,6 +43,6 @@ public class ReadValueInstruction extends InstructionWithNext {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
return new ReadValueInstruction(element);
|
return new ReadValueInstruction(element, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -24,8 +24,8 @@ public class ReturnNoValueInstruction extends AbstractJumpInstruction implements
|
|||||||
|
|
||||||
private final JetElement element;
|
private final JetElement element;
|
||||||
|
|
||||||
public ReturnNoValueInstruction(@NotNull JetElement element, Label targetLabel) {
|
public ReturnNoValueInstruction(@NotNull JetElement element, LexicalScope lexicalScope, Label targetLabel) {
|
||||||
super(targetLabel);
|
super(targetLabel, lexicalScope);
|
||||||
this.element = element;
|
this.element = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class ReturnNoValueInstruction extends AbstractJumpInstruction implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||||
return new ReturnNoValueInstruction(element, newLabel);
|
return new ReturnNoValueInstruction(element, lexicalScope, newLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -25,8 +25,8 @@ public class ReturnValueInstruction extends AbstractJumpInstruction implements R
|
|||||||
|
|
||||||
private final JetElement element;
|
private final JetElement element;
|
||||||
|
|
||||||
public ReturnValueInstruction(@NotNull JetExpression returnExpression, @NotNull Label targetLabel) {
|
public ReturnValueInstruction(@NotNull JetExpression returnExpression, @NotNull LexicalScope lexicalScope, @NotNull Label targetLabel) {
|
||||||
super(targetLabel);
|
super(targetLabel, lexicalScope);
|
||||||
this.element = returnExpression;
|
this.element = returnExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ public class ReturnValueInstruction extends AbstractJumpInstruction implements R
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||||
return new ReturnValueInstruction((JetExpression) element, newLabel);
|
return new ReturnValueInstruction((JetExpression) element, lexicalScope, newLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -22,8 +22,8 @@ import org.jetbrains.jet.lang.psi.JetElement;
|
|||||||
public class SubroutineEnterInstruction extends InstructionWithNext {
|
public class SubroutineEnterInstruction extends InstructionWithNext {
|
||||||
private final JetElement subroutine;
|
private final JetElement subroutine;
|
||||||
|
|
||||||
public SubroutineEnterInstruction(@NotNull JetElement subroutine) {
|
public SubroutineEnterInstruction(@NotNull JetElement subroutine, @NotNull LexicalScope lexicalScope) {
|
||||||
super(subroutine);
|
super(subroutine, lexicalScope);
|
||||||
this.subroutine = subroutine;
|
this.subroutine = subroutine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +49,6 @@ public class SubroutineEnterInstruction extends InstructionWithNext {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
return new SubroutineEnterInstruction(subroutine);
|
return new SubroutineEnterInstruction(subroutine, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -27,7 +27,8 @@ public class SubroutineExitInstruction extends InstructionImpl {
|
|||||||
private final boolean isError;
|
private final boolean isError;
|
||||||
private SubroutineSinkInstruction sinkInstruction;
|
private SubroutineSinkInstruction sinkInstruction;
|
||||||
|
|
||||||
public SubroutineExitInstruction(@NotNull JetElement subroutine, boolean isError) {
|
public SubroutineExitInstruction(@NotNull JetElement subroutine, @NotNull LexicalScope lexicalScope, boolean isError) {
|
||||||
|
super(lexicalScope);
|
||||||
this.subroutine = subroutine;
|
this.subroutine = subroutine;
|
||||||
this.isError = isError;
|
this.isError = isError;
|
||||||
}
|
}
|
||||||
@@ -69,6 +70,6 @@ public class SubroutineExitInstruction extends InstructionImpl {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
return new SubroutineExitInstruction(subroutine, isError);
|
return new SubroutineExitInstruction(subroutine, lexicalScope, isError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -26,7 +26,8 @@ public class SubroutineSinkInstruction extends InstructionImpl {
|
|||||||
private final JetElement subroutine;
|
private final JetElement subroutine;
|
||||||
private final String debugLabel;
|
private final String debugLabel;
|
||||||
|
|
||||||
public SubroutineSinkInstruction(@NotNull JetElement subroutine, @NotNull String debugLabel) {
|
public SubroutineSinkInstruction(@NotNull JetElement subroutine, @NotNull LexicalScope lexicalScope, @NotNull String debugLabel) {
|
||||||
|
super(lexicalScope);
|
||||||
this.subroutine = subroutine;
|
this.subroutine = subroutine;
|
||||||
this.debugLabel = debugLabel;
|
this.debugLabel = debugLabel;
|
||||||
}
|
}
|
||||||
@@ -59,6 +60,6 @@ public class SubroutineSinkInstruction extends InstructionImpl {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
return new SubroutineSinkInstruction(subroutine, debugLabel);
|
return new SubroutineSinkInstruction(subroutine, lexicalScope, debugLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -24,8 +24,8 @@ import org.jetbrains.jet.lang.psi.JetThrowExpression;
|
|||||||
public class ThrowExceptionInstruction extends AbstractJumpInstruction implements JetElementInstruction {
|
public class ThrowExceptionInstruction extends AbstractJumpInstruction implements JetElementInstruction {
|
||||||
private final JetThrowExpression expression;
|
private final JetThrowExpression expression;
|
||||||
|
|
||||||
public ThrowExceptionInstruction(@NotNull JetThrowExpression expression, @NotNull Label errorLabel) {
|
public ThrowExceptionInstruction(@NotNull JetThrowExpression expression, @NotNull LexicalScope lexicalScope, @NotNull Label errorLabel) {
|
||||||
super(errorLabel);
|
super(errorLabel, lexicalScope);
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class ThrowExceptionInstruction extends AbstractJumpInstruction implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||||
return new ThrowExceptionInstruction(expression, newLabel);
|
return new ThrowExceptionInstruction(expression, lexicalScope, newLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -22,8 +22,8 @@ import org.jetbrains.jet.lang.cfg.Label;
|
|||||||
public class UnconditionalJumpInstruction extends AbstractJumpInstruction {
|
public class UnconditionalJumpInstruction extends AbstractJumpInstruction {
|
||||||
|
|
||||||
|
|
||||||
public UnconditionalJumpInstruction(Label targetLabel) {
|
public UnconditionalJumpInstruction(Label targetLabel, @NotNull LexicalScope lexicalScope) {
|
||||||
super(targetLabel);
|
super(targetLabel, lexicalScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -42,7 +42,7 @@ public class UnconditionalJumpInstruction extends AbstractJumpInstruction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||||
return new UnconditionalJumpInstruction(newLabel);
|
return new UnconditionalJumpInstruction(newLabel, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -21,8 +21,8 @@ import org.jetbrains.jet.lang.psi.JetElement;
|
|||||||
|
|
||||||
public class UnsupportedElementInstruction extends InstructionWithNext {
|
public class UnsupportedElementInstruction extends InstructionWithNext {
|
||||||
|
|
||||||
protected UnsupportedElementInstruction(@NotNull JetElement element) {
|
protected UnsupportedElementInstruction(@NotNull JetElement element, @NotNull LexicalScope lexicalScope) {
|
||||||
super(element);
|
super(element, lexicalScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -43,6 +43,6 @@ public class UnsupportedElementInstruction extends InstructionWithNext {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
return new UnsupportedElementInstruction(element);
|
return new UnsupportedElementInstruction(element, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -22,12 +22,12 @@ import org.jetbrains.jet.lang.psi.JetParameter;
|
|||||||
import org.jetbrains.jet.lang.psi.JetVariableDeclaration;
|
import org.jetbrains.jet.lang.psi.JetVariableDeclaration;
|
||||||
|
|
||||||
public class VariableDeclarationInstruction extends InstructionWithNext {
|
public class VariableDeclarationInstruction extends InstructionWithNext {
|
||||||
protected VariableDeclarationInstruction(@NotNull JetParameter element) {
|
protected VariableDeclarationInstruction(@NotNull JetParameter element, @NotNull LexicalScope lexicalScope) {
|
||||||
super(element);
|
super(element, lexicalScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected VariableDeclarationInstruction(@NotNull JetVariableDeclaration element) {
|
protected VariableDeclarationInstruction(@NotNull JetVariableDeclaration element, @NotNull LexicalScope lexicalScope) {
|
||||||
super(element);
|
super(element, lexicalScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JetDeclaration getVariableDeclarationElement() {
|
public JetDeclaration getVariableDeclarationElement() {
|
||||||
@@ -53,8 +53,8 @@ public class VariableDeclarationInstruction extends InstructionWithNext {
|
|||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
if (element instanceof JetParameter) {
|
if (element instanceof JetParameter) {
|
||||||
return new VariableDeclarationInstruction((JetParameter) element);
|
return new VariableDeclarationInstruction((JetParameter) element, lexicalScope);
|
||||||
}
|
}
|
||||||
return new VariableDeclarationInstruction((JetVariableDeclaration) element);
|
return new VariableDeclarationInstruction((JetVariableDeclaration) element, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -24,8 +24,8 @@ public class WriteValueInstruction extends InstructionWithNext {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final JetElement lValue;
|
private final JetElement lValue;
|
||||||
|
|
||||||
public WriteValueInstruction(@NotNull JetElement assignment, @NotNull JetElement lValue) {
|
public WriteValueInstruction(@NotNull JetElement assignment, @NotNull JetElement lValue, @NotNull LexicalScope lexicalScope) {
|
||||||
super(assignment);
|
super(assignment, lexicalScope);
|
||||||
this.lValue = lValue;
|
this.lValue = lValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +56,6 @@ public class WriteValueInstruction extends InstructionWithNext {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected Instruction createCopy() {
|
protected Instruction createCopy() {
|
||||||
return new WriteValueInstruction(element, lValue);
|
return new WriteValueInstruction(element, lValue, lexicalScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,9 @@ import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
|
|||||||
|
|
||||||
class CallInstruction(
|
class CallInstruction(
|
||||||
element: JetElement,
|
element: JetElement,
|
||||||
|
lexicalScope: LexicalScope,
|
||||||
val resolvedCall: ResolvedCall<*>
|
val resolvedCall: ResolvedCall<*>
|
||||||
) : InstructionWithNext(element) {
|
) : InstructionWithNext(element, lexicalScope) {
|
||||||
|
|
||||||
override fun accept(visitor: InstructionVisitor) {
|
override fun accept(visitor: InstructionVisitor) {
|
||||||
visitor.visitCallInstruction(this)
|
visitor.visitCallInstruction(this)
|
||||||
@@ -33,15 +34,16 @@ class CallInstruction(
|
|||||||
return visitor.visitCallInstruction(this)
|
return visitor.visitCallInstruction(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createCopy() = CallInstruction(element, resolvedCall)
|
override fun createCopy() = CallInstruction(element, lexicalScope, resolvedCall)
|
||||||
|
|
||||||
override fun toString() = "call(${render(element)}, ${resolvedCall.getResultingDescriptor()!!.getName()})"
|
override fun toString() = "call(${render(element)}, ${resolvedCall.getResultingDescriptor()!!.getName()})"
|
||||||
}
|
}
|
||||||
|
|
||||||
class CompilationErrorInstruction(
|
class CompilationErrorInstruction(
|
||||||
element: JetElement,
|
element: JetElement,
|
||||||
|
lexicalScope: LexicalScope,
|
||||||
val message: String
|
val message: String
|
||||||
) : InstructionWithNext(element) {
|
) : InstructionWithNext(element, lexicalScope) {
|
||||||
|
|
||||||
override fun accept(visitor: InstructionVisitor) {
|
override fun accept(visitor: InstructionVisitor) {
|
||||||
visitor.visitCompilationErrorInstruction(this)
|
visitor.visitCompilationErrorInstruction(this)
|
||||||
@@ -51,7 +53,7 @@ class CompilationErrorInstruction(
|
|||||||
return visitor.visitCompilationErrorInstruction(this)
|
return visitor.visitCompilationErrorInstruction(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createCopy() = CompilationErrorInstruction(element, message)
|
override fun createCopy() = CompilationErrorInstruction(element, lexicalScope, message)
|
||||||
|
|
||||||
override fun toString() = "error(${render(element)}, $message)"
|
override fun toString() = "error(${render(element)}, $message)"
|
||||||
}
|
}
|
||||||
@@ -60,8 +62,9 @@ class CompilationErrorInstruction(
|
|||||||
// otherwise only individual parts of expression would be reported as unreachable
|
// otherwise only individual parts of expression would be reported as unreachable
|
||||||
// e.g. for (i in foo) {} -- only i and foo would be marked unreachable
|
// e.g. for (i in foo) {} -- only i and foo would be marked unreachable
|
||||||
class MarkInstruction(
|
class MarkInstruction(
|
||||||
element: JetElement
|
element: JetElement,
|
||||||
) : InstructionWithNext(element) {
|
lexicalScope: LexicalScope
|
||||||
|
) : InstructionWithNext(element, lexicalScope) {
|
||||||
|
|
||||||
override fun accept(visitor: InstructionVisitor) {
|
override fun accept(visitor: InstructionVisitor) {
|
||||||
visitor.visitMarkInstruction(this)
|
visitor.visitMarkInstruction(this)
|
||||||
@@ -71,7 +74,7 @@ class MarkInstruction(
|
|||||||
return visitor.visitMarkInstruction(this)
|
return visitor.visitMarkInstruction(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createCopy() = MarkInstruction(element)
|
override fun createCopy() = MarkInstruction(element, lexicalScope)
|
||||||
|
|
||||||
override fun toString() = "mark(${render(element)})"
|
override fun toString() = "mark(${render(element)})"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user