use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class DoWhileFactory method buildComplexNode.
static ComplexNode buildComplexNode(ReentrantASTIterator astpp, DoStatement doStmt) {
ComplexNode cNode = new ComplexNode(astpp.container(), doStmt);
Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), doStmt);
Node bodyNode = DelegatingNodeFactory.create(astpp, NodeNames.BODY, doStmt, doStmt.getStatement());
Node conditionNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.CONDITION, doStmt, doStmt.getExpression());
Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), doStmt);
Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), doStmt);
cNode.addNode(entryNode);
cNode.addNode(bodyNode);
cNode.addNode(conditionNode);
cNode.addNode(conditionForkNode);
cNode.addNode(exitNode);
cNode.connectInternalSucc(entryNode, bodyNode, conditionNode, conditionForkNode);
cNode.connectInternalSucc(ControlFlowType.LoopReenter, conditionForkNode, bodyNode);
cNode.connectInternalSucc(ControlFlowType.LoopExit, conditionForkNode, exitNode);
cNode.setEntryNode(entryNode);
cNode.setExitNode(exitNode);
// catch for short-circuits
conditionForkNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
exitNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse, ControlFlowType.LoopExit));
LabelledStatement lblStmt = ASTUtils.getLabelledStatement(doStmt);
exitNode.addCatchToken(new CatchToken(ControlFlowType.Break, lblStmt));
conditionNode.addCatchToken(new CatchToken(ControlFlowType.Continue, lblStmt));
return cNode;
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class EmptyStatementFactory method buildComplexNode.
static ComplexNode buildComplexNode(ReentrantASTIterator astpp, Statement empty) {
ComplexNode cNode = new ComplexNode(astpp.container(), empty);
Node entryAndExitNode = new RepresentingNode(NodeNames.ENTRY_EXIT, astpp.pos(), empty);
cNode.addNode(entryAndExitNode);
cNode.setEntryNode(entryAndExitNode);
cNode.setExitNode(entryAndExitNode);
return cNode;
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class IfFactory method buildComplexNode.
static ComplexNode buildComplexNode(ReentrantASTIterator astpp, IfStatement ifStmt) {
ComplexNode cNode = new ComplexNode(astpp.container(), ifStmt);
Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), ifStmt);
Node conditionNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.CONDITION, ifStmt, ifStmt.getExpression());
Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), ifStmt);
Node thenNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.THEN, ifStmt, ifStmt.getIfStmt());
Node elseNode = DelegatingNodeFactory.create(astpp, NodeNames.ELSE, ifStmt, ifStmt.getElseStmt());
Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), ifStmt);
cNode.addNode(entryNode);
cNode.addNode(conditionNode);
cNode.addNode(conditionForkNode);
cNode.addNode(thenNode);
cNode.addNode(elseNode);
cNode.addNode(exitNode);
cNode.connectInternalSucc(entryNode, conditionNode, conditionForkNode);
cNode.connectInternalSucc(ControlFlowType.IfTrue, conditionForkNode, thenNode);
cNode.connectInternalSucc(thenNode, exitNode);
// catch for short-circuits
thenNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
if (ifStmt.getElseStmt() == null) {
cNode.connectInternalSucc(ControlFlowType.IfFalse, conditionForkNode, exitNode);
// catch for short-circuits
exitNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse));
} else {
cNode.connectInternalSucc(ControlFlowType.IfFalse, conditionForkNode, elseNode);
cNode.connectInternalSucc(elseNode, exitNode);
// catch for short-circuits
elseNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse));
}
cNode.setEntryNode(entryNode);
cNode.setExitNode(exitNode);
return cNode;
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class ControlFlowGraphFactory method isExitingFinallyBlock.
private static boolean isExitingFinallyBlock(ComplexNodeMapper cnMapper, Node node) {
ControlFlowElement cfe = node.getControlFlowElement();
ComplexNode cn = cnMapper.get(cfe);
boolean isExitingFinallyBlock = true;
isExitingFinallyBlock &= cfe instanceof Block;
isExitingFinallyBlock &= cfe.eContainer() instanceof FinallyBlock;
isExitingFinallyBlock &= cn.getExit() == node;
return isExitingFinallyBlock;
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class ControlFlowGraphFactory method printAllEdgeDetails.
/**
* Prints detailed information of all control flow edges. Used for debugging purposes
*/
private static void printAllEdgeDetails(ComplexNodeMapper cnMapper) {
// TODO move this to a PrintUtils class
System.out.println("\nAll edges:");
Set<ControlFlowEdge> allEdges = new HashSet<>();
for (ComplexNode cn : cnMapper.getAll()) {
for (Node n : cn.getNodes()) {
allEdges.addAll(n.pred);
allEdges.addAll(n.succ);
}
}
for (ControlFlowEdge edge : allEdges) {
System.out.println(edge);
}
}
Aggregations