Search in sources :

Example 11 with HelperNode

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

the class WhileFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, WhileStatement whileStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), whileStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), whileStmt);
    Node conditionNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.CONDITION, whileStmt, whileStmt.getExpression());
    Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), whileStmt);
    Node bodyNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.BODY, whileStmt, whileStmt.getStatement());
    Node continueCatchNode = new HelperNode(NodeNames.CONTINUE_CATCH, astpp.pos(), whileStmt);
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), whileStmt);
    cNode.addNode(entryNode);
    cNode.addNode(conditionNode);
    cNode.addNode(conditionForkNode);
    cNode.addNode(bodyNode);
    cNode.addNode(continueCatchNode);
    cNode.addNode(exitNode);
    cNode.connectInternalSucc(entryNode, conditionNode, conditionForkNode);
    cNode.connectInternalSucc(ControlFlowType.LoopEnter, conditionForkNode, bodyNode);
    cNode.connectInternalSucc(ControlFlowType.LoopExit, conditionForkNode, exitNode);
    cNode.connectInternalSucc(bodyNode, continueCatchNode);
    cNode.connectInternalSucc(ControlFlowType.LoopRepeat, continueCatchNode, conditionNode);
    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(whileStmt);
    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) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken)

Example 12 with HelperNode

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

the class BinaryLogicalExpressionFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, BinaryLogicalExpression lbExpr) {
    ComplexNode cNode = new ComplexNode(astpp.container(), lbExpr);
    HelperNode entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), lbExpr);
    Node lhsNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.LHS, lbExpr, lbExpr.getLhs());
    Node scJumpNode = new HelperNode(NodeNames.SHORT_CIRCUIT_JUMP, astpp.pos(), lbExpr);
    Node rhsNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.RHS, lbExpr, lbExpr.getRhs());
    Node exitNode = new RepresentingNode(NodeNames.EXIT, astpp.pos(), lbExpr);
    cNode.addNode(entryNode);
    cNode.addNode(lhsNode);
    cNode.addNode(scJumpNode);
    cNode.addNode(rhsNode);
    cNode.addNode(exitNode);
    ControlFlowType thenCFT = null;
    ControlFlowType elseCFT = null;
    switch(lbExpr.getOp()) {
        case OR:
            thenCFT = ControlFlowType.IfFalse;
            elseCFT = ControlFlowType.IfTrue;
            break;
        case AND:
            thenCFT = ControlFlowType.IfTrue;
            elseCFT = ControlFlowType.IfFalse;
            break;
    }
    cNode.connectInternalSucc(entryNode, lhsNode, scJumpNode);
    cNode.connectInternalSucc(thenCFT, scJumpNode, rhsNode);
    cNode.connectInternalSucc(rhsNode, exitNode);
    // short-circuit evaluation
    scJumpNode.addJumpToken(new JumpToken(elseCFT));
    cNode.setJumpNode(scJumpNode);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    rhsNode.addCatchToken(new CatchToken(thenCFT));
    boolean isCatchingLhs = isTopJumpCatcher(lbExpr);
    if (isCatchingLhs) {
        exitNode.addCatchToken(new CatchToken(elseCFT));
        exitNode.addCatchToken(new CatchToken(thenCFT));
    } else {
    // TODO: minor improvement: add the following jump node
    // exitNode.addJumpToken(new JumpToken(thenCFT)); // short-circuit evaluation
    // cNode.setJumpNode(scJumpNode);
    }
    return cNode;
}
Also used : JumpToken(org.eclipse.n4js.flowgraphs.model.JumpToken) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ControlFlowType(org.eclipse.n4js.flowgraphs.ControlFlowType) 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) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken)

Example 13 with HelperNode

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

the class AbstractCaseClauseFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, AbstractCaseClause abstrCaseClause) {
    ComplexNode cNode = new ComplexNode(astpp.container(), abstrCaseClause);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), abstrCaseClause);
    List<Node> stmtNodes = new LinkedList<>();
    Node caseConditionNode = null;
    if (abstrCaseClause instanceof CaseClause) {
        CaseClause caseClause = (CaseClause) abstrCaseClause;
        caseConditionNode = DelegatingNodeFactory.create(astpp, NodeNames.CONDITION, caseClause, caseClause.getExpression());
    }
    EList<Statement> stmts = abstrCaseClause.getStatements();
    for (int i = 0; i < stmts.size(); i++) {
        Statement stmt = stmts.get(i);
        Node blockNode = new DelegatingNode("stmt_" + i, astpp.pos(), abstrCaseClause, stmt);
        stmtNodes.add(blockNode);
        astpp.visitUtil(blockNode.getDelegatedControlFlowElement());
    }
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), abstrCaseClause);
    cNode.addNode(entryNode);
    cNode.addNode(caseConditionNode);
    for (Node blockNode : stmtNodes) cNode.addNode(blockNode);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.add(caseConditionNode);
    nodes.addAll(stmtNodes);
    nodes.add(exitNode);
    cNode.connectInternalSucc(nodes);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Statement(org.eclipse.n4js.n4JS.Statement) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) DelegatingNode(org.eclipse.n4js.flowgraphs.model.DelegatingNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) Node(org.eclipse.n4js.flowgraphs.model.Node) CaseClause(org.eclipse.n4js.n4JS.CaseClause) AbstractCaseClause(org.eclipse.n4js.n4JS.AbstractCaseClause) DelegatingNode(org.eclipse.n4js.flowgraphs.model.DelegatingNode) LinkedList(java.util.LinkedList)

Example 14 with HelperNode

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

the class BlockFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, org.eclipse.n4js.n4JS.Block block) {
    ComplexNode cNode = new ComplexNode(astpp.container(), block);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), block);
    List<Node> blockNodes = new LinkedList<>();
    EList<Statement> stmts = block.getStatements();
    for (int i = 0; i < stmts.size(); i++) {
        Statement stmt = stmts.get(i);
        Node blockNode = DelegatingNodeFactory.create(astpp, "stmt_" + i, block, stmt);
        blockNodes.add(blockNode);
    }
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), block);
    cNode.addNode(entryNode);
    for (Node blockNode : blockNodes) cNode.addNode(blockNode);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.addAll(blockNodes);
    nodes.add(exitNode);
    cNode.connectInternalSucc(nodes);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    if (FGUtils.isCFContainer(block)) {
        exitNode.addCatchToken(new CatchToken(ControlFlowType.CatchesAll));
    } else {
        LabelledStatement lblStmt = ASTUtils.getLabelledStatement(block);
        if (lblStmt != null) {
            exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
        }
    }
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Statement(org.eclipse.n4js.n4JS.Statement) LabelledStatement(org.eclipse.n4js.n4JS.LabelledStatement) 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) LinkedList(java.util.LinkedList)

Example 15 with HelperNode

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

the class ForFactory method buildForInOf.

private static ComplexNode buildForInOf(ReentrantASTIterator astpp, ForStatement forStmt, boolean forInSemantics) {
    ComplexNode cNode = new ComplexNode(astpp.container(), forStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), forStmt);
    List<Node> declNodes = new LinkedList<>();
    List<Node> initNodes = new LinkedList<>();
    if (forStmt.getVarDeclsOrBindings() != null) {
        int i = 0;
        for (VariableDeclarationOrBinding vdob : forStmt.getVarDeclsOrBindings()) {
            Node initNode = DelegatingNodeFactory.create(astpp, "decl_" + i, forStmt, vdob);
            declNodes.add(initNode);
            i++;
        }
    }
    if (forStmt.getInitExpr() != null) {
        Node initNode = DelegatingNodeFactory.create(astpp, NodeNames.INITS, forStmt, forStmt.getInitExpr());
        initNodes.add(initNode);
    }
    Node expressionNode = DelegatingNodeFactory.create(astpp, NodeNames.EXPRESSION, forStmt, forStmt.getExpression());
    Node getObjectKeysNode = null;
    if (forInSemantics) {
        getObjectKeysNode = new HelperNode(NodeNames.GET_OBJECT_KEYS, astpp.pos(), forStmt);
    }
    Node getIteratorNode = new HelperNode(NodeNames.GET_ITERATOR, astpp.pos(), forStmt);
    Node hasNextNode = new HelperNode(NodeNames.HAS_NEXT, astpp.pos(), forStmt);
    Node nextNode = new HelperNode(NodeNames.NEXT, astpp.pos(), forStmt);
    Node bodyNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.BODY, forStmt, forStmt.getStatement());
    Node continueCatchNode = new HelperNode(NodeNames.CONTINUE_CATCH, astpp.pos(), forStmt);
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), forStmt);
    cNode.addNode(entryNode);
    for (Node declNode : declNodes) cNode.addNode(declNode);
    for (Node initNode : initNodes) cNode.addNode(initNode);
    cNode.addNode(expressionNode);
    cNode.addNode(getObjectKeysNode);
    cNode.addNode(getIteratorNode);
    cNode.addNode(hasNextNode);
    cNode.addNode(nextNode);
    cNode.addNode(bodyNode);
    cNode.addNode(continueCatchNode);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.addAll(declNodes);
    nodes.addAll(initNodes);
    nodes.add(expressionNode);
    nodes.add(getObjectKeysNode);
    nodes.add(getIteratorNode);
    nodes.add(hasNextNode);
    cNode.connectInternalSucc(nodes);
    cNode.connectInternalSucc(ControlFlowType.LoopExit, hasNextNode, exitNode);
    cNode.connectInternalSucc(ControlFlowType.LoopEnter, hasNextNode, nextNode);
    cNode.connectInternalSucc(nextNode, bodyNode, continueCatchNode);
    cNode.connectInternalSucc(ControlFlowType.LoopRepeat, continueCatchNode, hasNextNode);
    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)

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