use of com.google.javascript.jscomp.graph.DiGraph.DiGraphEdge in project closure-compiler by google.
the class NewTypeInference method getOutEnv.
private TypeEnv getOutEnv(DiGraphNode<Node, ControlFlowGraph.Branch> dn) {
List<DiGraphEdge<Node, ControlFlowGraph.Branch>> outEdges = dn.getOutEdges();
if (outEdges.isEmpty()) {
// This occurs when visiting a throw in the backward direction.
checkArgument(dn.getValue().isThrow());
return this.typeEnvFromDeclaredTypes;
}
if (outEdges.size() == 1) {
return envs.get(outEdges.get(0));
}
Set<TypeEnv> envSet = new LinkedHashSet<>();
for (DiGraphEdge<Node, ControlFlowGraph.Branch> de : outEdges) {
TypeEnv env = envs.get(de);
if (env != null) {
envSet.add(env);
}
}
checkState(!envSet.isEmpty());
return TypeEnv.join(envSet);
}
use of com.google.javascript.jscomp.graph.DiGraph.DiGraphEdge in project closure-compiler by google.
the class ControlFlowAnalysisTest method assertReturnEdge.
/**
* Assert that there exists a control flow edge of the given type
* from some node with the first token to the return node.
*/
private static void assertReturnEdge(ControlFlowGraph<Node> cfg, Token startToken) {
List<DiGraphEdge<Node, Branch>> edges = getAllEdges(cfg);
for (DiGraphEdge<Node, Branch> edge : edges) {
Node source = edge.getSource().getValue();
DiGraphNode<Node, Branch> dest = edge.getDestination();
if (source.getToken() == startToken && cfg.isImplicitReturn(dest)) {
return;
}
}
fail("No return edge found");
}
use of com.google.javascript.jscomp.graph.DiGraph.DiGraphEdge in project closure-compiler by google.
the class ControlFlowAnalysisTest method getAllEdges.
/**
* Gets all the control flow edges from some node with the first token to
* some node with the second token.
*/
private static List<DiGraphEdge<Node, Branch>> getAllEdges(ControlFlowGraph<Node> cfg, Token startToken, Token endToken) {
List<DiGraphEdge<Node, Branch>> edges = getAllEdges(cfg);
Iterator<DiGraphEdge<Node, Branch>> it = edges.iterator();
while (it.hasNext()) {
DiGraphEdge<Node, Branch> edge = it.next();
Node startNode = edge.getSource().getValue();
Node endNode = edge.getDestination().getValue();
if (startNode == null || endNode == null || startNode.getToken() != startToken || endNode.getToken() != endToken) {
it.remove();
}
}
return edges;
}
use of com.google.javascript.jscomp.graph.DiGraph.DiGraphEdge in project closure-compiler by google.
the class ControlFlowAnalysisTest method assertNoReturnEdge.
/**
* Assert that there exists no control flow edge of the given type
* from some node with the first token to the return node.
*/
private static void assertNoReturnEdge(ControlFlowGraph<Node> cfg, Token startToken) {
List<DiGraphEdge<Node, Branch>> edges = getAllEdges(cfg);
for (DiGraphEdge<Node, Branch> edge : edges) {
Node source = edge.getSource().getValue();
DiGraphNode<Node, Branch> dest = edge.getDestination();
if (source.getToken() == startToken) {
assertFalse("Token " + startToken + " should not have an out going" + " edge to the implicit return", cfg.isImplicitReturn(dest));
return;
}
}
}
use of com.google.javascript.jscomp.graph.DiGraph.DiGraphEdge 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<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);
}
}
}
Aggregations