当前位置: 首页>>代码示例>>Java>>正文


Java DiGraphNode.getOutEdges方法代码示例

本文整理汇总了Java中com.google.javascript.jscomp.graph.DiGraph.DiGraphNode.getOutEdges方法的典型用法代码示例。如果您正苦于以下问题:Java DiGraphNode.getOutEdges方法的具体用法?Java DiGraphNode.getOutEdges怎么用?Java DiGraphNode.getOutEdges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.jscomp.graph.DiGraph.DiGraphNode的用法示例。


在下文中一共展示了DiGraphNode.getOutEdges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:CheckPathsBetweenNodes.java

示例2: 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;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:28,代码来源:CheckPathsBetweenNodes.java

示例3: 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;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:28,代码来源:CheckPathsBetweenNodes.java

示例4: getOutEnv

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
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);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:21,代码来源:NewTypeInference.java

示例5: analyzeConditionalStmFwd

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
private void analyzeConditionalStmFwd(
    DiGraphNode<Node, ControlFlowGraph.Branch> stm, Node cond, TypeEnv inEnv) {
  for (DiGraphEdge<Node, ControlFlowGraph.Branch> outEdge :
      stm.getOutEdges()) {
    JSType specializedType;
    switch (outEdge.getValue()) {
      case ON_TRUE:
        specializedType = TRUTHY;
        break;
      case ON_FALSE:
        specializedType = FALSY;
        break;
      case ON_EX:
        specializedType = UNKNOWN;
        break;
      default:
        throw new RuntimeException(
            "Condition with an unexpected edge type: " + outEdge.getValue());
    }
    envs.put(outEdge,
        analyzeExprFwd(cond, inEnv, UNKNOWN, specializedType).env);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:24,代码来源:NewTypeInference.java

示例6: discoverBackEdges

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
private void discoverBackEdges(DiGraphNode<N, E> u) {
  u.setAnnotation(GRAY);
  for (DiGraphEdge<N, E> e : u.getOutEdges()) {
    if (ignoreEdge(e)) {
      continue;
    }
    DiGraphNode<N, E> v = e.getDestination();
    if (v.getAnnotation() == WHITE) {
      discoverBackEdges(v);
    } else if (v.getAnnotation() == GRAY) {
      e.setAnnotation(BACK_EDGE);
    }
  }
  u.setAnnotation(BLACK);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:CheckPathsBetweenNodes.java

示例7: computeFixedPoint

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
 * Compute a fixed point for the given graph, entering from the given nodes.
 * @param graph The graph to traverse.
 * @param entrySet The nodes to begin traversing from.
 */
public void computeFixedPoint(DiGraph<N, E> graph, Set<N> entrySet) {
  int cycleCount = 0;
  long nodeCount = graph.getNodes().size();

  // Choose a bail-out heuristically in case the computation
  // doesn't converge.
  long maxIterations = Math.max(nodeCount * nodeCount * nodeCount, 100);

  // Use a LinkedHashSet, so that the traversal is deterministic.
  LinkedHashSet<DiGraphNode<N, E>> workSet =
      Sets.newLinkedHashSet();
  for (N n : entrySet) {
    workSet.add(graph.getDirectedGraphNode(n));
  }
  for (; !workSet.isEmpty() && cycleCount < maxIterations; cycleCount++) {
    // For every out edge in the workSet, traverse that edge. If that
    // edge updates the state of the graph, then add the destination
    // node to the resultSet, so that we can update all of its out edges
    // on the next iteration.
    DiGraphNode<N, E> source = workSet.iterator().next();
    N sourceValue = source.getValue();

    workSet.remove(source);

    List<DiGraphEdge<N, E>> outEdges = source.getOutEdges();
    for (DiGraphEdge<N, E> edge : outEdges) {
      N destNode = edge.getDestination().getValue();
      if (callback.traverseEdge(sourceValue, edge.getValue(), destNode)) {
        workSet.add(edge.getDestination());
      }
    }
  }

  Preconditions.checkState(cycleCount != maxIterations,
      NON_HALTING_ERROR_MSG);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:42,代码来源:FixedPointGraphTraversal.java

示例8: 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()) {
    // Once we visited that edge once, we no longer need to
    // re-visit it again.
    if (e.getAnnotation() == VISITED_EDGE) {
      continue;
    }
    e.setAnnotation(VISITED_EDGE);

    if (ignoreEdge(e)) {
      continue;
    }
    if (e.getAnnotation() == BACK_EDGE) {
      continue;
    }

    DiGraphNode<N, E> next = e.getDestination();
    if (!checkAllPathsWithoutBackEdges(next, b)) {
      return false;
    }
  }
  return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:36,代码来源:CheckPathsBetweenNodes.java

示例9: 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()) {
    // Once we visited that edge once, we no longer need to
    // re-visit it again.
    if (e.getAnnotation() == VISITED_EDGE) {
      continue;
    }
    e.setAnnotation(VISITED_EDGE);

    if (ignoreEdge(e)) {
      continue;
    }
    if (e.getAnnotation() == BACK_EDGE) {
      continue;
    }

    DiGraphNode<N, E> next = e.getDestination();
    if (checkSomePathsWithoutBackEdges(next, b)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:36,代码来源:CheckPathsBetweenNodes.java

示例10: cloneGraph

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
private static <N, E> LinkedDirectedGraph<N, E> cloneGraph(
    DiGraph<N, E> graph) {
  LinkedDirectedGraph<N, E> newGraph = LinkedDirectedGraph.create();
  for (DiGraphNode<N, E> node : graph.getDirectedGraphNodes()) {
    newGraph.createNode(node.getValue());

    for (DiGraphEdge<N, E> outEdge : node.getOutEdges()) {
      N dest = outEdge.getDestination().getValue();
      newGraph.createNode(dest);
      newGraph.connect(node.getValue(), outEdge.getValue(), dest);
    }
  }

  return newGraph;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:GraphPruner.java

示例11: setOutEnv

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
private TypeEnv setOutEnv(
    DiGraphNode<Node, ControlFlowGraph.Branch> dn, TypeEnv e) {
  for (DiGraphEdge<Node, ControlFlowGraph.Branch> de : dn.getOutEdges()) {
    envs.put(de, e);
  }
  return e;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:8,代码来源:NewTypeInference.java

示例12: computeFixedPoint

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
 * Compute a fixed point for the given graph, entering from the given nodes.
 * @param graph The graph to traverse.
 * @param entrySet The nodes to begin traversing from.
 */
public void computeFixedPoint(DiGraph<N, E> graph, Set<N> entrySet) {
  int cycleCount = 0;
  long nodeCount = graph.getNodeCount();

  // Choose a bail-out heuristically in case the computation
  // doesn't converge.
  long maxIterations = Math.max(nodeCount * nodeCount * nodeCount, 100);

  // Use a LinkedHashSet, so that the traversal is deterministic.
  LinkedHashSet<DiGraphNode<N, E>> workSet = new LinkedHashSet<>();
  for (N n : entrySet) {
    workSet.add(graph.getDirectedGraphNode(n));
  }
  for (; !workSet.isEmpty() && cycleCount < maxIterations; cycleCount++) {
    // For every out edge in the workSet, traverse that edge. If that
    // edge updates the state of the graph, then add the destination
    // node to the resultSet, so that we can update all of its out edges
    // on the next iteration.
    DiGraphNode<N, E> source = workSet.iterator().next();
    N sourceValue = source.getValue();

    workSet.remove(source);

    List<DiGraphEdge<N, E>> outEdges = source.getOutEdges();
    for (DiGraphEdge<N, E> edge : outEdges) {
      N destNode = edge.getDestination().getValue();
      if (callback.traverseEdge(sourceValue, edge.getValue(), destNode)) {
        workSet.add(edge.getDestination());
      }
    }
  }

  checkState(cycleCount != maxIterations, NON_HALTING_ERROR_MSG);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:40,代码来源:FixedPointGraphTraversal.java

示例13: tryRemoveUnconditionalBranching

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
 * Tries to remove n if it is an unconditional branch node (break, continue,
 * or return) and the target of n is the same as the the follow of n.
 * That is, if removing n preserves the control flow. Also if n targets
 * another unconditional branch, this function will recursively try to remove
 * the target branch as well. The reason why we want to cascade this removal
 * is because we only run this pass once. If we have code such as
 *
 * break -> break -> break
 *
 * where all 3 breaks are useless, then the order of removal matters. When we
 * first look at the first break, we see that it branches to the 2nd break.
 * However, if we remove the last break, the 2nd break becomes useless and
 * finally the first break becomes useless as well.
 *
 * @return The target of this jump. If the target is also useless jump,
 *     the target of that useless jump recursively.
 */
@SuppressWarnings("fallthrough")
private Node tryRemoveUnconditionalBranching(Node n) {
  /*
   * For each unconditional branching control flow node, check to see
   * if the ControlFlowAnalysis.computeFollowNode of that node is same as
   * the branching target. If it is, the branch node is safe to be removed.
   *
   * This is not as clever as MinimizeExitPoints because it doesn't do any
   * if-else conversion but it handles more complicated switch statements
   * much more nicely.
   */

  // If n is null the target is the end of the function, nothing to do.
  if (n == null) {
     return n;
  }

  DiGraphNode<Node, Branch> gNode = cfg.getDirectedGraphNode(n);

  if (gNode == null) {
    return n;
  }

  switch (n.getType()) {
    case Token.RETURN:
      if (n.hasChildren()) {
        break;
      }
    case Token.BREAK:
    case Token.CONTINUE:

      // We are looking for a control flow changing statement that always
      // branches to the same node. If after removing it control still
      // branches to the same node, it is safe to remove.
      List<DiGraphEdge<Node,Branch>> outEdges = gNode.getOutEdges();
      if (outEdges.size() == 1 &&
          // If there is a next node, there is no chance this jump is useless.
          (n.getNext() == null || n.getNext().isFunction())) {

        Preconditions.checkState(outEdges.get(0).getValue() == Branch.UNCOND);
        Node fallThrough = computeFollowing(n);
        Node nextCfgNode = outEdges.get(0).getDestination().getValue();
        if (nextCfgNode == fallThrough) {
          removeDeadExprStatementSafely(n);
          return fallThrough;
        }
      }
  }
  return n;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:69,代码来源:UnreachableCodeElimination.java

示例14: tryRemoveUnconditionalBranching

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
 * Tries to remove n if it is an unconditional branch node (break, continue,
 * or return) and the target of n is the same as the follow of n.
 * That is, if removing n preserves the control flow. Also if n targets
 * another unconditional branch, this function will recursively try to
 * remove the target branch as well. The reason why we want to cascade this
 * removal is because we only run this pass once. If we have code such as
 *
 * break -> break -> break
 *
 * where all 3 breaks are useless, then the order of removal matters. When
 * we first look at the first break, we see that it branches to the 2nd
 * break. However, if we remove the last break, the 2nd break becomes
 * useless and finally the first break becomes useless as well.
 */
@SuppressWarnings("fallthrough")
private void tryRemoveUnconditionalBranching(Node n) {
  /*
   * For each unconditional branching control flow node, check to see
   * if the ControlFlowAnalysis.computeFollowNode of that node is same as
   * the branching target. If it is, the branch node is safe to be removed.
   *
   * This is not as clever as MinimizeExitPoints because it doesn't do any
   * if-else conversion but it handles more complicated switch statements
   * much more nicely.
   */

  // If n is null the target is the end of the function, nothing to do.
  if (n == null) {
     return;
  }

  DiGraphNode<Node, Branch> gNode = cfg.getDirectedGraphNode(n);

  if (gNode == null) {
    return;
  }

  switch (n.getToken()) {
    case RETURN:
      if (n.hasChildren()) {
        break;
      }
    case BREAK:
    case CONTINUE:
      // We are looking for a control flow changing statement that always
      // branches to the same node. If after removing it control still
      // branches to the same node, it is safe to remove.
      List<DiGraphEdge<Node, Branch>> outEdges = gNode.getOutEdges();
      if (outEdges.size() == 1
          &&
          // If there is a next node, this jump is not useless.
          (n.getNext() == null || n.getNext().isFunction())) {

        checkState(outEdges.get(0).getValue() == Branch.UNCOND);
        Node fallThrough = computeFollowing(n);
        Node nextCfgNode = outEdges.get(0).getDestination().getValue();
        if (nextCfgNode == fallThrough && !inFinally(n.getParent(), n)) {
          removeNode(n);
        }
      }
      break;
    default:
      break;
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:67,代码来源:UnreachableCodeElimination.java

示例15: tryRemoveUnconditionalBranching

import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
 * Tries to remove n if it is an unconditional branch node (break, continue,
 * or return) and the target of n is the same as the the follow of n.
 * That is, if removing n preserves the control flow. Also if n targets
 * another unconditional branch, this function will recursively try to
 * remove the target branch as well. The reason why we want to cascade this
 * removal is because we only run this pass once. If we have code such as
 *
 * break -> break -> break
 *
 * where all 3 breaks are useless, then the order of removal matters. When
 * we first look at the first break, we see that it branches to the 2nd
 * break. However, if we remove the last break, the 2nd break becomes
 * useless and finally the first break becomes useless as well.
 *
 * @return The target of this jump. If the target is also useless jump,
 *     the target of that useless jump recursively.
 */
@SuppressWarnings("fallthrough")
private void tryRemoveUnconditionalBranching(Node n) {
  /*
   * For each unconditional branching control flow node, check to see
   * if the ControlFlowAnalysis.computeFollowNode of that node is same as
   * the branching target. If it is, the branch node is safe to be removed.
   *
   * This is not as clever as MinimizeExitPoints because it doesn't do any
   * if-else conversion but it handles more complicated switch statements
   * much more nicely.
   */

  // If n is null the target is the end of the function, nothing to do.
  if (n == null) {
     return;
  }

  DiGraphNode<Node, Branch> gNode = cfg.getDirectedGraphNode(n);

  if (gNode == null) {
    return;
  }

  switch (n.getType()) {
    case Token.RETURN:
      if (n.hasChildren()) {
        break;
      }
    case Token.BREAK:
    case Token.CONTINUE:
      // We are looking for a control flow changing statement that always
      // branches to the same node. If after removing it control still
      // branches to the same node, it is safe to remove.
      List<DiGraphEdge<Node, Branch>> outEdges = gNode.getOutEdges();
      if (outEdges.size() == 1 &&
          // If there is a next node, this jump is not useless.
          (n.getNext() == null || n.getNext().isFunction())) {

        Preconditions.checkState(
            outEdges.get(0).getValue() == Branch.UNCOND);
        Node fallThrough = computeFollowing(n);
        Node nextCfgNode = outEdges.get(0).getDestination().getValue();
        if (nextCfgNode == fallThrough && !inFinally(n.getParent(), n)) {
          removeNode(n);
        }
      }
  }
}
 
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:67,代码来源:UnreachableCodeElimination.java


注:本文中的com.google.javascript.jscomp.graph.DiGraph.DiGraphNode.getOutEdges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。