本文整理汇总了Java中com.google.javascript.jscomp.graph.DiGraph.DiGraphNode类的典型用法代码示例。如果您正苦于以下问题:Java DiGraphNode类的具体用法?Java DiGraphNode怎么用?Java DiGraphNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiGraphNode类属于com.google.javascript.jscomp.graph.DiGraph包,在下文中一共展示了DiGraphNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
@Override
protected void initialize() {
orderedWorkSet.clear();
for (DiGraphNode<N, Branch> node : getCfg().getDirectedGraphNodes()) {
List<DiGraphEdge<N, Branch>> edgeList =
getCfg().getOutEdges(node.getValue());
int outEdgeCount = edgeList.size();
List<L> outLattices = Lists.newArrayList();
for (int i = 0; i < outEdgeCount; i++) {
outLattices.add(createInitialEstimateLattice());
}
node.setAnnotation(new BranchedFlowState<L>(
createInitialEstimateLattice(), outLattices));
if (node != getCfg().getImplicitReturn()) {
orderedWorkSet.add(node);
}
}
}
示例2: joinInputs
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
@Override
protected void joinInputs(DiGraphNode<N, Branch> node) {
BranchedFlowState<L> state = node.getAnnotation();
List<DiGraphNode<N, Branch>> predNodes =
getCfg().getDirectedPredNodes(node);
List<L> values = new ArrayList<L>(predNodes.size());
for (DiGraphNode<N, Branch> predNode : predNodes) {
BranchedFlowState<L> predNodeState = predNode.getAnnotation();
L in = predNodeState.out.get(
getCfg().getDirectedSuccNodes(predNode).indexOf(node));
values.add(in);
}
if (getCfg().getEntry() == node) {
state.setIn(createEntryLattice());
} else if (!values.isEmpty()) {
state.setIn(joinOp.apply(values));
}
}
示例3: allPathsReturn
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
/**
* @returns true if all paths from block must exit with an explicit return.
*/
private boolean allPathsReturn(Node block) {
// Computes the control flow graph.
ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false);
cfa.process(null, block);
ControlFlowGraph<Node> cfg = cfa.getCfg();
Node returnPathsParent = cfg.getImplicitReturn().getValue();
for (DiGraphNode<Node, Branch> pred :
cfg.getDirectedPredNodes(returnPathsParent)) {
Node n = pred.getValue();
if (n.getType() != Token.RETURN) {
return false;
}
}
return true;
}
示例4: CheckPathsBetweenNodes
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
/**
* Given a graph G with nodes A and B, this algorithm determines if all paths
* from A to B contain at least one node satisfying a given predicate.
*
* Note that nodePredicate is not necessarily called for all nodes in G nor is
* edgePredicate called for all edges in G.
*
* @param graph Graph G to analyze.
* @param a The node A.
* @param b The node B.
* @param nodePredicate Predicate which at least one node on each path from an
* A node to B (inclusive) must match.
* @param edgePredicate Edges to consider as part of the graph. Edges in
* graph that don't match edgePredicate will be ignored.
*/
CheckPathsBetweenNodes(DiGraph<N, E> graph, DiGraphNode<N, E> a,
DiGraphNode<N, E> b, Predicate<N> nodePredicate,
Predicate<DiGraphEdge<N, E>> edgePredicate) {
this.nodePredicate = nodePredicate;
this.edgePredicate = edgePredicate;
graph.pushNodeAnnotations();
graph.pushEdgeAnnotations();
discoverBackEdges(a);
result = checkAllPathsWithoutBackEdges(a, b);
graph.popNodeAnnotations();
graph.popEdgeAnnotations();
}
示例5: checkAllPathsWithoutBackEdges
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
/**
* Verify that all non-looping paths from {@code a} to {@code b} pass
* through at least one node where {@code nodePredicate} is true.
*/
private boolean checkAllPathsWithoutBackEdges(DiGraphNode<N, E> a,
DiGraphNode<N, E> b) {
if (nodePredicate.apply(a.getValue())) {
return true;
}
if (a == b) {
return false;
}
for (DiGraphEdge<N, E> e : a.getOutEdges()) {
if (ignoreEdge(e)) {
continue;
}
if (e.getAnnotation() == BACK_EDGE) {
continue;
}
DiGraphNode<N, E> next = e.getDestination();
if (!checkAllPathsWithoutBackEdges(next, b)) {
return false;
}
}
return true;
}
示例6: process
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
@Override
public void process(Node externs, Node root) {
if (nameGraph == null) {
NameReferenceGraphConstruction c =
new NameReferenceGraphConstruction(compiler);
c.process(externs, root);
nameGraph = c.getNameReferenceGraph();
}
for (DiGraphNode<Name, Reference> node :
nameGraph.getDirectedGraphNodes()) {
Name name = node.getValue();
if (name.canChangeSignature()) {
List<DiGraphEdge<Name, Reference>> edges = node.getInEdges();
tryEliminateConstantArgs(name, edges);
tryEliminateOptionalArgs(name, edges);
}
}
}
示例7: prioritizeFromEntryNode
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
/**
* Given an entry node, find all the nodes reachable from that node
* and prioritize them.
*/
private void prioritizeFromEntryNode(DiGraphNode<Node, Branch> entry) {
PriorityQueue<DiGraphNode<Node, Branch>> worklist =
new PriorityQueue<DiGraphNode<Node, Branch>>(10, priorityComparator);
worklist.add(entry);
while (!worklist.isEmpty()) {
DiGraphNode<Node, Branch> current = worklist.remove();
if (nodePriorities.containsKey(current)) {
continue;
}
nodePriorities.put(current, ++priorityCounter);
List<DiGraphNode<Node, Branch>> successors =
cfg.getDirectedSuccNodes(current);
for (DiGraphNode<Node, Branch> candidate : successors) {
worklist.add(candidate);
}
}
}
示例8: testManyValidPaths
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
/** Tests a graph with many valid paths. */
public void testManyValidPaths() {
DiGraph<String, String> g = new LinkedDirectedGraph<String, String>();
g.createDirectedGraphNode("a");
g.createDirectedGraphNode("b");
g.createDirectedGraphNode("c1");
g.createDirectedGraphNode("c2");
g.createDirectedGraphNode("c3");
DiGraphNode<String, String> d = g.createDirectedGraphNode("d");
g.connect("a", "-", "b");
g.connect("b", "-", "c1");
g.connect("b", "-", "c2");
g.connect("c2", "-", "d");
g.connect("c1", "-", "d");
g.connect("a", "-", "c3");
g.connect("c3", "-", "d");
assertGood(createTest(g, "a", "d", new PrefixPredicate("c"), ALL_EDGE));
}
示例9: assertNodeOrder
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
/**
* 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<Integer> nodeTypes) {
List<DiGraphNode<Node, Branch>> cfgNodes = cfg.getDirectedGraphNodes();
Collections.sort(cfgNodes, cfg.getOptionalNodeComparator(true));
// IMPLICIT RETURN must always be last.
Node implicitReturn = cfgNodes.remove(cfgNodes.size() - 1).getValue();
assertNull(implicitReturn == null ? "null" : implicitReturn.toStringTree(),
implicitReturn);
assertEquals("Wrong number of CFG nodes",
nodeTypes.size(), cfgNodes.size());
for (int i = 0; i < cfgNodes.size(); i++) {
int expectedType = nodeTypes.get(i);
int actualType = cfgNodes.get(i).getValue().getType();
assertEquals(
"Node type mismatch at " + i + ".\n" +
"found : " + Token.name(actualType) + "\n" +
"required: " + Token.name(expectedType) + "\n",
expectedType, actualType);
}
}
示例10: compare
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
public int compare(DiGraphNode<Name, Reference> node1,
DiGraphNode<Name, Reference> node2) {
Preconditions.checkNotNull(node1.getValue());
Preconditions.checkNotNull(node2.getValue());
if ((node1.getValue().getQualifiedName() == null) &&
(node2.getValue().getQualifiedName() == null)) {
return 0;
}
// Node 1, if null, comes before node 2.
if (node1.getValue().getQualifiedName() == null) {
return -1;
}
// Node 2, if null, comes before node 1.
if (node2.getValue().getQualifiedName() == null) {
return 1;
}
return node1.getValue().getQualifiedName().compareTo(
node2.getValue().getQualifiedName());
}
示例11: initialize
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
@Override
protected void initialize() {
orderedWorkSet.clear();
for (DiGraphNode<N, Branch> node : getCfg().getDirectedGraphNodes()) {
int outEdgeCount = getCfg().getOutEdges(node.getValue()).size();
List<L> outLattices = Lists.newArrayList();
for (int i = 0; i < outEdgeCount; i++) {
outLattices.add(createInitialEstimateLattice());
}
node.setAnnotation(new BranchedFlowState<L>(
createInitialEstimateLattice(), outLattices));
if (node != getCfg().getImplicitReturn()) {
orderedWorkSet.add(node);
}
}
}
示例12: checkAllPathsWithoutBackEdges
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
/**
* Verify that all non-looping paths from {@code a} to {@code b} pass
* through at least one node where {@code nodePredicate} is true.
*/
private boolean checkAllPathsWithoutBackEdges(DiGraphNode<N, E> a,
DiGraphNode<N, E> b) {
if (nodePredicate.apply(a.getValue()) &&
(inclusive || (a != start && a != end))) {
return true;
}
if (a == b) {
return false;
}
for (DiGraphEdge<N, E> e : a.getOutEdges()) {
if (ignoreEdge(e)) {
continue;
}
if (e.getAnnotation() == BACK_EDGE) {
continue;
}
DiGraphNode<N, E> next = e.getDestination();
if (!checkAllPathsWithoutBackEdges(next, b)) {
return false;
}
}
return true;
}
示例13: checkSomePathsWithoutBackEdges
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
/**
* Verify that some non-looping paths from {@code a} to {@code b} pass
* through at least one node where {@code nodePredicate} is true.
*/
private boolean checkSomePathsWithoutBackEdges(DiGraphNode<N, E> a,
DiGraphNode<N, E> b) {
if (nodePredicate.apply(a.getValue()) &&
(inclusive || (a != start && a != end))) {
return true;
}
if (a == b) {
return false;
}
for (DiGraphEdge<N, E> e : a.getOutEdges()) {
if (ignoreEdge(e)) {
continue;
}
if (e.getAnnotation() == BACK_EDGE) {
continue;
}
DiGraphNode<N, E> next = e.getDestination();
if (checkSomePathsWithoutBackEdges(next, b)) {
return true;
}
}
return false;
}
示例14: process
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
@Override
public void process(Node externs, Node root) {
if (nameGraph == null) {
NameReferenceGraphConstruction c =
new NameReferenceGraphConstruction(compiler);
c.process(externs, root);
nameGraph = c.getNameReferenceGraph();
}
for (DiGraphNode<Name, Reference> node :
nameGraph.getDirectedGraphNodes()) {
Name name = node.getValue();
if (name.canChangeSignature()) {
List<DiGraphEdge<Name, Reference>> edges = node.getInEdges();
tryEliminateConstantArgs(name, edges);
tryEliminateOptionalArgs(name, edges);
}
}
}
示例15: assertNodeOrder
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入依赖的package包/类
/**
* 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<Integer> nodeTypes) {
List<DiGraphNode<Node, Branch>> cfgNodes =
Lists.newArrayList(cfg.getDirectedGraphNodes());
Collections.sort(cfgNodes, cfg.getOptionalNodeComparator(true));
// IMPLICIT RETURN must always be last.
Node implicitReturn = cfgNodes.remove(cfgNodes.size() - 1).getValue();
assertNull(implicitReturn == null ? "null" : implicitReturn.toStringTree(),
implicitReturn);
assertEquals("Wrong number of CFG nodes",
nodeTypes.size(), cfgNodes.size());
for (int i = 0; i < cfgNodes.size(); i++) {
int expectedType = nodeTypes.get(i);
int actualType = cfgNodes.get(i).getValue().getType();
assertEquals(
"Node type mismatch at " + i + ".\n" +
"found : " + Token.name(actualType) + "\n" +
"required: " + Token.name(expectedType) + "\n",
expectedType, actualType);
}
}