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
|
||||
JetElement getReturnSubroutine();
|
||||
|
||||
// Lexical scopes
|
||||
void enterLexicalScope(@NotNull JetElement element);
|
||||
void exitLexicalScope(@NotNull JetElement element);
|
||||
|
||||
// Entry/exit points
|
||||
@NotNull
|
||||
Label getEntryPoint(@NotNull JetElement labelElement);
|
||||
|
||||
@@ -239,4 +239,14 @@ public abstract class JetControlFlowBuilderAdapter implements JetControlFlowBuil
|
||||
public void mark(@NotNull JetElement 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;
|
||||
for (JetCatchClause catchClause : catchClauses) {
|
||||
builder.enterLexicalScope(catchClause);
|
||||
if (!isFirst) {
|
||||
builder.bindLabel(catchLabels.remove());
|
||||
}
|
||||
@@ -523,6 +524,7 @@ public class JetControlFlowProcessor {
|
||||
generateInstructions(catchBody, NOT_IN_CONDITION);
|
||||
}
|
||||
builder.jump(afterCatches);
|
||||
builder.exitLexicalScope(catchClause);
|
||||
}
|
||||
|
||||
builder.bindLabel(afterCatches);
|
||||
@@ -578,6 +580,7 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@Override
|
||||
public void visitDoWhileExpressionVoid(@NotNull JetDoWhileExpression expression, CFPContext context) {
|
||||
builder.enterLexicalScope(expression);
|
||||
mark(expression);
|
||||
LoopInfo loopInfo = builder.enterLoop(expression, null, null);
|
||||
|
||||
@@ -594,10 +597,12 @@ public class JetControlFlowProcessor {
|
||||
builder.jumpOnTrue(loopInfo.getEntryPoint());
|
||||
builder.exitLoop(expression);
|
||||
builder.loadUnit(expression);
|
||||
builder.exitLexicalScope(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitForExpressionVoid(@NotNull JetForExpression expression, CFPContext context) {
|
||||
builder.enterLexicalScope(expression);
|
||||
mark(expression);
|
||||
JetExpression loopRange = expression.getLoopRange();
|
||||
if (loopRange != null) {
|
||||
@@ -630,6 +635,7 @@ public class JetControlFlowProcessor {
|
||||
builder.nondeterministicJump(loopInfo.getEntryPoint());
|
||||
builder.exitLoop(expression);
|
||||
builder.loadUnit(expression);
|
||||
builder.exitLexicalScope(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -731,6 +737,10 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@Override
|
||||
public void visitBlockExpressionVoid(@NotNull JetBlockExpression expression, CFPContext context) {
|
||||
boolean declareLexicalScope = !isBlockInDoWhile(expression);
|
||||
if (declareLexicalScope) {
|
||||
builder.enterLexicalScope(expression);
|
||||
}
|
||||
mark(expression);
|
||||
List<JetElement> statements = expression.getStatements();
|
||||
for (JetElement statement : statements) {
|
||||
@@ -739,6 +749,15 @@ public class JetControlFlowProcessor {
|
||||
if (statements.isEmpty()) {
|
||||
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
|
||||
|
||||
+5
-4
@@ -26,7 +26,8 @@ public abstract class AbstractJumpInstruction extends InstructionImpl {
|
||||
private final Label targetLabel;
|
||||
private Instruction resolvedTarget;
|
||||
|
||||
public AbstractJumpInstruction(Label targetLabel) {
|
||||
public AbstractJumpInstruction(Label targetLabel, LexicalScope lexicalScope) {
|
||||
super(lexicalScope);
|
||||
this.targetLabel = targetLabel;
|
||||
}
|
||||
|
||||
@@ -48,15 +49,15 @@ public abstract class AbstractJumpInstruction extends InstructionImpl {
|
||||
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) {
|
||||
return updateCopyInfo(createCopy(newLabel));
|
||||
return updateCopyInfo(createCopy(newLabel, lexicalScope));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
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 nextOnFalse;
|
||||
|
||||
public ConditionalJumpInstruction(boolean onTrue, Label targetLabel) {
|
||||
super(targetLabel);
|
||||
public ConditionalJumpInstruction(boolean onTrue, LexicalScope lexicalScope, Label targetLabel) {
|
||||
super(targetLabel, lexicalScope);
|
||||
this.onTrue = onTrue;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class ConditionalJumpInstruction extends AbstractJumpInstruction {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||
return new ConditionalJumpInstruction(onTrue, newLabel);
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||
return new ConditionalJumpInstruction(onTrue, lexicalScope, newLabel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,7 @@ public interface Instruction {
|
||||
|
||||
@NotNull
|
||||
Collection<Instruction> getCopies();
|
||||
|
||||
@NotNull
|
||||
LexicalScope getLexicalScope();
|
||||
}
|
||||
|
||||
@@ -27,10 +27,13 @@ public abstract class InstructionImpl implements Instruction {
|
||||
private Pseudocode owner;
|
||||
private final Collection<Instruction> previousInstructions = new LinkedHashSet<Instruction>();
|
||||
private final Collection<Instruction> copies = Sets.newHashSet();
|
||||
@NotNull
|
||||
protected final LexicalScope lexicalScope;
|
||||
private Instruction original;
|
||||
protected boolean isDead = false;
|
||||
|
||||
protected InstructionImpl() {
|
||||
protected InstructionImpl(@NotNull LexicalScope lexicalScope) {
|
||||
this.lexicalScope = lexicalScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,6 +99,12 @@ public abstract class InstructionImpl implements Instruction {
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public LexicalScope getLexicalScope() {
|
||||
return lexicalScope;
|
||||
}
|
||||
|
||||
protected Instruction updateCopyInfo(@NotNull Instruction instruction) {
|
||||
addCopy(instruction);
|
||||
((InstructionImpl)instruction).setOriginal(this);
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ import java.util.Collections;
|
||||
public abstract class InstructionWithNext extends JetElementInstructionImpl {
|
||||
private Instruction next;
|
||||
|
||||
protected InstructionWithNext(@NotNull JetElement element) {
|
||||
super(element);
|
||||
protected InstructionWithNext(@NotNull JetElement element, @NotNull LexicalScope lexicalScope) {
|
||||
super(element, lexicalScope);
|
||||
}
|
||||
|
||||
public Instruction getNext() {
|
||||
|
||||
+48
-24
@@ -36,6 +36,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
private JetControlFlowBuilder builder = null;
|
||||
|
||||
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 int labelCount = 0;
|
||||
private int allowDeadLabelCount = 0;
|
||||
@@ -76,6 +77,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
pushBuilder(subroutine, subroutine);
|
||||
}
|
||||
assert builder != null;
|
||||
builder.enterLexicalScope(subroutine);
|
||||
builder.enterSubroutine(subroutine);
|
||||
}
|
||||
|
||||
@@ -83,6 +85,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
@Override
|
||||
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
|
||||
super.exitSubroutine(subroutine);
|
||||
builder.exitLexicalScope(subroutine);
|
||||
JetControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine);
|
||||
if (!builders.empty()) {
|
||||
JetControlFlowInstructionsGeneratorWorker builder = builders.peek();
|
||||
@@ -163,7 +166,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
elementToBlockInfo.put(subroutine, blockInfo);
|
||||
allBlocks.push(blockInfo);
|
||||
bindLabel(entryPoint);
|
||||
add(new SubroutineEnterInstruction(subroutine));
|
||||
add(new SubroutineEnterInstruction(subroutine, getCurrentScope()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -191,7 +194,28 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
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) {
|
||||
List<TryFinallyBlockInfo> finallyBlocks = new ArrayList<TryFinallyBlockInfo>();
|
||||
@@ -219,11 +243,11 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
@Override
|
||||
public Pseudocode exitSubroutine(@NotNull JetElement subroutine) {
|
||||
bindLabel(getExitPoint(subroutine));
|
||||
pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, false));
|
||||
pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, getCurrentScope(), false));
|
||||
bindLabel(error);
|
||||
pseudocode.addErrorInstruction(new SubroutineExitInstruction(subroutine, true));
|
||||
pseudocode.addErrorInstruction(new SubroutineExitInstruction(subroutine, getCurrentScope(), true));
|
||||
bindLabel(sink);
|
||||
pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, "<SINK>"));
|
||||
pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, getCurrentScope(), "<SINK>"));
|
||||
elementToBlockInfo.remove(subroutine);
|
||||
allBlocks.pop();
|
||||
return pseudocode;
|
||||
@@ -231,64 +255,64 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
|
||||
@Override
|
||||
public void mark(@NotNull JetElement element) {
|
||||
add(new MarkInstruction(element));
|
||||
add(new MarkInstruction(element, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine) {
|
||||
Label exitPoint = getExitPoint(subroutine);
|
||||
handleJumpInsideTryFinally(exitPoint);
|
||||
add(new ReturnValueInstruction(returnExpression, exitPoint));
|
||||
add(new ReturnValueInstruction(returnExpression, getCurrentScope(), exitPoint));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine) {
|
||||
Label exitPoint = getExitPoint(subroutine);
|
||||
handleJumpInsideTryFinally(exitPoint);
|
||||
add(new ReturnNoValueInstruction(returnExpression, exitPoint));
|
||||
add(new ReturnNoValueInstruction(returnExpression, getCurrentScope(), exitPoint));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull JetElement assignment, @NotNull JetElement lValue) {
|
||||
add(new WriteValueInstruction(assignment, lValue));
|
||||
add(new WriteValueInstruction(assignment, lValue, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void declareParameter(@NotNull JetParameter parameter) {
|
||||
add(new VariableDeclarationInstruction(parameter));
|
||||
add(new VariableDeclarationInstruction(parameter, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void declareVariable(@NotNull JetVariableDeclaration property) {
|
||||
add(new VariableDeclarationInstruction(property));
|
||||
add(new VariableDeclarationInstruction(property, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void declareFunction(@NotNull JetElement subroutine, @NotNull Pseudocode pseudocode) {
|
||||
add(new LocalFunctionDeclarationInstruction(subroutine, pseudocode));
|
||||
add(new LocalFunctionDeclarationInstruction(subroutine, pseudocode, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUnit(@NotNull JetExpression expression) {
|
||||
add(new LoadUnitValueInstruction(expression));
|
||||
add(new LoadUnitValueInstruction(expression, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jump(@NotNull Label label) {
|
||||
handleJumpInsideTryFinally(label);
|
||||
add(new UnconditionalJumpInstruction(label));
|
||||
add(new UnconditionalJumpInstruction(label, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jumpOnFalse(@NotNull Label label) {
|
||||
handleJumpInsideTryFinally(label);
|
||||
add(new ConditionalJumpInstruction(false, label));
|
||||
add(new ConditionalJumpInstruction(false, getCurrentScope(), label));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jumpOnTrue(@NotNull Label label) {
|
||||
handleJumpInsideTryFinally(label);
|
||||
add(new ConditionalJumpInstruction(true, label));
|
||||
add(new ConditionalJumpInstruction(true, getCurrentScope(), label));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -299,20 +323,20 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
@Override
|
||||
public void nondeterministicJump(@NotNull Label label) {
|
||||
handleJumpInsideTryFinally(label);
|
||||
add(new NondeterministicJumpInstruction(label));
|
||||
add(new NondeterministicJumpInstruction(label, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nondeterministicJump(@NotNull List<Label> labels) {
|
||||
//todo
|
||||
//handleJumpInsideTryFinally(label);
|
||||
add(new NondeterministicJumpInstruction(labels));
|
||||
add(new NondeterministicJumpInstruction(labels, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jumpToError() {
|
||||
handleJumpInsideTryFinally(error);
|
||||
add(new UnconditionalJumpInstruction(error));
|
||||
add(new UnconditionalJumpInstruction(error, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -323,7 +347,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
@Override
|
||||
public void throwException(@NotNull JetThrowExpression expression) {
|
||||
handleJumpInsideTryFinally(error);
|
||||
add(new ThrowExceptionInstruction(expression, error));
|
||||
add(new ThrowExceptionInstruction(expression, getCurrentScope(), error));
|
||||
}
|
||||
|
||||
public void exitTryFinally() {
|
||||
@@ -333,7 +357,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
|
||||
@Override
|
||||
public void unsupported(JetElement element) {
|
||||
add(new UnsupportedElementInstruction(element));
|
||||
add(new UnsupportedElementInstruction(element, getCurrentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -373,7 +397,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
|
||||
@Override
|
||||
public void call(@NotNull JetExpression expression, @NotNull ResolvedCall<?> resolvedCall) {
|
||||
add(new CallInstruction(expression, resolvedCall));
|
||||
add(new CallInstruction(expression, getCurrentScope(), resolvedCall));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -383,11 +407,11 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
|
||||
@Override
|
||||
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) {
|
||||
add(new ReadValueInstruction(element));
|
||||
add(new ReadValueInstruction(element, getCurrentScope()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -24,7 +24,8 @@ public abstract class JetElementInstructionImpl extends InstructionImpl implemen
|
||||
@NotNull
|
||||
protected final JetElement element;
|
||||
|
||||
public JetElementInstructionImpl(@NotNull JetElement element) {
|
||||
public JetElementInstructionImpl(@NotNull JetElement element, LexicalScope lexicalScope) {
|
||||
super(lexicalScope);
|
||||
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 LoadUnitValueInstruction(@NotNull JetExpression expression) {
|
||||
super(expression);
|
||||
public LoadUnitValueInstruction(@NotNull JetExpression expression, LexicalScope lexicalScope) {
|
||||
super(expression, lexicalScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +43,6 @@ public class LoadUnitValueInstruction extends InstructionWithNext {
|
||||
@NotNull
|
||||
@Override
|
||||
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 Instruction sink;
|
||||
|
||||
public LocalFunctionDeclarationInstruction(@NotNull JetElement element, @NotNull Pseudocode body) {
|
||||
super(element);
|
||||
public LocalFunctionDeclarationInstruction(@NotNull JetElement element, @NotNull Pseudocode body, LexicalScope lexicalScope) {
|
||||
super(element, lexicalScope);
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,6 @@ public class LocalFunctionDeclarationInstruction extends InstructionWithNext {
|
||||
@NotNull
|
||||
@Override
|
||||
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 Map<Label, Instruction> resolvedTargets;
|
||||
|
||||
public NondeterministicJumpInstruction(List<Label> targetLabels) {
|
||||
public NondeterministicJumpInstruction(List<Label> targetLabels, LexicalScope lexicalScope) {
|
||||
super(lexicalScope);
|
||||
this.targetLabels = Lists.newArrayList(targetLabels);
|
||||
resolvedTargets = Maps.newLinkedHashMap();
|
||||
}
|
||||
|
||||
public NondeterministicJumpInstruction(Label targetLabel) {
|
||||
this(Lists.newArrayList(targetLabel));
|
||||
public NondeterministicJumpInstruction(Label targetLabel, LexicalScope lexicalScope) {
|
||||
this(Lists.newArrayList(targetLabel), lexicalScope);
|
||||
}
|
||||
|
||||
public List<Label> getTargetLabels() {
|
||||
@@ -102,6 +103,6 @@ public class NondeterministicJumpInstruction extends InstructionImpl{
|
||||
}
|
||||
|
||||
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 ReadValueInstruction(@NotNull JetElement element) {
|
||||
super(element);
|
||||
public ReadValueInstruction(@NotNull JetElement element, @NotNull LexicalScope lexicalScope) {
|
||||
super(element, lexicalScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +43,6 @@ public class ReadValueInstruction extends InstructionWithNext {
|
||||
@NotNull
|
||||
@Override
|
||||
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;
|
||||
|
||||
public ReturnNoValueInstruction(@NotNull JetElement element, Label targetLabel) {
|
||||
super(targetLabel);
|
||||
public ReturnNoValueInstruction(@NotNull JetElement element, LexicalScope lexicalScope, Label targetLabel) {
|
||||
super(targetLabel, lexicalScope);
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ReturnNoValueInstruction extends AbstractJumpInstruction implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||
return new ReturnNoValueInstruction(element, newLabel);
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||
return new ReturnNoValueInstruction(element, lexicalScope, newLabel);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -25,8 +25,8 @@ public class ReturnValueInstruction extends AbstractJumpInstruction implements R
|
||||
|
||||
private final JetElement element;
|
||||
|
||||
public ReturnValueInstruction(@NotNull JetExpression returnExpression, @NotNull Label targetLabel) {
|
||||
super(targetLabel);
|
||||
public ReturnValueInstruction(@NotNull JetExpression returnExpression, @NotNull LexicalScope lexicalScope, @NotNull Label targetLabel) {
|
||||
super(targetLabel, lexicalScope);
|
||||
this.element = returnExpression;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ReturnValueInstruction extends AbstractJumpInstruction implements R
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||
return new ReturnValueInstruction((JetExpression) element, newLabel);
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||
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 {
|
||||
private final JetElement subroutine;
|
||||
|
||||
public SubroutineEnterInstruction(@NotNull JetElement subroutine) {
|
||||
super(subroutine);
|
||||
public SubroutineEnterInstruction(@NotNull JetElement subroutine, @NotNull LexicalScope lexicalScope) {
|
||||
super(subroutine, lexicalScope);
|
||||
this.subroutine = subroutine;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,6 @@ public class SubroutineEnterInstruction extends InstructionWithNext {
|
||||
@NotNull
|
||||
@Override
|
||||
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 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.isError = isError;
|
||||
}
|
||||
@@ -69,6 +70,6 @@ public class SubroutineExitInstruction extends InstructionImpl {
|
||||
@NotNull
|
||||
@Override
|
||||
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 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.debugLabel = debugLabel;
|
||||
}
|
||||
@@ -59,6 +60,6 @@ public class SubroutineSinkInstruction extends InstructionImpl {
|
||||
@NotNull
|
||||
@Override
|
||||
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 {
|
||||
private final JetThrowExpression expression;
|
||||
|
||||
public ThrowExceptionInstruction(@NotNull JetThrowExpression expression, @NotNull Label errorLabel) {
|
||||
super(errorLabel);
|
||||
public ThrowExceptionInstruction(@NotNull JetThrowExpression expression, @NotNull LexicalScope lexicalScope, @NotNull Label errorLabel) {
|
||||
super(errorLabel, lexicalScope);
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ThrowExceptionInstruction extends AbstractJumpInstruction implement
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||
return new ThrowExceptionInstruction(expression, newLabel);
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||
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 UnconditionalJumpInstruction(Label targetLabel) {
|
||||
super(targetLabel);
|
||||
public UnconditionalJumpInstruction(Label targetLabel, @NotNull LexicalScope lexicalScope) {
|
||||
super(targetLabel, lexicalScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +42,7 @@ public class UnconditionalJumpInstruction extends AbstractJumpInstruction {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||
return new UnconditionalJumpInstruction(newLabel);
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel, @NotNull LexicalScope lexicalScope) {
|
||||
return new UnconditionalJumpInstruction(newLabel, lexicalScope);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -21,8 +21,8 @@ import org.jetbrains.jet.lang.psi.JetElement;
|
||||
|
||||
public class UnsupportedElementInstruction extends InstructionWithNext {
|
||||
|
||||
protected UnsupportedElementInstruction(@NotNull JetElement element) {
|
||||
super(element);
|
||||
protected UnsupportedElementInstruction(@NotNull JetElement element, @NotNull LexicalScope lexicalScope) {
|
||||
super(element, lexicalScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +43,6 @@ public class UnsupportedElementInstruction extends InstructionWithNext {
|
||||
@NotNull
|
||||
@Override
|
||||
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;
|
||||
|
||||
public class VariableDeclarationInstruction extends InstructionWithNext {
|
||||
protected VariableDeclarationInstruction(@NotNull JetParameter element) {
|
||||
super(element);
|
||||
protected VariableDeclarationInstruction(@NotNull JetParameter element, @NotNull LexicalScope lexicalScope) {
|
||||
super(element, lexicalScope);
|
||||
}
|
||||
|
||||
protected VariableDeclarationInstruction(@NotNull JetVariableDeclaration element) {
|
||||
super(element);
|
||||
protected VariableDeclarationInstruction(@NotNull JetVariableDeclaration element, @NotNull LexicalScope lexicalScope) {
|
||||
super(element, lexicalScope);
|
||||
}
|
||||
|
||||
public JetDeclaration getVariableDeclarationElement() {
|
||||
@@ -53,8 +53,8 @@ public class VariableDeclarationInstruction extends InstructionWithNext {
|
||||
@Override
|
||||
protected Instruction createCopy() {
|
||||
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
|
||||
private final JetElement lValue;
|
||||
|
||||
public WriteValueInstruction(@NotNull JetElement assignment, @NotNull JetElement lValue) {
|
||||
super(assignment);
|
||||
public WriteValueInstruction(@NotNull JetElement assignment, @NotNull JetElement lValue, @NotNull LexicalScope lexicalScope) {
|
||||
super(assignment, lexicalScope);
|
||||
this.lValue = lValue;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,6 @@ public class WriteValueInstruction extends InstructionWithNext {
|
||||
@NotNull
|
||||
@Override
|
||||
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(
|
||||
element: JetElement,
|
||||
lexicalScope: LexicalScope,
|
||||
val resolvedCall: ResolvedCall<*>
|
||||
) : InstructionWithNext(element) {
|
||||
) : InstructionWithNext(element, lexicalScope) {
|
||||
|
||||
override fun accept(visitor: InstructionVisitor) {
|
||||
visitor.visitCallInstruction(this)
|
||||
@@ -33,15 +34,16 @@ class CallInstruction(
|
||||
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()})"
|
||||
}
|
||||
|
||||
class CompilationErrorInstruction(
|
||||
element: JetElement,
|
||||
lexicalScope: LexicalScope,
|
||||
val message: String
|
||||
) : InstructionWithNext(element) {
|
||||
) : InstructionWithNext(element, lexicalScope) {
|
||||
|
||||
override fun accept(visitor: InstructionVisitor) {
|
||||
visitor.visitCompilationErrorInstruction(this)
|
||||
@@ -51,7 +53,7 @@ class CompilationErrorInstruction(
|
||||
return visitor.visitCompilationErrorInstruction(this)
|
||||
}
|
||||
|
||||
override fun createCopy() = CompilationErrorInstruction(element, message)
|
||||
override fun createCopy() = CompilationErrorInstruction(element, lexicalScope, 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
|
||||
// e.g. for (i in foo) {} -- only i and foo would be marked unreachable
|
||||
class MarkInstruction(
|
||||
element: JetElement
|
||||
) : InstructionWithNext(element) {
|
||||
element: JetElement,
|
||||
lexicalScope: LexicalScope
|
||||
) : InstructionWithNext(element, lexicalScope) {
|
||||
|
||||
override fun accept(visitor: InstructionVisitor) {
|
||||
visitor.visitMarkInstruction(this)
|
||||
@@ -71,7 +74,7 @@ class MarkInstruction(
|
||||
return visitor.visitMarkInstruction(this)
|
||||
}
|
||||
|
||||
override fun createCopy() = MarkInstruction(element)
|
||||
override fun createCopy() = MarkInstruction(element, lexicalScope)
|
||||
|
||||
override fun toString() = "mark(${render(element)})"
|
||||
}
|
||||
Reference in New Issue
Block a user