U
    hâËdV  ã                   @   s
  d dl Z d dlmZmZmZ d dlmZmZmZm	Z	m
Z
 dd„ Zdd„ Zdd	„ Zee jejejƒeƒ ee jejejƒeƒ ee jejejƒeƒ eejƒd
d„ ƒZe
ejƒdd„ ƒZeejejƒdd„ ƒZeejejƒdd„ ƒZeejejƒeejejƒdd„ ƒƒZdS )é    N)ÚtypesÚtypingÚcgutils)Ú
lower_castÚlower_builtinÚlower_getattr_genericÚimpl_ret_untrackedÚlower_setattr_genericc                 C   s   t jS ©N)r   Útrue_bit©ÚcontextÚbuilderÚsigÚargs© r   úL/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/core/optional.pyÚalways_return_true_impl
   s    r   c                 C   s   t jS r
   )r   Ú	false_bitr   r   r   r   Úalways_return_false_impl   s    r   c                 C   sj   |j \}}|\}}|tjkr0|| }}|| }}|}|}	|  |||	¡}
| t ||
j¡¡}t| ||j	|ƒS )z/
    Check if an Optional value is invalid
    )
r   r   ÚnoneÚmake_helperÚnot_r   Úas_bool_bitÚvalidr   Úreturn_type)r   r   r   r   ZltyZrtyZlvalÚrvalZopt_typeZopt_valÚoptÚresr   r   r   Úoptional_is_none   s    



r   c                 C   s2   |j }|  ||||¡}|  ||¡}|| ||||ƒS )z?
    Optional.__getattr__ => redirect to the wrapped type.
    )ÚtypeÚcastZget_getattr)r   r   ÚtypÚvalueÚattrZ
inner_typeÚvalÚimpr   r   r   Úoptional_getattr.   s    r'   c                 C   sR   |j \}}|\}}|j}	|  ||||	¡}t |j|	|¡}
|  ||
¡}||||fƒS )z?
    Optional.__setattr__ => redirect to the wrapped type.
    )r   r    r!   r   Ú	signaturer   Zget_setattr)r   r   r   r   r$   ZbasetyZvaltyÚtargetr%   Ztarget_typeZnewsigr&   r   r   r   Úoptional_setattr9   s    
r*   c           
   
   C   s¤   | j |||d�}t ||j¡}|   ||¡}| |¡�b\}}	|�& tj|_|  ||j|j|j¡|_W 5 Q R X |	� tj	|_t 
|jj¡|_W 5 Q R X W 5 Q R X | ¡ S )a«  
    The handling of optional->optional cast must be special cased for
    correct propagation of None value.  Given type T and U. casting of
    T? to U? (? denotes optional) should always succeed.   If the from-value
    is None, the None value the casted value (U?) should be None; otherwise,
    the from-value is casted to U. This is different from casting T? to U,
    which requires the from-value must not be None.
    ©r#   )r   r   r   r   Zif_elser   r!   Údatar    r   Zget_null_valueZ	_getvalue)
r   r   ÚfromtyÚtotyr%   ÚoptvalÚvalidbitZ	outoptvalZis_validZis_not_validr   r   r   Úoptional_to_optionalH   s     

 ÿÿr1   c                 C   s>   |t jkr|  ||j¡S |  ||||j¡}|  ||j|¡S d S r
   )r   r   Zmake_optional_noner    r!   Zmake_optional_value)r   r   r-   r.   r%   r   r   r   Úany_to_optionalg   s    
r2   c              	   C   sp   | j |||d�}t ||j¡}|j| |¡dd��$ d|jf }| j |t	|f¡ W 5 Q R X |  
||j|j|¡S )Nr+   F)Zlikelyzexpected %s, got None)r   r   r   r   Zif_thenr   r    Z	call_convZreturn_user_excÚ	TypeErrorr!   r,   )r   r   r-   r.   r%   r/   r0   Úmsgr   r   r   Úoptional_to_anyp   s    r5   )ÚoperatorZ
numba.corer   r   r   Znumba.core.imputilsr   r   r   r   r	   r   r   r   Úis_r   ÚOptionalr'   r*   r1   ÚAnyr2   ÚBooleanr5   r   r   r   r   Ú<module>   s&   




