
    J/PhY&                         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          Z G d dej	        d	
          Z
 G d d          Z G d de          Z G d d          Z e            Z G d de          ZdS )z[
This module contains utils for manipulating target configurations such as
compiler flags.
    N)MappingProxyType)utilsc                   ^    e Zd ZdZdZd Zed             Zed             Zed             Z	dS )Optionz.An option to be used in ``TargetConfig``.
    _type_default_docc                0    || _         || _        || _        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docs       W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/core/targetconfig.py__init__zOption.__init__   s     
			    c                     | j         S N)r   r   s    r   r   zOption.type"   s
    zr   c                     | j         S r   )r	   r   s    r   r   zOption.default&   s
    }r   c                     | j         S r   )r
   r   s    r   r   z
Option.doc*   s
    yr   N)
__name__
__module____qualname____doc__	__slots__r   propertyr   r   r    r   r   r   r      s         +I      X   X   X  r   r   c                       e Zd ZdS )_FlagsStackN)r   r   r   r   r   r   r    r    /   s        Dr   r    flags)
stack_namec                   @    e Zd ZdZed             Zd Zd Zd Z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                 L     |             }|r|                                 }nd}|S )z8Get the TOS or return None if no config is set.
        N)top)clsr   r!   s      r   top_or_nonezConfigStack.top_or_none9   s2     suu 	HHJJEE Er   c                 ,    t                      | _        d S r   )r    _stkr   s    r   r   zConfigStack.__init__E   s    MM			r   c                 4    | j                                         S r   )r*   r&   r   s    r   r&   zConfigStack.topH   s    y}}r   c                 *    t          | j                  S r   )lenr*   r   s    r   __len__zConfigStack.__len__K   s    49~~r   c                 6    | j                             |          S )zgReturns a contextmanager that performs ``push(flags)`` on enter and
        ``pop()`` on exit.
        )r*   enter)r   r!   s     r   r0   zConfigStack.enterN   s     yu%%%r   N)
r   r   r   r   classmethodr(   r   r&   r.   r0   r   r   r   r$   r$   3   su         
 	 	 [	" " "    & & & & &r   r$   c                       e Zd ZdZd Z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           	      T   i }t          |          D ]}|                    |j                   |                    |                     |                     t	          |          | _        d }| j                                        D ] \  }}t          | | |||                     !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                 V      fd} fd} fd}t          |||j                  S )Nc                 D    | j                             j                  S r   )_valuesgetr   )r   nameoptions    r   getterz=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.gettero   s    |''fn===r   c                 B                         |          | j        <   d S r   )r   r7   )r   valr9   r:   s     r   setterz=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.setterr   s!    %+[[%5%5T"""r   c                     | j         = d S r   )r7   r   r9   s    r   delterz=_MetaTargetConfig.__init__.<locals>.make_prop.<locals>.delteru   s    L&&&r   )r   r   )r9   r:   r;   r>   rA   s   ``   r   	make_propz-_MetaTargetConfig.__init__.<locals>.make_propn   sq    > > > > > >6 6 6 6 6 6' ' ' ' ' FFFFJ???r   N)reversedupdateoptionsfind_optionsr   itemssetattr)r'   r9   basesdctoptsbase_clsrB   r:   s           r   r   z_MetaTargetConfig.__init__\   s      ! 	* 	*HKK())))C$$S))***&t,,
	@ 
	@ 
	@  K--// 	8 	8LD&Cyyv667777	8 	8r   c                 >    d |                                 D             S )z[Returns a new dict with all the items that are a mapping to an
        ``Option``.
        c                 D    i | ]\  }}t          |t                    ||S r   )
isinstancer   .0kvs      r   
<dictcomp>z2_MetaTargetConfig.find_options.<locals>.<dictcomp>   s-    FFFA
1f0E0EF1FFFr   )rG   )r'   rJ   s     r   rF   z_MetaTargetConfig.find_options}   s!     GFFFFFr   N)r   r   r   r   r   rF   r   r   r   r3   r3   U   sB         8 8 8BG G G G Gr   r3   c                       e Zd Zd ZdS )_NotSetTypec                     dS )Nz<NotSet>r   r   s    r   __repr__z_NotSetType.__repr__   s    zr   N)r   r   r   rX   r   r   r   rV   rV      s#            r   rV   c                       e Zd ZdZdgZddiZddZd Zd Zd	 Z	d
 Z
d Zd ZefdZd ZdefdZd Zd Zedefd            ZdefdZededef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
    r7   wbitsiNc                     i | _         |8t          |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)r7   rO   rZ   rD   )r   	copy_froms     r   r   zTargetConfig.__init__   sN      i66666L	 122222 ! r   c                 B   g }g }| j         D ]W}| dt          | |           }|                     |          s|                    |           B|                    |           X| j        j        }| dd                    |           dd                    |           dS )N=(, z, [z]))rE   getattris_setappend	__class__r   join)r   argsdefsrR   msgclsnames         r   rX   zTargetConfig.__repr__   s      	! 	!A++q))++C;;q>> !C    C    .)CCDIIdOOCC		$CCCCr   c                 x    t          t          t          |                                                               S r   )hashtuplesortedvaluesr   s    r   __hash__zTargetConfig.__hash__   s(    E&//00111r   c                     t          |t                    r*|                                 |                                k    S t          S r   )rO   rZ   ro   NotImplemented)r   others     r   __eq__zTargetConfig.__eq__   s5    e\** 	";;==ELLNN22!!r   c                 *      fd j         D             S )z)Returns a dict of all the values
        c                 2    i | ]}|t          |          S r   )rb   )rQ   rR   r   s     r   rT   z'TargetConfig.values.<locals>.<dictcomp>   s%    :::74##:::r   )rE   r   s   `r   ro   zTargetConfig.values   s!     ;:::T\::::r   c                 >    |                      |           || j        v S )zIs the option set?
        )_guard_optionr7   r@   s     r   rc   zTargetConfig.is_set   s%     	4   t|##r   c                 f    |                      |           | 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   r7   popr@   s     r   discardzTargetConfig.discard   s6    
 	4   t$$$$$r   c                     |                      |           |                     |          sat                      }|r5|                                }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)rx   rc   r$   r&   rH   rb   _NotSet)r   r9   r   cstkr&   s        r   inherit_if_not_setzTargetConfig.inherit_if_not_set   s     	4   {{4   	-==D -hhjjdGC$6$677777''dG,,,,,	- 	- ('r   c                 2     t          |           |           S )zClone this instance.
        )r   r   s    r   copyzTargetConfig.copy   s     tDzz$r   returnc                     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                 "    g | ]\  }}| d | S )r_   r   rP   s      r   
<listcomp>z(TargetConfig.summary.<locals>.<listcomp>   s&    <<<tq!1

q

<<<r   r`   ra   ))_summary_argsre   r   rf   )r   rg   rj   s      r   summaryzTargetConfig.summary   sN     =<t'9'9';';<<<.)..DIIdOO....r   c                 ^    || j         vr#|dt          |            }t          |          d S )Nz is not a valid option for )rE   r   
ValueError)r   r9   ri   s      r   rx   zTargetConfig._guard_option   s<    t|##DDT

DDCS//! $#r   c                     g }t          | j                  D ]X}| j        |         }|                     |          r4t          | |          }|j        |k    r||f}|                    |           Y|S )zreturns a sorted sequence of 2-tuple containing the
        ``(flag_name, flag_value)`` for flag that are set with a non-default
        value.
        )rn   rE   rc   rb   r   rd   )r   rg   rR   optflagvalrS   s         r   r   zTargetConfig._summary_args  sy    
 %% 	# 	#A,q/C{{1~~ #!$**;'))GAKKNNNr   c                    g }|                     d           |                     | j        j                   |                    ddg           | j                                        D ]A\  }}|                     |           |                     t          |j                             Bd                    |          	                                S )z]Returns a ``bytes`` object suitable for use as a dictionary for
        compression.
        numbaTrueFalse )
rd   re   r   extendrE   rG   strr   rf   encode)r'   bufrR   r   s       r   _make_compression_dictionaryz)TargetConfig._make_compression_dictionary  s    
 

7

3=)***

FG$%%%k'')) 	) 	)FAsJJqMMMJJs3;''((((wws||""$$$r   c                    |                                  }t          j        d|t          j        d| j        }|                    |                                                                           g}|                    |	                                           t          j        d                    |                                                    S )z6Return a string suitable for symbol mangling.
        )zdictlevelr   r   )r   zlibcompressobjZ_BEST_COMPRESSION_ZLIB_CONFIGcompressr   r   rd   flushbase64	b64encoderf   decode)r   r   compr   s       r   get_mangle_stringzTargetConfig.get_mangle_string#  s     1133 5e43J 5 5"&"35 5 }}T\\^^2244556

4::<<   ..55777r   mangledc                    d }t          j        d||          }t          j        |          }|                                 }t          j        dd|i| j        }g }|r1|                    |	                    |                     |j
        }|1|                    |                                           d                    |                                          S )zCReturns the demangled result from ``.get_mangle_string()``
        c                 x    t          t          d|                     d          dd          z   d                    S )N0xr         )chrintgroup)xs    r   replz#TargetConfig.demangle.<locals>.repl5  s1    s4!''!**QRR.0"55666r   z_[a-zA-Z0-9][a-zA-Z0-9]r   r   r   )resubr   	b64decoder   r   decompressobjr   rd   
decompressunconsumed_tailr   rf   r   )r'   r   r   	unescapedrawr   dcr   s           r   demanglezTargetConfig.demangle0  s    
	7 	7 	7F5tWEE	y))0022@@e@s/?@@ 	%JJr}}S))***$C  	% 	

288::xx}}##%%%r   r   )r   r   r   r   r   r   r   rX   rp   rt   ro   rc   r{   r}   r   r   r   r   rx   r   r1   bytesr   r   r   r   r   r   rZ   rZ      st         I S>L3 3 3 3D D D2 2 2" " "; ; ;
$ $ $% % % 07 - - - -,     
/ / / / /" " "
   %U % % % [%"83 8 8 8 8 &s &s & & & [& & &r   rZ   )	metaclass)r   r   r   r   typesr   
numba.corer   r   ThreadLocalStackr    r$   r   r3   rV   r}   rZ   r   r   r   <module>r      s    
			   " " " " " "             D	 	 	 	 	%(W 	 	 	 	& & & & & & & &D,G ,G ,G ,G ,G ,G ,G ,G^       
 +--v& v& v& v& v&. v& v& v& v& v& v&r   