o
    tBh                     @  s   d Z ddlm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mZmZ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%dd Zd!S )&a  Transform that inserts error checks after opcodes.

When initially building the IR, the code doesn't perform error checks
for exceptions. This module is used to insert all required error checks
afterwards. Each Op describes how it indicates an error condition (if
at all).

We need to split basic blocks on each error check since branches can
only be placed at the end of a basic block.
    )annotations)FuncIR)
ERR_ALWAYS	ERR_FALSE	ERR_MAGICERR_MAGIC_OVERLAPPING	ERR_NEVERNO_TRACEBACK_LINE_NO
BasicBlockBranchCallCComparisonOpIntegerLoadErrorValue
RegisterOpReturnValue)bool_rprimitive)err_occurred_op)CFunctionDescriptionirr   returnNonec                 C  sR   d }| j D ]}tdd |jD }|rt| } nq|r't| j || j| _ d S d S )Nc                 s  s    | ]}|  V  qd S N)	can_raise).0op r   q/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypyc/transform/exceptions.py	<genexpr>+   s    z,insert_exception_handling.<locals>.<genexpr>)blocksanyopsadd_handler_blocksplit_blocks_at_errorstraceback_name)r   error_labelblockr   r   r   r   insert_exception_handling%   s   
r(   r
   c                 C  s<   t  }| j| t| j}|j| |jt| |S r   )r
   r    appendr   ret_typer"   r   )r   r'   r   r   r   r   r#   3   s   
r#   r    list[BasicBlock]default_error_handler	func_name
str | Nonec              	   C  s  g }| D ]}|j }g |_ |}|| |jp|}d |_|D ]}|}	|j | t|tr|jtkrt }
||
 |jtkrDt	j
}d}nk|jtkrOt	j}d}n`|jtkr_t	j}d}tdt}	nP|jtkrtt|	jj|jd}t|	|tj}|j | t }|| t	|||
t	jd}|j | |}ttg |	j}	|j |	 t	j
}d}nJ d|j |jtkr|jrJ dt	|	||
||jd}||_|jtkr|d ur||jf|_|j | |
}qq|S )	NFTr   )rtype)
true_labelfalse_labelr   zunknown error kind %dzvoid op generating errors?)r0   r1   r   line)r"   r)   error_handler
isinstancer   
error_kindr   r
   r   r   IS_ERRORr   BOOLr   r   r   r   inttypec_undefinedr   EQprimitive_callr   r2   is_voidnegatedr	   traceback_entry)r    r,   r-   
new_blocksr'   r"   	cur_blockr&   r   target	new_blockvariantr>   errvaluecomp
new_block2branchr   r   r   r$   <   sj   









6r$   descr   argslist[Value]r2   r8   r   c                 C  s   t | jg | j| j| j| j|S r   )r   c_function_namereturn_typestealsis_borrowedr5   )rI   rJ   r2   r   r   r   r<      s   r<   N)r   r   r   r   )r   r   r   r
   )r    r+   r,   r
   r-   r.   r   r+   )rI   r   rJ   rK   r2   r8   r   r   )__doc__
__future__r   mypyc.ir.func_irr   mypyc.ir.opsr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   mypyc.ir.rtypesr   mypyc.primitives.exc_opsr   mypyc.primitives.registryr   r(   r#   r$   r<   r   r   r   r   <module>   s    D


	J