Search in sources :

Example 6 with CFGEdgeBuilder

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);
    }
}
Also used : DoStatement(org.eclipse.jdt.core.dom.DoStatement) Statement(org.eclipse.jdt.core.dom.Statement) ContinueStatement(org.eclipse.jdt.core.dom.ContinueStatement) SynchronizedStatement(org.eclipse.jdt.core.dom.SynchronizedStatement) ThrowStatement(org.eclipse.jdt.core.dom.ThrowStatement) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) TypeDeclarationStatement(org.eclipse.jdt.core.dom.TypeDeclarationStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) BreakStatement(org.eclipse.jdt.core.dom.BreakStatement) EmptyStatement(org.eclipse.jdt.core.dom.EmptyStatement) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) TryStatement(org.eclipse.jdt.core.dom.TryStatement) AssertStatement(org.eclipse.jdt.core.dom.AssertStatement) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) LabeledStatement(org.eclipse.jdt.core.dom.LabeledStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) VariableDeclarationStatement(org.eclipse.jdt.core.dom.VariableDeclarationStatement) CFGEdgeBuilder(org.autorefactor.cfg.CFGEdgeBuilder)

Example 7 with CFGEdgeBuilder

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();
}
Also used : CFGEdgeBuilder(org.autorefactor.cfg.CFGEdgeBuilder)

Example 8 with CFGEdgeBuilder

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();
}
Also used : CFGEdgeBuilder(org.autorefactor.cfg.CFGEdgeBuilder)

Example 9 with CFGEdgeBuilder

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();
}
Also used : DoStatement(org.eclipse.jdt.core.dom.DoStatement) Statement(org.eclipse.jdt.core.dom.Statement) ContinueStatement(org.eclipse.jdt.core.dom.ContinueStatement) SynchronizedStatement(org.eclipse.jdt.core.dom.SynchronizedStatement) ThrowStatement(org.eclipse.jdt.core.dom.ThrowStatement) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) TypeDeclarationStatement(org.eclipse.jdt.core.dom.TypeDeclarationStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) BreakStatement(org.eclipse.jdt.core.dom.BreakStatement) EmptyStatement(org.eclipse.jdt.core.dom.EmptyStatement) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) TryStatement(org.eclipse.jdt.core.dom.TryStatement) AssertStatement(org.eclipse.jdt.core.dom.AssertStatement) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) LabeledStatement(org.eclipse.jdt.core.dom.LabeledStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) VariableDeclarationStatement(org.eclipse.jdt.core.dom.VariableDeclarationStatement) CFGEdgeBuilder(org.autorefactor.cfg.CFGEdgeBuilder)

Example 10 with CFGEdgeBuilder

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();
}
Also used : CFGEdgeBuilder(org.autorefactor.cfg.CFGEdgeBuilder)

Aggregations

CFGEdgeBuilder (org.autorefactor.cfg.CFGEdgeBuilder)14 AssertStatement (org.eclipse.jdt.core.dom.AssertStatement)3 BreakStatement (org.eclipse.jdt.core.dom.BreakStatement)3 ContinueStatement (org.eclipse.jdt.core.dom.ContinueStatement)3 DoStatement (org.eclipse.jdt.core.dom.DoStatement)3 EmptyStatement (org.eclipse.jdt.core.dom.EmptyStatement)3 EnhancedForStatement (org.eclipse.jdt.core.dom.EnhancedForStatement)3 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)3 ForStatement (org.eclipse.jdt.core.dom.ForStatement)3 IfStatement (org.eclipse.jdt.core.dom.IfStatement)3 LabeledStatement (org.eclipse.jdt.core.dom.LabeledStatement)3 ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)3 Statement (org.eclipse.jdt.core.dom.Statement)3 SwitchStatement (org.eclipse.jdt.core.dom.SwitchStatement)3 SynchronizedStatement (org.eclipse.jdt.core.dom.SynchronizedStatement)3 ThrowStatement (org.eclipse.jdt.core.dom.ThrowStatement)3 TryStatement (org.eclipse.jdt.core.dom.TryStatement)3 TypeDeclarationStatement (org.eclipse.jdt.core.dom.TypeDeclarationStatement)3 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)3 WhileStatement (org.eclipse.jdt.core.dom.WhileStatement)3