Search in sources :

Example 1 with Node

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

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

the class SuccessorPredecessorAnalysis method getPredecessors.

/**
 * see {@link N4JSFlowAnalyser#getPredecessors(ControlFlowElement)}
 */
public Set<ControlFlowElement> getPredecessors(ControlFlowElement cfe) {
    NextEdgesProvider nextEdgesProvider = new NextEdgesProvider.Backward();
    Node nextNode = getNextNode(cfe, false, nextEdgesProvider);
    Set<ControlFlowElement> predecessors = getNextCFEs(nextEdgesProvider, cfe, nextNode);
    return predecessors;
}
Also used : RepresentingNode(org.eclipse.n4js.flowgraphs.model.RepresentingNode) ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Example 3 with Node

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

the class GraphVisitorGuideInternal method mergeEdgeGuides.

private void mergeEdgeGuides() {
    List<EdgeGuide> joinGuideGroup = guideWorklist.getJoinGroups();
    if (!joinGuideGroup.isEmpty()) {
        EdgeGuide firstEG = joinGuideGroup.get(0);
        // end node is the same of all EGs in the list
        Node endNode = firstEG.getNextNode();
        for (EdgeGuide eg : joinGuideGroup) {
            Node startNode = eg.getPrevNode();
            // Before merging the join group, the edges are visited.
            callVisitOnEdge(startNode, eg, endNode);
        }
        EdgeGuide mergedEG = guideWorklist.mergeJoinGroup(joinGuideGroup);
        callVisitOnNode(mergedEG, endNode);
    }
}
Also used : ComplexNode(org.eclipse.n4js.flowgraphs.model.ComplexNode) Node(org.eclipse.n4js.flowgraphs.model.Node)

Example 4 with Node

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

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

the class N4JSFlowAnalyserDataRecorder method compareNodes.

static int compareNodes(Pair<Node, List<ControlFlowEdge>> p1, Pair<Node, List<ControlFlowEdge>> p2) {
    Node n1 = p1.getKey();
    Node n2 = p2.getKey();
    return n1.getExtendedString().compareTo(n2.getExtendedString());
}
Also used : Node(org.eclipse.n4js.flowgraphs.model.Node)

Aggregations

Node (org.eclipse.n4js.flowgraphs.model.Node)41 ComplexNode (org.eclipse.n4js.flowgraphs.model.ComplexNode)34 HelperNode (org.eclipse.n4js.flowgraphs.model.HelperNode)17 RepresentingNode (org.eclipse.n4js.flowgraphs.model.RepresentingNode)17 LinkedList (java.util.LinkedList)16 CatchToken (org.eclipse.n4js.flowgraphs.model.CatchToken)11 ControlFlowEdge (org.eclipse.n4js.flowgraphs.model.ControlFlowEdge)8 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)8 LabelledStatement (org.eclipse.n4js.n4JS.LabelledStatement)6 DelegatingNode (org.eclipse.n4js.flowgraphs.model.DelegatingNode)5 ControlFlowType (org.eclipse.n4js.flowgraphs.ControlFlowType)4 HashSet (java.util.HashSet)3 VariableDeclarationOrBinding (org.eclipse.n4js.n4JS.VariableDeclarationOrBinding)3 AbstractCaseClause (org.eclipse.n4js.n4JS.AbstractCaseClause)2 CaseClause (org.eclipse.n4js.n4JS.CaseClause)2 FinallyBlock (org.eclipse.n4js.n4JS.FinallyBlock)2 Statement (org.eclipse.n4js.n4JS.Statement)2 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 DummyBackwardVisitor (org.eclipse.n4js.flowgraphs.analysers.DummyBackwardVisitor)1