Yf @sdZddlZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZddlZdddddgZd dZGd d d ZeZGd ddeZGd ddeZGdddeZGdddeZedkrddlZddlZeejdZejZ WdQRXee ej!j"ejdddZ#x?e#j$D]1Z%e#j&e%Z'e(e'e'j)e'j*qWdS)z2Interface to the compiler's internal symbol tablesN) USE DEF_GLOBAL DEF_LOCAL DEF_PARAM DEF_IMPORT DEF_BOUND SCOPE_OFF SCOPE_MASKFREELOCALGLOBAL_IMPLICITGLOBAL_EXPLICITCELLsymtable SymbolTableClassFunctionSymbolcCs"tj|||}t||S)N) _symtabler_newSymbolTable)codefilenameZ compile_typetopr-/opt/alt/python35/lib64/python3.5/symtable.pyr sc@s4eZdZddZddZddZdS)SymbolTableFactorycCstj|_dS)N)weakrefWeakValueDictionary_SymbolTableFactory__memo)selfrrr__init__szSymbolTableFactory.__init__cCsK|jtjkrt||S|jtjkr>t||St||S)N)typer TYPE_FUNCTIONr TYPE_CLASSrr)rtablerrrrnews   zSymbolTableFactory.newcCsN||f}|jj|d}|dkrJ|j||}|j|<|S)N)rgetr%)rr$rkeyobjrrr__call__s   zSymbolTableFactory.__call__N)__name__ __module__ __qualname__r r%r)rrrrrs   rc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdS) rcCs||_||_i|_dS)N)_table _filename_symbols)rZ raw_tablerrrrr 's  zSymbolTable.__init__cCsm|jtkrd}nd|jj}|jjdkrMdj||jSdj||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|jjtjkr2dS|jjtjkrKdS|jjdksxtdj|jjdS) NmoduleZfunctionclasszunexpected type: {0})r8r9r:)r-r!rZ TYPE_MODULEr"r#AssertionErrorr4)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_optimizedcCst|jjS)N)rBr-nested)rrrr is_nestedOszSymbolTable.is_nestedcCst|jjS)N)rBr-children)rrrr has_childrenRszSymbolTable.has_childrencCsdS)z7Return true if the scope uses exec. Deprecated method.Fr)rrrrhas_execUszSymbolTable.has_execcCs|jjjS)N)r-symbolskeys)rrrrget_identifiersYszSymbolTable.get_identifierscCs^|jj|}|dkrZ|jj|}|j|}t|||}|j|<|S)N)r/r&r-rI_SymbolTable__check_childrenr)rr3Zsymflags namespacesrrrlookup\s  zSymbolTable.lookupcsfddjDS)Ncsg|]}j|qSr)rO).0ident)rrr es z+SymbolTable.get_symbols..)rK)rr)rr get_symbolsdszSymbolTable.get_symbolscs fddjjDS)Ncs1g|]'}|jkrt|jqSr)r3rr.)rPst)r3rrrrRhs z0SymbolTable.__check_children..)r-rF)rr3r)r3rrZ__check_childrengszSymbolTable.__check_childrencsfddjjDS)Ncs"g|]}t|jqSr)rr.)rPrT)rrrrRms z,SymbolTable.get_children..)r-rF)rr)rr get_childrenlszSymbolTable.get_childrenN)r*r+r,r r5r<r>r?rArCrErGrHrKrOrSrLrUrrrrr%s             c@sdeZdZdZdZdZdZddZddZddZ dd Z d d Z dS) rNcs&tfddjDS)Ncs,g|]"}jj|r|qSr)r-rI)rPrQ)r test_funcrrrRzs z.Function.__idents_matching..)tuplerK)rrVr)rrVrZ__idents_matchingyszFunction.__idents_matchingcCs.|jdkr'|jdd|_|jS)NcSs|t@S)N)r)xrrrsz)Function.get_parameters..)_Function__params_Function__idents_matching)rrrrget_parameters}szFunction.get_parameterscsF|jdkr?ttffdd}|j||_|jS)Ncs|t?t@kS)N)rr )rX)locsrrrYsz%Function.get_locals..)_Function__localsr rr[)rtestr)r]r get_localss  zFunction.get_localscsF|jdkr?ttffdd}|j||_|jS)Ncs|t?t@kS)N)rr )rX)globrrrYsz&Function.get_globals..)_Function__globalsr r r[)rr_r)rar get_globalss  zFunction.get_globalscCs4|jdkr-dd}|j||_|jS)NcSs|t?t@tkS)N)rr r )rXrrrrYsz$Function.get_frees..)_Function__freesr[)ris_freerrr get_freess zFunction.get_frees) r*r+r,rZr^rdrbr[r\r`rcrfrrrrrqs     c@s"eZdZdZddZdS)rNcCsO|jdkrHi}x!|jjD]}d||j)r4rj)rrrrr5szSymbol.__repr__cCs|jS)N)rj)rrrrr?szSymbol.get_namecCst|jtj@S)N)rBrkrr)rrrr is_referencedszSymbol.is_referencedcCst|jt@S)N)rBrkr)rrrr is_parameterszSymbol.is_parametercCst|jttfkS)N)rBrlr r )rrrr is_globalszSymbol.is_globalcCst|jtkS)N)rBrlr )rrrris_declared_globalszSymbol.is_declared_globalcCst|jt@S)N)rBrkr)rrrris_localszSymbol.is_localcCst|jtkS)N)rBrlr )rrrrreszSymbol.is_freecCst|jt@S)N)rBrkr)rrrr is_importedszSymbol.is_importedcCst|jt@S)N)rBrkr)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. )rBrm)rrrr is_namespaces zSymbol.is_namespacecCs|jS)z.Return a list of namespaces bound to this name)rm)rrrrget_namespacesszSymbol.get_namespacescCs,t|jdkr!td|jdS)zReturns the single namespace bound to this name. Raises ValueError if the name is bound to multiple namespaces. r8z$name is bound to multiple namespacesr)lenrm ValueError)rrrr get_namespaces zSymbol.get_namespace)r*r+r,r r5r?rnrorprqrrrersrtrurvryrrrrrs            __main__r8exec)+__doc__rrrrrrrrr r r r r rr__all__rrrobjectrrrrr*ossysopenargvfreadsrcpathsplitmodrKrQrOinfoprintrrrurrrrs& X   L& @ )