use of com.google.javascript.jscomp.graph.DiGraph.DiGraphNode in project closure-compiler by google.
the class DotFormatter method traverseNodes.
private void traverseNodes(Node parent) throws IOException {
// key
int keyParent = key(parent);
// edges
for (Node child = parent.getFirstChild(); child != null; child = child.getNext()) {
int keyChild = key(child);
builder.append(INDENT);
builder.append(formatNodeName(keyParent));
builder.append(ARROW);
builder.append(formatNodeName(keyChild));
builder.append(" [weight=1];\n");
traverseNodes(child);
}
// Flow Edges
if (cfg != null && cfg.hasNode(parent)) {
List<? extends DiGraphEdge<Node, Branch>> outEdges = cfg.getOutEdges(parent);
String[] edgeList = new String[outEdges.size()];
for (int i = 0; i < edgeList.length; i++) {
DiGraphEdge<Node, ControlFlowGraph.Branch> edge = outEdges.get(i);
DiGraphNode<Node, Branch> succ = edge.getDestination();
String toNode = null;
if (succ == cfg.getImplicitReturn()) {
toNode = "RETURN";
} else {
int keySucc = key(succ.getValue());
toNode = formatNodeName(keySucc);
}
edgeList[i] = formatNodeName(keyParent) + ARROW + toNode + " [label=\"" + edge.getValue() + "\", " + "fontcolor=\"red\", " + "weight=0.01, color=\"red\"];\n";
}
Arrays.sort(edgeList);
for (String element : edgeList) {
builder.append(INDENT);
builder.append(element);
}
}
}
use of com.google.javascript.jscomp.graph.DiGraph.DiGraphNode in project closure-compiler by google.
the class ControlFlowAnalysisTest method assertNodeOrder.
/**
* Asserts the priority order of CFG nodes.
*
* Checks that the node type of the highest-priority node matches the
* first element of the list, the type of the second node matches the
* second element of the list, and so on.
*
* @param cfg The control flow graph.
* @param nodeTypes The expected node types, in order.
*/
private void assertNodeOrder(ControlFlowGraph<Node> cfg, List<Token> nodeTypes) {
List<? extends DiGraphNode<Node, Branch>> cfgNodes = Ordering.from(cfg.getOptionalNodeComparator(true)).sortedCopy(cfg.getNodes());
// IMPLICIT RETURN must always be last.
Node implicitReturn = cfgNodes.remove(cfgNodes.size() - 1).getValue();
assertWithMessage(implicitReturn == null ? "null" : implicitReturn.toStringTree()).that(implicitReturn).isNull();
assertThat(cfgNodes.stream().map(DiGraphNode::getValue).map(Node::getToken).collect(Collectors.toList())).isEqualTo(nodeTypes);
}
Aggregations