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