use of org.eclipse.n4js.n4JS.ControlFlowElement 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.n4JS.ControlFlowElement 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.n4JS.ControlFlowElement 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);
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class ASTUtils method getNodeDetailString.
/**
* Returns a detailed string about the given node
*/
public static String getNodeDetailString(Node node) {
ControlFlowElement nCFE = node.getControlFlowElement();
String edgeStr = FGUtils.getClassName(nCFE) + ":" + node.name + ":" + FGUtils.getSourceText(nCFE);
return edgeStr;
}
use of org.eclipse.n4js.n4JS.ControlFlowElement in project n4js by eclipse.
the class CFGraph method layout.
@Override
public void layout(GC gc) {
if (layoutDone)
return;
int lastLine = 0;
int posInLine = 70;
int lineCounter = 0;
int entryLineCounter = 0;
Set<Entry<CFNode, ControlFlowElement>> entries = nodeMap.entrySet();
Iterator<Entry<CFNode, ControlFlowElement>> entriesIt = entries.iterator();
CFNode lastNode = null;
while (entriesIt.hasNext()) {
Entry<CFNode, ControlFlowElement> entry = entriesIt.next();
CFNode node = entry.getKey();
ControlFlowElement cfe = entry.getValue();
int line = getLineEnd(cfe);
boolean lineChange = lastLine != line;
if (lineChange) {
posInLine = 70;
boolean lastIsContainer = lastNode != null && (lastNode.isEntry || lastNode.isExit);
boolean isContainer = node.isEntry || node.isExit;
if (!lastIsContainer && !isContainer) {
// normal lines
lineCounter++;
}
if (lastIsContainer && isContainer) {
// lines between two functions
lineCounter += 2;
}
if (node.isExit && entryLineCounter == lineCounter) {
// line iff function consists of one line only
lineCounter++;
}
}
node.x = node.isEntry || node.isExit ? 0 : posInLine;
node.y = lineCounter * 100;
node.trim(gc);
posInLine += node.width + 50;
lastNode = node;
lastLine = line;
if (node.isEntry) {
entryLineCounter = lineCounter;
}
}
layoutDone = true;
}
Aggregations