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 )ConfigStackzA 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 )_MetaTargetConfigzMetaclass 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 )zInvoked 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
    wbitsiNc                 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 )zRemove 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 )zReturns 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 )zreturns 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   ""/