class GlobalNamespace extends java.lang.Object implements StaticTypedScope<TypeI>, StaticSymbolTable<GlobalNamespace.Name,GlobalNamespace.Ref>
Modifier and Type | Class and Description |
---|---|
(package private) static class |
GlobalNamespace.AstChange
A simple data class that contains the information necessary to inspect
a node for changes to the global namespace.
|
private class |
GlobalNamespace.BuildGlobalNamespace
Builds a tree representation of the global namespace.
|
(package private) static class |
GlobalNamespace.Name
A name defined in global scope (e.g.
|
(package private) static class |
GlobalNamespace.Ref
A global name reference.
|
Modifier and Type | Field and Description |
---|---|
private AbstractCompiler |
compiler |
private int |
currentPreOrderIndex
Each reference has an index in post-order.
|
private Node |
externsRoot |
private Scope |
externsScope |
private boolean |
generated |
private java.util.List<GlobalNamespace.Name> |
globalNames
Global namespace tree
|
private boolean |
inExterns |
private java.util.Map<java.lang.String,GlobalNamespace.Name> |
nameMap
Maps names (e.g.
|
private Node |
root |
Constructor and Description |
---|
GlobalNamespace(AbstractCompiler compiler,
Node root)
Creates an instance that may emit warnings when building the namespace.
|
GlobalNamespace(AbstractCompiler compiler,
Node externsRoot,
Node root)
Creates an instance that may emit warnings when building the namespace.
|
Modifier and Type | Method and Description |
---|---|
private void |
ensureGenerated() |
java.lang.Iterable<GlobalNamespace.Name> |
getAllSymbols()
Returns all variables in this symbol table.
|
(package private) java.util.List<GlobalNamespace.Name> |
getNameForest()
Gets a list of the roots of the forest of the global names, where the
roots are the top-level names.
|
(package private) java.util.Map<java.lang.String,GlobalNamespace.Name> |
getNameIndex()
Gets an index of all the global names, indexed by full qualified name
(as in "a", "a.b.c", etc.).
|
GlobalNamespace.Name |
getOwnSlot(java.lang.String name)
Like
getSlot but does not recurse into parent scopes. |
StaticTypedScope<TypeI> |
getParentScope()
Returns the scope enclosing this one or null if none.
|
java.lang.Iterable<GlobalNamespace.Ref> |
getReferences(GlobalNamespace.Name slot)
Returns the references that point to the given symbol.
|
Node |
getRootNode()
Returns the root node associated with this scope.
|
StaticTypedScope<TypeI> |
getScope(GlobalNamespace.Name slot)
Returns the scope for a given symbol.
|
GlobalNamespace.Name |
getSlot(java.lang.String name)
Returns any defined slot within this scope for this name.
|
private static java.lang.String |
getTopVarName(java.lang.String name)
Gets the top variable name from a possibly namespaced name.
|
TypeI |
getTypeOfThis()
Returns the expected type of
this in the current scope. |
(package private) boolean |
hasExternsRoot() |
private boolean |
isGlobalNameReference(java.lang.String name,
Scope s)
Determines whether a name reference in a particular scope is a global name
reference.
|
private boolean |
isGlobalVarReference(java.lang.String name,
Scope s)
Determines whether a variable name reference in a particular scope is a
global variable reference.
|
private void |
process()
Builds the namespace lazily.
|
private void |
scanFromNode(GlobalNamespace.BuildGlobalNamespace builder,
JSModule module,
Scope scope,
Node n) |
(package private) void |
scanNewNodes(java.util.Set<GlobalNamespace.AstChange> newNodes)
If the client adds new nodes to the AST, scan these new nodes
to see if they've added any references to the global namespace.
|
private AbstractCompiler compiler
private final Node root
private final Node externsRoot
private boolean inExterns
private Scope externsScope
private boolean generated
private int currentPreOrderIndex
private java.util.List<GlobalNamespace.Name> globalNames
private java.util.Map<java.lang.String,GlobalNamespace.Name> nameMap
GlobalNamespace(AbstractCompiler compiler, Node root)
compiler
- The AbstractCompiler, for reporting code changesroot
- The root of the rest of the code to build a namespace for.GlobalNamespace(AbstractCompiler compiler, Node externsRoot, Node root)
compiler
- The AbstractCompiler, for reporting code changesexternsRoot
- The root of the externs to build a namespace for. If
this is null, externs and properties defined on extern types will not
be included in the global namespace. If non-null, it allows
user-defined function on extern types to be included in the global
namespace. E.g. String.foo.root
- The root of the rest of the code to build a namespace for.boolean hasExternsRoot()
public Node getRootNode()
StaticScope
getRootNode
in interface StaticScope
public StaticTypedScope<TypeI> getParentScope()
StaticTypedScope
getParentScope
in interface StaticTypedScope<TypeI>
getParentScope
in interface StaticScope
public GlobalNamespace.Name getSlot(java.lang.String name)
StaticTypedScope
getSlot
in interface StaticTypedScope<TypeI>
getSlot
in interface StaticScope
name
- The name of the variable slot to look up.null
if no
definition exists.public GlobalNamespace.Name getOwnSlot(java.lang.String name)
StaticTypedScope
getSlot
but does not recurse into parent scopes.getOwnSlot
in interface StaticTypedScope<TypeI>
getOwnSlot
in interface StaticScope
public TypeI getTypeOfThis()
StaticTypedScope
this
in the current scope.getTypeOfThis
in interface StaticTypedScope<TypeI>
public java.lang.Iterable<GlobalNamespace.Ref> getReferences(GlobalNamespace.Name slot)
StaticSymbolTable
getReferences
in interface StaticSymbolTable<GlobalNamespace.Name,GlobalNamespace.Ref>
public StaticTypedScope<TypeI> getScope(GlobalNamespace.Name slot)
StaticSymbolTable
getScope
in interface StaticSymbolTable<GlobalNamespace.Name,GlobalNamespace.Ref>
public java.lang.Iterable<GlobalNamespace.Name> getAllSymbols()
StaticSymbolTable
getAllSymbols
in interface StaticSymbolTable<GlobalNamespace.Name,GlobalNamespace.Ref>
private void ensureGenerated()
java.util.List<GlobalNamespace.Name> getNameForest()
java.util.Map<java.lang.String,GlobalNamespace.Name> getNameIndex()
void scanNewNodes(java.util.Set<GlobalNamespace.AstChange> newNodes)
newNodes
- New nodes to check.private void scanFromNode(GlobalNamespace.BuildGlobalNamespace builder, JSModule module, Scope scope, Node n)
private void process()
private boolean isGlobalNameReference(java.lang.String name, Scope s)
name
- A variable or property name (e.g. "a" or "a.b.c.d")s
- The scope in which the name is referencedprivate static java.lang.String getTopVarName(java.lang.String name)
name
- A variable or qualified property name (e.g. "a" or "a.b.c.d")private boolean isGlobalVarReference(java.lang.String name, Scope s)
name
- A variable name (e.g. "a")s
- The scope in which the name is referenced