Search in sources :

Example 6 with HelperNode

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

the class ScriptFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, Script script) {
    ComplexNode cNode = new ComplexNode(astpp.container(), script);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), script);
    List<Node> scriptNodes = new LinkedList<>();
    EList<ScriptElement> scriptElems = script.getScriptElements();
    for (int n = 0; n < scriptElems.size(); n++) {
        ScriptElement scriptElem = getScriptElementAt(script, n);
        if (isControlFlowStatement(scriptElem)) {
            Node blockNode = DelegatingNodeFactory.create(astpp, "stmt_" + n, script, (Statement) scriptElem);
            scriptNodes.add(blockNode);
        }
    }
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), script);
    cNode.addNode(entryNode);
    for (Node scriptNode : scriptNodes) cNode.addNode(scriptNode);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.addAll(scriptNodes);
    nodes.add(exitNode);
    cNode.connectInternalSucc(nodes);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    exitNode.addCatchToken(new CatchToken(ControlFlowType.CatchesAll));
    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) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) ScriptElement(org.eclipse.n4js.n4JS.ScriptElement) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken) LinkedList(java.util.LinkedList)

Example 7 with HelperNode

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

the class SwitchFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, SwitchStatement switchStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), switchStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), switchStmt);
    Node pivotNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.PIVOT, switchStmt, switchStmt.getExpression());
    cNode.addNode(entryNode);
    cNode.addNode(pivotNode);
    List<Node> caseNodes = new LinkedList<>();
    // Assumption: clauses are ordered analog to the source code
    List<AbstractCaseClause> caseClauses = switchStmt.getCases();
    for (int n = 0; n < caseClauses.size(); n++) {
        AbstractCaseClause cc = caseClauses.get(n);
        Node caseNode = null;
        if (cc instanceof CaseClause) {
            caseNode = DelegatingNodeFactory.create(astpp, "case_" + n, switchStmt, cc);
        }
        if (cc instanceof DefaultClause) {
            caseNode = DelegatingNodeFactory.create(astpp, NodeNames.DEFAULT, switchStmt, cc);
        }
        caseNodes.add(caseNode);
        cNode.addNode(caseNode);
    }
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), switchStmt);
    cNode.addNode(exitNode);
    List<Node> cfs = new LinkedList<>();
    cfs.add(entryNode);
    cfs.add(pivotNode);
    cNode.connectInternalSucc(cfs);
    for (Node cnf : caseNodes) {
        cNode.connectInternalSucc(pivotNode, cnf);
    }
    cfs.clear();
    cfs.addAll(caseNodes);
    cfs.add(exitNode);
    // See {@link JumpFactory} how {@link BreakStatements} modify the control flow
    cNode.connectInternalSucc(cfs);
    if (switchStmt.getDefaultClause() == null)
        cNode.connectInternalSucc(pivotNode, exitNode);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    LabelledStatement lblStmt = ASTUtils.getLabelledStatement(switchStmt);
    exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
    return cNode;
}
Also used : DefaultClause(org.eclipse.n4js.n4JS.DefaultClause) 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) AbstractCaseClause(org.eclipse.n4js.n4JS.AbstractCaseClause) CaseClause(org.eclipse.n4js.n4JS.CaseClause) AbstractCaseClause(org.eclipse.n4js.n4JS.AbstractCaseClause) CatchToken(org.eclipse.n4js.flowgraphs.model.CatchToken) LinkedList(java.util.LinkedList)

Example 8 with HelperNode

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

the class TryFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, TryStatement tryStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), tryStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), tryStmt);
    Node tryNode = null;
    Node catchNode = null;
    Node finallyNode = null;
    if (tryStmt.getBlock() != null) {
        tryNode = DelegatingNodeFactory.create(astpp, NodeNames.TRY, tryStmt, tryStmt.getBlock());
    }
    if (tryStmt.getCatch() != null && tryStmt.getCatch().getBlock() != null) {
        CatchBlock catchClause = tryStmt.getCatch();
        CatchToken ct = new CatchToken(ControlFlowType.Throw);
        catchNode = DelegatingNodeFactory.create(astpp, NodeNames.CATCH, tryStmt, catchClause.getBlock());
        catchNode.addCatchToken(ct);
    }
    if (tryStmt.getFinally() != null && tryStmt.getFinally().getBlock() != null) {
        FinallyBlock finallyElem = tryStmt.getFinally();
        CatchToken ct = new CatchToken(ControlFlowType.CatchesAll);
        finallyNode = DelegatingNodeFactory.create(astpp, NodeNames.FINALLY, tryStmt, finallyElem.getBlock());
        finallyNode.addCatchToken(ct);
    }
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), tryStmt);
    cNode.addNode(entryNode);
    cNode.addNode(tryNode);
    cNode.addNode(catchNode);
    cNode.addNode(finallyNode);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.add(tryNode);
    nodes.add(finallyNode);
    nodes.add(exitNode);
    cNode.connectInternalSucc(nodes);
    // TODO: Consider to use a special edge type 'unsound'
    cNode.connectInternalSucc(entryNode, catchNode);
    LinkedList<Node> parts = ListUtils.filterNulls(finallyNode, exitNode);
    Node tgtFrgmt = parts.getFirst();
    // TODO: Consider to use a special edge type 'unsound'
    cNode.connectInternalSucc(tryNode, catchNode);
    cNode.connectInternalSucc(catchNode, tgtFrgmt);
    cNode.setEntryNode(entryNode);
    cNode.setExitNode(exitNode);
    return cNode;
}
Also used : HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) CatchBlock(org.eclipse.n4js.n4JS.CatchBlock) FinallyBlock(org.eclipse.n4js.n4JS.FinallyBlock) 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 9 with HelperNode

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

the class VariableStatementFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, VariableStatement varDeclStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), varDeclStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), varDeclStmt);
    List<Node> varDeclNodes = new LinkedList<>();
    for (int n = 0; n < varDeclStmt.getVarDeclsOrBindings().size(); n++) {
        VariableDeclarationOrBinding varDOB = varDeclStmt.getVarDeclsOrBindings().get(n);
        Node varDeclNode = DelegatingNodeFactory.create(astpp, "declaration_" + n, varDeclStmt, varDOB);
        varDeclNodes.add(varDeclNode);
    }
    Node exitNode = new RepresentingNode(NodeNames.EXIT, astpp.pos(), varDeclStmt);
    cNode.addNode(entryNode);
    for (Node varDeclNode : varDeclNodes) cNode.addNode(varDeclNode);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.addAll(varDeclNodes);
    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) 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) VariableDeclarationOrBinding(org.eclipse.n4js.n4JS.VariableDeclarationOrBinding) LinkedList(java.util.LinkedList)

Example 10 with HelperNode

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

the class WithFactory method buildComplexNode.

static ComplexNode buildComplexNode(ReentrantASTIterator astpp, WithStatement withStmt) {
    ComplexNode cNode = new ComplexNode(astpp.container(), withStmt);
    Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), withStmt);
    Node expressionNode = DelegatingNodeFactory.create(astpp, NodeNames.EXPRESSION, withStmt, withStmt.getExpression());
    Node statementNode = DelegatingNodeFactory.create(astpp, NodeNames.STATEMENT, withStmt, withStmt.getStatement());
    Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), withStmt);
    cNode.addNode(entryNode);
    cNode.addNode(expressionNode);
    cNode.addNode(statementNode);
    cNode.addNode(exitNode);
    List<Node> nodes = new LinkedList<>();
    nodes.add(entryNode);
    nodes.add(expressionNode);
    nodes.add(statementNode);
    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) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) HelperNode(org.eclipse.n4js.flowgraphs.model.HelperNode) Node(org.eclipse.n4js.flowgraphs.model.Node) 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