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);
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations