本文整理汇总了Java中com.google.javascript.jscomp.graph.DiGraph.DiGraphNode.getAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java DiGraphNode.getAnnotation方法的具体用法?Java DiGraphNode.getAnnotation怎么用?Java DiGraphNode.getAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.graph.DiGraph.DiGraphNode
的用法示例。
在下文中一共展示了DiGraphNode.getAnnotation方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
}
示例2: visit
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
@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);
}
示例3: visit
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
@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
|| !NodeUtil.mayHaveSideEffects(n, compiler)) {
removeDeadExprStatementSafely(n);
return;
}
tryRemoveUnconditionalBranching(n);
}
示例4: 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<>(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));
}
}
示例5: visit
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
@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);
}
示例6: flow
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
* 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);
}
}
示例7: getExitLatticeElement
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
* 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();
}
示例8: tryRemoveDeadAssignments
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
* 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) {
List<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);
}
}
示例9: 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);
}
示例10: visit
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (parent == null) {
return;
}
if (n.getType() == Token.FUNCTION || n.getType() == Token.SCRIPT) {
return;
}
// Removes TRYs that had its CATCH removed and/or empty FINALLY.
// TODO(dcc): Move the parts of this that don't require a control flow
// graph to PeepholeRemoveDeadCode
if (n.getType() == Token.TRY) {
Node body = n.getFirstChild();
Node catchOrFinallyBlock = body.getNext();
Node finallyBlock = catchOrFinallyBlock.getNext();
if (!catchOrFinallyBlock.hasChildren() &&
(finallyBlock == null || !finallyBlock.hasChildren())) {
n.removeChild(body);
parent.replaceChild(n, body);
compiler.reportCodeChange();
n = body;
}
}
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);
}
示例11: tryRemoveDeadAssignments
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
* 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);
}
}
示例12: computeVariableNamesInterferenceGraph
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
private UndiGraph<Var, Void> computeVariableNamesInterferenceGraph(
NodeTraversal t, ControlFlowGraph<Node> cfg, Set<Var> escaped) {
UndiGraph<Var, Void> interferenceGraph =
new LinkedUndirectedGraph<Var, Void>();
Scope scope = t.getScope();
// First create a node for each non-escaped variable.
for (Iterator<Var> i = scope.getVars(); i.hasNext();) {
Var v = i.next();
if (!escaped.contains(v)) {
// TODO(user): In theory, we CAN coalesce function names just like
// any variables. Our Liveness analysis captures this just like it as
// described in the specification. However, we saw some zipped and
// and unzipped size increase after this. We are not totally sure why
// that is but, for now, we will respect the dead functions and not play
// around with it.
if (!NodeUtil.isFunction(v.getParentNode())) {
interferenceGraph.createNode(v);
}
}
}
// Go through every single point of the program and look at each variable
// pairs. If they are both live at the same time, at an edge between them.
for (DiGraphNode<Node, Branch> cfgNode : cfg.getDirectedGraphNodes()) {
FlowState<LiveVariableLattice> state = cfgNode.getAnnotation();
if (cfg.isImplicitReturn(cfgNode)) {
continue;
}
int varsInScope = scope.getVarCount();
ArrayList<CombinedLiveRangeChecker> rangesToCheck =
new ArrayList<CombinedLiveRangeChecker>(
varsInScope * varsInScope);
for (Iterator<Var> i1 = scope.getVars(); i1.hasNext();) {
Var v1 = i1.next();
for (Iterator<Var> i2 = scope.getVars(); i2.hasNext();) {
Var v2 = i2.next();
if (v1 == v2 || !interferenceGraph.hasNode(v1) ||
!interferenceGraph.hasNode(v2)) {
// Skip nodes that were not added. They are globals and escaped
// locals. Also avoid merging a variable with itself.
continue;
}
boolean v1OutLive = state.getOut().isLive(v1);
boolean v2OutLive = state.getOut().isLive(v2);
// Finally, check the live states and add edge when possible.
if (v1.getParentNode().getType() == Token.LP &&
v2.getParentNode().getType() == Token.LP) {
interferenceGraph.connectIfNotFound(v1, null, v2);
} else if ((state.getIn().isLive(v1) && state.getIn().isLive(v2)) ||
(v1OutLive && v2OutLive)) {
interferenceGraph.connectIfNotFound(v1, null, v2);
} else {
LiveRangeChecker checker1 =
new LiveRangeChecker(v1, v2OutLive ? null : v2);
LiveRangeChecker checker2 =
new LiveRangeChecker(v2, v1OutLive ? null : v1);
rangesToCheck.add(new CombinedLiveRangeChecker(checker1, checker2));
}
}
}
// Do the collected live range checks.
checkRanges(rangesToCheck, cfgNode.getValue());
for (CombinedLiveRangeChecker range : rangesToCheck) {
range.connectIfCrossed(interferenceGraph);
}
}
return interferenceGraph;
}
示例13: computeVariableNamesInterferenceGraph
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
private UndiGraph<Var, Void> computeVariableNamesInterferenceGraph(
NodeTraversal t, ControlFlowGraph<Node> cfg, Set<Var> escaped) {
UndiGraph<Var, Void> interferenceGraph =
new LinkedUndirectedGraph<Var, Void>();
Scope scope = t.getScope();
// First create a node for each non-escaped variable.
for (Iterator<Var> i = scope.getVars(); i.hasNext();) {
Var v = i.next();
if (!escaped.contains(v)) {
// TODO(user): In theory, we CAN coalesce function names just like
// any variables. Our Liveness analysis captures this just like it as
// described in the specification. However, we saw some zipped and
// and unzipped size increase after this. We are not totally sure why
// that is but, for now, we will respect the dead functions and not play
// around with it.
if (!NodeUtil.isFunction(v.getParentNode())) {
interferenceGraph.createNode(v);
}
}
}
// Go through every single point of the program and look at each variable
// pairs. If they are both live at the same time, at an edge between them.
for (DiGraphNode<Node, Branch> cfgNode : cfg.getDirectedGraphNodes()) {
FlowState<LiveVariableLattice> state = cfgNode.getAnnotation();
if (cfg.isImplicitReturn(cfgNode)) {
continue;
}
int varsInScope = scope.getVarCount();
ArrayList<CombinedLiveRangeChecker> rangesToCheck =
new ArrayList<CombinedLiveRangeChecker>(
varsInScope * varsInScope);
for (Iterator<Var> i1 = scope.getVars(); i1.hasNext();) {
Var v1 = i1.next();
for (Iterator<Var> i2 = scope.getVars(); i2.hasNext();) {
Var v2 = i2.next();
if (v1 == v2 || !interferenceGraph.hasNode(v1) ||
!interferenceGraph.hasNode(v2)) {
// Skip nodes that were not added. They are globals and escaped
// locals. Also avoid merging a variable with itself.
continue;
}
boolean v1OutLive = state.getOut().isLive(v1);
boolean v2OutLive = state.getOut().isLive(v2);
// Finally, check the live states and add edge when possible.
if (v1.getParentNode().getType() == Token.LP &&
v2.getParentNode().getType() == Token.LP) {
interferenceGraph.connectIfNotFound(v1, null, v2);
} else if ((state.getIn().isLive(v1) && state.getIn().isLive(v2)) ||
(v1OutLive && v2OutLive)) {
interferenceGraph.connectIfNotFound(v1, null, v2);
} else {
LiveRangeChecker checker1 =
new LiveRangeChecker(v1, v2OutLive ? null : v2);
LiveRangeChecker checker2 =
new LiveRangeChecker(v2, v1OutLive ? null : v1);
rangesToCheck.add(new CombinedLiveRangeChecker(checker1, checker2));
}
}
}
// Do the collected live range checks.
checkRanges(rangesToCheck, cfgNode.getValue());
for (CombinedLiveRangeChecker range : rangesToCheck) {
range.connectIfCrossed(interferenceGraph);
}
}
return interferenceGraph;
}
示例14: tryRemoveDeadAssignments
import com.google.javascript.jscomp.graph.DiGraph.DiGraphNode; //导入方法依赖的package包/类
/**
* 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,
Map<String, Var> allVarsInFn) {
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.getToken()) {
case IF:
case WHILE:
case DO:
tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state, allVarsInFn);
continue;
case FOR:
case FOR_IN:
case FOR_OF:
if (n.isVanillaFor()) {
tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state, allVarsInFn);
}
continue;
case SWITCH:
case CASE:
case RETURN:
if (n.hasChildren()) {
tryRemoveAssignment(t, n.getFirstChild(), state, allVarsInFn);
}
continue;
// TODO(user): case VAR: Remove var a=1;a=2;.....
default:
break;
}
tryRemoveAssignment(t, n, state, allVarsInFn);
}
}