Search in sources :

Example 1 with HelperNode

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

the class ConditionalExpressionFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, ConditionalExpression condExpr) {
    ComplexNode cNode = new ComplexNode(astpp.container(), condExpr);
    HelperNode entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), condExpr);
    Node conditionNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.CONDITION, condExpr, condExpr.getExpression());
    HelperNode conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), condExpr);
    Node thenNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.THEN, condExpr, condExpr.getTrueExpression());
    Node elseNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.ELSE, condExpr, condExpr.getFalseExpression());
    Node exitNode = new RepresentingNode(NodeNames.EXIT, astpp.pos(), condExpr);
    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);
    cNode.connectInternalSucc(ControlFlowType.IfFalse, conditionForkNode, elseNode);
    cNode.connectInternalSucc(elseNode, exitNode);
    // catch for short-circuits
    thenNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
    // 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) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) Node(org.eclipse.n4js.flowgraphs.model.Node) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken)

Example 2 with HelperNode

use of org.eclipse.n4js.flowgraphs.model.HelperNode 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 3 with HelperNode

use of org.eclipse.n4js.flowgraphs.model.HelperNode 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 4 with HelperNode

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

the class ForFactory method buildForPlain.

private static ComplexNode buildForPlain(ReentrantASTIterator astpp, ForStatement forStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), forStmt);
    List<Node> initNodes = new LinkedList<>();
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), forStmt);
    Node conditionNode = null;
    Node bodyNode = null;
    Node updatesNode = null;
    if (forStmt.getVarDeclsOrBindings() != null) {
        int i = 0;
        for (VariableDeclarationOrBinding vdob : forStmt.getVarDeclsOrBindings()) {
            Node initNode = DelegatingNodeFactory.create(astpp, "init_" + i, forStmt, vdob);
            initNodes.add(initNode);
            i++;
        }
    }
    if (forStmt.getInitExpr() != null) {
        Node initNode = DelegatingNodeFactory.create(astpp, NodeNames.INITS, forStmt, forStmt.getInitExpr());
        initNodes.add(initNode);
    }
    if (forStmt.getExpression() != null) {
        conditionNode = DelegatingNodeFactory.create(astpp, NodeNames.CONDITION, forStmt, forStmt.getExpression());
    }
    Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), forStmt);
    bodyNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.BODY, forStmt, forStmt.getStatement());
    Node continueCatchNode = new HelperNode(NodeNames.CONTINUE_CATCH, astpp.pos(), forStmt);
    if (forStmt.getUpdateExpr() != null) {
        updatesNode = DelegatingNodeFactory.create(astpp, NodeNames.UPDATES, forStmt, forStmt.getUpdateExpr());
    }
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), forStmt);
    cNode.addNode(entryNode);
    cNode.addNode(exitNode);
    for (Node initNode : initNodes) cNode.addNode(initNode);
    cNode.addNode(conditionNode);
    cNode.addNode(conditionForkNode);
    cNode.addNode(bodyNode);
    cNode.addNode(continueCatchNode);
    cNode.addNode(updatesNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.addAll(initNodes);
    nodes.add(conditionNode);
    nodes.add(conditionForkNode);
    cNode.connectInternalSucc(nodes);
    cNode.connectInternalSucc(ControlFlowType.LoopEnter, conditionForkNode, bodyNode);
    if (conditionNode != null) {
        cNode.connectInternalSucc(ControlFlowType.LoopExit, conditionForkNode, exitNode);
        cNode.connectInternalSucc(bodyNode, continueCatchNode, updatesNode);
        Node beforeConditionNode = ListUtils.filterNulls(bodyNode, continueCatchNode, updatesNode).getLast();
        cNode.connectInternalSucc(ControlFlowType.LoopRepeat, beforeConditionNode, conditionNode);
    } else {
        cNode.connectInternalSucc(bodyNode, continueCatchNode, updatesNode);
        LinkedList<Node> loopCycle = ListUtils.filterNulls(continueCatchNode, updatesNode);
        Node loopSrc = loopCycle.getLast();
        cNode.connectInternalSucc(ControlFlowType.LoopInfinite, loopSrc, conditionForkNode);
        cNode.connectInternalSucc(ControlFlowType.DeadCode, loopSrc, exitNode);
    }
    // catch for short-circuits
    conditionForkNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
    exitNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse, ControlFlowType.LoopExit));
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    LabelledStatement lblStmt = ASTUtils.getLabelledStatement(forStmt);
    exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
    continueCatchNode.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) VariableDeclarationOrBinding(org.eclipse.n4js.n4JS.VariableDeclarationOrBinding) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken) LinkedList(java.util.LinkedList)

Example 5 with HelperNode

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

the class JumpFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, Statement stmt, Expression expr, JumpToken jumptoken) {
    ComplexNode cNode = new ComplexNode(astpp.container(), stmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), stmt);
    cNode.addNode(entryNode);
    Node expression = null;
    if (expr != null) {
        expression = DelegatingNodeFactory.create(astpp, NodeNames.EXPRESSION, stmt, expr);
        cNode.addNode(expression);
    }
    Node jumpNode = new RepresentingNode(NodeNames.JUMP, astpp.pos(), stmt);
    cNode.addNode(jumpNode);
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), stmt);
    cNode.addNode(exitNode);
    List<Node> cfs = new LinkedList<>();
    cfs.add(entryNode);
    cfs.add(expression);
    cNode.connectInternalSucc(entryNode, expression);
    Node beforeDeadNode = ListUtils.filterNulls(entryNode, expression).getLast();
    cNode.connectInternalSucc(beforeDeadNode, jumpNode);
    cNode.connectInternalSucc(ControlFlowType.DeadCode, jumpNode, exitNode);
    jumpNode.addJumpToken(jumptoken);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    cNode.setJumpNode(jumpNode);
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) LinkedList(java.util.LinkedList)

Aggregations

ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)17 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)17 Node (org.eclipse.n4js.flowgraphs.model.Node)17 LinkedList (java.util.LinkedList)12 CatchToken (org.eclipse.n4js.flowgraphs.model.CatchToken)11 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)6 LabelledStatement (org.eclipse.n4js.n4JS.LabelledStatement)6 VariableDeclarationOrBinding (org.eclipse.n4js.n4JS.VariableDeclarationOrBinding)3 AbstractCaseClause (org.eclipse.n4js.n4JS.AbstractCaseClause)2 CaseClause (org.eclipse.n4js.n4JS.CaseClause)2 Statement (org.eclipse.n4js.n4JS.Statement)2 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)1 DelegatingNode (org.eclipse.n4js.flowgraphs.model.DelegatingNode)1 JumpToken (org.eclipse.n4js.flowgraphs.model.JumpToken)1 BindingElement (org.eclipse.n4js.n4JS.BindingElement)1 CatchBlock (org.eclipse.n4js.n4JS.CatchBlock)1 DefaultClause (org.eclipse.n4js.n4JS.DefaultClause)1 FinallyBlock (org.eclipse.n4js.n4JS.FinallyBlock)1 ScriptElement (org.eclipse.n4js.n4JS.ScriptElement)1