U
    ø¾|e=&  ã                   @   s    d Z ddlZddlZddlZddlmZ ddlmZ G dd„ dƒZG dd„ dej	d	d
�Z
G dd„ dƒZG dd„ deƒZG dd„ dƒZeƒ ZG dd„ ded�ZdS )z[
This module contains utils for manipulating target configurations such as
compiler flags.
é    N)ÚMappingProxyType)Úutilsc                   @   s@   e Zd ZdZdZdd„ Zedd„ ƒZedd„ ƒZed	d
„ ƒZ	dS )ÚOptionz.An option to be used in ``TargetConfig``.
    ©Ú_typeÚ_defaultÚ_docc                C   s   || _ || _|| _dS )a-  
        Parameters
        ----------
        type :
            Type of the option value. It can be a callable.
            The setter always calls ``self._type(value)``.
        default :
            The default value for the option.
        doc : str
            Docstring for the option.
        Nr   )ÚselfÚtypeÚdefaultÚdoc© r   úT/var/www/website-v5/atlas_env/lib/python3.8/site-packages/numba/core/targetconfig.pyÚ__init__   s    zOption.__init__c                 C   s   | j S ©N)r   ©r	   r   r   r   r
   "   s    zOption.typec                 C   s   | j S r   )r   r   r   r   r   r   &   s    zOption.defaultc                 C   s   | j S r   )r   r   r   r   r   r   *   s    z
Option.docN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   Úpropertyr
   r   r   r   r   r   r   r      s   

r   c                   @   s   e Zd ZdS )Ú_FlagsStackN)r   r   r   r   r   r   r   r   /   s   r   Úflags)Ú
stack_namec                   @   s<   e Zd ZdZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
d„ Z	dS )ÚConfigStackzºA stack for tracking target configurations in the compiler.

    It stores the stack in a thread-local class attribute. All instances in the
    same thread will see the same stack.
    c                 C   s   | ƒ }|r|  ¡ }nd}|S )z8Get the TOS or return None if no config is set.
        N)Útop)Úclsr	   r   r   r   r   Útop_or_none9   s
    
zConfigStack.top_or_nonec                 C   s   t ƒ | _d S r   )r   Ú_stkr   r   r   r   r   E   s    zConfigStack.__init__c                 C   s
   | j  ¡ S r   )r   r   r   r   r   r   r   H   s    zConfigStack.topc                 C   s
   t | jƒS r   )Úlenr   r   r   r   r   Ú__len__K   s    zConfigStack.__len__c                 C   s   | j  |¡S )zgReturns a contextmanager that performs ``push(flags)`` on enter and
        ``pop()`` on exit.
        )r   Úenter)r	   r   r   r   r   r"   N   s    zConfigStack.enterN)
r   r   r   r   Úclassmethodr   r   r   r!   r"   r   r   r   r   r   3   s   
r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú_MetaTargetConfigzÚMetaclass for ``TargetConfig``.

    When a subclass of ``TargetConfig`` is created, all ``Option`` defined
    as class members will be parsed and corresponding getters, setters, and
    delters will be inserted.
    c                 C   sj   i }t |ƒD ]}| |j¡ q| |  |¡¡ t|ƒ| _dd„ }| j ¡ D ]\}}t| ||||ƒƒ qJdS )zÊInvoked when subclass is created.

        Insert properties for each ``Option`` that are class members.
        All the options will be grouped inside the ``.options`` class
        attribute.
        c                    s8   ‡ ‡fdd„}‡ ‡fdd„}‡ fdd„}t |||ˆjƒS )Nc                    s   | j  ˆ ˆj¡S r   )Ú_valuesÚgetr   r   ©ÚnameÚoptionr   r   Úgettero   s    z=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.getterc                    s   ˆ  |¡| jˆ < d S r   )r
   r%   )r	   Úvalr'   r   r   Úsetterr   s    z=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.setterc                    s   | j ˆ = d S r   )r%   r   )r(   r   r   Údelteru   s    z=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.delter)r   r   )r(   r)   r*   r,   r-   r   r'   r   Ú	make_propn   s    z-_MetaTargetConfig.__init__.<locals>.make_propN)ÚreversedÚupdateÚoptionsÚfind_optionsr   ÚitemsÚsetattr)r   r(   ÚbasesÚdctÚoptsÚbase_clsr.   r)   r   r   r   r   \   s    
z_MetaTargetConfig.__init__c                 C   s   dd„ |  ¡ D ƒS )z[Returns a new dict with all the items that are a mapping to an
        ``Option``.
        c                 S   s    i | ]\}}t |tƒr||“qS r   )Ú
isinstancer   ©Ú.0ÚkÚvr   r   r   Ú
<dictcomp>�   s     
  z2_MetaTargetConfig.find_options.<locals>.<dictcomp>)r3   )r   r6   r   r   r   r2   }   s    z_MetaTargetConfig.find_optionsN)r   r   r   r   r   r2   r   r   r   r   r$   U   s   !r$   c                   @   s   e Zd Zdd„ ZdS )Ú_NotSetTypec                 C   s   dS )Nz<NotSet>r   r   r   r   r   Ú__repr__…   s    z_NotSetType.__repr__N)r   r   r   r@   r   r   r   r   r?   „   s   r?   c                   @   s¸   e Zd ZdZddiZd%dd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zefdd„Zdd„ Zedœdd„Zdd„ Zdd„ Zeedœdd„ƒZedœd d!„Zeeed"œd#d$„ƒZdS )&ÚTargetConfigaÿ  Base class for ``TargetConfig``.

    Subclass should fill class members with ``Option``. For example:

    >>> class MyTargetConfig(TargetConfig):
    >>>     a_bool_option = Option(type=bool, default=False, doc="a bool")
    >>>     an_int_option = Option(type=int, default=0, doc="an int")

    The metaclass will insert properties for each ``Option``. For example:

    >>> tc = MyTargetConfig()
    >>> tc.a_bool_option = True  # invokes the setter
    >>> print(tc.an_int_option)  # print the default
    ÚwbitsiñÿÿÿNc                 C   s.   i | _ |dk	r*t|tƒst‚| j  |j ¡ dS )z·
        Parameters
        ----------
        copy_from : TargetConfig or None
            if None, creates an empty ``TargetConfig``.
            Otherwise, creates a copy.
        N)r%   r9   rA   ÚAssertionErrorr0   )r	   Z	copy_fromr   r   r   r       s    zTargetConfig.__init__c                 C   sr   g }g }| j D ]8}|› dt| |ƒ› �}|  |¡s<| |¡ q| |¡ q| jj}|› dd |¡› dd |¡› d�S )Nú=ú(ú, z, [z]))r1   ÚgetattrÚis_setÚappendÚ	__class__r   Újoin)r	   ÚargsÚdefsr<   ÚmsgÚclsnamer   r   r   r@   ­   s    

zTargetConfig.__repr__c                 C   s   t tt|  ¡ ƒƒƒS r   )ÚhashÚtupleÚsortedÚvaluesr   r   r   r   Ú__hash__»   s    zTargetConfig.__hash__c                 C   s"   t |tƒr|  ¡ | ¡ kS tS d S r   )r9   rA   rS   ÚNotImplemented)r	   Úotherr   r   r   Ú__eq__¾   s    
zTargetConfig.__eq__c                    s   ‡ fdd„ˆ j D ƒS )z)Returns a dict of all the values
        c                    s   i | ]}|t ˆ |ƒ“qS r   )rG   )r;   r<   r   r   r   r>   Ç   s      z'TargetConfig.values.<locals>.<dictcomp>)r1   r   r   r   r   rS   Ä   s    zTargetConfig.valuesc                 C   s   |   |¡ || jkS )zIs the option set?
        )Ú_guard_optionr%   ©r	   r(   r   r   r   rH   É   s    
zTargetConfig.is_setc                 C   s   |   |¡ | j |d¡ dS )z„Remove the option by name if it is defined.

        After this, the value for the option will be set to its default value.
        N)rX   r%   ÚpoprY   r   r   r   ÚdiscardÏ   s    
zTargetConfig.discardc                 C   sR   |   |¡ |  |¡sNtƒ }|r:| ¡ }t| |t||ƒƒ n|tk	rNt| ||ƒ dS )aL  Inherit flag from ``ConfigStack``.

        Parameters
        ----------
        name : str
            Option name.
        default : optional
            When given, it overrides the default value.
            It is only used when the flag is not defined locally and there is
            no entry in the ``ConfigStack``.
        N)rX   rH   r   r   r4   rG   Ú_NotSet)r	   r(   r   Zcstkr   r   r   r   Úinherit_if_not_set×   s    

zTargetConfig.inherit_if_not_setc                 C   s   t | ƒ| ƒS )zClone this instance.
        )r
   r   r   r   r   Úcopyí   s    zTargetConfig.copy)Úreturnc                 C   s0   dd„ |   ¡ D ƒ}| jj}|› dd |¡› d�S )z›Returns a ``str`` that summarizes this instance.

        In contrast to ``__repr__``, only options that are explicitly set will
        be shown.
        c                 S   s   g | ]\}}|› d |› �‘qS )rD   r   r:   r   r   r   Ú
<listcomp>ø   s     z(TargetConfig.summary.<locals>.<listcomp>rE   rF   ú))Ú_summary_argsrJ   r   rK   )r	   rL   rO   r   r   r   Úsummaryò   s    zTargetConfig.summaryc                 C   s(   || j kr$|›dt| ƒ› �}t|ƒ‚d S )Nz is not a valid option for )r1   r
   Ú
ValueError)r	   r(   rN   r   r   r   rX   ü   s    
zTargetConfig._guard_optionc                 C   sR   g }t | jƒD ]>}| j| }|  |¡rt| |ƒ}|j|kr||f}| |¡ q|S )z˜returns a sorted sequence of 2-tuple containing the
        ``(flag_name, flag_value)`` for flag that are set with a non-default
        value.
        )rR   r1   rH   rG   r   rI   )r	   rL   r<   ÚoptZflagvalr=   r   r   r   rb     s    



zTargetConfig._summary_argsc                 C   sf   g }|  d¡ |  | jj¡ | ddg¡ | j ¡ D ]"\}}|  |¡ |  t|jƒ¡ q4d |¡ 	¡ S )z]Returns a ``bytes`` object suitable for use as a dictionary for
        compression.
        ÚnumbaÚTrueÚFalseÚ )
rI   rJ   r   Úextendr1   r3   Ústrr   rK   Úencode)r   Úbufr<   re   r   r   r   Ú_make_compression_dictionary  s    

z)TargetConfig._make_compression_dictionaryc                 C   sX   |   ¡ }tjf |tjdœ| j—Ž}| |  ¡  ¡ ¡g}| | 	¡ ¡ t
 d |¡¡ ¡ S )z6Return a string suitable for symbol mangling.
        )ÚzdictÚleveló    )rn   ÚzlibÚcompressobjÚZ_BEST_COMPRESSIONÚ_ZLIB_CONFIGÚcompressrc   rl   rI   ÚflushÚbase64Ú	b64encoderK   Údecode)r	   ro   Úcomprm   r   r   r   Úget_mangle_string"  s    ÿzTargetConfig.get_mangle_string)Úmangledr_   c                 C   sz   dd„ }t  d||¡}t |¡}|  ¡ }tjf d|i| j—Ž}g }|r^| | 	|¡¡ |j
}qB| | ¡ ¡ d |¡ ¡ S )zCReturns the demangled result from ``.get_mangle_string()``
        c                 S   s    t td|  d¡dd …  dƒƒS )NÚ0xr   é   é   )ÚchrÚintÚgroup)Úxr   r   r   Úrepl4  s    z#TargetConfig.demangle.<locals>.replz_[a-zA-Z0-9][a-zA-Z0-9]ro   rq   )ÚreÚsubrx   Ú	b64decodern   rr   Údecompressobjru   rI   Ú
decompressÚunconsumed_tailrw   rK   rz   )r   r}   r…   Z	unescapedÚrawro   Údcrm   r   r   r   Údemangle/  s    
zTargetConfig.demangle)N)r   r   r   r   ru   r   r@   rT   rW   rS   rH   r[   r\   r]   r^   rk   rc   rX   rb   r#   Úbytesrn   r|   rŽ   r   r   r   r   rA   Œ   s&   

rA   )Ú	metaclass)r   r†   rr   rx   Útypesr   Ú
numba.corer   r   ÚThreadLocalStackr   r   r
   r$   r?   r\   rA   r   r   r   r   Ú<module>   s   ""/