Search in sources :

Example 16 with ControlFlowEdge

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

the class FinallyFlowContext method findFinallyBlockContextEdge.

/**
 * This method searches all FinallyBlock-entry/exit edges E to chose the correct next following edges. The following
 * rules are implemented:
 * <ul>
 * <li/>If there exists no next edge with a context, then null is returned.
 * <li/>If there exists a next edge with a context, and the current {@link EdgeGuide} instance has no context that
 * matches with one of the next edges, then all edges without context are returned.
 * <li/>If there exists a next edge with a context, and the current {@link EdgeGuide} instance has a context that
 * matches with one of the next edges, the matching edge is returned.
 * </ul>
 */
private List<ControlFlowEdge> findFinallyBlockContextEdge(List<ControlFlowEdge> nextEdges) {
    LinkedList<ControlFlowEdge> fbContextFreeEdges = new LinkedList<>();
    Map<JumpToken, ControlFlowEdge> contextEdges = new HashMap<>();
    mapFinallyBlockContextEdges(nextEdges, fbContextFreeEdges, contextEdges);
    if (contextEdges.isEmpty()) {
        return Lists.newLinkedList();
    }
    ControlFlowEdge matchedFBContextEdge = null;
    Map.Entry<JumpToken, ControlFlowEdge> otherEdgePair = null;
    for (Map.Entry<JumpToken, ControlFlowEdge> ctxEdgePair : contextEdges.entrySet()) {
        JumpToken fbContext = ctxEdgePair.getKey();
        otherEdgePair = ctxEdgePair;
        if (finallyBlockContexts.contains(fbContext)) {
            matchedFBContextEdge = ctxEdgePair.getValue();
        }
    }
    if (matchedFBContextEdge != null) {
        return Collections2.newLinkedList(matchedFBContextEdge);
    } else if (!fbContextFreeEdges.isEmpty()) {
        return fbContextFreeEdges;
    } else if (otherEdgePair != null) {
        LinkedList<ControlFlowEdge> contextAndDeadEdges = new LinkedList<>();
        contextAndDeadEdges.add(otherEdgePair.getValue());
        for (ControlFlowEdge edge : nextEdges) {
            if (edge.cfType == ControlFlowType.DeadCode) {
                contextAndDeadEdges.add(edge);
            }
        }
        return contextAndDeadEdges;
    }
    return null;
}
Also used : JumpToken(org.eclipse.n4js.flowgraphs.model.JumpToken) ControlFlowEdge(org.eclipse.n4js.flowgraphs.model.ControlFlowEdge) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) 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