U
    ,d                      @   s   d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	 ddddd	Z
d
d ZG dd deZG dd deZG dd deZdS )z
Function descriptors.
    )defaultdictN)typesitanium_mangler)_dynamic_modname_dynamic_module abi_tagsuidc                C   s   t j| |||dS )Nr   )r   Zmangle)nameargtypesr	   r
   r   r   7/tmp/pip-unpacked-wheel-eu7e0c37/numba/core/funcdesc.pydefault_mangler   s    r   c                 C   s   | rd | |S |S )zS
    Returns a new string that is used for the first half of the mangled name.
    z{}.{})format)modnamequalnamer   r   r   qualifying_prefix   s    r   c                   @   s|   e Zd ZdZdZdddZdd	 Zd
d Zdd Ze	dd Z
e	dd Ze	dd Zdd Zedd ZedddZdS )FunctionDescriptoraS  
    Base class for function descriptors: an object used to carry
    useful metadata about a natively callable function.

    Note that while `FunctionIdentity` denotes a Python function
    which is being concretely compiled by Numba, `FunctionDescriptor`
    may be more "abstract": e.g. a function decorated with `@generated_jit`.
    )nativer   r   doctypemap	calltypesargskwsrestyper   mangled_nameunique_nameenv_nameglobal_dictinlinenoaliasr	   r
   NFr   c                    s   | _ | _| _| _| _| _| _| _|	 _|
 _	| _
|d k	rdt|ts\t|| _nt fdd|	D  _|d krtn|}t j j}| _|| j||d _|d kr|d| j||d}| _| _| _| _d S )Nc                 3   s   | ]} j d |  V  qdS )zarg.N)r   ).0aselfr   r   	<genexpr>>   s     z.FunctionDescriptor.__init__.<locals>.<genexpr>r   z.NumbaEnv.{})r   r   r   r   r   r   r   r   r   r   r   
isinstancetupleAssertionErrorr   r   r   r
   r   r   r   r   r    r	   )r$   r   r   r   r   r   r   r   r   r   r   manglerr   r   r    r   r   r	   r
   Z
qualprefixr   r#   r   __init__&   sD       
  zFunctionDescriptor.__init__c                 C   s   | j p|  jS )z
        Return the global dictionary of the function.
        It may not match the Module's globals if the function is created
        dynamically (i.e. exec)
        )r   lookup_module__dict__r#   r   r   r   lookup_globalsO   s    z!FunctionDescriptor.lookup_globalsc                 C   s:   | j tkrtS zt| j W S  tk
r4   t Y S X dS )z
        Return the module in which this function is supposed to exist.
        This may be a dummy module if the function was dynamically
        generated or the module can't be found.
        N)r   r   r   	importlibimport_moduleImportErrorr#   r   r   r   r+   W   s    
z FunctionDescriptor.lookup_modulec                 C   s   t |  | jS )zO
        Return the original function object described by this object.
        )getattrr+   r   r#   r   r   r   lookup_functionf   s    z"FunctionDescriptor.lookup_functionc                 C   s   | j S )z@
        The LLVM-registered name for the raw function.
        r   r#   r   r   r   llvm_func_namel   s    z!FunctionDescriptor.llvm_func_namec                 C   s   t j| jddS )z
        The LLVM-registered name for a CPython-compatible wrapper of the
        raw function (i.e. a PyCFunctionWithKeywords).
        cpython)ns)r   Zprepend_namespacer   r#   r   r   r   llvm_cpython_wrapper_nameu   s    z,FunctionDescriptor.llvm_cpython_wrapper_namec                 C   s
   d| j  S )zb
        The LLVM-registered name for a C-compatible wrapper of the
        raw function.
        zcfunc.r3   r#   r   r   r   llvm_cfunc_wrapper_name~   s    z*FunctionDescriptor.llvm_cfunc_wrapper_namec                 C   s
   d| j  S )Nz<function descriptor %r>)r   r#   r   r   r   __repr__   s    zFunctionDescriptor.__repr__c           
      C   sb   |j j}|j j}|j}|jpd}t|j}d}d}|dkrHt}|j jj}|j j	}	||	|||||fS )z
        Returns
        -------
        qualname, unique_name, modname, doc, args, kws, globals

        ``unique_name`` must be a unique name.
         r   N)
func_idfuncZfunc_qualname
__module____doc__r'   	arg_namesr   __globals__r   )
clsfunc_irr<   r   r   r   r   r   r   r   r   r   r   _get_function_info   s    	


z%FunctionDescriptor._get_function_infoc
                 C   sH   |  |\}
}}}}}}| |||
||||||||||||	|jjd}|S )N)r)   r   r    r   r	   r
   )rC   r;   Z	unique_id)rA   rB   r   r   r   r   r)   r   r    r	   r   r   r   r   r   r   r   r$   r   r   r   _from_python_function   s            z(FunctionDescriptor._from_python_function)NNFFNNr   N)NFFr   )__name__r=   __qualname__r>   	__slots__r*   r-   r+   r2   propertyr4   r7   r8   r9   classmethodrC   rD   r   r   r   r   r      s:                
)



      r   c                   @   s,   e Zd ZdZdZedd Zedd ZdS )PythonFunctionDescriptorzE
    A FunctionDescriptor subclass for Numba-compiled functions.
    r   c	           	      C   s   | j ||||d||||d	S )zx
        Build a FunctionDescriptor for a given specialization of a Python
        function (in nopython mode).
        T)r   r)   r   r    r	   )rD   )	rA   rB   r   r   r   r)   r   r    r	   r   r   r   from_specialized_function   s      z2PythonFunctionDescriptor.from_specialized_functionc                 C   s.   t dd }| }tj}| j||||ddS )ze
        Build a FunctionDescriptor for an object mode variant of a Python
        function.
        c                   S   s   t jS N)r   pyobjectr   r   r   r   <lambda>       zDPythonFunctionDescriptor.from_object_mode_function.<locals>.<lambda>F)r   )r   copyr   rM   rD   )rA   rB   r   r   r   r   r   r   from_object_mode_function   s    z2PythonFunctionDescriptor.from_object_mode_functionN)rE   r=   rF   r>   rG   rI   rK   rQ   r   r   r   r   rJ      s   
rJ   c                       s$   e Zd ZdZdZ fddZ  ZS )ExternalFunctionDescriptorza
    A FunctionDescriptor subclass for opaque external functions
    (e.g. raw C functions).
    r   c                    sL   dd t t|D }ddd}tt| jdd ||dd |d |d ||d d S )	Nc                 S   s   g | ]}d | qS )zarg%dr   )r!   ir   r   r   
<listcomp>   s     z7ExternalFunctionDescriptor.__init__.<locals>.<listcomp>c                 S   s   | S rL   r   )r"   xr	   r
   r   r   r   r)      s    z4ExternalFunctionDescriptor.__init__.<locals>.manglerTr:   )r   r   r   r   r   r   r   r   r   r   r)   r   )N)rangelensuperrR   r*   )r$   r   r   r   r   r)   	__class__r   r   r*      s     

      z#ExternalFunctionDescriptor.__init__)rE   r=   rF   r>   rG   r*   __classcell__r   r   rY   r   rR      s   rR   )r>   collectionsr   r.   Z
numba.corer   r   Znumba.core.utilsr   r   r   r   objectr   rJ   rR   r   r   r   r   <module>   s    