use of com.android.tools.idea.experimental.codeanalysis.datastructs.stmt.impl.AssignStmtImpl in project android by JetBrains.
the class CFGBuilder method dfsPsiPostfixExpressionBuilder.
/**
* Temp work around
* Handle the case that is a ++
* Translate to l = a; l2 = l + 1; a = l2; return l;
*
* @param resultArray
* @param expression
* @return
*/
public Value dfsPsiPostfixExpressionBuilder(PsiPostfixExpression expression) {
PsiExpression valuePsiExpression = expression.getOperand();
Value valueExpr = dfsLHSExpressionBuilder(valuePsiExpression);
SynthesizedLocal retLocal = new SynthesizedLocalImpl(valuePsiExpression.getType(), expression.getText(), null);
PostfixExprImpl postfixExpr = new PostfixExprImpl(expression, expression.getOperationTokenType(), valueExpr, expression.getType());
AssignStmtImpl synAssign = new AssignStmtImpl(true, null, JavaTokenType.EQ);
synAssign.setLOp(retLocal);
synAssign.setROp(postfixExpr);
GraphNodeImpl prefixNode = new GraphNodeImpl(this.mGraph);
prefixNode.getStmtList().add(synAssign);
connectCurrentWorkingNode(prefixNode);
return retLocal;
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.stmt.impl.AssignStmtImpl in project android by JetBrains.
the class CFGBuilder method dfsBinaryExpressionBuilder.
/**
* Build nodes for expressions like expr OP expr.
* There are special cases: expr LogicalOP expr.
* The AND and OR is short-circuit. They are processed in
* this method.
*
* @param binExpression The expression
* @return The local or the reference to the expression
*/
public Value dfsBinaryExpressionBuilder(PsiBinaryExpression binExpression) {
PsiExpression opL = binExpression.getLOperand();
PsiExpression opR = binExpression.getROperand();
IElementType iOperator = binExpression.getOperationTokenType();
if ((binExpression.getType() == PsiType.BOOLEAN) && (iOperator == JavaTokenType.ANDAND || iOperator == JavaTokenType.OROR)) {
//The expression is using short circuit boolean operators
if (iOperator == JavaTokenType.OROR) {
//Short-circuit logical OR. evaluate Lop first
//If the L Operand is already true. The R Operand does not need to be
//evaluated.
Value LExpr = dfsExpressionBuilder(opL);
ConditionCheckNode condCheckNode = new ConditionCheckNodeImpl(mGraph, LExpr);
connectCurrentWorkingNode(condCheckNode);
//If the L Operand is false. Evaluate the R operand
curWorkingNodeList.clear();
curWorkingNodeList.add(condCheckNode.getFalseBranch());
Value RExpr = dfsExpressionBuilder(opR);
//Create synthesized local
SynthesizedLocal synLocal = new SynthesizedLocalImpl(PsiType.BOOLEAN, binExpression.getText(), binExpression);
//Create 2 assignment statement
//First: true branch
AssignStmtImpl trueBranch = new AssignStmtImpl(true, null, JavaTokenType.EQ);
trueBranch.setLOp(synLocal);
//Maybe it can be changed to a True constant in this case?
trueBranch.setROp(LExpr);
GraphNodeImpl LBranchNode = new GraphNodeImpl(this.mGraph);
LBranchNode.getStmtList().add(trueBranch);
GraphNodeUtil.connectGraphNode(condCheckNode.getTrueBranch(), LBranchNode);
//Second: false branch
AssignStmtImpl falseBranch = new AssignStmtImpl(true, null, JavaTokenType.EQ);
falseBranch.setLOp(synLocal);
falseBranch.setROp(RExpr);
GraphNodeImpl RBranchNode = new GraphNodeImpl(this.mGraph);
RBranchNode.getStmtList().add(falseBranch);
//GraphNodeUtil.connectGraphNode(condCheckNode.getFalseBranch(),);
for (GraphNode parentNode : curWorkingNodeList) {
GraphNodeUtil.connectGraphNode(parentNode, RBranchNode);
}
curWorkingNodeList.clear();
curWorkingNodeList.add(LBranchNode);
curWorkingNodeList.add(RBranchNode);
return synLocal;
}
if (iOperator == JavaTokenType.ANDAND) {
//Short-circuit logical AND. evaluate Lop first
Value LExpr = dfsExpressionBuilder(opL);
ConditionCheckNode condCheckNode = new ConditionCheckNodeImpl(mGraph, LExpr);
connectCurrentWorkingNode(condCheckNode);
//If the L Operand is true. Evaluate the R operand
curWorkingNodeList.clear();
curWorkingNodeList.add(condCheckNode.getTrueBranch());
Value RExpr = dfsExpressionBuilder(opR);
//Create synthesized local
SynthesizedLocal synLocal = new SynthesizedLocalImpl(PsiType.BOOLEAN, binExpression.getText(), binExpression);
//Create 2 assignment statement
//First false branch
AssignStmtImpl falseBranch = new AssignStmtImpl(true, null, JavaTokenType.EQ);
falseBranch.setLOp(synLocal);
//Can be a constant False
falseBranch.setROp(LExpr);
GraphNodeImpl LBranchNode = new GraphNodeImpl(this.mGraph);
LBranchNode.getStmtList().add(falseBranch);
GraphNodeUtil.connectGraphNode(condCheckNode.getFalseBranch(), LBranchNode);
//Second: true branch
AssignStmtImpl trueBranch = new AssignStmtImpl(true, null, JavaTokenType.EQ);
trueBranch.setLOp(synLocal);
trueBranch.setROp(RExpr);
GraphNodeImpl RBranchNode = new GraphNodeImpl(this.mGraph);
RBranchNode.getStmtList().add(trueBranch);
for (GraphNode parentNode : curWorkingNodeList) {
GraphNodeUtil.connectGraphNode(parentNode, RBranchNode);
}
curWorkingNodeList.clear();
curWorkingNodeList.add(LBranchNode);
curWorkingNodeList.add(RBranchNode);
return synLocal;
}
}
// End of short-circuit logic
//The expression is not using boolean operators
//Or not using short circuit boolean operators.
BinopExprImpl binopExpr = new BinopExprImpl(binExpression);
Value vOp1 = dfsExpressionBuilder(opL);
Value vOp2 = dfsExpressionBuilder(opR);
binopExpr.setOp1(vOp1);
binopExpr.setOp2(vOp2);
binopExpr.setOperator(binExpression.getOperationTokenType());
SynthesizedLocal binopLocal = createSynthesizeTemporalVariable(binopExpr);
return binopLocal;
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.stmt.impl.AssignStmtImpl in project android by JetBrains.
the class CFGBuilder method dfsPsiPrefixExpressionBuilder.
/**
* Temp work around
* Handle the case that is ++ a
* Translate to l = a; l2 = l + 1; a = l2 return l2
*
* @param resultArray
* @param expression
* @return
*/
public Value dfsPsiPrefixExpressionBuilder(PsiPrefixExpression expression) {
PsiExpression valuePsiExpression = expression.getOperand();
Value valueExpr = dfsLHSExpressionBuilder(valuePsiExpression);
SynthesizedLocal retLocal = new SynthesizedLocalImpl(valuePsiExpression.getType(), expression.getText(), null);
PrefixExprImpl prefixExpr = new PrefixExprImpl(expression, expression.getOperationTokenType(), valueExpr, expression.getType());
AssignStmtImpl synAssign = new AssignStmtImpl(true, null, JavaTokenType.EQ);
synAssign.setLOp(retLocal);
synAssign.setROp(prefixExpr);
GraphNodeImpl prefixNode = new GraphNodeImpl(this.mGraph);
prefixNode.getStmtList().add(synAssign);
connectCurrentWorkingNode(prefixNode);
return retLocal;
}
Aggregations