Search in sources :

Example 6 with ComplexNode

use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.

the class DoWhileFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, DoStatement doStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), doStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), doStmt);
    Node bodyNode = DelegatingNodeFactory.create(astpp, NodeNames.BODY, doStmt, doStmt.getStatement());
    Node conditionNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.CONDITION, doStmt, doStmt.getExpression());
    Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), doStmt);
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), doStmt);
    cNode.addNode(entryNode);
    cNode.addNode(bodyNode);
    cNode.addNode(conditionNode);
    cNode.addNode(conditionForkNode);
    cNode.addNode(exitNode);
    cNode.connectInternalSucc(entryNode, bodyNode, conditionNode, conditionForkNode);
    cNode.connectInternalSucc(ControlFlowType.LoopReenter, conditionForkNode, bodyNode);
    cNode.connectInternalSucc(ControlFlowType.LoopExit, conditionForkNode, exitNode);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    // catch for short-circuits
    conditionForkNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
    exitNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse, ControlFlowType.LoopExit));
    LabelledStatement lblStmt = ASTUtils.getLabelledStatement(doStmt);
    exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
    conditionNode.addCatchToken(new CatchToken(ControlFlowType.Continue, lblStmt));
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) LabelledStatement(org.eclipse.n4js.n4JS.LabelledStatement) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) Node(org.eclipse.n4js.flowgraphs.model.Node) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken)

Example 7 with ComplexNode

use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.

the class EmptyStatementFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, Statement empty) {
    ComplexNode cNode = new ComplexNode(astpp.container(), empty);
    Node entryAndExitNode = new RepresentingNode(NodeNames.ENTRY_EXIT, astpp.pos(), empty);
    cNode.addNode(entryAndExitNode);
    cNode.setEntryNode(entryAndExitNode);
    cNode.setExitNode(entryAndExitNode);
    return cNode;
}
Also used : ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) Node(org.eclipse.n4js.flowgraphs.model.Node) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode)

Example 8 with ComplexNode

use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.

the class IfFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, IfStatement ifStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), ifStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), ifStmt);
    Node conditionNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.CONDITION, ifStmt, ifStmt.getExpression());
    Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), ifStmt);
    Node thenNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.THEN, ifStmt, ifStmt.getIfStmt());
    Node elseNode = DelegatingNodeFactory.create(astpp, NodeNames.ELSE, ifStmt, ifStmt.getElseStmt());
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), ifStmt);
    cNode.addNode(entryNode);
    cNode.addNode(conditionNode);
    cNode.addNode(conditionForkNode);
    cNode.addNode(thenNode);
    cNode.addNode(elseNode);
    cNode.addNode(exitNode);
    cNode.connectInternalSucc(entryNode, conditionNode, conditionForkNode);
    cNode.connectInternalSucc(ControlFlowType.IfTrue, conditionForkNode, thenNode);
    cNode.connectInternalSucc(thenNode, exitNode);
    // catch for short-circuits
    thenNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
    if (ifStmt.getElseStmt() == null) {
        cNode.connectInternalSucc(ControlFlowType.IfFalse, conditionForkNode, exitNode);
        // catch for short-circuits
        exitNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse));
    } else {
        cNode.connectInternalSucc(ControlFlowType.IfFalse, conditionForkNode, elseNode);
        cNode.connectInternalSucc(elseNode, exitNode);
        // catch for short-circuits
        elseNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse));
    }
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) Node(org.eclipse.n4js.flowgraphs.model.Node) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken)

Example 9 with ComplexNode

use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.

the class ControlFlowGraphFactory method isExitingFinallyBlock.

private static boolean isExitingFinallyBlock(ComplexNodeMapper cnMapper, Node node) {
    ControlFlowElement cfe = node.getControlFlowElement();
    ComplexNode cn = cnMapper.get(cfe);
    boolean isExitingFinallyBlock = true;
    isExitingFinallyBlock &= cfe instanceof Block;
    isExitingFinallyBlock &= cfe.eContainer() instanceof FinallyBlock;
    isExitingFinallyBlock &= cn.getExit() == node;
    return isExitingFinallyBlock;
}
Also used : ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) FinallyBlock(org.eclipse.n4js.n4JS.FinallyBlock) FinallyBlock(org.eclipse.n4js.n4JS.FinallyBlock) Block(org.eclipse.n4js.n4JS.Block) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 10 with ComplexNode

use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.

the class ControlFlowGraphFactory method printAllEdgeDetails.

/**
 * Prints detailed information of all control flow edges. Used for debugging purposes
 */
private static void printAllEdgeDetails(ComplexNodeMapper cnMapper) {
    // TODO move this to a PrintUtils class
    System.out.println("\nAll edges:");
    Set<ControlFlowEdge> allEdges = new HashSet<>();
    for (ComplexNode cn : cnMapper.getAll()) {
        for (Node n : cn.getNodes()) {
            allEdges.addAll(n.pred);
            allEdges.addAll(n.succ);
        }
    }
    for (ControlFlowEdge edge : allEdges) {
        System.out.println(edge);
    }
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) DelegatingNode(org.eclipse.n4js.flowgraphs.model.DelegatingNode) Node(org.eclipse.n4js.flowgraphs.model.Node) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)33 Node (org.eclipse.n4js.flowgraphs.model.Node)27 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)17 LinkedList (java.util.LinkedList)13 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)12 CatchToken (org.eclipse.n4js.flowgraphs.model.CatchToken)11 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)7 LabelledStatement (org.eclipse.n4js.n4JS.LabelledStatement)6 DelegatingNode (org.eclipse.n4js.flowgraphs.model.DelegatingNode)5 ControlFlowEdge (org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)4 HashSet (java.util.HashSet)3 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)3 FinallyBlock (org.eclipse.n4js.n4JS.FinallyBlock)3 VariableDeclarationOrBinding (org.eclipse.n4js.n4JS.VariableDeclarationOrBinding)3 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 AbstractCaseClause (org.eclipse.n4js.n4JS.AbstractCaseClause)2 Block (org.eclipse.n4js.n4JS.Block)2 CaseClause (org.eclipse.n4js.n4JS.CaseClause)2 Statement (org.eclipse.n4js.n4JS.Statement)2