o
    ۾iQ                      @   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   mangle)nameargtypesr	   r
   r   r   G/home/ubuntu/.local/lib/python3.10/site-packages/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 )FunctionDescriptora"  
    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".
    )nativer   r   doctypemap	calltypesargskwsrestyper   mangled_nameunique_nameenv_nameglobal_dictinlinenoaliasr	   r
   NFr   c                    s   | _ | _| _| _| _| _| _| _|	 _|
 _	| _
|d ur2t|ts.J || _nt fdd|	D  _|d u rDtn|}t j j}| _|| j||d _|d u rj|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tupler   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
   
qualprefixr   r$   r   __init__&   s:   


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   s4   | j tkrtS zt| j W S  ty   t Y S w )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.
        )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   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.r4   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u r$t}|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func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
   )rF   r=   	unique_id)rD   rE   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__rA   	__slots__r+   r.   r,   r3   propertyr5   r9   r:   r;   classmethodrF   rH   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	   )rH   )	rD   rE   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>   s    zDPythonFunctionDescriptor.from_object_mode_function.<locals>.<lambda>F)r   )r   copyr   rQ   rH   )rD   rE   r   r   r   r   r   r   from_object_mode_function   s   z2PythonFunctionDescriptor.from_object_mode_functionN)rI   r@   rJ   rA   rK   rM   rO   rT   r   r   r   r   rN      s    
rN   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 rP   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   rP   )rangelensuperrU   r+   )r%   r   r   r   r   r)   	__class__r   r   r+      s   

z#ExternalFunctionDescriptor.__init__)rI   r@   rJ   rA   rK   r+   __classcell__r   r   r\   r   rU      s    rU   )rA   collectionsr   r/   
numba.corer   r   numba.core.utilsr   r   r   r   objectr   rN   rU   r   r   r   r   <module>   s     