o
    2h                     @   s   d Z ddlZddlZG dd dejZG dd deZG dd deZe Zdd
dZ	ed	fddZ
dddZdddZdddZdddZdddZdS )z4AST node annotation support.

Adapted from Tangent.
    Nc                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )NoValuez2Base class for different types of AST annotations.Nc                 C   s   t || |dS )N)default)getanno)selfnoder    r   `/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorflow/python/autograph/pyct/anno.pyof$   s   z
NoValue.ofc                 C   s   t || | d S N)setanno)r   r   valuer   r   r   add_to'   s   zNoValue.add_toc                 C   s
   t || S r
   )hasanno)r   r   r   r   r   exists*      
zNoValue.existsc                 C   s
   t | jS r
   )strname)r   r   r   r   __repr__-   r   zNoValue.__repr__r
   )__name__
__module____qualname____doc__r	   r   r   r   r   r   r   r   r   !   s    
r   c                   @   s(   e Zd ZdZdZdZdZdZdZdZ	dS )	BasiczhContainer for basic annotation keys.

  The enum values are used strictly for documentation purposes.
  z>Qualified name, as it appeared in the code. See qual_names.py.zBThis node should be preserved as is and not processed any further.zWhen a node is annotated with this, the remainder of the block should be indented below it. The annotation contains a tuple (new_body, name_map), where `new_body` is the new indented block and `name_map` allows renaming symbols.zaInformation about the source code that converted code originated from. See origin_information.py.zvUser directives associated with a statement or a variable. Typically, they affect the immediately-enclosing statement.zQA special annotation containing additional test code to be executed in for loops.N)
r   r   r   r   QNSKIP_PROCESSINGINDENT_BLOCK_REMAINDERORIGIN
DIRECTIVESEXTRA_LOOP_TESTr   r   r   r   r   1   s    r   c                   @   sL   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ZdZdS )StaticzrContainer for static analysis annotation keys.

  The enum values are used strictly for documentation purposes.
  z5Symbol is a parameter to the function being analyzed.z2The scope for the annotated node. See activity.py.z3The scope for the argument list of a function call.z7The scope for the test node of a conditional statement.z`The scope for the main body of a statement (True branch for if statements, main body for loops).zeThe scope for the orelse body of a statement (False branch for if statements, orelse body for loops).z=Reaching definition information. See reaching_definitions.py.zQThe value of DEFINITIONS that applied to the original code before any conversion.zWLocal function definitions that may exist when exiting the node. See reaching_fndefs.pyzDSymbols defined when entering the node. See reaching_definitions.py.z4Symbols live when exiting the node. See liveness.py.z5Symbols live when entering the node. See liveness.py.z/Static type information. See type_inference.py.z4Types of closure symbols at each detected call site.z0Static value information. See type_inference.py.N)r   r   r   r   IS_PARAMSCOPE
ARGS_SCOPE
COND_SCOPE
BODY_SCOPEORELSE_SCOPEDEFINITIONSORIG_DEFINITIONSDEFINED_FNS_INDEFINED_VARS_INLIVE_VARS_OUTLIVE_VARS_INTYPESCLOSURE_TYPESVALUEr   r   r   r   r   I   s.    r   ___pyct_annoc                 C   s"   t | |st S tt| | S r
   )hasattr	frozensetgetattrkeys)r   
field_namer   r   r   r3   u   s   
r3   c                 C   s2   |t u st| |r|t| |v rt| || S |S r
   )FAILr0   r2   )r   keyr   r4   r   r   r   r   {   s   r   c                 C   s   t | |o|t| |v S r
   )r0   r2   )r   r6   r4   r   r   r   r      s   r   c                 C   sB   t | |i }t| || |||< || jvr|  j|f7  _d S d S r
   )r2   setattr_fields)r   r6   r   r4   annotationsr   r   r   r      s   
r   c                    s@   t |  }||= |st|   t fdd| jD | _d S d S )Nc                 3   s    | ]	}| kr|V  qd S r
   r   ).0fr4   r   r   	<genexpr>   s    zdelanno.<locals>.<genexpr>)r2   delattrtupler8   )r   r6   r4   r9   r   r<   r   delanno   s   

r@   c                 C   s0   t | ||drt||t| ||d|d d S d S )Nr<   )r   r   r   )	from_nodeto_noder6   r4   r   r   r   copyanno   s   
rC   c              	   C   sD   t | D ]}|D ]}t|||rt||| t|||| q	qdS )a+  Recursively copies annotations in an AST tree.

  Args:
    node: ast.AST
    copy_map: Dict[Hashable, Hashable], maps a source anno key to a destination
        key. All annotations with the source key will be copied to identical
        annotations with the destination key.
    field_name: str
  N)gastwalkr   r   r   )r   copy_mapr4   nkr   r   r   dup   s   
rI   )r/   )r   enumrD   Enumr   r   r   objectr5   r3   r   r   r   r@   rC   rI   r   r   r   r   <module>   s   	)





	