o
    ÕtBh{  ã                   @  sš   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 ddlmZ ddlmZ ddd„Zddd„Zddd„ZdS )z½IRBuilder 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_tagged)Ú	IRBuilder)Úconstant_fold_exprÚselfr   Úer   Útruer   ÚfalseÚreturnÚNonec                 C  sà   t |tƒrC|jdv rC|jdkr)tƒ }t| |j||ƒ |  |¡ t| |j||ƒ d S tƒ }t| |j||ƒ |  |¡ t| |j||ƒ d S t |tƒrW|jdkrWt| |j	||ƒ d S t
| |||ƒ}|rbd 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Úreg© r)   úp/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypyc/irbuild/ast_helpers.pyr      s"   



r   Úboolc                 C  s¼   t |tƒrt|jƒdkrdS |  |jd ¡}|  |jd ¡}t|ƒr&t|ƒs(dS |jd }|dvr3dS |jd }|jd }t| |ƒ}	| j||	d}
| j|dd}| j	 
|
|||||j¡ dS )aM  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:
        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   Ú	operatorsÚis_borrow_friendly_exprr$   ÚbuilderÚcompare_tagged_conditionÚline)r   r   r   r   ÚltypeÚrtyper   Ú	left_exprÚ
right_exprÚborrow_leftr   r!   r)   r)   r*   r#   8   s    



r#   r"   c                 C  sz   t |ttttfƒrdS t |ttttfƒrt	| |ƒdurdS t |tƒr/t |j
tƒr/|jtkr/dS t |tƒr;|  |¡r;dS dS )zŽCan 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"   r)   r)   r*   r5   X   s   ÿ
r5   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   Úmypyc.irbuild.builderr   Úmypyc.irbuild.constant_foldr   r   r#   r5   r)   r)   r)   r*   Ú<module>   s    8

 