
    X-Ph                    P    d dl mZ d dlmZ  G d d          ZddZddZddZdS )    )annotations)Iterablec                  $    e Zd ZdZddZdddZdS )NameGeneratora  Utility for generating distinct C names from Python names.

    Since C names can't use '.' (or unicode), some care is required to
    make C names generated from Python names unique. Also, we want to
    avoid generating overly long C names since they make the generated
    code harder to read.

    Note that we don't restrict ourselves to a 32-character distinguishing
    prefix guaranteed by the C standard since all the compilers we care
    about at the moment support longer names without issues.

    For names that are exported in a shared library (not static) use
    exported_name() instead.

    Summary of the approach:

    * Generate a unique name prefix from suffix of fully-qualified
      module name used for static names. If only compiling a single
      module, this can be empty. For example, if the modules are
      'foo.bar' and 'foo.baz', the prefixes can be 'bar_' and 'baz_',
      respectively. If the modules are 'bar.foo' and 'baz.foo', the
      prefixes will be 'bar_foo_' and 'baz_foo_'.

    * Replace '.' in the Python name with '___' in the C name. (And
      replace the unlikely but possible '___' with '___3_'. This
      collides '___' with '.3_', but this is OK because names
      may not start with a digit.)

    The generated should be internal to a build and thus the mapping is
    arbitrary. Just generating names '1', '2', ... would be correct,
    though not very usable.
    groupsIterable[list[str]]returnNonec                    i | _         |D ])}| j                             t          |                     *i | _        t	                      | _        dS )a"  Initialize with a list of modules in each compilation group.

        The names of modules are used to shorten names referring to
        modules, for convenience. Arbitrary module
        names are supported for generated names, but uncompiled modules
        will use long names.
        N)
module_mapupdatemake_module_translation_maptranslationsset
used_names)selfr   namess      M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypyc/namegen.py__init__zNameGenerator.__init__(   sU     +- 	G 	GEO""#>u#E#EFFFF8:$'EE    Nmodulestrpartial_name
str | Nonec                   |-t          | j        |                             d                    S ||f| j        v r| j        ||f         S || j        v r| j        |         }n
|r|dz   }nd}t          | |           }|| j        ||f<   |S )a  Return a C name usable for a static definition.

        Return a distinct result for each (module, partial_name) pair.

        The caller should add a suitable prefix to the name to avoid
        conflicts with other C names. Only ensure that the results of
        this function are unique, not that they aren't overlapping with
        arbitrary names.

        If a name is not specific to any module, the module argument can
        be an empty string.
        N. )exported_namer   rstripr   )r   r   r   module_prefixactuals        r   private_namezNameGenerator.private_name6   s      !8!?!?!D!DEEEL!T%666$V\%9::T_$$ OF3MM 	"SLMMM-???@@28&,./r   )r   r   r	   r
   )N)r   r   r   r   r	   r   )__name__
__module____qualname____doc__r   r"    r   r   r   r      sL         B* * * *      r   r   fullnamer   r	   c                V    |                      dd                               dd          S )zReturn a C name usable for an exported definition.

    This is like private_name(), but the output only depends on the
    'fullname' argument, so the names are distinct across multiple
    builds.
    ______3_r   )replace)r(   s    r   r   r   S   s*     E7++33C???r   r   	list[str]dict[str, str]c                    i }| D ]0}t          |          D ]}|                    |d          dz   ||<   1i }| D ]'}t          |          D ]}||         dk    r n|||<   (|S )Nr      )candidate_suffixesget)r   num_instancesnamesuffixresults        r   r   r   ^   s    $&M E E(.. 	E 	EF$1$5$5fa$@$@1$DM&!!	EF  (.. 	 	FV$)) * tMr   c                    |                      d          }dg}t          t          |                    D ]9}|                    d                    || dz
  d                    dz              :|S )Nr   r   r0   )splitrangelenappendjoin)r(   
componentsr6   is       r   r1   r1   m   sq    $$JTF3z??## < <chhz1"q&((344s:;;;;Mr   N)r(   r   r	   r   )r   r-   r	   r.   )r(   r   r	   r-   )
__future__r   collections.abcr   r   r   r   r1   r'   r   r   <module>rA      s    " " " " " " $ $ $ $ $ $J J J J J J J JZ@ @ @ @        r   