U
    ,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   7/tmp/pip-unpacked-wheel-eu7e0c37/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&   




