{"modulePath":"github.com/go-python/gpython","version":"v0.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package symtable\n\n## Functions\n\n```go\nfunc AnalyzeCells(scopes Scopes, free StringSet)\n```\nIf a name is defined in free and also in locals, then this block\n\n\tprovides the binding for the free variable.  The name should be\n\tmarked CELL in this block and removed from the free list.\n\n\tNote that the current block's free variables are included in free.\n\tThat's safe because no name can be free and local in the same scope.\n\n## Types\n\n```go\ntype BlockType uint8\n```\nBlockType for SymTable\n\n```go\nconst (\n\tFunctionBlock BlockType = iota\n\tClassBlock\n\tModuleBlock\n)\n```\nBlockTypes\n\n```go\nfunc (i BlockType) String() string\n```\n\n```go\ntype Children []*SymTable\n```\n\n```go\ntype DefUseFlags uint8\n```\nDef-use flag information\n\n```go\nconst (\n\tDefGlobal    DefUseFlags = 1 \u003c\u003c iota // global stmt\n\tDefLocal                             // assignment in code block\n\tDefParam                             // formal parameter\n\tDefNonlocal                          // nonlocal stmt\n\tDefUse                               // name is used\n\tDefFree                              // name used but not defined in nested block\n\tDefFreeClass                         // free variable from class's method\n\tDefImport                            // assignment occurred via import\n\n\tDefBound = (DefLocal | DefParam | DefImport)\n\n\t// ScopeGlobalExplicit and ScopeGlobalImplicit are used internally by the symbol\n\t// table.  GLOBAL is returned from PyST_GetScope() for either of them.\n\t// It is stored in ste_symbols at bits 12-15.\n\tDefScopeMask = (DefGlobal | DefLocal | DefParam | DefNonlocal)\n)\n```\nFlags for def-use information\n\n```go\ntype LookupChild map[ast.Ast]*SymTable\n```\n\n```go\ntype OptType uint8\n```\nOptType for SymTable\n\n```go\ntype Scope uint8\n```\nScope\n\n```go\nconst (\n\tScopeInvalid Scope = iota\n\tScopeLocal\n\tScopeGlobalExplicit\n\tScopeGlobalImplicit\n\tScopeFree\n\tScopeCell\n)\n```\nScope definitions\n\n```go\nfunc (i Scope) String() string\n```\n\n```go\ntype Scopes map[string]Scope\n```\nAccumulate Scopes\n\n```go\ntype StringSet map[string]struct{}\n```\nStringSet for storing strings\n\n```go\nfunc (s StringSet) Add(elem string)\n```\nAdd adds elem to the set, returning the set\n\nIf the element already exists then it has no effect\n\n```go\nfunc (s StringSet) Contains(k string) bool\n```\nContains returns true if k is in s\n\n```go\nfunc (s StringSet) Copy() StringSet\n```\nCopy makes a shallow copy of s\n\n```go\nfunc (s StringSet) Discard(k string) bool\n```\nDiscard ensures k is not in the set returning true if it was found\n\n```go\nfunc (s StringSet) Update(other StringSet)\n```\nUpdate adds all the elements from the other set to this set.\n\n```go\ntype SymTable struct {\n\tType              BlockType // 'class', 'module', and 'function'\n\tName              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').\n\tFilename          string    // filename that this is being parsed from\n\tLineno            int       // number of the first line in the block this table represents.\n\tUnoptimized       OptType   // false if namespace is optimized\n\tNested            bool      // true if the block is a nested class or function.\n\tFree              bool      // true if block has free variables\n\tChildFree         bool      // true if a child block has free vars, including free refs to globals\n\tGenerator         bool      // true if namespace is a generator\n\tVarargs           bool      // true if block has varargs\n\tVarkeywords       bool      // true if block has varkeywords\n\tReturnsValue      bool      // true if namespace uses return with an argument\n\tNeedsClassClosure bool      // for class scopes, true if a closure over __class__ should be created\n\t// col_offset        int       // offset of first line of block\n\t// opt_lineno        int       // lineno of last exec or import *\n\t// opt_col_offset    int       // offset of last exec or import *\n\tTmpName int    // counter for listcomp temp vars\n\tPrivate string // name of current class or \"\"\n\n\tSymbols     Symbols\n\tGlobal      *SymTable // symbol table entry for module\n\tParent      *SymTable\n\tVarnames    []string    // list of function parameters\n\tChildren    Children    // Child SymTables\n\tLookupChild LookupChild // Child symtables keyed by ast\n}\n```\n\n```go\nfunc NewSymTable(Ast ast.Ast, filename string) (st *SymTable, err error)\n```\nMake a new top symbol table from the ast supplied\n\n```go\nfunc (st *SymTable) AddDef(node ast.Ast, name ast.Identifier, flags DefUseFlags)\n```\nAdd a symbol into the symble table\n\n```go\nfunc (st *SymTable) Analyze()\n```\nAnalyze the SymTable\n\n```go\nfunc (st *SymTable) AnalyzeBlock(bound, free, global StringSet)\n```\nMake final symbol table decisions for block of ste.\n\n\tArguments:\n\tst -- current symtable entry (input/output)\n\tbound -- set of variables bound in enclosing scopes (input).  bound\n\t    is nil for module blocks.\n\tfree -- set of free variables in enclosed scopes (output)\n\tglobals -- set of declared global variables in enclosing scopes (input)\n\n\tThe implementation uses two mutually recursive functions,\n\tanalyze_block() and analyze_child_block().  analyze_block() is\n\tresponsible for analyzing the individual names defined in a block.\n\tanalyze_child_block() prepares temporary namespace dictionaries\n\tused to evaluated nested blocks.\n\n\tThe two functions exist because a child block should see the name\n\tbindings of its enclosing blocks, but those bindings should not\n\tpropagate back to a parent block.\n\n```go\nfunc (st *SymTable) AnalyzeChildBlock(bound, free, global, child_free StringSet)\n```\n\n```go\nfunc (st *SymTable) AnalyzeName(scopes Scopes, name string, symbol Symbol, bound, local, free, global StringSet)\n```\nDecide on scope of name, given flags.\n\n\tThe namespace dictionaries may be modified to record information\n\tabout the new name.  For example, a new global will add an entry to\n\tglobal.  A name that was global can be changed to local.\n\n```go\nfunc (st *SymTable) DropClassFree(free StringSet)\n```\n\n```go\nfunc (st *SymTable) Find(scopeType Scope, flag DefUseFlags) (out []string)\n```\nReturn a sorted list of symbol names if the scope of a name matches either scopeType or flag is set\n\n```go\nfunc (st *SymTable) FindChild(Ast ast.Ast) *SymTable\n```\nFindChild finds SymTable attached to Ast - returns nil if not found\n\n```go\nfunc (st *SymTable) GetScope(name string) Scope\n```\nGetScope finds the scope for the name, returns ScopeInvalid if not found\n\n```go\nfunc (st *SymTable) Parse(Ast ast.Ast)\n```\nParse the ast into the symbol table\n\n```go\ntype Symbol struct {\n\tScope     Scope\n\tFlags     DefUseFlags\n\tLineno    int\n\tColOffset int\n}\n```\nInfo about a symbol\n\n```go\ntype Symbols map[string]Symbol\n```\n\n```go\nfunc (symbols Symbols) Update(scopes Scopes, bound, free StringSet, classflag bool)\n```\nEnter the final scope information into the st.Symbols dict. \\* \\* All arguments are dicts.  Modifies symbols, others are read-only.\n\n","path":"github.com/go-python/gpython/symtable","name":"symtable","synopsis":"","isRedistributable":true}
