use of org.autorefactor.cfg.CFGEdgeBuilder in project AutoRefactor by JnRouvignac.
the class CFGBuilder method buildCFG.
/**
* Builds a CFG for the passed in statement.
*
* @param node the statement for which to build a CFG
* @param state the liveness state before the current statement.
* It contains: the live edges before the current statement,
* the live basic block to which the current statement might be added.
* If null, then the new basic block must be created for the current statement.
* @param throwers the thrower blocks information
* @return the new live state after the current statement
*/
public LivenessState buildCFG(IfStatement node, LivenessState state, ThrowerBlocks throwers) {
final CFGBasicBlock exprBlock = getCFGBasicBlock(node, state.nextStmtWillCreateNewBlock(), true);
try {
addVariableAccess(exprBlock, node.getExpression(), READ, throwers);
final LivenessState result = new LivenessState();
CFGEdgeBuilder thenEdge = new CFGEdgeBuilder(node.getExpression(), true, exprBlock);
result.addAll(buildCFG(node.getThenStatement(), LivenessState.of(thenEdge), throwers));
final Statement elseStmt = node.getElseStatement();
CFGEdgeBuilder elseEdge = new CFGEdgeBuilder(node.getExpression(), false, exprBlock);
if (elseStmt != null) {
result.addAll(buildCFG(elseStmt, LivenessState.of(elseEdge), throwers));
} else {
result.add(elseEdge);
}
return result.nextStmtWillCreateNewBlock();
} finally {
moveAllEdgesToBuild(node, state);
}
}
use of org.autorefactor.cfg.CFGEdgeBuilder in project AutoRefactor by JnRouvignac.
the class CFGBuilder method buildCFG.
/**
* Builds a CFG for the provided node.
*
* @param node the node for which to build a CFG.
* @param switchConditionBasicBlock the basic block for the switch condition
* @param state the blocks liveness state before current node
* @param throwers the thrower blocks information
* @return the blocks liveness state after current node
*/
public LivenessState buildCFG(SwitchCase node, CFGBasicBlock switchConditionBasicBlock, LivenessState state, ThrowerBlocks throwers) {
// the current live blocks will be empty if there was a break,
// or populated in case of fall-through.
addVariableAccess(switchConditionBasicBlock, node.getExpression(), READ, throwers);
// add an edge going from the condition of the switch
// (state.liveBasicBlock is the condition of the switch)
state.add(new CFGEdgeBuilder(node.getExpression(), true, switchConditionBasicBlock));
return state.nextStmtWillCreateNewBlock();
}
use of org.autorefactor.cfg.CFGEdgeBuilder in project AutoRefactor by JnRouvignac.
the class CFGBuilder method buildCFG.
/**
* Builds a CFG for the provided node.
*
* @param node the node for which to build a CFG.
* @param state the blocks liveness state before current node
* @param throwers the thrower blocks information
* @return the blocks liveness state after current node
*/
public LivenessState buildCFG(SynchronizedStatement node, LivenessState state, ThrowerBlocks throwers) {
CFGBasicBlock basicBlock = getCFGBasicBlock(node, state.nextStmtWillCreateNewBlock());
addVariableAccess(basicBlock, node.getExpression(), READ, throwers);
CFGEdgeBuilder liveEdge = new CFGEdgeBuilder(basicBlock);
LivenessState result = buildCFG(node.getBody(), LivenessState.of(liveEdge), throwers);
return result.nextStmtWillCreateNewBlock();
}
use of org.autorefactor.cfg.CFGEdgeBuilder in project AutoRefactor by JnRouvignac.
the class CFGBuilder method buildCFG.
/**
* Builds a CFG for the provided node.
*
* @param node the node for which to build a CFG.
* @param state the blocks liveness state before current node
* @param throwers the thrower blocks information
* @return the blocks liveness state after current node
*/
public LivenessState buildCFG(ContinueStatement node, LivenessState state, ThrowerBlocks throwers) {
final CFGBasicBlock basicBlock = getCFGBasicBlock(node, state);
final Statement targetStmt;
if (node.getLabel() != null) {
targetStmt = findLabeledParentStmt(node);
} else {
targetStmt = findContinuableParentStmt(node);
}
addEdgeToBuild(targetStmt, new CFGEdgeBuilder(basicBlock), false);
return state.copyLiveBasicBlock();
}
use of org.autorefactor.cfg.CFGEdgeBuilder in project AutoRefactor by JnRouvignac.
the class CFGBuilder method buildCFG.
/**
* Builds a CFG for the provided node.
*
* @param node the node for which to build a CFG.
* @param state the blocks liveness state before current node
* @param throwers the thrower blocks information
* @return the blocks liveness state after current node
*/
public LivenessState buildCFG(WhileStatement node, LivenessState state, ThrowerBlocks throwers) {
final CFGBasicBlock conditionBlock = getCFGBasicBlock(node.getExpression(), state.nextStmtWillCreateNewBlock());
addVariableAccess(conditionBlock, node.getExpression(), READ, throwers);
final CFGEdgeBuilder liveEdge = new CFGEdgeBuilder(node.getExpression(), true, conditionBlock);
final LivenessState liveAfterStmt = buildCFG(node.getBody(), LivenessState.of(liveEdge), throwers);
liveAfterStmt.add(new CFGEdgeBuilder(node.getExpression(), false, conditionBlock));
buildEdgesAfterBranchableStmt(node, liveAfterStmt, conditionBlock);
return liveAfterStmt.nextStmtWillCreateNewBlock();
}
Aggregations