Search in sources :

Example 1 with FlowGraph

use of org.eclipse.n4js.flowgraphs.model.FlowGraph 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)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)1 FlowGraph (org.eclipse.n4js.flowgraphs.model.FlowGraph)1 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)1 ClosableMeasurement (org.eclipse.n4js.smith.ClosableMeasurement)1