use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class ControlFlowGraphFactory method augmentDataflowInformation.
/**
* see {@link N4JSFlowAnalyser#augmentEffectInformation()}
*/
public static void augmentDataflowInformation(FlowGraph fg, SymbolFactory symbolFactory) {
Map<ControlFlowElement, ComplexNode> cnMap = fg.getMap();
for (Map.Entry<ControlFlowElement, ComplexNode> entry : cnMap.entrySet()) {
ControlFlowElement cfe = entry.getKey();
ComplexNode cn = entry.getValue();
CFEEffectInfos.set(symbolFactory, cnMap, cn, cfe);
}
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class ControlFlowGraphFactory method build.
/**
* Builds and returns a control flow graph from a given {@link Script}.
*/
public static FlowGraph build(Script script) {
Set<ControlFlowElement> cfContainers = new LinkedHashSet<>();
Map<ControlFlowElement, ComplexNode> cnMap = new HashMap<>();
String uriString = script.eResource().getURI().toString();
ComplexNodeMapper cnMapper = null;
try (ClosableMeasurement m = dcCreateNodes.getClosableMeasurement("createNodes_" + uriString)) {
createComplexNodes(script, cfContainers, cnMap);
cnMapper = new ComplexNodeMapper(cnMap);
}
try (ClosableMeasurement m = dcConnectNodes.getClosableMeasurement("connectNodes_" + uriString)) {
connectComplexNodes(cnMapper);
}
try (ClosableMeasurement m = dcJumpEdges.getClosableMeasurement("jumpEdges_" + uriString)) {
createJumpEdges(cnMapper);
}
FlowGraph cfg = new FlowGraph(script, cfContainers, cnMap);
if (PRINT_EDGE_DETAILS)
printAllEdgeDetails(cnMapper);
return cfg;
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class ForFactory method buildForPlain.
private static ComplexNode buildForPlain(ReentrantASTIterator astpp, ForStatement forStmt) {
ComplexNode cNode = new ComplexNode(astpp.container(), forStmt);
List<Node> initNodes = new LinkedList<>();
Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), forStmt);
Node conditionNode = null;
Node bodyNode = null;
Node updatesNode = null;
if (forStmt.getVarDeclsOrBindings() != null) {
int i = 0;
for (VariableDeclarationOrBinding vdob : forStmt.getVarDeclsOrBindings()) {
Node initNode = DelegatingNodeFactory.create(astpp, "init_" + i, forStmt, vdob);
initNodes.add(initNode);
i++;
}
}
if (forStmt.getInitExpr() != null) {
Node initNode = DelegatingNodeFactory.create(astpp, NodeNames.INITS, forStmt, forStmt.getInitExpr());
initNodes.add(initNode);
}
if (forStmt.getExpression() != null) {
conditionNode = DelegatingNodeFactory.create(astpp, NodeNames.CONDITION, forStmt, forStmt.getExpression());
}
Node conditionForkNode = new HelperNode(NodeNames.CONDITION_FORK, astpp.pos(), forStmt);
bodyNode = DelegatingNodeFactory.createOrHelper(astpp, NodeNames.BODY, forStmt, forStmt.getStatement());
Node continueCatchNode = new HelperNode(NodeNames.CONTINUE_CATCH, astpp.pos(), forStmt);
if (forStmt.getUpdateExpr() != null) {
updatesNode = DelegatingNodeFactory.create(astpp, NodeNames.UPDATES, forStmt, forStmt.getUpdateExpr());
}
Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), forStmt);
cNode.addNode(entryNode);
cNode.addNode(exitNode);
for (Node initNode : initNodes) cNode.addNode(initNode);
cNode.addNode(conditionNode);
cNode.addNode(conditionForkNode);
cNode.addNode(bodyNode);
cNode.addNode(continueCatchNode);
cNode.addNode(updatesNode);
List<Node> nodes = new LinkedList<>();
nodes.add(entryNode);
nodes.addAll(initNodes);
nodes.add(conditionNode);
nodes.add(conditionForkNode);
cNode.connectInternalSucc(nodes);
cNode.connectInternalSucc(ControlFlowType.LoopEnter, conditionForkNode, bodyNode);
if (conditionNode != null) {
cNode.connectInternalSucc(ControlFlowType.LoopExit, conditionForkNode, exitNode);
cNode.connectInternalSucc(bodyNode, continueCatchNode, updatesNode);
Node beforeConditionNode = ListUtils.filterNulls(bodyNode, continueCatchNode, updatesNode).getLast();
cNode.connectInternalSucc(ControlFlowType.LoopRepeat, beforeConditionNode, conditionNode);
} else {
cNode.connectInternalSucc(bodyNode, continueCatchNode, updatesNode);
LinkedList<Node> loopCycle = ListUtils.filterNulls(continueCatchNode, updatesNode);
Node loopSrc = loopCycle.getLast();
cNode.connectInternalSucc(ControlFlowType.LoopInfinite, loopSrc, conditionForkNode);
cNode.connectInternalSucc(ControlFlowType.DeadCode, loopSrc, exitNode);
}
// catch for short-circuits
conditionForkNode.addCatchToken(new CatchToken(ControlFlowType.IfTrue));
exitNode.addCatchToken(new CatchToken(ControlFlowType.IfFalse, ControlFlowType.LoopExit));
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;
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class JumpFactory method buildComplexNode.
static ComplexNode buildComplexNode(ReentrantASTIterator astpp, Statement stmt, Expression expr, JumpToken jumptoken) {
ComplexNode cNode = new ComplexNode(astpp.container(), stmt);
Node entryNode = new HelperNode(NodeNames.ENTRY, astpp.pos(), stmt);
cNode.addNode(entryNode);
Node expression = null;
if (expr != null) {
expression = DelegatingNodeFactory.create(astpp, NodeNames.EXPRESSION, stmt, expr);
cNode.addNode(expression);
}
Node jumpNode = new RepresentingNode(NodeNames.JUMP, astpp.pos(), stmt);
cNode.addNode(jumpNode);
Node exitNode = new HelperNode(NodeNames.EXIT, astpp.pos(), stmt);
cNode.addNode(exitNode);
List<Node> cfs = new LinkedList<>();
cfs.add(entryNode);
cfs.add(expression);
cNode.connectInternalSucc(entryNode, expression);
Node beforeDeadNode = ListUtils.filterNulls(entryNode, expression).getLast();
cNode.connectInternalSucc(beforeDeadNode, jumpNode);
cNode.connectInternalSucc(ControlFlowType.DeadCode, jumpNode, exitNode);
jumpNode.addJumpToken(jumptoken);
cNode.setEntryNode(entryNode);
cNode.setExitNode(exitNode);
cNode.setJumpNode(jumpNode);
return cNode;
}
use of org.eclipse.n4js.flowgraphs.model.ComplexNode in project n4js by eclipse.
the class ReentrantASTIterator method visitUtil.
/**
* Creates {@link ComplexNode}s for every {@link ControlFlowElement}.
*/
public void visitUtil(ControlFlowElement termNode) {
termNode = CFEMapper.map(termNode);
while (astIt.hasNext()) {
ControlFlowElement cfe = astIt.next();
ControlFlowElement mappedCFE = CFEMapper.map(cfe);
if (cfe == mappedCFE) {
if (mappedCFE != null && !cnMap.containsKey(mappedCFE)) {
ComplexNode cn = CFEFactoryDispatcher.build(this, mappedCFE);
if (cn != null) {
checkState(astPositionCounter - 1 == cn.getExit().astPosition, ASSERTION_MSG_AST_ORDER);
cfContainers.add(cn.getControlFlowContainer());
cnMap.put(mappedCFE, cn);
}
}
if (termNode == cfe || (termNode == mappedCFE && termNode != null)) {
return;
}
}
}
checkState(termNode == null, ASSERTION_MSG_AST_ORDER);
}
Aggregations