private class NameAnalyzer.FindDependencyScopes extends NodeTraversal.AbstractPostOrderCallback
Identifies all dependency scopes.
A dependency scope is a relationship between a node tree and a name that implies that the node tree will not execute (and thus can be eliminated) if the name is never referenced.
The entire parse tree is ultimately in a dependency scope relationship
with window
(or an equivalent name for the global scope), but
the goal here is to find finer-grained relationships. This callback creates
dependency scopes for every assignment statement, variable declaration, and
function call in the global scope.
Note that dependency scope node trees aren't necessarily disjoint.
In the following code snippet, for example, the function definition
forms a dependency scope with the name f
and the assignment
inside the function forms a dependency scope with the name x
.
var x; function f() { x = 1; }
Modifier | Constructor and Description |
---|---|
private |
FindDependencyScopes() |
Modifier and Type | Method and Description |
---|---|
private void |
recordAssignment(NodeTraversal t,
Node n,
Node recordNode) |
private void |
recordConsumers(NodeTraversal t,
Node n,
Node recordNode) |
private void |
recordDepScope(Node node,
NameAnalyzer.NameInformation name)
Defines a dependency scope.
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
shouldTraverse
public void visit(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in postorder (after its children have been visited).
A node is visited only if all its parents should be traversed
(NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
).
Implementations can have side effects (e.g. modifying the parse tree).
private void recordConsumers(NodeTraversal t, Node n, Node recordNode)
private void recordAssignment(NodeTraversal t, Node n, Node recordNode)
private void recordDepScope(Node node, NameAnalyzer.NameInformation name)