o
    ?e                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 G dd	 d	eZG d
d deZG dd dejZdd ZdS )zHCanonicalizes continue statements by de-sugaring into a control boolean.    )	converter)anno)
qual_names)	templates)activity)NodeAnnoc                   @   s   e Zd Zdd Zdd ZdS )	_Continuec                 C   s   d| _ d | _d S NF)usedcontrol_var_nameself r   {/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/autograph/converters/continue_statements.py__init__   s   
z_Continue.__init__c                 C   s   d | j| jS )Nz<_Continue(used: {}, var: {})>)formatr
   r   r   r   r   r   __repr__   s   z_Continue.__repr__N)__name__
__module____qualname__r   r   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdd ZdS )_Blocka  Tracks information about lexical blocks as they are visited in the AST.

  Mainly, this object tracks the creation of block guards that replace
  `continue` statements (e.g. `if not continue_:`).

  Attributes:
    create_guard_current: bool, whether to create a guard for the current
      statement.
    create_guard_next: bool, whether to create a guard for the next
      statement.
    is_loop_type: bool, whether this block is the body of a loop.
  c                 C   s   d| _ d| _d| _d S r	   )is_loop_typecreate_guard_currentcreate_guard_nextr   r   r   r   r   2   s   
z_Block.__init__N)r   r   r   __doc__r   r   r   r   r   r   $   s    r   c                   @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )#ContinueCanonicalizationTransformerz?Canonicalizes continue statements into additional conditionals.c                 C   sL   d| j t _t| j t jD ]
}d|_|jr qqd}tj	|| j t j
dS )NTz
      var_name = True
    var_name)stater   r
   reversedr   stackr   r   r   replacer   )r   nodeblocktemplater   r   r   visit_Continue;   s   z2ContinueCanonicalizationTransformer.visit_Continuec                 C   s^   | j t jr+| j t }|j}|j|_d|_|r+d}tj|| j t j|d\}||j	fS |d fS )NFz>
          if not var_name:
            original_node
        )r   Zoriginal_node)
r   r   r
   r   r   r   r   r!   r   body)r   r"   r#   Zshould_wrap_currentr$   Zcondr   r   r   _postprocess_statementK   s   


z:ContinueCanonicalizationTransformer._postprocess_statementc                 C   s   | j t   | j t   d| j t _t|tj}| j	j
d|j}|| j t _| j|| jd}| j t jrEd}tj||d}|| }| j t   | j t   |S )NTZ	continue_Zafter_visitz 
        var_name = False
      r   )r   r   enterr   r   r   Zgetannor   Z
BODY_SCOPEctxnamerZ
new_symbolZ
referencedr   visit_blockr'   r
   r   r!   exit)r   r"   nodesscopeZcontinue_varr$   Zcontrol_var_initr   r   r   _visit_loop_body^   s   z4ContinueCanonicalizationTransformer._visit_loop_bodyc                 C   s0   | j t   | j|| jd}| j t   |S )Nr(   )r   r   r)   r,   r'   r-   )r   r.   r   r   r   _visit_non_loop_bodys   s   z8ContinueCanonicalizationTransformer._visit_non_loop_bodyc                 C   s0   |  |j|_| ||j|_| |j|_|S N)visittestr0   r&   r1   orelser   r"   r   r   r   visit_Whiley   s   z/ContinueCanonicalizationTransformer.visit_Whilec                 C   s>   |  |j|_|  |j|_| ||j|_| |j|_|S r2   )generic_visittargetiterr0   r&   r1   r5   r6   r   r   r   	visit_For   s
   z-ContinueCanonicalizationTransformer.visit_Forc                 C   s    |  |j|_|  |j|_|S r2   )r1   r&   r5   r6   r   r   r   visit_If      z,ContinueCanonicalizationTransformer.visit_Ifc                 C   s    |  |j|_| |j|_|S r2   )r,   itemsr1   r&   r6   r   r   r   
visit_With   r=   z.ContinueCanonicalizationTransformer.visit_Withc                 C   s<   |  |j|_|  |j|_|  |j|_| |j|_|S r2   )r1   r&   r5   	finalbodyr,   handlersr6   r   r   r   	visit_Try   s
   z-ContinueCanonicalizationTransformer.visit_Tryc                 C   s   |  |j|_|S r2   )r1   r&   r6   r   r   r   visit_ExceptHandler   s   z7ContinueCanonicalizationTransformer.visit_ExceptHandlerN)r   r   r   r   r%   r'   r0   r1   r7   r;   r<   r?   rB   rC   r   r   r   r   r   8   s    r   c                 C   s*   t | } t| |d } t|| } | S r2   )r   resolver   r   r3   )r"   r*   r   r   r   	transform   s   
rE   N)r   Z tensorflow.python.autograph.corer   Z tensorflow.python.autograph.pyctr   r   r   Z0tensorflow.python.autograph.pyct.static_analysisr   Z6tensorflow.python.autograph.pyct.static_analysis.annosr   objectr   r   ZBaser   rE   r   r   r   r   <module>   s   g