Search in sources :

Example 11 with ControlFlowEdge

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

the class EdgeGuideWorklist method getAllVisitedNodes.

/**
 * @return a set of all visited nodes
 */
Set<Node> getAllVisitedNodes(ComplexNode cn, NextEdgesProvider edgeProvider) {
    Set<Node> allVisitedNodes = new HashSet<>();
    for (ControlFlowEdge edge : allVisitedEdges) {
        allVisitedNodes.add(edge.start);
        allVisitedNodes.add(edge.end);
    }
    allVisitedNodes.add(edgeProvider.getStartNode(cn));
    return allVisitedNodes;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) HashSet(java.util.HashSet)

Example 12 with ControlFlowEdge

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

the class EdgeGuide method getNextEdgeGuides.

List<EdgeGuide> getNextEdgeGuides() {
    List<EdgeGuide> nextEGs = new LinkedList<>();
    List<ControlFlowEdge> nextEdges = edgeProvider.getNextEdges(getNextNode());
    nextEdges = finallyContext.filterEdges(nextEdges);
    Iterator<ControlFlowEdge> nextEdgeIt = nextEdges.iterator();
    boolean deadAliveChange = false;
    if (nextEdges.size() == 0) {
        for (BranchWalkerInternal aPath : getBranchIterable()) {
            aPath.deactivate();
        }
    }
    if (nextEdges.size() == 1) {
        deadAliveChange = isDeadAliveChange(nextEdges.get(0));
        if (!deadAliveChange) {
            ControlFlowEdge nextEdge = nextEdgeIt.next();
            edge = nextEdge;
            finallyContext.update(edgeProvider, edge);
            setBranchWalkersReachability();
            nextEGs.add(this);
        }
    }
    if (deadAliveChange || nextEdges.size() > 1) {
        while (nextEdgeIt.hasNext()) {
            ControlFlowEdge nextEdge = nextEdgeIt.next();
            Collection<BranchWalkerInternal> forkedPaths = new HashSet<>();
            for (BranchWalkerInternal aPath : getBranchIterable()) {
                BranchWalkerInternal forkedPath = aPath.callFork();
                aPath.deactivate();
                if (forkedPath != null) {
                    forkedPaths.add(forkedPath);
                }
            }
            NextEdgesProvider epCopy = edgeProvider.copy();
            EdgeGuide edgeGuide = new EdgeGuide(epCopy, nextEdge, forkedPaths, finallyContext, deadContext);
            nextEGs.add(edgeGuide);
        }
    }
    return nextEGs;
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 13 with ControlFlowEdge

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

the class GraphVisitorGuideInternal method callVisitOnEdge.

/**
 * This method must be kept in sync with {@link #callVisitOnNode(EdgeGuide, Node)}
 */
private void callVisitOnEdge(Node lastVisitNode, EdgeGuide currEdgeGuide, Node visitNode) {
    ControlFlowEdge egEdge = currEdgeGuide.getEdge();
    ControlFlowEdge visitedEdge = currEdgeGuide.getEdge();
    if (!guideWorklist.edgeVisited(egEdge)) {
        for (GraphVisitorInternal visitor : visitors) {
            visitor.callVisit(lastVisitNode, visitNode, visitedEdge);
        }
    }
    for (GraphVisitorInternal walker : visitors) {
        List<BranchWalkerInternal> activatedPaths = walker.activateRequestedExplorers();
        currEdgeGuide.addActiveBranches(activatedPaths);
    }
    for (Iterator<BranchWalkerInternal> branchWalkerIt = currEdgeGuide.getBranchIterable().iterator(); branchWalkerIt.hasNext(); ) {
        BranchWalkerInternal branchWalker = branchWalkerIt.next();
        branchWalker.callVisit(lastVisitNode, visitNode, visitedEdge);
        if (!branchWalker.isActive()) {
            branchWalkerIt.remove();
        }
    }
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)

Example 14 with ControlFlowEdge

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

the class BranchWalker method visit.

@Override
protected final void visit(Node start, Node end, ControlFlowEdge edge) {
    pEdgeTypes.add(edge.cfType);
    if (end instanceof RepresentingNode || this.getContainer() == end.getControlFlowElement()) {
        ControlFlowElement endCFE = end.getRepresentedControlFlowElement();
        endCFE = endCFE == null ? end.getControlFlowElement() : endCFE;
        if (lastRN != null) {
            ControlFlowElement startCFE = lastRN.getRepresentedControlFlowElement();
            startCFE = startCFE == null ? lastRN.getControlFlowElement() : startCFE;
            FlowEdge flowEdge = new FlowEdge(startCFE, endCFE, pEdgeTypes);
            visit(flowEdge);
            pEdgeTypes.clear();
        } else {
            HashSet<EdgeInfo> edgeInfos = new HashSet<>();
            addPredecedingRepNodes(this, edgeInfos, new EdgeInfo(this));
            for (EdgeInfo edgeInfo : edgeInfos) {
                ControlFlowElement startCFE = edgeInfo.startNode.getRepresentedControlFlowElement();
                startCFE = startCFE == null ? edgeInfo.startNode.getControlFlowElement() : startCFE;
                FlowEdge flowEdge = new FlowEdge(startCFE, endCFE, edgeInfo.pEdgeTypes);
                edgeInfo.edgeOwner.visit(flowEdge);
            }
            pEdgeTypes.clear();
        }
    }
}
Also used : FlowEdge(org.eclipse.n4js.flowgraphs.FlowEdge) ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement) HashSet(java.util.HashSet)

Example 15 with ControlFlowEdge

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

the class ControlFlowGraphFactory method removeNode.

private static void removeNode(ComplexNode cn, Node mNode) {
    ControlFlowEdge e1 = mNode.pred.first();
    ControlFlowEdge e2 = mNode.succ.first();
    Node pred = e1.start;
    Node succ = e2.end;
    EdgeUtils.removeCF(e1);
    EdgeUtils.removeCF(e2);
    cn.removeNodeChecks(mNode);
    cn.removeNode(mNode);
    for (Node intPred : mNode.getInternalPredecessors()) {
        intPred.removeInternalSuccessor(mNode);
    }
    for (Node intSucc : mNode.getInternalSuccessors()) {
        intSucc.removeInternalPredecessor(mNode);
    }
    mNode.getInternalPredecessors().clear();
    mNode.getInternalSuccessors().clear();
    EdgeUtils.connectCF(pred, succ);
}
Also used : ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) 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)

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