
    Ǆg                        d Z ddlZddlmZ  ej                  dej
                        ZdZej                  dej                  dej                  dej                  d	ej                  d
ej                  dej                  dej                  dej                   dej"                  dej$                  dej&                  dej(                  diZd Zd Zd ZdedefdZd"ddddZd ZeZeZd Zd Z ddddZ!d  Z"d! Z#y)#aM  
Itanium CXX ABI Mangler

Reference: https://itanium-cxx-abi.github.io/cxx-abi/abi.html

The basics of the mangling scheme.

We are hijacking the CXX mangling scheme for our use.  We map Python modules
into CXX namespace.  A `module1.submodule2.foo` is mapped to
`module1::submodule2::foo`.   For parameterized numba types, we treat them as
templated types; for example, `array(int64, 1d, C)` becomes an
`array<int64, 1, C>`.

All mangled names are prefixed with "_Z".  It is followed by the name of the
entity.  A name contains one or more identifiers.  Each identifier is encoded
as "<num of char><name>".   If the name is namespaced and, therefore,
has multiple identifiers, the entire name is encoded as "N<name>E".

For functions, arguments types follow.  There are condensed encodings for basic
built-in types; e.g. "i" for int, "f" for float.  For other types, the
previously mentioned name encoding should be used.

For templated types, the template parameters are encoded immediately after the
name.  If it is namespaced, it should be within the 'N' 'E' marker.  Template
parameters are encoded in "I<params>E", where each parameter is encoded using
the mentioned name encoding scheme.  Template parameters can contain literal
values like the '1' in the array type shown earlier.  There is special encoding
scheme for them to avoid leading digits.
    N)typesz
[^a-z0-9_]_ZvbhatsjiyxDhfdc                     d }t        j                  t        ||       }t        |t              s|j                  d      S |S )aP  Escape the given string so that it only contains ASCII characters
    of [a-zA-Z0-9_$].

    The dollar symbol ($) and other invalid characters are escaped into
    the string sequence of "$xx" where "xx" is the hex codepoint of the char.

    Multibyte characters are encoded into utf8 and converted into the above
    hex format.
    c                 n    dj                  d | j                  d      j                  d      D              S )N c              3   &   K   | ]	  }d |z    yw)z_%02xN ).0chs     b/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/numba/core/itanium_mangler.py	<genexpr>z/_escape_string.<locals>.repl.<locals>.<genexpr>K   s      <  " <s   r   utf8)joingroupencode)ms    r   replz_escape_string.<locals>.replJ   s3    ww <!"!2!26!:< < 	<    ascii)resub_re_invalid_char
isinstancestrr   )textr    rets      r   _escape_stringr*   ?   s:    < &&!4
.Cc3zz'""Jr!   c                 :    | r| d   j                         rd| z   S | S )z%
    Fix text with leading digit
    r   _)isdigit)r(   s    r   _fix_lead_digitr.   T   s#     Q!Tzr!   c                 8    t        |       } dt        |       | fz  S )zo
    Prefix string with digit indicating the length.
    Add underscore if string is prefixed with digits.
    z%u%s)r.   len)strings    r   _len_encodedr2   ^   s"    
 V$FS[&)))r!   abi_tagreturnc                 0    dt        t        |             z   S )NB)r2   r*   )r3   s    r   mangle_abi_tagr7   g   s    nW5666r!   r   abi_tagsuidc                8   |	d| g|}| j                  d      D cg c]  }t        t        |             }}t        t	        t
        |            }|dj                  |      z   }t        |      dkD  rddj                  |      |dS |d   |S c c}w )z
    Mangle the identifier with optional template parameters and abi_tags.

    Note:

    This treats '.' as '::' in C++.
    r   .r      NEr   )splitr2   r*   listmapr7   r   r0   )identtemplate_paramsr9   r:   r   partsenc_abi_tagsextrass           r   mangle_identifierrH   k   s     uI))6;kk#6FG\.+,GEGNH56Lrww|44F
5zA~775>622q6** Hs   Bc                    t        | t        j                        r#| t        v r	t        |    S t	        | j
                   S t        | t              rd| z  S t        | t              rt        |       S t        t        |             }t        |      S )z4
    Mangle type parameter and arbitrary value.
    zLi%dE)r&   r   TypeN2CODEmangle_templated_identmangling_argsintr'   rH   r*   r2   )typencs     r   mangle_type_or_valuerQ      sx    
 #uzz"&=#;)3+<+<==	C	}	C	 %% SX&C  r!   c                 f    |r"ddj                  t        t        |            z  nd}t        | |      S )z&
    Mangle templated identifier.
    zI%sEr   )r   rB   rQ   rH   )
identifier
parametersrD   s      r   rL   rL      s7    
 % ,@*(M NN*, Z99r!   c                 \    dj                  | D cg c]  }t        |       c}      S c c}w )zE
    Mangle sequence of Numba type objects and arbitrary values.
    r   )r   rQ   )argtysr	   s     r   mangle_argsrW      s'     77V<(+<==<s   )c                \    dj                  t        t        | ||      t        |      g      S )zA
    Mangle identifier with Numba type objects and abi-tags.
    r   r8   )r   PREFIXrH   rW   )rC   rV   r9   r:   s       r   manglerZ      s0     77F%ehCH') * *r!   c                    | j                  t              st        d      | j                  t        dz         r| dd }t        dz   t        |      z   |z   }|S | dd }t	        |      \  }}t        dz   t        |      z   |z   dz   |z   }|S )z,
    Prepend namespace to mangled name.
    zinput is not a mangled namer>      N   r?   )
startswithrY   
ValueErrorrH   _split_mangled_ident)mangledns	remainingr)   headtails         r   prepend_namespacerf      s     f%677			FSL	)ABK	sl.r22Y> J ABK	))4
dsl.r22T9C?$FJr!   c                 ^    t        |       }t        t        |            }||z   }| d| | |d fS )zy
    Returns `(head, tail)` where `head` is the `<len> + <name>` encoded
    identifier and `tail` is the remaining.
    N)rN   r0   r'   )ra   ctctlenats       r   r`   r`      s:    
 
WBBLE	B3B<%%r!   )r   )$__doc__r#   
numba.corer   compileIr%   rY   voidbooleanuint8int8uint16int16uint32int32uint64int64float16float32float64rK   r*   r.   r2   r'   r7   rH   rQ   mangle_typemangle_valuerL   rW   rZ   rf   r`   r   r!   r   <module>r~      s  > 
  2::mRTT2 	
 
JJ	MM3	KK	JJ	LL#	KK	LL#	KK	LL#	KK	MM4	MM3	MM3
"**7C 7C 7+RT +(!. ##:> ')d *$&r!   