B
     \^                 @   s  d dl mZmZmZ 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 )    )print_functionabsolute_importdivisionN)typescgutilstyping   )
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   5lib/python3.7/site-packages/numba/targets/optional.pyalways_return_true_impl   s    r   c             C   s   t jS )N)r   	false_bit)r   r   r   r   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lvalZrvalZopt_typeZopt_valZoptZ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   Z	signaturer   Zget_setattr)r   r   r   r   r#   ZbasetyZvaltytargetr$   Ztarget_typeZnewsigr%   r   r   r   optional_setattr:   s    
r(   c       
   
   C   s   | j |||d}t||j}|  ||}||b\}}	|& tj|_| ||j|j|j|_W dQ R X |	 tj	|_t
|jj|_W dQ R X W d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"   N)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_optionalI   s    

 r.   c             C   s>   |t jkr| ||jS | ||||j}| ||j|S d S )N)r   r   Zmake_optional_noner   r    Zmake_optional_value)r   r   r*   r+   r$   r   r   r   any_to_optionalh   s    
r/   c          	   C   sp   | j |||d}t||j}|j||dd$ d|jf }| j|t	|f W d Q R X | 
||j|j|S )N)r"   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,   r-   msgr   r   r   optional_to_anyq   s    r2   )Z
__future__r   r   r   operatorZnumbar   r   r   Zimputilsr	   r
   r   r   r   r   r   r   is_r   ZOptionalr&   r(   r.   ZAnyr/   ZBooleanr2   r   r   r   r   <module>   s   	