Search in sources :

Example 21 with ControlFlowElement

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);
    }
}
Also used : ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with ControlFlowElement

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) HashMap(java.util.HashMap) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) FlowGraph(org.eclipse.n4js.flowgraphs.model.FlowGraph) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 23 with ControlFlowElement

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);
}
Also used : ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 24 with ControlFlowElement

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;
}
Also used : ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 25 with ControlFlowElement

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;
}
Also used : Entry(java.util.Map.Entry) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Aggregations

ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)52 EObject (org.eclipse.emf.ecore.EObject)12 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)12 LinkedList (java.util.LinkedList)10 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)10 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)9 Xpect (org.eclipse.xpect.runner.Xpect)9 Node (org.eclipse.n4js.flowgraphs.model.Node)8 HashSet (java.util.HashSet)7 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)5 ControlFlowEdge (org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)4 HashMap (java.util.HashMap)3 FlowEdge (org.eclipse.n4js.flowgraphs.FlowEdge)3 FinallyBlock (org.eclipse.n4js.n4JS.FinallyBlock)3 LinkedHashSet (java.util.LinkedHashSet)2 N4JSFlowAnalyser (org.eclipse.n4js.flowgraphs.N4JSFlowAnalyser)2 Assumption (org.eclipse.n4js.flowgraphs.dataflow.Assumption)2 Symbol (org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol)2 Block (org.eclipse.n4js.n4JS.Block)2 ExpressionStatement (org.eclipse.n4js.n4JS.ExpressionStatement)2