Documentation of 'org.python.indexer.Scope' Java class
Scope
org.python.indexer

Class Scope



  • public class Scope
    extends java.lang.Object
    Symbol table.
    • Method Detail

      • setTable

        public void setTable(java.util.Map<java.lang.String,NBinding> table)
      • getTable

        public java.util.Map<java.lang.String,NBinding> getTable()
        Returns an immutable view of the table.
      • setParent

        public void setParent(Scope parent)
      • getParent

        public Scope getParent()
      • addSuper

        public void addSuper(Scope sup)
      • setSupers

        public void setSupers(java.util.List<Scope> supers)
      • getSupers

        public java.util.List<Scope> getSupers()
      • setScopeType

        public void setScopeType(Scope.Type type)
      • isFunctionScope

        public boolean isFunctionScope()
      • addGlobalName

        public void addGlobalName(java.lang.String name)
        Mark a name as being global (i.e. module scoped) for name-binding and name-lookup operations in this code block and any nested scopes.
      • isGlobalName

        public boolean isGlobalName(java.lang.String name)
        Returns true if name appears in a global statement in this scope or any enclosing scope.
      • put

        public NBinding put(java.lang.String id,
                            NNode loc,
                            NType type,
                            NBinding.Kind kind)
        Adds a definition and/or reference to the table. If there is no binding for id, creates one and gives it type and kind.

        If a binding already exists, then add either a definition or a reference at loc to the binding. By convention we consider it a definition if the type changes. If the passed type is different from the binding's current type, set the binding's type to the union of the old and new types, and add a definition. If the new type is the same, just add a reference.

        If the binding already exists, kind is only updated if a definition was added and the binding's type was previously the unknown type.

      • putAttr

        public NBinding putAttr(java.lang.String id,
                                NNode loc,
                                NType type,
                                NBinding.Kind kind)
        Same as put(java.lang.String, org.python.indexer.NBinding), but adds the name as an attribute of this scope. Looks up the superclass chain to see if the attribute exists, rather than looking in the lexical scope chain.
        Returns:
        the new binding, or null if the current scope does not have a properly initialized path.
      • update

        public NBinding update(java.lang.String id,
                               NNode loc,
                               NType type,
                               NBinding.Kind kind)
        Adds a new binding for id. If a binding already existed, replaces its previous definitions, if any, with loc. Sets the binding's type to type (not a union with the previous type).
      • update

        public NBinding update(java.lang.String id,
                               Def loc,
                               NType type,
                               NBinding.Kind kind)
        Adds a new binding for id. If a binding already existed, replaces its previous definitions, if any, with loc. Sets the binding's type to type (not a union with the previous type).
      • remove

        public void remove(java.lang.String id)
      • copy

        public Scope copy(Scope.Type tableType)
        Create a copy of the symbol table but without the links to parent, supers and children. Useful for creating instances.
        Returns:
        the symbol table for use by the instance.
      • setPath

        public void setPath(java.lang.String path)
      • getPath

        public java.lang.String getPath()
      • setPath

        public void setPath(java.lang.String a,
                            java.lang.String b)
      • lookup

        public NBinding lookup(java.lang.String name)
        Look up a name (String) in the current symbol table. If not found, recurse on the parent table.
      • lookup

        public NBinding lookup(NNode n)
        Specialized version for the convenience of looking up Names. For all other types return null.
      • lookupLocal

        public NBinding lookupLocal(java.lang.String name)
        Look up a name, but only in the current scope.
        Returns:
        the local binding for name, or null.
      • lookupAttr

        public NBinding lookupAttr(java.lang.String name,
                                   boolean supersOnly)
        Look up an attribute in the type hierarchy. Don't look at parent link, because the enclosing scope may not be a super class. The search is "depth first, left to right" as in Python's (old) multiple inheritance rule. The new MRO can be implemented, but will probably not introduce much difference.
        Parameters:
        supersOnly - search only in the supers' scopes, not in local table.
      • lookupType

        public NType lookupType(java.lang.String name)
        Look up the scope chain for a binding named name and if found, return its type.
      • lookupType

        public NType lookupType(java.lang.String name,
                                boolean localOnly)
        Look for a binding named name and if found, return its type.
        Parameters:
        localOnly - true to look only in the current scope; if false, follows the scope chain.
      • lookupTypeAttr

        public NType lookupTypeAttr(java.lang.String name)
      • lookupBounded

        public NBinding lookupBounded(java.lang.String name,
                                      Scope.Type typebound)
        Look up a name, but the search is bounded by a type and will not proceed to an outer scope when reaching a certain type of symbol table.
        Parameters:
        name - the name to be looked up
        typebound - the type we wish the search to be bounded at
        Returns:
        a binding, or null if not found
      • isScope

        public boolean isScope()
        Returns true if this is a scope in which names may be bound.
      • getScopeSymtab

        public Scope getScopeSymtab()
        Find the enclosing scope-defining symbol table.

        More precisely, if a form introduces a new name in the "current scope", resolving the form needs to search up the symbol-table chain until it finds the table representing the scope to which the name should be added. Used by NameBinder to create new name bindings in the appropriate enclosing table with the appropriate binding type.

      • lookupScope

        public NBinding lookupScope(java.lang.String name)
        Look up a name, but bounded by a scope defining construct. Those scopes are of type module, class, instance or function. This is used in determining the locations of a variable's definition.
      • getSymtabOfType

        public Scope getSymtabOfType(Scope.Type type)
        Find a symbol table of a certain type in the enclosing scopes.
      • getGlobalTable

        public Scope getGlobalTable()
        Returns the global scope (i.e. the module scope for the current module).
      • getEnclosingLexicalScope

        public Scope getEnclosingLexicalScope()
        Returns the containing lexical scope (which may be this scope) for lexical name lookups. In particular, it skips class scopes.
      • isNameBindingPhase

        public boolean isNameBindingPhase()
        Name binding occurs in a separate pass before the name resolution pass, building out the scope tree and binding names in the correct scopes. In this pass, the name binding and lookup rules are slightly different. This condition is transient: no scopes will be in the name-binding phase in a completed index (or module).
      • setNameBindingPhase

        public void setNameBindingPhase(boolean isBindingPhase)
      • merge

        public void merge(Scope other)
        Merge all records from another symbol table. Used by import from *.
      • keySet

        public java.util.Set<java.lang.String> keySet()
      • values

        public java.util.Collection<NBinding> values()
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,NBinding>> entrySet()
      • isEmpty

        public boolean isEmpty()
      • clear

        public void clear()
        Dismantles all resources allocated by this scope.
      • newLambdaName

        public java.lang.String newLambdaName()
      • extendPathForParam

        public java.lang.String extendPathForParam(java.lang.String name)
        Generates a qname for a parameter of a function or method. There is not enough context for extendPath(java.lang.String) to differentiate params from locals, so callers must use this method when the name is known to be a parameter name.
      • extendPath

        public java.lang.String extendPath(java.lang.String name)
        Constructs a qualified name by appending name to this scope's qname.

        The indexer uses globally unique fully qualified names to address identifier definition sites. Many Python identifiers are already globally addressable using dot-separated package, class and attribute names.

        Function variables and parameters are not globally addressable in the language, so the indexer uses a special path syntax for creating globally unique qualified names for them. By convention the syntax is "@" for parameters and "&" for local variables.

        Parameters:
        name - a name to append to the current qname
        Returns:
        the qname for name. Does not change this scope's path.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toShortString

        public java.lang.String toShortString()

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.