Search in sources :

Example 11 with CatchToken

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

CatchToken (org.eclipse.n4js.flowgraphs.model.CatchToken)11 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)11 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)11 Node (org.eclipse.n4js.flowgraphs.model.Node)11 LinkedList (java.util.LinkedList)6 LabelledStatement (org.eclipse.n4js.n4JS.LabelledStatement)6 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)2 VariableDeclarationOrBinding (org.eclipse.n4js.n4JS.VariableDeclarationOrBinding)2 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)1 JumpToken (org.eclipse.n4js.flowgraphs.model.JumpToken)1 AbstractCaseClause (org.eclipse.n4js.n4JS.AbstractCaseClause)1 CaseClause (org.eclipse.n4js.n4JS.CaseClause)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 Statement (org.eclipse.n4js.n4JS.Statement)1