Search in sources :

Example 1 with ControlFlowEdge

use of org.eclipse.n4js.flowgraphs.model.ControlFlowEdge in project n4js by eclipse.

the class FlowgraphsXpectMethod method allMergeBranches.

/**
 * This xpect method can evaluate all branches that are merged at the given node name.
 */
@ParameterParser(syntax = "('pleaseNeverUseThisParameterSinceItExistsOnlyToGetAReferenceOffset' arg1=OFFSET)?")
@Xpect
public void allMergeBranches(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion referenceOffset) {
    N4JSFlowAnalyserDataRecorder.setEnabled(true);
    GraphVisitor dfv = new DummyForwardVisitor();
    GraphVisitor dbv = new DummyBackwardVisitor();
    ControlFlowElement referenceCFE = getCFE(referenceOffset);
    getFlowAnalyzer(referenceCFE).accept(dfv, dbv);
    N4JSFlowAnalyserDataRecorder.setEnabled(false);
    performBranchAnalysis(referenceOffset, null, referenceOffset);
    List<String> edgeStrings = new LinkedList<>();
    int groupIdx = 0;
    List<Pair<Node, List<ControlFlowEdge>>> mergedEdges = N4JSFlowAnalyserDataRecorder.getMergedEdges();
    for (Pair<Node, List<ControlFlowEdge>> pair : mergedEdges) {
        Node startNode = pair.getKey();
        List<ControlFlowEdge> edges = pair.getValue();
        for (ControlFlowEdge edge : edges) {
            String c = edge.start == startNode ? "B" : "F";
            edgeStrings.add(c + groupIdx + ": " + edge.toString());
        }
        groupIdx++;
    }
    Collections.sort(edgeStrings);
    expectation.assertEquals(edgeStrings);
}
Also used : DummyBackwardVisitor(org.eclipse.n4js.flowgraphs.analysers.DummyBackwardVisitor) GraphVisitor(org.eclipse.n4js.flowgraphs.analysis.GraphVisitor) Node(org.eclipse.n4js.flowgraphs.model.Node) DummyForwardVisitor(org.eclipse.n4js.flowgraphs.analysers.DummyForwardVisitor) LinkedList(java.util.LinkedList) ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) LinkedList(java.util.LinkedList) List(java.util.List) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) Pair(org.eclipse.xtext.xbase.lib.Pair) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 2 with ControlFlowEdge

use of org.eclipse.n4js.flowgraphs.model.ControlFlowEdge in project n4js by eclipse.

the class NextEdgesProvider method filter.

/**
 * Filters out all {@literal ControlFlowType.Repeat} edges iff they were traversed twice already, and filters out
 * all edges whose {@link ControlFlowType} is not in the given set {@code cfTypes} iff {@code cfTypes} is neither
 * null nor empty.
 */
protected List<ControlFlowEdge> filter(Iterable<ControlFlowEdge> edges, ControlFlowType... flowTypes) {
    // copy of the original pred/succ list of Node
    List<ControlFlowEdge> filteredEdges = new LinkedList<>();
    for (ControlFlowEdge cfEdge : edges) {
        boolean copyEdge = true;
        int maxOccurences = getMaxOccurences(cfEdge.cfType);
        if (maxOccurences > 0) {
            copyEdge = getOccurences(cfEdge) < maxOccurences;
            incrOccurence(cfEdge);
        }
        if (copyEdge && cfEdge.cfType.isInOrEmpty(flowTypes)) {
            filteredEdges.add(cfEdge);
        }
    }
    return filteredEdges;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) LinkedList(java.util.LinkedList)

Example 3 with ControlFlowEdge

use of org.eclipse.n4js.flowgraphs.model.ControlFlowEdge in project n4js by eclipse.

the class NextEdgesProvider method join.

protected void join(NextEdgesProvider edgesProvider) {
    for (Map.Entry<ControlFlowEdge, Integer> repeatCounter : edgesProvider.loopEnterEdges.entrySet()) {
        ControlFlowEdge edge = repeatCounter.getKey();
        Integer otherCount = repeatCounter.getValue();
        int myCount = getOccurences(edge);
        int newCount = Math.max(myCount, otherCount);
        loopEnterEdges.put(edge, newCount);
    }
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ControlFlowEdge

use of org.eclipse.n4js.flowgraphs.model.ControlFlowEdge in project n4js by eclipse.

the class Path method walkMe.

private void walkMe(IPathWalkerInternal walker) {
    walker.visitNode(start);
    for (ControlFlowEdge edge : edges) {
        Node bNode = nextEdgesProvider.getPrevNode(edge);
        Node fNode = nextEdgesProvider.getNextNode(edge);
        walker.visitEdge(bNode, fNode, edge);
        walker.visitNode(fNode);
    }
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) Node(org.eclipse.n4js.flowgraphs.model.Node)

Example 5 with ControlFlowEdge

use of org.eclipse.n4js.flowgraphs.model.ControlFlowEdge in project n4js by eclipse.

the class DirectPathAnalyses method getPaths.

private LinkedList<LinkedList<ControlFlowEdge>> getPaths(NextEdgesProvider edgeProvider, LinkedList<ControlFlowEdge> path, Node notVia) {
    LinkedList<LinkedList<ControlFlowEdge>> resultPaths = new LinkedList<>();
    ControlFlowEdge e = path.getLast();
    Node nextNode = edgeProvider.getNextNode(e);
    List<ControlFlowEdge> nextEdges = edgeProvider.getNextEdges(nextNode, ControlFlowType.NonDeadTypes);
    for (ControlFlowEdge nextEdge : nextEdges) {
        Node uberNextNode = edgeProvider.getNextNode(nextEdge);
        if (notVia != null && notVia == uberNextNode) {
            // skip edges that target the notVia node
            continue;
        }
        LinkedList<ControlFlowEdge> pathCopy = path;
        if (nextEdges.size() > 1)
            pathCopy = Lists.newLinkedList(pathCopy);
        pathCopy.add(nextEdge);
        resultPaths.add(pathCopy);
    }
    return resultPaths;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) LinkedList(java.util.LinkedList)

Aggregations

ControlFlowEdge (org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)16 LinkedList (java.util.LinkedList)9 Node (org.eclipse.n4js.flowgraphs.model.Node)8 HashSet (java.util.HashSet)6 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)5 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)5 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DelegatingNode (org.eclipse.n4js.flowgraphs.model.DelegatingNode)2 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 FlowEdge (org.eclipse.n4js.flowgraphs.FlowEdge)1 DummyBackwardVisitor (org.eclipse.n4js.flowgraphs.analysers.DummyBackwardVisitor)1 DummyForwardVisitor (org.eclipse.n4js.flowgraphs.analysers.DummyForwardVisitor)1 GraphVisitor (org.eclipse.n4js.flowgraphs.analysis.GraphVisitor)1 JumpToken (org.eclipse.n4js.flowgraphs.model.JumpToken)1 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)1 Xpect (org.eclipse.xpect.runner.Xpect)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1