3
VY]                 @   s   d Z ddlmZmZm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	 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.
    )print_functiondivisionabsolute_import)defaultdictN   )typesitanium_mangler)_dynamic_modname_dynamic_modulec             C   s   t j| |S )N)r   Zmangle)nameargtypes r   -lib/python3.6/site-packages/numba/funcdesc.pydefault_mangler   s    r   c             C   s   | rdj | |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noaliasNFc                s   | _ | _| _| _| _| _| _| _|	 _|
 _	| _
|d k	rdt|ts\t|| _nt fdd|	D  _|d krtn|}t j j}|| j _|d kr|dj| j}| _| _| _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>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   manglerr   r    r!   r   r   Z
qualprefixr   )r$   r   __init__'   s0    
zFunctionDescriptor.__init__c             C   s   | j p| j 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_globalsL   s    z!FunctionDescriptor.lookup_globalsc             C   s   | j tkrtS tj| j  S 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.
        N)r   r	   r
   sysmodules)r$   r   r   r   r+   T   s    
z FunctionDescriptor.lookup_modulec             C   s   t | j | jS )zO
        Return the original function object described by this object.
        )getattrr+   r   )r$   r   r   r   lookup_function_   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_namee   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).
        Zcpython)ns)r   Zprepend_namespacer   )r$   r   r   r   llvm_cpython_wrapper_namen   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.)r   )r$   r   r   r   llvm_cfunc_wrapper_namew   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}f }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.
         N)
Zfunc_idfuncZfunc_qualname
__module____doc__r'   Z	arg_namesr	   __globals__r   )
clsfunc_irr8   r   r   r   r   r   r   r   r   r   r   _get_function_info   s    	


z%FunctionDescriptor._get_function_infoc	             C   s@   | j |\}	}
}}}}}| |||	|
||||||||||d}|S )N)r)   r    r!   r   )r>   )r<   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)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   )NNFFNN)NFF)__name__r9   __qualname__r:   	__slots__r*   r-   r+   r1   propertyr2   r4   r5   r6   classmethodr>   r?   r   r   r   r   r      s$        
"		r   c               @   s,   e Zd ZdZf Zedd Zedd ZdS )PythonFunctionDescriptorzE
    A FunctionDescriptor subclass for Numba-compiled functions.
    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?   )r<   r=   r   r   r   r)   r    r!   r   r   r   from_specialized_function   s    z2PythonFunctionDescriptor.from_specialized_functionc             C   s.   t dd }|j }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>   s    zDPythonFunctionDescriptor.from_object_mode_function.<locals>.<lambda>F)r   )r   copyr   rG   r?   )r<   r=   r   r   r   r   r   r   from_object_mode_function   s
    z2PythonFunctionDescriptor.from_object_mode_functionN)r@   r9   rA   r:   rB   rD   rF   rJ   r   r   r   r   rE      s   rE   c                   s$   e Zd ZdZf Z fddZ  ZS )ExternalFunctionDescriptorza
    A FunctionDescriptor subclass for opaque external functions
    (e.g. raw C functions).
    c                sF   dd t t|D }tt| jdd ||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>Tr7   c             S   s   | S )Nr   )r#   xr   r   r   rH      s    z5ExternalFunctionDescriptor.__init__.<locals>.<lambda>)r   r   r   r   r   r   r   r   r   r   r)   r   )rangelensuperrK   r*   )r$   r   r   r   r   )	__class__r   r   r*      s    
z#ExternalFunctionDescriptor.__init__)r@   r9   rA   r:   rB   r*   __classcell__r   r   )rR   r   rK      s   rK   )r:   Z
__future__r   r   r   collectionsr   r.   r7   r   r   Zutilsr	   r
   r   r   objectr   rE   rK   r   r   r   r   <module>   s    