Removed CFPContext

flag 'inCondition' became unused
This commit is contained in:
Svetlana Isakova
2014-06-20 18:52:30 +04:00
parent 9d4aad3bbc
commit d150bfbce0
@@ -52,8 +52,6 @@ import org.jetbrains.jet.lexer.JetTokens;
import java.util.*; import java.util.*;
import static org.jetbrains.jet.lang.cfg.JetControlFlowBuilder.PredefinedOperation.*; import static org.jetbrains.jet.lang.cfg.JetControlFlowBuilder.PredefinedOperation.*;
import static org.jetbrains.jet.lang.cfg.JetControlFlowProcessor.CFPContext.IN_CONDITION;
import static org.jetbrains.jet.lang.cfg.JetControlFlowProcessor.CFPContext.NOT_IN_CONDITION;
import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lexer.JetTokens.*; import static org.jetbrains.jet.lexer.JetTokens.*;
@@ -82,14 +80,14 @@ public class JetControlFlowProcessor {
JetDeclarationWithBody declarationWithBody = (JetDeclarationWithBody) subroutine; JetDeclarationWithBody declarationWithBody = (JetDeclarationWithBody) subroutine;
List<JetParameter> valueParameters = declarationWithBody.getValueParameters(); List<JetParameter> valueParameters = declarationWithBody.getValueParameters();
for (JetParameter valueParameter : valueParameters) { for (JetParameter valueParameter : valueParameters) {
cfpVisitor.generateInstructions(valueParameter, NOT_IN_CONDITION); cfpVisitor.generateInstructions(valueParameter);
} }
JetExpression bodyExpression = declarationWithBody.getBodyExpression(); JetExpression bodyExpression = declarationWithBody.getBodyExpression();
if (bodyExpression != null) { if (bodyExpression != null) {
cfpVisitor.generateInstructions(bodyExpression, NOT_IN_CONDITION); cfpVisitor.generateInstructions(bodyExpression);
} }
} else { } else {
cfpVisitor.generateInstructions(subroutine, NOT_IN_CONDITION); cfpVisitor.generateInstructions(subroutine);
} }
return builder.exitSubroutine(subroutine); return builder.exitSubroutine(subroutine);
} }
@@ -105,48 +103,33 @@ public class JetControlFlowProcessor {
builder.bindLabel(afterDeclaration); builder.bindLabel(afterDeclaration);
} }
/*package*/ enum CFPContext { private class CFPVisitor extends JetVisitorVoid {
IN_CONDITION(true),
NOT_IN_CONDITION(false);
private final boolean inCondition;
private CFPContext(boolean inCondition) {
this.inCondition = inCondition;
}
public boolean inCondition() {
return inCondition;
}
}
private class CFPVisitor extends JetVisitorVoidWithParameter<CFPContext> {
private final JetControlFlowBuilder builder; private final JetControlFlowBuilder builder;
private final JetVisitorVoidWithParameter<CFPContext> conditionVisitor = new JetVisitorVoidWithParameter<CFPContext>() { private final JetVisitorVoid conditionVisitor = new JetVisitorVoid() {
@Override @Override
public void visitWhenConditionInRangeVoid(@NotNull JetWhenConditionInRange condition, CFPContext context) { public void visitWhenConditionInRange(@NotNull JetWhenConditionInRange condition) {
generateInstructions(condition.getRangeExpression(), context); generateInstructions(condition.getRangeExpression());
generateInstructions(condition.getOperationReference(), context); generateInstructions(condition.getOperationReference());
// TODO : read the call to contains()... // TODO : read the call to contains()...
createNonSyntheticValue(condition, condition.getRangeExpression(), condition.getOperationReference()); createNonSyntheticValue(condition, condition.getRangeExpression(), condition.getOperationReference());
} }
@Override @Override
public void visitWhenConditionIsPatternVoid(@NotNull JetWhenConditionIsPattern condition, CFPContext context) { public void visitWhenConditionIsPattern(@NotNull JetWhenConditionIsPattern condition) {
// TODO: types in CF? // TODO: types in CF?
} }
@Override @Override
public void visitWhenConditionWithExpressionVoid(@NotNull JetWhenConditionWithExpression condition, CFPContext context) { public void visitWhenConditionWithExpression(@NotNull JetWhenConditionWithExpression condition) {
generateInstructions(condition.getExpression(), context); generateInstructions(condition.getExpression());
copyValue(condition.getExpression(), condition); copyValue(condition.getExpression(), condition);
} }
@Override @Override
public void visitJetElementVoid(@NotNull JetElement element, CFPContext context) { public void visitJetElement(@NotNull JetElement element) {
throw new UnsupportedOperationException("[JetControlFlowProcessor] " + element.toString()); throw new UnsupportedOperationException("[JetControlFlowProcessor] " + element.toString());
} }
}; };
@@ -159,9 +142,9 @@ public class JetControlFlowProcessor {
builder.mark(element); builder.mark(element);
} }
public void generateInstructions(@Nullable JetElement element, CFPContext context) { public void generateInstructions(@Nullable JetElement element) {
if (element == null) return; if (element == null) return;
element.accept(this, context); element.accept(this);
checkNothingType(element); checkNothingType(element);
} }
@@ -265,26 +248,26 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitParenthesizedExpressionVoid(@NotNull JetParenthesizedExpression expression, CFPContext context) { public void visitParenthesizedExpression(@NotNull JetParenthesizedExpression expression) {
mark(expression); mark(expression);
JetExpression innerExpression = expression.getExpression(); JetExpression innerExpression = expression.getExpression();
if (innerExpression != null) { if (innerExpression != null) {
generateInstructions(innerExpression, context); generateInstructions(innerExpression);
copyValue(innerExpression, expression); copyValue(innerExpression, expression);
} }
} }
@Override @Override
public void visitAnnotatedExpressionVoid(@NotNull JetAnnotatedExpression expression, CFPContext context) { public void visitAnnotatedExpression(@NotNull JetAnnotatedExpression expression) {
JetExpression baseExpression = expression.getBaseExpression(); JetExpression baseExpression = expression.getBaseExpression();
if (baseExpression != null) { if (baseExpression != null) {
generateInstructions(baseExpression, context); generateInstructions(baseExpression);
copyValue(baseExpression, expression); copyValue(baseExpression, expression);
} }
} }
@Override @Override
public void visitThisExpressionVoid(@NotNull JetThisExpression expression, CFPContext context) { public void visitThisExpression(@NotNull JetThisExpression expression) {
ResolvedCall<?> resolvedCall = getResolvedCall(expression); ResolvedCall<?> resolvedCall = getResolvedCall(expression);
if (resolvedCall == null) { if (resolvedCall == null) {
createNonSyntheticValue(expression); createNonSyntheticValue(expression);
@@ -300,13 +283,13 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitConstantExpressionVoid(@NotNull JetConstantExpression expression, CFPContext context) { public void visitConstantExpression(@NotNull JetConstantExpression expression) {
CompileTimeConstant<?> constant = trace.get(BindingContext.COMPILE_TIME_VALUE, expression); CompileTimeConstant<?> constant = trace.get(BindingContext.COMPILE_TIME_VALUE, expression);
builder.loadConstant(expression, constant); builder.loadConstant(expression, constant);
} }
@Override @Override
public void visitSimpleNameExpressionVoid(@NotNull JetSimpleNameExpression expression, CFPContext context) { public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) {
ResolvedCall<?> resolvedCall = getResolvedCall(expression); ResolvedCall<?> resolvedCall = getResolvedCall(expression);
if (resolvedCall instanceof VariableAsFunctionResolvedCall) { if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall; VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall;
@@ -318,18 +301,18 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitLabeledExpressionVoid(@NotNull JetLabeledExpression expression, CFPContext context) { public void visitLabeledExpression(@NotNull JetLabeledExpression expression) {
mark(expression); mark(expression);
JetExpression baseExpression = expression.getBaseExpression(); JetExpression baseExpression = expression.getBaseExpression();
if (baseExpression != null) { if (baseExpression != null) {
generateInstructions(baseExpression, context); generateInstructions(baseExpression);
copyValue(baseExpression, expression); copyValue(baseExpression, expression);
} }
} }
@SuppressWarnings("SuspiciousMethodCalls") @SuppressWarnings("SuspiciousMethodCalls")
@Override @Override
public void visitBinaryExpressionVoid(@NotNull JetBinaryExpression expression, CFPContext context) { public void visitBinaryExpression(@NotNull JetBinaryExpression expression) {
JetSimpleNameExpression operationReference = expression.getOperationReference(); JetSimpleNameExpression operationReference = expression.getOperationReference();
IElementType operationType = operationReference.getReferencedNameElementType(); IElementType operationType = operationReference.getReferencedNameElementType();
@@ -364,12 +347,12 @@ public class JetControlFlowProcessor {
} }
} }
else if (operationType == ELVIS) { else if (operationType == ELVIS) {
generateInstructions(left, NOT_IN_CONDITION); generateInstructions(left);
mark(expression); mark(expression);
Label afterElvis = builder.createUnboundLabel(); Label afterElvis = builder.createUnboundLabel();
builder.jumpOnTrue(afterElvis, expression, builder.getBoundValue(left)); builder.jumpOnTrue(afterElvis, expression, builder.getBoundValue(left));
if (right != null) { if (right != null) {
generateInstructions(right, NOT_IN_CONDITION); generateInstructions(right);
} }
builder.bindLabel(afterElvis); builder.bindLabel(afterElvis);
mergeValues(Arrays.asList(left, right), expression); mergeValues(Arrays.asList(left, right), expression);
@@ -387,7 +370,7 @@ public class JetControlFlowProcessor {
JetExpression right = expression.getRight(); JetExpression right = expression.getRight();
Label resultLabel = builder.createUnboundLabel(); Label resultLabel = builder.createUnboundLabel();
generateInstructions(left, IN_CONDITION); generateInstructions(left);
if (operationType == ANDAND) { if (operationType == ANDAND) {
builder.jumpOnFalse(resultLabel, expression, builder.getBoundValue(left)); builder.jumpOnFalse(resultLabel, expression, builder.getBoundValue(left));
} }
@@ -395,7 +378,7 @@ public class JetControlFlowProcessor {
builder.jumpOnTrue(resultLabel, expression, builder.getBoundValue(left)); builder.jumpOnTrue(resultLabel, expression, builder.getBoundValue(left));
} }
if (right != null) { if (right != null) {
generateInstructions(right, IN_CONDITION); generateInstructions(right);
} }
builder.bindLabel(resultLabel); builder.bindLabel(resultLabel);
JetControlFlowBuilder.PredefinedOperation operation = operationType == ANDAND ? AND : OR; JetControlFlowBuilder.PredefinedOperation operation = operationType == ANDAND ? AND : OR;
@@ -415,7 +398,7 @@ public class JetControlFlowProcessor {
return new Function0<PseudoValue>() { return new Function0<PseudoValue>() {
@Override @Override
public PseudoValue invoke() { public PseudoValue invoke() {
generateInstructions(expression, NOT_IN_CONDITION); generateInstructions(expression);
return builder.getBoundValue(expression); return builder.getBoundValue(expression);
} }
}; };
@@ -424,11 +407,11 @@ public class JetControlFlowProcessor {
private void generateBothArgumentsAndMark(JetBinaryExpression expression) { private void generateBothArgumentsAndMark(JetBinaryExpression expression) {
JetExpression left = JetPsiUtil.deparenthesize(expression.getLeft()); JetExpression left = JetPsiUtil.deparenthesize(expression.getLeft());
if (left != null) { if (left != null) {
generateInstructions(left, NOT_IN_CONDITION); generateInstructions(left);
} }
JetExpression right = expression.getRight(); JetExpression right = expression.getRight();
if (right != null) { if (right != null) {
generateInstructions(right, NOT_IN_CONDITION); generateInstructions(right);
} }
createNonSyntheticValue(expression, left, right); createNonSyntheticValue(expression, left, right);
mark(expression); mark(expression);
@@ -488,7 +471,7 @@ public class JetControlFlowProcessor {
mark(lhs); mark(lhs);
} }
generateInstructions(lhs.getArrayExpression(), NOT_IN_CONDITION); generateInstructions(lhs.getArrayExpression());
Map<PseudoValue, ReceiverValue> receiverValues = getReceiverValues(lhs, setResolvedCall, false); Map<PseudoValue, ReceiverValue> receiverValues = getReceiverValues(lhs, setResolvedCall, false);
SmartFMap<PseudoValue, ValueParameterDescriptor> argumentValues = SmartFMap<PseudoValue, ValueParameterDescriptor> argumentValues =
@@ -571,10 +554,10 @@ public class JetControlFlowProcessor {
JetExpression arrayExpression = arrayAccessExpression.getArrayExpression(); JetExpression arrayExpression = arrayAccessExpression.getArrayExpression();
inputExpressions.add(arrayExpression); inputExpressions.add(arrayExpression);
generateInstructions(arrayExpression, NOT_IN_CONDITION); generateInstructions(arrayExpression);
for (JetExpression index : arrayAccessExpression.getIndexExpressions()) { for (JetExpression index : arrayAccessExpression.getIndexExpressions()) {
generateInstructions(index, NOT_IN_CONDITION); generateInstructions(index);
inputExpressions.add(index); inputExpressions.add(index);
} }
@@ -582,13 +565,13 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitUnaryExpressionVoid(@NotNull JetUnaryExpression expression, CFPContext context) { public void visitUnaryExpression(@NotNull JetUnaryExpression expression) {
JetSimpleNameExpression operationSign = expression.getOperationReference(); JetSimpleNameExpression operationSign = expression.getOperationReference();
IElementType operationType = operationSign.getReferencedNameElementType(); IElementType operationType = operationSign.getReferencedNameElementType();
JetExpression baseExpression = expression.getBaseExpression(); JetExpression baseExpression = expression.getBaseExpression();
if (baseExpression == null) return; if (baseExpression == null) return;
if (JetTokens.EXCLEXCL == operationType) { if (JetTokens.EXCLEXCL == operationType) {
generateInstructions(baseExpression, NOT_IN_CONDITION); generateInstructions(baseExpression);
builder.predefinedOperation(expression, NOT_NULL_ASSERTION, elementsToValues(Collections.singletonList(baseExpression))); builder.predefinedOperation(expression, NOT_NULL_ASSERTION, elementsToValues(Collections.singletonList(baseExpression)));
return; return;
} }
@@ -601,7 +584,7 @@ public class JetControlFlowProcessor {
rhsValue = generateCall(incrementOrDecrement ? null : expression, operationSign, resolvedCall).getOutputValue(); rhsValue = generateCall(incrementOrDecrement ? null : expression, operationSign, resolvedCall).getOutputValue();
} }
else { else {
generateInstructions(baseExpression, NOT_IN_CONDITION); generateInstructions(baseExpression);
rhsValue = createNonSyntheticValue(expression, baseExpression); rhsValue = createNonSyntheticValue(expression, baseExpression);
} }
@@ -615,19 +598,19 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitIfExpressionVoid(@NotNull JetIfExpression expression, CFPContext context) { public void visitIfExpression(@NotNull JetIfExpression expression) {
mark(expression); mark(expression);
List<JetExpression> branches = new ArrayList<JetExpression>(2); List<JetExpression> branches = new ArrayList<JetExpression>(2);
JetExpression condition = expression.getCondition(); JetExpression condition = expression.getCondition();
if (condition != null) { if (condition != null) {
generateInstructions(condition, IN_CONDITION); generateInstructions(condition);
} }
Label elseLabel = builder.createUnboundLabel(); Label elseLabel = builder.createUnboundLabel();
builder.jumpOnFalse(elseLabel, expression, builder.getBoundValue(condition)); builder.jumpOnFalse(elseLabel, expression, builder.getBoundValue(condition));
JetExpression thenBranch = expression.getThen(); JetExpression thenBranch = expression.getThen();
if (thenBranch != null) { if (thenBranch != null) {
branches.add(thenBranch); branches.add(thenBranch);
generateInstructions(thenBranch, context); generateInstructions(thenBranch);
} }
else { else {
builder.loadUnit(expression); builder.loadUnit(expression);
@@ -638,7 +621,7 @@ public class JetControlFlowProcessor {
JetExpression elseBranch = expression.getElse(); JetExpression elseBranch = expression.getElse();
if (elseBranch != null) { if (elseBranch != null) {
branches.add(elseBranch); branches.add(elseBranch);
generateInstructions(elseBranch, context); generateInstructions(elseBranch);
} }
else { else {
builder.loadUnit(expression); builder.loadUnit(expression);
@@ -649,13 +632,11 @@ public class JetControlFlowProcessor {
private class FinallyBlockGenerator { private class FinallyBlockGenerator {
private final JetFinallySection finallyBlock; private final JetFinallySection finallyBlock;
private final CFPContext context;
private Label startFinally = null; private Label startFinally = null;
private Label finishFinally = null; private Label finishFinally = null;
private FinallyBlockGenerator(JetFinallySection block, CFPContext context) { private FinallyBlockGenerator(JetFinallySection block) {
finallyBlock = block; finallyBlock = block;
this.context = context;
} }
public void generate() { public void generate() {
@@ -668,18 +649,18 @@ public class JetControlFlowProcessor {
} }
startFinally = builder.createUnboundLabel("start finally"); startFinally = builder.createUnboundLabel("start finally");
builder.bindLabel(startFinally); builder.bindLabel(startFinally);
generateInstructions(finalExpression, context); generateInstructions(finalExpression);
finishFinally = builder.createUnboundLabel("finish finally"); finishFinally = builder.createUnboundLabel("finish finally");
builder.bindLabel(finishFinally); builder.bindLabel(finishFinally);
} }
} }
@Override @Override
public void visitTryExpressionVoid(@NotNull JetTryExpression expression, CFPContext context) { public void visitTryExpression(@NotNull JetTryExpression expression) {
mark(expression); mark(expression);
JetFinallySection finallyBlock = expression.getFinallyBlock(); JetFinallySection finallyBlock = expression.getFinallyBlock();
final FinallyBlockGenerator finallyBlockGenerator = new FinallyBlockGenerator(finallyBlock, context); final FinallyBlockGenerator finallyBlockGenerator = new FinallyBlockGenerator(finallyBlock);
boolean hasFinally = finallyBlock != null; boolean hasFinally = finallyBlock != null;
if (hasFinally) { if (hasFinally) {
builder.enterTryFinally(new GenerationTrigger() { builder.enterTryFinally(new GenerationTrigger() {
@@ -696,7 +677,7 @@ public class JetControlFlowProcessor {
}); });
} }
Label onExceptionToFinallyBlock = generateTryAndCatches(expression, context); Label onExceptionToFinallyBlock = generateTryAndCatches(expression);
if (hasFinally) { if (hasFinally) {
assert onExceptionToFinallyBlock != null : "No finally lable generated: " + expression.getText(); assert onExceptionToFinallyBlock != null : "No finally lable generated: " + expression.getText();
@@ -723,7 +704,7 @@ public class JetControlFlowProcessor {
// Returns label for 'finally' block // Returns label for 'finally' block
@Nullable @Nullable
private Label generateTryAndCatches(@NotNull JetTryExpression expression, CFPContext context) { private Label generateTryAndCatches(@NotNull JetTryExpression expression) {
List<JetCatchClause> catchClauses = expression.getCatchClauses(); List<JetCatchClause> catchClauses = expression.getCatchClauses();
boolean hasCatches = !catchClauses.isEmpty(); boolean hasCatches = !catchClauses.isEmpty();
@@ -740,7 +721,7 @@ public class JetControlFlowProcessor {
} }
JetBlockExpression tryBlock = expression.getTryBlock(); JetBlockExpression tryBlock = expression.getTryBlock();
generateInstructions(tryBlock, context); generateInstructions(tryBlock);
if (hasCatches) { if (hasCatches) {
Label afterCatches = builder.createUnboundLabel("afterCatches"); Label afterCatches = builder.createUnboundLabel("afterCatches");
@@ -771,7 +752,7 @@ public class JetControlFlowProcessor {
} }
JetExpression catchBody = catchClause.getCatchBody(); JetExpression catchBody = catchClause.getCatchBody();
if (catchBody != null) { if (catchBody != null) {
generateInstructions(catchBody, NOT_IN_CONDITION); generateInstructions(catchBody);
} }
builder.jump(afterCatches, expression); builder.jump(afterCatches, expression);
builder.exitLexicalScope(catchClause); builder.exitLexicalScope(catchClause);
@@ -784,13 +765,13 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitWhileExpressionVoid(@NotNull JetWhileExpression expression, CFPContext context) { public void visitWhileExpression(@NotNull JetWhileExpression expression) {
LoopInfo loopInfo = builder.enterLoop(expression, null, null); LoopInfo loopInfo = builder.enterLoop(expression, null, null);
builder.bindLabel(loopInfo.getConditionEntryPoint()); builder.bindLabel(loopInfo.getConditionEntryPoint());
JetExpression condition = expression.getCondition(); JetExpression condition = expression.getCondition();
if (condition != null) { if (condition != null) {
generateInstructions(condition, IN_CONDITION); generateInstructions(condition);
} }
mark(expression); mark(expression);
boolean conditionIsTrueConstant = CompileTimeConstantUtils.canBeReducedToBooleanConstant(condition, trace, true); boolean conditionIsTrueConstant = CompileTimeConstantUtils.canBeReducedToBooleanConstant(condition, trace, true);
@@ -801,7 +782,7 @@ public class JetControlFlowProcessor {
builder.bindLabel(loopInfo.getBodyEntryPoint()); builder.bindLabel(loopInfo.getBodyEntryPoint());
JetExpression body = expression.getBody(); JetExpression body = expression.getBody();
if (body != null) { if (body != null) {
generateInstructions(body, NOT_IN_CONDITION); generateInstructions(body);
} }
builder.jump(loopInfo.getEntryPoint(), expression); builder.jump(loopInfo.getEntryPoint(), expression);
builder.exitLoop(expression); builder.exitLoop(expression);
@@ -809,7 +790,7 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitDoWhileExpressionVoid(@NotNull JetDoWhileExpression expression, CFPContext context) { public void visitDoWhileExpression(@NotNull JetDoWhileExpression expression) {
builder.enterLexicalScope(expression); builder.enterLexicalScope(expression);
mark(expression); mark(expression);
LoopInfo loopInfo = builder.enterLoop(expression, null, null); LoopInfo loopInfo = builder.enterLoop(expression, null, null);
@@ -817,12 +798,12 @@ public class JetControlFlowProcessor {
builder.bindLabel(loopInfo.getBodyEntryPoint()); builder.bindLabel(loopInfo.getBodyEntryPoint());
JetExpression body = expression.getBody(); JetExpression body = expression.getBody();
if (body != null) { if (body != null) {
generateInstructions(body, NOT_IN_CONDITION); generateInstructions(body);
} }
builder.bindLabel(loopInfo.getConditionEntryPoint()); builder.bindLabel(loopInfo.getConditionEntryPoint());
JetExpression condition = expression.getCondition(); JetExpression condition = expression.getCondition();
if (condition != null) { if (condition != null) {
generateInstructions(condition, IN_CONDITION); generateInstructions(condition);
} }
builder.jumpOnTrue(loopInfo.getEntryPoint(), expression, builder.getBoundValue(condition)); builder.jumpOnTrue(loopInfo.getEntryPoint(), expression, builder.getBoundValue(condition));
builder.exitLoop(expression); builder.exitLoop(expression);
@@ -831,12 +812,12 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitForExpressionVoid(@NotNull JetForExpression expression, CFPContext context) { public void visitForExpression(@NotNull JetForExpression expression) {
builder.enterLexicalScope(expression); builder.enterLexicalScope(expression);
JetExpression loopRange = expression.getLoopRange(); JetExpression loopRange = expression.getLoopRange();
if (loopRange != null) { if (loopRange != null) {
generateInstructions(loopRange, NOT_IN_CONDITION); generateInstructions(loopRange);
} }
declareLoopParameter(expression); declareLoopParameter(expression);
@@ -855,7 +836,7 @@ public class JetControlFlowProcessor {
mark(expression); mark(expression);
JetExpression body = expression.getBody(); JetExpression body = expression.getBody();
if (body != null) { if (body != null) {
generateInstructions(body, NOT_IN_CONDITION); generateInstructions(body);
} }
builder.nondeterministicJump(loopInfo.getEntryPoint(), expression, null); builder.nondeterministicJump(loopInfo.getEntryPoint(), expression, null);
@@ -904,7 +885,7 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitBreakExpressionVoid(@NotNull JetBreakExpression expression, CFPContext context) { public void visitBreakExpression(@NotNull JetBreakExpression expression) {
JetElement loop = getCorrespondingLoop(expression); JetElement loop = getCorrespondingLoop(expression);
if (loop != null) { if (loop != null) {
checkJumpDoesNotCrossFunctionBoundary(expression, loop); checkJumpDoesNotCrossFunctionBoundary(expression, loop);
@@ -913,7 +894,7 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitContinueExpressionVoid(@NotNull JetContinueExpression expression, CFPContext context) { public void visitContinueExpression(@NotNull JetContinueExpression expression) {
JetElement loop = getCorrespondingLoop(expression); JetElement loop = getCorrespondingLoop(expression);
if (loop != null) { if (loop != null) {
checkJumpDoesNotCrossFunctionBoundary(expression, loop); checkJumpDoesNotCrossFunctionBoundary(expression, loop);
@@ -956,10 +937,10 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitReturnExpressionVoid(@NotNull JetReturnExpression expression, CFPContext context) { public void visitReturnExpression(@NotNull JetReturnExpression expression) {
JetExpression returnedExpression = expression.getReturnedExpression(); JetExpression returnedExpression = expression.getReturnedExpression();
if (returnedExpression != null) { if (returnedExpression != null) {
generateInstructions(returnedExpression, NOT_IN_CONDITION); generateInstructions(returnedExpression);
} }
JetSimpleNameExpression labelElement = expression.getTargetLabel(); JetSimpleNameExpression labelElement = expression.getTargetLabel();
JetElement subroutine; JetElement subroutine;
@@ -991,20 +972,20 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitParameterVoid(@NotNull JetParameter parameter, CFPContext context) { public void visitParameter(@NotNull JetParameter parameter) {
builder.declareParameter(parameter); builder.declareParameter(parameter);
JetExpression defaultValue = parameter.getDefaultValue(); JetExpression defaultValue = parameter.getDefaultValue();
if (defaultValue != null) { if (defaultValue != null) {
Label skipDefaultValue = builder.createUnboundLabel("after default value for parameter " + parameter.getName()); Label skipDefaultValue = builder.createUnboundLabel("after default value for parameter " + parameter.getName());
builder.nondeterministicJump(skipDefaultValue, defaultValue, null); builder.nondeterministicJump(skipDefaultValue, defaultValue, null);
generateInstructions(defaultValue, context); generateInstructions(defaultValue);
builder.bindLabel(skipDefaultValue); builder.bindLabel(skipDefaultValue);
} }
generateInitializer(parameter, createSyntheticValue(parameter)); generateInitializer(parameter, createSyntheticValue(parameter));
} }
@Override @Override
public void visitBlockExpressionVoid(@NotNull JetBlockExpression expression, CFPContext context) { public void visitBlockExpression(@NotNull JetBlockExpression expression) {
boolean declareLexicalScope = !isBlockInDoWhile(expression); boolean declareLexicalScope = !isBlockInDoWhile(expression);
if (declareLexicalScope) { if (declareLexicalScope) {
builder.enterLexicalScope(expression); builder.enterLexicalScope(expression);
@@ -1012,7 +993,7 @@ public class JetControlFlowProcessor {
mark(expression); mark(expression);
List<JetElement> statements = expression.getStatements(); List<JetElement> statements = expression.getStatements();
for (JetElement statement : statements) { for (JetElement statement : statements) {
generateInstructions(statement, NOT_IN_CONDITION); generateInstructions(statement);
} }
if (statements.isEmpty()) { if (statements.isEmpty()) {
builder.loadUnit(expression); builder.loadUnit(expression);
@@ -1032,12 +1013,12 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitNamedFunctionVoid(@NotNull JetNamedFunction function, CFPContext context) { public void visitNamedFunction(@NotNull JetNamedFunction function) {
processLocalDeclaration(function); processLocalDeclaration(function);
} }
@Override @Override
public void visitFunctionLiteralExpressionVoid(@NotNull JetFunctionLiteralExpression expression, CFPContext context) { public void visitFunctionLiteralExpression(@NotNull JetFunctionLiteralExpression expression) {
mark(expression); mark(expression);
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
processLocalDeclaration(functionLiteral); processLocalDeclaration(functionLiteral);
@@ -1045,39 +1026,39 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitQualifiedExpressionVoid(@NotNull JetQualifiedExpression expression, CFPContext context) { public void visitQualifiedExpression(@NotNull JetQualifiedExpression expression) {
mark(expression); mark(expression);
JetExpression selectorExpression = expression.getSelectorExpression(); JetExpression selectorExpression = expression.getSelectorExpression();
JetExpression receiverExpression = expression.getReceiverExpression(); JetExpression receiverExpression = expression.getReceiverExpression();
// todo: replace with selectorExpresion != null after parser is fixed // todo: replace with selectorExpresion != null after parser is fixed
if (selectorExpression instanceof JetCallExpression || selectorExpression instanceof JetSimpleNameExpression) { if (selectorExpression instanceof JetCallExpression || selectorExpression instanceof JetSimpleNameExpression) {
generateInstructions(selectorExpression, NOT_IN_CONDITION); generateInstructions(selectorExpression);
copyValue(selectorExpression, expression); copyValue(selectorExpression, expression);
} }
else { else {
generateInstructions(receiverExpression, NOT_IN_CONDITION); generateInstructions(receiverExpression);
createNonSyntheticValue(expression, receiverExpression); createNonSyntheticValue(expression, receiverExpression);
} }
} }
@Override @Override
public void visitCallExpressionVoid(@NotNull JetCallExpression expression, CFPContext context) { public void visitCallExpression(@NotNull JetCallExpression expression) {
JetExpression calleeExpression = expression.getCalleeExpression(); JetExpression calleeExpression = expression.getCalleeExpression();
if (!generateCall(expression, calleeExpression)) { if (!generateCall(expression, calleeExpression)) {
List<JetExpression> inputExpressions = new ArrayList<JetExpression>(); List<JetExpression> inputExpressions = new ArrayList<JetExpression>();
for (ValueArgument argument : expression.getValueArguments()) { for (ValueArgument argument : expression.getValueArguments()) {
JetExpression argumentExpression = argument.getArgumentExpression(); JetExpression argumentExpression = argument.getArgumentExpression();
if (argumentExpression != null) { if (argumentExpression != null) {
generateInstructions(argumentExpression, NOT_IN_CONDITION); generateInstructions(argumentExpression);
inputExpressions.add(argumentExpression); inputExpressions.add(argumentExpression);
} }
} }
for (JetExpression functionLiteral : expression.getFunctionLiteralArguments()) { for (JetExpression functionLiteral : expression.getFunctionLiteralArguments()) {
generateInstructions(functionLiteral, NOT_IN_CONDITION); generateInstructions(functionLiteral);
inputExpressions.add(functionLiteral); inputExpressions.add(functionLiteral);
} }
generateInstructions(calleeExpression, NOT_IN_CONDITION); generateInstructions(calleeExpression);
inputExpressions.add(calleeExpression); inputExpressions.add(calleeExpression);
inputExpressions.add(generateAndGetReceiverIfAny(expression)); inputExpressions.add(generateAndGetReceiverIfAny(expression));
@@ -1095,13 +1076,13 @@ public class JetControlFlowProcessor {
if (qualifiedExpression.getSelectorExpression() != expression) return null; if (qualifiedExpression.getSelectorExpression() != expression) return null;
JetExpression receiverExpression = qualifiedExpression.getReceiverExpression(); JetExpression receiverExpression = qualifiedExpression.getReceiverExpression();
generateInstructions(receiverExpression, NOT_IN_CONDITION); generateInstructions(receiverExpression);
return receiverExpression; return receiverExpression;
} }
@Override @Override
public void visitPropertyVoid(@NotNull JetProperty property, CFPContext context) { public void visitProperty(@NotNull JetProperty property) {
builder.declareVariable(property); builder.declareVariable(property);
JetExpression initializer = property.getInitializer(); JetExpression initializer = property.getInitializer();
if (initializer != null) { if (initializer != null) {
@@ -1109,23 +1090,23 @@ public class JetControlFlowProcessor {
} }
JetExpression delegate = property.getDelegateExpression(); JetExpression delegate = property.getDelegateExpression();
if (delegate != null) { if (delegate != null) {
generateInstructions(delegate, NOT_IN_CONDITION); generateInstructions(delegate);
} }
if (JetPsiUtil.isLocal(property)) { if (JetPsiUtil.isLocal(property)) {
for (JetPropertyAccessor accessor : property.getAccessors()) { for (JetPropertyAccessor accessor : property.getAccessors()) {
generateInstructions(accessor, NOT_IN_CONDITION); generateInstructions(accessor);
} }
} }
} }
@Override @Override
public void visitMultiDeclarationVoid(@NotNull JetMultiDeclaration declaration, CFPContext context) { public void visitMultiDeclaration(@NotNull JetMultiDeclaration declaration) {
visitMultiDeclaration(declaration, true); visitMultiDeclaration(declaration, true);
} }
private void visitMultiDeclaration(@NotNull JetMultiDeclaration declaration, boolean generateWriteForEntries) { private void visitMultiDeclaration(@NotNull JetMultiDeclaration declaration, boolean generateWriteForEntries) {
JetExpression initializer = declaration.getInitializer(); JetExpression initializer = declaration.getInitializer();
generateInstructions(initializer, NOT_IN_CONDITION); generateInstructions(initializer);
for (JetMultiDeclarationEntry entry : declaration.getEntries()) { for (JetMultiDeclarationEntry entry : declaration.getEntries()) {
builder.declareVariable(entry); builder.declareVariable(entry);
@@ -1152,34 +1133,34 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitPropertyAccessorVoid(@NotNull JetPropertyAccessor accessor, CFPContext context) { public void visitPropertyAccessor(@NotNull JetPropertyAccessor accessor) {
processLocalDeclaration(accessor); processLocalDeclaration(accessor);
} }
@Override @Override
public void visitBinaryWithTypeRHSExpressionVoid(@NotNull JetBinaryExpressionWithTypeRHS expression, CFPContext context) { public void visitBinaryWithTypeRHSExpression(@NotNull JetBinaryExpressionWithTypeRHS expression) {
mark(expression); mark(expression);
IElementType operationType = expression.getOperationReference().getReferencedNameElementType(); IElementType operationType = expression.getOperationReference().getReferencedNameElementType();
JetExpression left = expression.getLeft(); JetExpression left = expression.getLeft();
if (operationType == JetTokens.COLON || operationType == JetTokens.AS_KEYWORD || operationType == JetTokens.AS_SAFE) { if (operationType == JetTokens.COLON || operationType == JetTokens.AS_KEYWORD || operationType == JetTokens.AS_SAFE) {
generateInstructions(left, NOT_IN_CONDITION); generateInstructions(left);
copyValue(left, expression); copyValue(left, expression);
} }
else { else {
visitJetElementVoid(expression, context); visitJetElement(expression);
createNonSyntheticValue(expression, left); createNonSyntheticValue(expression, left);
} }
} }
@Override @Override
public void visitThrowExpressionVoid(@NotNull JetThrowExpression expression, CFPContext context) { public void visitThrowExpression(@NotNull JetThrowExpression expression) {
mark(expression); mark(expression);
JetExpression thrownExpression = expression.getThrownExpression(); JetExpression thrownExpression = expression.getThrownExpression();
if (thrownExpression == null) return; if (thrownExpression == null) return;
generateInstructions(thrownExpression, NOT_IN_CONDITION); generateInstructions(thrownExpression);
PseudoValue thrownValue = builder.getBoundValue(thrownExpression); PseudoValue thrownValue = builder.getBoundValue(thrownExpression);
if (thrownValue == null) return; if (thrownValue == null) return;
@@ -1188,7 +1169,7 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitArrayAccessExpressionVoid(@NotNull JetArrayAccessExpression expression, CFPContext context) { public void visitArrayAccessExpression(@NotNull JetArrayAccessExpression expression) {
mark(expression); mark(expression);
ResolvedCall<FunctionDescriptor> getMethodResolvedCall = trace.get(BindingContext.INDEXED_LVALUE_GET, expression); ResolvedCall<FunctionDescriptor> getMethodResolvedCall = trace.get(BindingContext.INDEXED_LVALUE_GET, expression);
if (!checkAndGenerateCall(expression, expression, getMethodResolvedCall)) { if (!checkAndGenerateCall(expression, expression, getMethodResolvedCall)) {
@@ -1197,20 +1178,20 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitIsExpressionVoid(@NotNull JetIsExpression expression, CFPContext context) { public void visitIsExpression(@NotNull JetIsExpression expression) {
mark(expression); mark(expression);
JetExpression left = expression.getLeftHandSide(); JetExpression left = expression.getLeftHandSide();
generateInstructions(left, context); generateInstructions(left);
createNonSyntheticValue(expression, left); createNonSyntheticValue(expression, left);
} }
@Override @Override
public void visitWhenExpressionVoid(@NotNull JetWhenExpression expression, CFPContext context) { public void visitWhenExpression(@NotNull JetWhenExpression expression) {
mark(expression); mark(expression);
JetExpression subjectExpression = expression.getSubjectExpression(); JetExpression subjectExpression = expression.getSubjectExpression();
if (subjectExpression != null) { if (subjectExpression != null) {
generateInstructions(subjectExpression, context); generateInstructions(subjectExpression);
} }
boolean hasElse = false; boolean hasElse = false;
@@ -1236,7 +1217,7 @@ public class JetControlFlowProcessor {
JetWhenCondition[] conditions = whenEntry.getConditions(); JetWhenCondition[] conditions = whenEntry.getConditions();
for (int i = 0; i < conditions.length; i++) { for (int i = 0; i < conditions.length; i++) {
JetWhenCondition condition = conditions[i]; JetWhenCondition condition = conditions[i];
condition.accept(conditionVisitor, context); condition.accept(conditionVisitor);
if (i + 1 < conditions.length) { if (i + 1 < conditions.length) {
PseudoValue conditionValue = createSyntheticValue(condition, subjectExpression, condition); PseudoValue conditionValue = createSyntheticValue(condition, subjectExpression, condition);
builder.nondeterministicJump(bodyLabel, expression, conditionValue); builder.nondeterministicJump(bodyLabel, expression, conditionValue);
@@ -1256,7 +1237,7 @@ public class JetControlFlowProcessor {
builder.bindLabel(bodyLabel); builder.bindLabel(bodyLabel);
JetExpression whenEntryExpression = whenEntry.getExpression(); JetExpression whenEntryExpression = whenEntry.getExpression();
if (whenEntryExpression != null) { if (whenEntryExpression != null) {
generateInstructions(whenEntryExpression, context); generateInstructions(whenEntryExpression);
branches.add(whenEntryExpression); branches.add(whenEntryExpression);
} }
builder.jump(doneLabel, expression); builder.jump(doneLabel, expression);
@@ -1274,28 +1255,28 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitObjectLiteralExpressionVoid(@NotNull JetObjectLiteralExpression expression, CFPContext context) { public void visitObjectLiteralExpression(@NotNull JetObjectLiteralExpression expression) {
mark(expression); mark(expression);
JetObjectDeclaration declaration = expression.getObjectDeclaration(); JetObjectDeclaration declaration = expression.getObjectDeclaration();
generateInstructions(declaration, context); generateInstructions(declaration);
builder.createAnonymousObject(expression); builder.createAnonymousObject(expression);
} }
@Override @Override
public void visitObjectDeclarationVoid(@NotNull JetObjectDeclaration objectDeclaration, CFPContext context) { public void visitObjectDeclaration(@NotNull JetObjectDeclaration objectDeclaration) {
visitClassOrObject(objectDeclaration, context); visitClassOrObject(objectDeclaration);
} }
@Override @Override
public void visitStringTemplateExpressionVoid(@NotNull JetStringTemplateExpression expression, CFPContext context) { public void visitStringTemplateExpression(@NotNull JetStringTemplateExpression expression) {
mark(expression); mark(expression);
List<JetExpression> inputExpressions = new ArrayList<JetExpression>(); List<JetExpression> inputExpressions = new ArrayList<JetExpression>();
for (JetStringTemplateEntry entry : expression.getEntries()) { for (JetStringTemplateEntry entry : expression.getEntries()) {
if (entry instanceof JetStringTemplateEntryWithExpression) { if (entry instanceof JetStringTemplateEntryWithExpression) {
JetExpression entryExpression = entry.getExpression(); JetExpression entryExpression = entry.getExpression();
generateInstructions(entryExpression, NOT_IN_CONDITION); generateInstructions(entryExpression);
inputExpressions.add(entryExpression); inputExpressions.add(entryExpression);
} }
} }
@@ -1303,67 +1284,67 @@ public class JetControlFlowProcessor {
} }
@Override @Override
public void visitTypeProjectionVoid(@NotNull JetTypeProjection typeProjection, CFPContext context) { public void visitTypeProjection(@NotNull JetTypeProjection typeProjection) {
// TODO : Support Type Arguments. Class object may be initialized at this point"); // TODO : Support Type Arguments. Class object may be initialized at this point");
} }
@Override @Override
public void visitAnonymousInitializerVoid(@NotNull JetClassInitializer classInitializer, CFPContext context) { public void visitAnonymousInitializer(@NotNull JetClassInitializer classInitializer) {
generateInstructions(classInitializer.getBody(), context); generateInstructions(classInitializer.getBody());
} }
private void visitClassOrObject(JetClassOrObject classOrObject, CFPContext context) { private void visitClassOrObject(JetClassOrObject classOrObject) {
for (JetDelegationSpecifier specifier : classOrObject.getDelegationSpecifiers()) { for (JetDelegationSpecifier specifier : classOrObject.getDelegationSpecifiers()) {
generateInstructions(specifier, context); generateInstructions(specifier);
} }
List<JetDeclaration> declarations = classOrObject.getDeclarations(); List<JetDeclaration> declarations = classOrObject.getDeclarations();
if (classOrObject.isLocal()) { if (classOrObject.isLocal()) {
for (JetDeclaration declaration : declarations) { for (JetDeclaration declaration : declarations) {
generateInstructions(declaration, context); generateInstructions(declaration);
} }
return; return;
} }
//For top-level and inner classes and objects functions are collected and checked separately. //For top-level and inner classes and objects functions are collected and checked separately.
for (JetDeclaration declaration : declarations) { for (JetDeclaration declaration : declarations) {
if (declaration instanceof JetProperty || declaration instanceof JetClassInitializer) { if (declaration instanceof JetProperty || declaration instanceof JetClassInitializer) {
generateInstructions(declaration, context); generateInstructions(declaration);
} }
} }
} }
@Override @Override
public void visitClassVoid(@NotNull JetClass klass, CFPContext context) { public void visitClass(@NotNull JetClass klass) {
List<JetParameter> parameters = klass.getPrimaryConstructorParameters(); List<JetParameter> parameters = klass.getPrimaryConstructorParameters();
for (JetParameter parameter : parameters) { for (JetParameter parameter : parameters) {
generateInstructions(parameter, context); generateInstructions(parameter);
} }
visitClassOrObject(klass, context); visitClassOrObject(klass);
} }
@Override @Override
public void visitDelegationToSuperCallSpecifierVoid(@NotNull JetDelegatorToSuperCall call, CFPContext context) { public void visitDelegationToSuperCallSpecifier(@NotNull JetDelegatorToSuperCall call) {
List<? extends ValueArgument> valueArguments = call.getValueArguments(); List<? extends ValueArgument> valueArguments = call.getValueArguments();
for (ValueArgument valueArgument : valueArguments) { for (ValueArgument valueArgument : valueArguments) {
generateInstructions(valueArgument.getArgumentExpression(), context); generateInstructions(valueArgument.getArgumentExpression());
} }
} }
@Override @Override
public void visitDelegationByExpressionSpecifierVoid(@NotNull JetDelegatorByExpressionSpecifier specifier, CFPContext context) { public void visitDelegationByExpressionSpecifier(@NotNull JetDelegatorByExpressionSpecifier specifier) {
generateInstructions(specifier.getDelegateExpression(), context); generateInstructions(specifier.getDelegateExpression());
} }
@Override @Override
public void visitJetFileVoid(@NotNull JetFile file, CFPContext context) { public void visitJetFile(@NotNull JetFile file) {
for (JetDeclaration declaration : file.getDeclarations()) { for (JetDeclaration declaration : file.getDeclarations()) {
if (declaration instanceof JetProperty) { if (declaration instanceof JetProperty) {
generateInstructions(declaration, context); generateInstructions(declaration);
} }
} }
} }
@Override @Override
public void visitJetElementVoid(@NotNull JetElement element, CFPContext context) { public void visitJetElement(@NotNull JetElement element) {
builder.unsupported(element); builder.unsupported(element);
} }
@@ -1440,7 +1421,7 @@ public class JetControlFlowProcessor {
else if (receiver instanceof ExpressionReceiver) { else if (receiver instanceof ExpressionReceiver) {
JetExpression expression = ((ExpressionReceiver) receiver).getExpression(); JetExpression expression = ((ExpressionReceiver) receiver).getExpression();
if (generateInstructions) { if (generateInstructions) {
generateInstructions(expression, NOT_IN_CONDITION); generateInstructions(expression);
} }
PseudoValue receiverPseudoValue = builder.getBoundValue(expression); PseudoValue receiverPseudoValue = builder.getBoundValue(expression);
@@ -1478,7 +1459,7 @@ public class JetControlFlowProcessor {
SmartFMap<PseudoValue, ValueParameterDescriptor> parameterValues) { SmartFMap<PseudoValue, ValueParameterDescriptor> parameterValues) {
JetExpression expression = valueArgument.getArgumentExpression(); JetExpression expression = valueArgument.getArgumentExpression();
if (expression != null) { if (expression != null) {
generateInstructions(expression, NOT_IN_CONDITION); generateInstructions(expression);
PseudoValue argValue = builder.getBoundValue(expression); PseudoValue argValue = builder.getBoundValue(expression);
if (argValue != null) { if (argValue != null) {