o
    j\0                     @   s   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mZ G dd dZG dd	 d	eZ	G d
d deZ
G dd deZG dd dZG dd dejeZeZG dd dejeZG dd dejZG dd deZdS )   )Nodes)	ExprNodes)Node)AtomicExprNode)
c_ptr_type
c_int_typec                   @   s&   e Zd ZdZdZdddZdd ZdS )
TempHandleNFc                 C   s$   || _ |d u r|j| _d S || _d S N)typeis_pyobjectneeds_cleanup)selfr
   r    r   Z/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/Cython/Compiler/UtilNodes.py__init__   s   
zTempHandle.__init__c                 C   s   t || | jdS )N)handler
   )TempRefNoder
   )r   posr   r   r   ref      zTempHandle.refr	   )__name__
__module____qualname__tempneeds_xdecrefr   r   r   r   r   r   r      s
    
r   c                   @   s>   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdddZdS )r   c                 C      | j | jj ks	J | S r	   r
   r   r   envr   r   r   analyse_types"      zTempRefNode.analyse_typesc                 C   r   r	   r   r   r   r   r   analyse_target_types&   r    z TempRefNode.analyse_target_typesc                 C      d S r	   r   r   r   r   r   analyse_target_declaration*      z&TempRefNode.analyse_target_declarationc                 C   s   | j j}|d u r
d}|S )Nz<error>)r   r   )r   resultr   r   r   calculate_result_code-   s   z!TempRefNode.calculate_result_codec                 C   r"   r	   r   r   coder   r   r   generate_result_code2   r$   z TempRefNode.generate_result_codeFc                 C   sj   | j jr|| ||  |   |d|  |r| n||  f  || |	| d S N%s = %s;)
r
   r   make_owned_referenceZput_xdecrefr%   ctypeputln	result_asgenerate_post_assignment_code
free_tempsr   rhsr(   Zoverloaded_assignmentr   r   r   generate_assignment_code5   s   

z$TempRefNode.generate_assignment_codeNF)	r   r   r   r   r!   r#   r&   r)   r4   r   r   r   r   r      s    r   c                   @   s>   e Zd ZdZdgZdd Zdd Zdd Zd	d
 Zdd Z	dS )TempsBlockNodea_  
    Creates a block which allocates temporary variables.
    This is used by transforms to output constructs that need
    to make use of a temporary variable. Simply pass the types
    of the needed temporaries to the constructor.

    The variables can be referred to using a TempRefNode
    (which can be constructed by calling get_ref_node).
    bodyc                 C   sz   | j D ]}|jj|j|jd|_q| j| | j D ] }|jr3|jr+|	|j|j n|
|j|j |j|j qd S )NZ
manage_ref)Ztemps	funcstateallocate_tempr
   r   r   r7   generate_execution_coder   Zput_xdecref_clearput_decref_clearrelease_temp)r   r(   r   r   r   r   r;   T   s   


z&TempsBlockNode.generate_execution_codec                 C      | j | d S r	   r7   analyse_declarationsr   r   r   r   r@   a   r   z#TempsBlockNode.analyse_declarationsc                 C      | j || _ | S r	   r7   analyse_expressionsr   r   r   r   rC   d      z"TempsBlockNode.analyse_expressionsc                 C      | j || d S r	   r7   generate_function_definitionsr   r   r(   r   r   r   rG   h      z,TempsBlockNode.generate_function_definitionsc                 C   r>   r	   )r7   annotater'   r   r   r   rJ   k   r   zTempsBlockNode.annotateN)
r   r   r   __doc__child_attrsr;   r@   rC   rG   rJ   r   r   r   r   r6   B   s    r6   c                   @   s   e Zd Zg ZdZd(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d Zdd Zdd Zdd Zd)d d!Zd"d# Zd$d% Zd&d' ZdS )*ResultRefNodeFNTc                 C   sh   || _ d | _|| _|d ur|j| _t|dd | _|d ur|| _|d ur&|| _|r+d| _| jd us2J d S )Nr
   T)
expressionr   may_hold_nonegetattrr
   is_temp)r   rN   r   r
   rO   rQ   r   r   r   r   v   s   zResultRefNode.__init__c                 C      | S r	   r   r   r   r   r   
clone_node   s   zResultRefNode.clone_nodec                 C   s   | j r	| j |S dS )Nr   )rN   type_dependenciesr   r   r   r   rU      s   zResultRefNode.type_dependenciesc                 C   s$   || _ t|dd }|r|| _d S d S )Nr
   )rN   rP   r
   )r   rN   r
   r   r   r   update_expression   s
   
zResultRefNode.update_expressionc                 C   r"   r	   r   r   r   r   r   r#      r$   z(ResultRefNode.analyse_target_declarationc                 C   s.   | j d ur| j js| j || _ | j j| _| S r	   )rN   r
   r   r   r   r   r   r      s
   

zResultRefNode.analyse_typesc                 C   sB   | j d ur| j S | jd ur| jj d ur| jj S | j|S J d)NFz"cannot infer type of ResultRefNode)r
   rN   
infer_typer   r   r   r   rW      s   

zResultRefNode.infer_typec                 C   s   | j jsdS | jS )NF)r
   r   rO   rS   r   r   r   may_be_none   s   zResultRefNode.may_be_nonec                 C   s*   | j d ur
| j  S | jd ur| jjS dS NT)rN   rX   r
   r   rS   r   r   r   _DISABLED_may_be_none   s
   


z#ResultRefNode._DISABLED_may_be_nonec                 C   s   dS rY   r   rS   r   r   r   	is_simple   r$   zResultRefNode.is_simplec                 C   s>   z| j W S  ty   | jd ur| j | _ Y | j S Y | j S w r	   )result_codeAttributeErrorrN   r%   rS   r   r   r   r%      s   
zResultRefNode.resultc                 C   r"   r	   r   r'   r   r   r   generate_evaluation_code   r$   z&ResultRefNode.generate_evaluation_codec                 C   r"   r	   r   r'   r   r   r   r)      r$   z"ResultRefNode.generate_result_codec                 C   r"   r	   r   r'   r   r   r   generate_disposal_code   r$   z$ResultRefNode.generate_disposal_codec                 C   sp   | j jr|| | js||  |   |d|  |r"| n||  f  |	| |
| d S r*   )r
   r   r,   lhs_of_first_assignmentZ
put_decrefr%   r-   r.   r/   r0   r1   r2   r   r   r   r4      s   

z&ResultRefNode.generate_assignment_codec                 C   r"   r	   r   r   r   r   r   allocate_temps   r$   zResultRefNode.allocate_tempsc                 C   r"   r	   r   r   r   r   r   r=      r$   zResultRefNode.release_tempc                 C   r"   r	   r   r'   r   r   r   r1      r$   zResultRefNode.free_temps)NNNTFr5   )r   r   r   subexprsr`   r   rT   rU   rV   r#   r   rW   rX   rZ   r[   r%   r^   r)   r_   r4   ra   r=   r1   r   r   r   r   rM   o   s*    
		
rM   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )LetNodeMixinc                 C   s   || _ |j| _d S r	   )	lazy_temprN   temp_expression)r   rd   r   r   r   set_temp_expr   s   zLetNodeMixin.set_temp_exprc                 C   s   | j | | j j| _| jjrt| jj| _| j  | _| jr&| j 	 | _
n4| jjr1| j | n| j | |jj| jdd| _
|d| j
| j 	 f  | j | | j | | j
| j_d S )NTr8   r+   )re   r^   r
   	temp_typeZis_arrayr   Z	base_typeZresult_in_temp_result_in_tempr%   r   Zis_memoryviewsliceZmake_owned_memoryviewslicer,   r9   r:   r.   r_   r1   rd   r\   r'   r   r   r   setup_temp_expr   s"   
zLetNodeMixin.setup_temp_exprc                 C   sL   | j r| j| | j| d S | jjr|| j| j |j	| j d S r	   )
rh   re   r_   r1   rg   Zneeds_refcountingr<   r   r9   r=   r'   r   r   r   teardown_temp_expr   s   zLetNodeMixin.teardown_temp_exprN)r   r   r   rf   ri   rj   r   r   r   r   rc      s    rc   c                   @   sT   e Zd Zddg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 )EvalWithTempExprNodere   subexpressionc                 C   s&   |  | |j| _|| _| jj| _d S r	   )rf   r   rl   r
   )r   rd   rl   r   r   r   r   	  s   
zEvalWithTempExprNode.__init__c                 C   s   | j |S r	   )rl   rW   r   r   r   r   rW     s   zEvalWithTempExprNode.infer_typec                 C   
   | j  S r	   )rl   rX   rS   r   r   r   rX        
z EvalWithTempExprNode.may_be_nonec                 C   rm   r	   )rl   r%   rS   r   r   r   r%     rn   zEvalWithTempExprNode.resultc                 C   s8   | j || _ | j| j  | j|| _| jj| _| S r	   )re   r   rd   rV   rl   r
   r   r   r   r   r     s
   
z"EvalWithTempExprNode.analyse_typesc                 C   r>   r	   )rl   r1   r'   r   r   r   free_subexpr_temps   r   z'EvalWithTempExprNode.free_subexpr_tempsc                 C   r>   r	   )rl   r_   r'   r   r   r   generate_subexpr_disposal_code#  r   z3EvalWithTempExprNode.generate_subexpr_disposal_codec                 C   $   |  | | j| | | d S r	   )ri   rl   r^   rj   r'   r   r   r   r^   &     
z-EvalWithTempExprNode.generate_evaluation_codeN)r   r   r   rb   r   rW   rX   r%   r   ro   rp   r^   r   r   r   r   rk     s    rk   c                   @   s<   e Zd ZddgZdd Zdd Zdd Zd	d
 Zdd ZdS )LetNodere   r7   c                 C   s   |  | |j| _|| _d S r	   )rf   r   r7   )r   rd   r7   r   r   r   r   ;  s   

zLetNode.__init__c                 C   s   | j | | j| d S r	   )re   r@   r7   r   r   r   r   r@   @     zLetNode.analyse_declarationsc                 C   s    | j || _ | j|| _| S r	   )re   rC   r7   r   r   r   r   rC   D  s   zLetNode.analyse_expressionsc                 C   rq   r	   )ri   r7   r;   rj   r'   r   r   r   r;   I  rr   zLetNode.generate_execution_codec                 C   s    | j || | j|| d S r	   )re   rG   r7   rH   r   r   r   rG   N  s   z%LetNode.generate_function_definitionsN)	r   r   r   rL   r   r@   rC   r;   rG   r   r   r   r   rs   /  s    
rs   c                   @   sF   e Zd Zg ZdgZdd Zdd Zdd Zdd	 Zd
d Z	dd Z
dS )TempResultFromStatNoder7   c                 C   s&   || _ |j| _|| _|j| _d| _d S )Nr   )
result_refr   r7   r
   rQ   )r   rv   r7   r   r   r   r   \  s
   
zTempResultFromStatNode.__init__c                 C   r>   r	   r?   r   r   r   r   r@   c  r   z+TempResultFromStatNode.analyse_declarationsc                 C   rA   r	   rB   r   r   r   r   r   f  rD   z$TempResultFromStatNode.analyse_typesc                 C   rm   r	   )rv   rX   rS   r   r   r   rX   j  rn   z"TempResultFromStatNode.may_be_nonec                 C   s   |   | j_| j| d S r	   )r%   rv   r\   r7   r;   r'   r   r   r   r)   m  rt   z+TempResultFromStatNode.generate_result_codec                 C   rE   r	   rF   rH   r   r   r   rG   q  rI   z4TempResultFromStatNode.generate_function_definitionsN)r   r   r   rb   rL   r   r@   r   rX   r)   rG   r   r   r   r   ru   S  s    ru   c                   @   s,   e Zd ZdZeZdd Zdd Zdd ZdS )	HasNoGilNodez\
    Simple node that evaluates to
    * 0 if gil
    * 1 if nogil
    * 2 if maybe gil
    c                 C   rR   r	   r   r   r   r   r   r   ~  r$   zHasNoGilNode.analyse_typesc                 C   r"   r	   r   r'   r   r   r   r)     r$   z!HasNoGilNode.generate_result_codec                 C   s   t t| jS r	   )strintZin_nogil_contextrS   r   r   r   r&     s   z"HasNoGilNode.calculate_result_codeN)	r   r   r   rK   r   r
   r   r)   r&   r   r   r   r   rw   u  s    rw   N) r   r   r   r   Z
PyrexTypesr   r   r   r   r6   rM   rc   ZExprNoderk   Z
LetRefNodeZStatNoders   ru   rw   r   r   r   r   <module>   s   $-q#)$"