
    X-Ph                        d Z ddlm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 ddlmZ ddlmZmZ ddlmZ ddlmZ ddZddZddZdS )zIRBuilder AST transform helpers shared between expressions and statements.

Shared code that is tightly coupled to mypy ASTs can be put here instead of
making mypyc.irbuild.builder larger.
    )annotations)LDEF	BytesExprComparisonExpr
Expression	FloatExprIntExpr
MemberExprNameExprOpExprStrExpr	UnaryExprVar)
BasicBlock)is_fixed_width_rtype	is_tagged)	IRBuilder)constant_fold_exprselfr   er   truer   falsereturnNonec                   t          |t                    r|j        dv r|j        dk    rSt                      }t	          | |j        ||           |                     |           t	          | |j        ||           d S t                      }t	          | |j        ||           |                     |           t	          | |j        ||           d S t          |t                    r$|j        dk    rt	          | |j	        ||           d S t          | |||          }|rd S |                     |          }|                     |||           d S )N)andorr   not)
isinstancer   opr   process_conditionalleftactivate_blockrightr   expr$maybe_process_conditional_comparisonacceptadd_bool_branch)r   r   r   r   newresregs          Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypyc/irbuild/ast_helpers.pyr!   r!      sR    !V /!6!645==,,Cafc5999$$$agtU;;;;; ,,CafdC888$$$agtU;;;;;	Ay	!	! /ademmD!&%6666624D%HH 	Fkk!nnS$.....    boolc                V   t          |t                    rt          |j                  dk    rdS |                     |j        d                   }|                     |j        d                   }t          |          st          |          rt          |          st          |          sdS |j        d         }|dvrdS |j        d         }|j        d         }t          | |          }	| 	                    ||	          }
| 	                    |d          }t          |          st          |          rt          |          s| 
                    |
||j                  }
n+t          |          s| 
                    |||j                  }|                     |
|||j                  }| j                                         |                     |||           nM| j                            |
|||j                  }|                                  |                     |||           dS )ak  Transform simple tagged integer comparisons in a conditional context.

    Return True if the operation is supported (and was transformed). Otherwise,
    do nothing and return False.

    Args:
        self: IR form Builder
        e: Arbitrary expression
        true: Branch target if comparison is true
        false: Branch target if comparison is false
       Fr      )z==z!=<z<=>z>=)
can_borrowT)r   r   lenoperands	node_typer   r   	operatorsis_borrow_friendly_exprr'   coerceline	binary_opbuilderflush_keep_alivesr(   )r   r   r   r   ltypertyper    	left_expr
right_exprborrow_leftr"   r$   r+   s                r,   r&   r&   8   s    a(( C
OOq,@,@uNN1:a=))ENN1:a=))E	5		1%88u!5e!<!< u	
QB	333u
1IAJ)$
;;K;;y[;99DKK
tK44EE"" /&:5&A&A /#E** 	6;;tUAF33DD%e,, 	6KKuaf55EnnT5"af55&&(((S$.... l$$T5"af==   S$...4r-   r%   c                   t          |t          t          t          t          f          rdS t          |t
          t          t          t          f          rt          | |          dS t          |t                    r,t          |j
        t                    r|j        t          k    rdS t          |t                    r|                     |          rdS dS )zCan the result of the expression borrowed temporarily?

    Borrowing means keeping a reference without incrementing the reference count.
    TNF)r   r	   r   r   r   r   r   r   r
   r   noder   kindr   is_native_attr_ref)r   r%   s     r,   r9   r9   g   s    
 $)Wi@AA t4)VXzBCCtT**6 t$!! di%% 	$)t*;*;4$
## (?(?(E(E t5r-   N)
r   r   r   r   r   r   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r.   )r   r   r%   r   r   r.   )__doc__
__future__r   
mypy.nodesr   r   r   r   r   r	   r
   r   r   r   r   r   mypyc.ir.opsr   mypyc.ir.rtypesr   r   mypyc.irbuild.builderr   mypyc.irbuild.constant_foldr   r!   r&   r9    r-   r,   <module>rP      sF    # " " " " "                            $ # # # # # ; ; ; ; ; ; ; ; + + + + + + : : : : : :/ / / /6, , , ,^     r-   