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;
}
Aggregations