private static final class ProcessDefines.CollectDefines extends java.lang.Object implements NodeTraversal.Callback
Modifier and Type | Class and Description |
---|---|
private static class |
ProcessDefines.CollectDefines.RefInfo
A simple data structure for associating a Ref with the name
that it references.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,ProcessDefines.DefineInfo> |
allDefines |
private java.util.Map<Node,ProcessDefines.CollectDefines.RefInfo> |
allRefInfo |
private java.util.Map<java.lang.String,ProcessDefines.DefineInfo> |
assignableDefines |
private java.util.Deque<java.lang.Integer> |
assignAllowed |
private AbstractCompiler |
compiler |
private Node |
lvalueToRemoveLater |
Constructor and Description |
---|
CollectDefines(AbstractCompiler compiler,
java.util.List<GlobalNamespace.Name> listOfDefines) |
Modifier and Type | Method and Description |
---|---|
(package private) java.util.Map<java.lang.String,ProcessDefines.DefineInfo> |
getAllDefines()
Get a map of
ProcessDefines.DefineInfo structures, keyed by the name of
the define. |
private static Node |
getValueParent(GlobalNamespace.Ref ref)
Gets the parent node of the value for any assignment to a Name.
|
private boolean |
isAssignAllowed()
Determines whether assignment to a define should be allowed
at the current point of the traversal.
|
private boolean |
processDefineAssignment(NodeTraversal t,
java.lang.String name,
Node value,
Node valueParent)
Tracks the given define.
|
private static void |
setDefineInfoNotAssignable(ProcessDefines.DefineInfo info,
NodeTraversal t)
Records the fact that because of the current node in the node traversal,
the define can't ever be assigned again.
|
boolean |
shouldTraverse(NodeTraversal nodeTraversal,
Node n,
Node parent)
Keeps track of whether the traversal is in a conditional branch.
|
private void |
updateAssignAllowedStack(Node n,
boolean entering)
Determines whether assignment to a define should be allowed
in the subtree of the given node, and if not, records that fact.
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
private final AbstractCompiler compiler
private final java.util.Map<java.lang.String,ProcessDefines.DefineInfo> assignableDefines
private final java.util.Map<java.lang.String,ProcessDefines.DefineInfo> allDefines
private final java.util.Map<Node,ProcessDefines.CollectDefines.RefInfo> allRefInfo
private Node lvalueToRemoveLater
private final java.util.Deque<java.lang.Integer> assignAllowed
CollectDefines(AbstractCompiler compiler, java.util.List<GlobalNamespace.Name> listOfDefines)
java.util.Map<java.lang.String,ProcessDefines.DefineInfo> getAllDefines()
ProcessDefines.DefineInfo
structures, keyed by the name of
the define.public boolean shouldTraverse(NodeTraversal nodeTraversal, Node n, Node parent)
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
private void updateAssignAllowedStack(Node n, boolean entering)
n
- The node whose subtree we're about to enter or exit.entering
- True if we're entering the subtree, false otherwise.private boolean isAssignAllowed()
private boolean processDefineAssignment(NodeTraversal t, java.lang.String name, Node value, Node valueParent)
t
- The current traversal, for context.name
- The full name for this define.value
- The value assigned to the define.valueParent
- The parent node of value.private static Node getValueParent(GlobalNamespace.Ref ref)
var x = 3;
the parent would be the NAME node.private static void setDefineInfoNotAssignable(ProcessDefines.DefineInfo info, NodeTraversal t)
info
- Represents the define variable.t
- The current traversal.