B 7 @sNdZddlZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZddlZdddddgZd dZGd d d ZeZGd ddeZGd ddeZGdddeZGdddeZedkrJddlZddlZeejdZe Z!WdQRXee!ej"#ejdddZ$x0e$%D]$Z&e$'e&Z(e)e(e(*e(+q"WdS)z2Interface to the compiler's internal symbol tablesN)USE DEF_GLOBAL DEF_LOCAL DEF_PARAM DEF_IMPORT DEF_BOUND DEF_ANNOT SCOPE_OFF SCOPE_MASKFREELOCALGLOBAL_IMPLICITGLOBAL_EXPLICITCELLsymtable SymbolTableClassFunctionSymbolcCst|||}t||S)N) _symtabler_newSymbolTable)codefilenameZ compile_typetopr+/opt/alt/python37/lib/python3.7/symtable.pyr sc@s$eZdZddZddZddZdS)SymbolTableFactorycCst|_dS)N)weakrefZWeakValueDictionary_SymbolTableFactory__memo)selfrrr__init__szSymbolTableFactory.__init__cCs6|jtjkrt||S|jtjkr,t||St||S)N)typer TYPE_FUNCTIONr TYPE_CLASSrr)rtablerrrrnews     zSymbolTableFactory.newcCs8||f}|j|d}|dkr4|||}|j|<|S)N)rgetr%)rr$rkeyobjrrr__call__s zSymbolTableFactory.__call__N)__name__ __module__ __qualname__r r%r)rrrrrsrc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdS) rcCs||_||_i|_dS)N)_table _filename_symbols)rZ raw_tablerrrrr 'szSymbolTable.__init__cCsN|jtkrd}n d|jj}|jjdkr6d||jSd||jj|jSdS)Nz%s globalz<{0}SymbolTable for module {1}>z<{0}SymbolTable for {1} in {2}>) __class__rr*r-nameformatr.)rZkindrrr__repr__,s   zSymbolTable.__repr__cCs:|jjtjkrdS|jjtjkr$dS|jjtjkr6dSdS)NmoduleZfunctionclass)r-r!rZ TYPE_MODULEr"r#)rrrrget_type9szSymbolTable.get_typecCs|jjS)N)r-id)rrrrget_idCszSymbolTable.get_idcCs|jjS)N)r-r3)rrrrget_nameFszSymbolTable.get_namecCs|jjS)N)r-lineno)rrrr get_linenoIszSymbolTable.get_linenocCst|jjtjkS)N)boolr-r!rr")rrrr is_optimizedLszSymbolTable.is_optimizedcCs t|jjS)N)r>r-nested)rrrr is_nestedOszSymbolTable.is_nestedcCs t|jjS)N)r>r-children)rrrr has_childrenRszSymbolTable.has_childrencCsdS)z7Return true if the scope uses exec. Deprecated method.Fr)rrrrhas_execUszSymbolTable.has_execcCs |jjS)N)r-symbolskeys)rrrrget_identifiersYszSymbolTable.get_identifierscCsD|j|}|dkr@|jj|}||}t|||}|j|<|S)N)r/r&r-rE_SymbolTable__check_childrenr)rr3Zsymflags namespacesrrrlookup\s    zSymbolTable.lookupcsfddDS)Ncsg|]}|qSr)rK).0ident)rrr esz+SymbolTable.get_symbols..)rG)rr)rr get_symbolsdszSymbolTable.get_symbolscsfddjjDS)Ncs"g|]}|jkrt|jqSr)r3rr.)rLst)r3rrrrNhsz0SymbolTable.__check_children..)r-rB)rr3r)r3rrZ__check_childrengs zSymbolTable.__check_childrencsfddjjDS)Ncsg|]}t|jqSr)rr.)rLrP)rrrrNmsz,SymbolTable.get_children..)r-rB)rr)rr get_childrenls zSymbolTable.get_childrenN)r*r+r,r r5r8r:r;r=r?rArCrDrGrKrOrHrQrrrrr%s  c@sDeZdZdZdZdZdZddZddZddZ dd Z d d Z dS) rNcstfddDS)Nc3s"|]}jj|r|VqdS)N)r-rE)rLrM)r test_funcrr zsz-Function.__idents_matching..)tuplerG)rrRr)rrRrZ__idents_matchingyszFunction.__idents_matchingcCs |jdkr|dd|_|jS)NcSs|t@S)N)r)xrrrz)Function.get_parameters..)_Function__params_Function__idents_matching)rrrrget_parameters}s zFunction.get_parameterscs0|jdkr*ttffdd}|||_|jS)Ncs|t?t@kS)N)r r )rU)locsrrrVrWz%Function.get_locals..)_Function__localsr rrY)rtestr)r[r get_localss    zFunction.get_localscs0|jdkr*ttffdd}|||_|jS)Ncs|t?t@kS)N)r r )rU)globrrrVrWz&Function.get_globals..)_Function__globalsr rrY)rr]r)r_r get_globalss    zFunction.get_globalscCs$|jdkrdd}|||_|jS)NcSs|t?t@tkS)N)r r r )rUrrrrVrWz$Function.get_frees..)_Function__freesrY)ris_freerrr get_freess  zFunction.get_frees) r*r+r,rXr\rbr`rYrZr^rardrrrrrqsc@seZdZdZddZdS)rNcCs:|jdkr4i}x|jjD]}d||j<qWt||_|jS)N)_Class__methodsr-rBr3rT)rdrPrrr get_methodss   zClass.get_methods)r*r+r,rfrhrrrrrsc@seZdZd ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZdS)!rNcCs(||_||_|t?t@|_|p d|_dS)Nr) _Symbol__name_Symbol__flagsr r _Symbol__scope_Symbol__namespaces)rr3rIrJrrrr szSymbol.__init__cCs d|jS)Nz)r4ri)rrrrr5szSymbol.__repr__cCs|jS)N)ri)rrrrr;szSymbol.get_namecCst|jtj@S)N)r>rjrr)rrrr is_referencedszSymbol.is_referencedcCst|jt@S)N)r>rjr)rrrr is_parameterszSymbol.is_parametercCst|jttfkS)N)r>rkr r)rrrr is_globalszSymbol.is_globalcCst|jtkS)N)r>rkr)rrrris_declared_globalszSymbol.is_declared_globalcCst|jttfkS)N)r>rkr r)rrrris_localszSymbol.is_localcCst|jt@S)N)r>rjr)rrrr is_annotatedszSymbol.is_annotatedcCst|jtkS)N)r>rkr )rrrrrcszSymbol.is_freecCst|jt@S)N)r>rjr)rrrr is_importedszSymbol.is_importedcCst|jt@S)N)r>rjr)rrrr is_assignedszSymbol.is_assignedcCs 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. )r>rl)rrrr is_namespaces zSymbol.is_namespacecCs|jS)z.Return a list of namespaces bound to this name)rl)rrrrget_namespacesszSymbol.get_namespacescCs t|jdkrtd|jdS)zReturns the single namespace bound to this name. Raises ValueError if the name is bound to multiple namespaces. rez$name is bound to multiple namespacesr)lenrl ValueError)rrrr get_namespaceszSymbol.get_namespace)N)r*r+r,r r5r;rmrnrorprqrrrcrsrtrurvryrrrrrs  __main__reexec),__doc__rrrrrrrrr r r r r rrr__all__rrrobjectrrrrr*ossysopenargvfreadsrcpathsplitmodrGrMrKinfoprintrqrurrrrs&@L& C