Ë
    òT•j*  ã                   ón  — d Z ddlZddlmZmZmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZ ddlZg d¢Zd„ Z G d„ d«      Z e«       Z G d„ d	«      Z G d
„ de«      Z G d„ de«      Z G d„ d«      Zedk(  r¶ddlZddlZ eej<                  d   «      5 ZejA                  «       Z!ddd«        ee!ejD                  jG                  ej<                  d   «      d   d«      Z$e$jK                  «       D ]9  Z&e$jO                  e&«      Z( e)e(e(jU                  «       e(jW                  «       «       Œ; yy# 1 sw Y   ŒŠxY w)z2Interface to the compiler's internal symbol tablesé    N)ÚUSEÚ
DEF_GLOBALÚDEF_NONLOCALÚ	DEF_LOCALÚ	DEF_PARAMÚ
DEF_IMPORTÚ	DEF_BOUNDÚ	DEF_ANNOTÚ	SCOPE_OFFÚ
SCOPE_MASKÚFREEÚLOCALÚGLOBAL_IMPLICITÚGLOBAL_EXPLICITÚCELL)ÚsymtableÚSymbolTableÚClassÚFunctionÚSymbolc                 óH   — t        j                  | ||«      }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)ÚcodeÚfilenameÚcompile_typeÚtops       ú/usr/lib/python3.12/symtable.pyr   r      s%   € ô ×
Ñ
˜T 8¨\Ó
:€CÜ˜3 Ó)Ð)ó    c                   ó   — e Zd Zd„ Zd„ Zd„ Zy)ÚSymbolTableFactoryc                 ó6   — t        j                  «       | _        y ©N)ÚweakrefÚWeakValueDictionaryÚ_SymbolTableFactory__memo©Úselfs    r   Ú__init__zSymbolTableFactory.__init__   s   € Ü×1Ñ1Ó3ˆ�r   c                 ó¾   — |j                   t        j                  k(  rt        ||«      S |j                   t        j                  k(  rt        ||«      S t        ||«      S r#   )Útyper   ÚTYPE_FUNCTIONr   Ú
TYPE_CLASSr   r   )r(   Útabler   s      r   ÚnewzSymbolTableFactory.new   sM   € Ø�:‰:œ×0Ñ0Ò0Ü˜E 8Ó,Ð,Ø�:‰:œ×-Ñ-Ò-Ü˜ Ó)Ð)Ü˜5 (Ó+Ð+r   c                 óŒ   — ||f}| j                   j                  |d «      }|€!| j                  ||«      x}| j                   |<   |S r#   )r&   Úgetr/   )r(   r.   r   ÚkeyÚobjs        r   Ú__call__zSymbolTableFactory.__call__    sG   € Ø�XˆoˆØ�k‰k�o‰o˜c 4Ó(ˆØˆ;Ø%)§X¡X¨e°XÓ%>Ð>ˆC�$—+‘+˜cÑ"Øˆ
r   N)Ú__name__Ú
__module__Ú__qualname__r)   r/   r4   © r   r   r!   r!      s   „ ò4ò,ór   r!   c                   ó`   — e Zd Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zy)r   c                 ó.   — || _         || _        i | _        y r#   )Ú_tableÚ	_filenameÚ_symbols)r(   Ú	raw_tabler   s      r   r)   zSymbolTable.__init__,   s   € ØˆŒØ!ˆŒØˆ�r   c                 ó,  — | j                   t        k(  rd}nd| j                   j                  z  }| j                  j                  dk(  rdj                  || j                  «      S dj                  || j                  j                  | j                  «      S )NÚ z%s r   z<{0}SymbolTable for module {1}>z<{0}SymbolTable for {1} in {2}>)Ú	__class__r   r5   r;   ÚnameÚformatr<   )r(   Úkinds     r   Ú__repr__zSymbolTable.__repr__1   s{   € Ø�>‰>œ[Ò(Ø‰Dà˜4Ÿ>™>×2Ñ2Ñ2ˆDà�;‰;×Ñ˜uÒ$Ø4×;Ñ;¸DÀ$Ç.Á.ÓQÐQà4×;Ñ;¸DØ<@¿K¹K×<LÑ<LØ<@¿N¹NóLð Lr   c                 ón  — | j                   j                  t        j                  k(  ry| j                   j                  t        j                  k(  ry| j                   j                  t        j
                  k(  ry| j                   j                  t        j                  k(  ry| j                   j                  t        j                  k(  ry| j                   j                  t        j                  k(  ry| j                   j                  t        j                  k(  ryJ d| j                   j                  › �«       ‚)	z¸Return the type of the symbol table.

        The values returned are 'class', 'module', 'function',
        'annotation', 'TypeVar bound', 'type alias', and 'type parameter'.
        ÚmoduleÚfunctionÚclassÚ
annotationzTypeVar boundz
type aliasztype parameterzunexpected type: )
r;   r+   r   ÚTYPE_MODULEr,   r-   ÚTYPE_ANNOTATIONÚTYPE_TYPE_VAR_BOUNDÚTYPE_TYPE_ALIASÚTYPE_TYPE_PARAMr'   s    r   Úget_typezSymbolTable.get_type>   sÞ   € ð �;‰;×Ñœy×4Ñ4Ò4ØØ�;‰;×Ñœy×6Ñ6Ò6ØØ�;‰;×Ñœy×3Ñ3Ò3ØØ�;‰;×Ñœy×8Ñ8Ò8ØØ�;‰;×Ñœy×<Ñ<Ò<Ø"Ø�;‰;×Ñœy×8Ñ8Ò8ØØ�;‰;×Ñœy×8Ñ8Ò8Ø#Ø<Ð)¨$¯+©+×*:Ñ*:Ð);Ð<Ó<ˆur   c                 ó.   — | j                   j                  S )z,Return an identifier for the table.
        )r;   Úidr'   s    r   Úget_idzSymbolTable.get_idT   s   € ð �{‰{�~‰~Ðr   c                 ó.   — | j                   j                  S )zµReturn 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;   rB   r'   s    r   Úget_namezSymbolTable.get_nameY   s   € ð �{‰{×ÑÐr   c                 ó.   — | j                   j                  S )zPReturn the number of the first line in the
        block for the table.
        )r;   Úlinenor'   s    r   Ú
get_linenozSymbolTable.get_linenob   s   € ð �{‰{×!Ñ!Ð!r   c                 ób   — t        | j                  j                  t        j                  k(  «      S )zJReturn *True* if the locals in the table
        are optimizable.
        )Úboolr;   r+   r   r,   r'   s    r   Úis_optimizedzSymbolTable.is_optimizedh   s$   € ô �D—K‘K×$Ñ$¬	×(?Ñ(?Ñ?Ó@Ð@r   c                 ó@   — t        | j                  j                  «      S )zAReturn *True* if the block is a nested class
        or function.)rZ   r;   Únestedr'   s    r   Ú	is_nestedzSymbolTable.is_nestedn   s   € ô �D—K‘K×&Ñ&Ó'Ð'r   c                 ó@   — t        | j                  j                  «      S )z:Return *True* if the block has nested namespaces.
        )rZ   r;   Úchildrenr'   s    r   Úhas_childrenzSymbolTable.has_childrens   s   € ô �D—K‘K×(Ñ(Ó)Ð)r   c                 óJ   — | j                   j                  j                  «       S )zKReturn a view object containing the names of symbols in the table.
        )r;   ÚsymbolsÚkeysr'   s    r   Úget_identifierszSymbolTable.get_identifiersx   s   € ð �{‰{×"Ñ"×'Ñ'Ó)Ð)r   c                 ó  — | j                   j                  |«      }|€a| j                  j                  |   }| j	                  |«      }| j                  j
                  dk(  }t        ||||¬«      x}| j                   |<   |S )zLLookup a *name* in the table.

        Returns a *Symbol* instance.
        r   ©Úmodule_scope)r=   r1   r;   rc   Ú_SymbolTable__check_childrenrB   r   )r(   rB   ÚsymÚflagsÚ
namespacesrh   s         r   ÚlookupzSymbolTable.lookup}   s   € ð
 �m‰m×Ñ Ó%ˆØˆ;Ø—K‘K×'Ñ'¨Ñ-ˆEØ×.Ñ.¨tÓ4ˆJØ ŸK™K×,Ñ,°Ñ5ˆLÜ(.¨t°U¸JØ<Hô)Jð JˆC�$—-‘- Ñ%àˆ
r   c                 óf   — | j                  «       D �cg c]  }| j                  |«      ‘Œ c}S c c}w )zLReturn a list of *Symbol* instances for
        names in the table.
        )re   rm   )r(   Úidents     r   Úget_symbolszSymbolTable.get_symbols‹   s*   € ð 15×0DÑ0DÓ0FÖG u�—‘˜EÕ"ÒGÐGùÒGs   “.c                 óš   — | j                   j                  D �cg c]'  }|j                  |k(  rt        || j                  «      ‘Œ) c}S c c}w r#   )r;   r`   rB   r   r<   )r(   rB   Ústs      r   Ú__check_childrenzSymbolTable.__check_children‘   sB   € àŸ+™+×.Ñ.ö$ØØ—7‘7˜d’?ô    D§N¡NÕ3ò $ð 	$ùò $s   ™,Ac                 ó|   — | j                   j                  D �cg c]  }t        || j                  «      ‘Œ c}S c c}w )z3Return a list of the nested symbol tables.
        )r;   r`   r   r<   )r(   rr   s     r   Úget_childrenzSymbolTable.get_children–   s9   € ð Ÿ+™+×.Ñ.ö0Øô    D§N¡NÕ3ò 0ð 	0ùò 0s   ™9N)r5   r6   r7   r)   rE   rP   rS   rU   rX   r[   r^   ra   re   rm   rp   ri   ru   r8   r   r   r   r   *   sK   „ òò
Lò=ò,ò
 ò"òAò(ò
*ò
*ò
òHò$ó
0r   r   c                   óD   — e Zd ZdZdZdZdZdZd„ Zd„ Z	d„ Z
d„ Zd„ Zd„ Zy)r   Nc                 óL   ‡ ‡— t        ˆ ˆfd„‰ j                  «       D «       «      S )Nc              3   ó`   •K  — | ]%  } ‰‰j                   j                  |   «      r|–— Œ' y ­wr#   )r;   rc   )Ú.0ro   r(   Ú	test_funcs     €€r   ú	<genexpr>z-Function.__idents_matching.<locals>.<genexpr>§   s/   øè ø€ ò ?˜uÙ! $§+¡+×"5Ñ"5°eÑ"<Ô=ô ñ ?ùs   ƒ+.)Útuplere   )r(   rz   s   ``r   Ú__idents_matchingzFunction.__idents_matching¦   s%   ù€ Üô ?¨×(<Ñ(<Ó(>ô ?ó ?ð 	?r   c                 ó`   — | j                   €| j                  d„ «      | _         | j                   S )z6Return a tuple of parameters to the function.
        c                 ó   — | t         z  S r#   )r   ©Úxs    r   ú<lambda>z)Function.get_parameters.<locals>.<lambda>®   s
   € ¸AÄ	¹M€ r   )Ú_Function__paramsÚ_Function__idents_matchingr'   s    r   Úget_parameterszFunction.get_parametersª   s+   € ð �=‰=Ð Ø ×2Ñ2Ñ3IÓJˆDŒMØ�}‰}Ðr   c                 ó‚   ‡— | j                   €'t        t        fŠˆfd„}| j                  |«      | _         | j                   S )z2Return a tuple of locals in the function.
        c                 ó(   •— | t         z	  t        z  ‰v S r#   ©r   r   )r�   Úlocss    €r   r‚   z%Function.get_locals.<locals>.<lambda>¶   s   ø€ ˜q¤I™~´Ñ;ÀÐD€ r   )Ú_Function__localsr   r   r„   )r(   Útestr‰   s     @r   Ú
get_localszFunction.get_locals±   s9   ø€ ð �=‰=Ð Üœ4�=ˆDÛDˆDØ ×2Ñ2°4Ó8ˆDŒMØ�}‰}Ðr   c                 ó‚   ‡— | j                   €'t        t        fŠˆfd„}| j                  |«      | _         | j                   S )z3Return a tuple of globals in the function.
        c                 ó(   •— | t         z	  t        z  ‰v S r#   rˆ   )r�   Úglobs    €r   r‚   z&Function.get_globals.<locals>.<lambda>¿   s   ø€ ˜a¤9™n´
Ñ:¸tÐC€ r   )Ú_Function__globalsr   r   r„   )r(   r‹   r�   s     @r   Úget_globalszFunction.get_globalsº   s:   ø€ ð �>‰>Ð!Ü#¤_Ð5ˆDÛCˆDØ!×3Ñ3°DÓ9ˆDŒNØ�~‰~Ðr   c                 ó`   — | j                   €| j                  d„ «      | _         | j                   S )z5Return a tuple of nonlocals in the function.
        c                 ó   — | t         z  S r#   )r   r€   s    r   r‚   z(Function.get_nonlocals.<locals>.<lambda>Ç   s   € ¸qÄ<Ñ?O€ r   )Ú_Function__nonlocalsr„   r'   s    r   Úget_nonlocalszFunction.get_nonlocalsÃ   s0   € ð ×ÑÐ#Ø#×5Ñ5Ñ6OÓPˆDÔØ×ÑÐr   c                 ód   — | j                   €d„ }| j                  |«      | _         | j                   S )z:Return a tuple of free variables in the function.
        c                 ó0   — | t         z	  t        z  t        k(  S r#   )r   r   r   r€   s    r   r‚   z$Function.get_frees.<locals>.<lambda>Î   s   €  ¤i¡´:Ñ =Ä$ÑF€ r   )Ú_Function__freesr„   )r(   Úis_frees     r   Ú	get_freeszFunction.get_freesÊ   s/   € ð �<‰<ÐÙFˆGØ×1Ñ1°'Ó:ˆDŒLØ�|‰|Ðr   )r5   r6   r7   rƒ   rŠ   r˜   r�   r”   r„   r…   rŒ   r‘   r•   rš   r8   r   r   r   r   �   s;   „ ð €HØ€HØ€GØ€IØ€Kò?òòòò ór   r   c                   ó   — e Zd ZdZd„ Zy)r   Nc                 óª   — | j                   €<i }| j                  j                  D ]  }d||j                  <   Œ t	        |«      | _         | j                   S )z9Return a tuple of methods declared in the class.
        é   )Ú_Class__methodsr;   r`   rB   r|   )r(   Údrr   s      r   Úget_methodszClass.get_methods×   sN   € ð �>‰>Ð!ØˆAØ—k‘k×*Ñ*ò �Ø��"—'‘'’
ðä" 1›XˆDŒNØ�~‰~Ðr   )r5   r6   r7   rž   r    r8   r   r   r   r   Ó   s   „ à€Iór   r   c                   ót   — e Zd Zdddœd„Zd„ Zd„ Zd„ Zd„ Zd	„ Zd
„ Z	d„ Z
d„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)r   NFrg   c                ón   — || _         || _        |t        z	  t        z  | _        |xs d| _        || _        y )Nr8   )Ú_Symbol__nameÚ_Symbol__flagsr   r   Ú_Symbol__scopeÚ_Symbol__namespacesÚ_Symbol__module_scope)r(   rB   rk   rl   rh   s        r   r)   zSymbol.__init__ä   s6   € ØˆŒØˆŒØ¤Ñ*¬jÑ8ˆŒØ&Ò,¨"ˆÔØ*ˆÕr   c                 ó8   — dj                  | j                  «      S )Nz<symbol {0!r}>)rC   r£   r'   s    r   rE   zSymbol.__repr__ë   s   € Ø×&Ñ& t§{¡{Ó3Ð3r   c                 ó   — | j                   S )z#Return a name of a symbol.
        )r£   r'   s    r   rU   zSymbol.get_nameî   s   € ð �{‰{Ðr   c                 óN   — t        | j                  t        j                  z  «      S )zBReturn *True* if the symbol is used in
        its block.
        )rZ   r¤   r   r   r'   s    r   Úis_referencedzSymbol.is_referencedó   s   € ô �D—L‘L¤9§=¡=Ñ0Ó1Ð1r   c                 ó:   — t        | j                  t        z  «      S )z4Return *True* if the symbol is a parameter.
        )rZ   r¤   r   r'   s    r   Úis_parameterzSymbol.is_parameterù   ó   € ô �D—L‘L¤9Ñ,Ó-Ð-r   c                 óŠ   — t        | j                  t        t        fv xs! | j                  xr | j
                  t        z  «      S )z/Return *True* if the symbol is global.
        )rZ   r¥   r   r   r§   r¤   r	   r'   s    r   Ú	is_globalzSymbol.is_globalþ   s@   € ô �D—L‘L¤_´oÐ$FÐFò JØ×+Ñ+ÒH°·±¼yÑ0HóKð 	Kr   c                 ó:   — t        | j                  t        z  «      S )z(Return *True* if the symbol is nonlocal.)rZ   r¤   r   r'   s    r   Úis_nonlocalzSymbol.is_nonlocal  s   € ä�D—L‘L¤<Ñ/Ó0Ð0r   c                 ó:   — t        | j                  t        k(  «      S )zOReturn *True* if the symbol is declared global
        with a global statement.)rZ   r¥   r   r'   s    r   Úis_declared_globalzSymbol.is_declared_global  s   € ô �D—L‘L¤OÑ3Ó4Ð4r   c                 óŠ   — t        | j                  t        t        fv xs! | j                  xr | j
                  t        z  «      S )z.Return *True* if the symbol is local.
        )rZ   r¥   r   r   r§   r¤   r	   r'   s    r   Úis_localzSymbol.is_local  s?   € ô �D—L‘L¤U¬D MÐ1ò JØ×+Ñ+ÒH°·±¼yÑ0HóKð 	Kr   c                 ó:   — t        | j                  t        z  «      S )z2Return *True* if the symbol is annotated.
        )rZ   r¤   r
   r'   s    r   Úis_annotatedzSymbol.is_annotated  r®   r   c                 ó:   — t        | j                  t        k(  «      S )zIReturn *True* if a referenced symbol is
        not assigned to.
        )rZ   r¥   r   r'   s    r   r™   zSymbol.is_free  s   € ô �D—L‘L¤DÑ(Ó)Ð)r   c                 ó:   — t        | j                  t        z  «      S )zQReturn *True* if the symbol is created from
        an import statement.
        )rZ   r¤   r   r'   s    r   Úis_importedzSymbol.is_imported  s   € ô �D—L‘L¤:Ñ-Ó.Ð.r   c                 ó:   — t        | j                  t        z  «      S )z)Return *True* if a symbol is assigned to.)rZ   r¤   r   r'   s    r   Úis_assignedzSymbol.is_assigned$  s   € ä�D—L‘L¤9Ñ,Ó-Ð-r   c                 ó,   — t        | j                  «      S )a‹  Returns *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.
        )rZ   r¦   r'   s    r   Úis_namespacezSymbol.is_namespace(  s   € ô �D×%Ñ%Ó&Ð&r   c                 ó   — | j                   S )z.Return a list of namespaces bound to this name)r¦   r'   s    r   Úget_namespaceszSymbol.get_namespaces5  s   € à× Ñ Ð r   c                 ó¬   — t        | j                  «      dk(  rt        d«      ‚t        | j                  «      dkD  rt        d«      ‚| j                  d   S )z˜Return the single namespace bound to this name.

        Raises ValueError if the name is bound to multiple namespaces
        or no namespace.
        r   z#name is not bound to any namespacesr�   z$name is bound to multiple namespaces)Úlenr¦   Ú
ValueErrorr'   s    r   Úget_namespacezSymbol.get_namespace9  sS   € ô ˆt× Ñ Ó! QÒ&ÜÐBÓCÐCÜ�×"Ñ"Ó# aÒ'ÜÐCÓDÐDà×$Ñ$ QÑ'Ð'r   r#   )r5   r6   r7   r)   rE   rU   r«   r­   r°   r²   r´   r¶   r¸   r™   r»   r½   r¿   rÁ   rÅ   r8   r   r   r   r   â   s[   „ ð+ÀUô +ò4òò
2ò.ò
Kò1ò5ò
Kò.ò
*ò/ò.ò'ò!ó(r   r   Ú__main__r�   Úexec),Ú__doc__r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r$   Ú__all__r   r!   r   r   r   r   r   r5   ÚosÚsysÚopenÚargvÚfÚreadÚsrcÚpathÚsplitÚmodre   ro   rm   ÚinfoÚprintr¶   r¿   r8   r   r   ú<module>rÖ      s'  ðÙ 8ã ÷4÷ 4÷ 4÷ 4ñ 4ó â
D€ò*÷ñ ñ$ %Ó&€÷p0ñ p0ôf3ˆ{ô 3ôlˆKô ÷b(ñ b(ðH ˆzÒßÙ	ˆc�h‰h�q‰kÓ	ð ˜aØ�f‰f‹hˆ÷á
�3˜Ÿ™Ÿ™ c§h¡h¨q¡kÓ2°1Ñ5°vÓ
>€CØ×$Ñ$Ó&ò :ˆØ�z‰z˜%Ó ˆÙˆd�D—M‘M“O T×%6Ñ%6Ó%8Õ9ñ:ð ÷ð ús   ÂD+Ä+D4