3 \m @sNdZddlZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZddlZdddddgZd dZGd d d ZeZGd ddeZGd ddeZGdddeZGdddeZedkrJddlZddlZeejdZej Z!WdQRXee!ej"j#ejdddZ$x0e$j%D]$Z&e$j'e&Z(e)e(e(j*e(j+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 SymbolTableClassFunctionSymbolcCstj|||}t||S)N) _symtabler_newSymbolTable)codefilenameZ compile_typetopr /usr/lib64/python3.6/symtable.pyr sc@s$eZdZddZddZddZdS)SymbolTableFactorycCstj|_dS)N)weakrefWeakValueDictionary_SymbolTableFactory__memo)selfrrr__init__szSymbolTableFactory.__init__cCs6|jtjkrt||S|jtjkr,t||St||S)N)typer TYPE_FUNCTIONr TYPE_CLASSrr)r tablerrrrnews     zSymbolTableFactory.newcCs8||f}|jj|d}|dkr4|j||}|j|<|S)N)rgetr&)r r%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)r Z raw_tablerrrrr!'szSymbolTable.__init__cCsN|jtkrd}n d|jj}|jjdkr6dj||jSdj||jj|jSdS)Nz%s globalz<{0}SymbolTable for module {1}>z<{0}SymbolTable for {1} in {2}>) __class__rr+r.nameformatr/)r Zkindrrr__repr__,s   zSymbolTable.__repr__cCsX|jjtjkrdS|jjtjkr$dS|jjtjkr6dS|jjdksTtdj|jjdS) NmoduleZfunctionclasszunexpected type: {0})r9r:r;)r.r"rZ TYPE_MODULEr#r$AssertionErrorr5)r rrrget_type9szSymbolTable.get_typecCs|jjS)N)r.id)r rrrget_idCszSymbolTable.get_idcCs|jjS)N)r.r4)r rrrget_nameFszSymbolTable.get_namecCs|jjS)N)r.lineno)r rrr get_linenoIszSymbolTable.get_linenocCst|jjtjkS)N)boolr.r"rr#)r rrr is_optimizedLszSymbolTable.is_optimizedcCs t|jjS)N)rCr.nested)r rrr is_nestedOszSymbolTable.is_nestedcCs t|jjS)N)rCr.children)r rrr has_childrenRszSymbolTable.has_childrencCsdS)z7Return true if the scope uses exec. Deprecated method.Fr)r rrrhas_execUszSymbolTable.has_execcCs |jjjS)N)r.symbolskeys)r rrrget_identifiersYszSymbolTable.get_identifierscCsD|jj|}|dkr@|jj|}|j|}t|||}|j|<|S)N)r0r'r.rJ_SymbolTable__check_childrenr)r r4Zsymflags namespacesrrrlookup\s    zSymbolTable.lookupcsfddjDS)Ncsg|]}j|qSr)rP).0ident)r rr esz+SymbolTable.get_symbols..)rL)r r)r r get_symbolsdszSymbolTable.get_symbolscsfddjjDS)Ncs"g|]}|jkrt|jqSr)r4rr/)rQst)r4r rrrShsz0SymbolTable.__check_children..)r.rG)r r4r)r4r rZ__check_childrengs zSymbolTable.__check_childrencsfddjjDS)Ncsg|]}t|jqSr)rr/)rQrU)r rrrSmsz,SymbolTable.get_children..)r.rG)r r)r r get_childrenls zSymbolTable.get_childrenN)r+r,r-r!r6r=r?r@rBrDrFrHrIrLrPrTrMrVrrrrr%s  c@sDeZdZdZdZdZdZddZddZddZ dd Z d d Z dS) rNcstfddjDS)Ncs g|]}jj|r|qSr)r.rJ)rQrR)r test_funcrrrSzsz.Function.__idents_matching..)tuplerL)r rWr)r rWrZ__idents_matchingyszFunction.__idents_matchingcCs |jdkr|jdd|_|jS)NcSs|t@S)N)r)xrrrsz)Function.get_parameters..)_Function__params_Function__idents_matching)r rrrget_parameters}s zFunction.get_parameterscs0|jdkr*ttffdd}|j||_|jS)Ncs|t?t@kS)N)r r )rY)locsrrrZsz%Function.get_locals..)_Function__localsr rr\)r testr)r^r get_localss    zFunction.get_localscs0|jdkr*ttffdd}|j||_|jS)Ncs|t?t@kS)N)r r )rY)globrrrZsz&Function.get_globals..)_Function__globalsr rr\)r r`r)rbr get_globalss    zFunction.get_globalscCs$|jdkrdd}|j||_|jS)NcSs|t?t@tkS)N)r r r )rYrrrrZsz$Function.get_frees..)_Function__freesr\)r is_freerrr get_freess  zFunction.get_frees) r+r,r-r[r_rercr\r]rardrgrrrrrqsc@seZdZdZddZdS)rNcCs:|jdkr4i}x|jjD]}d||j<qWt||_|jS)Nr9)_Class__methodsr.rGr4rX)r drUrrr get_methodss   zClass.get_methods)r+r,r-rhrjrrrrrsc@seZdZd ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZdS)!rNcCs(||_||_|t?t@|_|p f|_dS)N) _Symbol__name_Symbol__flagsr r _Symbol__scope_Symbol__namespaces)r r4rNrOrrrr!szSymbol.__init__cCs dj|jS)Nz)r5rk)r rrrr6szSymbol.__repr__cCs|jS)N)rk)r rrrr@szSymbol.get_namecCst|jtj@S)N)rCrlrr)r rrr is_referencedszSymbol.is_referencedcCst|jt@S)N)rCrlr)r rrr is_parameterszSymbol.is_parametercCst|jttfkS)N)rCrmr r)r rrr is_globalszSymbol.is_globalcCst|jtkS)N)rCrmr)r rrris_declared_globalszSymbol.is_declared_globalcCst|jt@S)N)rCrlr)r rrris_localszSymbol.is_localcCst|jt@S)N)rCrlr)r rrr is_annotatedszSymbol.is_annotatedcCst|jtkS)N)rCrmr )r rrrrfszSymbol.is_freecCst|jt@S)N)rCrlr)r rrr is_importedszSymbol.is_importedcCst|jt@S)N)rCrlr)r rrr 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. )rCrn)r rrr is_namespaces zSymbol.is_namespacecCs|jS)z.Return a list of namespaces bound to this name)rn)r rrrget_namespacesszSymbol.get_namespacescCs t|jdkrtd|jdS)zReturns the single namespace bound to this name. Raises ValueError if the name is bound to multiple namespaces. r9z$name is bound to multiple namespacesr)lenrn ValueError)r rrr get_namespaceszSymbol.get_namespace)N)r+r,r-r!r6r@rorprqrrrsrtrfrurvrwrxr{rrrrrs  __main__r9exec),__doc__rrrrrrrrr r r r r rrr__all__rrrobjectrrrrr+ossysopenargvfreadsrcpathsplitmodrLrRrPinfoprintrsrwrrrrs&@L& C