\d(dZddlZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZddlZgdZdZGddZeZGdd ZGd d eZGd d eZGddZedkrddlZddlZeejd5Ze Z!dddn #1swxYwYee!ej"#ejdddZ$e$%D]JZ&e$'e&Z(e)e(e(*e(+IdSdS)z2Interface to the compiler's internal symbol tablesN)USE DEF_GLOBAL DEF_NONLOCAL DEF_LOCAL DEF_PARAM DEF_IMPORT DEF_BOUND DEF_ANNOT SCOPE_OFF SCOPE_MASKFREELOCALGLOBAL_IMPLICITGLOBAL_EXPLICITCELL)symtable SymbolTableClassFunctionSymbolcNtj|||}t||S)z Return the toplevel *SymbolTable* for the source code. *filename* is the name of the file with the code and *compile_type* is the *compile()* mode argument. ) _symtabler_newSymbolTable)codefilename compile_typetops ..\python\lib\symtable.pyrr s(  T8\ : :C 3 ) ))c eZdZdZdZdZdS)SymbolTableFactoryc6tj|_dSN)weakrefWeakValueDictionary_SymbolTableFactory__memoselfs r__init__zSymbolTableFactory.__init__s133 rc|jtjkrt||S|jtjkrt ||St ||Sr#)typer TYPE_FUNCTIONr TYPE_CLASSrr)r(tablers rnewzSymbolTableFactory.newsR :0 0 0E8,, , :- - -)) )5(+++rc||f}|j|d}| |||x}|j|<|Sr#)r&getr/)r(r.rkeyobjs r__call__zSymbolTableFactory.__call__ sIXokooc4(( ;%)XXeX%>%> >C$+c" rN)__name__ __module__ __qualname__r)r/r4rrr!r!sA444,,,rr!cbeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdS)rc0||_||_i|_dSr#)_table _filename_symbols)r( raw_tablers rr)zSymbolTable.__init__,s ! rc|jtkrd}nd|jjz}|jjdkrd||jSd||jj|jS)Nz%s rz<{0}SymbolTable for module {1}>z<{0}SymbolTable for {1} in {2}>) __class__rr5r;nameformatr<)r(kinds r__repr__zSymbolTable.__repr__1sw >[ ( (DD4>22D ; u $ $4;;D$.QQ Q4;;D<@Ks ; y4 4 48 ; y6 6 6: ; y3 3 37{9,,,%,,T[-=>>-,,,,rc|jjS)z,Return an identifier for the table. )r;idr's rget_idzSymbolTable.get_idMs{~rc|jjS)zReturn the table's name. This corresponds to the name of the class, function or 'top' if the table is for a class, function or global respectively. )r;rBr's rget_namezSymbolTable.get_nameRs{rc|jjS)zPReturn the number of the first line in the block for the table. )r;linenor's r get_linenozSymbolTable.get_lineno[s{!!rcPt|jjtjkS)zJReturn *True* if the locals in the table are optimizable. )boolr;r+rr,r's r is_optimizedzSymbolTable.is_optimizedasDK$ (??@@@rc4t|jjS)zAReturn *True* if the block is a nested class or function.)rXr;nestedr's r is_nestedzSymbolTable.is_nestedgsDK&'''rc4t|jjS)z:Return *True* if the block has nested namespaces. )rXr;childrenr's r has_childrenzSymbolTable.has_childrenlsDK()))rc>|jjS)zKReturn a view object containing the names of symbols in the table. )r;symbolskeysr's rget_identifierszSymbolTable.get_identifiersqs{"'')))rc|j|}|T|jj|}||}|jjdk}t ||||x}|j|<|S)zLLookup a *name* in the table. Returns a *Symbol* instance. Nr module_scope)r=r1r;ra_SymbolTable__check_childrenrBr)r(rBsymflags namespacesrfs rlookupzSymbolTable.lookupvs m%% ;K'-E..t44J K,5L(.tUJz+SymbolTable.get_symbols..s%GGGu E""GGGr)rcr's`r get_symbolszSymbolTable.get_symbolss,HGGG0D0D0F0FGGGGrc8fdjjDS)NcPg|]"}|jk t|j#Sr8)rBrr<)rnstrBr(s rrpz0SymbolTable.__check_children..s8$$$7d?? DN33"??rr;r^)r(rBs``r__check_childrenzSymbolTable.__check_childrens9$$$$$+.$$$ $rc4fdjjDS)z3Return a list of the nested symbol tables. c:g|]}t|jSr8)rr<)rnrtr(s rrpz,SymbolTable.get_children..s5000 DN33000rrur's`r get_childrenzSymbolTable.get_childrens30000+.000 0rN)r5r6r7r)rErNrQrSrVrYr\r_rcrkrqrgryr8rrrr*s L L L ? ? ?    """ AAA ((( *** ***   HHH $$$ 00000rrcFeZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ dS)rNcbtfdDS)Nc3RK|]!}jj||V"dSr#)r;ra)rnror( test_funcs r z-Function.__idents_matching..sO??u! $+"5e"<==?U??????r)tuplerc)r(r}s``r__idents_matchingzFunction.__idents_matchingsL?????(<(<(>(>????? ?rcT|j|d|_|jS)z6Return a tuple of parameters to the function. Nc|tzSr#)rxs rz)Function.get_parameters..s A Mr)_Function__params_Function__idents_matchingr's rget_parameterszFunction.get_parameterss- =  223I3IJJDM}rcz|j-ttffd}|||_|jS)z2Return a tuple of locals in the function. Nc,|tz tzvSr#r r )rlocss rrz%Function.get_locals..sqI~;Dr)_Function__localsrrr)r(testrs @r get_localszFunction.get_localssA = 4=DDDDDD 22488DM}rcz|j-ttffd}|||_|jS)z3Return a tuple of globals in the function. Nc,|tz tzvSr#r)rglobs rrz&Function.get_globals..sa9n :tCr)_Function__globalsrrr)r(rrs @r get_globalszFunction.get_globalssB > !#_5DCCCCD!33D99DN~rcT|j|d|_|jS)z5Return a tuple of nonlocals in the function. Nc|tzSr#)rrs rrz(Function.get_nonlocals..s q.si: =$Fr)_Function__freesr)r(is_frees r get_freeszFunction.get_freess1 < FFG11'::DL|r)r5r6r7rrrrrrrrrrrr8rrrrsHHGIK???   rrceZdZdZdZdS)rNc||j/i}|jjD] }d||j< t ||_|jS)z9Return a tuple of methods declared in the class. NrJ)_Class__methodsr;r^rBr)r(drts r get_methodszClass.get_methodssG > !Ak*  "' "1XXDN~r)r5r6r7rrr8rrrrs(IrrcveZdZddddZdZdZdZdZd Zd Z d Z d Z d Z dZ dZdZdZdZdZdS)rNFrecp||_||_|tz tz|_|pd|_||_dS)Nr8) _Symbol__name_Symbol__flagsr r _Symbol__scope_Symbol__namespaces_Symbol__module_scope)r(rBrirjrfs rr)zSymbol.__init__s<  *j8 &,"*rc6d|jS)Nz)rCrr's rrEzSymbol.__repr__s&&t{333rc|jS)z#Return a name of a symbol. )rr's rrSzSymbol.get_names {rcDt|jtjzS)zBReturn *True* if the symbol is used in its block. )rXrrrr's r is_referencedzSymbol.is_referencedsDL9=0111rc:t|jtzS)z4Return *True* if the symbol is a parameter. )rXrrr's r is_parameterzSymbol.is_parameterDL9,---rcrt|jttfvp|jo|jt zS)z/Return *True* if the symbol is global. )rXrrrrrr r's r is_globalzSymbol.is_globals?DL_o$FFJ+H y0HKK Krc:t|jtzS)z(Return *True* if the symbol is nonlocal.)rXrrr's r is_nonlocalzSymbol.is_nonlocalsDL</000rc<t|jtkS)zOReturn *True* if the symbol is declared global with a global statement.)rXrrr's ris_declared_globalzSymbol.is_declared_globalsDLO3444rcrt|jttfvp|jo|jt zS)z.Return *True* if the symbol is local. )rXrrrrrr r's ris_localzSymbol.is_locals>DLUDM1J+H y0HKK Krc:t|jtzS)z2Return *True* if the symbol is annotated. )rXrr r's r is_annotatedzSymbol.is_annotated rrc<t|jtkS)zIReturn *True* if a referenced symbol is not assigned to. )rXrr r's rrzSymbol.is_freesDLD()))rc:t|jtzS)zQReturn *True* if the symbol is created from an import statement. )rXrrr's r is_importedzSymbol.is_importedsDL:-...rc:t|jtzS)z)Return *True* if a symbol is assigned to.)rXrrr's r is_assignedzSymbol.is_assignedsDL9,---rc*t|jS)aReturns *True* if name binding introduces new namespace. If the name is used as the target of a function or class statement, this will be true. Note that a single name can be bound to multiple objects. If is_namespace() is true, the name may also be bound to other objects, like an int or list, that does not introduce a new namespace. )rXrr's r is_namespacezSymbol.is_namespace!sD%&&&rc|jS)z.Return a list of namespaces bound to this name)rr's rget_namespaceszSymbol.get_namespaces.s   rct|jdkrtdt|jdkrtd|jdS)zReturn the single namespace bound to this name. Raises ValueError if the name is bound to multiple namespaces or no namespace. rz#name is not bound to any namespacesrJz$name is bound to multiple namespaces)lenr ValueErrorr's r get_namespacezSymbol.get_namespace2s\ t ! !Q & &BCC C " # #a ' 'CDD D$Q' 'rr#)r5r6r7r)rErSrrrrrrrrrrrrrr8rrrrs+U+++++444 222 ... KKK 111555 KKK ... *** /// ... ' ' '!!! ( ( ( ( (rr__main__rJexec),__doc__rrrrrrrr r r r r rrrrr$__all__rr!rrrrrr5ossysopenargvfreadsrcpathsplitmodrcrorkinfoprintrrr8rrrs884444444444444444444444444444444444 D D D***$%$&&i0i0i0i0i0i0i0i0X33333{333l     K   b(b(b(b(b(b(b(b(H zNNNNNNN chqk  affhh (3 chqk2215v > >C$$&&::zz%   dDMMOOT%6%6%8%89999 ::s%CC  C