use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class BlockFactory method buildComplexNode.
static ComplexNode buildComplexNode(ReentrantASTIterator astpp, org.eclipse.n4js.n4JS.Block block) {
ComplexNode cNode = new ComplexNode(astpp.container(), block);
Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), block);
List<Node> blockNodes = new LinkedList<>();
EList<Statement> stmts = block.getStatements();
for (int i = 0; i < stmts.size(); i++) {
Statement stmt = stmts.get(i);
Node blockNode = DelegatingNodeFactory.create(astpp, "stmt_" + i, block, stmt);
blockNodes.add(blockNode);
}
Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), block);
cNode.addNode(entryNode);
for (Node blockNode : blockNodes) cNode.addNode(blockNode);
cNode.addNode(exitNode);
List<Node> nodes = new LinkedList<>();
nodes.add(entryNode);
nodes.addAll(blockNodes);
nodes.add(exitNode);
cNode.connectInternalSucc(nodes);
cNode.setEntryNode(entryNode);
cNode.setExitNode(exitNode);
if (FGUtils.isCFContainer(block)) {
exitNode.addCatchToken(new CatchToken(ControlFlowType.CatchesAll));
} else {
LabelledStatement lblStmt = ASTUtils.getLabelledStatement(block);
if (lblStmt != null) {
exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
}
}
return cNode;
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class ControlFlowGraphFactory method connectNode.
/**
* Connects all nodes based on
* <ul>
* <li/>the delegating nodes, and
* <li/>the internal successor information of each node.
* </ul>
*/
private static void connectNode(ComplexNodeMapper cnMapper, Node mNode) {
Node internalStartNode = mNode;
ControlFlowElement subASTElem = mNode.getDelegatedControlFlowElement();
if (subASTElem != null) {
ComplexNode subCN = cnMapper.get(subASTElem);
if (subCN != null) {
// can be null in case of malformed AST
EdgeUtils.connectCF(mNode, subCN.getEntry());
internalStartNode = subCN.getExit();
}
}
Set<Node> internalSuccs = mNode.getInternalSuccessors();
for (Node internalSucc : internalSuccs) {
ControlFlowType cfType = mNode.getInternalSuccessorControlFlowType(internalSucc);
EdgeUtils.connectCF(internalStartNode, internalSucc, cfType);
}
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class ControlFlowGraphFactory method connectToJumpTarget.
private static void connectToJumpTarget(ComplexNodeMapper cnMapper, Node jumpNode, JumpToken jumpToken) {
Pair<Node, ControlFlowType> catcher = CatchNodeFinder.find(jumpToken, jumpNode, cnMapper);
if (catcher == null) {
String jumpTokenStr = getJumpTokenDetailString(jumpToken, jumpNode);
System.err.println("Could not find catching node for jump token '" + jumpTokenStr + "'");
return;
}
Node catchNode = catcher.getKey();
ControlFlowType newEdgeType = catcher.getValue();
FinallyBlock enteringFinallyBlock = getEnteringFinallyBlock(catchNode);
boolean isExitingFinallyBlock = isExitingFinallyBlock(cnMapper, jumpNode);
if (enteringFinallyBlock != null || isExitingFinallyBlock) {
boolean equalEdgeExistsAlready = equalEdgeExistsAlready(jumpNode, jumpToken, catchNode);
if (!equalEdgeExistsAlready) {
EdgeUtils.connectCF(jumpNode, catchNode, jumpToken);
}
} else {
EdgeUtils.connectCF(jumpNode, catchNode, newEdgeType);
}
if (enteringFinallyBlock != null) {
// Iff finally block was entered abruptly, jump on from exit of finally block
Block block = enteringFinallyBlock.getBlock();
ComplexNode cnBlock = cnMapper.get(block);
Node exitFinallyBlock = cnBlock.getExit();
connectToJumpTarget(cnMapper, exitFinallyBlock, jumpToken);
}
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class ControlFlowGraphFactory method removeNode.
private static void removeNode(ComplexNode cn, Node mNode) {
ControlFlowEdge e1 = mNode.pred.first();
ControlFlowEdge e2 = mNode.succ.first();
Node pred = e1.start;
Node succ = e2.end;
EdgeUtils.removeCF(e1);
EdgeUtils.removeCF(e2);
cn.removeNodeChecks(mNode);
cn.removeNode(mNode);
for (Node intPred : mNode.getInternalPredecessors()) {
intPred.removeInternalSuccessor(mNode);
}
for (Node intSucc : mNode.getInternalSuccessors()) {
intSucc.removeInternalPredecessor(mNode);
}
mNode.getInternalPredecessors().clear();
mNode.getInternalSuccessors().clear();
EdgeUtils.connectCF(pred, succ);
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode 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