Java Code Examples for com.google.javascript.jscomp.graph.DiGraph.DiGraphNode#getAnnotation()
The following examples show how to use
com.google.javascript.jscomp.graph.DiGraph.DiGraphNode#getAnnotation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Closure_127_UnreachableCodeElimination_t.java From coming with MIT License | 6 votes |
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (parent == null || n.isFunction() || n.isScript()) { return; } DiGraphNode<Node, Branch> gNode = cfg.getDirectedGraphNode(n); if (gNode == null) { // Not in CFG. return; } if (gNode.getAnnotation() != GraphReachability.REACHABLE || (removeNoOpStatements && !NodeUtil.mayHaveSideEffects(n, compiler))) { removeDeadExprStatementSafely(n); return; } tryRemoveUnconditionalBranching(n); }
Example 2
Source File: Closure_127_UnreachableCodeElimination_s.java From coming with MIT License | 6 votes |
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (parent == null || n.isFunction() || n.isScript()) { return; } DiGraphNode<Node, Branch> gNode = cfg.getDirectedGraphNode(n); if (gNode == null) { // Not in CFG. return; } if (gNode.getAnnotation() != GraphReachability.REACHABLE || (removeNoOpStatements && !NodeUtil.mayHaveSideEffects(n, compiler))) { removeDeadExprStatementSafely(n); return; } tryRemoveUnconditionalBranching(n); }
Example 3
Source File: Closure_85_UnreachableCodeElimination_t.java From coming with MIT License | 6 votes |
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (parent == null) { return; } if (n.getType() == Token.FUNCTION || n.getType() == Token.SCRIPT) { return; } DiGraphNode<Node, Branch> gNode = curCfg.getDirectedGraphNode(n); if (gNode == null) { // Not in CFG. return; } if (gNode.getAnnotation() != GraphReachability.REACHABLE || (removeNoOpStatements && !NodeUtil.mayHaveSideEffects(n))) { removeDeadExprStatementSafely(n); return; } tryRemoveUnconditionalBranching(n); }
Example 4
Source File: Closure_85_UnreachableCodeElimination_s.java From coming with MIT License | 6 votes |
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (parent == null) { return; } if (n.getType() == Token.FUNCTION || n.getType() == Token.SCRIPT) { return; } DiGraphNode<Node, Branch> gNode = curCfg.getDirectedGraphNode(n); if (gNode == null) { // Not in CFG. return; } if (gNode.getAnnotation() != GraphReachability.REACHABLE || (removeNoOpStatements && !NodeUtil.mayHaveSideEffects(n))) { removeDeadExprStatementSafely(n); return; } tryRemoveUnconditionalBranching(n); }
Example 5
Source File: UnreachableCodeElimination.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (parent == null) { return; } if (n.isFunction() || n.isScript()) { return; } DiGraphNode<Node, Branch> gNode = cfg.getDirectedGraphNode(n); if (gNode == null) { // Not in CFG. return; } if (gNode.getAnnotation() != GraphReachability.REACHABLE || (removeNoOpStatements && !NodeUtil.mayHaveSideEffects(n, compiler))) { removeDeadExprStatementSafely(n); return; } tryRemoveUnconditionalBranching(n); }
Example 6
Source File: DataFlowAnalysis.java From astor with GNU General Public License v2.0 | 6 votes |
@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)); } }
Example 7
Source File: Closure_88_DeadAssignmentsElimination_s.java From coming with MIT License | 5 votes |
/** * Try to remove useless assignments from a control flow graph that has been * annotated with liveness information. * * @param t The node traversal. * @param cfg The control flow graph of the program annotated with liveness * information. */ private void tryRemoveDeadAssignments(NodeTraversal t, ControlFlowGraph<Node> cfg) { Iterable<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes(); for (DiGraphNode<Node, Branch> cfgNode : nodes) { FlowState<LiveVariableLattice> state = cfgNode.getAnnotation(); Node n = cfgNode.getValue(); if (n == null) { continue; } switch (n.getType()) { case Token.IF: case Token.WHILE: case Token.DO: tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state); continue; case Token.FOR: if (!NodeUtil.isForIn(n)) { tryRemoveAssignment( t, NodeUtil.getConditionExpression(n), state); } continue; case Token.SWITCH: case Token.CASE: case Token.RETURN: if (n.hasChildren()) { tryRemoveAssignment(t, n.getFirstChild(), state); } continue; // TODO(user): case Token.VAR: Remove var a=1;a=2;..... } tryRemoveAssignment(t, n, state); } }
Example 8
Source File: Closure_88_DeadAssignmentsElimination_t.java From coming with MIT License | 5 votes |
/** * Try to remove useless assignments from a control flow graph that has been * annotated with liveness information. * * @param t The node traversal. * @param cfg The control flow graph of the program annotated with liveness * information. */ private void tryRemoveDeadAssignments(NodeTraversal t, ControlFlowGraph<Node> cfg) { Iterable<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes(); for (DiGraphNode<Node, Branch> cfgNode : nodes) { FlowState<LiveVariableLattice> state = cfgNode.getAnnotation(); Node n = cfgNode.getValue(); if (n == null) { continue; } switch (n.getType()) { case Token.IF: case Token.WHILE: case Token.DO: tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state); continue; case Token.FOR: if (!NodeUtil.isForIn(n)) { tryRemoveAssignment( t, NodeUtil.getConditionExpression(n), state); } continue; case Token.SWITCH: case Token.CASE: case Token.RETURN: if (n.hasChildren()) { tryRemoveAssignment(t, n.getFirstChild(), state); } continue; // TODO(user): case Token.VAR: Remove var a=1;a=2;..... } tryRemoveAssignment(t, n, state); } }
Example 9
Source File: Closure_76_DeadAssignmentsElimination_s.java From coming with MIT License | 5 votes |
/** * Try to remove useless assignments from a control flow graph that has been * annotated with liveness information. * * @param t The node traversal. * @param cfg The control flow graph of the program annotated with liveness * information. */ private void tryRemoveDeadAssignments(NodeTraversal t, ControlFlowGraph<Node> cfg) { Iterable<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes(); for (DiGraphNode<Node, Branch> cfgNode : nodes) { FlowState<LiveVariableLattice> state = cfgNode.getAnnotation(); Node n = cfgNode.getValue(); if (n == null) { continue; } switch (n.getType()) { case Token.IF: case Token.WHILE: case Token.DO: tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state); continue; case Token.FOR: if (!NodeUtil.isForIn(n)) { tryRemoveAssignment( t, NodeUtil.getConditionExpression(n), state); } continue; case Token.SWITCH: case Token.CASE: case Token.RETURN: if (n.hasChildren()) { tryRemoveAssignment(t, n.getFirstChild(), state); } continue; // TODO(user): case Token.VAR: Remove var a=1;a=2;..... } tryRemoveAssignment(t, n, state); } }
Example 10
Source File: Closure_76_DeadAssignmentsElimination_t.java From coming with MIT License | 5 votes |
/** * Try to remove useless assignments from a control flow graph that has been * annotated with liveness information. * * @param t The node traversal. * @param cfg The control flow graph of the program annotated with liveness * information. */ private void tryRemoveDeadAssignments(NodeTraversal t, ControlFlowGraph<Node> cfg) { Iterable<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes(); for (DiGraphNode<Node, Branch> cfgNode : nodes) { FlowState<LiveVariableLattice> state = cfgNode.getAnnotation(); Node n = cfgNode.getValue(); if (n == null) { continue; } switch (n.getType()) { case Token.IF: case Token.WHILE: case Token.DO: tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state); continue; case Token.FOR: if (!NodeUtil.isForIn(n)) { tryRemoveAssignment( t, NodeUtil.getConditionExpression(n), state); } continue; case Token.SWITCH: case Token.CASE: case Token.RETURN: if (n.hasChildren()) { tryRemoveAssignment(t, n.getFirstChild(), state); } continue; // TODO(user): case Token.VAR: Remove var a=1;a=2;..... } tryRemoveAssignment(t, n, state); } }
Example 11
Source File: DataFlowAnalysis.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Performs a single flow through a node. * * @return {@code true} if the flow state differs from the previous state. */ protected boolean flow(DiGraphNode<N, Branch> node) { FlowState<L> state = node.getAnnotation(); if (isForward()) { L outBefore = state.out; state.out = flowThrough(node.getValue(), state.in); return !outBefore.equals(state.out); } else { L inBefore = state.in; state.in = flowThrough(node.getValue(), state.out); return !inBefore.equals(state.in); } }
Example 12
Source File: DataFlowAnalysis.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns the lattice element at the exit point. Needs to be overridden * because we use a BranchedFlowState instead of a FlowState; ugh. */ @Override L getExitLatticeElement() { DiGraphNode<N, Branch> node = getCfg().getImplicitReturn(); BranchedFlowState<L> state = node.getAnnotation(); return state.getIn(); }
Example 13
Source File: DataFlowAnalysis.java From astor with GNU General Public License v2.0 | 5 votes |
@Override protected final boolean flow(DiGraphNode<N, Branch> node) { BranchedFlowState<L> state = node.getAnnotation(); List<L> outBefore = state.out; state.out = branchedFlowThrough(node.getValue(), state.in); Preconditions.checkState(outBefore.size() == state.out.size()); for (int i = 0; i < outBefore.size(); i++) { if (!outBefore.get(i).equals(state.out.get(i))) { return true; } } return false; }
Example 14
Source File: DeadAssignmentsElimination.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Try to remove useless assignments from a control flow graph that has been * annotated with liveness information. * * @param t The node traversal. * @param cfg The control flow graph of the program annotated with liveness * information. */ private void tryRemoveDeadAssignments(NodeTraversal t, ControlFlowGraph<Node> cfg) { Iterable<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes(); for (DiGraphNode<Node, Branch> cfgNode : nodes) { FlowState<LiveVariableLattice> state = cfgNode.getAnnotation(); Node n = cfgNode.getValue(); if (n == null) { continue; } switch (n.getType()) { case Token.IF: case Token.WHILE: case Token.DO: tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state); continue; case Token.FOR: if (!NodeUtil.isForIn(n)) { tryRemoveAssignment( t, NodeUtil.getConditionExpression(n), state); } continue; case Token.SWITCH: case Token.CASE: case Token.RETURN: if (n.hasChildren()) { tryRemoveAssignment(t, n.getFirstChild(), state); } continue; // TODO(user): case Token.VAR: Remove var a=1;a=2;..... } tryRemoveAssignment(t, n, state); } }
Example 15
Source File: CheckPathsBetweenNodes.java From astor with GNU General Public License v2.0 | 5 votes |
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); }
Example 16
Source File: DataFlowAnalysis.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Returns the lattice element at the exit point. */ L getExitLatticeElement() { DiGraphNode<N, Branch> node = getCfg().getImplicitReturn(); FlowState<L> state = node.getAnnotation(); return state.getIn(); }