Qf0ndZddlZddlmZmZmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZddlZgdZdZGddZeZGdd ZGd d eZGd d eZGddZedk(rddlZddlZeej<d5ZejAZ!dddee!ejDjGej<dddZ$e$jKD]9Z&e$jOe&Z(e)e(e(jUe(jW;yy#1swYxYw)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 SymbolTableClassFunctionSymbolcHtj|||}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 //opt/alt/python312/lib64/python3.12/symtable.pyrr s%   T8\ :C 3 ))ceZdZdZdZdZy)SymbolTableFactoryc6tj|_yN)weakrefWeakValueDictionary_SymbolTableFactory__memoselfs r__init__zSymbolTableFactory.__init__s113 rc|jtjk(r t||S|jtjk(r t ||St ||Sr#)typer TYPE_FUNCTIONr TYPE_CLASSrr)r(tablers rnewzSymbolTableFactory.newsM ::00 0E8, , ::-- -) )5(++rc||f}|jj|d}|!|j||x}|j|<|Sr#)r&getr/)r(r.rkeyobjs r__call__zSymbolTableFactory.__call__ sGXokkooc4( ;%)XXeX%> >C$++c" rN)__name__ __module__ __qualname__r)r/r4rrr!r!s4,rr!c`eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZy)rc.||_||_i|_yr#)_table _filename_symbols)r( raw_tablers rr)zSymbolTable.__init__,s ! rc,|jtk(rd}nd|jjz}|jjdk(rdj ||j Sdj ||jj|j S)Nz%s rz<{0}SymbolTable for module {1}>z<{0}SymbolTable for {1} in {2}>) __class__rr5r;nameformatr<)r(kinds r__repr__zSymbolTable.__repr__1s{ >>[ (D4>>222D ;;  u $4;;D$..Q Q4;;D<@KKs ;;  y44 4 ;;  y66 6 ;;  y33 3 ;;  y88 8 ;;  y<< <" ;;  y88 8 ;;  y88 8#<)$++*:*:);<++..0.B DNN3.0 00s9N)r5r6r7r)rErPrSrUrXr[r^rarermrprirur8rrrr*sK L=,  " A ( * * H $ 0rrcDeZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ y)rNcLtfdjDS)Nc3`K|]%}jj|r|'ywr#)r;rc).0ror( test_funcs r z-Function.__idents_matching..s0?(>u!$++"5"5e"<=(>s+.)tuplere)r(rzs``r__idents_matchingzFunction.__idents_matchings%?(<(<(>?? ?rc`|j|jd|_|jS)z6Return a tuple of parameters to the function. c|tzSr#)rxs rz)Function.get_parameters..sA Mr)_Function__params_Function__idents_matchingr's rget_parameterszFunction.get_parameterss+ ==  223IJDM}}rc|j'ttffd}|j||_|jS)z2Return a tuple of locals in the function. c(|tz tzvSr#r r )rlocss rrz%Function.get_locals..sqI~;Dr)_Function__localsrrr)r(testrs @r get_localszFunction.get_localss9 == 4=DDD 2248DM}}rc|j'ttffd}|j||_|jS)z3Return a tuple of globals in the function. c(|tz tzvSr#r)rglobs rrz&Function.get_globals..sa9n :tCr)_Function__globalsrrr)r(rrs @r get_globalszFunction.get_globalss: >> !#_5DCD!33D9DN~~rc`|j|jd|_|jS)z5Return a tuple of nonlocals in the function. c|tzSr#)rrs rrz(Function.get_nonlocals..s q.si: =$Fr)_Function__freesr)r(is_frees r get_freeszFunction.get_freess/ << FG11':DL||r)r5r6r7rrrrrrrrrrrr8rrrrs;HHGIK? rrceZdZdZdZy)rNcLj i}fd}jjD]}||js|jxt j k(r/|jdk(rd|jvrSd||j<ct jk(sv|j}|jD]K}|j|k(s|jt j k(s1|dk7sd|jvsJd||<t|_jS)z9Return a tuple of methods declared in the class. c~jjj|d}|tz tzt k(S)Nr)r;rcr1r r r)rorkr(s ris_local_symbolz*Class.get_methods..is_local_symbols4 ++//q9)+z9eCCrgenexprz.0) _Class__methodsr;r`rBr+rr,varnamesrOr|)r(drrr scope_namecs` r get_methodszClass.get_methodss >> !A Dkk**"277+''4Y44 "ww)3 8K ()*AbggJ&66*,J%'[[#$66Z#7AFFiF]F]<],6+BdRSR\R\F\$\+\45AjM$)&1+4#1XDN~~r)r5r6r7rrr8rrrrs I%rrcteZdZddddZdZdZdZdZd Zd Z d Z d Z d Z dZ dZdZdZdZdZy)rNFrgcn||_||_|tz tz|_|xsd|_||_y)Nr8) _Symbol__name_Symbol__flagsr r _Symbol__scope_Symbol__namespaces_Symbol__module_scope)r(rBrkrlrhs rr)zSymbol.__init__s6  *j8 &,"*rc8dj|jS)Nz)rCrr's rrEzSymbol.__repr__s&&t{{33rc|jS)z#Return a name of a symbol. )rr's rrUzSymbol.get_name s{{rcNt|jtjzS)zBReturn *True* if the symbol is used in its block. )rZrrrr's r is_referencedzSymbol.is_referencedsDLL9==011rc:t|jtzS)z4Return *True* if the symbol is a parameter. )rZrrr's r is_parameterzSymbol.is_parameterDLL9,--rct|jttfvxs!|jxr|j t zS)z/Return *True* if the symbol is global. )rZrrrrrr r's r is_globalzSymbol.is_globals@DLL_o$FFJ++H y0HK Krc:t|jtzS)z(Return *True* if the symbol is nonlocal.)rZrrr's r is_nonlocalzSymbol.is_nonlocal!sDLL</00rc:t|jtk(S)zOReturn *True* if the symbol is declared global with a global statement.)rZrrr's ris_declared_globalzSymbol.is_declared_global%sDLLO344rct|jttfvxs!|jxr|j t zS)z.Return *True* if the symbol is local. )rZrrrrrr r's ris_localzSymbol.is_local*s?DLLUDM1J++H y0HK Krc:t|jtzS)z2Return *True* if the symbol is annotated. )rZrr r's r is_annotatedzSymbol.is_annotated0rrc:t|jtk(S)zIReturn *True* if a referenced symbol is not assigned to. )rZrr r's rrzSymbol.is_free5sDLLD())rc:t|jtzS)zQReturn *True* if the symbol is created from an import statement. )rZrrr's r is_importedzSymbol.is_imported;sDLL:-..rc:t|jtzS)z)Return *True* if a symbol is assigned to.)rZrrr's r is_assignedzSymbol.is_assignedAsDLL9,--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. )rZrr's r is_namespacezSymbol.is_namespaceEsD%%&&rc|jS)z.Return a list of namespaces bound to this name)rr's rget_namespaceszSymbol.get_namespacesRs   rct|jdk(r tdt|jdkDr td|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 namespacesrz$name is bound to multiple namespaces)lenr ValueErrorr's r get_namespacezSymbol.get_namespaceVsS t  !Q &BC C "" #a 'CD D$$Q' 'rr#)r5r6r7r)rErUrrrrrrrrrrrrrr8rrrrs[+U+4 2 . K 15 K . * / . '! (rr__main__rexec),__doc__rrrrrrrr r r r r rrrrr$__all__rr!rrrrrr5ossysopenargvfreadsrcpathsplitmodrerorminfoprintrrr8rrrs844444 D*$%&p0p0f3{3l)K)Xb(b(H z chhqk affh  3 chhqk215v >C$$&zz%  dDMMOT%6%6%89'   s D++D4