
    BVh                        d Z ddlZddlZddlmZ ddlmZ  G d de      Z G d d ej                  dd	g            Z	 G d
 d ej                  ddg            Z
 G d de      Z G d dej                        Zd Zd Zy)zUtilities for manipulating qualified names.

A qualified name is a uniform way to refer to simple (e.g. 'foo') and composite
(e.g. 'foo.bar') syntactic symbols.

This is *not* related to the __qualname__ attribute used by inspect, which
refers to scopes.
    N)anno)parserc                       e Zd Zy)CallerMustSetThisN)__name__
__module____qualname__     [/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/autograph/pyct/qual_names.pyr   r       s    r   r   c                       e Zd ZdZy)SymbolzRepresents a Python symbol.N)r   r   r	   __doc__r
   r   r   r   r   $   s    #r   r   namec                       e Zd ZdZd Zd Zy)Literalz$Represents a Python numeric literal.c                     t        | j                  t              rdj                  | j                        S t        | j                        S )Nz'{}')
isinstancevaluestrformatselfs    r   __str__zLiteral.__str__+   s1    $**c"]]4::&&tzz?r   c                     t        |       S Nr   r   s    r   __repr__zLiteral.__repr__0       t9r   N)r   r   r	   r   r   r   r
   r   r   r   r   (   s    ,
r   r   r   c                       e Zd ZdZddZd Zd Zd Zd Zd Z	e
d	        Ze
d
        Ze
d        Ze
d        Zd Zd Zd Zd Zd Zd Zd Zd Zy)QNzRepresents a qualified name.Nc                    ||t        dj                  ||            d| _        d| _        |Tt	        |t
              st        d|z        t	        |t              st        d|z        || _        ||f| _        d| _        y |3t	        |t
              st        d      || _        ||f| _        d| _        y t	        |t        t        f      st        dt        |      z        d|vrd	|vrd
|vsJ d | _        |f| _        y )NzPA QN can only be either an attr or a subscript, not both: attr={}, subscript={}.Fz6for attribute QNs, base must be a QN; got instead "%s"z+attr may only be a string; got instead "%s"Tz%For subscript QNs, base must be a QN.zKfor simple QNs, base must be a string or a Literal object; got instead "%s".[])
ValueErrorr   	_has_attr_has_subscriptr   r!   r   _parentqnr   type)r   baseattr	subscripts       r   __init__zQN.__init__8   s'   I1 66<fT96MO ODNDb!DtKM 	Mc"FMNNdltdgdn		b!@AAdly!dg d sGn- "&t*-. 	. _DS_DDdldgr   c                 <    t        | j                  d   t              S )Nr   )r   r*   r   r   s    r   	is_symbolzQN.is_symbol[   s    dggaj#&&r   c                 2    t        | j                        dk  S N   lenr*   r   s    r   	is_simplezQN.is_simple^   s    tww<1r   c                 2    t        | j                        dkD  S r3   r5   r   s    r   is_compositezQN.is_compositea   s    tww<!r   c                     | j                   S r   )r(   r   s    r   has_subscriptzQN.has_subscriptd   s    r   c                     | j                   S r   )r'   r   s    r   has_attrzQN.has_attrg   s    >>r   c                 T    | j                   st        d| z        | j                  d   S )Nz&Cannot get attr of non-attribute "%s".r4   )r'   r&   r*   r   s    r   r-   zQN.attrj   s(    >>?$FGG771:r   c                 h    | j                   t        d| j                  d   z        | j                   S )Nz&Cannot get parent of simple name "%s".r   )r)   r&   r*   r   s    r   parentz	QN.parentp   s/    ||?$''!*LMM<<r   c                     t               }| j                         s| j                         r@|j                  | j                         |j                  | j                  j                         |S )zReturns all the symbols (simple or composite) that own this QN.

    In other words, if this symbol was modified, the symbols in the owner set
    may also be affected.

    Examples:
      'a.b[c.d]' has two owners, 'a' and 'a.b'
    )setr=   r;   addr@   update	owner_set)r   ownerss     r   rE   zQN.owner_setv   sJ     UF}}$,,.jjmmDKK))*Mr   c                 h   t               }| j                         r'|j                  | j                  j                         |S | j                         rO|j                  | j                  j                         |j                  | j                  d   j                         |S |j                  |        |S )aN  Returns the set of simple symbols that this QN relies on.

    This would be the smallest set of symbols necessary for the QN to
    statically resolve (assuming properties and index ranges are verified
    at runtime).

    Examples:
      'a.b' has only one support symbol, 'a'
      'a[i]' has two support symbols, 'a' and 'i'
    r4   )rB   r=   rD   r@   support_setr;   r*   rC   )r   rootss     r   rH   zQN.support_set   s     EE}}ll4;;**+ L 
			ll4;;**+ll4771:))* L iioLr   c                 ^    t        | j                  | j                  | j                  fz         S r   )hashr*   r'   r(   r   s    r   __hash__zQN.__hash__   s%    4>>4+>+>??@@r   c                     t        |t              xr_ | j                  |j                  k(  xrD | j                         |j                         k(  xr! | j	                         |j	                         k(  S r   )r   r!   r*   r;   r=   r   others     r   __eq__z	QN.__eq__   s^    ub! 0dgg&9 0 E$7$7$990MMOu~~//1r   c                 0    t        |       t        |      k  S r   r   rN   s     r   __lt__z	QN.__lt__       t9s5z!!r   c                 0    t        |       t        |      kD  S r   r   rN   s     r   __gt__z	QN.__gt__   rS   r   c                    | j                   d   }| j                         rdj                  || j                   d         S | j                         r)dj	                  t        t        | j                               S t        |      S )Nr   z{}[{}]r4   r#   )r*   r;   r   r=   joinmapr   )r   roots     r   r   z
QN.__str__   sa    771:D__T4771:..}}XXc#tww'((Yr   c                     t        |       S r   r   r   s    r   r   zQN.__repr__   r   r   c                     | j                   D cg c]$  }t        |t              r|j                         n|& }}d}t	        dt        | j                         dz
        D ]"  }| j                         rd}nd}|||   |z   z  }$ ||d   z   S c c}w )zSimple symbol form. r   r4   _sub__)r*   r   r!   ssfranger6   r;   )r   nssfs
ssf_stringi	delimiters         r   r`   zQN.ssf   s    9=AAz!R(AEEGa/ADAJ1c$''lQ&' (						DGi''j( R   Bs   )Bc                 J   | j                         rOt        j                  | j                  j	                         | j
                  d   j	                         t              S | j                         rAt        j                  | j                  j	                         | j
                  d   t              S | j
                  d   }t        |t              rt        j                  |t        dd      S t        |t              r!t        j                  |j                  d      S J d       )	zAST representation.r_   )r   slicectx)r   r-   ri   r   N)ri   
annotationtype_comment)kindz?the constructor should prevent types other than str and Literal)r;   gast	Subscriptr@   astr*   r   r=   	Attributer   r   Namer   Constantr   )r   r,   s     r   ro   zQN.ast   s     ^^!!! ! }}^^!9JL L 771:D$YY
%$TK K	D'	"]]4::D11( ' (Ur   )NN)r   r   r	   r   r/   r1   r7   r9   r;   r=   propertyr-   r@   rE   rH   rL   rP   rR   rU   r   r   r`   ro   r
   r   r   r!   r!   5   s    $!F'  
  
    ,A1
""
!(r   r!   c                   "    e Zd ZdZd Zd Zd Zy)
QnResolverzdAnnotates nodes with QN information.

  Note: Not using NodeAnnos to avoid circular dependencies.
  c                     | j                  |      }t        j                  |t        j                  j                  t	        |j
                               |S r   )generic_visitr   setannoBasicr!   idr   nodes     r   
visit_NamezQnResolver.visit_Name   s7    d#DLLtzz}}bk2Kr   c           
         | j                  |      }t        j                  |j                  t        j                  j
                        rzt        j                  |t        j                  j
                  t        t        j                  |j                  t        j                  j
                        |j                               |S )N)r-   )	rw   r   hasannor   ry   r!   rx   getannor-   r{   s     r   visit_AttributezQnResolver.visit_Attribute   so    d#D||DJJ

.
ll4dll4::tzz}}=DIINPKr   c           
      >   | j                  |      }|j                  }t        |t        j                  t        j
                  f      r|S t        |t        j                        r2|j                  t        k7  rt        t        |j                              }n_t        j                  |t        j                  j                        r/t        j                  |t        j                  j                        }n|S t        j                  |j                  t        j                  j                        rpt        j                  |t        j                  j                  t        t        j                  |j                  t        j                  j                        |             |S )N)r.   )rw   rh   r   rm   TupleSlicerr   r   Ellipsisr!   r   r   r   ry   r   rx   )r   r|   sr.   s       r   visit_SubscriptzQnResolver.visit_Subscript   s    d#D

A!djj$**-. k!T]]#8(;WQWW%&i 
a	'LLDJJMM2	||DJJ

.
ll4dll4::tzz}}= )+, Kr   N)r   r   r	   r   r}   r   r   r
   r   r   ru   ru      s    

r   ru   c                 4    t               j                  |       S r   )ru   visit)r|   s    r   resolver     s    			D	!!r   c                     t        j                  |       }t        |      }t        j                  |t        j
                  j                        S r   )r   parse_expressionr   r   r   ry   r!   )qn_strr|   s     r   from_strr     s4    		 	 	($	$	dDJJMM	**r   )r   collectionsrm    tensorflow.python.autograph.pyctr   r   objectr   
namedtupler   r   r!   NodeTransformerru   r   r   r
   r   r   <module>r      s      1 3 $#[##Hvh7 $	$k$$Y	: 	b( b(J&%% &R"+r   