
    d(                        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    rddlZddlZ eej        d                   5 Ze                                 Z!ddd           n# 1 swxY w Y    ee!ej"        #                    ej        d                   d         d          Z$e$%                                D ]JZ&e$'                    e&          Z( e)e(e(*                                e(+                                           IdS dS )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                 N    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         /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/symtable.pyr   r      s(     
T8\
:
:C3)))    c                        e Zd Zd Zd Zd ZdS )SymbolTableFactoryc                 6    t          j                    | _        d S N)weakrefWeakValueDictionary_SymbolTableFactory__memoselfs    r   __init__zSymbolTableFactory.__init__   s    13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   sR    :000E8,,,:---)))5(+++r   c                     ||f}| j                             |d           }| |                     ||          x}| j         |<   |S r#   )r&   getr/   )r(   r.   r   keyobjs        r   __call__zSymbolTableFactory.__call__    sI    Xokooc4((;%)XXeX%>%>>C$+c"
r   N)__name__
__module____qualname__r)   r/   r4    r   r   r!   r!      sA        4 4 4, , ,    r   r!   c                   b    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dS )r   c                 0    || _         || _        i | _        d S 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                  S d                    || 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   sw    >[((DD4>22D;u$$4;;D$.QQQ4;;D<@K<L<@NL L Lr   c                    | j         j        t          j        k    rdS | j         j        t          j        k    rdS | j         j        t          j        k    rdS | j         j        dv s'J d                    | j         j                              dS )zxReturn the type of the symbol table.

        The values returned are 'class', 'module' and
        'function'.
        modulefunctionclass)         zunexpected type: {0}N)r;   r+   r   TYPE_MODULEr,   r-   rC   r'   s    r   get_typezSymbolTable.get_type>   s     ;y4448;y666:;y3337{9,,,%,,T[-=>> -,,,,r   c                     | j         j        S )z,Return an identifier for the table.
        )r;   idr'   s    r   get_idzSymbolTable.get_idM   s     {~r   c                     | j         j        S )zReturn 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_nameR   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_lineno[   s     {!!r   c                 P    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_optimizeda   s     DK$	(??@@@r   c                 4    t          | j        j                  S )zAReturn *True* if the block is a nested class
        or function.)rX   r;   nestedr'   s    r   	is_nestedzSymbolTable.is_nestedg   s     DK&'''r   c                 4    t          | j        j                  S )z:Return *True* if the block has nested namespaces.
        )rX   r;   childrenr'   s    r   has_childrenzSymbolTable.has_childrenl   s     DK()))r   c                 >    | j         j                                        S )zKReturn a view object containing the names of symbols in the table.
        )r;   symbolskeysr'   s    r   get_identifierszSymbolTable.get_identifiersq   s     {"'')))r   c                     | j                             |          }|T| j        j        |         }|                     |          }| j        j        dk    }t          ||||          x}| j         |<   |S )zLLookup a *name* in the table.

        Returns a *Symbol* instance.
        Nr   module_scope)r=   r1   r;   ra   _SymbolTable__check_childrenrB   r   )r(   rB   symflags
namespacesrf   s         r   lookupzSymbolTable.lookupv   s    
 m%%;K'-E..t44J K,5L(.tUJ<H)J )J )J JC$-%
r   c                 D      fd                                  D             S )zLReturn a list of *Symbol* instances for
        names in the table.
        c                 :    g | ]}                     |          S r8   )rk   ).0identr(   s     r   
<listcomp>z+SymbolTable.get_symbols.<locals>.<listcomp>   s%    GGGuE""GGGr   )rc   r'   s   `r   get_symbolszSymbolTable.get_symbols   s,     HGGG0D0D0F0FGGGGr   c                 8      fd j         j        D             S )Nc                 P    g | ]"}|j         k    t          |j                  #S r8   )rB   r   r<   )rn   strB   r(   s     r   rp   z0SymbolTable.__check_children.<locals>.<listcomp>   s8     $ $ $7d??  DN33"??r   r;   r^   )r(   rB   s   ``r   __check_childrenzSymbolTable.__check_children   s9    $ $ $ $ $+.$ $ $ 	$r   c                 4      fd j         j        D             S )z3Return a list of the nested symbol tables.
        c                 :    g | ]}t          |j                  S r8   )r   r<   )rn   rt   r(   s     r   rp   z,SymbolTable.get_children.<locals>.<listcomp>   s5     0 0 0  DN33 0 0 0r   ru   r'   s   `r   get_childrenzSymbolTable.get_children   s3    0 0 0 0+.0 0 0 	0r   N)r5   r6   r7   r)   rE   rN   rQ   rS   rV   rY   r\   r_   rc   rk   rq   rg   ry   r8   r   r   r   r   *   s          
L L L? ? ?  
     " " "A A A( ( (
* * *
* * *
  H H H$ $ $
0 0 0 0 0r   r   c                   F    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S )r   Nc                 b     t           fd                                 D                       S )Nc              3   R   K   | ]!} j         j        |                   |V  "d S r#   )r;   ra   )rn   ro   r(   	test_funcs     r   	<genexpr>z-Function.__idents_matching.<locals>.<genexpr>   sO       ? ?u!	$+"5e"<==?U ? ? ? ? ? ?r   )tuplerc   )r(   r}   s   ``r   __idents_matchingzFunction.__idents_matching   sL     ? ? ? ? ?(<(<(>(> ? ? ? ? ? 	?r   c                 T    | j         |                     d           | _         | j         S )z6Return a tuple of parameters to the function.
        Nc                     | 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23I3IJJDM}r   c                 z    | j         -t          t          ffd}|                     |          | _         | j         S )z2Return a tuple of locals in the function.
        Nc                 ,    | t           z	  t          z  v S r#   r   r   )r   locss    r   r   z%Function.get_locals.<locals>.<lambda>   s    qI~;D r   )_Function__localsr   r   r   )r(   testr   s     @r   
get_localszFunction.get_locals   sA     = 4=DDDDDD 22488DM}r   c                 z    | j         -t          t          ffd}|                     |          | _         | j         S )z3Return a tuple of globals in the function.
        Nc                 ,    | t           z	  t          z  v S r#   r   )r   globs    r   r   z&Function.get_globals.<locals>.<lambda>   s    a9n
:tC r   )_Function__globalsr   r   r   )r(   r   r   s     @r   get_globalszFunction.get_globals   sB     >!#_5DCCCCD!33D99DN~r   c                 T    | j         |                     d           | _         | j         S )z5Return a tuple of nonlocals in the function.
        Nc                     | 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56O6OPPDr   c                 X    | j         d }|                     |          | _         | j         S )z:Return a tuple of free variables in the function.
        Nc                 8    | 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   s1     <FFG11'::DL|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dS )r   Nc                 |    | j         /i }| j        j        D ]}d||j        <   t	          |          | _         | j         S )z9Return a tuple of methods declared in the class.
        NrJ   )_Class__methodsr;   r^   rB   r   )r(   drt   s      r   get_methodszClass.get_methods   sG     >!Ak*  "'

"1XXDN~r   )r5   r6   r7   r   r   r8   r   r   r   r      s(        I    r   r   c                   v    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dS )r   NFre   c                p    || _         || _        |t          z	  t          z  | _        |pd| _        || _        d S )Nr8   )_Symbol__name_Symbol__flagsr   r   _Symbol__scope_Symbol__namespaces_Symbol__module_scope)r(   rB   ri   rj   rf   s        r   r)   zSymbol.__init__   s<    *j8&,"*r   c                 6    d                     | j                  S )Nz<symbol {0!r}>)rC   r   r'   s    r   rE   zSymbol.__repr__   s    &&t{333r   c                     | j         S )z#Return a name of a symbol.
        )r   r'   s    r   rS   zSymbol.get_name   s     {r   c                 D    t          | j        t          j        z            S )zBReturn *True* if the symbol is used in
        its block.
        )rX   r   r   r   r'   s    r   is_referencedzSymbol.is_referenced   s     DL9=0111r   c                 :    t          | j        t          z            S )z4Return *True* if the symbol is a parameter.
        )rX   r   r   r'   s    r   is_parameterzSymbol.is_parameter        DL9,---r   c                 r    t          | j        t          t          fv p| j        o| j        t          z            S )z/Return *True* if the symbol is global.
        )rX   r   r   r   r   r   r	   r'   s    r   	is_globalzSymbol.is_global   s?     DL_o$FF J+Hy0HK K 	Kr   c                 :    t          | j        t          z            S )z(Return *True* if the symbol is nonlocal.)rX   r   r   r'   s    r   is_nonlocalzSymbol.is_nonlocal   s    DL</000r   c                 <    t          | j        t          k              S )zOReturn *True* if the symbol is declared global
        with a global statement.)rX   r   r   r'   s    r   is_declared_globalzSymbol.is_declared_global  s     DLO3444r   c                 r    t          | j        t          t          fv p| j        o| j        t          z            S )z.Return *True* if the symbol is local.
        )rX   r   r   r   r   r   r	   r'   s    r   is_localzSymbol.is_local  s>     DLUDM1 J+Hy0HK K 	Kr   c                 :    t          | j        t          z            S )z2Return *True* if the symbol is annotated.
        )rX   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.
        )rX   r   r   r'   s    r   r   zSymbol.is_free  s     DLD()))r   c                 :    t          | j        t          z            S )zQReturn *True* if the symbol is created from
        an import statement.
        )rX   r   r   r'   s    r   is_importedzSymbol.is_imported  s     DL:-...r   c                 :    t          | j        t          z            S )z)Return *True* if a symbol is assigned to.)rX   r   r   r'   s    r   is_assignedzSymbol.is_assigned  s    DL9,---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.
        )rX   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_namespaces.  s      r   c                     t          | j                  dk    rt          d          t          | j                  dk    rt          d          | j        d         S )zReturn 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 namespacesrJ   z$name is bound to multiple namespaces)lenr   
ValueErrorr'   s    r   get_namespacezSymbol.get_namespace2  s\     t !!Q&&BCCC"##a''CDDD$Q''r   r#   )r5   r6   r7   r)   rE   rS   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   r   r   r   r      s       +U + + + + +4 4 4  
2 2 2. . .
K K K1 1 15 5 5
K K K. . .
* * */ / /. . .' ' '! ! !( ( ( ( (r   r   __main__rJ   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modrc   ro   rk   infoprintr   r   r8   r   r   <module>r      s   8 8    4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 
D
D
D* * *       $ %$&&i0 i0 i0 i0 i0 i0 i0 i0X3 3 3 3 3{ 3 3 3l    K   b( b( b( b( b( b( b( b(H zNNNNNNN	chqk		 affhh              
(3chqk2215v
>
>C$$&& : :zz%  dDMMOOT%6%6%8%89999 
: :s   %CC
C
