use of com.android.tools.idea.experimental.codeanalysis.datastructs.graph.BlockGraph in project android by JetBrains.
the class CFGBuilder method dfsPsiDoWhileStatementBuilder.
/**
* Build nodes for "Do While" loops
* @param statement The while statement
* @param label The label for this loop. In case of labeled break.
*/
public void dfsPsiDoWhileStatementBuilder(@NotNull PsiDoWhileStatement statement, @Nullable PsiIdentifier label) {
PsiStatement loopBody = statement.getBody();
int loopType;
LoopBranchingNodeImpl loopNode;
GraphNode conditionCheckEntry;
ConditionCheckNode conditionCheckExit;
GraphNode postLoopEntry;
GraphNode postLoopExit;
loopType = LoopBranchingNode.DOWHILE_LOOP;
PsiDoWhileStatement dowhileStmt = (PsiDoWhileStatement) statement;
loopNode = new LoopBranchingNodeImpl(this.mGraph, loopType);
connectCurrentWorkingNode(loopNode);
//Push this loopNode into the stack
pushLoopNode(loopNode, label);
//Eval the loopbody
BlockGraph loopBodyGraph = loopbodyBuilder(loopBody, statement);
connectCurrentWorkingNode(loopBodyGraph.getEntryNode());
curWorkingNodeList.clear();
curWorkingNodeList.add(loopBodyGraph.getExitNode());
//Eval the condition check
PsiExpression psiConditionCheckCode = dowhileStmt.getCondition();
Value finalCheckVal = dfsExpressionBuilder(psiConditionCheckCode);
conditionCheckExit = new ConditionCheckNodeImpl(this.mGraph, finalCheckVal);
if (loopBodyGraph.getExitNode().getOut().length == 0) {
//The dummy loop node does not have any out edges
//In this case the conditionCheckEntry is the same
//as the conditionCheckExit
conditionCheckEntry = conditionCheckExit;
} else {
//At this point the dummy LoopNode is connected to the entry
//of the condition check code.
conditionCheckEntry = loopBodyGraph.getExitNode().getOut()[0];
}
connectCurrentWorkingNode(conditionCheckExit);
//True branch connect back to the body
GraphNodeUtil.connectGraphNode(conditionCheckExit.getTrueBranch(), loopBodyGraph.getEntryNode());
curWorkingNodeList.clear();
curWorkingNodeList.add(conditionCheckExit.getFalseBranch());
loopNode.setConditionCheckEntry(conditionCheckEntry);
loopNode.setConditionCheckExitNode(conditionCheckExit);
loopNode.setLoopBody(loopBodyGraph);
loopNode.setPostLoopEntryNode(null);
loopNode.setPostLoopExitNode(null);
//Do while loop build complete;
//Process the break and continue nodes
loopNode.connectSpecialNodes();
popLoopNode();
}
use of com.android.tools.idea.experimental.codeanalysis.datastructs.graph.BlockGraph in project android by JetBrains.
the class CFGBuilder method dfsPsiWhileStatementBuilder.
/**
* Build nodes for "while" loops
* @param statement The while statement
* @param label The label for this loop. In case of labeled break.
*/
public void dfsPsiWhileStatementBuilder(@NotNull PsiWhileStatement statement, @Nullable PsiIdentifier label) {
PsiStatement loopBody = statement.getBody();
int loopType;
LoopBranchingNodeImpl loopNode;
GraphNode conditionCheckEntry;
ConditionCheckNode conditionCheckExit;
GraphNode postLoopEntry;
GraphNode postLoopExit;
PsiWhileStatement whileStmt = (PsiWhileStatement) statement;
loopType = LoopBranchingNode.WHILE_LOOP;
loopNode = new LoopBranchingNodeImpl(this.mGraph, loopType);
connectCurrentWorkingNode(loopNode);
//Push this loopNode into the stack
pushLoopNode(loopNode, label);
//Eval the condition check
PsiExpression psiConditionCheckCode = whileStmt.getCondition();
Value finalCheckVal = dfsExpressionBuilder(psiConditionCheckCode);
//Build the final condition check for this loop
conditionCheckExit = new ConditionCheckNodeImpl(this.mGraph, finalCheckVal);
if (loopNode.getOut().length == 0) {
//The dummy loop node does not have any out edges
//In this case the conditionCheckEntry is the same
//as the conditionCheckExit
conditionCheckEntry = conditionCheckExit;
} else {
//At this point the dummy LoopNode is connected to the entry
//of the condition check code.
conditionCheckEntry = loopNode.getOut()[0];
}
connectCurrentWorkingNode(conditionCheckExit);
//Build the loop body
BlockGraph loopBodyGraph = loopbodyBuilder(loopBody, statement);
//Connect the condition check code true branch to loop entry
GraphNodeUtil.connectGraphNode(conditionCheckExit.getTrueBranch(), loopBodyGraph.getEntryNode());
curWorkingNodeList.clear();
curWorkingNodeList.add(loopBodyGraph.getExitNode());
//Connect the loopbody exit to the condition check entry
connectCurrentWorkingNode(conditionCheckEntry);
curWorkingNodeList.clear();
curWorkingNodeList.add(conditionCheckExit.getFalseBranch());
loopNode.setConditionCheckEntry(conditionCheckEntry);
loopNode.setConditionCheckExitNode(conditionCheckExit);
loopNode.setPostLoopEntryNode(null);
loopNode.setPostLoopExitNode(null);
loopNode.setLoopBody(loopBodyGraph);
//While loop build complete
//Process the break and continue nodes
loopNode.connectSpecialNodes();
popLoopNode();
}
Aggregations