private class InlineObjectLiterals.InliningBehavior extends java.lang.Object implements ReferenceCollectingCallback.Behavior
Modifier and Type | Field and Description |
---|---|
private java.util.Set<Var> |
staleVars
A list of variables that should not be inlined, because their
reference information is out of sync with the state of the AST.
|
Modifier | Constructor and Description |
---|---|
private |
InliningBehavior() |
Modifier and Type | Method and Description |
---|---|
void |
afterExitScope(NodeTraversal t,
ReferenceCollectingCallback.ReferenceMap referenceMap)
Called after we finish with a scope.
|
private void |
blacklistVarReferencesInTree(Node root,
Scope scope)
If there are any variable references in the given node tree,
blacklist them to prevent the pass from trying to inline the
variable.
|
private java.util.Map<java.lang.String,java.lang.String> |
computeVarList(ReferenceCollectingCallback.ReferenceCollection referenceInfo)
Computes a list of ever-referenced keys in the object being
inlined, and returns a mapping of key name -> generated
variable name.
|
private void |
fillInitialValues(ReferenceCollectingCallback.Reference init,
java.util.Map<java.lang.String,Node> initvals)
Populates a map of key names -> initial assigned values.
|
private boolean |
isInlinableObject(java.util.List<ReferenceCollectingCallback.Reference> refs)
Counts the number of direct (full) references to an object.
|
private boolean |
isVarInlineForbidden(Var var)
Whether the given variable is forbidden from being inlined.
|
private boolean |
isVarOrAssignExprLhs(Node n) |
private void |
replaceAssignmentExpression(Var v,
ReferenceCollectingCallback.Reference ref,
java.util.Map<java.lang.String,java.lang.String> varmap)
Replaces an assignment like x = {...} with t1=a,t2=b,t3=c,true.
|
private void |
splitObject(Var v,
ReferenceCollectingCallback.Reference init,
ReferenceCollectingCallback.ReferenceCollection referenceInfo)
Splits up the object literal into individual variables, and
updates all uses.
|
private final java.util.Set<Var> staleVars
public void afterExitScope(NodeTraversal t, ReferenceCollectingCallback.ReferenceMap referenceMap)
ReferenceCollectingCallback.Behavior
afterExitScope
in interface ReferenceCollectingCallback.Behavior
private void blacklistVarReferencesInTree(Node root, Scope scope)
private boolean isVarInlineForbidden(Var var)
private boolean isInlinableObject(java.util.List<ReferenceCollectingCallback.Reference> refs)
x; x.fn();
private boolean isVarOrAssignExprLhs(Node n)
private java.util.Map<java.lang.String,java.lang.String> computeVarList(ReferenceCollectingCallback.ReferenceCollection referenceInfo)
private void fillInitialValues(ReferenceCollectingCallback.Reference init, java.util.Map<java.lang.String,Node> initvals)
private void replaceAssignmentExpression(Var v, ReferenceCollectingCallback.Reference ref, java.util.Map<java.lang.String,java.lang.String> varmap)
private void splitObject(Var v, ReferenceCollectingCallback.Reference init, ReferenceCollectingCallback.ReferenceCollection referenceInfo)