Search in sources :

Example 6 with ControlFlowEdge

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

the class EdgeGuide method getFirstEdgeGuides.

static List<EdgeGuide> getFirstEdgeGuides(ComplexNode cn, NextEdgesProvider edgeProvider, Collection<BranchWalkerInternal> activatedPaths) {
    List<EdgeGuide> nextEGs = new LinkedList<>();
    Node node = edgeProvider.getStartNode(cn);
    List<ControlFlowEdge> nextEdges = edgeProvider.getNextEdges(node);
    Iterator<ControlFlowEdge> nextEdgeIt = nextEdges.iterator();
    if (nextEdges.size() == 1) {
        ControlFlowEdge nextEdge = nextEdgeIt.next();
        EdgeGuide eg = new EdgeGuide(edgeProvider.copy(), nextEdge, activatedPaths);
        eg.deadContext.update(eg.getPrevNode());
        nextEGs.add(eg);
    }
    if (nextEdges.size() > 1) {
        while (nextEdgeIt.hasNext()) {
            ControlFlowEdge nextEdge = nextEdgeIt.next();
            Collection<BranchWalkerInternal> forkedPaths = new HashSet<>();
            for (BranchWalkerInternal aPath : activatedPaths) {
                BranchWalkerInternal forkedPath = aPath.callFork();
                forkedPaths.add(forkedPath);
            }
            EdgeGuide eg = new EdgeGuide(edgeProvider.copy(), nextEdge, forkedPaths);
            eg.deadContext.update(eg.getPrevNode());
            nextEGs.add(eg);
        }
    }
    return nextEGs;
}
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) HashSet(java.util.HashSet)

Example 7 with ControlFlowEdge

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

the class DataRecorderPackageProxy method addMergedEdges.

static void addMergedEdges(List<EdgeGuide> edgeGuides) {
    if (!N4JSFlowAnalyserDataRecorder.isEnabled()) {
        return;
    }
    List<ControlFlowEdge> edges = new LinkedList<>();
    for (EdgeGuide eg : edgeGuides) {
        edges.add(eg.getEdge());
    }
    Node startNode = edgeGuides.get(0).getNextNode();
    N4JSFlowAnalyserDataRecorder.addMergedEdges(startNode, edges);
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) Node(org.eclipse.n4js.flowgraphs.model.Node) LinkedList(java.util.LinkedList)

Example 8 with ControlFlowEdge

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

the class ControlFlowGraphFactory method printAllEdgeDetails.

/**
 * Prints detailed information of all control flow edges. Used for debugging purposes
 */
private static void printAllEdgeDetails(ComplexNodeMapper cnMapper) {
    // TODO move this to a PrintUtils class
    System.out.println("\nAll edges:");
    Set<ControlFlowEdge> allEdges = new HashSet<>();
    for (ComplexNode cn : cnMapper.getAll()) {
        for (Node n : cn.getNodes()) {
            allEdges.addAll(n.pred);
            allEdges.addAll(n.succ);
        }
    }
    for (ControlFlowEdge edge : allEdges) {
        System.out.println(edge);
    }
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) DelegatingNode(org.eclipse.n4js.flowgraphs.model.DelegatingNode) Node(org.eclipse.n4js.flowgraphs.model.Node) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with ControlFlowEdge

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

the class SuccessorPredecessorAnalysis method getNextCFEs.

/**
 * @return the set of all next {@link ControlFlowElement}
 */
private Set<ControlFlowElement> getNextCFEs(NextEdgesProvider nextEdgesProvider, ControlFlowElement cfe, Node nextNode) {
    Objects.requireNonNull(cfe);
    Set<ControlFlowElement> nexts = new HashSet<>();
    LinkedList<ControlFlowEdge> allEdges = new LinkedList<>();
    List<ControlFlowEdge> nextEdges = nextEdgesProvider.getNextEdges(nextNode, ControlFlowType.NonDeadTypes);
    allEdges.addAll(nextEdges);
    while (!allEdges.isEmpty()) {
        ControlFlowEdge nextEdge = allEdges.removeFirst();
        nextNode = nextEdgesProvider.getNextNode(nextEdge);
        if (nextNode instanceof RepresentingNode) {
            ControlFlowElement succ = nextNode.getRepresentedControlFlowElement();
            nexts.add(succ);
        } else {
            nextEdges = nextEdgesProvider.getNextEdges(nextNode, ControlFlowType.NonDeadTypes);
            allEdges.addAll(nextEdges);
        }
    }
    return nexts;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 10 with ControlFlowEdge

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

the class DirectPathAnalyses method findPath.

private LinkedList<ControlFlowEdge> findPath(Node startNode, Node endNode, Node notVia, NextEdgesProvider edgeProvider) {
    if (startNode == endNode) {
        return Lists.newLinkedList();
    }
    LinkedList<LinkedList<ControlFlowEdge>> allPaths = new LinkedList<>();
    // initialization
    List<ControlFlowEdge> nextEdges = edgeProvider.getNextEdges(startNode, ControlFlowType.NonDeadTypes);
    for (ControlFlowEdge nextEdge : nextEdges) {
        LinkedList<ControlFlowEdge> path = new LinkedList<>();
        path.add(nextEdge);
        if (isEndNode(edgeProvider, endNode, nextEdge)) {
            // direct edge from startNode to endNode due to nextEdge
            return path;
        }
        allPaths.add(path);
    }
    // explore all paths, terminate when endNode is found
    while (!allPaths.isEmpty()) {
        LinkedList<ControlFlowEdge> firstPath = allPaths.removeFirst();
        LinkedList<LinkedList<ControlFlowEdge>> ch = getPaths(edgeProvider, firstPath, notVia);
        for (LinkedList<ControlFlowEdge> chPath : ch) {
            if (isEndNode(edgeProvider, endNode, chPath.getLast())) {
                return chPath;
            }
        }
        allPaths.addAll(ch);
    }
    return null;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) 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