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