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


Java Branch类代码示例

本文整理汇总了Java中com.google.javascript.jscomp.ControlFlowGraph.Branch的典型用法代码示例。如果您正苦于以下问题:Java Branch类的具体用法?Java Branch怎么用?Java Branch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: enterScope

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
@Override
public void enterScope(NodeTraversal t) {
  ControlFlowGraph<Node> cfg = t.getControlFlowGraph();

  for (DiGraphEdge<Node, Branch> s : cfg.getImplicitReturn().getInEdges()) {
    Node exitNode = s.getSource().getValue();
    if (exitNode.getType() != Token.RETURN ||
        exitNode.getFirstChild() == null ||
        exitNode.getFirstChild().getType() != Token.THIS) {
      badFunctionNodes.add(t.getScopeRoot());
      return;
    }
  }

  goodFunctionNodes.add(t.getScopeRoot());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:ChainCalls.java

示例2: initialize

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的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);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:DataFlowAnalysis.java

示例3: joinInputs

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的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));
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:DataFlowAnalysis.java

示例4: shouldTraverse

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
@Override
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  GraphNode<Node, Branch> gNode = t.getControlFlowGraph().getNode(n);
  if (gNode != null && gNode.getAnnotation() != GraphReachability.REACHABLE) {

    // Only report error when there are some line number informations.
    // There are synthetic nodes with no line number informations, nodes
    // introduce by other passes (although not likely since this pass should
    // be executed early) or some rhino bug.
    if (n.getLineno() != -1 &&
        // Allow spurious semi-colons and spurious breaks.
        n.getType() != Token.EMPTY && n.getType() != Token.BREAK) {
      compiler.report(JSError.make(t, n, level, UNREACHABLE_CODE));
      // From now on, we are going to assume the user fixed the error and not
      // give more warning related to code section reachable from this node.
      new GraphReachability<Node, ControlFlowGraph.Branch>(
          t.getControlFlowGraph()).recompute(n);

      // Saves time by not traversing children.
      return false;
    }
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:CheckUnreachableCode.java

示例5: allPathsReturn

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的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;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:InstrumentFunctions.java

示例6: apply

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
public boolean apply(DiGraphEdge<Node, ControlFlowGraph.Branch> input) {
  // First skill all exceptions.
  Branch branch = input.getValue();
  if (branch == Branch.ON_EX) {
    return false;
  } else if (branch.isConditional()) {
    Node condition = NodeUtil.getConditionExpression(
        input.getSource().getValue());
    // TODO(user): We CAN make this bit smarter just looking at
    // constants. We DO have a full blown ReverseAbstractInterupter and
    // type system that can evaluate some impressions' boolean value but
    // for now we will keep this pass lightweight.
    if (condition != null && NodeUtil.isLiteralValue(condition) ) {
      return NodeUtil.getBooleanValue(condition) ==
        (Branch.ON_TRUE == branch);
    }
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:CheckMissingReturn.java

示例7: enterScope

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
@Override
public void enterScope(NodeTraversal t) {
  if (!explicitReturnExpected(t.getScopeRoot())) {
    return;
  }

  if (fastAllPathsReturnCheck(t.getControlFlowGraph())) {
    return;
  }

  CheckPathsBetweenNodes<Node, ControlFlowGraph.Branch> test =
      new CheckPathsBetweenNodes<Node, ControlFlowGraph.Branch>(
          t.getControlFlowGraph(),
          t.getControlFlowGraph().getEntry(),
          t.getControlFlowGraph().getImplicitReturn(),
          IS_RETURN, GOES_THROUGH_TRUE_CONDITION_PREDICATE);

  if (!test.allPathsSatisfyPredicate()) {
    compiler.report(
        JSError.make(t, t.getScopeRoot(), level, MISSING_RETURN_STATEMENT));
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:CheckMissingReturn.java

示例8: prioritizeFromEntryNode

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的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);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:ControlFlowAnalysis.java

示例9: handleSwitch

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
private void handleSwitch(Node node) {
  // Transfer to the first non-DEFAULT CASE. if there are none, transfer
  // to the DEFAULT or the EMPTY node.
  Node next = getNextSiblingOfType(
      node.getFirstChild().getNext(), Token.CASE, Token.EMPTY);
  if (next != null) { // Has at least one CASE or EMPTY
    createEdge(node, Branch.UNCOND, next);
  } else { // Has no CASE but possibly a DEFAULT
    if (node.getFirstChild().getNext() != null) {
      createEdge(node, Branch.UNCOND, node.getFirstChild().getNext());
    } else { // No CASE, no DEFAULT
      createEdge(node, Branch.UNCOND, computeFollowNode(node));
    }
  }
  connectToPossibleExceptionHandler(node, node.getFirstChild());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:ControlFlowAnalysis.java

示例10: handleCase

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
private void handleCase(Node node) {
  // Case is a bit tricky....First it goes into the body if condition is true.
  createEdge(node, Branch.ON_TRUE,
      node.getFirstChild().getNext());
  // Look for the next CASE, skipping over DEFAULT.
  Node next = getNextSiblingOfType(node.getNext(), Token.CASE);
  if (next != null) { // Found a CASE
    Preconditions.checkState(next.getType() == Token.CASE);
    createEdge(node, Branch.ON_FALSE, next);
  } else { // No more CASE found, go back and search for a DEFAULT.
    Node parent = node.getParent();
    Node deflt = getNextSiblingOfType(
      parent.getFirstChild().getNext(), Token.DEFAULT);
    if (deflt != null) { // Has a DEFAULT
      createEdge(node, Branch.ON_FALSE, deflt);
    } else { // No DEFAULT found, go to the follow of the SWITCH.
      createEdge(node, Branch.ON_FALSE, computeFollowNode(node));
    }
  }
  connectToPossibleExceptionHandler(node, node.getFirstChild());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:ControlFlowAnalysis.java

示例11: flowThrough

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
@Override
LiveVariableLattice flowThrough(Node node, LiveVariableLattice input) {
  final BitSet gen = new BitSet(input.liveSet.size());
  final BitSet kill = new BitSet(input.liveSet.size());

  // Make kills conditional if the node can end abruptly by an exception.
  boolean conditional = false;
  List<DiGraphEdge<Node, Branch>> edgeList = getCfg().getOutEdges(node);
  for (DiGraphEdge<Node, Branch> edge : edgeList) {
    if (Branch.ON_EX.equals(edge.getValue())) {
      conditional = true;
    }
  }
  computeGenKill(node, gen, kill, conditional);
  LiveVariableLattice result = new LiveVariableLattice(input);
  // L_in = L_out - Kill + Gen
  result.liveSet.andNot(kill);
  result.liveSet.or(gen);
  return result;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:LiveVariablesAnalysis.java

示例12: getAllEdges

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
/**
 * 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, int startToken, int 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.getType() != startToken || endNode.getType() != endToken) {
      it.remove();
    }
  }
  return edges;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:ControlFlowAnalysisTest.java

示例13: getAllDownEdges

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
/**
 * Gets all the control flow edges of the given type from some node with
 * the first token to some node with the second token.
 * This edge must flow from a parent to one of its descendants.
 */
private static List<DiGraphEdge<Node, Branch>> getAllDownEdges(
    ControlFlowGraph<Node> cfg, int startToken, int endToken, Branch type) {
  List<DiGraphEdge<Node, Branch>> edges =
      getAllEdges(cfg, startToken, endToken, type);
  Iterator<DiGraphEdge<Node, Branch>> it = edges.iterator();
  while (it.hasNext()) {
    DiGraphEdge<Node, Branch> edge = it.next();
    Node source = edge.getSource().getValue();
    Node dest = edge.getDestination().getValue();
    if (!isAncestor(source, dest)) {
      it.remove();
    }
  }

  return edges;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:ControlFlowAnalysisTest.java

示例14: testSimpleSwitch

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的package包/类
public void testSimpleSwitch() {
  String src = "var x; switch(x){ case(1): x(); case('x'): x(); break" +
      "; default: x();}";
  ControlFlowGraph<Node> cfg = createCfg(src);
  assertCrossEdge(cfg, Token.VAR, Token.SWITCH, Branch.UNCOND);
  assertNoEdge(cfg, Token.SWITCH, Token.NAME);
  // Transfer between cases and default.
  assertDownEdge(cfg, Token.SWITCH, Token.CASE, Branch.UNCOND);
  assertCrossEdge(cfg, Token.CASE, Token.CASE, Branch.ON_FALSE);
  assertCrossEdge(cfg, Token.CASE, Token.DEFAULT, Branch.ON_FALSE);
  // Within each case.
  assertDownEdge(cfg, Token.CASE, Token.BLOCK, Branch.ON_TRUE);
  assertDownEdge(cfg, Token.BLOCK, Token.EXPR_RESULT, Branch.UNCOND);
  assertNoEdge(cfg, Token.EXPR_RESULT, Token.CALL);
  assertNoEdge(cfg, Token.CALL, Token.NAME);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:ControlFlowAnalysisTest.java

示例15: assertNodeOrder

import com.google.javascript.jscomp.ControlFlowGraph.Branch; //导入依赖的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);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:33,代码来源:ControlFlowAnalysisTest.java


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