use of org.eclipse.n4js.n4JS.AbstractCaseClause 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.n4JS.AbstractCaseClause 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;
}
use of org.eclipse.n4js.n4JS.AbstractCaseClause in project n4js by eclipse.
the class SwitchStatementImpl method getDefaultClause.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public DefaultClause getDefaultClause() {
final Function1<AbstractCaseClause, Boolean> _function = new Function1<AbstractCaseClause, Boolean>() {
public Boolean apply(final AbstractCaseClause it) {
return Boolean.valueOf((it instanceof DefaultClause));
}
};
AbstractCaseClause _findFirst = IterableExtensions.<AbstractCaseClause>findFirst(this.getCases(), _function);
return ((DefaultClause) _findFirst);
}
Aggregations