class CrossModuleCodeMotion extends java.lang.Object implements CompilerPass
Compiler
pass for moving code to a deeper module if possible.
- currently it only moves functions + variablesModifier and Type | Class and Description |
---|---|
private static class |
CrossModuleCodeMotion.Declaration |
private class |
CrossModuleCodeMotion.InstanceofInfo |
private class |
CrossModuleCodeMotion.NamedInfo
useful information for each variable candidate
|
Modifier and Type | Field and Description |
---|---|
private AbstractCompiler |
compiler |
private JSModuleGraph |
graph |
private java.util.Map<Node,CrossModuleCodeMotion.InstanceofInfo> |
instanceofNodes |
private static java.util.logging.Logger |
logger |
private java.util.Map<JSModule,Node> |
moduleVarParentMap
Map from module to the node in that module that should parent any string
variable declarations that have to be moved into that module
|
private java.util.Map<Var,CrossModuleCodeMotion.NamedInfo> |
namedInfo |
private boolean |
parentModuleCanSeeSymbolsDeclaredInChildren |
Constructor and Description |
---|
CrossModuleCodeMotion(AbstractCompiler compiler,
JSModuleGraph graph,
boolean parentModuleCanSeeSymbolsDeclaredInChildren)
Creates an instance.
|
Modifier and Type | Method and Description |
---|---|
private static boolean |
canMoveValue(ReferenceCollectingCallback collector,
Scope scope,
Node n)
Determines whether the given value is eligible to be moved across modules.
|
private void |
collectReferences(Node root) |
private JSModule |
getModule(ReferenceCollectingCallback.Reference ref) |
private CrossModuleCodeMotion.NamedInfo |
getNamedInfo(Var v)
get the information on a variable
|
private static boolean |
hasConditionalAncestor(Node n)
return true if the node has any form of conditional in its ancestry
TODO(nicksantos) keep track of the conditionals in the ancestry, so
that we don't have to recrawl it.
|
private void |
makeInstanceOfCodeOrderIndependent()
Transforms instanceof usages into an expression that short circuits to
false if tested with a constructor that is undefined.
|
private boolean |
maybeProcessDeclaration(ReferenceCollectingCallback collector,
ReferenceCollectingCallback.Reference ref,
CrossModuleCodeMotion.NamedInfo info)
Determines whether the given NAME node belongs to a declaration that
can be moved across modules.
|
private void |
moveCode()
move the code accordingly
|
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
private void |
processRead(ReferenceCollectingCallback.Reference ref,
CrossModuleCodeMotion.NamedInfo info)
Process the reads to named variables
|
private void |
processReference(ReferenceCollectingCallback collector,
ReferenceCollectingCallback.Reference ref,
CrossModuleCodeMotion.NamedInfo info) |
private static final java.util.logging.Logger logger
private final AbstractCompiler compiler
private final JSModuleGraph graph
private final java.util.Map<JSModule,Node> moduleVarParentMap
private final java.util.Map<Var,CrossModuleCodeMotion.NamedInfo> namedInfo
private final java.util.Map<Node,CrossModuleCodeMotion.InstanceofInfo> instanceofNodes
private final boolean parentModuleCanSeeSymbolsDeclaredInChildren
CrossModuleCodeMotion(AbstractCompiler compiler, JSModuleGraph graph, boolean parentModuleCanSeeSymbolsDeclaredInChildren)
compiler
- The compilerpublic void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treeprivate void moveCode()
private static boolean hasConditionalAncestor(Node n)
private CrossModuleCodeMotion.NamedInfo getNamedInfo(Var v)
private void processRead(ReferenceCollectingCallback.Reference ref, CrossModuleCodeMotion.NamedInfo info)
private void collectReferences(Node root)
private void processReference(ReferenceCollectingCallback collector, ReferenceCollectingCallback.Reference ref, CrossModuleCodeMotion.NamedInfo info)
private JSModule getModule(ReferenceCollectingCallback.Reference ref)
private boolean maybeProcessDeclaration(ReferenceCollectingCallback collector, ReferenceCollectingCallback.Reference ref, CrossModuleCodeMotion.NamedInfo info)
private static boolean canMoveValue(ReferenceCollectingCallback collector, Scope scope, Node n)
private void makeInstanceOfCodeOrderIndependent()