
    Ng*                         d dl mZ ddlmZmZ ddlmZ ddlmZ ddlmZ  G d dej	                  Z
 G d	 d
e          Z G d dej                  ZddZdS )    )absolute_import   )parse_from_stringsStringParseContext)Symtab)Naming)Codec                   ,     e Zd Zd Z fdZddZ xZS )NonManglingModuleScopec                     || _         d | _        |                    dd          | _        t	          j        j        | g|R i | d S )NcppF)prefixcython_scopepopr   r   ModuleScope__init__)selfr   argskws       W/var/www/html/ai-engine/env/lib/python3.11/site-packages/Cython/Compiler/UtilityCode.pyr   zNonManglingModuleScope.__init__   sP     66%''#D64666266666    c                 f    d|_         t          t          |                               |||          S )NT)usedsuperr   add_imported_entry)r   nameentrypos	__class__s       r   r   z)NonManglingModuleScope.add_imported_entry   s.    
+T22EEdESVWWWr   Nc                     |r=|t           j        t           j        t           j        t           j        fv r| j        }||S t          j                            | |          S N)	r   typeobj_prefixfunc_prefix
var_prefixpyfunc_prefixr   r   r   mangle)r   r   r   s      r   r&   zNonManglingModuleScope.mangle   s\     	;&/1CVEVX^Xlmmm #VTT**%,,T6:::r   r!   )__name__
__module____qualname__r   r   r&   __classcell__)r   s   @r   r   r   	   s`        7 7 7X X X X X; ; ; ; ; ; ; ;r   r   c                       e Zd ZdZddZdS )CythonUtilityCodeContextNTFc                     |rt          d          || j        k    r%|| j        vrt          d          | j        |         S | j        #t	          | j        |d | | j                  | _        | j        S )Nz/Relative imports not supported in utility code.z%Only the cython cimport is supported.)parent_modulecontextr   )AssertionErrormodule_namemodulesscoper   r   r   )r   r1   from_moduler   need_pxdabsolute_fallbackrelative_imports          r   find_modulez$CythonUtilityCodeContext.find_module#   s     	T !RSSS$***$,..$%LMMM|K00:/[dPTPXZ Z ZDJ zr   )NNTTF)r'   r(   r)   r3   r8    r   r   r,   r,       s-        E     r   r,   c                   ~    e Zd ZdZdZ	 	 	 ddZd Zd Zd	 ZddZ	d Z
edd            Z	 	 ddZed             ZdS )CythonUtilityCodeaR  
    Utility code written in the Cython language itself.

    The @cname decorator can set the cname for a function, method of cdef class.
    Functions decorated with @cname('c_func_name') get the given cname.

    For cdef classes the rules are as follows:
        obj struct      -> <cname>_obj
        obj type ptr    -> <cname>_type
        methods         -> <class_cname>_<method_cname>

    For methods the cname decorator is optional, but without the decorator the
    methods will not be prototyped. See Cython.Compiler.CythonScope and
    tests/run/cythonscope.pyx for examples.
    T	__pyxutil Nc
                 2   i }
|Qddl m} |                                D ]\  }}t          ||          r
|||<   ||
|<    t	          j        ||||          }|| _        || _        || _        || _	        |pg | _
        || _        |	| _        || _        |
| _        d S )Nr   )BaseType)
PyrexTypesr?   items
isinstancer	   sub_tempitaimplr   filer   requires
from_scopeouter_module_scopecompiler_directivescontext_types)r   rD   r   r   rF   rE   rG   r/   rI   rH   rJ   r?   keyvalues                 r   r   zCythonUtilityCode.__init__F   s     ,,,,,,%mmoo / /
UeX.. /#&GCL).M#&#D'4>>D			 B$"4#6 *r   c                     t          |t                    r*|                                 |                                k    S dS )NF)rB   r;   _equality_params)r   others     r   __eq__zCythonUtilityCode.__eq__a   s=    e.// 	((**e.D.D.F.FFF5r   c                     | j         }t          |t                    r|j        }t          |t                    | j        || j        fS r!   )rH   rB   r   outer_scoperD   rI   )r   rR   s     r   rN   z"CythonUtilityCode._equality_paramsg   sL    -&<== 	2%1K &<== 	2y+t'???r   c                 *    t          | j                  S r!   )hashrD   )r   s    r   __hash__zCythonUtilityCode.__hash__m   s    DIr   Fc                 "    ddl m} |g}ddlm}m} t           j         j        |r|                                nd          } j	        |_	        ||_
        t           j         j        |dd          }|                    |d|	          }	|r5g }
|	D ].}|
                    |           t          ||j                  r n/|
}	|                    |          }|j        }|                    |	||
          }	d } j        r+|                    |	 | j                  |j        
          }	 j        D ]Y}t          |t,                    rBt/          |d          r2|s0|                    |	 ||j        j                  |j        
          }	Z j        r" fd}|                    |	||j        
          }	 j        r" fd}|                    |	||j        
          }	|                    |	|d          \  }}|r
J |            | _        |S )Nr   )AutoTestDictTransform)PipelineParseTreeTransformsF)rI   r   T)r/   allow_struct_enum_decoratorin_utility_codepyx)exclude_classes)beforec                       fd}|S )Nc                 <    | j                                        | S r!   )r3   merge_in)module_noder3   s    r   merge_scope_transformzNCythonUtilityCode.get_tree.<locals>.merge_scope.<locals>.merge_scope_transform   s     !**5111""r   r9   )r3   rc   s   ` r   merge_scopez/CythonUtilityCode.get_tree.<locals>.merge_scope   s$    # # # # # )(r   treec                 *    j         | j        _        | S r!   )rH   r3   rR   )rb   r   s    r   scope_transformz3CythonUtilityCode.get_tree.<locals>.scope_transform   s    040G!-""r   c                     t                      }j                                        D ]F\  }}t          |d|          }| j                            ||d d          }||ur||_        d|_        G| S )Nr   extern)
visibilityT)objectrJ   rA   getattrr3   declare_typer   in_cinclude)rb   dummy_entryr   typeold_type_entryr   r   s         r   rg   z3CythonUtilityCode.get_tree.<locals>.scope_transform   s    $hh"&"4":":"<"< - -JD$ &-T7K%H%HN'-::4tX`:aaE%[88%3
(,E%%""r   )	printtree)AnalysedTreeTransformsrW   r=   rX   rY   r,   r   rI   is_cppr   r   r   rD   create_pipelineappendrB   AnalyseDeclarationsTransformCnameDirectivesTransformInterpretCompilerDirectivesinsert_into_pipelinerG   rF   r;   hasattrre   r3   rH   rJ   run_pipeline)r   entries_onlyr   rW   excludesrX   rY   r/   re   pipelinept	transformr^   rd   deprg   errs   `                 r   get_treezCythonUtilityCode.get_treep   s   AAAAAA **33333333*I4+C)5@##%%%5B B B +!Ity't " " " ++GUH+UU 	A  a!4!QRR E H'@@II	 %@0098> 1 @ @	) 	) 	) ? 	I44++do66*G 5 I IH = 	M 	MC#011 Mgc66J6J MS_ M#88kk#(.99.K 9 M M " 	I# # # # #  44/*G 5 I IH  	I# # # # #  44/*G 5 I IH ++Hde+LLd	r   c                     d S r!   r9   )r   outputs     r   put_codezCythonUtilityCode.put_code   s    r   c                 <     | j         ||fi |}|j        |j        fS )zR
        Load a utility code as a string. Returns (proto, implementation)
        )loadprotorD   )clsutil_code_name	from_filekwargsutils        r   load_as_stringz CythonUtilityCode.load_as_string   s.    
 sx	<<V<<z49$$r   c                    |                      d|          }|j        j        }|                    d           |                    d           |                    d           |                    d           |                                D ]}| |_        ||_        |j        }|                    |d|           ||_        | j        D ] }	|	j	        r|	
                    ||           !|S )	z
        Declare all entries from the utility code in dest_scope. Code will only
        be included for used entries. If module_name is given, declare the
        type entries with that name.
        T)r}   r   r'   __file____builtins____doc__)merge_unused	allowlist)r   )r   r3   entriesr   valuesutility_code_definitionr   ra   rF   is_cython_utilitydeclare_in_scope)
r   
dest_scoper   r   r   re   r   r   original_scoper   s
             r   r   z"CythonUtilityCode.declare_in_scope   s     }}$\}JJ*$JJN###I^^%% 	 	E,0E)EJJNSSS
= 	L 	LC$ L$$Zl$KKKr   c                 \    ddl m} t          |          }d}|D ]}|| v r| |         ||<   |S )a   
        Cython utility code should usually only pick up a few directives from the
        environment (those that intentionally control its function) and ignore most
        other compiler directives. This function provides a sensible default list
        of directives to copy.
        r   )_directive_defaults)bindingalways_allow_keywordsallow_none_for_extension_argsauto_pickleccomplexc_string_typec_string_encodingzoptimize.inline_defnode_callszoptimize.unpack_method_callsz&optimize.unpack_method_calls_in_pyinitzoptimize.use_switch)Optionsr   dict)current_directivesr   utility_code_directivesinherited_directive_namesr   s        r   filter_inherited_directivesz-CythonUtilityCode.filter_inherited_directives   sd     	100000"&':";";%M! . 	I 	ID)))0B40H'-&&r   )r<   r=   NNNNNN)FNr!   )FNN)r'   r(   r)   r   r   r   rP   rN   rU   r   r   classmethodr   r   staticmethodr   r9   r   r   r;   r;   3   s           CGOS$(+ + + +6  @ @ @  T T T Tl   % % % [% EI#'   : ' ' \' ' 'r   r;   Tc                 L    t          | g|R i |                    |           dS )z`
    Declare some declarations given as Cython code in declaration_string
    in scope env.
    N)r;   r   )declaration_stringenvprivate_typer   r   s        r   declare_declarations_in_scoper     s7     (:4:::6::KKCPPPPPr   N)T)
__future__r   TreeFragmentr   r   r=   r   r   r	   r   r   r,   UtilityCodeBaser;   r   r9   r   r   <module>r      s   & & & & & & @ @ @ @ @ @ @ @                  ; ; ; ; ;V/ ; ; ;.    1   &N' N' N' N' N', N' N' N'bQ Q Q Q Q Qr   