o
    @aX                     @   s  d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
mZmZ ddlZG dd deZe Zd	ZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZ G d&d' d'eZ!G d(d) d)e!eZ"G d*d+ d+e!eZ#G d,d- d-e!eZ$G d.d/ d/e!eZ%dS )0zF This module contains all classes used to model intrinsics behavior.      to_ast)UNKNOWN_RANGEbool_values)extract_combiner)AnyUnionFun	GeneratorNc                   @      e Zd ZdZdS )UnboundValueTypez;
    Represents a new location, bound to no identifier
    N__name__
__module____qualname____doc__ r   r   3/usr/lib/python3/dist-packages/pythran/intrinsic.pyr          r      c                   @      e Zd ZdS )UpdateEffectNr   r   r   r   r   r   r   r          r   c                   @   r   )
ReadEffectNr   r   r   r   r   r      r   r   c                   @   r   )ReadOnceEffectNr   r   r   r   r   r      r   r   c                   @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )	Intrinsicat  
    Model any Method/Function.

    Its member variables are:

    - argument_effects that describes the effect of the function on its
      argument (either UpdateEffect, ReadEffect or ReadOnceEffect)
    - global_effects that describes whether the function has side effects
    - return_alias that describes the aliasing between the return value
      and the parameters. The lambda returns an ast expression, generally
      depending on the node arguments (see dict.setdefault)
    - args that describes the name and default value of each arg, using the
      same representation as ast.FunctionDef, i.e. ast.arguments
    c                 K   s   | dt ft | _| dd| _| ddd | _tdd | d	g D g d d
d | dg D g d dd | dg D | _| ddd | _	| ddd | _
d S )Nargument_effectsglobal_effectsFreturn_aliasc                 S   s   t hS N)UnboundValue)xr   r   r   <lambda>9   s    z$Intrinsic.__init__.<locals>.<lambda>c                 S       g | ]}t |t  d d qS r    astNameZParam.0nr   r   r   
<listcomp>;       z&Intrinsic.__init__.<locals>.<listcomp>argsc                 S   r$   r    r%   r(   r   r   r   r+   >   r,   
kwonlyargsc                 S   s   g | ]}t |qS r   r   )r)   dr   r   r   r+   A   s    defaultsreturn_rangec                 S      t S r    r   )callr   r   r   r#   C       return_range_contentc                 S   r2   r    r3   )cr   r   r   r#   E   r5   )getr   DefaultArgNumr   r   r   r&   Z	argumentsr-   r1   r6   selfkwargsr   r   r   __init__4   s0   



zIntrinsic.__init__c                 C      dS NFr   r;   r   r   r   	isliteralG      zIntrinsic.isliteralc                 C   r>   r?   r   r@   r   r   r   
isfunctionJ   rB   zIntrinsic.isfunctionc                 C   r>   r?   r   r@   r   r   r   isstaticfunctionM   rB   zIntrinsic.isstaticfunctionc                 C   r>   r?   r   r@   r   r   r   ismethodP   rB   zIntrinsic.ismethodc                 C   r>   r?   r   r@   r   r   r   isattributeS   rB   zIntrinsic.isattributec                 C   s   t dd | jD  o| j S )Nc                 s   s    | ]}t |tV  qd S r    )
isinstancer   )r)   r"   r   r   r   	<genexpr>W   s    

z$Intrinsic.isconst.<locals>.<genexpr>)anyr   r   r@   r   r   r   isconstV   s
   
zIntrinsic.isconstc                 C   s   t | j| tS r    )rG   r   r   )r;   r*   r   r   r   
isreadonce[   s   zIntrinsic.isreadoncec                 C   s   d S r    r   )r;   snoder   r   r   combiner^   rB   zIntrinsic.combinerN)r   r   r   r   r=   rA   rC   rD   rE   rF   rJ   rK   rN   r   r   r   r   r   #   s    r   c                       s<   e Zd Z fddZdd Zdd Zdd Zd	d
 Z  ZS )FunctionIntrc                    s   | dd tt| jdi | |d | _d|v rm|d | _t| j}|d ur0|  j|f7  _d|vrlt| jtrIt	dd | jj
D rHt| _n't| jtr[| jj
d tu rZt| _nt| jtrl| jj
d tu rlt| _nt| _d	|v r{|d	 | _d S g | _d S )
N	combinersr   	signaturer1   c                 s   s    | ]
}|j d  tu V  qdS )N)__args__bool)r)   rr   r   r   rH   n   s    z(FunctionIntr.__init__.<locals>.<genexpr>r   rR   immediate_arguments)
setdefaultsuperrO   r=   rP   rQ   r   rG   r   allrS   r   r1   r
   rT   r	   r   rV   )r;   r<   Zdeduced_combiner	__class__r   r   r=   c   s6   



zFunctionIntr.__init__c                 C   r>   NTr   r@   r   r   r   rC   ~   rB   zFunctionIntr.isfunctionc                 C   r>   r\   r   r@   r   r   r   rD      rB   zFunctionIntr.isstaticfunctionc                 C   s   |  j |f7  _ d S r    rP   )r;   Z	_combinerr   r   r   add_combiner   s   zFunctionIntr.add_combinerc                 C   s   | j D ]}||| qd S r    r]   )r;   rL   rM   Zcombr   r   r   rN      s   
zFunctionIntr.combiner)	r   r   r   r=   rC   rD   r^   rN   __classcell__r   r   rZ   r   rO   b   s    rO   c                          e Zd Z fddZ  ZS )UserFunctionc                    s"   ||d< t t| jdi | d S )NrP   r   )rX   ra   r=   r;   rP   r<   rZ   r   r   r=      s   zUserFunction.__init__r   r   r   r=   r_   r   r   rZ   r   ra          ra   c                       r`   )ConstFunctionIntrc                    .   | dt ft  tt| jdi | d S Nr   r   )rW   r   r9   rX   re   r=   r:   rZ   r   r   r=         
zConstFunctionIntr.__init__rc   r   r   rZ   r   re      rd   re   c                       r`   )ConstExceptionIntrc                    rf   rg   )rW   r   r9   rX   ri   r=   r:   rZ   r   r   r=      rh   zConstExceptionIntr.__init__rc   r   r   rZ   r   ri      rd   ri   c                       r`   )ReadOnceFunctionIntrc                    &   t t| jddt ft i| d S rg   )rX   rj   r=   r   r9   r:   rZ   r   r   r=      
   

zReadOnceFunctionIntr.__init__rc   r   r   rZ   r   rj      rd   rj   c                       s,   e Zd Z fddZdd Zdd Z  ZS )
MethodIntrc                    s>   | dt ft ft   ||d< tt| jdi | d S )Nr   rP   r   )rW   r   r   r9   rX   rm   r=   rb   rZ   r   r   r=      s
   zMethodIntr.__init__c                 C   r>   r\   r   r@   r   r   r   rE      rB   zMethodIntr.ismethodc                 C   r>   r?   r   r@   r   r   r   rD      rB   zMethodIntr.isstaticfunction)r   r   r   r=   rE   rD   r_   r   r   rZ   r   rm      s    rm   c                       r`   )ConstMethodIntrc                    s.   | dt ft  tt| j|i | d S )Nr   )rW   r   r9   rX   rn   r=   rb   rZ   r   r   r=      s   zConstMethodIntr.__init__rc   r   r   rZ   r   rn      rd   rn   c                       r`   )ReadOnceMethodIntrc                    rk   rg   )rX   ro   r=   r   r9   r:   rZ   r   r   r=      rl   zReadOnceMethodIntr.__init__rc   r   r   rZ   r   ro      rd   ro   c                       (   e Zd ZdZ fddZdd Z  ZS )AttributeIntrz^
    Internal representation for any attributes.

    Examples
    --------
    >> a.real
    c                    s6   t t| jdi | d|v r|d | _dS t| _dS )z Forward arguments. rQ   Nr   )rX   rq   r=   rQ   r   r:   rZ   r   r   r=      s   
zAttributeIntr.__init__c                 C   r>   )z& Mark this intrinsic as an attribute. Tr   r@   r   r   r   rF         zAttributeIntr.isattribute)r   r   r   r   r=   rF   r_   r   r   rZ   r   rq      s    rq   c                       rp   )ConstantIntrz]
    Internal representation for any constant.

    Examples
    --------
    >> math.pi
    c                    s"   d|d< t t| jdi | dS )z1 Forward arguments and remove arguments effects. r   r   N)rX   rs   r=   r:   rZ   r   r   r=      s   zConstantIntr.__init__c                 C   r>   )z# Mark this intrinsic as a literal. Tr   r@   r   r   r   rA      rr   zConstantIntr.isliteral)r   r   r   r   r=   rA   r_   r   r   rZ   r   rs      s    rs   c                       s4   e Zd Z fddZdd Zdd Zdd Z  ZS )	Classc                    s    t t| j|i | || _d S r    )rX   rt   r=   fieldsr;   r/   r-   r<   rZ   r   r   r=      s   
zClass.__init__c                 C   s
   | j | S r    ru   r;   keyr   r   r   __getitem__      
zClass.__getitem__c                 C   s
   | j  S r    )ru   __iter__r@   r   r   r   r|      r{   zClass.__iter__c                 C   s
   || j v S )z( Forward key content to aliased module. rw   rx   r   r   r   __contains__   s   
zClass.__contains__)r   r   r   r=   rz   r|   r}   r_   r   r   rZ   r   rt      s
    rt   c                       r`   )ClassWithReadOnceConstructorc                    "   t t| j|g|R i | d S r    )rX   r~   r=   rv   rZ   r   r   r=         "z%ClassWithReadOnceConstructor.__init__rc   r   r   rZ   r   r~      rd   r~   c                       r`   )ClassWithConstConstructorc                    r   r    )rX   r   r=   rv   rZ   r   r   r=     r   z"ClassWithConstConstructor.__init__rc   r   r   rZ   r   r      rd   r   c                       r`   )ExceptionClassc                    r   r    )rX   r   r=   rv   rZ   r   r   r=     r   zExceptionClass.__init__rc   r   r   rZ   r   r     rd   r   c                   @   r   )UFuncz% Representation of ufunc from numpy. Nr   r   r   r   r   r   
  r   r   )&r   Zpythran.conversionr   Zpythran.intervalr   r   Zpythran.types.signaturer   Zpythran.typingr   r   r	   r
   Zgastr&   objectr   r!   r9   r   r   r   r   rO   ra   re   ri   rj   rm   rn   ro   rq   rs   rt   r~   r   r   r   r   r   r   r   <module>   s8    ?*