final class CombinedCompilerPass extends java.lang.Object implements HotSwapCompilerPass, NodeTraversal.ScopedCallback
A compiler pass combining multiple NodeTraversal.Callback
and NodeTraversal.ScopedCallback
objects. This pass can be used to separate
logically different verifications without incurring any additional traversal
and CFG generation costs.
Due to this compiler pass' nature, none of the callbacks may mutate the parse tree.
TODO(user):
This combined pass is currently limited in the type of callbacks it can
combine due to the difficulty of handling NodeTraversal's methods that
initiate more recursion (e.g., NodeTraversal.traverse(Node)
and
NodeTraversal.traverseInnerNode(Node, Node, Scope)
). The
NodeTraversal
object passed to the individual callbacks should
be instrumented to emulate the correct behavior. For instance,
one could create a NodeTraversal
whose
NodeTraversal.traverseInnerNode(Node, Node, Scope)
ties
back into this compiler pass to give it context about what combined
passes are doing.
Modifier and Type | Class and Description |
---|---|
private static class |
CombinedCompilerPass.CallbackWrapper
Maintains information about a callback in order to simulate it being the
exclusive client of the shared
NodeTraversal . |
Modifier and Type | Field and Description |
---|---|
private CombinedCompilerPass.CallbackWrapper[] |
callbacks
The callbacks that this pass combines.
|
private AbstractCompiler |
compiler |
Constructor and Description |
---|
CombinedCompilerPass(AbstractCompiler compiler,
java.util.List<NodeTraversal.Callback> callbacks) |
CombinedCompilerPass(AbstractCompiler compiler,
NodeTraversal.Callback... callbacks)
Creates a combined compiler pass.
|
Modifier and Type | Method and Description |
---|---|
void |
enterScope(NodeTraversal t)
Called immediately after entering a new scope.
|
void |
exitScope(NodeTraversal t)
Called immediately before exiting a scope.
|
void |
hotSwapScript(Node scriptRoot,
Node originalRoot)
Process the JS with root node root.
|
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
boolean |
shouldTraverse(NodeTraversal t,
Node n,
Node parent)
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed.
|
(package private) static void |
traverse(AbstractCompiler compiler,
Node root,
java.util.List<NodeTraversal.Callback> callbacks) |
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
private final CombinedCompilerPass.CallbackWrapper[] callbacks
private final AbstractCompiler compiler
CombinedCompilerPass(AbstractCompiler compiler, NodeTraversal.Callback... callbacks)
compiler
- the compilerCombinedCompilerPass(AbstractCompiler compiler, java.util.List<NodeTraversal.Callback> callbacks)
static void traverse(AbstractCompiler compiler, Node root, java.util.List<NodeTraversal.Callback> callbacks)
public final void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treepublic void hotSwapScript(Node scriptRoot, Node originalRoot)
HotSwapCompilerPass
hotSwapScript
in interface HotSwapCompilerPass
scriptRoot
- Root node corresponding to the file that is modified,
should be of type Token.SCRIPT
.originalRoot
- Root node corresponding to the original version of the
file that is modified. Should be of type token.SCRIPT
.public boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed. If children are
traversed, they will be visited by
NodeTraversal.Callback.visit(NodeTraversal, Node, Node)
in postorder.
Implementations can have side effects (e.g. modifying the parse tree).
shouldTraverse
in interface NodeTraversal.Callback
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).
visit
in interface NodeTraversal.Callback
public void enterScope(NodeTraversal t)
NodeTraversal.ScopedCallback
enterScope
in interface NodeTraversal.ScopedCallback
public void exitScope(NodeTraversal t)
NodeTraversal.ScopedCallback
exitScope
in interface NodeTraversal.ScopedCallback