o
    1&i'                     @   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   BC:\wamp64\www\opt\env\Lib\site-packages\numba/core/targetconfig.py__init__   s   
zOption.__init__c                 C      | j S N)r   r	   r   r   r   r
   "      zOption.typec                 C   r   r   )r   r   r   r   r   r   &   r   zOption.defaultc                 C   r   r   )r   r   r   r   r   r   *   r   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)Z
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|  }|S 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      zConfigStack.__init__c                 C   s
   | j  S r   )r    r   r   r   r   r   r   H      
zConfigStack.topc                 C   s
   t | jS r   )lenr    r   r   r   r   __len__K   r"   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| |||| q%d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      z=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.setterc                    s   | j  = d S r   )r(   r   )r+   r   r   delteru   r!   z=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.delter)r   r   )r+   r,   r-   r/   r1   r   r*   r   	make_propn   s   z-_MetaTargetConfig.__init__.<locals>.make_propN)reversedupdateoptionsfind_optionsr   itemssetattr)r   r+   basesdctoptsZbase_clsr2   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>)r7   )r   r:   r   r   r   r6   }   s   z_MetaTargetConfig.find_optionsN)r   r   r   r   r   r6   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   rC   r   r   r   r   rB      s    rB   c                   @   s   e Zd ZdZdg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defddZdd Zdd Zedefdd Zdefd!d"Zed#edef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
    r(   wbitsiNc                 C   s2   i | _ |durt|tsJ | j |j  dS dS )z
        Parameters
        ----------
        copy_from : TargetConfig or None
            if None, creates an empty ``TargetConfig``.
            Otherwise, creates a copy.
        N)r(   r<   rD   r4   )r	   Z	copy_fromr   r   r   r      s
   zTargetConfig.__init__c                 C   sr   g }g }| j D ]}| dt| | }| |s|| q|| q| jj}| dd| dd| dS )N=(, z, [z]))r5   getattris_setappend	__class__r   join)r	   argsZdefsr?   msgclsnamer   r   r   rC      s   

"zTargetConfig.__repr__c                 C   s   t tt|  S r   )hashtuplesortedvaluesr   r   r   r   __hash__   r0   zTargetConfig.__hash__c                 C   s   t |tr|  | kS tS r   )r<   rD   rT   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   )rI   )r>   r?   r   r   r   rA      s    z'TargetConfig.values.<locals>.<dictcomp>)r5   r   r   r   r   rT      s   zTargetConfig.valuesc                 C   s   |  | || jv S )zIs the option set?
        )_guard_optionr(   r	   r+   r   r   r   rJ      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)rY   r(   poprZ   r   r   r   discard   s   
zTargetConfig.discardc                 C   s\   |  | | |s*t }|r| }t| |t|| dS |tur,t| || dS dS 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)rY   rJ   r   r   r8   rI   _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 )rF   r   r=   r   r   r   
<listcomp>   s    z(TargetConfig.summary.<locals>.<listcomp>rG   rH   ))_summary_argsrL   r   rM   )r	   rN   rP   r   r   r   summary   s   zTargetConfig.summaryc                 C   s(   || j vr|dt|  }t|d S )Nz is not a valid option for )r5   r
   
ValueError)r	   r+   rO   r   r   r   rY      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.
        )rS   r5   rJ   rI   r   rK   )r	   rN   r?   optZflagvalr@   r   r   r   rc     s   




zTargetConfig._summary_argsc                 C   sf   g }| d | | jj |ddg | j D ]\}}| | | t|j qd|	 S )z]Returns a ``bytes`` object suitable for use as a dictionary for
        compression.
        ZnumbaTrueFalse )
rK   rL   r   extendr5   r7   strr   rM   encode)r   bufr?   rf   r   r   r   _make_compression_dictionary  s   

z)TargetConfig._make_compression_dictionaryc                 C   sX   |   }tjd|tjd| j}||   g}||	  t
d| S )z6Return a string suitable for symbol mangling.
        )zdictlevel    Nr   )rn   zlibcompressobjZ_BEST_COMPRESSION_ZLIB_CONFIGcompressrd   rl   rK   flushbase64	b64encoderM   decode)r	   ro   comprm   r   r   r   get_mangle_string#  s   zTargetConfig.get_mangle_stringmangledc                 C   s|   dd }t d||}t|}|  }tjdd|i| j}g }|r0||	| |j
}|s#||  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   repl5  s    z#TargetConfig.demangle.<locals>.replz_[a-zA-Z0-9][a-zA-Z0-9]ro   rq   Nr   )resubrx   	b64decodern   rr   decompressobjru   rK   
decompressunconsumed_tailrw   rM   rz   )r   r}   r   Z	unescapedrawro   Zdcrm   r   r   r   demangle0  s   
zTargetConfig.demangler   )r   r   r   r   r   ru   r   rC   rU   rX   rT   rJ   r\   r]   r^   r_   rk   rd   rY   rc   r&   bytesrn   r|   r   r   r   r   r   rD      s*    

rD   )	metaclass)r   r   rr   rx   typesr   Z
numba.corer   r   ZThreadLocalStackr   r   r
   r'   rB   r]   rD   r   r   r   r   <module>   s    ""/