Documentation ¶
Index ¶
- func AnalyzeCells(scopes Scopes, free StringSet)
- type BlockType
- type Children
- type DefUseFlags
- type LookupChild
- type OptType
- type Scope
- type Scopes
- type StringSet
- type SymTable
- func (st *SymTable) AddDef(node ast.Ast, name ast.Identifier, flags DefUseFlags)
- func (st *SymTable) Analyze()
- func (st *SymTable) AnalyzeBlock(bound, free, global StringSet)
- func (st *SymTable) AnalyzeChildBlock(bound, free, global, child_free StringSet)
- func (st *SymTable) AnalyzeName(scopes Scopes, name string, symbol Symbol, ...)
- func (st *SymTable) DropClassFree(free StringSet)
- func (st *SymTable) Find(scopeType Scope, flag DefUseFlags) (out []string)
- func (st *SymTable) FindChild(Ast ast.Ast) *SymTable
- func (st *SymTable) GetScope(name string) Scope
- func (st *SymTable) Parse(Ast ast.Ast)
- type Symbol
- type Symbols
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnalyzeCells ¶
If a name is defined in free and also in locals, then this block
provides the binding for the free variable. The name should be marked CELL in this block and removed from the free list. Note that the current block's free variables are included in free. That's safe because no name can be free and local in the same scope.
Types ¶
type DefUseFlags ¶
type DefUseFlags uint8
Def-use flag information
const ( DefGlobal DefUseFlags = 1 << iota // global stmt DefLocal // assignment in code block DefParam // formal parameter DefNonlocal // nonlocal stmt DefUse // name is used DefFree // name used but not defined in nested block DefFreeClass // free variable from class's method DefImport // assignment occurred via import DefBound = (DefLocal | DefParam | DefImport) // ScopeGlobalExplicit and ScopeGlobalImplicit are used internally by the symbol // table. GLOBAL is returned from PyST_GetScope() for either of them. // It is stored in ste_symbols at bits 12-15. DefScopeMask = (DefGlobal | DefLocal | DefParam | DefNonlocal) )
Flags for def-use information
type LookupChild ¶
type Scope ¶
type Scope uint8
Scope
type StringSet ¶
type StringSet map[string]struct{}
StringSet for storing strings
func (StringSet) Add ¶
Add adds elem to the set, returning the set
If the element already exists then it has no effect
type SymTable ¶
type SymTable struct { Type BlockType // 'class', 'module', and 'function' Name string // name of the class if the table is for a class, the name of the function if the table is for a function, or 'top' if the table is global (get_type() returns 'module'). Filename string // filename that this is being parsed from Lineno int // number of the first line in the block this table represents. Unoptimized OptType // false if namespace is optimized Nested bool // true if the block is a nested class or function. Free bool // true if block has free variables ChildFree bool // true if a child block has free vars, including free refs to globals Generator bool // true if namespace is a generator Varargs bool // true if block has varargs Varkeywords bool // true if block has varkeywords ReturnsValue bool // true if namespace uses return with an argument NeedsClassClosure bool // for class scopes, true if a closure over __class__ should be created // col_offset int // offset of first line of block // opt_lineno int // lineno of last exec or import * // opt_col_offset int // offset of last exec or import * TmpName int // counter for listcomp temp vars Private string // name of current class or "" Symbols Symbols Global *SymTable // symbol table entry for module Parent *SymTable Varnames []string // list of function parameters Children Children // Child SymTables LookupChild LookupChild // Child symtables keyed by ast }
func NewSymTable ¶
Make a new top symbol table from the ast supplied
func (*SymTable) AddDef ¶
func (st *SymTable) AddDef(node ast.Ast, name ast.Identifier, flags DefUseFlags)
Add a symbol into the symble table
func (*SymTable) AnalyzeBlock ¶
Make final symbol table decisions for block of ste.
Arguments: st -- current symtable entry (input/output) bound -- set of variables bound in enclosing scopes (input). bound is nil for module blocks. free -- set of free variables in enclosed scopes (output) globals -- set of declared global variables in enclosing scopes (input) The implementation uses two mutually recursive functions, analyze_block() and analyze_child_block(). analyze_block() is responsible for analyzing the individual names defined in a block. analyze_child_block() prepares temporary namespace dictionaries used to evaluated nested blocks. The two functions exist because a child block should see the name bindings of its enclosing blocks, but those bindings should not propagate back to a parent block.
func (*SymTable) AnalyzeChildBlock ¶
func (*SymTable) AnalyzeName ¶
func (st *SymTable) AnalyzeName(scopes Scopes, name string, symbol Symbol, bound, local, free, global StringSet)
Decide on scope of name, given flags.
The namespace dictionaries may be modified to record information about the new name. For example, a new global will add an entry to global. A name that was global can be changed to local.
func (*SymTable) DropClassFree ¶
func (*SymTable) Find ¶
func (st *SymTable) Find(scopeType Scope, flag DefUseFlags) (out []string)
Return a sorted list of symbol names if the scope of a name matches either scopeType or flag is set
Click to show internal directories.
Click to hide internal directories.