o
    j	                    @   s:  d dl Z e jdi dededededededed	ed
edededededededededededededededededededededed ed!ed"ed#ed$ed%ed&ed'ed(ed)e d dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d d*lmZ d+d,lmZmZmZmZmZmZmZmZ d+d-lmZmZ d+d.lmZ d+d/lmZ d+d0lmZ d+d1lmZ d+d2lmZm Z  d+d3lm!Z! d+d4l!m"Z"m#Z#m$Z$m%Z%m&Z& d+d5lm'Z' d+d6l(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z3m4Z4 d+d7lm(Z( d+d8lm5Z5 d9d:lm6Z6 d+d;l7m8Z8 d+d<lm9Z9 d9d=l:m;Z; d+d>l<m=Z=m>Z> d+d?l?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZN d+d@l!mOZO ePeQfZRG dAdB dBZSeS ZTe ZUdCdD ZVe.e/fdEe.e!j"fdFe.e!jWfdFe.e!jXfdFe.e!jYfdFe/e.fdGe/e!jZfdHe/e!j[fdHe!j"e.fdIe!jWe.fdIe!jXe.fdIe!jYe.fdIeVe!\ dJeVe!] dKiZ^dLd Z_dMdN Z`dOdP ZaddQdRZbdSdT ZcdUdV ZddWdX ZedYdZ Zfd[d\ Zgd]d^ ZhG d_d` d`eZiG dadb dbeiZjG dcdd ddeiZkG dedf dfekZlG dgdh dhelZmG didj djelZnG dkdl dlekZoG dmdn dneoZpG dodp dpeoZqG dqdr dreoZrG dsdt dteoZsG dudv dveoZtdwdx ZuG dydz dzeoZvG d{d| d|eoZwG d}d~ d~ewZxG dd dekZyG dd dekZzG dd dekZ{G dd deiZ|G dd deiZ}G dd deiZ~G dd de~ZG dd deiZG dd dekZG dd de~ZG dd dekZG dd deiejZG dd dekZG dd deiZG dd deZG dd deiZG dd deiZG dd deiZG dd dekZG dd dekZG dd deiZG dd deZG dd deZG dd deZG dd deZG dd deiZG dd deZG dd deZG dd deiZG dd deiZG dd deZG dd deiZG dd deZG dd deiZG ddĄ deZG ddƄ deZG ddȄ deiZG ddʄ deZG dd̄ deZG dd΄ deZG ddЄ deiZG dd҄ deiZG ddԄ deiZG ddք deiZG dd؄ deiZG ddڄ deZG dd܄ deZG ddބ de~ZG dd deZG dd deZG dd deiZG dd deiZG dd deiZG dd deiZG dd deiZG dd deiZG dd dejZG dd dZG dd deieZG dd deiZG dd deiZG dd deieZG dd deiZG dd deiZG dd  d eieZG dd deZG dd dZG dd deiZG dd deiZG d	d
 d
eiZG dd deZG dd deZG dd deZG dd deZG dd deiZG dd deăZG dd deŃZG dd deŃZG dd deǃZG dd dekZG dd  d eZG d!d" d"eZG d#d$ d$ekZ̐d%d& Zejejejejѐd'ZG d(d) d)eiZG d*d+ d+eӃZG d,d- d-eӃZG d.d/ d/eӃZG d0d1 d1eӃZG d2d3 d3eӃZG d4d5 d5e؃ZG d6d7 d7e؃Zڐd8d9 ZG d:d; d;e؃Zeeeאd<Zݐd=d> ZG d?d@ d@eiZߐdAZdBZdCZdDZdEZG dFdG dGeiZG dHdI dIeiZG dJdK dKeZG dLdM dMeZG dNdO dOeiZG dPdQ dQeiZzejZW n ey8   dRdS ZY nw i dTejdUejdVejdWejdXejdYejdZejd[ejd\ejd]ejd^ejd_ejd`ejdaejdbejdcejddejejej ejededf dgdf dhZdidj ZG dkdl dleiZG dmdn dneZdodp ZG dqdr dreZG dsdt dteZG dudv dveZ	G dwdx dxeZ
G dydz dzeZG d{d| d|eZG d}d~ d~eZG dd deZe	djZeh dZG dd deZG dd deZG dd deiZG dd deiZG dd deiZdddddddddd	ZG dd dZG dd deieZG dd deeZeee	eeeee
eeeeeeedZdАddZG dd deiZG dd deZ G dd deZ!G dd deZ"G dd dejZ#G dd deZ$G dd de$Z%G dd deZ&G dd deZ'G dd de'Z(G dd deZ)dd Z*G dd deZ+G dd deZ,G dd deZ-G dd deZ.G dd de-Z/G dd deiZ0G ddÄ deiZ1G dĐdń deiZ2G dƐdǄ deiZ3G dȐdɄ deiZ4G dʐd˄ deiZ5G d̐d̈́ deiZ6dS (      NerrorwarningZ	warn_onceInternalErrorCompileErrorUtilityCodeTempitaUtilityCodeStringEncodingoperatorlocal_errorsreport_errorNamingNodes
PyrexTypespy_object_type	list_type
tuple_typeset_type	dict_typeunicode_type
bytes_type	type_typeBuiltinSymtabUtilsfind_coercion_errordebug_disposal_codeZdebug_temp_allocdebug_coercionbytearray_type
slice_typememoryview_typebuiltin_sequence_typesbuild_line_tableinspectcopyospathlibresys)Optional   )r   r   r   r   r   r
   CannotSpecializeperformance_hint)r   r   )r!   )r   )r   )r   )NodeSingleAssignmentNode)r   )c_char_ptr_typer   typecast
error_typeunspecified_type)	TypeSlots)r   r   r   r   r   r   r   r   r   sequence_typesr   )r   )r      )r   )AnnotationItem)Future)print_call_chain)r   r   )
to_pythranis_pythran_supported_type#is_pythran_supported_operation_typeis_pythran_exprpythran_func_typepythran_binop_typepythran_unaryop_typehas_np_pythranpythran_indexing_codepythran_indexing_type!is_pythran_supported_node_or_nonepythran_typepythran_is_numpy_func_supportedpythran_get_func_include_filepythran_functor)PythranExprc                       (   e Zd ZdZ fddZdd Z  ZS )NotConstantNc                    s   t jd u rt | t _t jS N)rI   _objsuper__new__)cls	__class__ Z/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/Cython/Compiler/ExprNodes.pyrM   C   s   
zNotConstant.__new__c                 C      dS )Nz<NOT CONSTANT>rQ   selfrQ   rQ   rR   __repr__I      zNotConstant.__repr__)__name__
__module____qualname__rK   rM   rV   __classcell__rQ   rQ   rO   rR   rI   @   s    rI   c                 C   s   | | fS rJ   rQ   )tprQ   rQ   rR   _type_to_itselfO      r]   zGCannot convert Unicode string to 'bytes' implicitly, encoding required.z5Unicode objects only support coercion to Py_UNICODE*.zBCannot convert 'bytes' object to str implicitly, decoding requiredz8Cannot convert 'bytes' object to Py_UNICODE*, use 'str'.z?Cannot convert 'char*' to unicode implicitly, decoding requiredzcython.pymutex cannot be copiedz*cython.pythread_type_lock cannot be copiedc                    sx   t  }|d u r|S |jd r:t fddtjtjtjtjfD r: d j	r*|S |jd dv r3|S d d j
 S |S )Nc_string_encodingc                 3   s    | ]}| v V  qd S rJ   rQ   .0t
type_tuplerQ   rR   	<genexpr>o       z&find_coercion_error.<locals>.<genexpr>r)   )asciiutf8z\'%s' objects do not support coercion to C types with non-ascii or non-utf8 c_string_encodingr   )coercion_error_dictget
directivesanyr   r.   c_uchar_ptr_typec_const_char_ptr_typec_const_uchar_ptr_typeis_pyobjectname)rd   defaultenverrrQ   rc   rR   r   j   s   


c                 C   s   t tttd| jd S )N)bytes	bytearraystrunicodeZc_string_type)r   r   r   rj   rk   rs   rQ   rQ   rR   default_str_type{   s   rz   c                  G   sB   | D ]}|du st |jttfsq|jdk rt|jddd qdS )z
    Raise a warning on nodes that are known to have negative numeric values.
    Used to find (potential) bugs inside of "wraparound=False" sections.
    Nr   zfthe result of using negative indices inside of code sections marked as 'wraparound=False' is undefinedr)   level)
isinstanceconstant_resultintfloatr   pos)nodesnoderQ   rQ   rR   check_negative_indices   s   
r   c           	   
      sb  |j s,|d u r| }|tu r,|jr,t|jdkr,z|jd j}W n	 ty+   Y nw |j rQ|d urQ| rQz|j|j	 }W n t
ttfyK   Y nw | S |j sW|jrdd |jD }t|t|jk } fdd|D }d |v rwd S dd |D }t|dkr| }|r|js|j}|S |s|ttfv rtdd	 |D r|tu rtjntj}|S d S )
Nr)   r   c                 S   s   g | ]}|j s|qS rQ   )is_nonera   itemrQ   rQ   rR   
<listcomp>       z,infer_sequence_item_type.<locals>.<listcomp>c                    s&   h | ]}|j rt |n| qS rQ   )
is_starredinfer_sequence_item_type
infer_typer   ry   rQ   rR   	<setcomp>   s    z+infer_sequence_item_type.<locals>.<setcomp>c                 S   s"   h | ]}|j r|jr|jn|qS rQ   )rp   equivalent_type)ra   	item_typerQ   rQ   rR   r      s    c                 s   s    | ]
}|j o
| V  qd S rJ   )is_string_literalcan_coerce_to_char_literalra   argrQ   rQ   rR   re      s    z+infer_sequence_item_type.<locals>.<genexpr>)is_sequence_constructorr   r   cf_statelenrhsAttributeErrorhas_constant_resultargsr~   
ValueError	TypeError
IndexErroris_set_literalpoprp   r   r   r   allr   c_py_ucs4_typec_uchar_type)	rs   Zseq_node
index_nodeseq_typer   Zargs_without_noneZhas_none
item_typesr   rQ   ry   rR   r      sN   



r   c                 C   s&   dd |D }d|v rdS | t |fS )a  
    Recursively generate a deduplication key from a sequence of values.
    Includes Cython node types to work around the fact that (1, 2.0) == (1.0, 2), for example.

    @param outer_type: The type of the outer container.
    @param item_nodes: A sequence of constant nodes that will be traversed recursively.
    @return: A tuple that can be used as a dict key for deduplication.
    c                 S   s   g | ]F}|d u rt d td fn8|jr"t|j|jr|jnd g|j n%|jr1t|j|j|j	|j
fn| rF|j|j|jt u rCt|jnd fnd qS rJ   )r   typer   make_dedup_key
is_literalmult_factorr   is_slicestartstopstepr   r~   ra   r   rQ   rQ   rR   r      s    	&
z"make_dedup_key.<locals>.<listcomp>N)tuple)Z
outer_typeZ
item_nodesZ	item_keysrQ   rQ   rR   r      s   		r   c                 C   sV   | d u rdS | j tjkr| jdkrdS | j jr#d| jj| jjf dfS d| jj dfS )N)__Pyx_CppExn2PyErr();F*)r   Tztry { throw; } catch(const std::exception& exn) {PyErr_SetString((PyObject*)%s, exn.what());} catch(...) { PyErr_SetNone((PyObject*)%s); }Fzc%s(); if (!PyErr_Occurred())PyErr_SetString(PyExc_RuntimeError, "Error converting c++ exception.");)r   r   c_char_typevaluerp   entrycname)exception_valuerQ   rQ   rR   get_exception_handler   s$   
	r   c                 C   sL   |r$|r| j tdd | | d| d S | | d| d S d S )NErrOccurredWithGILExceptions.c__Pyx_ErrOccurredWithGIL()PyErr_Occurred())globalstateuse_utility_coder   load_cachedputlnerror_goto_if)codecheck_py_exceptionr   nogilrQ   rQ   rR   maybe_check_py_error   s   
r   c                 C   s   t |\}}| d | d|  |r| | || t| ||| | d |r1| jdd | | |r<|   | | | | d d S )Ntry {z%s} catch(...) {TZdeclare_gilstate})r   r   error_goto_if_nullr   put_ensure_gilput_release_ensured_gil
error_goto)r   r   Zinside	py_resultr   r   Zraise_py_exceptionr   rQ   rQ   rR   translate_cpp_exception   s   


r   c                 C   sH   | j dksJ | jd u rdS | jjrdS t| jtr"| jjdkr"dS dS )N+TFr   )exception_checkr   is_namer}   CharNoder   )r   rQ   rQ   rR   needs_cpp_exception_conversion  s   
r   c                 C   s  t |\}}	t |\}
}| d | |d|  t| |	|| | d | d|  t| ||| | d |rB| jdd | |
 |rM|   | | | | d | d |rg| jdd | | |rr|   | | | | d d S )Nr   z__pyx_local_lvalue = %s;r   Tr   r   )r   r   declaration_coder   r   r   r   )r   r   lhs_typeZlhs_coderhs_codeZlhs_exc_valZassign_exc_valr   Zhandle_lhs_excZlhc_check_py_excZhandle_assignment_excZassignment_check_py_excrQ   rQ   rR   translate_double_cpp_exception!  s0   






r   c                   @   sr  e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZeZe j!j"dkrKe#e$%ddZ&ne#dd Z&d	d
 Z'dd Z(dd Z)dd Z*dd Z+dd Z,dd Z-dddZ.dd Z/dd Z0dddZ1dd  Z2dd!d"Z3d#d$ Z4d%d& Z5d'd( Z6d)d* Z7d+d, Z8d-d. Z9d/d0 Z:d1d2 Z;d3e<fd4d5Z=d6d7 Z>d8d9 Z?d:d; Z@d<d= ZAd>d? ZBd@dA ZCdBdC ZDdDdE ZEdFdG ZFdHdI ZGddKdLZHdMdN ZIdOdP ZJdQdR ZKdSdT ZLdUdV ZMdWdX ZNdYdZ ZOd[d\ ZPd]d^ ZQd_d` ZRdadb ZSdcdd ZTdedf ZUdgdh ZVdidj ZWdkdl ZXdmdn ZYdodp ZZdqdr Z[dsdt Z\dudv Z]dwdx Z^dydz Z_d{d| Z`d}d~ Za		dddZbdddZcdd Zddd Zedd Zfdd Zgdd Zh		dddZidd Zjdd Zkdd Zldd Zmdd Zndd ZodddZpdd Zqdd Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd ZydddZze{dd Z|dd Z}dS )ExprNodeNTFcpythonsubexprs)fgetc                 C      | j S rJ   )r   rT   rQ   rQ   rR   child_attrs  s   zExprNode.child_attrsc                 C      d S rJ   rQ   rU   rs   rQ   rQ   rR   analyse_annotations  rW   zExprNode.analyse_annotationsc                 C   s   t |d td| jj|f )Nznot implementedz%s.%s not implemented)r7   r   rP   rX   )rU   method_namerQ   rQ   rR   not_implemented  s   
zExprNode.not_implementedc                 C   rS   Nr   rQ   rT   rQ   rQ   rR   	is_lvalue  rW   zExprNode.is_lvaluec                 C   s   |   o| jj S rJ   )r   r   is_memoryviewslicerT   rQ   rQ   rR   is_addressable     zExprNode.is_addressablec                 C   s   | j jo| jS rJ   )r   rp   is_temprT   rQ   rQ   rR   is_ephemeral  s   zExprNode.is_ephemeralc                 C   sH   g }| j D ]}t| |}|d ur!t|tu r|| q|| q|S rJ   )r   getattrr   listextendappend)rU   r   rq   r   rQ   rQ   rR   subexpr_nodes  s   


zExprNode.subexpr_nodesc                 C   s   | j r| jS |  S rJ   )r   	temp_codecalculate_result_coderT   rQ   rQ   rR   result  s   zExprNode.resultc                 C   s<   |r| j r| jjr| jjr|S d| _d|rd|S d|S )NTz{}({})Z__PYX_STD_MOVE_IF_SUPPORTEDz	std::move)r   r   is_cpp_classis_referencehas_temp_movedformatrU   r   optionalrQ   rQ   rR   _make_move_result_rhs  s   zExprNode._make_move_result_rhsc                 C   s   | j |  ddS )NTr   )r   r   rT   rQ   rQ   rR   move_result_rhs  r   zExprNode.move_result_rhsc                 C   s6   |  |}|js|js|jo| j}| j|| d}|S )Nr   )	result_asr   Zneeds_refcountingZis_rvalue_referencer   r   )rU   r   r   Zrequires_moverQ   rQ   rR   move_result_rhs_as  s
   
zExprNode.move_result_rhs_asc                 C   s&   t | rt| S |d usJ t| |S rJ   )rB   r8   )rU   type_rQ   rQ   rR   pythran_result%  s   
zExprNode.pythran_resultc                 C   rS   )zZ
        Subtypes may return False here if result temp allocation can be skipped.
        TrQ   rT   rQ   rQ   rR   is_c_result_required,     zExprNode.is_c_result_requiredc                 C   s:   | j r| jjr|tkrt|t|  S t||  |  S rJ   )r   r   rp   r   r/   r   ctyperU   r   rQ   rQ   rR   r   2  s   zExprNode.result_asc                 C   s
   |  tS rJ   )r   r   rT   rQ   rQ   rR   r   ;     
zExprNode.py_resultc                 C   s   | j p| jS rJ   )result_ctyper   rT   rQ   rQ   rR   r  ?     zExprNode.ctypec                 C   r   rJ   rQ   rT   rQ   rQ   rR   get_constant_c_result_codeD  s   	z#ExprNode.get_constant_c_result_codec                 C   r   rJ   rQ   rT   rQ   rQ   rR   calculate_constant_resultO  s   
z"ExprNode.calculate_constant_resultc                 C      | j tuo	| j tuS rJ   r~   constant_value_not_setnot_a_constantrT   rQ   rQ   rR   r   [     
zExprNode.has_constant_resultc                 C      t | jd d S )NzInvalid compile-time expressionr   r   rU   denvrQ   rQ   rR   compile_time_value_     zExprNode.compile_time_valuec                 C   s   t | jd|jj|f  d S )Nz(Error in compile-time expression: %s: %s)r   r   rP   rX   )rU   erQ   rQ   rR   compile_time_value_errorc  s   z!ExprNode.compile_time_value_errorc                 C   sD   |   }|du rt| jd dS |  r| jn|}tj||| jS )z
        Returns a PyrexTypes.CFuncType.ExceptionValue (or None)

        The python_value attribute of the result can be either a Python constant
        or a string for types that can't be represented by a Python constant
        (e.g. enums)
        Nz Exception value must be constant)	r  r   r   r   r~   r   	CFuncTypeZExceptionValuer   )rU   rs   Zc_resultr   rQ   rQ   rR   as_exception_valueg  s   zExprNode.as_exception_valuereturnc                 C   sZ   | j rdS | jr
dS t| dr| jd u rdS | jjrdS | jjjr+| jjs+| jjs+dS dS )NZ&__Pyx_ReferenceSharing_SharedReferenceZ)__Pyx_ReferenceSharing_OwnStrongReferencer   Z'__Pyx_ReferenceSharing_FunctionArgument)	in_parallel_blockr   hasattrr   is_argscopeZis_local_scope
in_closurefrom_closurerT   rQ   rQ   rR   may_be_unsafe_sharedy  s   
zExprNode.may_be_unsafe_sharedc                 C   r  )NzCannot assign to or delete thisr  r   rQ   rQ   rR   analyse_target_declaration     z#ExprNode.analyse_target_declarationc                 C   r  )Nz=Cannot use anything except a name in an assignment expressionr  r   rQ   rQ   rR   0analyse_assignment_expression_target_declaration  r   z9ExprNode.analyse_assignment_expression_target_declarationc                 C   s   |  |}|  |S rJ   )analyse_typescheck_constrU   rs   r   rQ   rQ   rR   analyse_const_expression  s   
z!ExprNode.analyse_const_expressionc                 C   
   |  |S rJ   r"  r   rQ   rQ   rR   analyse_expressions     
zExprNode.analyse_expressionsc                 C   r&  rJ   )analyse_target_typesrU   rs   r   rQ   rQ   rR   analyse_target_expression  r)  z"ExprNode.analyse_target_expressionc                 C   s   |  |}||}|S rJ   )r"  coerce_to_boolean)rU   rs   r   boolrQ   rQ   rR   analyse_boolean_expression  s   

z#ExprNode.analyse_boolean_expressionc                 C   s   |  |}|||S rJ   )r"  r-  coerce_to_simpler$  rQ   rQ   rR   analyse_temp_boolean_expression  s   
z(ExprNode.analyse_temp_boolean_expressionc                    s0   t | dd d ur
dS t fdd|  D dS )Nr   rQ   c                       g | ]}|  qS rQ   )type_dependenciesr   ry   rQ   rR   r     r   z.ExprNode.type_dependencies.<locals>.<listcomp>)r   sumr   r   rQ   ry   rR   r3    s   zExprNode.type_dependenciesc                 C   s@   t | dd }|d ur|S t | dd }|d ur|jS | d d S )Nr   r   r   )r   r   r   rU   rs   r   r   rQ   rQ   rR   r     s   zExprNode.infer_typec                 C   s   | j p| jp| jjp| jjS rJ   )r   r   r   is_arrayis_cfunctionrT   rQ   rQ   rR   nonlocally_immutable  s   zExprNode.nonlocally_immutabler   c                 C   s   t | j| t| j|dS )z
        Return a node that represents the (type) result of an indexing operation,
        e.g. for tuple unpacking or iteration.
        baseindex)	IndexNoder   IntNodefor_sizerU   r;  rQ   rQ   rR   inferable_item_node  s   zExprNode.inferable_item_nodec                 C   r   rJ   rQ   r   rQ   rQ   rR   analyse_as_module     zExprNode.analyse_as_modulec                 C   r   rJ   rQ   r   rQ   rQ   rR   analyse_as_type  rB  zExprNode.analyse_as_typec                 C   sV   |  |}|r|jr|jrz||jW S  ty   Y nw |r)|jr)t| jd |S )NzType is not specific)rC  is_fusedfused_to_specific
specializeKeyErrorr   r   )rU   rs   r   rQ   rQ   rR   analyse_as_specialized_type  s   

z$ExprNode.analyse_as_specialized_typec                 C   r   rJ   rQ   r   rQ   rQ   rR   analyse_as_extension_type  rB  z"ExprNode.analyse_as_extension_typec                 C      |  d d S )Nr"  r   r   rQ   rQ   rR   r"        zExprNode.analyse_typesc                 C   r&  rJ   r'  r   rQ   rQ   rR   r*       
zExprNode.analyse_target_typesc                 C   s"   | j r| j jr|   d S d S d S rJ   )r   rp   	gil_errorr   rQ   rQ   rR   nogil_check  s   zExprNode.nogil_checkc                 C   s&   |j r| jjrt| jd d S d S d S )Nz3Assignment of Python object not allowed without gil)r   r   rp   r   r   r   rQ   rQ   rR   gil_assignment_check  s   zExprNode.gil_assignment_checkc                 C      |    dS NF)	not_constrT   rQ   rQ   rR   r#       zExprNode.check_constc                 C   r  )Nz$Not allowed in a constant expressionr  rT   rQ   rQ   rR   rS    r   zExprNode.not_constc                 C   rQ  rR  )addr_not_constrT   rQ   rQ   rR   check_const_addr  rT  zExprNode.check_const_addrc                 C   r  )NzAddress is not constantr  rT   rQ   rQ   rR   rU    r   zExprNode.addr_not_constc                 C   r   rJ   r   rT   rQ   rQ   rR   result_in_temp!  s   zExprNode.result_in_tempc                 C      |   S rJ   r   rT   rQ   rQ   rR   target_code*     zExprNode.target_codec                 C   rJ  )Nr   rK  rT   rQ   rQ   rR   r   .  rL  zExprNode.calculate_result_codec                 C   sv   | j rtd| jj| jf | j}|js6|jrtj	}n| j
s*|js*|  s*d | _ d S |jj|| jd| _ d S d | _ d S )Nz'Temp allocated multiple times in %r: %r
manage_ref)r   RuntimeErrorrP   rX   r   r   is_voidrp   r   r   result_is_usedr   r   	funcstateallocate_tempuse_managed_ref)rU   r   r   rQ   rQ   rR   allocate_temp_result5  s   
zExprNode.allocate_temp_resultc                 C   s   | j s9| jsd S | jrtj| jd  f| jdd   nd}| jr/td| j| j	j
|f td| j	j
|f |j| j  | j | _d | _ d S )Nr   r)   z(?)z+temp %s released multiple times in %s at %rz*no temp, but release requested in %s at %r)r   ra  r   r$   pathbasenameget_descriptionold_tempr_  rP   rX   rb  release_temp)rU   r   r   rQ   rQ   rR   release_temp_resultD  s   0
zExprNode.release_temp_resultc                 C   s$   |   s||  |   dS dS )z|
        Make sure we own a reference to result.
        If the result is in a temp, it is already a new reference.
        N)rX  
put_increfr   r  rU   r   rQ   rQ   rR   make_owned_referenceV  s   zExprNode.make_owned_referencec                 C   s*   |   s|j|  | j| j d dS dS )zJ
        Make sure we own the reference to this memoryview slice.
        have_gilN)rX  put_incref_memoryviewslicer   r   in_nogil_contextrm  rQ   rQ   rR   make_owned_memoryviewslice^  s
   
z#ExprNode.make_owned_memoryviewslicec                 C   sj   |  | || j | jr| | | | | jr/| jjs1| jjs3| 	| | 
| d S d S d S d S rJ   ) generate_subexpr_evaluation_codemark_posr   r   re  generate_result_coder   	is_stringis_pyunicode_ptrgenerate_subexpr_disposal_codefree_subexpr_tempsrm  rQ   rQ   rR   generate_evaluation_codeg  s   



z!ExprNode.generate_evaluation_codec                 C      |   D ]}|| qd S rJ   )r   r{  rU   r   r   rQ   rQ   rR   rt  x     z)ExprNode.generate_subexpr_evaluation_codec                 C   rJ  )Nrv  rK  rm  rQ   rQ   rR   rv  |  rL  zExprNode.generate_result_codec                 C   s~   | j r|jtdd | jr8| jjs| jjr"| 	| | 
| |  r6|j|  |  | j d d S d S | 	| d S )NMoveIfSupportedCppSupport.cppro  )r   r   r   r   r   r   r   rw  rx  ry  rz  r   put_decref_clearr  rr  rm  rQ   rQ   rR   generate_disposal_code  s   



zExprNode.generate_disposal_codec                 C   r|  rJ   )r   r  r}  rQ   rQ   rR   ry    s   z'ExprNode.generate_subexpr_disposal_codec                 C   s   | j rK| jjs| jjr| | | | n$| jjr$|d|    n| jj	r:|d|    |d|    | j
rI|jtdd d S d S | | d S )N%s = 0;z%s.memview = NULL;z%s.data = NULL;r  r  )r   r   rw  rx  ry  rz  rp   r   r   r   r   r   r   r   r   rm  rQ   rQ   rR   generate_post_assignment_code  s   

z&ExprNode.generate_post_assignment_codec                 C   r   rJ   rQ   )rU   r   r   overloaded_assignmentr   r   rQ   rQ   rR   generate_assignment_code     z!ExprNode.generate_assignment_codec                 C   r   rJ   rQ   rU   r   ignore_nonexistingrQ   rQ   rR   generate_deletion_code  r   zExprNode.generate_deletion_codec                 C   s.   | j r| jjs| | d S d S | | d S rJ   )r   r   r`  rk  rz  rm  rQ   rQ   rR   
free_temps  s
   zExprNode.free_tempsc                 C   r|  rJ   )r   r  )rU   r   subrQ   rQ   rR   rz    r~  zExprNode.free_subexpr_tempsc                 C   r   rJ   rQ   rU   rs   r   rQ   rQ   rR   generate_function_definitions  rW   z&ExprNode.generate_function_definitionsc                 C      | |  |  | d S rJ   )put_decref_setr   r  rU   r   r   rQ   rQ   rR   generate_decref_set     zExprNode.generate_decref_setc                 C   r  rJ   )Zput_xdecref_setr   r  r  rQ   rQ   rR   generate_xdecref_set  r  zExprNode.generate_xdecref_setc                 C   sB   |r| j s|r| jr|r| | d S ||  |   d S d S rJ   )
cf_is_nullcf_maybe_nullgenerate_xgotref
put_gotrefr   r  )rU   r   handle_nullmaybe_null_extra_checkrQ   rQ   rR   generate_gotref  s   

zExprNode.generate_gotrefc                 C      | |  |   d S rJ   )put_xgotrefr   r  rm  rQ   rQ   rR   r       zExprNode.generate_xgotrefc                 C   r  rJ   )put_giverefr   r  rm  rQ   rQ   rR   generate_giveref  r  zExprNode.generate_giverefc                 C   r  rJ   )put_xgiverefr   r  rm  rQ   rQ   rR   generate_xgiveref  r  zExprNode.generate_xgiverefc                 C   r|  rJ   )r   annotater}  rQ   rQ   rR   r    r~  zExprNode.annotatec                 C   s  | }| j }| ||r| S |j}|r|js|j}|jr|j}|js$|jrm|jrP|jsP|jrP|j	jrP|j	}|
 D ]}||rO||_ |j j|_d|j_|   S q8|jrZt| jd n|jrb|jrb| S t| jd t| _ | S | jd urt| jd| jd}||| |jrddlm} |j js|j jrt|||}|S |j jrt||||}|S |jst| jd|f  |S |j jrd|_|j j|| j | j!d	s|j j"|j"rd
}	|j |f}
n	d}	|j j"|j"f}
t| j|	|
  |S |jrB|j#r	 |S |j$d u rt%|j||}|S |j jr|j &|st'|||}|S |t(u r,|j j)r,t*||}nt+|||d}|j &|s@t'|||}|S t,|rOt-|j rO|S t,|j ret-|r\|S t+|||d}|S |j jr|ry|j.ryt/| jd|  t0|||}|S |j1r||kr|2|rt3|||}|S |t4j5u r||kr|2|st6|||}|S |j |kst7|j t7|ks|2|s| 8| |S )NTzType is not specializedz/Cannot coerce to a type that is not specialized )rq   r   r)   
MemoryViewz&Cannot convert '%s' to memoryviewslice)	broadcastZcopyingz3Memoryview '%s' not conformable to memoryview '%s'.z-Different base types for memoryviews (%s, %s)r   zTCannot pass Python object as C++ data structure reference (%s &), will pass by copy.)9r   check_for_coercion_errorr   ref_base_typeis_cv_qualifiedcv_base_typerD  r7  is_ptr	base_type"get_all_specialized_function_typessame_asr   usedr   r   Zis_null_ptrr0   coercion_typeNameNode	coerce_tor   r  r  rp   CoerceToMemViewSliceNoder6  CythonArrayNodefrom_carrayis_errorwritable_neededZconforms_tois_memview_broadcastis_memview_copy_assignmentdtyper   r~   NoneNode
subtype_ofPyTypeTestNoder   is_intCoerceIntToBytesNodeCoerceToPyTypeNoder;   r9   r   r   CoerceFromPyTypeNode
is_complexassignable_fromCoerceToComplexNoder   soft_complex_typecoerce_from_soft_complexrw   fail_assignment)rU   dst_typers   srcZsrc_typeZused_as_reference	signaturer   r  msgtuprQ   rQ   rR   r    s   



IGE720
,!



	,
zExprNode.coerce_toc                 C   s   t | dr	| jjnd }| jjrd| j  dnd}|jr%d|  dnd}|| j|}t| jd| j d| d| d| |rBdnd | 
 d S )	Nr   z (alias of 'z')r  zCannot assign type ''z to '.)	r  r   rq   r   Z
is_typedefresolveZassignment_failure_extra_infor   r   )rU   r  Zsrc_nameZsrc_resolvedZdst_resolvedZextra_diagnosticsrQ   rQ   rR   r  o  s   
zExprNode.fail_assignmentc                 C   sX   |r|sd}t | j|f||}|d ur!t| j|| j|d  dS |r*| | dS dS )Nz)Cannot assign type '%(FROM)s' to '%(TO)s')ZFROMZTOTF)r   r   r   r   r  )rU   r  rs   failrr   messagerQ   rQ   rR   r  z  s   
z!ExprNode.check_for_coercion_errorc                 C      |  tj|S rJ   )r  r   r   r   rQ   rQ   rR   coerce_to_pyobject  rL  zExprNode.coerce_to_pyobjectc                 C   s   |   rt| j}t| j|dS | j}|js|jr| S |tj	u r"| S |j
s.|js.|js.|jr3t| |S |jrS|jrS|jdrSt| jt| j| tddg d|S |jrdt|jdk}t| j|dS t| jd|  | S )Nr   zoperator bool)obj	attributefunctionr   r   z%Type '%s' not acceptable as a boolean)r   r.  r~   BoolNoder   r   is_enumr  r   c_bint_typerp   r  r  is_floatCoerceToBooleanNoder   r  lookupSimpleCallNodeAttributeNoder   EncodedStringr"  	is_ctupler   
componentsr   )rU   rs   
bool_valuer   rQ   rQ   rR   r-    s2   


zExprNode.coerce_to_booleanc                 C   s   | j jr| S | tj|S rJ   )r   r  r  r   c_py_ssize_t_typer   rQ   rQ   rR   coerce_to_index  s   zExprNode.coerce_to_indexc                 C   s   |   r| S t| |S rJ   )rX  CoerceToTempNoder   rQ   rQ   rR   coerce_to_temp     
zExprNode.coerce_to_tempc                 C   s   |   r| S | |S rJ   )	is_simpler  r   rQ   rQ   rR   r0    r  zExprNode.coerce_to_simplec                 C   rY  rJ   )rX  rT   rQ   rQ   rR   r    s   zExprNode.is_simplec                 C   s    z|   W S  ty   Y dS w rR  )r  	ExceptionrT   rQ   rQ   rR   try_is_simple  s
   
zExprNode.try_is_simplec                 C   s0   | j r| j js| j jsdS |  r| jd uS dS NFT)r   rp   r   r   r~   rT   rQ   rQ   rR   may_be_none  s   
zExprNode.may_be_nonec                 C   r   rJ   rQ   rT   rQ   rQ   rR   as_cython_attribute  rW   zExprNode.as_cython_attributePyExc_TypeErrorrQ   c                 C   s   |   rt| |||S | S rJ   )r  NoneCheckNode)rU   r  r   format_argsrQ   rQ   rR   as_none_safe_node  s   zExprNode.as_none_safe_nodec              	   K   sX   d  }|D ]}||v rqzt||}W n	 ty   Y qw |||< q| |jfi |S )zInstantiate this node class from another node, properly
        copying over all attributes that one would forget otherwise.
        z1cf_state cf_maybe_null cf_is_null constant_result)splitr   r   r   )rN   r   kwargs
attributes	attr_namer   rQ   rQ   rR   	from_node  s   
zExprNode.from_nodec                 C   rS   )z
        Gets the module.path that this node was imported from.

        Many nodes do not have one, or it is ambiguous, in which case
        this function returns a false value.
        NrQ   rT   rQ   rQ   rR   !get_known_standard_library_import  s   z*ExprNode.get_known_standard_library_importFrJ   r   FNN)FTFN)r  rQ   )~rX   rY   rZ   r  r   
annotationr   ri  rd  ra  is_numpy_attributeZgenerator_arg_tagr  r   is_dict_literalr   r   is_attributeis_subscriptr   is_buffer_accessis_memview_indexis_memview_slicer  r  r   r   	is_targetr   is_annotationr
  r~   r'   implementationrq   propertyr	   
attrgetterr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r  r  r  rw   r  r  r!  r%  r(  r,  r/  r1  r3  r   r8  r@  rA  rC  rH  rI  r"  r*  rO  rP  r#  rS  rV  rU  rX  r[  r   re  rk  rn  rs  r{  rt  rv  r  ry  r  r  r  r  rz  r  r  r  r  r  r  r  r  r  r  r  r  r-  r  r  r0  r  r  r  r  r  classmethodr  r  rQ   rQ   rQ   rR   r   >  s    s




		
			


	 


r   c                       s   e Zd ZdZdgZdZ fddZedd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Z  ZS ) _TempModifierNodez[Base class for nodes that inherit the result of their temp argument and can modify it.
    r   Fc                    s   t  j||d d S Nr   )rL   __init__rU   r   r   rO   rQ   rR   r       z_TempModifierNode.__init__c                 C      | j jS rJ   r   r   rT   rQ   rQ   rR   r     r\  z_TempModifierNode.typec                 C      | j |S rJ   r   r   r   rQ   rQ   rR   r        z_TempModifierNode.infer_typec                 C      | j || _ | S rJ   )r   r"  r   rQ   rQ   rR   r"       z_TempModifierNode.analyse_typesc                 C   
   | j  S rJ   )r   r  rT   rQ   rQ   rR   r    rM  z+_TempModifierNode.calculate_constant_resultc                 C   r  rJ   r   r  rT   rQ   rQ   rR   r    rM  z_TempModifierNode.may_be_nonec                 C   r  rJ   r   r  rT   rQ   rQ   rR   r    rM  z_TempModifierNode.is_simplec                 C   r  rJ   r   rX  rT   rQ   rQ   rR   rX    rM  z _TempModifierNode.result_in_tempc                 C   r  rJ   r   r8  rT   rQ   rQ   rR   r8    rM  z&_TempModifierNode.nonlocally_immutablec                 C   r  rJ   r   r   rT   rQ   rQ   rR   r     rM  z'_TempModifierNode.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv    rW   z&_TempModifierNode.generate_result_codec                 C      | j | d S rJ   r   r  rm  rQ   rQ   rR   r    r   z/_TempModifierNode.generate_post_assignment_codec                 C   r  rJ   )r   re  rm  rQ   rQ   rR   re     r  z&_TempModifierNode.allocate_temp_resultc                 C   r!  rJ   r   r  rm  rQ   rQ   rR   r  #  r   z_TempModifierNode.free_temps)rX   rY   rZ   __doc__r   r   r  r  r   r   r"  r  r  r  rX  r8  r   rv  r  re  r  r[   rQ   rQ   rO   rR   r    s&    
r  c                   @   s    e Zd Zg Zdd Zdd ZdS )AtomicExprNodec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rt  4  rW   z/AtomicExprNode.generate_subexpr_evaluation_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   ry  6  rW   z-AtomicExprNode.generate_subexpr_disposal_codeN)rX   rY   rZ   r   rt  ry  rQ   rQ   rQ   rR   r%  -  s    r%  c                   @   s@   e Zd ZdZeZdZdd Zdd Zdd Z	d	d
 Z
dd ZdS )PyConstNoder)   Nc                 C   rS   Nr)   rQ   rT   rQ   rQ   rR   r  A  rW   zPyConstNode.is_simplec                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  D  rW   zPyConstNode.may_be_nonec                 C      | S rJ   rQ   r   rQ   rQ   rR   r"  G  rW   zPyConstNode.analyse_typesc                 C   r   rJ   r  rT   rQ   rQ   rR   r   J     z!PyConstNode.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  M  rW   z PyConstNode.generate_result_code)rX   rY   rZ   r   r   r   rO  r  r  r"  r   rv  rQ   rQ   rQ   rR   r&  :  s    r&  c                       s8   e Zd ZdZdZdZdd Zdd Z fdd	Z  Z	S )
r  r)   Py_NoneNc                 C   r   rJ   rQ   r  rQ   rQ   rR   r  Y  rW   zNoneNode.compile_time_valuec                 C   rS   NTrQ   rT   rQ   rQ   rR   r  \  rW   zNoneNode.may_be_nonec                    s0   |j s|js|jst| jd|  t ||S )NzCannot assign None to %s)rp   r   r  r   r   rL   r  rU   r  rs   rO   rQ   rR   r  _  s   zNoneNode.coerce_to)
rX   rY   rZ   r   r   r~   r  r  r  r[   rQ   rQ   rO   rR   r  Q  s    r  c                   @      e Zd ZdZeZdd ZdS )EllipsisNodeZPy_Ellipsisc                 C      t S rJ   )Ellipsisr  rQ   rQ   rR   r  m  rW   zEllipsisNode.compile_time_valueN)rX   rY   rZ   r   r0  r~   r  rQ   rQ   rQ   rR   r.  f  s    r.  c                   @   sd   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd ZeefddZdS )	ConstNoder)   Nc                 C   rS   r'  rQ   rT   rQ   rQ   rR   r  y  rW   zConstNode.is_simplec                 C   rS   r'  rQ   rT   rQ   rQ   rR   r8  |  rW   zConstNode.nonlocally_immutablec                 C   rS   rR  rQ   rT   rQ   rQ   rR   r    rW   zConstNode.may_be_nonec                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"    rW   zConstNode.analyse_typesc                 C   rS   r+  rQ   rT   rQ   rQ   rR   r#    rW   zConstNode.check_constc                 C   rY  rJ   rZ  rT   rQ   rQ   rR   r    r^   z$ConstNode.get_constant_c_result_codec                 C   
   t | jS rJ   )rw   r   rT   rQ   rQ   rR   r     rM  zConstNode.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv    rW   zConstNode.generate_result_codec                 C   s   t }|tju s|dks|dkr|jrt| S |jstjrt}n|jr%t	}n|t
u r,t}n|tu r2t}|j|u r@|| ||d}|S || |||d}|S )NNULLr   r   r~   r   r   r~   )r1  r   c_null_ptr_typer  NullNoder  r  r=  r  	FloatNoder   	BytesNoder   UnicodeNoder   )r   r   r   r~   rN   r   rQ   rQ   rR   for_type  s"   

zConstNode.for_type)rX   rY   rZ   r   rO  r  r8  r  r"  r#  r  r   rv  staticmethodr
  r;  rQ   rQ   rQ   rR   r1  q  s    r1  c                       sZ   e Zd ZejZddef fddZdd Zdd Z	d	d
 Z
dd Zdd Zdd Z  ZS )r  Nr   c                    sd   |du s|du sJ t |t j|||d |d ur.|| jur0|tju s)J ||| _d S d S d S )NTFr4  )reprrL   r  r   r   	bool_type)rU   r   r   r   rO   rQ   rR   r    s   
zBoolNode.__init__c                 C      | j | _d S rJ   r4  rT   rQ   rQ   rR   r    r  z"BoolNode.calculate_constant_resultc                 C   r   rJ   r  r  rQ   rQ   rR   r    r)  zBoolNode.compile_time_valuec                 C   s$   | j jr| jr	dS dS | jrdS dS )NZPy_TrueZPy_False10)r   rp   r   rT   rQ   rQ   rR   r        zBoolNode.calculate_result_codec                 C   s    | j jr| S t| j| jtjdS )Nr   r   )r   rp   r  r   r   r   r>  r   rQ   rQ   rR   r    s   zBoolNode.coerce_to_pyobjectc                 C   s   | j jr| S t| j| jdS Nr  )r   r  r  r   r   r   rQ   rQ   rR   r-    s   zBoolNode.coerce_to_booleanc                 C   st   || j kr| S |tu r| j tju r| S |jr$| j jr$t| j| jtjdS |jr3| j jr3t| j| jdS t	
| ||S )NrC  r  )r   r   r   r>  rp   r  r  r   r   r1  r  r,  rQ   rQ   rR   r    s   
zBoolNode.coerce_torJ   )rX   rY   rZ   r   r  r   r.  r  r  r  r   r  r-  r  r[   rQ   rQ   rO   rR   r    s    r  c                   @   s"   e Zd ZejZdZdZdd ZdS )r7  r3  r   c                 C   r   rJ   r  rT   rQ   rQ   rR   r    r)  z#NullNode.get_constant_c_result_codeN)	rX   rY   rZ   r   r6  r   r   r~   r  rQ   rQ   rQ   rR   r7    s
    r7  c                   @   s*   e Zd ZejZdd Zdd Zdd ZdS )r   c                 C      t | j| _d S rJ   )ordr   r~   rT   rQ   rQ   rR   r    r   z"CharNode.calculate_constant_resultc                 C   r2  rJ   )rF  r   r  rQ   rQ   rR   r    rM  zCharNode.compile_time_valuec                 C   s   dt | j S )Nz'%s')r   escape_charr   rT   rQ   rQ   rR   r     r   zCharNode.calculate_result_codeN)	rX   rY   rZ   r   r   r   r  r  r   rQ   rQ   rQ   rR   r     s
    r   c                   @   s   e Zd ZdZdZdZedd Zedd Zdd Z	e
ejfd	d
Ze
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )r=  r  Nc                 C   s   t tt | jS rJ   )r   strip_py2_long_suffixhexstr_to_numberr   rT   rQ   rQ   rR   	hex_value     zIntNode.hex_valuec                 C   s   t t| jS rJ   )rw   r   rJ  r   rT   rQ   rQ   rR   base_10_value  r  zIntNode.base_10_valuec                 K   s.   t j| |fi | d|vr|  | _d S d S )Nr   )r   r  find_suitable_type_for_valuer   rU   r   kwdsrQ   rQ   rR   r    s   zIntNode.__init__c                 C   s,   t |tsJ t|| |t|||ddS )NT)r   r~   r   is_c_literal)r}   r   r=  rw   )rN   r   	int_valuer   rQ   rQ   rR   for_int  s   zIntNode.for_intc                 C   s   | j ||tjdS Nr  )rS  r   r  )rN   r   rR  rQ   rQ   rR   r>    s   zIntNode.for_sizec                 C   s   | j tu rz|   W n	 ty   Y nw | js$|  r$| js$| jdkrC| jdkr+dp,d}tj	| j |df }| j
rAt|| j
}|S d| j   krNdk ran n| j
r\| j
jr\| j
}|S tj}|S tj}|S )NLLr4   r)   r   i   l        )r~   r
  r  r   rQ  r   unsignedlongnessr   Zmodifiers_and_name_to_typer   widest_numeric_typer  c_long_typer   int_type)rU   rankZsuitable_typerQ   rQ   rR   rN    s2   


z$IntNode.find_suitable_type_for_valuec              	   C   s   | j |u r| S |js|tju r.|  r$t| jdt| j |t	| jdS t| j| j
|tdS |jrF|jsFt| j| j
| j|d| j| jd}|S |jr[t| j| j
| jtjd| j| jd}nt| j| j
| j| j| jd}t|||S )Nz%d.0r5  T)r   r~   r   rQ  rV  rW  F)r   r~   rV  rW  )r   r  r   
float_typer   r8  r   r   r~   r   r   r  
is_numericr  r=  rV  rW  rp   rZ  r1  r  rU   r  rs   r   rQ   rQ   rR   r  ,  s2   
zIntNode.coerce_toc                 C   s    t | j| j| jtj| j| jdS )N)r   r~   r   rV  rW  )r=  r   r   r~   r   r  rV  rW  r   rQ   rQ   rR   r-  I  s   zIntNode.coerce_to_booleanc                 C   sX   | j jr%t| j}|dkrtnt}||}t|}||| j	| _
d S |  | _
d S )Nl     a$)r   rp   r   rJ  r   rI  rw   rH  Z
get_py_intrW  result_coder  )rU   r   r   	formatterZplain_integer_stringrQ   rQ   rR   r{  P  s   
z IntNode.generate_evaluation_codec                 C   st   | j | j}}|  }|s4|s4| jjr4|d dkr4|d dkr4| jjtjjkr*d}n
| jjtjjkr4d}|| | S )Nr   -r)   rA  rU  L)	rV  rW  value_as_c_integer_stringr   r  r[  r   Zc_longlong_typerY  )rU   rV  rW  literalrQ   rQ   rR   r  ^  s   (z"IntNode.get_constant_c_result_codec                 C   s   | j }t|dkr|S d}|d dkrd}|dd  }|d dkra|d }|r>|dv r>|dd   r>tt|}|| S |dv rNd|dd   }|| S |d	v r]tt|dd  d}|| S | rs| jss| jss|ssd
t| }|| S )Nr4   r  r   ra  r)   rA  ZoOxX0123456789ZoOZbBz0x%X)	r   r   isdigitrw   r   rJ  r   rV  rW  )rU   r   Zneg_signZliteral_typerQ   rQ   rR   rc  i  s,   
z!IntNode.value_as_c_integer_stringc                 C   r   rJ   r_  rT   rQ   rQ   rR   r     r)  zIntNode.calculate_result_codec                 C   s   t | j| _d S rJ   )r   rJ  r   r~   rT   rQ   rQ   rR   r    r   z!IntNode.calculate_constant_resultc                 C   s   t | jS rJ   )r   rJ  r   r  rQ   rQ   rR   r    r  zIntNode.compile_time_value)rX   rY   rZ   rV  rW  rQ  r  rK  rM  r  r  r   
c_int_typerS  r>  rN  r  r-  r{  r  rc  r   r  r  rQ   rQ   rQ   rR   r=    s,    


r=  c                   @   sB   e Zd ZejZdd Zdd Zdd Zdd Z	d	d
 Z
dd ZdS )r8  c                 C   rE  rJ   )r   r   r~   rT   rQ   rQ   rR   r    r   z#FloatNode.calculate_constant_resultc                 C   sN   t | j}d| d}t| j}||t|dfvr%t| jd|  |S )Nz%.330frA  zEUsing this floating point value with DEF may lose precision, using %r)	r   r   stripr   Znormalise_float_reprr=  lstripr   r   )rU   r  float_valueZstr_float_valueZ	str_valuerQ   rQ   rR   r    s   
zFloatNode.compile_time_valuec                 C   sX   |j r| jjrt| j| j| jtjdS |jr%| jj r%t| j| j| j|dS t	
| ||S )N)r   r~   r   )rp   r   r  r8  r   r   r~   r   r\  r1  r  r,  rQ   rQ   rR   r    s   zFloatNode.coerce_toc                 C   r   rJ   rf  rT   rQ   rQ   rR   r     r)  zFloatNode.calculate_result_codec                 C   sH   | j }t|ts
J tt|}|dkrdS |dkrdS |dkr"dS |S )Nnanz(Py_HUGE_VAL * 0)infZPy_HUGE_VALz-infz(-Py_HUGE_VAL))r   r}   rw   r=  r   )rU   strvalZcmpvalrQ   rQ   rR   r    s   z$FloatNode.get_constant_c_result_codec                 C   s.   |   }| jjr|| j|| _d S || _d S rJ   )r  r   rp   Zget_py_floatr   r_  )rU   r   Zc_valuerQ   rQ   rR   r{    s   
z"FloatNode.generate_evaluation_codeN)rX   rY   rZ   r   c_double_typer   r  r  r  r   r  r{  rQ   rQ   rQ   rR   r8    s    r8  c           
   	   C   sl  t | }|d ur|jr|S | }|| }|r-|jr-|j}|r)|js'|jr)|S |p,|}ddlm} t	ddt |d |d |d d f}z|d|  |d j
|d	}W n	 ty]   Y n?w |jjd j}	t|	tr|	|}	t|	tr|	j}|r|js|jr|W  d    S |p|}W d    |S W d    |S W d    |S W d    |S 1 sw   Y  |S )
Nr)   )TreeFragmentTignorer   r4      
sizeof(%s))rq   Zinitial_pos)r   parse_basic_typein_c_type_contextglobal_scoper  is_typer   rp   ro  r
   filenamer   rootstatsexprr}   SizeofTypeNoder"  arg_type)
rq   r   rs   r  rv  Zglobal_entryr   ro  ZdeclarationZsizeof_noderQ   rQ   rR   _analyse_name_as_type  sP   










r~  c                   @   sf   e Zd ZdZeZdd ZdddZdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )r9  Tc                 C   r?  rJ   r4  rT   rQ   rQ   rR   r    r  z#BytesNode.calculate_constant_resultNc                 C   s,   t | j||| | jj}t| j||dS Nr4  )r   bytes_literalr   encodingr9  r   )rU   r   r   r   r   rQ   rQ   rR   as_sliced_node  s   zBytesNode.as_sliced_nodec                 C   r  rJ   )r   Z
byteencoder  rQ   rQ   rR   r    rM  zBytesNode.compile_time_valuec                 C   s   t | jd| j|S )Nz	ISO8859-1)r~  r   decoder   r   rQ   rQ   rR   rC       zBytesNode.analyse_as_typec                 C      t | jdkS r'  r   r   rT   rQ   rQ   rR   r     rL  z$BytesNode.can_coerce_to_char_literalc                 C   s   t | jt| jdS rD  )r  r   r.  r   r   rQ   rQ   rR   r-    s   zBytesNode.coerce_to_booleanc                 C   s   | j |kr| S |jr-|  st| jd | S |jr!t| jd | S t| j| jt| jdS t	| j| j| j
d}|jrQ|ttjfv rGtj|_ |S | j||dd |S |tjtjfv r^||_ |S |tjtjtjfv rx|jjrotjntj|_ t||S |tjr|jr|jr||_ |S t|||S )Nz?Only single-character string literals can be coerced into ints.zRBytes literals cannot coerce to Py_UNICODE/Py_UCS4, use a unicode literal instead.r4  Tr  )r   r  r   r   r   is_unicode_charr   r   rF  r9  r~   rp   r   r   r   r  r   r.   rn   rm   ro   c_void_ptr_typer  is_constCastNoder  r   r1  r  r^  rQ   rQ   rR   r     s@   


zBytesNode.coerce_toc                 C   sb   | j jr|| j}n!| j js| j jr| j jjr|| j}n| j	 }t
| j tj|}|| _d S rJ   )r   rp   get_py_string_constr   r  r6  r  r  get_string_constZas_c_string_literalr/   r   r  r_  )rU   r   r   rd  rQ   rQ   rR   r{  &  s   

z"BytesNode.generate_evaluation_codec                 C   r   rJ   rQ   rT   rQ   rQ   rR   r  2  rW   z$BytesNode.get_constant_c_result_codec                 C   r   rJ   rf  rT   rQ   rQ   rR   r   5  r)  zBytesNode.calculate_result_coderJ   )rX   rY   rZ   r   r   r   r  r  r  rC  r   r-  r  r{  r  r   rQ   rQ   rQ   rR   r9    s    
&r9  c                       s   e Zd ZdZdZdZeZd fdd	Zdd Z	dd Z
dd	d
Zdd Zdd Zdd Zdd Zdd Zdd Zdd Z  ZS )r:  TNc                    sB   t  j|||d |d ur|| _|d ur|tur|| _d S d S d S r  )rL   r  bytes_valuer   r   )rU   r   r   r  r   rO   rQ   rR   r  F  s   
zUnicodeNode.__init__c                 C   r?  rJ   r4  rT   rQ   rQ   rR   r  M  r  z%UnicodeNode.calculate_constant_resultc                 C   s   t | j| j|S rJ   )r~  r   r   r   rQ   rQ   rR   rC  P  r   zUnicodeNode.analyse_as_typec                 C   sX   t | j||| | jj}| jd ur"t | j||| | jj}nd }t| j||dS )N)r   r  )r   encoded_stringr   r  r  r  r:  r   )rU   r   r   r   r   r  rQ   rQ   rR   r  S  s   
zUnicodeNode.as_sliced_nodec              	   C   s`  || j u r	 | S |jr%|  st| jd | S t| j}tj| j||dS |j	r1t
| j| j|dS |js|jsD|jsD|jsD|jr|jjr| jd ur\|jrP| }t| j| jd||S |jd rz| j|jd }W n ttfyw   Y nw t| j|d||S | j rt| jt| jdd||S t| jd | S |tur| j||dd	 | S )
NzhOnly single-character Unicode string literals or surrogate pairs can be coerced into Py_UCS4/Py_UNICODE.r  rC  r  r_   rg   zUnicode literals do not support coercion to C types other than Py_UCS4/Py_UNICODE (for characters), Py_UNICODE* (for strings) or char*/void* (for auto-encoded strings).Tr  ) r   r  r   r   r   rF  r   r=  rS  rx  r:  rp   rw  is_cpp_stringr  r  r  r`  r  r6  Zelement_ptr_typer9  r  rk   encodeUnicodeEncodeErrorLookupErrorisasciir   BytesLiteralr   r  )rU   r  rs   rR  Zbyte_stringrQ   rQ   rR   r  ]  sR   
$



zUnicodeNode.coerce_toc                 C   r  r'  r  rT   rQ   rQ   rR   r     rL  z&UnicodeNode.can_coerce_to_char_literalc                 C   s   t | j}t| j|dS rD  )r.  r   r  r   )rU   rs   r  rQ   rQ   rR   r-    s   
zUnicodeNode.coerce_to_booleanc                 C   s8   | j  rdS tt| j }|dkrdS |dkrdS dS )N      i  i )r   r  rF  max)rU   Zmax_charvalrQ   rQ   rR   estimate_max_charval  s   
z UnicodeNode.estimate_max_charvalc              
   C   s   | j jrat| jrL|d| _|t| j	d}|
| j}|d u r(d S || j |d| j|||| j| jf  || jd| j  d S | jrX|| j| _d S || j| _d S || j| _d S )NZustringunicode_escapez@%s = PyUnicode_DecodeUnicodeEscape(%s, sizeof(%s) - 1, NULL); %sz__Pyx_PyUnicode_READY(%s))r   rp   r   Zstring_contains_lone_surrogatesr   get_py_constr_  r  r  r  get_cached_constants_writerru  r   r   r   put_error_if_negis_identifierintern_identifierr  Zget_pyunicode_ptr_const)rU   r   Z
data_cname
const_coderQ   rQ   rR   r{    s2   z$UnicodeNode.generate_evaluation_codec                 C   r   rJ   rf  rT   rQ   rQ   rR   r     r)  z!UnicodeNode.calculate_result_codec                 C   r   rJ   r  r  rQ   rQ   rR   r    r)  zUnicodeNode.compile_time_valueNNrJ   )rX   rY   rZ   r   r  r  r   r   r  r  rC  r  r  r   r-  r  r{  r   r  r[   rQ   rQ   rO   rR   r:  9  s     

(r:  c                   @   s   e Zd ZdZdS )IdentifierStringNodeTN)rX   rY   rZ   r  rQ   rQ   rQ   rR   r    s    r  c                   @   sN   e Zd ZejZdd Zdd Zdd Zdd Z	d	d
 Z
dZdd Zdd ZdS )ImagNodec                 C   s   t dt| j| _d S Ng        )complexr   r   r~   rT   rQ   rQ   rR   r    r  z"ImagNode.calculate_constant_resultc                 C   s   t dt| jS r  )r  r   r   r  rQ   rQ   rR   r    r   zImagNode.compile_time_valuec                 C   s   | j | | S rJ   )r   create_declaration_utility_coder   rQ   rQ   rR   r"       zImagNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r    rW   zImagNode.may_be_nonec                 C   s@   | j |u r| S t| j| jd}|jrd|_tj|_ t	|||S )Nr  r)   )
r   r  r   r   rp   r   r   complex_typer%  r  r^  rQ   rQ   rR   r    s   
zImagNode.coerce_tozConstructing complex numberc                 C   s&   | j jr|  S d| j jt| jf S )Nz	%s(0, %r))r   rp   r   
from_partsr   r   rT   rQ   rQ   rR   r     s   zImagNode.calculate_result_codec              	   C   sF   | j jr!|d|  t| j||  | jf  | | d S d S )Nz'%s = PyComplex_FromDoubles(0.0, %r); %s)	r   rp   r   r   r   r   r   r   r  rm  rQ   rQ   rR   rv    s   zImagNode.generate_result_codeN)rX   rY   rZ   r   Zc_double_complex_typer   r  r  r"  r  r  gil_messager   rv  rQ   rQ   rQ   rR   r    s    r  c                   @   8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )NewExprNodeNc                 C   s`   | j |}|d u s|jst| jd t| _d S | | || j}|| _	|| _
|j| _| jS )Nz/new operator can only be applied to a C++ class)ZcppclassrC  r   r   r   r0   r   	cpp_checkZget_constructor
class_typer   )rU   rs   r   constructorrQ   rQ   rR   r     s   
zNewExprNode.infer_typec                 C   s   | j d u r
| | | S rJ   )r   r   r   rQ   rQ   rR   r"    s   

zNewExprNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r    rW   zNewExprNode.may_be_nonec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv    rW   z NewExprNode.generate_result_codec                 C   s   d| j   S )Nznew )r  empty_declaration_coderT   rQ   rQ   rR   r     rL  z!NewExprNode.calculate_result_code)	rX   rY   rZ   r   r   r"  r  rv  r   rQ   rQ   rQ   rR   r    s    r  c                       s  e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdd Zdd	 Zd
d Zdd Zdd Z fddZdQddZdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Z d(Z!dQd)d*Z"d+d, Z#d-d. Z$d/d0 Z% fd1d2Z&d3d4 Z'd5d6 Z(d7d8 Z)d9d: Z*d;d< Z+d=d> Z,d?d@ Z-dAdB Z.dCdD Z/		dRdEdFZ0dGdH Z1dIdJ Z2dQdKdLZ3dMdN Z4dOdP Z5  Z6S )Sr  TFNr   r  c                 C   r   rJ   )cython_attributerT   rQ   rQ   rR   r  4  r)  zNameNode.as_cython_attributec                 C   s6   | j d u r|| j| _ | j d ur| j jjr| fS dS NrQ   )r   r  rq   r   is_unspecifiedr   rQ   rQ   rR   r3  7  s
   
zNameNode.type_dependenciesc                 C   s   | j d u r|| j| _ | j d u s| j jtu r!| jd ur| jS tS | j jjs+| j jjr5| j | j jj kr5t	S | j jt
u rJ| j | j jj krJ| jdv rJt	S | j jjr]| j jjrVtS t| j jS | j jjrp| jrp| jjrm| j jsp| jS | j jS )N)rx   
basestring)r   r  rq   r   r1   inferred_typer   is_extension_typeis_builtin_typer   r   r7  r  Zis_builtin_scoper   CPtrTyperp   r  Zmight_overflowr   rQ   rQ   rR   r   ?  s(   



zNameNode.infer_typec                 C   s6   z| | jW S  ty   t| jd| j  Y d S w )Nz"Compile-time name '%s' not defined)r  rq   rG  r   r   r  rQ   rQ   rR   r  `  s
   zNameNode.compile_time_valuec                 C   s   | j r| j jjr
d S | j jS rJ   )r   r   rp   r   rT   rQ   rQ   rR   r  f  s   z#NameNode.get_constant_c_result_codec                    sp   |t u r1| j}|r1|jr1|j}|r1|jr|jr||j| j}t	| j| jd}||_|
| |S t ||S )Nrq   )r   r   r7  as_variable
is_builtinr  declare_builtinrq   r   r  analyse_rvalue_entryrL   r  )rU   r  rs   r   Z	var_entryr   rO   rQ   rR   r  k  s   

zNameNode.coerce_toc           
      C   s^  | j }| j}| jp||}|s|jrdS d}|jjs |jd s#d}n|jr)t	}n|
|\}}|du rB|r?|jd dkr?tnt	}n#|jre|jrez||j}W n tyd   t| jd| j   t}Y nw d}|jr}|jdk}	|jsw||r}|	r{d	nd
}|r|jr|js|jst	}t|jdd |j||| j| ||d }| _|r|js||_dS dS dS )as  Implements PEP 526 annotation typing in a fairly relaxed way.

        Annotations are ignored for global variables.
        All other annotations are stored on the entry in the symbol table.
        String literals are allowed and not evaluated.
        The ambiguous Python types 'int' and 'long' are not evaluated - the 'cython.int' form must be used instead.
        NrQ   Zannotation_typinginfer_typesFzR'%s' cannot be specialized since its type is not a fused argument to this functionprivatefrozenreadonlypubliczxAnnotation ignored since class-level attributes must be Python objects. Were you trying to set up an instance attribute?r4   )Zis_cdef
visibilityZpytyping_modifiers)rq   r   r   lookup_hereis_module_scoper{  r   rk   is_py_class_scoper   analyse_type_annotationr1   rD  rE  rF  r*   r   r   r0   is_c_dataclass_scoperp   can_coerce_to_pyobjectis_c_class_scoper  r   declare_var)
rU   rs   	as_targetrq   r   r   	modifiersZatyper  	is_frozenrQ   rQ   rR   declare_from_annotation~  sZ   


z NameNode.declare_from_annotationc                 C   sN   | j }|s|| j}|r|jr|jS |r%|jr%t|j}|r%|jr%|S d S rJ   )r   r  rq   	as_moduleknown_standard_library_importr   Z'get_known_standard_library_module_scoper  )rU   rs   r   r  rQ   rQ   rR   rA    s   


zNameNode.analyse_as_modulec                 C   s   d }| j rt| j }n	|jrt| j}|r|S | j}|s$|| j}|r2|js2|j	r2t
|j	}|rE|jrE|j}|jrC|jrC|j}|S | jdkrLtS |jrUt| jS t| jrjt| jd| j d| j d d S )NobjectzFound C type name 'z6' in a Python annotation. Did you mean to use 'cython.z'?)r  r   rt  ru  Zparse_basic_ctyperq   r   r  rw  r  r   Z get_known_standard_library_entryr   rp   r   r   r   r   r5  rQ   rQ   rR   rC    s0   

zNameNode.analyse_as_typec                 C   s:   | j }|s|| j}|r|jr|jjs|jjr|jS d S rJ   )r   r  rq   rw  r   r  r  rU   rs   r   rQ   rQ   rR   rI    s   
z"NameNode.analyse_as_extension_typec                 C      | j |ddS )NFis_assignment_expression_analyse_target_declarationr   rQ   rQ   rR   r    rL  z#NameNode.analyse_target_declarationc                 C   r  )NTr  r  r   rQ   rQ   rR   r!   	  rL  z9NameNode.analyse_assignment_expression_target_declarationc                 C   s  d| _ | js|r|| j| _n|| j| _| jrd| j_| js2| jd ur2|j}| j|| d n| jrE| jj	rE| jrE|jrEt
| jd | jsz|jd rWt| jd| j d |jd d	krat}nt}|rp|| j|| j| _n
|| j|| j| _| jjrt| _| jjrd| j_d S d S )
NTr  )r  z7Cannot redeclare inherited fields in Cython dataclasseszwarn.undeclaredzimplicit declaration of '%s'r)   r  F)r  r   Z#lookup_assignment_expression_targetrq   r  r  r   r  r  Zis_inheritedr   r   rk   r   r1   r   Z$declare_assignment_expression_targetr  is_declared_genericr  r  is_variable)rU   rs   r  is_dataclassr   rQ   rQ   rR   r  	  s<   
z$NameNode._analyse_target_declarationc                 C   s   |j d | _| j}|d u r3|| j}|s(|| j| j}|r(|jr(|jr(d| _	|s0t
j| _| S || _d|_|jjrEddlm} || | | | S )NinitializedcheckTr)   Buffer)rk   initialized_checkr   r  rq   r  r   r  r  r   r   r0   r   r  	is_bufferr  r  used_buffer_aux_varsr  rU   rs   r   r  rQ   rQ   rR   r"  &	  s$   

zNameNode.analyse_typesc                 C   s   | j |dd | j}|jr(|jr(|js|jjs|  s(|jr(|j }| _|j| _|  s9t| j	d| j
  tj| _d|_|jjrKddlm} || | S )NTr  zAssignment to non-lvalue '%s'r)   r  )analyse_entryr   r7  r  is_overridabler   r   fused_cfunctionr   r   rq   r   r0   r  r  r  r  r  r  rQ   rQ   rR   r*  :	  s   
zNameNode.analyse_target_typesc                 C   sj   |  | | j}|jrt| _|js|jr&|jr|jrd| _nd| _d| _	| S |j
jr3d| _d| _	d| _| S )Nr   r)   FT)r  r   r  r   r  is_pyglobalr  r  r   is_used_as_rvaluer   r   rd  r  rQ   rQ   rR   r  N	  s   
zNameNode.analyse_rvalue_entryc                 C   sH   d| _ | jr | j}|jr|js|   d S d S |jr"|   d S d S d S r+  )r   r  r   r  r  rN  r  r  rQ   rQ   rR   rO  d	  s   zNameNode.nogil_checkz"Accessing Python global or builtinc                 C   sd   |    | j}|j}|s|jr| jr| jjr| j}|| _|jjr.|js&|j	r0|
d| _d S d S d S Nr  )check_identifier_kindr   r   rp   r  r  r  r  r  Zis_cclass_var_entryname_in_module_statemodule_state_lookup)rU   rs   r  r   r   rQ   rQ   rR   r  p	  s   zNameNode.analyse_entryc                 C   s   | j }|jr|jjr|| _|jr0|jjs|jjr0|jr0t	| j
d t}d|_| j j|_|| _ d S |jsX|jsZ|js\|js^|js`| j jrJ| j j| _ d S | jsbt| jd| j
  d S d S d S d S d S d S d S )NTz7'%s' is not a constant, variable or function identifier)r   rw  r   r  
type_entryr  is_cpp_enumZcreate_wrapperr   Entryrq   r   r  r  r  r  r  r7  r   r  is_cython_moduler   r   )rU   r   Zpy_entryrQ   rQ   rR   r  	  s*   

zNameNode.check_identifier_kindc                 C   s0   | j s| jrdS | jp|| j}|jo|j S rR  )r  r  r   r  rq   r  r  r  rQ   rQ   rR   "is_cimported_module_without_shadow	  s   z+NameNode.is_cimported_module_without_shadowc                 C   rS   r'  rQ   rT   rQ   rQ   rR   r  	     zNameNode.is_simplec                    sl   | j r1| jr1| jjs| jjr1t| ddrdS d| _d}| j D ]}|j r,d} | `|S q| `|S t  S )N_none_checkingFT)	r   r   rp   r   r   r  r   r  rL   )rU   r  
assignmentrO   rQ   rR   r  	  s"   


zNameNode.may_be_nonec                 C   s:   t | rdS | j}|r|jrdS |jp|jp|jp|jS NTF)r   r8  r   r  is_localr  r  is_readonlyrU   r   rQ   rQ   rR   r8  	  s   

zNameNode.nonlocally_immutablec                 C   r   rJ   rQ   r   rQ   rQ   rR   calculate_target_results	  rW   z!NameNode.calculate_target_resultsc                 C   s8   | j }|d ur|js|js|js|jjs|   dS dS r  )r   r  r7  r  r   rS  r  rQ   rQ   rR   r#  	  s   zNameNode.check_constc                 C   s(   | j }|js|js|js|   dS dS r  )r   
is_cglobalr7  r  rU  r  rQ   rQ   rR   rV  	  s
   zNameNode.check_const_addrc                 C   s"   | j jo| j j p| j jo| j jS rJ   )r   r  r  r7  r  rT   rQ   rQ   rR   r   	  s   zNameNode.is_lvaluec                 C   s   | j jo| jj S rJ   )r   r  r   r   rT   rQ   rQ   rR   r   	  r   zNameNode.is_addressablec                 C   rS   r   rQ   rT   rQ   rQ   rR   r   	  rB  zNameNode.is_ephemeralc                 C   s2   | j }|sdS | j jr| jsd|j S | j|j S )N<error>(*%s))r   is_cpp_optionalr  r   r  r  rQ   rQ   rR   r   	  s   
zNameNode.calculate_result_codec                 C   st  | j }|d u r	d S |jr|j|j |jr|jrd S |jr|jjs&J d|	| j j
}|jr4tj}n|jj}| jsU|d|  ||f  |d|    |d |jtdd |d|  |f  | jsr|d |||  | j | | d S |jr|jjs|jjsJ d|	| j j
}|jtd	d |d
|  |||  | jf  | | d S |js|jr2|jjr2|jjsJ d|	| j j
}|jjr|jtdd |d|  |||  | jf  n/||j}| j jj}|jtdd |d|  |rdnd||||  | jf  | | d S |jsC|jsC|jsC|jjr| jsK| joN| j  }|jjoV| j!}|j"o]| j!}	|	ri|j#|j$}
n|j%|j$}
|
r|r|jjs|s|	r|j&| j|| j'|
d d S d S d S d S |j(r|j"r| j!r|j#|j$}
|j&| j|| j'|
d d S d S d S d S )N,Python global or builtin not a Python objectz%s = PyObject_GetItem(%s, %s);if (unlikely(!%s)) {PyErr_Clear();ZGetModuleGlobalNameObjectHandling.cz"__Pyx_GetModuleGlobalName(%s, %s);r   ZGetBuiltinNamez!%s = __Pyx_GetBuiltinName(%s); %sz%__Pyx_GetModuleGlobalName(%s, %s); %sZGetNameInClassz&__Pyx_GetNameInClass(%s, %s%s, %s); %sz(PyObject*)r  unbound_check_code))r   utility_coder   r   r  r  is_pyclass_attrr   rp   r  rq   r   Zbuiltins_cnamer  namespace_cnamer  r   r   r   r   r   r   r  r  r  namespace_cname_in_module_statenamespace_cname_is_typer  r  r  r   r  
allow_nullr  r   cpp_optional_check_for_null_coder   Zcheck_for_null_codeput_error_if_unboundrr  r  )rU   r   r   interned_cname	namespacer  r  Zraise_unboundZmemslice_checkZoptional_cpp_checkr  rQ   rQ   rR   rv  	  s   






""zNameNode.generate_result_codec              	   C   s|  | j }|d u r	d S | j jjrt|tr| js|jst| jd |j	r|jj
s*J d|| j j}|| j j}| j jj}	d}
|jrQd}d}
|jtdd n.|jjr^d}|tj}n!|jry| jd	krhd
nd}|jt|d d| }nJ t||	r|
sd| d}|
r|	sJ || jd|||| f  trtd td|  || | | d S | jj!r| "|| n
| jj#r| $|| d}| jj%rd}| jj
r1| j&r1|'| |j(p| j j)p| j j*}|r| j+|dd d}|j(r| ,||-| .  n"| j/s'| j0r| 1||-| .  n| ,||-| .  nd}|r1|2| | jj!s|s|rl|3 }|dkr`t4|| jd| 5 |f | jj
rY| 5 nd || j6 n:|7d| 5 |f  n.|8| . }t9| jr|7d| 5 | 5 |f  n|| 5 kr|7d| 5 |f  trtd td|  |:| n
|; r|:| | | d S )Nz?Literal list must be assigned to pointer at time of declarationr  FZ__Pyx_SetItemOnTypeDictTZSetItemOnTypeDictzExtensionTypes.cPyDict_SetItemrM   ZSetNewInClassZSetNameInClassr  Z__Pyx_((PyObject*))z%s(%s, %s, %s)z"NameNode.generate_assignment_code:z"...generating disposal code for %s)r  r   %s = %s;new (&%s) decltype(%s){%s};z)...generating post-assignment code for %s)<r   r   r  r}   ListNodelhs_of_first_assignmentin_module_scoper   r   r  rp   r  rq   r  r  r  	is_memberr   r   r   r   r  r  r   moddict_cnamer  r=  r  r   r   printr  r  r    generate_acquire_memoryviewslicer  generate_acquire_bufferr  rd  rn  r  r  r  r  r  r   r  r  r  r  r  r   r   r   rr  r   r   r;   r  rX  )rU   r   r   r  r   r   r   r  r  Znamespace_is_typeZnamespace_needs_typesetternassignedZis_external_refr   rQ   rQ   rR   r  F
  s   










z!NameNode.generate_assignment_codec              	   C   s6   ddl m} |j|  | j| j||| j | jd dS )z
        Slices, coercions from objects, return values etc are new references.
        We have a borrowed reference in case of dst = src
        r)   r  )Z	lhs_cnamer   Zlhs_posr   r   rp  Zfirst_assignmentN)r  r  Zput_acquire_memoryviewslicer   r   r   rr  r  )rU   r   r   r  rQ   rQ   rR   r  
  s   
z)NameNode.generate_acquire_memoryviewslicec                 C   s   t |tp| }|r||  }n|jj| jjdd}|	d|||  f  ddl
m} |j|  || j| j | j|d |sS|	d|  |j| d S d S )NFr]  r  r)   r  )Zis_initializedr   r   r  )r}   r  rX  r   r  rb  rc  r   r   r   r  r  Zput_assign_to_bufferr   r  r   rj  )rU   r   r   Z
pretty_rhsZrhstmpr  rQ   rQ   rR   r  
  s   z NameNode.generate_acquire_bufferc              	   C   s  | j d u rd S | j jr3| j jj}|| j j}|rd}nd| j j }|d||||| jf  d S | j j	ri|j
tdd || j j}dtj|f }|r`|d||| jf  d S || j| d S | j jjss| j jjr| js| jr|s|| j| j | j | j jr| j|d|d	 |r| jr|j|  |  | j d
 d S |j|  |  | j d
 d S d S t| jd d S )NzPyErr_Clear(); elsezT{ PyErr_Clear(); PyErr_Format(PyExc_NameError, "name '%%s' is not defined", "%s"); }ziif (unlikely(PyObject_DelItem(%s, %s) < 0)) { if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) %s %s }PyObjectSetAttrStrr  !__Pyx_PyObject_DelAttrStr(%s, %s)zjif (unlikely(%s < 0)) { if (likely(PyErr_ExceptionMatches(PyExc_AttributeError))) PyErr_Clear(); else %s }T)r  r  ro  z!Deletion of C names not supported) r   r  r  r  r  rq   r   r   r   r  r   r   r   r   r   module_cnamer  r   rp   r   r  r  r  rr  r  r  put_xdecref_clearr   r  r   r  r   )rU   r   r  r  r  Zkey_error_codeZdel_coderQ   rQ   rR   r  
  sb   







zNameNode.generate_deletion_codec                 C   sz   t | ddr;| jd | jd | jd t| j d f}| jjr$d\}}nd\}}||t||| j t| jd d S d S )	N	is_calledFr   r)   r4   )Zpy_callzpython function (%s))Zc_callzc function (%s)size)r   r   r   rq   r   rp   r  r5   )rU   r   r   styletextrQ   rQ   rR   r    s   *
&zNameNode.annotatec                 C   s   | j r| j jS d S rJ   )r   r  rT   rQ   rQ   rR   r    s   z*NameNode.get_known_standard_library_importr  r  )7rX   rY   rZ   r   r  r  r  r  r   r  r  r  r	  r   r  r  r  r3  r   r  r  r  r  rA  rC  rI  r  r!  r  r"  r*  r  rO  r  r  r  r  r  r  r8  r  r#  rV  r   r   r   r   rv  r  r  r  r  r  r  r[   rQ   rQ   rO   rR   r    sl    !
@&#

	^
x
2	r  c                   @   s2   e Zd ZeZdgZdd ZdZdd Zdd Z	d	S )
BackquoteNoder   c                 C   s&   | j || _ | j || _ d| _| S r'  )r   r"  r  r   r   rQ   rQ   rR   r"  ,  s   zBackquoteNode.analyse_typeszBackquote expressionc                 C      t | jj| _d S rJ   )r=  r   r~   rT   rQ   rQ   rR   r  4  r   z'BackquoteNode.calculate_constant_resultc              	   C   s:   | d|  | j ||  | jf  | | d S )Nz%s = PyObject_Repr(%s); %s)r   r   r   r   r   r   r  rm  rQ   rQ   rR   rv  7  s   z"BackquoteNode.generate_result_codeN)
rX   rY   rZ   r   r   r   r"  r  r  rv  rQ   rQ   rQ   rR   r'  #  s    r'  c                   @   s8   e Zd ZeZdZddgZdd ZdZdd Z	d	d
 Z
dS )
ImportNodeTmodule_nameimported_namesc                    s   | j d u r  jr jd stj jjvrd| _ nd| _ | j	 }|
 | _| jjs/J | jd ur? fdd| jD | _| j dkrq| j dkrL| j nd}  j}t|D ]
}|d\}}}qWt| d| jj | _| S d | _| S )NZ
py2_importr   c                    r2  rQ   r'  )ra   rq   ry   rQ   rR   r   l  s    
z,ImportNode.analyse_types.<locals>.<listcomp>r)   r  )r|   rv  parent_modulerk   r6   absolute_importcontextZfuture_directivesr*  r"  r  r   r+  Zqualified_namerange
rpartitionr   r  r   module_qualname)rU   rs   r*  r|   qualname_rQ   ry   rR   r"  ]  s.   





zImportNode.analyse_typeszPython importc           	   
   C   s  | j jsJ d}| jd ur|| j}|jtdd | jd ur9|	d |	dd
dd | jD  d	 d
| j  | jd urEdnd| jd urPt| jnd|| jf }|jj| jdd}|	| d| d||| j  | jd ur||	d | jrd| j jv r|jtdd |jj| jdd}| j jd}|dd  D ]6}|t|}|	| d| d| d |	d| d |	||| j |	| d| d q|j| |	|   d| d |j| | | d S )Nr3  ImportzImportExport.c{z*PyObject* const __pyx_imported_names[] = {,c                 s       | ]}|  V  qd S rJ   r   )ra   r  rQ   rQ   rR   re     rf   z2ImportNode.generate_result_code.<locals>.<genexpr>};z __Pyx_Import(%s, %s, %d, %s, %d)Z__pyx_imported_namesrA  r   Fr]   = ; r   r  
ImportFromr)   z = __Pyx_ImportFrom(, );z
Py_DECREF(;)r*  r   r2  r  r   r   r   r   r+  r   joinr   r   r|   rb  rc  r   r   r   Zis_import_as_namer   r  r   r  rj  r   r  )	rU   r   r2  Zimport_codeZtmp_submodule	submodulemodulesmoduleZ
module_objrQ   rQ   rR   rv  |  sJ   




zImportNode.generate_result_codec                 C   r  rJ   )r*  r   rT   rQ   rQ   rR   r    r^   z,ImportNode.get_known_standard_library_importN)rX   rY   rZ   r   r   r   r   r"  r  rv  r  rQ   rQ   rQ   rR   r)  F  s    ,r)  c                       sZ   e Zd Zg ZdZdZdddZdd Zdd Zd	d
 Z	dd Z
 fddZdd Z  ZS )ScopedExprNodeNTc                 C   s<   |d ur	|| _ d S | jrt|| _ d S | j sd | _ d S d S rJ   )
expr_scopehas_local_scoper   ZComprehensionScope)rU   outer_scoperF  rQ   rQ   rR   
init_scope  s   

zScopedExprNode.init_scopec                 C      |  | d S rJ   )rI  r   rQ   rQ   rR   analyse_declarations  rL  z#ScopedExprNode.analyse_declarationsc                 C   r   rJ   rQ   r   rQ   rQ   rR   analyse_scoped_declarations  r  z*ScopedExprNode.analyse_scoped_declarationsc                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"    r  zScopedExprNode.analyse_typesc                 C   r(  rJ   rQ   r   rQ   rQ   rR   analyse_scoped_expressions  r  z)ScopedExprNode.analyse_scoped_expressionsc                    s>  t  j}| jr| jjs|| d S |d g }tdd | jj D D ]\}}|j	s8|j
jr8|jr8|| q%|sF|| |d d S | }| }|| | || |d}|| |j|fgtt| | D ]\}	}
||	r||	 | || ||
 qq|| |d || ||_d S )Nz{ /* enter inner scope */c                 s   s    | ]	}|d  r|V  qdS )r   NrQ   r   rQ   rQ   rR   re     s    z:ScopedExprNode.generate_evaluation_code.<locals>.<genexpr>z} /* exit inner scope */
exit_scope)rL   r{  rG  rF  var_entriesr   sortedentriesitemsr  r   rp   r  r   Znew_loop_labelsZnew_error_label_generate_vars_cleanup	new_labelput_gotoerror_labelr   zipZget_loop_labelsZ
label_used	put_labelZset_loop_labels)rU   r   Zgenerate_inner_evaluation_code
py_entriesr4  r   Zold_loop_labelsZold_error_labelrN  labelZ	old_labelrO   rQ   rR   r{    sB   
"











z'ScopedExprNode.generate_evaluation_codec                 C   s6   |D ]}|j r|| ||d q|| qd S )Nr*  )r  Zput_var_gotrefZput_var_decref_setZput_var_xdecref_clear)rU   r   rY  r   rQ   rQ   rR   rS    s   
z%ScopedExprNode._generate_vars_cleanuprJ   )rX   rY   rZ   r   rF  rG  rI  rK  rL  r"  rM  r{  rS  r[   rQ   rQ   rO   rR   rE    s    
,rE  c                
   @   s   e Zd ZeZdZdZdZdZdZ	dgZ
dd ZdZeeejedejdgZdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd ZdS )IteratorNodeNFsequencec                 C   s   | j r| j }| j|| _| jjjs| jjjr"| jjjs"| jj| _n=| jjjr2t| j	| jd|S | 
 rI| jjjd j}t| j	|dd|S | j|| _| jjttfv r_| jd| _d| _| S )N)r\  r   T)r\  reversed!'NoneType' object is not iterabler)   )rF  r\  r"  r   r6  r  rw  r   CppIteratorNoder   is_reversed_cpp_iteration	arg_tupler   r   r  r   r   r  r   )rU   rs   r\  rQ   rQ   rR   r"    s"   
zIteratorNode.analyse_typeszIterating over Python objectitc                 C   s   t | jtr| jjrt| jjjdksdS | jj}|jr?|jdkr?|j	j
s'dS | jjjd }t |tr?|jjr?|jj	}|jjS dS )z
        Returns True if the 'reversed' function is applied to a C++ iterable.

        This supports C++ classes with reverse_iterator implemented.
        r)   Fr]  r   )r}   r\  r  ra  r   r   r  r   rq   r   r  CoercionNoder   r   r   )rU   funcr   rQ   rQ   rR   r`  2  s   z&IteratorNode.is_reversed_cpp_iterationc                 C   s   | j | jp|S rJ   )r\  r3  rF  r   rQ   rQ   rR   r3  E  r   zIteratorNode.type_dependenciesc                 C   sP   | j |}|js|jr|S |jr!|jd}|d ur|jjS t
S |j	r&|S t
S )Nbegin)r\  r   r6  r  r   r  r  r   return_typerp   r   )rU   rs   sequence_typere  rQ   rQ   rR   r   H  s   zIteratorNode.infer_typec              	   C   s  | j j}|jrJ d|js|jrtd|ttfv }|s$| jr$J d|j	 | _
| j
r;|d| j  | j  f  |s@| j
r|d|  | j  |  f  |jjtjdd| _| jr|tu red}nd	}|d
| j||  f  |d ||| j| j |d |d| j  n|d| j  |s|jj| jdd| _| j
r|d| j  |d |d| j  |d|  | j  ||  | jf  | | || j d|   d ||| j| j | j
r|d d S d S )NFz+Should have been changed to CppIteratorNodez#for in carray slice not transformedzBinternal error: reversed() only implemented for list/tuple objectsz>if (likely(PyList_CheckExact(%s)) || PyTuple_CheckExact(%s)) {z%s = %s; __Pyx_INCREF(%s);r]  __Pyx_PyList_GET_SIZE__Pyx_PyTuple_GET_SIZEz%s = %s(%s);#if !CYTHON_ASSUME_SAFE_SIZE#endifz--%s;r  
%s = NULL;} else {z	%s = -1; %s = PyObject_GetIter(%s); %sT = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(); r   )r\  r   r   r6  r  r   r   r   r]  r  may_be_a_sequencer   r   r   rb  rc  r   r  counter_cnameerror_goto_if_negr   _func_iternext_typeiter_func_ptrputr   r  )rU   r   rg  Zis_builtin_sequenceZlen_funcrQ   rQ   rR   rv  T  sp   





z!IteratorNode.generate_result_codec                 C      | d d S Nz;;rv  rm  rQ   rQ   rR   generate_for_loop_header  rL  z%IteratorNode.generate_for_loop_headerc              
   C   s  | j sJ d|dv sJ d| d|   d}d}| jjr@t| jj}| jjd u r/|}d}nt| jjjt	r@|| jjj }d}|rM|
d| j |f  n4|
d	 |
d
tj|f  |
d |
|tj| j |
d |
d| j tjf  |
d | jrdnd}|dkr|
| d|   d| j  d|   d n1|
d |
| d|   d| j  d |
d |
| d|   d| j  d |
d |
| | j  d d S )Nz/internal error: counter_cname temp not prepared)ListTuple__Pyx_Pyz
_GET_SIZE(r  FTzif (%s >= %s) break;r6  zPy_ssize_t %s = %s;rj  rk  r   z--++r{  z = __Pyx_PyList_GetItemRefFast(r>  r?  <#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFSz! = __Pyx_NewRef(PyTuple_GET_ITEM());#elsez = __Pyx_PySequence_ITEM(r@  )rr  r   r\  r   r   r   r   r}   r~   r   r   r   quick_temp_cnamers  r   r]  r  )rU   Z	test_nameresult_namer   Z
final_sizeZsize_is_safe
item_countZinc_decrQ   rQ   rR   generate_next_sequence_item  sL   




"
"
z(IteratorNode.generate_next_sequence_itemc                 C   s  | j j}| jr|d| j d |tu r.| d|| |||| j |	|t
 d S |tu rK| d|| |||| j |	|t
 d S | jr|d| j  |d|    | d|| |d | d|| |d |||| j |d	 |d
 || d| j d|   d |d|  |d |d ||d| j |d |d |d |d |d |	|t
 d S )Nif (z < 0) break;r{  r|  zif (likely(!%s)) {z$if (likely(PyList_CheckExact(%s))) {rm  r   z} else r6  r;  (r?  r  z&PyObject* exc_type = PyErr_Occurred();zif (exc_type) {zA!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)r   break;)r\  r   r]  r   rr  r   r  r   r   r  r   r   rq  ru  r   rv  r   )rU   r  r   rg  rQ   rQ   rR   generate_iter_next_result_code  sD   



"






z+IteratorNode.generate_iter_next_result_codec                 C   s>   | j r
|j| j  | jr|j| j d | _t| | d S rJ   )rr  rb  rj  ru  r   r  rm  rQ   rQ   rR   r    s   zIteratorNode.free_temps)rX   rY   rZ   r   r   ru  rr  r]  is_asyncrG  r   r"  r  r   r  r  CFuncTypeArgrt  r`  r3  r   rv  rz  r  r  r  rQ   rQ   rQ   rR   r[    s.    ?(&r[  c                   @   sn   e Zd ZdZdZdZdZdZdgZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )r_  Nr  r  TFr\  c                 C   s   | j sdS dS )N)re  end)ZrbeginZrend)r]  rT   rQ   rQ   rR   get_iterator_func_names  rL  z'CppIteratorNode.get_iterator_func_namesc                 C   s  | j j}|jr
|j}|  \}}|j|}|j|}|d u s(|jjr(|jjr9t	| j
d|| j jf  t| _| S |d u sE|jjrE|jjrVt	| j
d|| j jf  t| _| S |jj}|jr|jd red| _|| j
d||jjgd u rt	| j
d|| j jf  t| _| S || j
d|gd u rt	| j
d|| j jf  t| _| S || j
d|gd u rt	| j
d|| j jf  t| _| S || _| S |jr||jjkst	| j
d	||f  || _| S t	| j
d
|| j jf  t| _| S )Nzmissing %s() on %s
cpp_localsr   !=z*missing operator!= on result of %s() on %sr~  z*missing operator++ on result of %s() on %sz)missing operator* on result of %s() on %sz$incompatible types for %s() and %s()z8result type of %s() on %s must be a C++ class or pointer)r\  r   r  r  r  r  r  r7  r   r   r   r0   rf  r   rk   extra_dereferencelookup_operator_for_types)rU   rs   rg  
begin_nameend_namere  r  Z	iter_typerQ   rQ   rR   r"    sl   

zCppIteratorNode.analyse_typesc                 C   s   | j j}|  \}}| j  r"|d|  | j  | j|f  d S |}|jr-t	|j
}|js6|jjd r9d| _|jj|dd| _|d| j|jrLdnd| j  f  |d|  | j| j|f  d S )	Nz%s = %s%s%s();r  ->Fr]  z
%s = %s%s;&r  )r\  r   r  r  r   r   cpp_attribute_opr   r   r  r  r  r   rk   rb  rc  cpp_sequence_cnamer   )rU   r   rg  r  r4  Z	temp_typerQ   rQ   rR   rv  +  s6   
z$CppIteratorNode.generate_result_codec                 C   sF   |   \}}|d| j|  | jp| j | j|| j|  f  d S )Nz; %s%s != %s%s%s(); ++%s%s)r  rv  r  r   r  r\  r  )rU   r   r4  r  rQ   rQ   rR   rz  V  s   z(CppIteratorNode.generate_for_loop_headerc                 C   s   | d|| j|  f  d S )Nz%s = *%s%s;)r   r  r   )rU   r  r   rQ   rQ   rR   r  c  s
   z.CppIteratorNode.generate_iter_next_result_codec                 C      | j sd S t| | d S rJ   )r  r   ry  rm  rQ   rQ   rR   ry  i     z.CppIteratorNode.generate_subexpr_disposal_codec                 C   r  rJ   )r  r   rz  rm  rQ   rQ   rR   rz  p  r  z"CppIteratorNode.free_subexpr_tempsc                 C   s.   | j st| | t| | t| | d S rJ   )r  r   ry  rz  r  rm  rQ   rQ   rR   r  w  s   z&CppIteratorNode.generate_disposal_codec                 C   s$   | j r
|j| j  t| | d S rJ   )r  rb  rj  r   r  rm  rQ   rQ   rR   r    s   zCppIteratorNode.free_temps)rX   rY   rZ   r  r  r  r   r]  r   r  r"  rv  rz  r  ry  rz  r  r  rQ   rQ   rQ   rR   r_    s     0+r_  c                   @   sB   e Zd ZdZdd Zdd Zdd Zdd	d
Zdd Zdd Z	dS )NextNodeTc                 C      t | |j || _d S rJ   r%  r  r   iteratorrU   r  rQ   rQ   rR   r       
zNextNode.__init__c                 C   r   rJ   rQ   r   rQ   rQ   rR   rO    r  zNextNode.nogil_checkc                 C   r  rJ   )r  r3  r   rQ   rQ   rR   r3    r  zNextNode.type_dependenciesNc                 C   s   |d u r
| j |}|js|jr|jS |jr*|| jd|gjj	}t
j|dd}|S t| j| j jt| jdt
jdd}||S )Nr   TZremove_fakerefPY_SSIZE_T_MAXrC  r9  )r  r   r  r6  r  r   r  r   r   rf  r   remove_cv_refr<  r\  r=  r  )rU   rs   Ziterator_typer   Zfake_index_noderQ   rQ   rR   r     s    
zNextNode.infer_typec                 C   sB   |  || jj}| jjjr|js|jpt| _| ||S || _| S rJ   )r   r  r   rp   r   r   r  )rU   rs   r   rQ   rQ   rR   r"    s   zNextNode.analyse_typesc                 C   s   | j |  | d S rJ   )r  r  r   rm  rQ   rQ   rR   rv    r  zNextNode.generate_result_coderJ   )
rX   rY   rZ   r   r  rO  r3  r   r"  rv  rQ   rQ   rQ   rR   r    s    
r  c                   @   sB   e Zd ZdgZdZeZdZdZdd Z	dd Z
d	d
 Zdd ZdS )AsyncIteratorNoder\  Tr)   Fc                 C   r/  rJ   r   r   rQ   rQ   rR   r     rW   zAsyncIteratorNode.infer_typec                 C   sB   | j r| j }| j|| _| jjjst| jd | j|| _| S )Nz*async for loops not allowed on C/C++ types)rF  r\  r"  r   rp   r   r   r  r   rQ   rQ   rR   r"    s   
zAsyncIteratorNode.analyse_typesc              	   C   N   |j tdd |d|  | j ||  | j	f  | 
| d S )N	AsyncIterCoroutine.cz)%s = __Pyx_Coroutine_GetAsyncIter(%s); %s)r   r   r   r   r   r   r\  r   r   r   r  rm  rQ   rQ   rR   rv       z&AsyncIteratorNode.generate_result_codec                 C   rw  rx  ry  rm  rQ   rQ   rR   rz    rL  z*AsyncIteratorNode.generate_for_loop_headerN)rX   rY   rZ   r   r  r   r   r   rG  r   r"  rv  rz  rQ   rQ   rQ   rR   r    s    	r  c                   @   s4   e Zd ZeZdZdd Zdd Zdd Zdd	 Z	d
S )AsyncNextNoder)   c                 C   r  rJ   r  r  rQ   rQ   rR   r    r  zAsyncNextNode.__init__c                 C   r/  rJ   r  r   rQ   rQ   rR   r     rW   zAsyncNextNode.infer_typec                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"    rW   zAsyncNextNode.analyse_typesc              	   C   r  )Nr  r  z*%s = __Pyx_Coroutine_AsyncIterNext(%s); %s)r   r   r   r   r   r   r  r   r   r   r  rm  rQ   rQ   rR   rv    r  z"AsyncNextNode.generate_result_codeN)
rX   rY   rZ   r   r   r   r  r   r"  rv  rQ   rQ   rQ   rR   r    s    r  c                   @   s2   e Zd ZddgZdgZdZdZdd Zdd	 ZdS )
WithExitCallNoder   
await_expr	with_statTNc                 C   s4   | j || _ | jr| j|| _tj| _d| _| S r+  )r   r"  r  r   r  r   r   r   rQ   rQ   rR   r"    s   zWithExitCallNode.analyse_typesc                 C   st  | j r|d| jj  | j| |jjtdd}|	| j
 |jtdd |d|| jj| j f  |j| jjtd | j| | j| |||| j
 ||t | jr| jj||dd	 |d
|| j f  | j| | j| | jr| | |d|  |f  |j|td | jr|| j
|   |j| | j r|d d S d S )N	if (%s) {Fr]  PyObjectCallr  z'%s = __Pyx_PyObject_Call(%s, %s, NULL);r  T)source_cnamedecref_sourcer  z%s = __Pyx_PyObject_IsTrue(%s);r   )test_if_runr   r  Zexit_varr   r{  rb  rc  r   ru  r   r   r   r   r   r   r  r  r  r   r  r  r   r  ra  re  r  rj  )rU   r   Z
result_varrQ   rQ   rR   r{    sB   

z)WithExitCallNode.generate_evaluation_code)	rX   rY   rZ   r   Zuptree_ref_attrsr  r  r"  r{  rQ   rQ   rQ   rR   r     s    r  c                   @   s8   e Zd ZefddZdd Zdd Zdd Zd	d
 ZdS )ExcValueNodec                 C      t j| ||d d S rT  )r%  r  )rU   r   r   rQ   rQ   rR   r  B  r  zExcValueNode.__init__c                 C   
   || _ d S rJ   var)rU   r  rQ   rQ   rR   set_varE  rM  zExcValueNode.set_varc                 C   r   rJ   r  rT   rQ   rQ   rR   r   H  r)  z"ExcValueNode.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  K  rW   z!ExcValueNode.generate_result_codec                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  N  rW   zExcValueNode.analyse_typesN)	rX   rY   rZ   r   r  r  r   rv  r"  rQ   rQ   rQ   rR   r  =  s    r  c                   @   sZ   e Zd Zg ZdddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )TempNodeNc                 C   s(   t | | || _|jrt| _d| _d S r'  )r   r  r   rp   r   r  r   )rU   r   r   rs   rQ   rQ   rR   r  ]  s
   
zTempNode.__init__c                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  d  rW   zTempNode.analyse_typesc                 C   
   d| _ d S r+  r  r   rQ   rQ   rR   r  g  rM  z#TempNode.analyse_target_declarationc                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  j  rW   zTempNode.generate_result_codec                 C   s   |j j| jdd| _d S )NTr]  )rb  rc  r   
temp_cnamerm  rQ   rQ   rR   allocatem  r  zTempNode.allocatec                 C   s   |j | j d | _d S rJ   )rb  rj  r  rm  rQ   rQ   rR   releasep  r  zTempNode.releasec                 C   s   z| j W S    J d)NFz-Remember to call allocate/release on TempNode)r  rT   rQ   rQ   rR   r   t  s   zTempNode.resultc                 C   r   rJ   rQ   rm  rQ   rQ   rR   re  |  rW   zTempNode.allocate_temp_resultc                 C   r   rJ   rQ   rm  rQ   rQ   rR   rk    rW   zTempNode.release_temp_resultrJ   )rX   rY   rZ   r   r  r"  r  rv  r  r  r   re  rk  rQ   rQ   rQ   rR   r  R  s    	
r  c                   @      e Zd Zdd ZdS )
PyTempNodec                 C   s   t | |tj| d S rJ   )r  r  r   r   )rU   r   rs   rQ   rQ   rR   r    r  zPyTempNode.__init__NrX   rY   rZ   r  rQ   rQ   rQ   rR   r        r  c                   @   s:   e Zd Zg ZdddZdd Zdd Zdd	 Zd
d ZdS )RawCNameExprNodeNc                 C   s&   t j| ||d |d ur|| _d S d S rT  )r   r  r   )rU   r   r   r   rQ   rQ   rR   r    s   
zRawCNameExprNode.__init__c                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"    rW   zRawCNameExprNode.analyse_typesc                 C   r  rJ   r   )rU   r   rQ   rQ   rR   	set_cname  rM  zRawCNameExprNode.set_cnamec                 C   r   rJ   r  rT   rQ   rQ   rR   r     r)  zRawCNameExprNode.resultc                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv    rW   z%RawCNameExprNode.generate_result_coder  )	rX   rY   rZ   r   r  r"  r  r   rv  rQ   rQ   rQ   rR   r    s    
r  c                   @   s6   e Zd ZeZdZdZdgZdd Zdd Z	dd	 Z
d
S )JoinedStrNodeTzString concatenationvaluesc                        fdd| j D | _ | S )Nc                    s   g | ]
}|   qS rQ   )r"  r  )ra   vry   rQ   rR   r         z/JoinedStrNode.analyse_types.<locals>.<listcomp>)r  r   rQ   ry   rR   r"    s   zJoinedStrNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r    r  zJoinedStrNode.may_be_nonec              
      s  | | j t| j}|dk }t }d}| jD ]*}t|tr&t|| }qt|t	r6|j
dkr6|jjjr6qt|tr<q|| qg }i  t|g}| jD ]A}|| t|trbtt|j}	nd|  d}	||v ry|d|  d |	 v r |	  d7  < qN||	 d |	< qN|r|jjttj|dd	}
n,|jjttjdd	}
|d
|
|f  |d|
  |d|| j  |d t| jD ]\}}|d|
|| f  qч fdd|D }| | j | | |jt !dd |d| " |
|d#|d#|f  |s|d|
  |j$|
 ||%|  | j | &| | jD ]}|'| |(| q8d S )N    r  cz__Pyx_PyUnicode_GET_LENGTH(r  z__Pyx_PyUnicode_MAX_CHAR_VALUE(r)   Fr]  z7%s = (PyObject **) PyMem_Calloc(%d, sizeof(PyObject*));r  zPyErr_NoMemory(); %sr   z%s[%d] = %s;c                    s.   g | ]} | d kr| d |  n|qS )r)   z * rQ   )ra   partcountsrQ   rR   r     s     z:JoinedStrNode.generate_evaluation_code.<locals>.<listcomp>ZJoinPyUnicodeStringTools.cz*%s = __Pyx_PyUnicode_Join(%s, %d, %s, %s); +  | zPyMem_Free(%s);))ru  r   r   r  setr}   r:  r  r  FormattedValueNodec_format_specr   r   r]  	CloneNodeaddrw   r{  r   r   rb  rc  r   c_array_typer   r  r   r   	enumeratere  r   r   r   r   r   rA  rj  r   r  r  r  )rU   r   	num_itemsZuse_stack_memoryZunknown_nodesZmax_char_valuer   Zlength_partsZcharval_partsZlength_partZvalues_arrayirQ   r  rR   r{    s~   

















z&JoinedStrNode.generate_evaluation_codeN)rX   rY   rZ   r   r   r   r  r   r"  r  r{  rQ   rQ   rQ   rR   r    s    r  c                   @   sL   e Zd ZddgZeZdZdZdZdddd	d
j	Z
dd Zdd Zdd ZdS )r  r   format_specTNzString formattingZPyObject_StrZPyObject_ReprZPyObject_ASCIIZ__Pyx_PyNumber_Long)sradc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  #  r  zFormattedValueNode.may_be_nonec                 C   s   | j || _ | j j }| jr| jjr*| jr| jj n|j}| j jj||dr*|| _| jr7| j|	|| _| jd u rZ| j 	|| _ | jsZ| j
rN| j
dkrZ|tu rZ| j  sZ| j S | S )N)r  r  )r   r"  r   r  r  r   Zdefault_format_specZcan_coerce_to_pystringr  r  conversion_charr   r  )rU   rs   Zresolved_typer  rQ   rQ   rR   r"  '  s   
z FormattedValueNode.analyse_typesc           	      C   st  | j d ur1| jjjs1| jj| j || j }|d|  |||  | jf  | 	| d S | j
 }| jjtu oA| j  }| jrMd}| j
 }nd}|tj}| j}|dkr`|r`d }|r| |}|d usqJ d| d||f }|jtdd |d	7 }n| jr|jtd
d n
|jtdd |d|  |||||  | jf  | 	| d S )N%s = %s; %sZ__Pyx_PyObject_FormatZ__Pyx_PyObject_FormatSimpler  z(invalid conversion character found: '%s'%s(%s)ZPyObjectFormatAndDecrefr  Z	AndDecrefZPyObjectFormatZPyObjectFormatSimple%s = %s(%s, %s); %s)r  r   r   rp   Zconvert_to_pystringr   r   r   r   r  r   r   r  r  r  r   empty_unicoder  find_conversion_funcr   r   r   r   )	rU   r   Zconvert_func_callZvalue_resultZvalue_is_unicodeZformat_funcr  r  fnrQ   rQ   rR   rv  9  sX   






z'FormattedValueNode.generate_result_code)rX   rY   rZ   r   r   r   r   r  r  rj   r  r  r"  rv  rQ   rQ   rQ   rR   r    s     r  c                   @   .   e Zd ZdZejZdd Zdd Zdd Z	dS )	ParallelThreadsAvailableNodea*  
    Note: this is disabled and not a valid directive at this moment

    Implements cython.parallel.threadsavailable(). If we are called from the
    sequential part of the application, we need to call omp_get_max_threads(),
    and in the parallel part we can just call omp_get_num_threads()
    c                 C   
   d| _ | S r+  rW  r   rQ   rQ   rR   r"  |     z*ParallelThreadsAvailableNode.analyse_typesc                 C   sR   | d | d| j  | d| j  | d | d| j  | d d S )N#ifdef _OPENMPz2if (omp_in_parallel()) %s = omp_get_max_threads();z else %s = omp_get_num_threads();r  z%s = 1;rk  r   r   rm  rQ   rQ   rR   rv    s   

z1ParallelThreadsAvailableNode.generate_result_codec                 C   r   rJ   r   rT   rQ   rQ   rR   r     r)  z#ParallelThreadsAvailableNode.resultN
rX   rY   rZ   r$  r   rg  r   r"  rv  r   rQ   rQ   rQ   rR   r  q  s    	r  c                   @   r  )	ParallelThreadIdNodez/
    Implements cython.parallel.threadid()
    c                 C   r  r+  rW  r   rQ   rQ   rR   r"    r  z"ParallelThreadIdNode.analyse_typesc                 C   sB   | d | d| j  | d | d| j  | d d S )Nr  z%s = omp_get_thread_num();r  r  rk  r  rm  rQ   rQ   rR   rv    s
   

z)ParallelThreadIdNode.generate_result_codec                 C   r   rJ   r  rT   rQ   rQ   rR   r     r)  zParallelThreadIdNode.resultNr  rQ   rQ   rQ   rR   r    s    r  c                   @   $   e Zd Zdd Zdd Zdd ZdS )_IndexingBaseNodec                 C   s   | j  p| j jtttfv S rJ   )r:  r   r   r   r   r   rT   rQ   rQ   rR   r     s   z_IndexingBaseNode.is_ephemeralc                 C   s   | j  o	| j S rJ   )r:  rV  r;  r#  rT   rQ   rQ   rR   rV    r  z"_IndexingBaseNode.check_const_addrc                 C   s*   | j jr| j jjrdS dS | j jrdS dS r  )r   r   r  r6  r  rT   rQ   rQ   rR   r     s   
z_IndexingBaseNode.is_lvalueN)rX   rY   rZ   r   rV  r   rQ   rQ   rQ   rR   r    s    r  c                   @   s  e Zd ZddgZdZdZdZdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd?ddZdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd@d,d-Zd.d/ Zd0Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z 		dAd9d:Z!d;d< Z"dBd=d>Z#dS )Cr<  r:  r;  NTFc                 C   s   | j j| jj | _d S rJ   )r:  r~   r;  rT   rQ   rQ   rR   r    r  z#IndexNode.calculate_constant_resultc              
   C   sT   | j |}| j|}z|| W S  ty) } z| | W Y d }~d S d }~ww rJ   )r:  r  r;  r  r  )rU   r  r:  r;  r  rQ   rQ   rR   r    s   
zIndexNode.compile_time_valuec                 C   s.   | j }| o| j o|jo|jjp|jjS rJ   )r:  r  r;  r   r  r6  rU   r:  rQ   rQ   rR   r    s   zIndexNode.is_simplec                 C   sH   | j j}|r|jrdS |tttfv rdS t| jtr|j	rdS t
| S rR  )r:  r   rw  r   r   r   r}   r;  	SliceNoder  r   r  rU   r  rQ   rQ   rR   r    s   
zIndexNode.may_be_nonec                 C   r   rJ   rQ   r   rQ   rQ   rR   r    rW   z$IndexNode.analyse_target_declarationc              	   C   s  | j  }|d urp|dv rp| j|}|d u r$t| j jd| d d S |dkr-t|S |dk}| }|jrV|j	rE|rCt| j jd d}|j
rS|rQt| j jd d}|j}|jrgt| j jd	| d
| d tj||| dS | j |}|r|js~|jr| jjr| jj}n| jg}tj| j|d d}|j||dS | jjs| jjrddlm} |||jj | jjr| jgnt| jj}	t||||	S |js| j |}
|
d urzt!|
}
W n t"t#fy   Y nw t$||
S t| jd d S )N)pointerconstZvolatilezinvalid use of 'z', argument is not a typer  r  zDuplicate 'const'TzDuplicate 'volatile'z(Cannot declare memory view variable as 'z'. Did you mean 'z[item_type][:]' ?)r  is_volatile)r   positional_argskeyword_args)r  r)   r  z*Array size must be a compile time constant)%r:  r  r;  rC  r   r   r   r  r  r  r  r  r   c_const_or_volatile_typer   python_type_constructor_namer   r   r   ZTemplatedTypeNodeanalyser   r  r  r   get_view_utility_coder/  shared_utility_qualified_namer   MemoryViewSliceTypeget_axes_specsrp   r  r   r   r   
CArrayType)rU   rs   modifierr  r  r  Ztemplate_valuesZ	type_noder  axesr;  rQ   rQ   rR   rC    sv   


zIndexNode.analyse_as_typec                 C   sR   g }| }|j r'|j|}|r!|jr!|jr!|| rdn|j |j}|j s|S Nztyping.Optional)r  r:  rC  r  Zmodifier_namer   Zallows_noner;  )rU   rs   r  Zmodifier_nodeZmodifier_typerQ   rQ   rR   analyse_pytyping_modifiers?  s   
z$IndexNode.analyse_pytyping_modifiersc                 C      | j || j| S rJ   )r:  r3  r;  r   rQ   rQ   rR   r3  M  r  zIndexNode.type_dependenciesc                 C   sh  | j |}| jjr&|jrtS |jrtS |tttt	t
fv r|S |jr$|S tS | j|}|r1|js7t| jtr|tu r>tjS |tu sF|tu rItjS |t
t	tfv rat|| j | j|d}|d ur`|S nc|jsg|jrj|jS |jrt| jtr| j r| jj}|dk r||j7 }d|  kr|jk rn n|j| S t|j}t|dkr| S n|jr|j dkr	 |j dkr|j!S t"|j!|j#dd  S | jj$r|jr|}| jj%D ]}|js nt&| j't(| j j'|d|d|}q|S |j)rG dd d}	|	| j'|d|	| j'|dg}
|*d	|
}|d ur|j+j,S t-|r+t-|r+| j|f}t.t/||gS |tu r2|S tS )
Nr   r   r)   r  r9  c                   @   r  )z)IndexNode.infer_type.<locals>.FakeOperandc                 [   r!  rJ   )__dict__update)rU   rP  rQ   rQ   rR   r    r   z2IndexNode.infer_type.<locals>.FakeOperand.__init__Nr  rQ   rQ   rQ   rR   FakeOperand      r	  )r   r   [])0r:  r   r;  r   rw  r   rx  r   r   r   r   r   r   r  r}   r=  r   r   r   r   r   r  r6  r  r  r   r~   r$  r  r  r   r   ndimr  r  r  r   r   r<  r   r   r   lookup_operatorr   rf  r;   rG   rA   )rU   rs   r  
index_typer   r;  r   r  r  r	  operandsZ
index_funcZindex_with_typerQ   rQ   rR   r   P  s   








zIndexNode.infer_typec                 C   s   | j || _ | j|ddS )NTgetting)r:  r"  analyse_base_and_index_typesr   rQ   rQ   rR   r"       zIndexNode.analyse_typesc                 C   sV   | j || _ | j|dd}|jjrt| jd || u r)| s)t| jd|j  |S )NT)settingzAssignment to const dereference%Assignment to non-lvalue of type '%s')r:  r"  r  r   r  r   r   r   r$  rQ   rQ   rR   r*    s   zIndexNode.analyse_target_typesc                 C   s  | j jjrtj| _| S | jj}|jd s%|r t| jj	| jj
 nt| j |s;t| jtr;t| jjr;| j|| _| j jj}|s`t| j tsJ|r`| j jjsY| j jjs`| j jjs`| j || _ | ||}|d url|S |j| _| j j}|js| j|| _| jj| _| jjr| jj| _|jr|rt| jddd n	| jj dv r| j S | j || _ | j j}|j!r| "||||S |js|jr| #||S |j$r| %||S |jr| &|S |j'r| (|||S t)| jd|  tj| _| S )N
wraparoundz%cannot assign to Unicode string indexr)   r{   )r   r,  z'Attempting to index non-array type '%s')*r:  r   r  r   r0   r;  r   rk   r   r   r   r}   r=  r   Zlong_literalr   r  r   r9  rw  r  r6  analyse_as_buffer_operationr   r7  r"  original_index_typer   r  r  r   r   r~   rp   analyse_as_pyobjectanalyse_as_c_arrayr   analyse_as_cppanalyse_as_c_functionr  analyse_as_c_tupler   )rU   rs   r  r  r   Zis_memslicereplacement_noder  rQ   rQ   rR   r    s`   






z&IndexNode.analyse_base_and_index_typesc                 C   s  | j j}| jjjr |tur t| jddd | j|| _d| _nV| jjj	rl|turl|rV|j
d sV|tttfv rV| jjjrR|j
d rRt| jtrV| j rV| jjdkrVd| _nd| _| jtj||| _| j| n
| j|| _d| _| o}| jjj	}|r|tu rtj| _n`|r|ttfv r|rtj| _nQtj| _nL|r|tttttfv r|| _n=d }|r|ttfv rt|| j | j|d}n| j jrt|| j |d}|tttfv r| j  d| _ |d u s|j!st"| _n|| _| #|| | S )	NzItem lookup of unicode character codes now always converts to a Unicode string. Use an explicit C integer cast to get back the previous integer lookup behaviour.r)   r{   boundscheckr  r   r  &'NoneType' object is not subscriptable)$r:  r   r;  r  r   r   r   r  r   r  rk   r   r   r   signedr}   r=  r   r~   r  r   r  r0  r  create_to_py_utility_coder   r   r   r   rg  r   r   r  rp   r   wrap_in_nonecheck_node)rU   rs   r   r  r  r  Zis_int_indexingr   rQ   rQ   rR   r    sb   



zIndexNode.analyse_as_pyobjectc                 C   sv   | j j}|j| _| jjrt| j| _|r|| _| S | jjjr*| jtj	|| _| S | jjj
s9t| jd| jj  | S )NzInvalid index type '%s')r:  r   r  r   r   CReferenceTyper;  rp   r  r  r  r   r   )rU   rs   r   r  rQ   rQ   rR   r  =  s   

zIndexNode.analyse_as_c_arrayc                 C   s   | j j}|d| j | jg}|d u r't| jd|| jjf  tj| _d| _| S |j}|j	r0|j
}|j| _|j| _| jrM|s@d| _t| rM|tdd | j|jd j|| _|j| _|rl|jjslt| jd| j  | S )	Nr  z/Indexing '%s' not supported for index type '%s'r  TCppExceptionConversionr  r   z#Can't set non-reference result '%s')r:  r   r  r;  r   r   r   r0   r_  r  r  r   r   r   r   r   r   r   r  r   rf  r   )rU   rs   r  r  r  	func_typerQ   rQ   rR   r  J  s,   zIndexNode.analyse_as_cppc                 C   s   | j j}|jr| | | S | || _d | _|jd u r't| j	d t
| _| S | jd u r1t
| _| S t|jt| jkrPt| j	dt|jt| jf  t
| _| S |tt|j| j| _| S )Nz)Can only parameterize template functions.z7Wrong number of template arguments: expected %s, got %s)r:  r   rD  parse_indexed_fused_cdefparse_index_as_typestype_indicesr;  Z	templatesr   r   r0   r   rF  dictrW  rU   rs   r  rQ   rQ   rR   r  b  s*   


zIndexNode.analyse_as_c_functionc                 C   s   | j j}t| jtrC| j rC| jj}|j |  kr |jk r3n n|dk r+||j7 }|j| | _| S t	| j
d||f  tj| _| S | j || _ | j|||dS )Nr   zIndex %s out of bounds for '%s'r  r  )r:  r   r}   r;  r=  r   r~   r$  r  r   r   r   r0   r  r  )rU   rs   r  r  r  r;  rQ   rQ   rR   r  x  s"   
zIndexNode.analyse_as_c_tuplec                    s  t | jtr| jj}n| jg}| j}|j}d}|jrRddlm} |j	r4|
|}|dur4|j}|j}|}|||j\}	}}
|	rIt| j||d}not| j||d}nf|jsX|jr|jsbt||jkrd} fdd|D }|jrtdd	 |D }|rt|D ]\}}|jrt|j|j|j|jd
}| }|||< qn	tdd	 |D }|rt| j||d}t | jtrJ |dur| |}|S )zI
        Analyse buffer indexing and memoryview indexing/slicing
        Nr)   r  )indicesr:  Tc                    r2  rQ   r'  ra   r;  ry   rQ   rR   r     r   z9IndexNode.analyse_as_buffer_operation.<locals>.<listcomp>c                 s   s&    | ]}|j jp|jp|j jV  qd S rJ   )r   r  r   r;   r.  rQ   rQ   rR   re     s
    
z8IndexNode.analyse_as_buffer_operation.<locals>.<genexpr>r   r   r   c                 s   s    | ]}|j jV  qd S rJ   r   r  r.  rQ   rQ   rR   re     rf   )r}   r;  	TupleNoder   r:  r   r   r  r  r  merged_indicesunellipsifyr  MemoryViewSliceNoder   MemoryViewIndexNoder  r;   r   r   r  r   SliceIntNoder   r   r   r"  BufferIndexNoder  )rU   rs   r  r-  r:  r  r  r  r2  have_slicesnewaxesr  Zdo_replacementr  r;  rQ   ry   rR   r    sP   


z%IndexNode.analyse_as_buffer_operationc                 C   s*   |j d r
| j sd S | jd| _d S )N	nonecheckr   )rk   r:  r  r  rU   rs   r  rQ   rQ   rR   r#    s   z IndexNode.wrap_in_nonecheck_nodec                 C   sb   t | jtr| jj}n| jg}g }|D ]}||| |d d u r.|r+t|jd  d S q|S )Nr,  znot parsable as a type)r}   r;  r1  r   r   rC  r   r   )rU   rs   requiredr-  r)  r;  rQ   rQ   rR   r(    s   
zIndexNode.parse_index_as_typesc                    sB  t j| _d| _| jj}g }| jjs| jjr|| jj	 nt
| jtr0| jjD ]}||j	 q'| j|dd}|du rq| j|| _| jjjsNt| j	d n| jjj | j_| _| jj | j_| _d| j_d| _d| j_d| _dS t|D ]\}}||||< qu| }t|t|krt| j	dS t|t|k r|t| }	t| j	d|	 S t|||D ]"\}
 }t fdd	|jD st|
d
  S  du sΈ jr dS qtt||}||}|jrt| j	d dS | jj D ]-}| |r|| _| jjr|j| _d| _| jj!| _!d| jj_|| j_|j| j_ dS qt"d)aK  
        Interpret fused_cdef_func[specific_type1, ...]

        Note that if this method is called, we are an indexed cdef function
        with fused argument types, and this IndexNode will be replaced by the
        NameNode with specific entry just after analysis of expressions by
        AnalyseExpressionsTransform.
        TF)r<  Nz)Can only index fused functions with typeszToo many types specifiedzHNot enough types specified to specialize the function, %s is still fusedc                    s   g | ]}  |qS rQ   )r  r`   Zspecific_typerQ   rR   r   
  r   z6IndexNode.parse_indexed_fused_cdef.<locals>.<listcomp>zType not in fused typez6Index operation makes function only partially specificz!Couldn't find the right signature)#r   r0   r   is_fused_indexr:  r;  r   r  r   r   r}   r1  r   r(  r"  r   r  r   r   r  r  Zspecialize_fusedZget_fused_typesr   rW  rl   typesr  r*  rF  rD  r  r  r  r   )rU   rs   r  Z	positionsr   Zspecific_typesr  r   Zfused_typesrb   r   Z
fused_typerE  r  rQ   r=  rR   r'    sv   	





z"IndexNode.parse_indexed_fused_cdefzIndexing Python objectc                 C   s
  | j jtttfv r,| j jtu rd}ng| j jtu rd}n^| j jtu r$d}nUJ d| j j | j jjrCd| j  ddd	 | jD f S | j jj	r`| j
j}|d
k rW|| j jj7 }d| j  |f S | jjsh| jjrw| j| j jkrwt| jd d S d}|| j  | j
 f S )Nz__Pyx_PyList_GET_ITEM(%s, %s)z__Pyx_PyTuple_GET_ITEM(%s, %s)z5((unsigned char)(__Pyx_PyByteArray_AsString(%s)[%s]))Fz$unexpected base type in indexing: %sz%s<%s>r7  c                 S      g | ]}|  qS rQ   )r  )ra   paramrQ   rQ   rR   r   ?      z3IndexNode.calculate_result_code.<locals>.<listcomp>r   z%s.f%szInvalid use of pointer slicez(%s[%s]))r:  r   r   r   r   r7  r   rA  r)  r  r;  r~   r$  r  r6  r   r   )rU   
index_coder;  rQ   rQ   rR   r   /  s.   

zIndexNode.calculate_result_codec              	   C   s   | j jjrd| jjtu }t|jjd o$| jj	o$t
| j jto#| j jdk }t|jjd }| j }| j }| jjtu rM|sM|rM|jjd rMt| jdd d| j | jj	rXdpYd| jj|||||f S dS )	Nr  r   r  Zfreethreading_compatiblezIndexing a bytearray with 'boundscheck' enabled and without the GIL is not thread-safe on freethreaded Python (disable 'boundscheck' to turn off this warning)r)   z , %s, %d, %s, %d, %d, %d, %d, %sr  )r;  r   r  r:  r   r.  r   rk   r  r!  r}   r~   r   rr  r  r   r   r   r  Zto_py_function)rU   r   Zis_listr  r  Zhas_gilZunsafe_sharedrQ   rQ   rR   extra_index_paramsL  s4   




zIndexNode.extra_index_paramsc                 C   s  | j sd S | jj}d }d }| jjrbd}| jjjr/|tu rd}n	|tu r&d}nd}t	dd}n|t
u r<d}t	dd}n|tu rO| jjtu rOd	}t	dd}nvd
}|jt	dd t	dd}nc| jjr||tu r|| jjjsqJ d}d}t	dd}nI|tu r| jjjsJ | jjsJ d}d}t	dd}n-|tu r| jjjsJ | jjsJ d}d}t	dd}n|jr| jsJ d| j|| jf |d ur|j| | jjjr| j }n| j }|jr
| jr
t|| jd|  | j | j f | jjr|  nd | j| j n)|dkrdnd| }|d|  || j || ||||   | jf  | jjr?| | d S d S )Nr3  Z__Pyx_GetItemInt_ListZ__Pyx_GetItemInt_TupleZ__Pyx_GetItemIntZ
GetItemIntr  Z__Pyx_PyDict_GetItemZDictGetItemZ__Pyx_PyObject_Dict_GetItemZ__Pyx_PyObject_GetItemZObjectGetItemZ__Pyx_GetItemInt_Unicodez(Py_UCS4)-1ZGetItemIntUnicoder  Z__Pyx_GetItemInt_Bytesz-1ZGetItemIntBytesZ__Pyx_GetItemInt_ByteArrayZGetItemIntByteArrayFz5unexpected type %s and base type %s for indexing (%s)z%s = %s[%s];!%sz	%%s == %s%s = %s(%s, %s%s); %s)r   r:  r   rp   r;  r  r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r   rr  r   rD  r   r  )rU   r   r  r  Zerror_valuer  rC  Zerror_checkrQ   rQ   rR   rv  g  s   





zIndexNode.generate_result_codec                 C   s   | j jjr*| jjtu r|jtdd d}n|jtdd d}| j 	 }n| j 
 }| jjtu r8d}nd}||d	|| j
 ||| |f | j d S )
NZSetItemIntByteArrayr  Z__Pyx_SetItemInt_ByteArrayZ
SetItemIntr  Z__Pyx_SetItemIntr  ZPyObject_SetItemz%s(%s, %s, %s%s))r;  r   r  r:  r   r   r   r   r   r   r   r   r   rs  rD  r   )rU   
value_coder   r  rC  rQ   rQ   rR   generate_setitem_code  s2   



	
zIndexNode.generate_setitem_codec              	   C   s  |  | | jjr| | | ng| jjtu r%| ||}| || nT| jjjrl| j	rl| j	dkrl|rO|rO| j
|krOt|| j| j|  | | j
|| j n*t|| jd|  | f | jjrd|  nd | j
| j n|d|  | f  | | | | || || d S )Nr   r  )rt  r   rp   rH  r   r:  r   _check_byte_valuer   r   r   r   r   r   rr  r   r   ry  rz  r  r  )rU   r   r   r  r   r   rG  rQ   rQ   rR   r    s0   



z"IndexNode.generate_assignment_codec                 C   s  |j jsJ t|j | }| r.d|j  krdk r |S  d}t|jd|j dd n|j tj	k}| j
s|g }|js@|j jrG|d|  |jsY| rY|j tj	tjtjfv s`|d|  |r||d	d
|  |d|| j  |d |rd| }|S )Nr      Tz9value outside of range(0, 256) when assigning to byte: %sr)   r{   z%s < 0z%s > 255if (unlikely(%s)) {z || zFPyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); %sr   z((unsigned char)%s))r   r  r=  r   r   r~   r   r   r   r   r   r   r!  r   rX  r   c_schar_typer   rA  r   )rU   r   r   rG  Z
needs_cast
conditionsrQ   rQ   rR   rI    sJ   

zIndexNode._check_byte_valuec                 C   s   |  | | jjjrd}| j }|jtdd n| j	 }| j
jtu r*d}nd}||d|| j
	 || |f | j | | | | d S )NZ__Pyx_DelItemIntZ
DelItemIntr  ZPyDict_DelItemZPyObject_DelItemz%s(%s, %s%s))rt  r;  r   r  r   r   r   r   r   r   r:  r   r   rs  rD  r   ry  rz  )rU   r   r  r  rC  rQ   rQ   rR   r    s,   





z IndexNode.generate_deletion_code)FFTr  r  )$rX   rY   rZ   r   r)  r  r>  r  r  r  r  r  rC  r  r3  r   r"  r*  r  r  r  r  r  r  r  r#  r(  r'  r  r   rD  rv  rH  r  rI  r  rQ   rQ   rQ   rR   r<    sH    
C]
	D?5
[O!
!$r<  c                       s   e Zd ZdZddgZdZdZdZdd Zd$d	d
Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd%ddZd&ddZd d! Z fd"d#Z  ZS )'r7  z
    Indexing of buffers and memoryviews. This node is created during type
    analysis from IndexNode and replaces it.

    Attributes:
        base - base node being indexed
        indices - list of indexing expressions
    r:  r-  TFrQ   c                 C   s   | j |dd d S NFr  r'  r   rQ   rQ   rR   r*  I  r   z$BufferIndexNode.analyse_target_typesc                 C   s   | j jst| j jst| jd t| _| S |s2| j jjjs$t| jd nd| _	| j jj
r2d| j jj_	d| _| || | | | S )zz
        Analyse types for buffer indexing only. Overridden by memoryview
        indexing and slicing subclasses
        zCan only index buffer variableszWriting to readonly bufferTr   )r:  r   r;   r   r   r   r0   r   writabler  r  Z
buffer_auxnone_error_messageanalyse_buffer_indexr#  r;  rQ   rQ   rR   r"  L  s   

zBufferIndexNode.analyse_typesc                 C   s|   t | jjrdd | jD }tt| jj|| _n| j|| _| jjj| _| jj| _|r:| jj	s5| jj r<d| _
d S d S d S )Nc                 S   s   g | ]}||j fqS rQ   r  )ra   idxrQ   rQ   rR   r   f  r   z8BufferIndexNode.analyse_buffer_index.<locals>.<listcomp>T)r;   r:  r   r-  rG   rA   r0  r  buffer_typerp   r   )rU   rs   r  Zindex_with_type_listrQ   rQ   rR   rR  d  s   

z$BufferIndexNode.analyse_buffer_indexc                 C   rS   )zk
        Called by IndexNode when this node is assigned to,
        with the rhs of the assignment
        NrQ   rU   r   rQ   rQ   rR   analyse_assignmentp  s    z"BufferIndexNode.analyse_assignmentc                 C   s,   |j d r
| j sd S | j| j| _d S )Nr:  )rk   r:  r  r  rQ  r   rQ   rQ   rR   r#  v  s   z&BufferIndexNode.wrap_in_nonecheck_nodec                 C   s2   | j s| jr| jjrt| jd t| _d S d S d S )Nz2Cannot access buffer with object dtype without gil)r  r  r   rp   r   r   r0   r   rQ   rQ   rR   rO  {  s   
zBufferIndexNode.nogil_checkc                 C   s
   d| j  S Nr  )buffer_ptr_coderT   rQ   rQ   rR   r     rM  z%BufferIndexNode.calculate_result_codec                 C   s    | j }| j jr
|j}|j|S rJ   )r:  is_nonecheckr   r   Z	get_entryr  rQ   rQ   rR   buffer_entry  s   zBufferIndexNode.buffer_entryc                 C   sD   |j jt|j|jjrtjntjdd}|d||	 f  |S )NFr]  r  )
rb  rc  r   rX  r   r!  Zc_ssize_t_typec_size_t_typer   r   )rU   r   ivarretrQ   rQ   rR   get_index_in_temp  s   z!BufferIndexNode.get_index_in_tempc                    s   j rjs	jr jjd rtjd j  fddjD  _}ddl	m
}  }|jjr8|jj}n|jd }||j|dd jD | jjj |j d	fS )
z8
        ndarray[1, 2, 3] and memslice[1, 2, 3]
        r  z(Use boundscheck(False) for faster accessc                    s   g | ]}  |qS rQ   )r^  ra   r\  r   rU   rQ   rR   r         z6BufferIndexNode.buffer_lookup_code.<locals>.<listcomp>r)   r  negative_indicesc                 S   s   g | ]}|j jqS rQ   )r   r!  r_  rQ   rQ   rR   r     rB  )r   Zindex_signedsZindex_cnamesrk   r   r   rb  rr  )rr  r  r  r   rk   r+   r   r-  index_tempsr  r  rZ  r   r  rb  Zbuffer_defaultsZput_buffer_lookup_code)rU   r   rc  r  rZ  rb  rQ   r`  rR   buffer_lookup_code  s&   

z"BufferIndexNode.buffer_lookup_codec                 C   sB   |  | | || | | | | || || d S rJ   )rt  generate_buffer_setitem_codery  rz  r  r  rU   r   r   r  rQ   rQ   rR   r    s   



z(BufferIndexNode.generate_assignment_coder  c           
      C   sL  | j j}t|rGt|jrG|jjtt| j jdd}|d|  |d||| j 	 f  |d|t
| j||	 f  |j| d S | |\}}| jjjr|jj|jdd}| }	|d||f  |d| | jj |d|	|f  |d	|||	f  |d| | jj |j| d S |d	||| f  d S )
NFr]  __Pyx_call_destructor(%s);r  z%s%s %s= %s;r  z*%sz%__Pyx_INCREF(%s); __Pyx_XDECREF(*%s);z*%s %s= %s;)r:  r   r;   r9   rb  rc  rG   rC   r   r   r@   r-  rj  rd  rT  r  rp   Zbuf_ptr_typer   r  r  )
rU   r   r   opr  r  rZ  Zptrexprptrr   rQ   rQ   rR   re    s8   	

z,BufferIndexNode.generate_buffer_setitem_codec                 C   s   t | jjr$|  }|d|  |d||| j t| jf  d S | |\}| _	| jj
rP|  }|d|| j	f  |d||f  |d|  d S d S )Nrg  new (&%s) decltype(%s){%s%s};z%s = (PyObject *) *%s;z'if (unlikely(%s == NULL)) %s = Py_None;z__Pyx_INCREF((PyObject*)%s);)r;   r:  r   r   r   r   r@   r-  rd  rX  rp   )rU   r   resrZ  rQ   rQ   rR   rv    s"   z$BufferIndexNode.generate_result_codec                    s.   | j D ]}|j| qd| _ t | d S r  )rc  rb  rj  rL   rz  )rU   r   temprO   rQ   rR   rz    s   
z"BufferIndexNode.free_subexpr_tempsrN  r  )r  )rX   rY   rZ   r$  r   r  r  rc  r*  r"  rR  rV  r#  rO  r   rZ  r^  rd  r  re  rv  rz  r[   rQ   rQ   rO   rR   r7  5  s(    	
	

*r7  c                   @   s6   e Zd ZdZdZdddZdd Zdd Zd	d
 ZdS )r5  TFc                 C   s<  ddl m} t|| _| j}||| jjj\}}}|s-d| _	| jj
s'| jjr-d| jjj_	| o8t|| jjjk| _g }tj}g }	t|t| | jjjkrbt| _t|| jjj jd| jj  | S d}
t|D ]\}}||}|jrd| _|	| |d qh| jjj|
 \}}|
d7 }
|jrd| _|jjr|||f n||df dD ]}t||}|js|||}t||| |	| qqh|jjs|jj r|jj rt!|jd	| d| _"|||}|||< |	| qht| _t|jd
|j  |   S | j"o| j | _"|	| _|| _#|j$| _$| %|||}|&| |S )Nr)   r  Tz&Too many indices specified for type %sr   )directstridedrn  r/  z/Index should be typed for more efficient accessz/Invalid index for memoryview specified, type %s)'r  r  r?   Zis_pythran_moder-  r3  r:  r   r  r  r   r  r   r   Zmemslice_indexr   r  r0   r   r   r  r"  r   r  r   r  r   r   r   r  setattrr  rp   r+   r  original_indicesr   analyse_operationr#  )rU   rs   r  r  r-  r8  r9  r  r  new_indicesZaxis_idxr  r;  accesspackingattrr   r   rQ   rQ   rR   r"    st   







z!MemoryViewIndexNode.analyse_typesc                 C   s   d| _ | || | S )Nz"Cannot index None memoryview slice)rQ  rR  )rU   rs   r  r  rQ   rQ   rR   rq  R  s   z%MemoryViewIndexNode.analyse_operationc                 C   s0   | j jr| }|js|jrd|_d|_dS dS dS )z
        Support broadcasting for slice assignment.
        E.g.
            m_2d[...] = m_1d  # or,
            m_1d[...] = m_2d  # if the leading dimension has extent 1
        TN)r   r   r  rU   r   lhsrQ   rQ   rR   analyse_broadcast_operationW  s   
z/MemoryViewIndexNode.analyse_broadcast_operationc                 C   s   |  |}|r|j|_|S | S rJ   )rV  r  rv  rQ   rQ   rR   $analyse_as_memview_scalar_assignmentd  s
   
z8MemoryViewIndexNode.analyse_as_memview_scalar_assignmentNrN  )	rX   rY   rZ   r  r  r"  rq  rx  ry  rQ   rQ   rQ   rR   r5    s    
Or5  c                   @   sb   e Zd ZdZdZdZdZdZdd Zdd Z	dd Z
d	d
 Zdd Zdd Zdd ZdddZdS )r4  TFc                 C   s.   t dd | jD | _| jr| jj| _dS dS )z@Slicing operations needing no evaluation, i.e. m[...] or m[:, :]c                 s   s.    | ]}|j o|jjo|jjo|jjV  qd S rJ   )r   r   r   r   r   r.  rQ   rQ   rR   re   y  s
    
z<MemoryViewSliceNode.analyse_ellipsis_noop.<locals>.<genexpr>N)r   r-  is_ellipsis_noopr:  r   r;  rQ   rQ   rR   analyse_ellipsis_noopv  s   
z)MemoryViewSliceNode.analyse_ellipsis_noopc                 C   s   ddl m} |sd| _d| _nd| _| || | jr| S d | _d| _d| _|	| j
|s2t| _| S t| jjj|| _| j sM| j sM| j|| _| S )Nr)   r  Tz&Cannot assign to None memoryview slicez"Cannot slice None memoryview slice)r  r  r  rQ  r{  rz  r;  r   rd  Zvalidate_axesr   r0   r   r   r  r:  r  r  rX  r  )rU   rs   r  r  r  rQ   rQ   rR   rq    s$   z%MemoryViewSliceNode.analyse_operationc                 C   s8   |j js| j j|j s|j jrt| j| S t| j| S rJ   )r   r   r  r  rp   MemoryCopyScalarr   MemoryCopySlicerU  rQ   rQ   rR   rV    s   z&MemoryViewSliceNode.analyse_assignmentc                 C   s   |sdS | j dd }|dd }t| j D ]/\}}|jr>|jjr;|jjr;|jjr;|d ||< |d |s:|  S q dS |jj	sE dS q|r[t
|t
| | jjjkrWdS ||7 }|S )a  Return a new list of indices/slices with 'indices' merged into the current ones
        according to slicing rules.
        Is used to implement "view[i][j]" => "view[i, j]".
        Return None if the indices cannot (easily) be merged at compile time.
        Nr   )rp  r  r   r   r   r   r   r   r   r  r   r:  r  )rU   r-  rr  r  r  rQ   rQ   rR   r2    s*   
z"MemoryViewSliceNode.merged_indicesc                 C   s"   | j r| j p| j S |  S rJ   )rz  r:  r  rX  rT   rQ   rQ   rR   r    s   zMemoryViewSliceNode.is_simplec                 C   r  )z3This is called in case this is a no-op slicing node)r:  r   rT   rQ   rQ   rR   r     r  z)MemoryViewSliceNode.calculate_result_codec              	   C   s   | j rd S |  }| j }d}t| j}| jD ]'}|jr:d}|jjs't	||_|j
js0t	||_
|jjs9t	||_qt	| qt|rEJ |j|| j|  | j|||jjd d S )NFT)rp  r8  rk   )rz  rZ  rr  iterr-  rp  r   r   r   nextr   r   r   Zgenerate_buffer_slice_coder   r   r   rk   )rU   r   rZ  rp  r8  rb  r;  rQ   rQ   rR   rv    s.   






z(MemoryViewSliceNode.generate_result_codec                 C   sp   | j r	| | n| | | jr| || n| || | j r'| | n| | || || d S rJ   )	rz  rt  r{  is_memview_scalar_assignmentZ+generate_memoryviewslice_assign_scalar_codeZ&generate_memoryviewslice_setslice_codery  r  r  rf  rQ   rQ   rR   r    s   


z,MemoryViewSliceNode.generate_assignment_codeNr  )rX   rY   rZ   r  rz  r  r  r  r{  rq  rV  r2  r  r   rv  r  rQ   rQ   rQ   rR   r4  l  s    
	r4  c                       s0   e Zd ZdZdgZ fddZdddZ  ZS )	MemoryCopyNodeze
    Wraps a memoryview slice for slice assignment.

        dst: destination mememoryview slice
    dstc                    s   t  | || _|j| _d S rJ   )rL   r  r  r   rU   r   r  rO   rQ   rR   r    s   zMemoryCopyNode.__init__Fc                 C   sH   | j | | || | j | | j | || || d S rJ   )r  r{  _generate_assignment_coder  r  rf  rQ   rQ   rR   r    s   
z'MemoryCopyNode.generate_assignment_coder  )rX   rY   rZ   r$  r   r  r  r[   rQ   rQ   rO   rR   r    s
    r  c                   @   s    e Zd ZdZdZdZdd ZdS )r}  z
    Copy the contents of slice src to slice dst. Does not support indirect
    slices.

        memslice1[...] = memslice2
        memslice1[:] = memslice2
    TZ__pyx_memoryview_copy_contentsc                 C   sb   | j }|j|j |j|j ||d| j| | |jj|jj|jj	j
f |j d S )Nz%s(%s, %s, %d, %d, %d))r  r   assert_direct_dimsr   r   rs  copy_slice_cnamer   r  r  rp   )rU   r  r   r  rQ   rQ   rR   r  !  s   
z)MemoryCopySlice._generate_assignment_codeN)rX   rY   rZ   r$  r  r  r  rQ   rQ   rQ   rR   r}    s
    r}  c                       rH   )r|  z
    Assign a scalar to a slice. dst must be simple, scalar will be assigned
    to a correct type and not just something assignable.

        memslice1[...] = 0.0
        memslice1[:] = 0.0
    c                    s   t  || |jj| _d S rJ   )rL   r  r   r  r  rO   rQ   rR   r  8  r  zMemoryCopyScalar.__init__c                 C   sF  ddl m} | jj| jj | jjj}|d}| jjd}|  |	d||
 f  | j s9| j r?| j
 }n|	d|| j
 f  d}d}| jj}	|	D ]}
t|
trj|
jjrh|
jjrh|
jjsjd}qU|j| jj|| jjj||d	}| }|jr|	d
|  |	d||f  |jr|	d |  |  d S )Nr)   r  r  z%s __pyx_temp_scalar = %s;z%s __pyx_temp_slice = %s;Z__pyx_temp_sliceFT)force_stridedzPy_DECREF(*(PyObject **) %s);z!*((%s *) %s) = __pyx_temp_scalar;zPy_INCREF(__pyx_temp_scalar);)r  r  r  r   r  r   r  r   Zbegin_blockr   r   rX  r  rp  r}   r  r   r   r   r   Z
slice_iterr  Zstart_loopsrp   Z	end_loopsZ	end_block)rU   Zscalarr   r  r  Z	type_declZ
slice_declZdst_tempr  r-  rS  Zslice_iter_objprQ   rQ   rR   r  <  sB   



z*MemoryCopyScalar._generate_assignment_code)rX   rY   rZ   r$  r  r  r[   rQ   rQ   rO   rR   r|  /  s    r|  c                       s   e Zd Zg dZdZdZdd Zd3ddZd	d
 Zdd Z	dd Z
dd Zdd Zd4ddZdd Z fddZdZejddddidZejdddd idZ fd!d"Zd#d$ Z		d5d%d&Zd6d'd(Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Z  ZS )7SliceIndexNode)r:  r   r   sliceFNc                 C   sZ   | j |}|js|jrtS |jrtS |ttttt	fv r|S |j
s$|jr+t|jd S tS rJ   )r:  r   rw  r   r   rx  r   r   r   r   r  r6  r   r  r  r   r+  rQ   rQ   rR   r   t  s   zSliceIndexNode.infer_typer   c                 C   s6   |t ur| jr| j r|| jj7 }nt }| j|S rJ   )r  r   r   r~   r:  r@  r?  rQ   rQ   rR   r@    s
   
z"SliceIndexNode.inferable_item_nodec                 C   s6   | j j}|r|jrdS |tttttfv rdS t	| S rR  )
r:  r   rw  r   r   r   r   r   r   r  r  rQ   rQ   rR   r    s   
zSliceIndexNode.may_be_nonec                 C   sF   | j d u rd }n| j j}| jd u rd }n| jj}| jj|| | _d S rJ   )r   r~   r   r:  )rU   r   r   rQ   rQ   rR   r    s   

z(SliceIndexNode.calculate_constant_resultc              
   C   s   | j |}| jd u rd}n| j|}| jd u rd }n| j|}z||| W S  tyA } z| | W Y d }~d S d }~ww r   )r:  r  r   r   r  r  )rU   r  r:  r   r   r  rQ   rQ   rR   r    s   

z!SliceIndexNode.compile_time_valuec                 C   r   rJ   rQ   r   rQ   rQ   rR   r    rW   z)SliceIndexNode.analyse_target_declarationc                 C   s    | j |dd}|jjrt|_|S rO  )r"  r   rp   r   r$  rQ   rQ   rR   r*    s   z#SliceIndexNode.analyse_target_typesTc                    sL  | j || _ | j jjs| j jjs| j jjr<t| j}t| j| j	p"|| j
p&||d}t| j|| j d}|j||| dS | j	rF| j	|| _	| j
rP| j
|| _
|jd s\t| j	| j
 | j j}|jrw|sw| j	so| j
so|| _n7t|j| _n/|js}|jrt|| _n#|jrt| _n|jr|| _n|jrt|j| _n
| j || _ t| _|jr|| _| j d| _ | jtu r| j	r| j	jr| j
r| j
jrt| j}t| jt| j	p|t| j
p||d|| _ n<tj!  fdd}| j	r| j	jj"r|| j	d|| _	| j	# || _	| j
r!| j
jj"r|| j
d	|| _
| j
# || _
d
| _$| S )Nr/  )r;  r:  r,  r  r   c              
      sz   ddl m}m} || }t| jt| j || rt|ntd|	 |t
| j|dt| jd|d|}|||S )Nr)   EvalWithTempExprNodeResultRefNode)r   r   r~   is)operand1r	   operand2)true_val	false_valtest)	UtilNodesr  r  CondExprNoder   r=  re  r   r  r  PrimaryCmpNoder  r"  analyse_result_type)r   default_valuers   r  r  Znode_refZnew_exprc_intrQ   rR   
allow_none  s,   

z0SliceIndexNode.analyse_types.<locals>.allow_nonerA  r  r)   )%r:  r"  r   r  r;   r   r  r   r  r   r   r<  r  rk   r   r6  r   r  r  rw  r  rz   rx  r   r  r  r   r  r  r   r#   deepcopyr  r  rp   r  r   )rU   rs   r  	none_noder;  r   r  r  rQ   r  rR   r"    s   





zSliceIndexNode.analyse_typesc                 C   sr   | j |}|r7| js7| js7ddlm} |||jj	 t
| j}t| j|||d}t||||gS d S )Nr)   r  r/  )r:  rC  r   r   r  r  r   r  r/  r  r  r   r  r   r  r  )rU   rs   r  r  r  Z
slice_noderQ   rQ   rR   rC    s(   
zSliceIndexNode.analyse_as_typec                    s   |j | _ t |S rJ   )r   rL   rO  r   rO   rQ   rR   rO  -  s   zSliceIndexNode.nogil_checkzSlicing Python objectZSliceObjectr  rs  ZGet)r/  Setc                    s   | j jjs
| j jjr)|tttfv r)|tu r&|jd s&t| j	d| j j|f  || _|j
r>| j jj
r>| js>| js>| j ||S t ||S )Nr_   :default encoding required for conversion from '%s' to '%s')r:  r   rw  r  r   r   r   rk   r   r   r6  r   r   r  rL   r,  rO   rQ   rR   r  9  s   
zSliceIndexNode.coerce_toc                 C   s  | j jst| jd| j   d S | jj }|  }|  }|  }|jrd| j	t
j}| j tu r1d}n| j tu r9d}n| j j }| jd u rQd| d| d| d}nd| d| d| d	| d
| d}n|jr| j	t
j}|jtdd | jd u rd| d| d}nd| d| d	| d
| d	}n|tu r| j }|jtdd d| d	| d	| d}n| j tu r| j }|  \}	}
}}}}}t|jjd }|j| j d| d	| d	| d	| d	| d	| d	|	dd	|
dd	|dd}n9| j }|tu r|jtdd d}n|tu r&|jtdd d}nd}| d| d	| d	| d}| | d| d|!|| j  | "| d S )Nz,Slicing is not currently supported for '%s'.Z	ByteArrayZUnicoder}  z_FromString(r  r  z_FromStringAndSize(r>  z - Zpyunicode_from_unicoder  z__Pyx_PyUnicode_FromUnicode(z%__Pyx_PyUnicode_FromUnicodeAndLength(ZPyUnicode_Substringz__Pyx_PyUnicode_Substring(r  z__Pyx_PyObject_GetSlice(r  ZSliceTupleAndListr  Z__Pyx_PyList_GetSliceZ__Pyx_PyTuple_GetSliceZPySequence_GetSlicer  r;  r<  )#r   rp   r   r   r:  r   
start_code	stop_coderw  r   r   rn   r   r   rq   titler   rx  c_const_py_unicode_ptr_typer   r   r   r   r   r   get_slice_configr.  rk   get_slice_utility_coder   r   r   r   r   r  )rU   r   r  r   r  r  Zbase_result	type_namecallhas_c_start
has_c_stopc_startc_stoppy_startpy_stoppy_slicer  cfuncrQ   rQ   rR   rv  H  s   


&

 









$z#SliceIndexNode.generate_result_codec                 C   s  |  | | jjr:|j| j |  \}}}}	}
}}|| jd| j	
 |
 ||	|
||||t|jjd f
  n>| jrA|  nd}|jjrR|jj}| || nd|  |f }|jtdd |d| j	 || | j	 |f  | | | | || || d S )Nz?__Pyx_PyObject_SetSlice(%s, %s, %s, %s, %s, %s, %s, %d, %d, %d)r  rA  z%s - %sIncludeStringHr  z,memcpy(&(%s[%s]), %s, sizeof(%s[0]) * (%s));)rt  r   rp   r   r   set_slice_utility_coder  r  r   r:  r   r.  rk   r   r  r6  r$  generate_slice_guard_coder  r   r   r   r   ry  rz  r  r  )rU   r   r   r  r   r   r  r  r  r  r  r  r  start_offsetarray_lengthrQ   rQ   rR   r    s:   
	




z'SliceIndexNode.generate_assignment_codec           
      C   s   | j jjst| jd| j  d S | | |j| j | 	 \}}}}}}}	|
| jd| j  |||||	||t|jjd f	  | | | | d S )Nz=Deleting slices is only supported for Python types, not '%s'.z;__Pyx_PyObject_DelSlice(%s, %s, %s, %s, %s, %s, %d, %d, %d)r  )r:  r   rp   r   r   rt  r   r   r  r  r  r   r.  rk   ry  rz  )
rU   r   r  r  r  r  r  r  r  r  rQ   rQ   rR   r    s*   



z%SliceIndexNode.generate_deletion_codec                 C   s   d\}}}| j r| j jj }|r| j  }nd| j   }d\}}}| jr:| jjj }|r3| j }nd| j  }| jrDd| j  pEd}|||||||fS )N)FrA  r3  &%sr3  )r   r   rp   r   r   r   r  )rU   r  r  r  r  r  r  r  rQ   rQ   rR   r    s    

zSliceIndexNode.get_slice_configc           
      C   sT  | j jjsd S | j jj}zt| }}W n ty   d }Y nw d  }}| jrT| j }zt|}|dk rE|d u r@d||f }n||7 }n|}d }W n	 tyS   Y nw | jr| j }z.t|}|dk rw|d u rsd| j jj|f }n||7 }t	|tr||8 }nd||f }d }W n	 ty   Y nw d }d}zt|}	W n ty   d }	Y nw t	|t}|r|dk r|	dkrt
| jd n3|r|d u r|d u r|	|krt
| jd||f  n|d ur|d u r|}d||f }n	|d ur|}n|}|r(|d||f  | jr|  |d	||f  | jr|  ||| j |d
 d S d S )Nr   z%s + %dz	%s - (%s)FzAssignment to empty slice.z8Assignment to slice of wrong length, expected %s, got %sz	(%s)-(%s)zif (unlikely((%s) != (%s))) {zPyErr_Format(PyExc_ValueError, "Assignment to slice of wrong length, expected %%" CYTHON_FORMAT_SSIZE_T "d, got %%" CYTHON_FORMAT_SSIZE_T "d", (Py_ssize_t)(%s), (Py_ssize_t)(%s));r   )r:  r   r6  r$  r   r   r   r   r   r}   r   r   r   r   r   r   r   )
rU   r   Ztarget_sizeZ
slice_sizetotal_lengthr   r   Zruntime_checkZcompile_time_checkZint_target_sizerQ   rQ   rR   r    s   







z(SliceIndexNode.generate_slice_guard_codec                 C   s   | j r| j  S dS )NrA  )r   r   rT   rQ   rQ   rR   r  )  s   
zSliceIndexNode.start_codec                 C   s(   | j r| j  S | jjjr| jjjS dS )Nr  )r   r   r:  r   r6  r$  rT   rQ   rQ   rR   r  /  s
   


zSliceIndexNode.stop_codec                 C   rS   )Nz<unused>rQ   rT   rQ   rQ   rR   r   7  r  z$SliceIndexNode.calculate_result_coder  rN  r  r  )rX   rY   rZ   r   r   r  r   r@  r  r  r  r  r*  r"  rC  rO  r  r   loadr  r  r  rv  r  r  r  r  r  r  r   r[   rQ   rQ   rO   rR   r  f  s@    	
	

_

G

"Rr  c                   @   sT   e Zd Zg dZdZeZdZdd Zdd Z	dd	 Z
d
d ZdZdd Zdd ZdS )r  r/  Tr)   c                 C      t | jj| jj| jj| _d S rJ   r  r   r~   r   r   rT   rQ   rQ   rR   r  H  
   
z#SliceNode.calculate_constant_resultc              
   C   d   | j |}| j|}| j|}zt|||W S  ty1 } z| | W Y d }~d S d }~ww rJ   r   r  r   r   r  r  r  rU   r  r   r   r   r  rQ   rQ   rR   r  N     zSliceNode.compile_time_valuec                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  W  rW   zSliceNode.may_be_nonec                 C   sp   | j |}| j|}| j|}||| _ ||| _||| _| j jr6| jjr6| jjr6d| _d| _| S r  )r   r"  r   r   r  r   r   )rU   rs   r   r   r   rQ   rQ   rR   r"  Z  s   zSliceNode.analyse_typesz Constructing Python slice objectc                 C   r   rJ   rf  rT   rQ   rQ   rR   r   h  r)  zSliceNode.calculate_result_codec                 C   s   | j r$t| j| f}|jd|d| _|| j}|d u rd S || j |d| 	 | j
 | j | j || 	 | jf  | | | j rQ| | d S d S )Nr  	dedup_keyz %s = PySlice_New(%s, %s, %s); %s)r   r   r   r  r_  r  ru  r   r   r   r   r   r   r   r   r  r  )rU   r   r  rQ   rQ   rR   rv  k  s(   
zSliceNode.generate_result_codeN)rX   rY   rZ   r   r   r   r   r   r  r  r  r"  r  r   rv  rQ   rQ   rQ   rR   r  <  s    	r  c                   @   @   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )r6  r   c                 C   r  rJ   r  rT   rQ   rQ   rR   r    r  z&SliceIntNode.calculate_constant_resultc              
   C   r  rJ   r  r  rQ   rQ   rR   r    r  zSliceIntNode.compile_time_valuec                 C   rS   rR  rQ   rT   rQ   rQ   rR   r    rW   zSliceIntNode.may_be_nonec                 C   s   | j || _ | j|| _| j|| _| j js | j || _ | jjs+| j|| _| jjs6| j|| _| j jrH| jjrH| jjrHd| _d| _| S r  )r   r"  r   r   r   r  r   r   r   rQ   rQ   rR   r"    s   zSliceIntNode.analyse_typesc                 C   r   rJ   rQ   rT   rQ   rQ   rR   r     rW   z"SliceIntNode.calculate_result_codec                 C   s.   | j | j| jfD ]}t|tr|j  qd S rJ   )r   r   r   r}   r  r   r   )rU   r   r  rQ   rQ   rR   rv    s
   

z!SliceIntNode.generate_result_codeN)
rX   rY   rZ   r   r  r  r  r"  r   rv  rQ   rQ   rQ   rR   r6    s    		r6  c                   @   s^   e Zd ZdZdd Zdd Zdd Zdd	 Zdd
dZdd Z	dd Z
dd Zdd ZdZdS )CallNodeNc           
         sx  | j }| }t|trt|jS |tu r?|jr0|j	 }|j
r0t||j}|tur0|S t|dd }|d ur?|jp>|}|jrE|j}|jrwt| j dd rtt| drt fdd| jD }| j j |}|rt|j}|jrq|j}|jS |jS |tu r|jr|jr|jjr|jj}|jr|S |j
r|jj}	|	dkrtjS |	dkrtjS |	tjv r|S | j  }|r|j s|j!r|S tS )Nr   r   c                    r2  rQ   r   r   ry   rQ   rR   r     r   z'CallNode.infer_type.<locals>.<listcomp>r   r.  )"r  r   r}   r  r   r  r  r   r  r  r  r   "find_return_type_of_builtin_methodr  r   r   r  r  r7  r  r   r   best_function_matchrf  r   r   r  rq   rn  r  #types_that_construct_their_instancerC  is_struct_or_unionr   )
rU   rs   r  r&  method_obj_typeresult_typer   	arg_types
func_entry	func_namerQ   ry   rR   r     sV   



zCallNode.infer_typec                 C   r  rJ   )r  r3  r   rQ   rQ   rR   r3    r  zCallNode.type_dependenciesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r    r  zCallNode.is_simplec                 C   s^   | j d ur| j S | jj}|tu r*| jjr*| jj}|jjrdS |jjr*|jt	j
v r*dS t| S rR  )may_return_noner  r   r   r   r   r  r  rq   r   r  r   r  )rU   r&  r   rQ   rQ   rR   r    s   

zCallNode.may_be_nonec                 C   s   t | _|d u r
|j}|jrP|j}|tju r>|r>|jr>|jtjv r>t | _	d| _
|jdkr5tj| _tj| _	d S tj|j | _d S |jrN|jj| _t | _	d| _
d S d S |jry|jjjr{|jj}t||j}|t u | _
|jrp|| _d S |jr}|j| _d S d S d S d S )NFr   )r   r   r   r   r   r   r  rq   r  r  r  r   rn  Zbuiltin_typesr  r  r  r  r  r  rp   r   )rU   r  r&  r   r  r  rQ   rQ   rR   set_py_result_type  s@   





zCallNode.set_py_result_typec           
   	      s(  | j  }|rI|jrI|  \}}g }t||jjD ]\}}|t|j	t
|j	|jd|d q|r7||j7 }t| j	|d}| | }|S |r|jr fdd| jD | _|jd}	|	sqt| j j	d| j j  t| _| S t| j j	|	j| _ |	| j _| j |  |   || _| S dS dS )	z4
        Returns a replacement node or None
        r  keyr   key_value_pairsc                    r2  rQ   r'  r   ry   rQ   rR   r   6  r   z8CallNode.analyse_as_type_constructor.<locals>.<listcomp>z<init>z'no constructor found for C++  type '%s'N)r  rC  r  explicit_args_kwdsrW  r  rO  r   DictItemNoder   r:  rq   r  DictNoder"  r  r   r   r  r   r0   r   r  r   r  r  analyse_c_function_call)
rU   rs   r   r   rP  rR  r   memberr   r  rQ   ry   rR   analyse_as_type_constructor%  s2   
$


z$CallNode.analyse_as_type_constructorc                 C   s   | j j}|jr
|j}|S rJ   )r  r   r  r  rU   r&  rQ   rQ   rR   function_typeC  s   zCallNode.function_typec                 C   r  rJ   )r   r   rT   rQ   rQ   rR   r   M  r^   zCallNode.is_lvaluec                 C   s@   |   }|jr|   d S |jst|dds|   d S d S d S )Nr   F)r  rp   rN  r  r   )rU   rs   r&  rQ   rQ   rR   rO  P  s   zCallNode.nogil_checkzCalling gil-requiring functionrJ   )rX   rY   rZ   r  r   r3  r  r  r  r  r  r   rO  r  rQ   rQ   rQ   rR   r    s    0
!
r  c                       s   e Zd Zg dZdZdZdZdZdZdZ	dZ
dZdd Zdd Zedd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Z fddZdd Z  ZS )r  )rU   coerced_selfr  r   ra  NFc              
      s\   | j  } fdd| jD }z|| W S  ty- } z| | W Y d }~d S d }~ww )Nc                    r2  rQ   r  r   r  rQ   rR   r   s  r   z5SimpleCallNode.compile_time_value.<locals>.<listcomp>)r  r  r   r  r  )rU   r  r  r   r  rQ   r  rR   r  q  s   
z!SimpleCallNode.compile_time_valuec                 C   s   | j jr?| j jjrA| j j}t|st|rC|j}| j jj	}|r$|j
nt	|jj}t||rEdd | jD }|| | _d S d S d S d S d S )Nc                 S      g | ]}|j qS rQ   r~   r   rQ   rQ   rR   r         z<SimpleCallNode.calculate_constant_result.<locals>.<listcomp>)r  r  r  r   r~   r"   	isbuiltinismethodrX   r   rq   __self__r   is_safe_compile_time_methodr   )rU   methodr   object_typeobject_type_namer   rQ   rQ   rR   r  y  s   
z(SimpleCallNode.calculate_constant_resultc                 C   sP   |j }||j}|sJ d||jf t||j||jd}| |||gd}|S )Nz Getter not found in scope %s: %s)rq   r   r   r  )r  r  rq   rQ  r  r   )rN   r   r  r   Zproperty_scopeZgetter_entryr  r   rQ   rQ   rR   for_cproperty  s   zSimpleCallNode.for_cpropertyc                 C   s   | j  }|dkr3t| jdkrt| jjd d S | jd |}|s.t| jd jd d S t|S |dkrPt| jdkrEt| jjd | jd 	|}|j
S d S )Nr  r)   zonly one type allowed.r   zUnknown typeZtypeof)r  r  r   r   r   r   rC  r   r  r"  r   )rU   rs   ru  r   operandrQ   rQ   rR   rC    s   

zSimpleCallNode.analyse_as_typec                 C   s
   | j d fS rJ   r   rT   rQ   rQ   rR   r    rM  z!SimpleCallNode.explicit_args_kwdsc                    s  | j r| S d| _ |   }d ur|S d| j_| j | _| j}|jr5|jr5|jjr5|j| _	t
| j	|_|  }d| _t rk|jrkt|rkd}t| j| jd| _| j | _| jjD ]}|t|M }q]t|| _| jr t| tj| t|| jtt|| jjdS |jrt| j| jd| _| j  | _d | _| || d| _ | S  fdd| jD | _| !  |j"dkrd| _ | S )	NTr)   Fr  )function_cnamera  r   c                    r2  rQ   r'  r   ry   rQ   rR   r     r   z0SimpleCallNode.analyse_types.<locals>.<listcomp>r   )#analysedr  r  r"  r"  r  r   
is_cmethodr  rU   r  r  Zis_numpy_call_with_exprsr?   r  rD   r1  r   r   ra  rB   r.  Zadd_include_filerE   NumPyMethodCallNoder  rF   rG   r<   rp   r  r  r   r  r   )rU   rs   as_type_constructorr  r&  Zhas_pythran_argsr   rQ   ry   rR   r"    sT   


zSimpleCallNode.analyse_typesc              
   C   s  | j j}|tu rt| _d S |jr%|jr%| jr!| jjjr!t| jd | j	}n| jr0| jg| j	 }n| j	}|j
rL| j jjd}|d u rKtj| _d| _d S nt| j drW| j j}n| j jre| j jre| j jj}nd }|rz|j|dd |D ddd |D d	}W n' tjy } zt|}|rt| j| tj| _d| _W Y d }~d S d }~ww d|_|j
s|| j _|j| j _|  }nd }|  }|jst| jd
|  tj| _d| _d S t|j	}||j }	t|}
|jr|	|
krd| _d| _|rq|jrq|j	rq|jsq|j	d }|d }|jr5| jr)| jjdt|j dkrdndd|j gd| _n|jd|j |jj gd}| jrS|j!rCt"| j}nt#| j}|$|j| }| _%n|jj&rm|$|j|}|jj&rmt'|t(rmd|_)||d< d}t*t+||
D ]T}|j	| }|j}|| $||}|jr|d}|, r|dkrd}n'|jj-r|j.s|dkr| jd urn|/ rn|dkrd}|0|}|||< qzt*||
D ]B}|| }|jj-r	|jt1u rtj2}n|j3 }|d u rt| j	|d  jd n
|$|| ||< }|, r|dkrd}q|rgt*|
d D ]F}|dkr/| jd ur/q || }|/ r:q |jj
rAq |j.rL|jj-rLq |dks\|dkre| jd uret4|jdd  nq || j	d d < t'| j t5r~t6| j j7| _n|j8| _| j j9s| j j:r| j j}|r|j;s|j<rd| _| jj-rt=| _>d| _n|j?d us|j@rd| _n| jjArd| _| jr| jjBrtC| jjD| _|j8jErd|F| j j|j8jG_|j@dkrtH|r|ItJKdd |jLd | _Md S )Nz4Cannot call a static method on an instance variable.z
operator()r  r   c                 S   r  rQ   r  r   rQ   rQ   rR   r     r  z:SimpleCallNode.analyse_c_function_call.<locals>.<listcomp>Tc                 S   r@  rQ   )r   r   rQ   rQ   rR   r     rB  )Zfail_if_emptyZarg_is_lvalue_arrayzCalling non-function type '%s'r)   r   )'NoneType' object has no attribute '%{}s'   .30r  PyExc_AttributeError)r   r  z@descriptor '%s' requires a '%s' object but received a 'NoneType'r  FzGcannot pass None into a C function argument that is declared 'not None'z5Python object cannot be passed as a varargs parameterTArgument evaluation order in C function call is undefined and may not be as expectedr   r%  r  overflowcheck)Nr  r   r0   r7  is_static_methodrU   r  r   r   r   r   r  r  r   r_  r  r   r  r>  r  ZNoMatchFoundrw   r  r  r   optional_arg_counthas_optional_argsr   r  Znot_noner  r   rq   Zaccept_builtin_subtypesCMethodSelfCloneNoder  r  r  r  r}   r  exact_builtin_typer0  minrX  rp   r   r8  r  r   r.   Zdefault_coerced_ctyper   r  r  r  rf  r   r  r  Zutility_code_definitionr   r  r   r   r   r   CFakeReferenceTyper  r  declare_tuple_typer  r   r   r   r   rk   r  )rU   rs   r&  r   Zoverloaded_entryr   excr  	max_nargsexpected_nargsactual_nargs
formal_argr   some_args_in_tempsr  formal_typeZ	arg_ctyper  rQ   rQ   rR   r    s8  




















 



z&SimpleCallNode.analyse_c_function_callc                 C   rY  rJ   )c_call_coderT   rQ   rQ   rR   r     r^   z$SimpleCallNode.calculate_result_codec                 C   s  |   }| jtju s|jsdS |j}g }tt|| j}t|j}||j	 }t| j}|d | D ]\}}	|	
|j}
||
 q1|jrS|tt| jpO| jjj |j	rg||kr]d}nd| j }|| | jt|d  D ]	}	||	  qpd| j d|f }|S )Nr  r3  r  r  r>  )r  r   r   r0   r7  r   r   rW  r   r  r   r   r  rw   r   wrapper_callr  r   is_unbound_cmethodopt_arg_structr   r   rA  )rU   r&  Zformal_argsZarg_list_coder   r   r  r  r  
actual_argarg_codeZoptional_argsr   rQ   rQ   rR   r    s.   




zSimpleCallNode.c_call_codec                 C   s$   |   }|jd u s|jdkrdS dS )Nr   FT)r  r   r   r  rQ   rQ   rR   r     s   z#SimpleCallNode.is_c_result_requiredc              
      s  | j }|js	|jr|j|j d}| jjo| jj}| j	rH|rH|
 |v rH|jtdd |d| jd 
 | jd j || jf  |jjr\t| jjdks\| jjrd| jjrdt | d S | jjrn| jjd nd }| j| j||f}|D ]}|d ur|| qz|| j | jsJ | | |d u r|jtdd |d	| 
 | || 
 | jf  n"|jtd
d |d| 
 | | || 
 | jf  |  | |D ]}|d ur|!| |"| qd S )N)absZlabsZ__Pyx_abs_longlongZCommon
Overflow.czif (unlikely(%s == __PYX_MIN(%s))) {                PyErr_SetString(PyExc_OverflowError,                                "Trying to take the absolute value of the most negative integer is not defined."); %s; }r   r)   ZPyObjectCallNoArgr  z%%s = __Pyx_PyObject_CallNoArg(%s); %sPyObjectCallOneArgz*%s = __Pyx_PyObject_CallOneArg(%s, %s); %s)#r  r   r  r   use_entry_utility_coder   r   r  r!  r  r   r   r   r   r   r   r  r   r   rp   r   ra  r   rL   r{  rU   r  ru  r   re  r   r   r  r  r  )rU   r   r  Zabs_function_cnamesZis_signed_intr   r   ZsubexprrO   rQ   rR   r{    st   








z'SimpleCallNode.generate_evaluation_codec              
   C   s&  |   }|jr4| j }|jtdd |d| 	 | j
 ||| 	 | jf  | | d S |jr|jj }| jrt| j}t|j|j }|jj|jjdd| _|d| jtjd t| j| f  tt|j| j}||| D ]\}}	|d| j||j|	|j f  qzg }
| j jr| j!r|
"d| 	   nl| j j#r| j!sJ |
"| j $| 	  nW|j%d	kr|j&}|j%}|d ur|
"|'| 	 | |r|r|
st(| j
d
d }t)j*| j|jj+|r|jnd | j j,d|o|j-d |jtdd |
"d n|
"d | j!s|
r| . }| 	 r8d| 	  }| j!r7| j jr7t/t0| j |}nd}|j%d	krYt1|| jd||f | j jrR| 	 nd |j&| n|
rg|2d3|
| j}nd}|d|||f  | j jr| 	 r| | | jr|j4| j d S d S d S )Nr  r  z*%s = __Pyx_PyObject_Call(%s, %s, NULL); %sTr]  %s.%s = %s;r  rE  r   r   )function_nameZvoid_returnZis_callZis_from_pxdr   r   r   r   z%s = r  z%s%s;z && z%s%s; %s)5r  rp   ra  r   r   r   r   r   r   r   r  r   r   r  r7  rb  Z	gil_ownedr  r   r   r  rc  op_arg_structr  r	  r   Zpyrex_prefixr   rW  Zopt_arg_cnamerq   r   r   r   r   r   Zerror_conditionr   r   Zexception_test_coder   r   Zwrite_noexcept_performance_hintr  r`  Zdefined_in_pxdr  r/   r   r   r   rA  rj  )rU   r   r&  r  r   r  r  r   r  r
  Z
exc_checksexc_valZ	exc_checkZperf_hint_entryr   rw  Z
goto_errorrQ   rQ   rR   rv    s   












Az#SimpleCallNode.generate_result_code)rX   rY   rZ   r   rU   r  ra  r  r  r   r  r  r  r  r  r  rC  r  r"  r  r   r  r   r{  rv  r[   rQ   rQ   rO   rR   r  Z  s0    
	0 Q9r  c                   @   s"   e Zd ZdgZdZdZdd ZdS )r  ra  Tc              
   C   s   | | j | | | jjd u sJ | jj}|D ]}|| q|d |d|    |d|  |  | j	d
dd |D f  d S )Nz.// function evaluation code for numpy functionrg  z!new (&%s) decltype(%s){%s{}(%s)};r>  c                 s   r8  rJ   )r   )ra   r  rQ   rQ   rR   re   o  rf   z?NumPyMethodCallNode.generate_evaluation_code.<locals>.<genexpr>)ru  r   re  ra  r   r   r{  r   r   r  rA  )rU   r   r   r   rQ   rQ   rR   r{  `  s   

z,NumPyMethodCallNode.generate_evaluation_codeN)rX   rY   rZ   r   r   r  r{  rQ   rQ   rQ   rR   r  V  s
    r  c                       s   e Zd Zg dZdZdZdZdZdZ fddZ	dd Z
ed	d
 ZedddZedd ZdefddZdd Zdd Zdd Zdd Zdd Z  ZS )PyMethodCallNode)r  ra  kwdictkwargs_key_value_pairsTFNc                    sV   t  j|fi | |  rd| _| jj| _| jr'| jjr)| jj	| _
d | _d S d S d S r+  )rL   r  can_avoid_attribute_lookupuse_method_vectorcallr  r  function_objr  r  r  r  )rU   r   kwrO   rQ   rR   r    s   


zPyMethodCallNode.__init__c                 C   sL   | j rt| j tsdS | j}|jsdS |jsdS |jrdS t|s$dS dS r  )	r  r}   r  r  r  
is_py_attris_special_lookupr  attribute_is_likely_method)rU   r  rQ   rQ   rR   r    s   
z+PyMethodCallNode.can_avoid_attribute_lookupc                 C   s   | j }|jr|jjrdS dS r  )r  r   r   r  )ru  r  rQ   rQ   rR   r    s   z+PyMethodCallNode.attribute_is_likely_methodc                 C   sH   t | tsdS | jrdS | jrt| jdkrdS t| js"|p!| S dS )z~
        Test whether the positional args given are compatible with
        being translated into a PyMethodCallNode.
        Fr)   T)r}   r1  r   r   r   r   )r  Z
has_kwargsZhas_explicit_kwargsrQ   rQ   rR   can_be_used_for_posargs  s   


z(PyMethodCallNode.can_be_used_for_posargsc                    sj   d}| j r| jr| jjjrd}|S | jr3| j}|jjrd}|S |jr3tttf t	 fdd|jD }|S )zo
        Test whether the function passed is suitable to be translated
        into a PyMethodCallNode
        TFc                 3   s$    | ]}|j ot|j   V  qd S rJ   )r   r}   )ra   r  Znon_method_nodesrQ   rR   re     s
    
z<PyMethodCallNode.can_be_used_for_function.<locals>.<genexpr>)
r  r   r   r7  r   Zcf_assignmentsPyCFunctionNode	ClassNodePy3ClassNoderl   )r  Zmay_be_a_methodr   rQ   r  rR   can_be_used_for_function  s    
z)PyMethodCallNode.can_be_used_for_functionr  c                 C   s   | j r$| j| || d| j  d ||t || jj	S || d | j| | j
 s?| jsD| j rD| j S |jjtdd}| j| |d|| j f  | j| | j| |S )Nr;  r@  z = NULL;Tr]  	%s = %s; )r  r  r{  r   r   rl  r   r  r  r  rX  unpackr8  r   rb  rc  rn  r  r  )rU   r   self_argr  rQ   rQ   rR   generate_evaluate_function  s   
z+PyMethodCallNode.generate_evaluate_functionc                 C   st   | j r| j| | j| d S | j s| js,| j r,| j| | j| d S ||t	 |j
| d S rJ   )r  r  r  r  r  rX  r%  r8  r  r   rb  rj  rU   r   r  rQ   rQ   rR   generate_dispose_function  s   z*PyMethodCallNode.generate_dispose_functionc                 C   s.  | j s| jsd S | jjr| | jrdnd}n.| jjrC| jjrC| jjD ]}|j}|r?|jr?|jj	r?|jj	j
r?| |r?d} nq#d}nd}|d |d||f  || d| d |d| d |d| d ||t |d	t ||td	 || d
 |d |d d S )NZlikelyZunlikelyz#if CYTHON_UNPACK_METHODSzif (%s(PyMethod_Check(%s))) {z = PyMethod_GET_SELF(r?  zassert(z2PyObject* __pyx__function = PyMethod_GET_FUNCTION(Z__pyx__function = 0;r   rk  )r  r%  r  r  r  r   r   r   r  r   rp   r   rl  r   r  )rU   r   r&  space_for_selfarg_var
method_objZlikely_methodr  r   rQ   rQ   rR   &generate_runtime_method_unpacking_code  s4   


z7PyMethodCallNode.generate_runtime_method_unpacking_codec                 C   s   | | dt| d||| j  ||t t|D ]>\}}|jjt	j
u o.|j  }|| jd|r8dnd d|j  d|j  d| dtj dt|d	  d|d
d qd S )Nz# = __Pyx_MakeVectorcallBuilderKwds(rp  Z__Pyx_VectorcallBuilder_AddArgr  Z_Checkr  r>  r   r)   r  r  )r   r   r   r   r  r   r  r  r   r   r   r  r  r   r   r   callargs_cname)rU   r   r   r  Zkwnames_tempr  keyvalueZ
key_is_strrQ   rQ   rR   generate_keyvalue_args  s2   
z'PyMethodCallNode.generate_keyvalue_argsc                 C   s`   | j r| jrd}d}nd}d}n| jrd}d}n| jr d}d}nd}d	}|jt|d
 |S )NZ!PyObjectVectorCallMethodKwBuilderZ-__Pyx_Object_VectorcallMethod_CallFromBuilderZPyObjectFastCallMethodZ__Pyx_PyObject_FastCallMethodZPyObjectVectorCallKwBuilderZ'__Pyx_Object_Vectorcall_CallFromBuilderZPyObjectFastCallZ__Pyx_PyObject_FastCallDictZ__Pyx_PyObject_FastCallr  )r  r  r  r   r   r   r   )rU   r   rq   r  rQ   rQ   rR   select_utility_code+  s$   
z$PyMethodCallNode.select_utility_codec                 C   s  | | j | | | j}| j}|jjtdd}| ||}| j	j
}| j	jd u s+J |D ]}|| q-|rB|D ]}|| q9n|rI|| |jjtjdd}	||	 d| jr\dnd d | j|||	|d | |}
|d	 |rd
dd |D nd}|rdt| dnd}|dtj d|rt|d ndd| d| d
| d
 d}|r|jjtdd}| |||| n|r| }||   d|
 d| d
tj d|	 dt|d dd|	 d| jrdn|	 d|rd
nd | d ||t ||	fD ]	}|j| q|D ]}|| || q|r?|D ]}|| || q$||t |j| n|rL|| || | || |||  | j |  | |d d S ) NTr]  Fr;  rA  r@  r@  )r&  r+  r,  r6  r>  c                 s   r8  rJ   r   r   rQ   rQ   rR   re   j  rf   z<PyMethodCallNode.generate_evaluation_code.<locals>.<genexpr>r3  z + ((CYTHON_VECTORCALL) ? z : 0)r  
PyObject *[r)   r4   r  z] = {r:  r  r   z, (ra  z) | (z&*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)r?  r   )!ru  r   re  r  r  rb  rc  r   r'  ra  r   r   r{  r   r[  r   r  r-  r1  rA  r   r   r.  r0  r   r!  rj  r  r  r  r)  r   r  )rU   r   r  r  r&  r  r   r   r/  Zspace_for_selfargZfunction_callerZ	args_listZextra_keyword_argsZkeyword_variabletmpZkw_noderQ   rQ   rR   r{  B  s   

 

4





z)PyMethodCallNode.generate_evaluation_coder  )rX   rY   rZ   r   r   r  r  r  r  r  r  r<  r  r  r#  rw   r'  r)  r-  r0  r1  r{  r[   rQ   rQ   rO   rR   r  r  s*    	

$r  c                   @   s<   e Zd ZddgZdZeZdZdZdd Z	dd Z
d	d
 ZdS )InlinedDefNodeCallNoder   r  r)   Nc                 C   s>   | j j}|js
|jrdS t|jt| jkrdS |jrdS dS r  )r  def_nodestar_argstarstar_argr   r   num_kwonly_argsr  rQ   rQ   rR   can_be_inlined  s   z%InlinedDefNodeCallNode.can_be_inlinedc                    s  | j  | _  fdd| jD | _| jj}t| j}d}t|D ]8}|j| j}| j| | }|	 r=|dkr<d}n|jj
rT jsT| rIn|dkrOd}| }|| j|< q!|rt|d D ]'}| j| }| rnqb|jjrsqb jr{|jj
r{qb|dkrt|jdd  | S qb| S )Nc                    r2  rQ   r'  r   ry   rQ   rR   r     r   z8InlinedDefNodeCallNode.analyse_types.<locals>.<listcomp>Fr   Tr)   r  )r  r"  r   r  r7  r   r0  r   r  rX  rp   r   r8  r  r   r   r   )rU   rs   r&  r  r  r  r  r   rQ   ry   rR   r"    sD   


z$InlinedDefNodeCallNode.analyse_typesc              
   C   s>  | j  }| jjjsI|d |d |dtj d| d ||tj d| j	 |d |dtj d| d |d	 tj}|g}| jj}t
| j|jD ]\}}|jjri|||j qW||  qWd
|}|d|  | jjjj|||  | j	f  | jjjs|d | | d S )Nr6  ##if CYTHON_COMPILING_IN_LIMITED_APIr3  z = PyCFunction_GetSelf(r?  z == NULL && PyErr_Occurred()r  z = PyCFunction_GET_SELF(rk  r>  %s = %s(%s); %sr   )r  r   r  r7  is_cyfunctionr   r   r  r   r   rW  r   r   rp   r   r   r   rA  r   pyfunc_cnamer   r  )rU   r   Z	self_coder  r&  r   Z	proto_argrQ   rQ   rR   rv    sF   










z+InlinedDefNodeCallNode.generate_result_code)rX   rY   rZ   r   r   r   r   r  r  r;  r"  rv  rQ   rQ   rQ   rR   r6    s    
9r6  c                   @   s2   e Zd Zg Zd
ddZdd Zdd Zdd	 ZdS )PythonCapiFunctionNodeNc                 C   s   t j| |||||d d S )N)rq   r   r   r  r   r  )rU   r   py_namer   r&  r  rQ   rQ   rR   r    s   
zPythonCapiFunctionNode.__init__c                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"    rW   z$PythonCapiFunctionNode.analyse_typesc                 C   s   | j r|j| j  d S d S rJ   )r  r   r   rm  rQ   rQ   rR   rv    s   z+PythonCapiFunctionNode.generate_result_codec                 C   r   rJ   r  rT   rQ   rQ   rR   r   "  r)  z,PythonCapiFunctionNode.calculate_result_coderJ   )rX   rY   rZ   r   r  r"  rv  r   rQ   rQ   rQ   rR   r@    s    
r@  c                   @   s   e Zd ZdZ	dddZdS )PythonCapiCallNodeFNc                 K   s<   |j | _| j| _t|||||d| _tj| |fi | d S )N)r  )rf  r   r  r@  r  r  r  )rU   r   r  r&  r  rB  r  rQ   rQ   rR   r  /  s   zPythonCapiCallNode.__init__r  )rX   rY   rZ   r  r  rQ   rQ   rQ   rR   rC  &  s    rC  c                       s8   e Zd ZddgZdZ fddZdd Zdd	 Z  ZS )
CachedBuiltinMethodCallNoder  r   Tc                    s"   t  j|j||||j|jd d S )N)r  r   r   r  r   )rL   r  r   r  r   )rU   Z	call_noder  r   r   rO   rQ   rR   r  A  s   
z$CachedBuiltinMethodCallNode.__init__c                 C   s   | j d ur| j S t| S rJ   )r  r   r  rT   rQ   rQ   rR   r  H  s   

z'CachedBuiltinMethodCallNode.may_be_nonec              	   C   st   | j jj}| j  }dd | jD }|j|d||| j|}|	d| 
 ||| 
 | jf  | | d S )Nc                 S   r@  rQ   r2  r   rQ   rQ   rR   r   P  rB  zDCachedBuiltinMethodCallNode.generate_result_code.<locals>.<listcomp>r  r  )r  r   typeptr_cnamer   r   r   Zcached_unbound_method_call_coder  r   r   r   r   r   r  )rU   r   Z
type_cnameZ	obj_cnamer   Z	call_coderQ   rQ   rR   rv  M  s   


z0CachedBuiltinMethodCallNode.generate_result_code)	rX   rY   rZ   r   r   r  r  rv  r[   rQ   rQ   rO   rR   rD  ;  s    rD  c                   @   sN   e Zd ZeZg dZejZdd Z	dd Z
dd Zdd	 Zd
d Zdd ZdS )GeneralCallNode)r  r  r  c              
   C   sf   | j |}| j|}| j|}z||i |W S  ty2 } z| | W Y d }~d S d }~ww rJ   )r  r  r  r  r  r  )rU   r  r  r  r  r  rQ   rQ   rR   r  i  s   z"GeneralCallNode.compile_time_valuec                 C   s   | j jrB| j jjrD| j j}t|st|rF|j}| j jj	}|r$|j
nt	|jj}t||rH| jj}| jj}||i || _d S d S d S d S d S rJ   )r  r  r  r   r~   r"   r  r  rX   r   rq   r  r   r  r  r  )rU   r  r   r  r  r   r  rQ   rQ   rR   r  r  s   
z)GeneralCallNode.calculate_constant_resultc                 C   s0   | j r| j jr| jjst| jd| jj| j fS )Nz0Compile-time keyword arguments must be explicit.)r  r  r  r   r   r   r   rT   rQ   rQ   rR   r    s   z"GeneralCallNode.explicit_args_kwdsc                 C   s   |  | }d ur|S | j|| _| jjjsY| jjjr!t| _| S t| jdrR|  }|d ur8|| ur8||S | jj	j
rE| j|| _n|| u rPt| jd n		 n| j|| _| jrc| j|| _| j|| _| j|| _| | j d| _| S )Nr   zRNon-trivial keyword arguments and starred arguments not allowed in cdef functions.r)   )r  r  r"  r   rp   r  r0   r  map_to_simple_call_noder   r  r  r   r   r  r  r  r   )rU   rs   r  r   rQ   rQ   rR   r"    s6   




zGeneralCallNode.analyse_typesc                    sj  t | jts| S | jjs| S | j}t|dd}|s| S |j}|jr$|j	}|j
s)| S | jj | j}|j}|jr<|dd }t t|krTt| jdt|t f  dS dd |dt  D }|t d }d}t }	t|}
d}|jD ]}|jj}||
v rt|jd	|  d
}|
| qxt||jD ]\}}|jj}|j|kr|| |d7 }|	|j q ddlm}m} g }t|j|kr||t|	d } fddt|jD }d}|D ]W}|j}||vr|s|}q|r|jr|   S t| jd|   dS || \}}|| |d7 }|j r|	|j q||j}| s+J |	| |||f q|r|g }g }|d d }|	D ]$}||u rP n| r\|| qG||}|| || qG|rq|}	|dd t|D  }|jD ]}|jj}||vrd
}t|jd|  q|rdS t | j||	d}|ddd D ]}|||}q|S )z
        Tries to map keyword arguments to declared positional arguments.
        Returns self to try a Python call, None to report an error
        or a SimpleCallNode if the mapping succeeds.
        r   Nr)   zDfunction call got too many positional arguments, expected %d, got %sc                 S   s   h | ]}|j r|j qS rQ   r  r   rQ   rQ   rR   r     s    z:GeneralCallNode.map_to_simple_call_node.<locals>.<setcomp>r   Fzargument '%s' passed twiceT)r  
LetRefNodec                    s&   i | ]\}}|j j|t  |fqS rQ   )r  r   r   ra   r  r   Zpos_argsrQ   rR   
<dictcomp>  s    z;GeneralCallNode.map_to_simple_call_node.<locals>.<dictcomp>z(C function call is missing argument '%s'r,  c                 S   s   g | ]\}}|qS rQ   rQ   rI  rQ   rQ   rR   r     rB  z;GeneralCallNode.map_to_simple_call_node.<locals>.<listcomp>z/C function got unexpected keyword argument '%s'r  )!r}   r  r1  r  r  r  r   r   r  r  r7  r   r  r   r   r   r   r  r  r  r   r  rW  rq   r   r  r  rH  r  r  r  rP  r  )rU   r  r   r  r  Zdeclared_argsZmatched_argsZunmatched_argsZmatched_kwargs_countr   seenZ
has_errorsr   rq   Zdecl_argr  rH  ZtempskeywordsZfirst_missing_keywordr   rl  Z
final_argsZ	new_tempsZfirst_temp_arg	arg_valuer   rQ   rJ  rR   rG    s   











z'GeneralCallNode.map_to_simple_call_nodec                 C   sz   | j jrd S | jr| j }nd}|jtdd |d| 	 | j
 | j ||| 	 | jf  | | d S )Nr3  r  r  z(%s = __Pyx_PyObject_Call(%s, %s, %s); %s)r   r  r  r   r   r   r   r   r   r   r  r  r   r   r  )rU   r   r  rQ   rQ   rR   rv  3  s"   
z$GeneralCallNode.generate_result_codeN)rX   rY   rZ   r   r   r   r,   rN  rO  r  r  r  r"  rG  rv  rQ   rQ   rQ   rR   rF  [  s    	  rF  c                   @   sH   e Zd ZdgZdZdd Zdd Zdd Zd	d
 Ze	j
ZdZdd ZdS )AsTupleNoder   r)   c                 C   r(  rJ   )r   r   r~   rT   rQ   rQ   rR   r  N  r   z%AsTupleNode.calculate_constant_resultc              
   C   sH   | j |}zt|W S  ty# } z| | W Y d }~d S d }~ww rJ   )r   r  r   r  r  )rU   r  r   r  rQ   rQ   rR   r  Q  s   
zAsTupleNode.compile_time_valuec                 C   s6   | j ||| _ | j jtu r| j dS t| _| S Nr^  )r   r"  r  r   r   r  r   rQ   rQ   rR   r"  X  s
   zAsTupleNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  _  rW   zAsTupleNode.may_be_noneConstructing Python tuplec              
   C   sT   | j jttfv r
dnd}|d|  || j  ||  | jf  | 	| d S )NZ__Pyx_PySequence_TupleZPySequence_Tupler=  )
r   r   r   r   r   r   r   r   r   r  )rU   r   r  rQ   rQ   rR   rv  e  s   
z AsTupleNode.generate_result_codeN)rX   rY   rZ   r   r   r  r  r"  r  r,   rN  rO  r  rv  rQ   rQ   rQ   rR   rO  E  s    rO  c                   @   sb   e Zd ZdgZdZeZdZdd Zdd Z	dd	 Z
d
d Zdd Zdd ZdZdd Zdd ZdS )MergedDictNoder  r)   Tc                 C   sp   i }| j }| jD ]*}|jrdd |jD }n|j }|D ]\}}|r-||v r-td| |||< qq|| _d S )Nc                 s   s     | ]\}}|j |j fV  qd S rJ   r  ra   r  r   rQ   rQ   rR   re     s    z;MergedDictNode.calculate_constant_result.<locals>.<genexpr>$duplicate keyword argument found: %s)reject_duplicatesr  r  r  r~   	iteritemsr   )rU   r   rU  r   rR  r  r   rQ   rQ   rR   r  y  s   



z(MergedDictNode.calculate_constant_resultc           	         s   i }| j }| jD ]G}|jr fdd|jD }n|  }z|D ]\}}|r2||v r2td| |||< q"W q tyO } z| | W Y d }~qd }~ww |S )Nc                    s$   g | ]\}}|  |  fqS rQ   r  rS  r  rQ   rR   r     s    z5MergedDictNode.compile_time_value.<locals>.<listcomp>rT  )	rU  r  r  r  r  rV  r   r  r  )	rU   r  r   rU  r   rR  r  r   r  rQ   r  rR   r    s&   


z!MergedDictNode.compile_time_valuec                 C   rS   r  rQ   r   rQ   rQ   rR   r3    rW   z MergedDictNode.type_dependenciesc                 C   r/  rJ   r   r   rQ   rQ   rR   r     rW   zMergedDictNode.infer_typec                    r  )Nc                    "   g | ]}|   d qS )z1argument after ** must be a mapping, not NoneTyper"  r  r  r   ry   rQ   rR   r         z0MergedDictNode.analyse_types.<locals>.<listcomp>)r  r   rQ   ry   rR   r"    s   
zMergedDictNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r    rW   zMergedDictNode.may_be_noneConstructing Python dictc              
   C   sR  | | j | | t| j}t|}|| |jtur'|	d|
   |jrB|| |	d|  |
 f  || nb| r||	d |	d|
  d|  d |	d|  |
 f  || |	d |	d |	d	 |	d
|  |
 ||  |jf  | | || | r|	d |jtur|	d |jtdd |	d|  |
 ||  | jf  | | || |	d || t }|D ]}|jrC|jD ]R}|| | jr"|	d|  |j
 f  |d |	d|j
 || jf  |	d ||jjd|  |j
 |j 
 f  || || qq|| | jra|d ||jd|  |
 f  n)|d |	d|  |
 f  |	d|
   |	||j |	d || || qt!|D ]}|jt|d qd S )Nz$if (likely(PyDict_CheckExact(%s))) {r  zB#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_APIz!if (__Pyx_IS_UNIQUELY_REFERENCED(r>  z)) {z} elserk  r6  z%s = PyDict_Copy(%s); %sr   rm  r  r  z?%s = __Pyx_PyObject_CallOneArg((PyObject*)&PyDict_Type, %s); %s(if (unlikely(PyDict_Contains(%s, %s))) {RaiseDoubleKeywords2__Pyx_RaiseDoubleKeywordsError("function", %s); %sPyDict_SetItem(%s, %s, %s)ZMergeKeywordsz__Pyx_MergeKeywords(%s, %s)ZRaiseMappingExpectedz*if (unlikely(PyDict_Update(%s, %s) < 0)) {zVif (PyErr_ExceptionMatches(PyExc_AttributeError)) __Pyx_RaiseMappingExpectedError(%s);FunctionArguments.c)"ru  r   re  r~  r  r  r{  r   r   r   r   r  rn  r   r  rX  r  r   r  r  r   r   r   r   r  r  r  rU  r  r  r   r  r   rP  )rU   r   r   r   helpersr   helperrQ   rQ   rR   r{    s   





 


























z'MergedDictNode.generate_evaluation_codec                 C      | j D ]}|| qd S rJ   )r  r  rU   r   r   rQ   rQ   rR   r       
zMergedDictNode.annotateN)rX   rY   rZ   r   r   r   r   rU  r  r  r3  r   r"  r  r  r{  r  rQ   rQ   rQ   rR   rR  o  s    
^rR  c                   @   sH  e Zd ZdZdgZdZdZdZdZdZ	dZ
dd Zd	d
 Zdd Zdd Zdd Zdd Zdd Zdd ZdJddZdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( ZdKd)d*ZdLd+d,Zd-d. Zd/d0 Zd1Z d2d3 Z!d4d5 Z"d6d7 Z#d8d9 Z$d:d; Z%d<d= Z&d>d? Z'd@dA Z(		dMdBdCZ)dNdDdEZ*dFdG Z+dHdI Z,dS )Or  r)   r  Nr   TFc                 C   sD   t | jtr| jjr| jdks| jS | j }|r d|| jf S d S )NZparallel%s.%s)r}   r  r  r  r  r  )rU   cyrQ   rQ   rR   r  0  s   

z!AttributeNode.as_cython_attributec              	   C   s  |t u rz| j}|r|jr|jrd| _|j| _| | | S |rz|jrz| jjtj	urzddl
m}m} || j| jjd}| jj|_|| _t| ||}tdd}ttj tdtj d tdtj d g}	t| jd|	||g|d	}
|||
}||S t| ||S )
Nr)   r  r  ZPyMethodNew2Argr  rd  rU   Z__Pyx_PyMethod_New2Arg)r  r&  r   r  )r   r   r7  r  r   analyse_as_python_attributer  r   r   r   r  r  r  r  r   r  r   r   r   r  r  rC  r   r"  )rU   r  rs   r   r  r  Zobj_nodeZunbound_noder  r&  Zbinding_callZcomplete_callrQ   rQ   rR   r  ;  s@   



zAttributeNode.coerce_toc                 C   s2   | j }|dr|drd S t| jj|| _d S )N__)r  
startswithendswithr   r  r~   )rU   ru  rQ   rQ   rR   r  e  s   z'AttributeNode.calculate_constant_resultc              
   C   sx   | j }|dr|drt| jd|  d S | j|}zt||W S  ty; } z| 	| W Y d }~d S d }~ww )Nri  z6Invalid attribute name '%s' in compile-time expression)
r  rj  rk  r   r   r  r  r   r  r  )rU   r  ru  r  r  rQ   rQ   rR   r  k  s   z AttributeNode.compile_time_valuec                 C   r  rJ   )r  r3  r   rQ   rQ   rR   r3  w  r  zAttributeNode.type_dependenciesc                 C   s   | j |dd}|d ur|jjr|jjjrt|jjS |jjS | |}|d ur,|jjS | j|}| j	||d |j
rB| jjrBtS | jrK| jjrKtS | jS )NFtarget)obj_type)#analyse_as_cimported_attribute_noder   r   r7  r   r  analyse_as_type_attributer  r   analyse_attributer  r   r  )rU   rs   r   rn  rQ   rQ   rR   r   z  s   
zAttributeNode.infer_typec                 C   r  r+  r  r   rQ   rQ   rR   r    rM  z(AttributeNode.analyse_target_declarationc                 C   sF   | j |dd}|jjrt| jd| j  | s!t| jd| j  |S )Nr)   rl  z"Assignment to const attribute '%s'r  )r"  r   r  r   r   r  r   r$  rQ   rQ   rR   r*    s   z"AttributeNode.analyse_target_typesc                 C   s   | j stj| _ |jd | _| ||}|d u r|s| |}|d u r.| ||}|d us.J |js4|j	r;|j
r;d|j
_|jrC|| |S )Nr  T)r   r   r0   rk   r  ro  rp  "analyse_as_ordinary_attribute_noder  r   r   r  wrap_obj_in_nonecheck)rU   rs   rm  r   rQ   rQ   rR   r"    s   

zAttributeNode.analyse_typesc                 C   sp   | j |}|r6|| j}|r&|js&|js|js|js|jr&| 	|||S | 
|r6t| jd| j  | S d S )Nz&cimported module has no attribute '%s')r  rA  r  r  r  r  r7  rw  r  as_name_noder  r   r   )rU   rs   rm  module_scoper   rQ   rQ   rR   ro    s"   

z1AttributeNode.analyse_as_cimported_attribute_nodec                    s<  j jrd S j  rjsjsjrSjj}|rQ|j	s*jrQ|j
jrQjr5js2d S |}n| } fdd|jD |_j |ddS d S jsYjrjjv rjjD ]}|jjkruj |dd  S qctjdjf  d S jdrjdrd S tjdjf  d S )Nc                    s   g | ]	} | qS rQ   )_create_unbound_cmethod_entry)ra   Zoverloaded_alternativers   rU   r   rQ   rR   r     s    z;AttributeNode.analyse_as_type_attribute.<locals>.<listcomp>Frl  z%s not a known value of %sri  )r  r   rC  r  r  r   r  r  r  r  r   r7  r"  rv  Zoverloaded_alternativesrt  r  r  r  r   Zenum_valuesrq   r   r   rj  rk  )rU   rs   r   
ubcm_entryrQ   rw  rR   rp    s:   z'AttributeNode.analyse_as_type_attributec                 C   s   |j rG|jjd u rG|j }|jjs|jr|jjr|j}n7|jr-t| jd|j	|f  t
j}n%t|j}|jd d  |_t
d|dd |jd< nd|j|jf }|j}t|j	||}d|_|j |_ d|_|j|_|S )Nz%s not a static member of %srU   r   %s->%sr)   )Z
func_cnamer   r  r  parent_scopeZis_cpp_class_scoper   r   r   rq   r   r0   r#   r   r  Zvtabptr_cnamer   r   r  r7  r  r  )rU   r   r   rs   r   r  rx  rQ   rQ   rR   rv    s,   z+AttributeNode._create_unbound_cmethod_entryc                 C   sV   | j |}|r|| jS | j js)| j |}|r)t|dd d ur)|j| jS d S )Nr  )r  rA  lookup_typer  r   rC  r   r  )rU   rs   ru  r  rQ   rQ   rR   rC     s   zAttributeNode.analyse_as_typec                 C   s@   | j |}|r|| j}|r|jr|jjs|jjr|jS d S rJ   )r  rA  r  r  rw  r   r  r  rU   rs   ru  r   rQ   rQ   rR   rI  
  s   
z'AttributeNode.analyse_as_extension_typec                 C   s0   | j |}|r|| j}|r|jr|jS d S rJ   )r  rA  r  r  r  r|  rQ   rQ   rR   rA    s   
zAttributeNode.analyse_as_modulec                 C   s8   t j| | j|d}|r||}n||}d|j_|S )N)rq   r   r)   )r  r  r  r*  r  r   r  )rU   rs   r   rm  r   rQ   rQ   rR   rt    s   
zAttributeNode.as_name_nodec                 C   s   | j || _ | | | jr| jjr| js	 | jr$|s"d| _t| _	| S |r3| j j
jr3t| jd | S | jrO| jjrO|sIt| j| j | j|S t| jd | S )Nr)   z'Assignment to an immutable object fieldz"Assignment to a read-only property)r  r"  rq  r   r  r"  r  r   r   r  r   r  r   r   is_cpropertyr  r  )rU   rs   rm  rQ   rQ   rR   rr  *  s"   

z0AttributeNode.analyse_as_ordinary_attribute_nodec                 C   s  |d u}d| _ | j| _|d u r%| jjjs| jjjr | j|| _| jj}n|js+|jr-t}|j	s3|j
r:|j}d| _n|js@|jrDd| _n|jrN|jrNd| _nd| _|jr| r|j| j}|jr|s| jdkr}d| _d| _d| _| jj| j| _d S || j|| j |j| j}|r|jrd }nt| jd|  tj| _d S || _ |r|jr|j!dkrt| jd |j"r|j| _d S |j#r|j$r|j%r|j| _|j&| _d S 	 | '||| d S )	Nr   r  r  TTz/Cannot select attribute of incomplete type '%s'__weakref__z,Illegal use of special attribute __weakref__)(r  r  r  r  r   rw  rx  r  r   r  r6  r  rh  r  r  r   Zis_fake_referenceZhas_attributesZattributes_knownr  r  r   is_memslice_transposer   rd  Z	transposer   Zdeclare_attributer  r   r   r0   r   rq   r}  r  r  r  r   rh  )rU   rs   rn  immutable_objr   rQ   rQ   rR   rq  B  sh   



zAttributeNode.analyse_attributec                 C   s   |d u r| j j}|| j| _| j| _t| _d| _|js||js~|j	s>|j
s>|js>|js>|js>|jr6||s>|jrK||rK|sI| j || _ d S d S |jro| j jsV| j jro| j jjro| j jjjjro|sm| j || _ d S d S t| jd|| jf  d S d S d S )Nr)   z)Object of type '%s' has no attribute '%s')r  r   Zmangle_class_private_namer  r  r   r  rp   r  rw  r  r  r   r]  r  r  	is_structr  r7  r   r  r   r  r   r   )rU   rs   rn  r  rQ   rQ   rR   rh    sN   z)AttributeNode.analyse_as_python_attributec                 C   s   |j d sd S d }d}| jjjr)| jr)| js)dt| jdkr!dnd}| jf}n| jjj	rE| j
r4d}n| jjj| j}|rEd}|jf}|rS| jj|d	|d
| _d S d S )Nr:  rQ   r  r  r  r  z&Cannot transpose None memoryview slicez5Cannot access '%s' attribute of None memoryview slicer  r  )rk   r  r   r  needs_none_checkr  r   r   r  r   r  r  r  rq   r  )rU   rs   r  r  r   rQ   rQ   rR   rs    s*   



z#AttributeNode.wrap_obj_in_nonecheckc                 C   s   | j r	|   d S d S rJ   )r  rN  r   rQ   rQ   rR   rO    s   zAttributeNode.nogil_checkzAccessing Python attributec                 C   r  rJ   )r  r  r   rQ   rQ   rR   r    r  z0AttributeNode.is_cimported_module_without_shadowc                 C   s"   | j r|  p| j  S t| S rJ   )r  rX  r  r  rT   rQ   rQ   rR   r    s   
zAttributeNode.is_simplec                 C   s   | j rdS t| S r+  )r  r  r   rT   rQ   rQ   rR   r     s   
zAttributeNode.is_lvaluec                 C   s   | j r| j  S t| S rJ   )r  r   r  rT   rQ   rQ   rR   r     s   

zAttributeNode.is_ephemeralc                 C   s(   |   }| jr| jjr| jsd| }|S rW  )calculate_access_coder   r  r  )rU   r   rQ   rQ   rR   r     s   z#AttributeNode.calculate_result_codec                 C   s   | j }||j}| jr@| jjr@|jjr8| jjs8| jjr | jjS | jjr)| jj	| _
d|jj|| j|jj| j
f S | jr>| j
S d S |jjrMd| j
 |f S |jjrb| jrb| jjrb|jj| dd}d|| j| j
f S )Nz((struct %s *)%s%s%s)->%sz__Pyx_C%s(%s)T)Zto_object_structz%s%s%s)r  r   r   r   r  r  Zis_builtin_cmethodZfinal_func_cnameZ
from_fusedr   r  Zvtabstruct_cnamerh  Zvtabslot_cnamera  r  upperr  r  	cast_coder   )rU   r  Zobj_coderQ   rQ   rR   r    s(   

z#AttributeNode.calculate_access_codec                 C   s  | j rB| jr|jtdd d}n|jtdd d}|d|  || j	 |
| j||  | jf  | | d S | jjr| jr| jjD ]\}}|dkr^t| jd  d S qM|d	|  | j f  |j|  | jd
d d|   }|||| j d S | jr|d|  || jf  d S d S | jjr| jr| jr|  }n	| jrJ |  }| j|}|j| j| j| j|d d S | jjr| jjj rd S | jr| jj!r|j"| j d S d S d S )NZPyObjectLookupSpecialr  Z__Pyx_PyObject_LookupSpecialZPyObjectGetAttrStrZ__Pyx_PyObject_GetAttrStrr  ri  z=Transposing not supported for slices with indirect dimensionsr  Tro  z__pyx_memslice_transpose(&%s)zeif (unlikely(!%s.memview)) {PyErr_SetString(PyExc_AttributeError,"Memoryview is not initialized");%s}r  )#r  r  r   r   r   r   r   r   r  r   r  r  r   r   r  r   r   r  r  r   rq  rs  r  r   r   r  r  r   r  r
  r  rr  r  r  r  )rU   r   Zlookup_func_namers  rt  r~  Zundereferenced_resultr  rQ   rQ   rR   rv     sh   




z"AttributeNode.generate_result_codec                 C   s>   | j r| jjr| jr|j|  | jdd d S t| | d S )NTro  )r   r   r   r  r!  r   r   r  rm  rQ   rQ   rR   r  ;   s   z$AttributeNode.generate_disposal_codec              
   C   s  | j | | jr3|jtdd || jd| j 	 |
| j|	 f  || || n| j jjr_|d| j | j jj| j | j j||  f  || || nW|  }| jjr| jr|| || ||| j |||   n| jjrddlm} | ||| | j| | jjs|d||!|  f  |"| || | j | | j | d S )Nr  r  z%__Pyx_PyObject_SetAttrStr(%s, %s, %s)z__Pyx_SET_C%s%s(%s, %s);r)   r  r  )#r  r{  r  r   r   r   r   r  r   r   r  r  r  r  r   r  r   r  r  Zimplementation_suffixr   r  r   rp   rd  rn  r  r  
put_decrefr   r  r  Zput_assign_to_memviewslicer   r  )rU   r   r   r  r   r   Zselect_coder  rQ   rQ   rR   r  B   sZ   








z&AttributeNode.generate_assignment_codec                 C   s   | j | | js| jjjr2d| jjjv r2|jt	
dd || jd| j  || jf  nt| jd | j | | j | d S )N__del__r  r  r  z+Cannot delete C attribute of extension type)r  r{  r  r   r  Zis_property_scoperQ  r   r   r   r   r  r   r   r  r  r   r  r  r  rQ   rQ   rR   r  n   s   

z$AttributeNode.generate_deletion_codec                 C   s@   | j rd\}}nd\}}|| jt||| j t| jd d S )N)Zpy_attrzpython attribute (%s))Zc_attrzc attribute (%s)r#  )r  r  r   r5   r   r   r  )rU   r   r%  r&  rQ   rQ   rR   r  }   s   
(zAttributeNode.annotatec                 C   s&   | j  }|rtd|| jf S d S )Nrf  )r  r  r   r  r  )rU   r*  rQ   rQ   rR   r     s   
z/AttributeNode.get_known_standard_library_importr  rJ   rR  r  r  )-rX   rY   rZ   r  r   r   r"  r  r  r  r  r  r  r  r  r3  r   r  r*  r"  ro  rp  rv  rC  rI  rA  rt  rr  rq  rh  rs  rO  r  r  r  r   r   r   r  rv  r  r  r  r  r  rQ   rQ   rQ   rR   r    sZ    *
&



F$9

,r  c                   @   sb   e Zd ZdgZdZeZdZdZdd Z	dd Z
dd	 Zd
d Zdd Zdd Zdd Zdd ZdS )StarredUnpackingNoderm  r)   Fc                 C   r  )Nrl  rA  )rU   r   rm  rQ   rQ   rR   r     r  zStarredUnpackingNode.__init__c                 C   s"   | j s	t| jd | j| d S Nz&starred expression is not allowed here)starred_expr_allowed_herer   r   rm  rK  r   rQ   rQ   rR   rK     s   z)StarredUnpackingNode.analyse_declarationsc                 C   r  rJ   )rm  r   r   rQ   rQ   rR   r      r  zStarredUnpackingNode.infer_typec                 C   s.   | j s	t| jd | j|| _| jj| _| S r  )r  r   r   rm  r"  r   r   rQ   rQ   rR   r"     s
   
z"StarredUnpackingNode.analyse_typesc                 C   r!  rJ   )rm  r  r   rQ   rQ   rR   r     r   z/StarredUnpackingNode.analyse_target_declarationc                 C   s   | j || _ | j j| _| S rJ   )rm  r*  r   r   rQ   rQ   rR   r*     s   
z)StarredUnpackingNode.analyse_target_typesc                 C   rS   r  rQ   rT   rQ   rQ   rR   r      rW   z*StarredUnpackingNode.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv     rW   z)StarredUnpackingNode.generate_result_codeN)rX   rY   rZ   r   r   r   r   r   r  r  rK  r   r"  r  r*  r   rv  rQ   rQ   rQ   rR   r     s    r  c                
       s   e Zd ZddgZdZdZdZdZdZdd Z	dd	 Z
d
d Zd,ddZdd Zdd Zdd Zdd Zdd Zdd Zd-ddZ fddZ		d.ddZeeejed ejdgZd!d" Zd#d$ Zd/d&d'Zd(d) Zd*d+ Z   Z!S )0SequenceNoder   r   r)   NFc                    s    fdd| j D S )Nc                    r2  rQ   r  r   r  rQ   rR   r      r   z8SequenceNode.compile_time_value_list.<locals>.<listcomp>r  r  rQ   r  rR   compile_time_value_list   r  z$SequenceNode.compile_time_value_listc                 C   sT   d| _ g }| jD ]}|jr| j rt|jd d| _ |j}d|_|| q|| _d S )NFz,more than 1 starred expression in assignmentT)starred_assignmentr   r   r   r   rm  r   rU   r   r   rQ   rQ   rR   replace_starred_target_node   s   

z(SequenceNode.replace_starred_target_nodec                 C   s"   |    | jD ]}|| qd S rJ   )r  r   r  rU   rs   r   rQ   rQ   rR   r     s   
z'SequenceNode.analyse_target_declarationc                 C   s   t | jD ]\}}|s||}||| j|< q| jr1| j|}|jjs+||}||| _d| _|j	sA|j
sA|jrD|jj	rDd| _| S Nr)   T)r  r   r"  r  r   r   r  r0  r   r  r  r  rH  slow)rU   rs   skip_childrenr  r   r   rQ   rQ   rR   r"     s"   

zSequenceNode.analyse_typesc                    s   t j|dd}| j|kr| S | jrJ t| j|jkr)t| jd|jt| jf   fddt	| j|j
D }t| j||ddS )NTr  zHtrying to coerce sequence to ctuple of wrong length, expected %d, got %dc                    s   g | ]
\}}| | qS rQ   )r  )ra   r   r   ry   rQ   rR   r   
!  r  z1SequenceNode.coerce_to_ctuple.<locals>.<listcomp>)r   r   r   )r   r  r   r   r   r   r$  r   r   rW  r  r1  rU   r  rs   Zcoerced_argsrQ   ry   rR   coerce_to_ctuple !  s   

zSequenceNode.coerce_to_ctuplec              	   C   s   |    tdd | jD s| S g }g }| jD ]&}|jr8|r1|t|d j|dj|dd g }||j q|| q|rQ|t|d j|dj|dd t	| j|| j
}| jrmt| jd|| j|d| j
dd}|S )	Nc                 s       | ]}|j V  qd S rJ   )r   r   rQ   rQ   rR   re   !      z?SequenceNode._create_merge_node_if_necessary.<locals>.<genexpr>r   r  Tr  r   )inplacer   r   )_flatten_starred_argsrl   r   r   r   r1  r   r"  rm  MergedSequenceNoder   r   
binop_noder  )rU   rs   r   r  r   r   rQ   rQ   rR   _create_merge_node_if_necessary!  s*   
""z,SequenceNode._create_merge_node_if_necessaryc                 C   sR   g }| j D ]}|jr|jjr|jjs||jj  q|| q|| j d d < d S rJ   )r   r   rm  r   r   r   r   r  rQ   rQ   rR   r  %!  s   
z"SequenceNode._flatten_starred_argsc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  .!  rW   zSequenceNode.may_be_nonec                 C   s   | j r	t| jd g | _g | _d| _t| jD ]E\}}|| }| j|< |j	r<|j
ts4t|jd |j
tu r<t|_
t| j|}||j
|}||urPd| _| j| | j| qt| _
| S )Nz#can't assign to multiplied sequenceFz2starred target must have Python object (list) typeT)r   r   r   unpacked_itemscoerced_unpacked_itemsZany_coerced_itemsr  r   r*  r   r   r  r   r   r  r  r   )rU   rs   r  r   Zunpacked_itemZcoerced_unpacked_itemrQ   rQ   rR   r*  1!  s,   
z!SequenceNode.analyse_target_typesc                 C   rJ  rJ   generate_operation_coderm  rQ   rQ   rR   rv  H!  rL  z!SequenceNode.generate_result_codec                 C   sF  |d u r|   }d }}d }| jr?|s?| j}|jjr?|  }t|jtr/|jdkr/d|j }n|jjr:d||f }nd|f }| jtu sI| jt	u r| j
sO| jr|st| jdkr| jt	u rjd}|jtdd nd	}|d
||t| jddd | jD ||| jf  ||t d| _n| jjrt| jD ]\}}	|d|||	  f  qn| jt	u rd\}
}n| jtu rd\}
}ntd| j t| j}|d||
||||| jf  ||t |rtj}|d|  |dkr|}nd||f }|d||||f  d| _nd}t|D ]A}| j| }	|s#|	 s-| |	  |	!  |	"| |d|||rD|rDd||f pH|pH||	# |$| jf  q|rc|d |d |d ur|jj%r|dtj||# |tj| jf  |tjt |&|t |d|tjf  |d d S d S d S )Nr  r   z * %sz * ((%s<0) ? 0:%s)z * (%s)Z__Pyx_PyList_PackZListPackr  ZPyTuple_Packz%s = %s(%d, %s); %sr>  c                 s   r8  rJ   r2  r   rQ   rQ   rR   re   m!  rf   z>SequenceNode.generate_sequence_packing_code.<locals>.<genexpr>Tz%s.f%s = %s;)Z
PyList_NewZ__Pyx_PyList_SET_ITEM)ZPyTuple_NewZ__Pyx_PyTuple_SET_ITEMz'sequence packing for unexpected type %sz%s = %s(%s%s); %sz{ Py_ssize_t %s;r)   z%s * %szfor (%s=0; %s < %s; %s++) {zif (%s(%s, %s, %s) != (0)) %s;z%s + %sr   z5{ PyObject* %s = PyNumber_InPlaceMultiply(%s, %s); %sr  )'r   r   r   r  r}   r~   r   r!  r   r   r   r  r   r   r   r   r   r   r   rA  r   r   r  r   needs_subexpr_disposalr  r  r   r   r  r0  rX  rl  r  r  r   r   rp   r  )rU   r   rm  plainZsize_factorZc_multr   Z	pack_namer  r   Zcreate_funcZset_item_func	arg_countZcounteroffsetrQ   rQ   rR   generate_sequence_packing_codeK!  s   













"


z+SequenceNode.generate_sequence_packing_codec                    sF   | j rt | d S | jD ]}|| q| jr!| j| d S d S rJ   )r  rL   ry  r   r  r   r  rU   r   r   rO   rQ   rR   ry  !  s   
z+SequenceNode.generate_subexpr_disposal_codec                 C   sD   | j r
| || n| || | jD ]}|| q|| d S rJ   )r   generate_starred_assignment_code!generate_parallel_assignment_coder  r  r  )rU   r   r   r  r   r   r   rQ   rQ   rR   r  !  s   
z%SequenceNode.generate_assignment_coderb  c                 C   s   | j D ]}|| q|jtu p|jttfv p|jj }t| j dk}|r.| j|||d n|	d | j
||| j |d |	d | jD ]}|| qEtt| jD ]}| j| | j| | qTd S )N   use_loopr6  r   )r  r  r   r   r   r   r  r   (generate_special_parallel_unpacking_coder   (generate_generic_parallel_unpacking_coder  r{  r0  r   r  )rU   r   r   r   Zspecial_unpackZlong_enough_for_a_loop
value_noder  rQ   rQ   rR   r  !  s0   







z.SequenceNode.generate_parallel_assignment_codec              
   C   sZ  d}d|   }|jtu rdg}d}| r|}n)|jtu r*dg}d}| r)|}nddg}d}d|   }d	|   }	d
||	f }|d|  |d|    |d|  |dt| j  |j	t
dd |dt| jt| jf  |j	t
dd |d ||| j |d |d t|dkr|d|d   t| jD ]J\}
}|d dkr||  d|
 d|   d ||| | j || |  q||  d|
 d || |  qt|dkra|d t| jD ]M\}
}|d dkrC||  d|
 d|   d ||| | j || |  q||  d|
 d || |  q|d |d |st| jD ]!\}
}|d | |
|| | jf  || |j qnnJ|d! |d" |d#t| jd$d%d& | jD f  |d't| j  |d(|d)| j  |d)t |d* |d |d |d+ || |dkr|d d S ||kr|d |j	t
d,d |d-|| j  |d d S |d | j||| j|d. |d d S )/Nr@  zlikely(%s != Py_None)r{  rh  r|  ri  Z__Pyx_PySequence_SIZEzlikely(PyTuple_CheckExact(%s))zPyList_CheckExact(%s)z(%s) || (%s)r  zPyObject* sequence = %s;zPy_ssize_t size = %s(sequence);zif (unlikely(size != %d)) {ZRaiseTooManyValuesToUnpackr  z1if (size > %d) __Pyx_RaiseTooManyValuesError(%d);RaiseNeedMoreValuesToUnpackz9else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);r   r  r4   z(if (likely(Py%s_CheckExact(sequence))) {r   z) = __Pyx_PyList_GetItemRefFast(sequence, r>  r?  z = PyTuple_GET_ITEM(sequence, rm  r)   r  z,%s = __Pyx_PySequence_ITEM(sequence, %d); %sr6  zPy_ssize_t i;PyObject** temps[%s] = {%s};r7  c                 S      g | ]}d |   qS r  r9  r   rQ   rQ   rR   r   4"  ra  zISequenceNode.generate_special_parallel_unpacking_code.<locals>.<listcomp>zfor (i=0; i < %s; i++) {z7PyObject* item = __Pyx_PySequence_ITEM(sequence, i); %sr   z*(temps[i]) = item;rk  ZRaiseNoneIterErrorz%__Pyx_RaiseNoneNotIterableError(); %sr  )r   r   r   r  r   r   r   r   r   r   r   r   r   r   r  r  r   r  r   r  r  rl  r  rA  r   r  r  )rU   r   r   r  Zsequence_type_testZ
none_checkr3   Zget_size_funcZtuple_checkZ
list_checkr  r   rQ   rQ   rR   r  !  s   








$














z5SequenceNode.generate_special_parallel_unpacking_codeTc              	   C   sH  |j tdd |j tdd |d |r/|dt| jddd |D f  |jj	t
d	d
}|d|| ||| jf  ||t
 || |jj	| jdd
}|| d| d |d}d||f }	|r|dt|  |d|	  || |dt
 |d |d n"t|D ]\}
}|d|
| |	| f  || || q|r|j tdd || jd|	t|f  |d|  ||t
 |d}|| || ||t
 |d|  |d ||| j || |j| |r"|j| d }|S )Nr  r  Z
IterFinishzPy_ssize_t index = -1;r  r7  c                 S   r  r  r9  r   rQ   rQ   rR   r   Y"  ra  zISequenceNode.generate_generic_parallel_unpacking_code.<locals>.<listcomp>Tr]  rn  Fro  r?  Zunpacking_failedr  z$for (index=0; index < %s; index++) {z*PyObject* item = %s; if (unlikely(!item)) r   z*(temps[index]) = item;r   z(index = %d; %s = %s; if (unlikely(!%s)) ZUnpackItemEndCheckz$__Pyx_IternextUnpackEndCheck(%s, %d)rl  Zunpacking_donezCif (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);)r   r   r   r   r   r   r  rA  rb  rc  r   r   r   r   r  r  rt  rT  rv  rU  r  r   r  r  r  rX  r   rj  )rU   r   r   r  r  	terminateiterator_tempZiternext_funcZunpacking_error_labelZunpack_coder  r   Zunpacking_done_labelrQ   rQ   rR   r  O"  s   














z5SequenceNode.generate_generic_parallel_unpacking_codec                 C   s^  t | jD ]\}}|jr#| j| }| jd | }| j|d d  } nqJ d }|r[|D ]}	|	| q,|d | j|||ddd}t |D ]\}}	| j| }
|
| qG|d || |	 }|d||sw|
 rw|jttfv rwdnd	|p}| ||| jf  || |r||t |j| n|| |r|jtd
d |jjtjdd}|d||f  |d|t|f  |dt|||| jf  |d |d d d D ]}	|	| qt t|d d d | jd d d D ]E\}\}	}|d |d|	 |||d f  |d|  |d |d|	 |||d f  |d |	| || q |d |jjtdd}|d|||t|||| jf  | |t |j| |!|t |d|||f  |d |d|  |j| |d t | jD ]\}}|"| j| | qd S )Nr)   Fr6  T)r  r  r   r=  __Pyx_PySequence_ListKeepNewPySequence_Listr  r  r]  z%s = __Pyx_PyList_GET_SIZE(%s);zif (unlikely(%s < %d)) {z)__Pyx_RaiseNeedMoreValuesError(%d+%s); %sr,  z#if CYTHON_COMPILING_IN_CPYTHONz!%s = PyList_GET_ITEM(%s, %s-%d); z((PyVarObject*)%s)->ob_size--;r  z'%s = __Pyx_PySequence_ITEM(%s, %s-%d); rk  z #if !CYTHON_COMPILING_IN_CPYTHONz*%s = PySequence_GetSlice(%s, 0, %s-%d); %s%s = %s; %s = NULL;zCYTHON_UNUSED_VAR(%s);)#r  r   r   r  r  r   r  r  r{  r   rX  r   r   r   r   r   r   r  r  rb  rj  r  r   r   r   r   rc  r   r  r   r   rW  r  r  r  )rU   r   r   r  r   Zstarred_targetZunpacked_fixed_items_leftZunpacked_fixed_items_rightr  r   r  Ztarget_listZlength_tempcoerced_argZsublist_temprQ   rQ   rR   r  "  s   

















z-SequenceNode.generate_starred_assignment_codec                 C   sP   | j D ]}|| q| jr$| jD ]}|| q| jD ]	}|| qd S d S rJ   )r   r  r  r  r  rQ   rQ   rR   r  "  s   


zSequenceNode.annotater  rR  r  rN  )"rX   rY   rZ   r   r   r  r   r  r  r  r  r  r"  r  r  r  r  r*  rv  r  ry  r  r   r  r  r   r  rt  r  r  r  r  r  r[   rQ   rQ   rO   rR   r     s@    	
	
f

fITr  c                   @   sr   e Zd ZeZdZdZdd ZdddZdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )r1  FrQ  c                    sJ   | j s| jstS  fdd| jD }tdd |D rtS  | j|jS )Nc                    r2  rQ   r  r   ry   rQ   rR   r   #  r   z(TupleNode.infer_type.<locals>.<listcomp>c                 s   s(    | ]}|j p|jp|jp|jV  qd S rJ   )rp   r   r  rD  )ra   r   rQ   rQ   rR   re   #  s     z'TupleNode.infer_type.<locals>.<genexpr>)r   r   r   rl   r  r   r   )rU   rs   r  rQ   ry   rR   r   "  s   zTupleNode.infer_typec                 C   sF  | j rd| _ | jrd| _t| jdkrd| _d| _ | S |s5t| jD ]\}}|jr,d|_||| j|< q"| j	sVt
dd | jD sV|| jdd | jD j| _d| _| S tj| |dd}||}|jsh|S td	d |jD st|S |j	r|j	j rt|j	jtrd|_d|_ |S |j	jjs|j	jjs|j	||_	d|_d|_|S )
NFr   Tc                 s   s.    | ]}|j p|jjp|jjp|jjV  qd S rJ   )r   r   rp   r   rD  r   rQ   rQ   rR   re   #  s    &z*TupleNode.analyse_types.<locals>.<genexpr>c                 s   r  rJ   r  r   rQ   rQ   rR   re   #  r  r)   r  c                 s   r  rJ   )r   )ra   childrQ   rQ   rR   re   $#  r  )r   is_partly_literalr   r   r   r  r   r  r"  r   rl   r  r   r   r  r  r   r   r}   r~   r   rp   r  r  )rU   rs   r  r  r   r   rQ   rQ   rR   r"  #  sP   
zTupleNode.analyse_typesc                    sH   | j sd S  fdd| j D }tdd |D rd S  | j|}|jS )Nc                    r2  rQ   )rC  r   ry   rQ   rR   r   6#  r   z-TupleNode.analyse_as_type.<locals>.<listcomp>c                 s   s    | ]}|d u V  qd S rJ   rQ   r`   rQ   rQ   rR   re   7#  rf   z,TupleNode.analyse_as_type.<locals>.<genexpr>)r   rl   r  r   r   )rU   rs   r   r   rQ   ry   rR   rC  2#  s   zTupleNode.analyse_as_typec                    s   | j jr?|jr| j j|jkr| | S |tu s|tu r6 fdd| jD }t| j|t| j	ddj
 ddS |  | S |jrK| j	sK| | S t| | S )Nc                    r2  rQ   )r  r   ry   rQ   rR   r   A#  r   z'TupleNode.coerce_to.<locals>.<listcomp>r)   )r   r   r   r   Tr  )r   r  r$  r  r   r   r   r1  r   r   r"  r  r  r  r  rQ   ry   rR   r  <#  s$   zTupleNode.coerce_toc                 C   0   t | j| j| jd}t| jtrt| j|_|S N)r   r   )r  r   r   r   r}   r~   r   r   rU   rb   rQ   rQ   rR   as_listP#     zTupleNode.as_listc                 C   rS   r+  rQ   rT   rQ   rQ   rR   r  V#  r  zTupleNode.is_simplec                 C   rS   r+  rQ   rT   rQ   rQ   rR   r8  Z#  r  zTupleNode.nonlocally_immutablec                 C   r   rJ   rf  rT   rQ   rQ   rR   r   ^#  r)  zTupleNode.calculate_result_codec                 C   s&   | j rt tdd | jD | _d S )Nc                 S   r  rQ   r  r   rQ   rQ   rR   r   d#      z7TupleNode.calculate_constant_result.<locals>.<listcomp>)r   r   r   r   r~   rT   rQ   rQ   rR   r  a#  s
   z#TupleNode.calculate_constant_resultc              
   C   sZ   |  |}| jd u sJ | jzt|W S  ty, } z| | W Y d }~d S d }~ww rJ   )r  r   r   r  r  rU   r  r  r  rQ   rQ   rR   r  g#  s   

zTupleNode.compile_time_valuec              
   C   sV  t | jdkr|tj| _d S | js| jrt| j	| jr| j
nd g| j }|jd|d}||}|d urL|| j | j||| j d ||t | jrT|| _d S | j
j	jr|jtdd |d|  || j
 ||  | jf  | | d S |d|  || j
 ||  | jf  | | d S d	| j	j_| | d S )
Nr   r   r  )r  PySequenceMultiplyr  z*%s = __Pyx_PySequence_Multiply(%s, %s); %sz"%s = PyNumber_Multiply(%s, %s); %sT)r   r   r  r   Zempty_tupler_  r   r  r   r   r   r  r  ru  r   r  r  r   r  r   r   r   r   r   r   r   r  r   r   r  )rU   r   r  Ztuple_targetr  rQ   rQ   rR   r  o#  s:    




z!TupleNode.generate_operation_codeNr  )rX   rY   rZ   r   r   r  r  r   r"  rC  r  r  r  r8  r   r  r  r  rQ   rQ   rQ   rR   r1  "  s    
	+
r1  c                   @   st   e Zd Zg ZeZdZdZdd Zdd Z	dd Z
d	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )r  FzConstructing Python listc                 C   rS   r  rQ   r   rQ   rQ   rR   r3  #  rW   zListNode.type_dependenciesc                 C   r/  rJ   )r   r   rQ   rQ   rR   r   #  r  zListNode.infer_typec                 C   s.   | j D ]}|jrd|_qt| |}||S r+  )r   r   r  r  r(  r  )rU   rs   r   r   rQ   rQ   rR   r(  #  s   

zListNode.analyse_expressionsc                 C   sb   t dd}t| j| _t| |}W d    n1 sw   Y  ||_|jr*d| _|	|}|S )NTrp  )
r
   r   r   original_argsr  r"  obj_conversion_errorsr  r  r  )rU   rs   errorsr   rQ   rQ   rR   r"  #  s   
zListNode.analyse_typesc           
      C   s4  |j r | jD ]}t| qg | _| j|st| jd|  | S |js&|jr|j	t
jurt| j}| jrYt| jjtrQ| jjdkrJt| jd|  n|| jj9 }nt| jd|  |j	}t
||| _tt| jD ]}| j| }t|try|j}|||| j|< qj| S |jrt| j| t
jd||S | jrt| jd|  | S |jrt| jt|jjkrt| jd|  nDt| jt|jjk rt| jd| d	 tt | j| j|jjD ]#\}\}}}	t|tr|j}n	|	jj!r|j"r|}||	j|| j|< q|| _| S |j#r| $||S t%| _t| jd|  | S )
NzCannot coerce list to type '%s'r   z4Cannot coerce non-positively multiplied list to '%s'z1Cannot coerce dynamically multiplied list to '%s')r  r   z%Cannot coerce multiplied list to '%s'zToo many members for '%s'zToo few members for '%s'r)   )&rp   r  r   r   r  r   r   r6  r  r  r   Zc_void_typer   r   r   r}   r~   r   r   r0  r  r  r   r  r   TypecastNoder   r  r  rO  r   r  rW  r  r  r  r  r0   )
rU   r  rs   rt   r  r  r  r   r  r  rQ   rQ   rR   r  #  s\   

*


&
zListNode.coerce_toc                 C   r(  rJ   rQ   rT   rQ   rQ   rR   r  #  rW   zListNode.as_listc                 C   r  r  )r1  r   r   r   r}   r~   r   r   r  rQ   rQ   rR   as_tuple#  r  zListNode.as_tuplec                 C   sT   | j jr"| jr|jj| j dddd| _d S |jj| j ddd| _d S t| | d S )NFT)r^  Zstaticreusable)r^  r  )r   r6  r  rb  rc  r   r  re  rm  rQ   rQ   rR   re  #  s   
zListNode.allocate_temp_resultc                 C   s"   | j rt dd | jD | _d S )Nc                 S   r  rQ   r  r   rQ   rQ   rR   r   $  r  z6ListNode.calculate_constant_result.<locals>.<listcomp>)r   r   r   r~   rT   rQ   rQ   rR   r  $  s
   z"ListNode.calculate_constant_resultc                 C   s$   |  |}| jr|| j|9 }|S rJ   )r  r   r  )rU   r  lrQ   rQ   rR   r  $  s   
zListNode.compile_time_valuec              
   C   sl  | j jr| jD ]}t| q| | d S | j jr| jrB|d |dtj	  |dj
tj	| j d dt| jtj	f }nd}t| jD ]4\}}|j jrn|jtdd |d	|  ||| |  f  qI|d
|  ||| f  qI| jr|d |d d S d S | j jrt| j| j jjD ]\}}|d|  |j| f  qd S td)Nr6  zPy_ssize_t %s;z&for ({i} = 0; {i} < {count}; {i}++) {{)r  countz+ (%d * %s)r  r  r  z'memcpy(&(%s[%s%s]), %s, sizeof(%s[0]));z%s[%s%s] = %s;r   r  zList type never specified)r   rp   r  r   r  r6  r   r   r   r  r   r   r   r   r  r   r   r   r   r  rW  r  rO  r   r   )rU   r   rt   r  r  r   r  rQ   rQ   rR   r  $  sN   







z ListNode.generate_operation_codeN)rX   rY   rZ   r  r   r   r  r  r3  r   r(  r"  r  r  r  re  r  r  r  rQ   rQ   rQ   rR   r  #  s     
2r  c                   @   sb   e Zd ZdgZdZeZdd Zdd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd ZdS )ComprehensionNodeloopTc                 C   r   rJ   r  r   rQ   rQ   rR   r   =$  r)  zComprehensionNode.infer_typec                 C   sj   | | j _| | t| jtjr't| jjtsJ | jj| jjd | d S t| jtj	s3J | jd S rJ   )
r   rm  rI  r}   r  r   _ForInStatNoder  rE  ForFromStatNoder   rQ   rQ   rR   rK  @$  s   
z&ComprehensionNode.analyse_declarationsc                 C   r!  rJ   )r  rK  r   rQ   rQ   rR   rL  J$  r   z-ComprehensionNode.analyse_scoped_declarationsc                 C   s   | j s
| j|| _| S rJ   rG  r  r(  r   rQ   rQ   rR   r"  M$     zComprehensionNode.analyse_typesc                 C   s   | j r
| j|| _| S rJ   r  r   rQ   rQ   rR   rM  R$  r  z,ComprehensionNode.analyse_scoped_expressionsc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  W$  rW   zComprehensionNode.may_be_nonec                 C   rJ  rJ   r  rm  rQ   rQ   rR   rv  Z$  rL  z&ComprehensionNode.generate_result_codec              	   C   s   | j tju r	d}n| j tju rd}n| j tju rd}ntd| j  |d|  |||  | j	f  | 
| | j| d S )NzPyList_New(0)zPySet_New(NULL)zPyDict_New()z"illegal type for comprehension: %sr  )r   r   r   r   r   r   r   r   r   r   r  r  generate_execution_code)rU   r   Zcreate_coderQ   rQ   rR   r  ]$  s   
z)ComprehensionNode.generate_operation_codec                 C   r!  rJ   )r  r  rm  rQ   rQ   rR   r  m$  r   zComprehensionNode.annotateN)rX   rY   rZ   r   r   r  r~   r   rK  rL  r"  rM  r  rv  r  r  rQ   rQ   rQ   rR   r  5$  s    
r  c                   @   s<   e Zd ZdgZdZejZdd Zdd Z	dd Z
d	d
 ZdS )ComprehensionAppendNoder{  Nc                 C   s*   | j || _ | j jjs| j || _ | S rJ   )r{  r(  r   rp   r  r   rQ   rQ   rR   r(  z$  s   
z+ComprehensionAppendNode.analyse_expressionsc              	   C   s   | j jtu r|jtdd d}n| j jtu rd}ntd| j j | j	
| ||d|| j  | j	 f | j | j	| | j	| d S )NListCompAppend
Optimize.c__Pyx_ListComp_Append	PySet_Addz'Invalid type for comprehension node: %sz%s(%s, (PyObject*)%s))rm  r   r   r   r   r   r   r   r   r{  r{  r   r   r   r   r  r  r(  rQ   rQ   rR   r  $  s(   


z/ComprehensionAppendNode.generate_execution_codec                 C   s   | j || d S rJ   )r{  r  r  rQ   rQ   rR   r  $  r   z5ComprehensionAppendNode.generate_function_definitionsc                 C   r!  rJ   )r{  r  rm  rQ   rQ   rR   r  $  r   z ComprehensionAppendNode.annotate)rX   rY   rZ   r   rm  r   rg  r   r(  r  r  r  rQ   rQ   rQ   rR   r  q$  s    r  c                   @   s4   e Zd ZddgZdd Zdd Zdd Zd	d
 ZdS )DictComprehensionAppendNodekey_expr
value_exprc                 C   sP   | j || _ | j jjs| j || _ | j|| _| jjjs&| j|| _| S rJ   )r  r(  r   rp   r  r  r   rQ   rQ   rR   r(  $  s   

z/DictComprehensionAppendNode.analyse_expressionsc              	   C   s|   | j | | j| ||d| j | j  | j f | j | j | | j 	| | j| | j	| d S )Nz0PyDict_SetItem(%s, (PyObject*)%s, (PyObject*)%s))
r  r{  r  r   r   rm  r   r   r  r  rm  rQ   rQ   rR   r  $  s   
z3DictComprehensionAppendNode.generate_execution_codec                 C   s    | j || | j|| d S rJ   )r  r  r  r  rQ   rQ   rR   r  $     z9DictComprehensionAppendNode.generate_function_definitionsc                 C      | j | | j| d S rJ   )r  r  r  rm  rQ   rQ   rR   r  $     z$DictComprehensionAppendNode.annotateN)rX   rY   rZ   r   r(  r  r  r  rQ   rQ   rQ   rR   r  $  s    	r  c                       sT   e Zd ZdgZdZdZdZeZd fdd	Z	dd Z
dd	 Zd
d Zdd Z  ZS )InlinedGeneratorExpressionNodegenNTc                    sf   |j j}d|_|d ur%|tttfv sJ |||_|jt||t	j
|d t j|fd|i| d S )NT)rm  r   r  )r7  gbodyZ
is_inlinedr   r   r   Zinlined_comprehension_typer  r  r   retval_cnamerL   r  )rU   r   r  Zcomprehension_typer  r  rO   rQ   rR   r  $  s   z'InlinedGeneratorExpressionNode.__init__c                 C   s
   | j dvS )N)rl   r   rP  )	orig_funcrT   rQ   rQ   rR   r  $  rM  z*InlinedGeneratorExpressionNode.may_be_nonec                 C   r   rJ   r  r   rQ   rQ   rR   r   $  r)  z)InlinedGeneratorExpressionNode.infer_typec                 C   r  rJ   )r  r(  r   rQ   rQ   rR   r"  $  r  z,InlinedGeneratorExpressionNode.analyse_typesc              	   C   s:   | d|  | j ||  | jf  | | d S )Nz-%s = __Pyx_Generator_GetInlinedResult(%s); %s)r   r   r  r   r   r  rm  rQ   rQ   rR   rv  $  s
   z3InlinedGeneratorExpressionNode.generate_result_coderJ   )rX   rY   rZ   r   r  rm  r   r   r   r  r  r   r"  rv  r[   rQ   rQ   rO   rR   r  $  s    r  c                   @   sf   e Zd ZdZdgZdZdZdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )r  z
    Merge a sequence of iterables into a set/list/tuple.

    The target collection is determined by self.type, which must be set externally.

    args    [ExprNode]
    r   TzConstructing Python collectionc                 C   sd   |t tfv r'|r'|d jr'|d jt ur't|d j|d jd|d jd|d< tj	| |||d d S )Nr   T)r   r   r   )r   r   )
r   r   r   r   r  r   r   r   r   r  )rU   r   r   r   rQ   rQ   rR   r  $  s   &zMergedSequenceNode.__init__c                 C   s   g }| j D ]&}|jr|jr|jjdkrq|js|jr#dd |j D }n|j}|| q| jtu r6t|}n| jt	u r@t
|}n| jtu sGJ || _d S )Nr   c                 s   r  rJ   r  r   rQ   rQ   rR   re   %  r  z?MergedSequenceNode.calculate_constant_result.<locals>.<genexpr>)r   r   r   r~   r   r   r   r   r  r   r   r   )rU   r   r   rR  rQ   rQ   rR   r  $  s   





z,MergedSequenceNode.calculate_constant_resultc              
      s   g }| j D ],}|jr|jr|j dkrq|js|jr' fdd|j D }n| }|| q| jtu rWzt|}W |S  t	yV } z| 
| W Y d }~|S d }~ww | jtu rbt|}|S | jtu siJ |S )Nr   c                 3   s    | ]}|  V  qd S rJ   r  r   r  rQ   rR   re   %  s    z8MergedSequenceNode.compile_time_value.<locals>.<genexpr>)r   r   r   r  r   r   r   r   r  r  r  r   r   r   )rU   r  r   r   rR  r  rQ   r  rR   r  %  s.   




z%MergedSequenceNode.compile_time_valuec                 C   rS   r  rQ   r   rQ   rQ   rR   r3  )%  rW   z$MergedSequenceNode.type_dependenciesc                 C   r   rJ   r  r   rQ   rQ   rR   r   ,%  r)  zMergedSequenceNode.infer_typec                    sV    fdd| j D }t|dkr|d j| ju r|d S | jtttfv s&J || _ | S )Nc                    rX  )z2argument after * must be an iterable, not NoneTyperY  r   ry   rQ   rR   r   0%  rZ  z4MergedSequenceNode.analyse_types.<locals>.<listcomp>r)   r   )r   r   r   r   r   r   )rU   rs   r   rQ   ry   rR   r"  /%  s   
z MergedSequenceNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  @%  rW   zMergedSequenceNode.may_be_nonec           
   
   C   s  | | j | | | jtu }t| j}t|}|| |r#|j	s-|s@|j
r@|jtu r@|d|  | f  || n1|d|  |rJdn| rW|jttfv rWdnd| ||  | jf  | | || || t }|rd}d}nd}d	}|D ]l}|r|j	s|j
s|j
r|js|s|jr|d
 |jD ]!}|| ||jd||  | f  || || qq|r|d n|d || ||jd||  | f  || || q| jtu r0|d |dtj|  f  ||  t |d|  tj||  | jf  | | |d t|D ]}	|j t!j"|	  q4d S )Nr  r=  Z	PySet_Newr  r  r  Z__Pyx_PySet_Updater  Z__Pyx_PyList_Extend)r  r  
%s(%s, %s))ZPySet_Updatez
Builtins.c)Z
ListExtendr  r6  z"PyObject *%s = PyList_AsTuple(%s);r  r   )#ru  r   re  r   r   r~  r   r  r{  r   r   r   r   r   r   r  rX  r   r   r  r  r  r  r   r  r  r   r   r  r  rP  r   r   r   r   )
rU   r   is_setr   r   ra  Zadd_funcZextend_funcr   rb  rQ   rQ   rR   r{  C%  s   





















z+MergedSequenceNode.generate_evaluation_codec                 C   rc  rJ   )r   r  rd  rQ   rQ   rR   r  %  re  zMergedSequenceNode.annotateN)rX   rY   rZ   r$  r   r   r  r  r  r  r3  r   r"  r  r{  r  rQ   rQ   rQ   rR   r  $  s    Mr  c                   @   sJ   e Zd ZdZdgZeZdZdZdd Z	dd Z
d	d
 Zdd Zdd ZdS )SetNodez
    Set constructor.
    r   TzConstructing Python setc                 C   sH   t t| jD ]}| j| }||}||| j|< qt| _d| _| S r'  )r0  r   r   r"  r  r   r   r   )rU   rs   r  r   rQ   rQ   rR   r"  %  s   

zSetNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  %  rW   zSetNode.may_be_nonec                 C   s   dd | j D | _d S )Nc                 S   s   h | ]}|j qS rQ   r  r   rQ   rQ   rR   r   %  r  z4SetNode.calculate_constant_result.<locals>.<setcomp>)r   r~   rT   rQ   rQ   rR   r  %  r  z!SetNode.calculate_constant_resultc              
      P    fdd| j D }zt|W S  ty' } z| | W Y d }~d S d }~ww )Nc                    r2  rQ   r  r   r  rQ   rR   r   %  r   z.SetNode.compile_time_value.<locals>.<listcomp>)r   r  r  r  r  rQ   r  rR   r  %  s   
zSetNode.compile_time_valuec                 C   s   | j D ]}|| q| | |d|  ||  | jf  | | | j D ]}|| jd|  |	 f  |
| || q*d S )Nz%s = PySet_New(0); %szPySet_Add(%s, %s))r   r{  re  r   r   r   r   r  r  r   r  r  r  rQ   rQ   rR   r{  %  s$   




z SetNode.generate_evaluation_codeN)rX   rY   rZ   r$  r   r   r   r   r  r"  r  r  r  r{  rQ   rQ   rQ   rR   r  %  s    	r  c                       s   e Zd ZdgZdZdZeZdZdZ	g Z
edd Zdd Zd	d
 Zdd Zdd Zdd Zdd Z fddZdd ZdZdd Zdd Zdd Z  ZS )r  r  r)   FTc                    s   |   fdd|D dS )Nc                    s   g | ]\}}t  ||d qS r  )r  )ra   kr  r   rQ   rR   r   %  s    z'DictNode.from_pairs.<locals>.<listcomp>r  rQ   )rN   r   pairsrQ   r  rR   
from_pairs%  s   
zDictNode.from_pairsc                 C   s   t dd | jD | _d S )Nc                 S   r  rQ   r  r   rQ   rQ   rR   r   %  r  z6DictNode.calculate_constant_result.<locals>.<listcomp>)r*  r  r~   rT   rQ   rQ   rR   r  %  s   z"DictNode.calculate_constant_resultc              
      r  )Nc                    s$   g | ]}|j  |j fqS rQ   )r  r  r   r   r  rQ   rR   r   %  s    z/DictNode.compile_time_value.<locals>.<listcomp>)r  r*  r  r  )rU   r  r  r  rQ   r  rR   r  %  s   

zDictNode.compile_time_valuec                 C   rS   r  rQ   r   rQ   rQ   rR   r3  %  rW   zDictNode.type_dependenciesc                 C   r/  rJ   rW  r   rQ   rQ   rR   r   %  r  zDictNode.infer_typec                    sJ   t dd} fdd| jD | _W d    n1 sw   Y  || _| S )NTrp  c                    r2  rQ   r'  r   ry   rQ   rR   r   %  s    z*DictNode.analyse_types.<locals>.<listcomp>)r
   r  r  )rU   rs   r  rQ   ry   rR   r"  %  s   

zDictNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  %  rW   zDictNode.may_be_nonec                    s  t j|dd}|jr>|   | jjr.t|st| j	d|  t
| j	 fdd| jD dS | j|s<t| j	d|  | S |jr|| _|jsWt| jdkrWt| j	d	|  n|jrnt| jt|jjk rnt| j	d
| d | jD ]R}t|jtr~|jj|_|jjst|jj	d t|jj	tdd|_qqt|jj}|j|}|st|jj	d||f  qq|j}t|tr|j}||j |_qq| S t | S )NTr  z-Cannot interpret struct as non-dict type '%s'c                    s,   g | ]}t |j|j |j d qS r  )r  r   r  r  r   r   ry   rQ   rR   r   &  s    
z&DictNode.coerce_to.<locals>.<listcomp>r  z"Cannot interpret dict as type '%s'r)   z<Exactly one field must be specified to convert to union '%s'z%Not all members given for struct '%s'zInvalid struct field identifierr  r  zstruct '%s' has no field '%s')r   r  rp   release_errorsr   r  r   r  r   r   r  r  r  r   r  rO  r   r}   r  r  r   r   r:  r   r  rw   r   r  r  rL   )rU   r  rs   r   r  r  r   rO   ry   rR   r  %  sD   




zDictNode.coerce_toc                 C   s   | j D ]}t| qg | _ d S rJ   )r  r   )rU   rt   rQ   rQ   rR   r  !&  s   


zDictNode.release_errorsr[  c                 C   s  | | j | | | jj}|r3|   |d|  t| j	|
|  | jf  | | d }n| jj}t }d }d}| j	D ]}|| |r| jrW|d|j   |j}| jr|d ur|jsgd }n(|j|v rod }n |t|jur|d u rt|j}||j n	d }n||j |d u r|d|  | f  d}|d| ||jf  |d || jd|  |j |j f  | jr|d u r|d	 | jr|d	 nR||jj}	|	d usJ d
|jj d|	j}
|j }|jjjr!|jtdd |d|   d|
 d| d| d	 n||   d|
 d| d || | | qA|rK|jtdd d S d S )Nz%%s = __Pyx_PyDict_NewPresized(%d); %sFr  r\  Tr^  rm  r_  r   zstruct member z1 not found, error was not handled during coercionr  r  zmemcpy(r  r>  z	, sizeof(r  r;  r@  r]  r`  )!ru  r   re  r   rp   r  r   r   r   r  r   r  r  r  r{  exclude_null_valuesr   r   r  rU  r   r  r   r  r  r   r6  r   r   r   r   r  r  )rU   r   Zis_dictZstruct_scopeZ	keys_seenZkey_typeZneeds_error_helperr   r  r  Z	key_cnamevalue_cnamerQ   rQ   rR   r{  (&  s   











* 

z!DictNode.generate_evaluation_codec                 C   rc  rJ   )r  r  rd  rQ   rQ   rR   r  z&  re  zDictNode.annotatec                 C   s   dd | j D S )Nc                 S   s   i | ]\}}|j |qS rQ   r  rS  rQ   rQ   rR   rK  &  ra  z+DictNode.as_python_dict.<locals>.<dictcomp>r  rT   rQ   rQ   rR   as_python_dict~&     zDictNode.as_python_dict)rX   rY   rZ   r   r   r  r   r   r  rU  r  r  r  r  r  r3  r   r"  r  r  r  r  r{  r  r  r[   rQ   rQ   rO   rR   r  %  s,    
	'Rr  c                   @   sH   e Zd ZddgZdZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )r  r  r   Nc                 C   s   | j j| jjf| _d S rJ   )r  r~   r   rT   rQ   rQ   rR   r  &  s   
z&DictItemNode.calculate_constant_resultc                 C   s<   | j || _ | j|| _| j || _ | j|| _| S rJ   )r  r"  r   r  r   rQ   rQ   rR   r"  &  s
   zDictItemNode.analyse_typesc                 C   r  rJ   )r  r{  r   rm  rQ   rQ   rR   r{  &  r  z%DictItemNode.generate_evaluation_codec                 C   r  rJ   )r  r  r   rm  rQ   rQ   rR   r  &  r  z#DictItemNode.generate_disposal_codec                 C   r  rJ   )r  r  r   rm  rQ   rQ   rR   r  &  r  zDictItemNode.free_tempsc                 C   s   t | j| jgS rJ   )r~  r  r   rT   rQ   rQ   rR   __iter__&  r   zDictItemNode.__iter__)rX   rY   rZ   r   rO  r  r"  r{  r  r  r  rQ   rQ   rQ   rR   r  &  s    r  c                   @   s6   e Zd ZdgZdZdd Zdd Zdd Zd	d
 ZdS )SortedDictKeysNoder   Tc                 C   s   t j| |j|d tj| _d S r  )r   r  r   r   r   r   rU   r   rQ   rQ   rR   r  &  s   zSortedDictKeysNode.__init__c                 C   s,   | j |}|jtju r|d}|| _ | S rP  )r   r"  r   r   r   r  r  rQ   rQ   rR   r"  &  s   z SortedDictKeysNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  &  rW   zSortedDictKeysNode.may_be_nonec              
   C   s  | j  }| j jtju r%|d|  |||  | jf  | 	| nT|j
tdd |td}|d|  ||||  | jf  | 	| |d|    | |d|    |||  | j | 	| |d || jd	|    d S )
Nz%s = PyDict_Keys(%s); %sZPyObjectCallMethod0r  keysz+%s = __Pyx_PyObject_CallMethod0(%s, %s); %sz"if (unlikely(!PyList_Check(%s))) {zPySequence_List(%s)r   zPyList_Sort(%s))r   r   r   r   r   r   r   r   r   r  r   r   r   r   r  r   r  r  r  )rU   r   Zdict_resultZ
keys_cnamerQ   rQ   rR   rv  &  s0   





z'SortedDictKeysNode.generate_result_codeN)	rX   rY   rZ   r   r   r  r"  r  rv  rQ   rQ   rQ   rR   r  &  s    r  c                   @   r-  )SortedListNodez0Sorts a newly created Python list in place.
    c                 C   s&   | |d| j  d| j d S )NzPyList_Sort(r  )r   rs  r   r   r   rm  rQ   rQ   rR   rv  &  s   &z#SortedListNode.generate_result_codeN)rX   rY   rZ   r$  r   r   rv  rQ   rQ   rQ   rR   r  &  s    r  c                   @   s   e Zd Zdd Zdd ZdS )ModuleNameMixinc                 C      |j | jddS NT
identifier)r  r*  rm  rQ   rQ   rR   get_py_mod_name&     zModuleNameMixin.get_py_mod_namec                 C   r  r  )r  r3  rm  rQ   rQ   rR   get_py_qualified_name&  r  z%ModuleNameMixin.get_py_qualified_nameN)rX   rY   rZ   r  r  rQ   rQ   rQ   rR   r  &  s    r  c                   @   sF   e Zd ZdgZeZdZdd Zdd Zdd Z	d	d
 Z
dZdd ZdS )r!  docTc                 C   r   rJ   rQ   r   rQ   rQ   rR   r   &  rW   zClassNode.analyse_annotationsc                 C   r/  rJ   r  r   rQ   rQ   rR   r   &  r  zClassNode.infer_typec                 C   s8   | j r| j || _ | j || _ |tdd | S )NZCreateClassr  )r  r"  r  r   r   r   r   rQ   rQ   rR   r"  &  s
   zClassNode.analyse_typesc                 C   rS   r+  rQ   rT   rQ   rQ   rR   r  '  rW   zClassNode.may_be_noneConstructing Python classc                 C   s   | j }|| j}| jr$|| jd|j |t	d| j f  | 
|}| |}|d|  |j |j |||||  | jf  | | d S )Nr_  r$  z.%s = __Pyx_CreateClass(%s, %s, %s, %s, %s); %s)class_def_noder  rq   r  r  r   r*  r   r   r  r  r  r   r   basesr   r  )rU   r   r  r   py_mod_namer3  rQ   rQ   rR   rv  
'  s4   

	zClassNode.generate_result_codeN)rX   rY   rZ   r   r   r   r   r   r   r"  r  r  rv  rQ   rQ   rQ   rR   r!  &  s    
r!  c                   @   sH   e Zd Zg ZeZdZdZdd Zdd Z	dd Z
d	Zd
d Zdd ZdS )r"  FTc                 C   r/  rJ   r  r   rQ   rQ   rR   r   4'  r  zPy3ClassNode.infer_typec                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  8'  rW   zPy3ClassNode.analyse_typesc                 C   rS   r+  rQ   rT   rQ   rQ   rR   r  ;'  rW   zPy3ClassNode.may_be_noner   c                 C   s   ddl m} | jj}dd |j D }|rKt||d}t|t	dd}|
|jp2||jt||_t|||d}|| | jjjd	| d S d S )
Nr)   AnnotationWriterc                 S   s2   g | ]}|j rt|jt|j|jd |j jdqS r  r  )r   r  r   r  rq   stringra   r   rQ   rQ   rR   r   C'  s    z4Py3ClassNode.analyse_annotations.<locals>.<listcomp>r  __annotations__r  )rw  r   r   )AutoDocTransformsr  r  r   rQ  r  r  r  r   r  r  rq   r  r   r   r-   rK  bodyrz  insert)rU   rs   r  position
dict_itemsannotations_dictrw  r   rQ   rQ   rR   r   @'  s   	
z Py3ClassNode.analyse_annotationsc                 C   s   |j tdd || j}| j}|jr|j nd}|j	r&|j	 }n| j
r,d}nd}|d|  |||j |j || j| j||  | jf	  | | ||   d S )NZPy3ClassCreater  r3  z((PyObject*)&PyType_Type)z$((PyObject*)&__Pyx_DefaultClassType)z9%s = __Pyx_Py3ClassCreate(%s, %s, %s, %s, %s, %d, %d); %s)r   r   r   r   r  rq   r  mkwr   	metaclass
force_typer   r   r  r*  Zcalculate_metaclassZallow_py2_metaclassr   r   r  put_make_object_deferred)rU   r   r   r  r  r  rQ   rQ   rR   rv  T'  s0   
z!Py3ClassNode.generate_result_codeN)rX   rY   rZ   r   r   r   r  r   r   r"  r  r  r   rv  rQ   rQ   rQ   rR   r"  #'  s    r"  c                   @   s(   e Zd Zg Zdd Zdd Zdd ZdS )PyClassMetaclassNodec                 C   s   t | _d| _| S r+  )r   r   r   r   rQ   rQ   rR   r"  u'  s   z"PyClassMetaclassNode.analyse_typesc                 C   rS   r+  rQ   rT   rQ   rQ   rR   r  z'  rW   z PyClassMetaclassNode.may_be_nonec              	   C   s   | j j}| j j}|r|jtdd d| | f }n|jtdd d|  }|d|  ||	|  | j
f  | | d S )NZPy3MetaclassGetr  z__Pyx_Py3MetaclassGet(%s, %s)ZCalculateMetaclassz"__Pyx_CalculateMetaclass(NULL, %s)r  )r  r  r  r   r   r   r   r   r   r   r   r  )rU   r   r  r  r  rQ   rQ   rR   rv  }'  s.   

z)PyClassMetaclassNode.generate_result_codeNrX   rY   rZ   r   r"  r  rv  rQ   rQ   rQ   rR   r  n'  s
    r  c                   @   *   e Zd ZdgZdd Zdd Zdd ZdS )	PyClassNamespaceNoder  c                 C   s*   | j r| j ||| _ t| _d| _| S r'  )r  r"  r  r   r   r   r   rQ   rQ   rR   r"  '  s
   z"PyClassNamespaceNode.analyse_typesc                 C   rS   r+  rQ   rT   rQ   rQ   rR   r  '  rW   z PyClassNamespaceNode.may_be_nonec           
      C   s   | | j}| |}| |}| j}d}| jr| j n|}|jr'|j n|}|j	r1|j	 n|}	|
d|  |	|j |||||||  | jf	  | | d S )Nz(PyObject *) NULLz>%s = __Pyx_Py3MetaclassPrepare(%s, %s, %s, %s, %s, %s, %s); %s)r  rq   r  r  r  r  r   r  r   r  r   r  r   r   r  )
rU   r   r   r  r3  r  nullZdoc_coder  r  rQ   rQ   rR   rv  '  s,   

z)PyClassNamespaceNode.generate_result_codeNr  rQ   rQ   rQ   rR   r  '  s
    r  c                   @   s4   e Zd ZdZeZg ZdZdd Zdd Z	dd Z
d	S )
ClassCellInjectorNodeTFc                 C   r(  rJ   rQ   r   rQ   rQ   rR   r(  '  rW   z)ClassCellInjectorNode.analyse_expressionsc                 C   s<   | j sJ |d|  ||  | jf  | | d S )Nz%s = PyList_New(0); %s)	is_activer   r   r   r   r  rm  rQ   rQ   rR   rv  '  s   
z*ClassCellInjectorNode.generate_result_codec                 C   s<   | j sJ |jtdd || jd|  |f  d S )NZCyFunctionClassCellCythonFunction.cz&__Pyx_CyFunction_InitClassCell(%s, %s))r  r   r   r   r   r  r   r   )rU   r   Zclassobj_cnamerQ   rQ   rR   generate_injection_code'  s   


z-ClassCellInjectorNode.generate_injection_codeN)rX   rY   rZ   r   r   r   r   r  r(  rv  r  rQ   rQ   rQ   rR   r  '  s    r  c                   @   s,   e Zd Zg ZdZdZeZdd Zdd Z	dS )ClassCellNodeTFc                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  '  rW   zClassCellNode.analyse_typesc                 C   sj   | j s|d|  tjf  n|d|  tjf  |d|  || jf  ||  t	 d S )Nz&%s = __Pyx_CyFunction_GetClassObj(%s);z%s =  %s->classobj;zUif (!%s) { PyErr_SetString(PyExc_RuntimeError, "super(): empty __class__ cell"); %s })
is_generatorr   r   r   
self_cnamegenerator_cnamer   r   rl  r   rm  rQ   rQ   rR   rv  '  s    


z"ClassCellNode.generate_result_codeN)
rX   rY   rZ   r   r   r  r   r   r"  rv  rQ   rQ   rQ   rR   r  '  s    r  c                   @   s   e Zd Zg dZdZdZdZdZdZdZ	dZ
eZdZdZdZedd Zedd Zd	d
 Zdd Zdd ZdZdd Zdd Zdd Zdd ZdS )r   )defaults_tupledefaults_kwdictr  FNr)   c                 C   s    | |j ||jj|p|j|jdS )N)r7  pymethdef_cnamebindingspecialized_cpdefs)r   r   r#  r%  )rN   r   r$  rQ   rQ   rR   from_defnode
(  s   zPyCFunctionNode.from_defnodec                 C   r  rJ   )r7  code_objectrT   rQ   rQ   rR   r'  (  r\  zPyCFunctionNode.code_objectc                 C   s   | j r| | | S rJ   )r$  analyse_default_argsr   rQ   rQ   rR   r"  (     
zPyCFunctionNode.analyse_typesc                 C   s  g }g }g }g }g }|j p| jjo|j}| jjD ]b}|jrd|sK|jjr9t|j|j|_|jj	r8|j
|j	||_nd|_|j	jrF|| n|| |jj	rd|jj	|rd|jr_|| n|| |jrz|j||_||j|j|jjf q| jj| jjfD ]}|r|jr|j||_||j|j|jjf q| jj}	|	r|	|| j_||	jtd|	jf |s|r4| }
g }|D ]}|j	}|jr|j}|| q|dd |D 7 }|
| j|| _| jj	j}tt |j!" }dd |D }g | _#t$|| |D ]\}}|j%|_&| j#||f qt'|| _(| j#D ]\}}dt)j*|j%f |_+q |j| j_,|s:|r| jdu rn|rXt-| jdd |D d	}||.|| _/|rmt0| jd
d |D d}||| _1nr| j2s|rt3| j|| jj	j}nt4| j}|rt5| j|| jj	j}nt4| j}t6j7| jg ddt6j8| jt9t-| j||gd	ddtdd}| }
t6j:;||
}|<|
 |=|
}|j>}|j>=|j?|_>d|_@d|_A|| j_B|rt0| jdd |D d}||| _CdS dS )zB
        Handle non-literal function's default arguments.
        Tr  c                 S   r  rQ   r  r   rQ   rQ   rR   r   W(  r  z8PyCFunctionNode.analyse_default_args.<locals>.<listcomp>c                 S   s   g | ]\}}| d r|qS r  )rj  )ra   rq   r  rQ   rQ   rR   r   ](  s    ry  Nc                 S   r  rQ   )rr   r   rQ   rQ   rR   r   l(  r  r  c                 S   s*   g | ]}t |jt|j|jd |jdqS r  )r  r   r  rq   rr   r   rQ   rQ   rR   r   p(  s    r  )rf  r   __defaults__)r   r8  r9  r  Z
decoratorsrq   Fc                 S   s(   g | ]\}}}t |t||d |dqS r  )r  r  )ra   r   rq   r   rQ   rQ   rR   r   (  s    )Dr  r7  Z
is_wrapperr  r   rr   r   DefaultLiteralArgNoder   r   r  
is_dynamicrp   r   r  kw_onlyr   r"  rq   r  r8  r9  Zreturn_type_annotationr   r  rv  r  r:  Zdeclare_defaults_c_classdefaults_entryr  rP  r   rQ  rR  defaultsrW  r   defaults_class_keyr   Zdefaults_pyobjectsr   Zdynamic_args_cnamer  defaults_structr1  r  r!  r  r"  r%  DefaultsTupleNoder  DefaultsKwDictNoder   ZDefNodeZReturnStatNoder   ZCompilerDirectivesNodeZfor_internalrK  r(  r  local_scopepy_wrapper_requiredpymethdef_requireddefaults_getterr  )rU   rs   Znonliteral_objectsZnonliteral_otherZdefault_argsZdefault_kwargsannotationsZmust_use_constantsr   r   ru  r?  r   Zdefaults_class_scopeZarg_entriesr   r!  r"  r7  Zdirectives_noder  rQ   rQ   rR   r(  (  s   












	


z$PyCFunctionNode.analyse_default_argsc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  (  rW   zPyCFunctionNode.may_be_nonezConstructing Python functionc                 C   rS   )Nr3  rQ   rT   rQ   rQ   rR   closure_result_code(  rW   z#PyCFunctionNode.closure_result_codec                 C   s"   | j r
| | d S | | d S rJ   )r$  generate_cyfunction_codegenerate_pycfunction_coderm  rQ   rQ   rR   rv  (  s   z$PyCFunctionNode.generate_result_codec                 C   sH   |  |}|d|  | j|  |||  | jf  | | d S )Nz'%s = PyCFunction_NewEx(&%s, %s, %s); %s)r  r   r   r#  r9  r   r   r  )rU   r   r  rQ   rQ   rR   r;  (  s   
z)PyCFunctionNode.generate_pycfunction_codec           
      C   s  | j r	| j d }n| j}| j s| jr|jtdd d}n|jtdd d}g }|jr6|d n|j	r>|d |j
jjrL|jjsL|d	 |jrT|d
 |r\d|}nd}|tj}| j| |d|  || j|| ||  | ||| j ||  | jf
  | | | |   |j!r|j"sJ d|j"d }|d|j# |  f  | j$r|d|  || j%j&j'|(| jf  d| j%j&j)|  f }| j$D ]\}}	|j*r|j+|| d|	j, d q| j-r|d|  | j- f  | j sC| j.r|d|  | j. f  |j/r/|d|  |j/jj0f  | j1rE|d|  | j1 f  d S d S d S )Nr   ZFusedFunctionr  Z__pyx_FusedFunction_NewZCythonFunctionZ__Pyx_CyFunction_NewZ__Pyx_CYFUNCTION_STATICMETHODZ__Pyx_CYFUNCTION_CLASSMETHODZ__Pyx_CYFUNCTION_CCLASSZ__Pyx_CYFUNCTION_COROUTINEr  rA  z(%s = %s(&%s, %s, %s, %s, %s, %s, %s); %szpyclass_stack is emptyr,  zPyList_Append(%s, %s);z.if (!__Pyx_CyFunction_InitDefaults(%s, %s)) %sz(__Pyx_CyFunction_Defaults(struct %s, %s)r  )Zcyfunc_struct_targetz*__Pyx_CyFunction_SetDefaultsTuple(%s, %s);z+__Pyx_CyFunction_SetDefaultsKwDict(%s, %s);z+__Pyx_CyFunction_SetDefaultsGetter(%s, %s);z,__Pyx_CyFunction_SetAnnotationsDict(%s, %s);)2r%  r7  is_specializationr   r   r   r   Zis_staticmethodr   Zis_classmethodr4  rz  r  r   Zis_anonymousis_coroutinerA  r  r   r  r'  rv  r   r   r#  r  r9  r  r   r   r   r  r  Zrequires_classobjZpyclass_stackZ
class_cellr/  r.  r   rE  r   Zobjstruct_cnamer,  r  r   r!  r"  r7  r?  r  )
rU   r   r7  r  flagsr  Z
class_noder/  r   r   rQ   rQ   rR   r:  (  s   








z(PyCFunctionNode.generate_cyfunction_code)rX   rY   rZ   r   r$  r7  r/  r.  r!  r"  r  r   r   r   r%  r<  r  r&  r  r'  r"  r(  r  r  r9  rv  r;  r:  rQ   rQ   rQ   rR   r   '  s4    

	
 r   c                   @   s   e Zd ZdZdZdd ZdS )InnerFunctionNodeTc                 C   s   | j rdtj S dS )Nz((PyObject*)%s)r3  )needs_closure_coder   cur_scope_cnamerT   rQ   rQ   rR   r9  )  r)  z%InnerFunctionNode.closure_result_codeN)rX   rY   rZ   r$  r@  r9  rQ   rQ   rQ   rR   r?  )  s    r?  c                   @   sP   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdd Zedd Zed	d
 ZdS )DefFuncLikeNodez\
    Adapter for CFuncDefNode to give it the same attributes as DefNode in CodeObjects.
    Fr   Nc                 C   s.   |j j| _|j j| _|j| _|j| _|| _d S rJ   )r   rq   r  r4  r   r   _cfuncdef_node)rU   cfuncdef_noderQ   rQ   rR   r  -)  s
   


zDefFuncLikeNode.__init__c                 C   r  rJ   )rC  node_positionsrT   rQ   rQ   rR   rE  4)  r\  zDefFuncLikeNode.node_positionsc                 C   r  rJ   )rC  node_positions_to_offsetrT   rQ   rQ   rR   rF  8)  r\  z(DefFuncLikeNode.node_positions_to_offset)rX   rY   rZ   r$  r  r=  is_asyncgenis_generator_expressionnum_posonly_argsr:  r8  r9  r  r  rE  rF  rQ   rQ   rQ   rR   rB  )  s    
rB  c                   @   sP   e Zd ZdgZdZdZdd Zedd Zdd	 Z	dd
dZ
dd Zdd ZdS )CodeObjectNodevarnamesFNc                 C   sF   t j| |j|d t|j}dd |jjD }dd || D | _d S )N)r7  c                 S   s   g | ]}|j r|qS rQ   r  r   rQ   rQ   rR   r   K)  r   z+CodeObjectNode.__init__.<locals>.<listcomp>c                 S   s   g | ]
}t |j|jd qS )r  )r  r   rq   r   rQ   rQ   rR   r   L)  s    )r   r  r   r   r   r4  rO  rK  )rU   r7  r   
local_varsrQ   rQ   rR   r  G)  s   
zCodeObjectNode.__init__c                 C   s   | t |S rJ   )rB  )rN   rD  rQ   rQ   rR   	for_cfuncQ)  s   zCodeObjectNode.for_cfuncc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  U)  rW   zCodeObjectNode.may_be_nonec                 C   s   | j d u r|| | _ | j S rJ   r_  Zget_py_codeobj_constrm  rQ   rQ   rR   r   X)  s   
z$CodeObjectNode.calculate_result_codec                 C   s   | j d u r|| | _ d S d S rJ   rN  rm  rQ   rQ   rR   rv  ])  s   
z#CodeObjectNode.generate_result_codec                 C   s  | j }| jd }|j|jdd}|jd  }tj|r$|jd  }t	
t| }||}|jrMt	t|j|dd}||}	t|}
nd}	d}
ddg}|jr]|d	 |jre|d
 |jrn|d n|jrw|d n|jr|d |jrd}nt|j}|j}|j}t| j}dd| pd}|d |d||  d| d| d| d| d| d | jD ]}| | qdd | jD pdg}|dd|  | jD ]}|!| |"| q|| j# d| d| d|	 d| j# d| d |d d S )Nr)   Tr  r   z	iso8859-1r3  ZCO_OPTIMIZEDZCO_NEWLOCALS
CO_VARARGSCO_VARKEYWORDSCO_ASYNC_GENERATORCO_COROUTINECO_GENERATORz(unsigned int)(%s)|rA  r6  z5const __Pyx_PyCode_New_function_description descr = {r>  r:  c                 S   r@  rQ   r2  ra   r  rQ   rQ   rR   r   )  rB  z3CodeObjectNode.generate_codeobj.<locals>.<listcomp>z"PyObject* const varnames[] = {%s};z% = __Pyx_PyCode_New(descr, varnames, z", tuple_dedup_map); if (unlikely(!z)) goto r@  r   )$r7  r   r  rq   Zget_filenametable_entryr$   rf  isabsrh  r   r  r%   Pathas_posixrE  r  r!   r  r   r8  r   r9  rG  r=  r  rH  r   rI  r:  rK  rA  r   r{  r  r  r_  )rU   r   rV  rd  Zfirst_linenoZfunc_name_result	file_pathZfile_path_resultZ
line_tableZline_table_resultZline_table_lengthr>  ZargcountrI  Zkwonly_argcountZnlocalsr  rK  rQ   rQ   rR   generate_codeobja)  s   












zCodeObjectNode.generate_codeobjrJ   )rX   rY   rZ   r   r   r_  r  r  rM  r  r   rv  rZ  rQ   rQ   rQ   rR   rJ  =)  s    


rJ  c                       sH   e Zd Zg ZdZdZ fddZdd Zdd Zd	d
 Z	dd Z
  ZS )r+  TFc                    s.   t  | || _|j| _| jj| _d| _d S rR  )rL   r  r   r~   r   	evaluatedr  rO   rQ   rR   r  )  s
   

zDefaultLiteralArgNode.__init__c                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  )  rW   z#DefaultLiteralArgNode.analyse_typesc                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  )  rW   z*DefaultLiteralArgNode.generate_result_codec                 C   s    | j s| j| d| _ d S d S r+  )r[  r   r{  rm  rQ   rQ   rR   r{  )  s   
z.DefaultLiteralArgNode.generate_evaluation_codec                 C   s   | j | j S rJ   )r   r  r   r   rT   rQ   rQ   rR   r   )  r   zDefaultLiteralArgNode.result)rX   rY   rZ   r   r   r   r  r"  rv  r{  r   r[   rQ   rQ   rO   rR   r+  )  s    r+  c                       s8   e Zd Zg Z fddZdd Zdd Zdd Z  ZS )	DefaultNonLiteralArgNodec                    s   t  | || _|| _d S rJ   )rL   r  r   r1  )rU   r   r   r1  rO   rQ   rR   r  )  s   
z!DefaultNonLiteralArgNode.__init__c                 C      | j j| _d| _| S rR  )r   r   r   r   rQ   rQ   rR   r"  )     
z&DefaultNonLiteralArgNode.analyse_typesc                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  )  rW   z-DefaultNonLiteralArgNode.generate_result_codec                 C   s"   d| j jtj| j | jjjf S )Nz,__Pyx_CyFunction_Defaults(struct %s, %s)->%s)r1  rq   r   r  r  r   r0  r   rT   rQ   rQ   rR   r   )  s   
zDefaultNonLiteralArgNode.result)	rX   rY   rZ   r   r  r"  rv  r   r[   rQ   rQ   rO   rR   r\  )  s    r\  c                       s*   e Zd Z fddZd fdd	Z  ZS )r2  c                    sH   g }|D ]}|j jst|||}n|j }|| qt j||d d S Nr  )rr   r   r\  r   rL   r  )rU   r   r/  r1  r   r   rO   rQ   rR   r  )  s   zDefaultsTupleNode.__init__Fc                    s   t  |||S rJ   )rL   r"  r  )rU   rs   r  rO   rQ   rR   r"  )  r  zDefaultsTupleNode.analyse_typesr  rX   rY   rZ   r  r"  r[   rQ   rQ   rO   rR   r2  )  s    
r2  c                       s   e Zd Z fddZ  ZS )r3  c                    sd   g }|D ]#}t |j|jd}|jjst|||}n|j}|t|j||d qt j	||d d S )Nr  r  r  )
r  r   rq   rr   r   r\  r   r  rL   r  )rU   r   r/  r1  rR  r   rq   rO   rQ   rR   r   *  s   zDefaultsKwDictNode.__init__)rX   rY   rZ   r  r[   rQ   rQ   rO   rR   r3  )  s    r3  c                       s@   e Zd ZdgZedZdd Z fddZ fddZ	  Z
S )	
LambdaNoder7  <lambda>c                 C   sb   t | drd S |d | _| j_d| j_d| j_d| j_| j| | jjj	| _	|
| j d S )Nlambda_namelambdaT)r  next_idrc  r7  Zno_assignment_synthesisr6  r>  rK  r   r#  Zadd_lambda_defr   rQ   rQ   rR   rK  *  s   
zLambdaNode.analyse_declarationsc                    s   | j || _ t |S rJ   )r7  r(  rL   r"  r   rO   rQ   rR   r"  &*  s   zLambdaNode.analyse_typesc                    s   | j | t | d S rJ   )r7  r  rL   rv  rm  rO   rQ   rR   rv  **  r  zLambdaNode.generate_result_code)rX   rY   rZ   r   r   r  rq   rK  r"  rv  r[   rQ   rQ   rO   rR   ra  *  s    

ra  c                       sV   e Zd ZedZdZejdg Zej	dg Z	 fddZ
 fddZdd	 Z  ZS )
GeneratorExpressionNodegenexprFcall_parametersc                    s$   t  j|g|R i | g | _d S rJ   )rL   r  rh  )rU   r   r   rP  rO   rQ   rR   r  >*  s   
z GeneratorExpressionNode.__init__c                    s   t | drd S |d| _t | d| j_d| j_d| j_t	j
| jj_t| jtjr?t| jjts5J | jjd | d S t| jtjsHJ d S )Ngenexpr_namerg  F)r  re  ri  rL   rK  r7  r6  r5  r>  r2   Zpyfunction_noargsr   r  r}   r  r   r  r  rE  rI  r  r   rO   rQ   rR   rK  B*  s   
z,GeneratorExpressionNode.analyse_declarationsc              
   C   s`   |   gdd | jD  }d|}|d|  | jjj|||  | j	f  | 
| d S )Nc                 S   r@  rQ   r9  )ra   cprQ   rQ   rR   r   W*  rB  z@GeneratorExpressionNode.generate_result_code.<locals>.<listcomp>r>  r=  )r9  rh  rA  r   r   r7  r   r?  r   r   r  )rU   r   Zargs_to_callrQ   rQ   rR   rv  U*  s   
z,GeneratorExpressionNode.generate_result_code)rX   rY   rZ   r   r  rq   r$  ra  r   r   r  rK  rv  r[   rQ   rQ   rO   rR   rf  /*  s    
	rf  c                   @   sR   e Zd ZdgZeZdZdZdZdZ	dZ
dd Zdd Zd	d
 Zdd Zdd ZdS )YieldExprNoder   r   Fyieldc                 C   sZ   | j r	| jr| jrt| jd| j  d| _| jd ur+| j|| _| jj	j
s+| | | S )Nz'%s' not supported herer)   )	label_numis_yield_fromin_async_genr   r   expr_keywordr   r   r"  r   rp   coerce_yield_argumentr   rQ   rQ   rR   r"  q*  s   


zYieldExprNode.analyse_typesc                 C      | j || _ d S rJ   r   r  r   rQ   rQ   rR   rq  {*  r   z#YieldExprNode.coerce_yield_argumentc                 C   sp   | j r*| j | | j | |dtj| j tf  | j | | j 	| n|
tjt | | d S Nr  )r   r{  rn  r   r   r  r   r   r  r  Zput_init_to_py_nonegenerate_yield_coderm  rQ   rQ   rR   r{  ~*  s   
z&YieldExprNode.generate_evaluation_codec                 C   st  | | jdd\}}|| g }|jj  |j D ]7\}}}|jj|}|	|||f |j
rD|jtdd d| }n||| |dtj||f  q|jjd }	|jjd }
|	sf|
ro|jtj| jd	 |tjt |  |jjd
ur|dtj  n|dtj  |d| jrdnd| jrdndf  |dtj|f  | jr| js|dtj  n|dtj  || |	s|
r|| j |D ];\}}}dtj|f }|j
rd| }|d||f  |jr|d|  | || q|j!r|d||f  q| "|tj# | j$r8| %| |&d| ' tj#f  |(| ' t d
S d
S )z
        Generate the code to return the argument in 'Naming.retval_cname'
        and to continue at the yield label.
         r4  r  r  z__PYX_STD_MOVE_IF_SUPPORTED(%s)z%s->%s = %s;profile	linetracer  Nz"__Pyx_Coroutine_SwapException(%s);z+__Pyx_Coroutine_ResetAndClearException(%s);z*/* return from %sgenerator, %sing value */zasync r  awaitrl  z%s->resume_label = %d;z,return __Pyx__PyAsyncGenValueWrapperNew(%s);z
return %s;ry  r  r  z"%s.memview = NULL; %s.data = NULL;r$  ))Znew_yield_labelrp  replaceZ	use_labelrb  Zclosure_tempsresetZtemps_in_userc  r   r   r   r   r   r   r  r   r   rA  rk   Zput_trace_yieldr  r   r   Zput_finish_refcount_contextZcurrent_exceptr   ro  is_awaitrX  Zput_trace_resumerp   r  r   !generate_sent_value_handling_codeZsent_value_cnamera  re  rv  r   rl  )rU   r   rm  Zresume_labelsavedr   r   r^  Z
save_cnamerw  rx  rQ   rQ   rR   ru  *  sn   




z!YieldExprNode.generate_yield_codec                 C   s   | ||| j d S rJ   )r   r   r   rU   r   r  rQ   rQ   rR   r}  *  r  z/YieldExprNode.generate_sent_value_handling_codeN)rX   rY   rZ   r   r   r   rm  rn  r|  ro  rp  r"  rq  r{  ru  r}  rQ   rQ   rQ   rR   rk  b*  s    
Erk  c                   @   s.   e Zd Zdd ZdddZdd Zd	d
 ZdS )_YieldDelegationExprNodec                 C   s   t  rJ   )NotImplementedErrorrm  rQ   rQ   rR   yield_from_func*  r)  z(_YieldDelegationExprNode.yield_from_funcNFc                 C   s  |d u r
| j | |jjtjdd}|d|| |tj	|d u r&| j 
 n|tjf  |d u r>| j | | j | n|rF||t |d|  |tjt |j| | | |d|  |tjt | jrv| | n|tjt |d | | |d d S )NFr]  z%s = %s(%s, %s, &%s);zif (likely(%s == PYGEN_NEXT)) {z(} else if (likely(%s == PYGEN_RETURN)) {rm  r   )r   r{  rb  rc  r   ZPySendResult_typer   r  r   r   r   r  r  r  r  r   r  rj  ru  ra  fetch_iteration_resultpropagate_exception)rU   r   r  r  Zresult_temprQ   rQ   rR   r{  *  s6   


z1_YieldDelegationExprNode.generate_evaluation_codec                 C   s$   | tjt ||| j d S rJ   )r  r   r  r   r   r   r   rm  rQ   rQ   rR   r  *  s   z,_YieldDelegationExprNode.propagate_exceptionc                 C   s    | d|  tjtjf  d S )Nr  )r   r   r   r  rm  rQ   rQ   rR   r  *  s
   z/_YieldDelegationExprNode.fetch_iteration_resultrR  )rX   rY   rZ   r  r{  r  r  rQ   rQ   rQ   rR   r  *  s
    
r  c                   @   $   e Zd ZdZdZdd Zdd ZdS )YieldFromExprNodeTz
yield fromc                 C   s(   | j jjst| jd | j || _ d S )Nz-yielding from non-Python object not supported)r   r   rw  r   r   r  r   rQ   rQ   rR   rq  +  s   
z'YieldFromExprNode.coerce_yield_argumentc                 C      |j tdd dS )NZGeneratorYieldFromr  Z__Pyx_Generator_Yield_Fromr   r   r   r   rm  rQ   rQ   rR   r  +     z!YieldFromExprNode.yield_from_funcN)rX   rY   rZ   rn  rp  rq  r  rQ   rQ   rQ   rR   r  +  s
    r  c                   @   r  )AwaitExprNodeTry  c                 C   s    | j d ur| j || _ d S d S rJ   rs  r   rQ   rQ   rR   rq  +  s   
z#AwaitExprNode.coerce_yield_argumentc                 C   r  )NZCoroutineYieldFromr  Z__Pyx_Coroutine_Yield_Fromr  rm  rQ   rQ   rR   r  $+  r  zAwaitExprNode.yield_from_funcN)rX   rY   rZ   r|  rp  rq  r  rQ   rQ   rQ   rR   r  +  s
    r  c                       s,   e Zd Zdd Z fddZdd Z  ZS )AwaitIterNextExprNodec                 C   s6   | d | d | d | d | d d S )Nz8PyObject* exc_type = __Pyx_PyErr_CurrentExceptionType();zif (unlikely(exc_type && (exc_type == PyExc_StopAsyncIteration || ( exc_type != PyExc_StopIteration && exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopAsyncIteration))))) {r   r  r   )r   rm  rQ   rQ   rR   _generate_break.+  s
   



z%AwaitIterNextExprNode._generate_breakc                    s   |  | t | d S rJ   )r  rL   r  rm  rO   rQ   rR   r  7+  s   
z)AwaitIterNextExprNode.propagate_exceptionc                 C   sF   |j sJ d|d|  | | ||| j |d d S )Nz1AwaitIterNextExprNode outside of 'async for' loopr  r   )Zbreak_labelr   r  r   r   r  rQ   rQ   rR   r}  ;+  s
   
z7AwaitIterNextExprNode.generate_sent_value_handling_code)rX   rY   rZ   r  r  r}  r[   rQ   rQ   rO   rR   r  )+  s    	r  c                   @   s0   e Zd ZeZdZdd ZdZdd Zdd Z	d	S )
GlobalsExprNoder)   c                 C   s   | tj | S rJ   )r   r   Zglobals_utility_coder   rQ   rQ   rR   r"  H+  r  zGlobalsExprNode.analyse_typeszConstructing globals dictc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  N+  rW   zGlobalsExprNode.may_be_nonec                 C   s2   | d|  ||  | jf  | | d S )Nz%s = __Pyx_Globals(); %s)r   r   r   r   r  rm  rQ   rQ   rR   rv  Q+  s
   z$GlobalsExprNode.generate_result_codeN)
rX   rY   rZ   r   r   r   r"  r  r  rv  rQ   rQ   rQ   rR   r  D+  s    r  c                   @   r  )LocalsDictItemNodec                 C   sT   | j || _ | j|| _| j || _ | jj|r%| j|| _| S d | _| S rJ   )r  r"  r   r  r   r  r   rQ   rQ   rR   r"  Y+  s   z LocalsDictItemNode.analyse_typesN)rX   rY   rZ   r"  rQ   rQ   rQ   rR   r  X+  r
  r  c                       s$   e Zd Zdd Z fddZ  ZS )FuncLocalsExprNodec                    s@   t dd |j D } fdd|D }tj|  |dd d S )Nc                 S   s   g | ]}|j r|j qS rQ   r  r  rQ   rQ   rR   r   f+  s
    z/FuncLocalsExprNode.__init__.<locals>.<listcomp>c              
      s,   g | ]}t  t |d t |dddqS )r  T)rq   r	  r  )r  r  r  rU  r  rQ   rR   r   h+  s    
T)r  r  )rP  rQ  r  r  r  )rU   r   rs   rL  rR  rQ   r  rR   r  e+  s   


zFuncLocalsExprNode.__init__c                    s"   t  |}dd |jD |_|S )Nc                 S   s   g | ]	}|j d ur|qS rJ   r  )ra   r  rQ   rQ   rR   r   q+  s    
z4FuncLocalsExprNode.analyse_types.<locals>.<listcomp>)rL   r"  r  r$  rO   rQ   rR   r"  o+  s   z FuncLocalsExprNode.analyse_typesr`  rQ   rQ   rO   rR   r  d+  s    
r  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )PyClassLocalsExprNodec                 C      t | | || _d S rJ   )r%  r  pyclass_dict)rU   r   r  rQ   rQ   rR   r  w+     
zPyClassLocalsExprNode.__init__c                 C   r]  rR  )r  r   r   r   rQ   rQ   rR   r"  {+  r^  z#PyClassLocalsExprNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  +  rW   z!PyClassLocalsExprNode.may_be_nonec                 C   r  rJ   )r  r   rT   rQ   rQ   rR   r   +  rM  zPyClassLocalsExprNode.resultc                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  +  rW   z*PyClassLocalsExprNode.generate_result_codeN)rX   rY   rZ   r  r"  r  r   rv  rQ   rQ   rQ   rR   r  v+  s    r  c                 C   s*   |j rt| S |jrt| |jS t| |S rJ   )r  r  r  r  r*  r  )r   Z
scope_noders   rQ   rQ   rR   LocalsExprNode+  s
   
r  )not~ra  r   c                   @   s   e Zd ZdgZdZdZdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd%d"d#Zd$S )&UnopNoder  TFc                 C   s   t | j }|| jj| _d S rJ   )compile_time_unary_operatorsr	   r  r~   rU   rd  rQ   rQ   rR   r  +     
z"UnopNode.calculate_constant_resultc              
   C   sj   t | j}|st| jd| j  | j|}z||W S  ty4 } z| | W Y d }~d S d }~ww )Nz3Unary '%s' not supported in compile-time expression)	r  rj   r	   r   r   r  r  r  r  )rU   r  rd  r  r  rQ   rQ   rR   r  +  s   
zUnopNode.compile_time_valuec                 C   s<   | j |}|js|jr|| j}|d ur|S | ||S rJ   )r  r   r   r  find_cpp_operation_typer	   infer_unop_type)rU   rs   operand_typecpp_typerQ   rQ   rR   r   +  s   zUnopNode.infer_typec                 C   s   |j r|jstS |S rJ   )rp   r  r   rU   rs   r  rQ   rQ   rR   r  +  s   zUnopNode.infer_unop_typec                 C   s,   | j jr| j jjr| j jturdS t| S rR  )r  r   r  r   r   r  rT   rQ   rQ   rR   r  +  s   
zUnopNode.may_be_nonec                 C   s~   | j || _ | |rtt| j| j j| _d| _| S |  r-| 	| t
| _d| _| S |  r8| | | S | | | S r'  )r  r"  is_pythran_operationrG   r>   r	   r   r   is_py_operationcoerce_operand_to_pyobjectr   is_cpp_operationanalyse_cpp_operationanalyse_c_operationr   rQ   rQ   rR   r"  +  s   
	


zUnopNode.analyse_typesc                 C   r  rJ   r  r#  rT   rQ   rQ   rR   r#  +  rM  zUnopNode.check_constc                 C   s   | j jjp	| j jjS rJ   )r  r   rp   r  rT   rQ   rQ   rR   r  +  r  zUnopNode.is_py_operationc                 C   s    t |}| jj}|o|jp|jS rJ   )r?   r  r   r  r;   )rU   rs   Z
np_pythranop_typerQ   rQ   rR   r  +  s   zUnopNode.is_pythran_operationc                 C      |   r
|   d S d S rJ   r  rN  r   rQ   rQ   rR   rO  +     zUnopNode.nogil_checkc                 C   s   | j j}|jS rJ   )r  r   r   r  rQ   rQ   rR   r  +  s   zUnopNode.is_cpp_operationc                 C   rr  rJ   )r  r  r   rQ   rQ   rR   r  +  r   z#UnopNode.coerce_operand_to_pyobjectc                 C   s   | j jr'|d |d|    |d|  |  | j| j f  d S | jj jr3| | d S | j	rr| 
 r`| jdkr`t|| jd|  | j| j f | j jrW|  nd | j| j d S |d|  | j| j f  d S d S )Nz// Pythran unaryoprg  rj  r   %s = %s %s;)r   r;   r   r   r	   r  r   rp   generate_py_operation_coder   r  r   r   r   r   rr  rm  rQ   rQ   rR   rv  +  s(   

$zUnopNode.generate_result_codec              
   C   sF   |  |}|d|  || j ||  | jf  | | d S )Nr=  )py_operation_functionr   r   r  r   r   r   r  r(  rQ   rQ   rR   r  ,  s   
z#UnopNode.generate_py_operation_codec                 C   s0   | j jjst| jd| j| j jf  tj| _d S )Nz"Invalid operand type for '%s' (%s))r  r   r  r   r   r	   r   r0   rT   rQ   rQ   rR   
type_error,  s
   
zUnopNode.type_errorc                 C   s  | j jg}| jr| js|tj || j| j	|}|r$|s$| 
  d S |rF|jj| _|jj| _| jdkrEd| _t| rE|tdd nd| _d| _| jr^| js^| j jj| j	tjd}n| j j| j	}|r}|d u r}t| jd| j	tf  | 
  d S || _d S )Nr   Tr%  r  r  )r  z '%s' operator not defined for %s)r  r   is_inc_dec_op	is_prefixr   r   rg  r  r   r	   r  r   r   r   r   r   r   r   r  r   )rU   rs   overload_checkZoperand_typesr   r  rQ   rQ   rR   r  ,  s:   




zUnopNode.analyse_cpp_operationNrN  )rX   rY   rZ   r   infixr  r  r  r   r  r  r"  r#  r  r  rO  r  r  rv  r  r  r  rQ   rQ   rQ   rR   r  +  s(    
r  c                   @   s>   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d ZdS )NotNode!c                 C   s   | j j | _d S rJ   )r  r~   rT   rQ   rQ   rR   r  D,  r   z!NotNode.calculate_constant_resultc              
   C   sF   | j |}z| W S  ty" } z| | W Y d }~d S d }~ww rJ   )r  r  r  r  )rU   r  r  r  rQ   rQ   rR   r  G,  s   zNotNode.compile_time_valuec                 C      t jS rJ   )r   r  r  rQ   rQ   rR   r  N,  r)  zNotNode.infer_unop_typec                 C   s<   | j || _ | j j}|jr| | | S | j || _ | S rJ   )r  r"  r   r   r  r-  r  rQ   rQ   rR   r"  Q,  s   
zNotNode.analyse_typesc                 C      d| j   S )Nz(!%s)r  r   rT   rQ   rQ   rR   r   Z,  rL  zNotNode.calculate_result_codeN)rX   rY   rZ   r	   r   r  r   r  r  r  r"  r   rQ   rQ   rQ   rR   r  <,  s    	r  c                   @   (   e Zd ZdZdd Zdd Zdd ZdS )	UnaryPlusNoder   c                 C   s   t | jjt j| _d S rJ   )r   rX  r  r   rg  r   rQ   rQ   rR   r  c,  s   

z!UnaryPlusNode.analyse_c_operationc                 C   rS   )NZPyNumber_PositiverQ   rm  rQ   rQ   rR   r  g,  rW   z#UnaryPlusNode.py_operation_functionc                 C   s    |   rd| j  S | j S )Nz(+%s))r  r  r   rT   rQ   rQ   rR   r   j,  s   
z#UnaryPlusNode.calculate_result_codeN)rX   rY   rZ   r	   r  r  r   rQ   rQ   rQ   rR   r  ^,  s
    r  c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )UnaryMinusNodera  c                 C   sR   | j jjrt| j jtj| _n| j jjrtj| _n|   | jjr'd| _	d S d S rR  )
r  r   r]  r   rX  rg  r  r  r  r  r   rQ   rQ   rR   r  v,  s   




z"UnaryMinusNode.analyse_c_operationc                 C   rS   )NZPyNumber_NegativerQ   rm  rQ   rQ   rR   r  ,  rW   z$UnaryMinusNode.py_operation_functionc                 C   s0   | j r
d| j  S d| jjd| j f S )N(-%s)r  ra  )r  r  r   r   unary_oprT   rQ   rQ   rR   r   ,  s   z$UnaryMinusNode.calculate_result_codec                 C   s   | j  }|rd| S d S )Nr  )r  r  )rU   r   rQ   rQ   rR   r  ,  s   
z)UnaryMinusNode.get_constant_c_result_codeN)rX   rY   rZ   r	   r  r  r   r  rQ   rQ   rQ   rR   r  q,  s    r  c                   @   r  )	TildeNodec                 C   sD   | j jjrt| j jtj| _d S | j jjrtj| _d S |   d S rJ   )r  r   r  r   rX  rg  r  r  r   rQ   rQ   rR   r  ,  s   



zTildeNode.analyse_c_operationc                 C   rS   )NZPyNumber_InvertrQ   rm  rQ   rQ   rR   r  ,  rW   zTildeNode.py_operation_functionc                 C   r  )Nz(~%s)r  rT   rQ   rQ   rR   r   ,  rL  zTildeNode.calculate_result_codeN)rX   rY   rZ   r  r  r   rQ   rQ   rQ   rR   r  ,  s    	r  c                   @   r  )	CUnopNodec                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  ,  rW   zCUnopNode.is_py_operationN)rX   rY   rZ   r  rQ   rQ   rQ   rR   r  ,  s    r  c                   @   r  )	DereferenceNoder   c                 C   s   |j r|jS tjS rJ   )r  r  r   r0   r  rQ   rQ   rR   r  ,  s   zDereferenceNode.infer_unop_typec                 C   sB   | j jjr|jrt| j jj| _d S | j jj| _d S |   d S rJ   )r  r   r  Zis_cppr   r$  r  r  r   rQ   rQ   rR   r  ,  s
   
z#DereferenceNode.analyse_c_operationc                 C   r  rW  r  rT   rQ   rQ   rR   r   ,  rL  z%DereferenceNode.calculate_result_codeN)rX   rY   rZ   r	   r  r  r   rQ   rQ   rQ   rR   r  ,  s
    	r  c                   @   r  )	DecrementIncrementNodeTc                 C   sV   | j jjs%| jrt| jd| j| j jf  nt| jd| j| j| j jf  tj| _d S )Nz0No match for 'operator%s' (operand type is '%s')zENo 'operator%s(int)' declared for postfix '%s' (operand type is '%s'))	r  r   r  r  r   r   r	   r   r0   rT   rQ   rQ   rR   r  ,  s   
z!DecrementIncrementNode.type_errorc                 C   sF   | j jjrt| j jtj| _d S | j jjr| j j| _d S |   d S rJ   )r  r   r]  r   rX  rg  r  r  r   rQ   rQ   rR   r  ,  s   



z*DecrementIncrementNode.analyse_c_operationc                 C   s.   | j rd| j| j f S d| j | jf S )Nz(%s%s))r  r	   r  r   rT   rQ   rQ   rR   r   ,  s   z,DecrementIncrementNode.calculate_result_codeN)rX   rY   rZ   r  r  r  r   rQ   rQ   rQ   rR   r  ,  s
    
	r  c                    s    fddS )Nc                    s   t | f d|S )Nr  r	   )r  )r   rP  r  rQ   rR   <lambda>,  r   z%inc_dec_constructor.<locals>.<lambda>rQ   r  rQ   r  rR   inc_dec_constructor,  rL  r  c                   @   r  )AmpersandNoder  c                 C   s
   t |S rJ   )r   
c_ptr_typer  rQ   rQ   rR   r  ,  rM  zAmpersandNode.infer_unop_typec                 C   s   | j || _ | j j}|jr| j|dd |js3|js3| j  s3|jr*| 	d | S | 	d|  | S |j
rS| 	d| j jrCd| j j n| j jrMd| j j nd  | S |jrY| js_t|| _| S )	NF)r  z'Cannot take address of memoryview slicez&Taking address of non-lvalue (type %s)z Cannot take address of Python %szvariable '%s'zobject attribute '%s'r  )r  r"  r   r   r  r7  r   r   r   r   rp   r   rq   r  r  r   r  )rU   rs   ZargtyperQ   rQ   rR   r"  ,  s(   
zAmpersandNode.analyse_typesc                 C   r  rJ   )r  rV  rT   rQ   rQ   rR   r#  ,  rM  zAmpersandNode.check_constc                 C      t | j| tj| _d| _d S Nr  r   r   r   r0   r   r_  rU   ZmessrQ   rQ   rR   r   -     
zAmpersandNode.errorc                 C   r  )Nz(&%s)r  rT   rQ   rQ   rR   r   -  rL  z#AmpersandNode.calculate_result_codec                 C   s^   | j jjr+| jdkr-t|| jd|  | j| j  f | jjr"|  nd | j	| j
 d S d S d S )Nr   r  )r  r   r   r   r   r   r   r	   rp   r   rr  rm  rQ   rQ   rR   rv  	-  s   z"AmpersandNode.generate_result_codeN)
rX   rY   rZ   r	   r  r"  r#  r   r   rv  rQ   rQ   rQ   rR   r  ,  s    r  )r   ra  r  c                 C   s   t |tr|dkrt|jtt|j |j|jdS t |t	r8|j
|  kr+dv r8n nt| d|fd  d t| | ||dS )Nra  )r   r   rW  rV  z+-zAPython has no increment/decrement operator: %s%sx == %s(%sx) == x      )r	   r  )r}   r=  r   rw   r   rJ  r   rW  rV  r  r	   r   unop_node_classes)r   r	   r  rQ   rQ   rR   	unop_node-  s   $r  c                   @   s   e Zd ZdgZd Z ZZdd Zdd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd ZdddZdd Zdd Zdd ZdS )r  r  Nc                 C   rS   r  rQ   r   rQ   rQ   rR   r3  2-  rW   zTypecastNode.type_dependenciesc                 C   s0   | j d u r| j|}| j||\}| _ | j S rJ   )r   r  r  
declarator)rU   rs   r  r4  rQ   rQ   rR   r   5-  s   
zTypecastNode.infer_typec                 C   s  | j d u r| j|}| j||\}| _ | j r|   | j jr,t| j	d t
j| _ | j|| _| j t
ju r?| j|S | j j}| jj j}|r_|s_| j r_| j js_| j js_t| j	d |r|s| j tu rs| jj jrst| j|S | jj |rt| _| j| j || _n| jj jr| jj jjs| jj jjst| j	d nt| j	d| jj | j f  | j|| _n|r|s| j |r| j| j || _nl| j jr| j jjs| j jjst| j	d nWt| j	d| j | jj f  nI|r|r| j rt!| j| j |dd| _n3t"| jt#r| j| j || _n"| j j$r%| jj j$r%| j|| _n| jj j%r4| j| j || _| j jr_| j jjr_| j jj&r_| jj }|jrP|j}|jr_|j&s_t| j	dd	 | S )
NzCannot cast to a function typez>Casting temporary Python object to non-numeric non-Python typez>Python objects cannot be cast from pointers of primitive typesz8No conversion from %s to %s, python object pointer used.z<Python objects cannot be cast to pointers of primitive typesT)notnonezQCasting a GIL-requiring function into a nogil function circumvents GIL validationr)   )'r   r  r  r  r  r   r  r7  r   r   r   r0   r"  r  r-  rp   r   r]  r   r   r  r  r  r   r  r  r  r`  r  r   r0  create_from_py_utility_codeZ	typecheckr  r}   r  r  rD  r   )rU   rs   r  r4  Zto_pyZfrom_pyr  rQ   rQ   rR   r"  ;-  sz   






"zTypecastNode.analyse_typesc                 C   r  rJ   )r  r  rT   rQ   rQ   rR   r  {-  r  zTypecastNode.is_simplec                 C   r  rJ   )r  r   rT   rQ   rQ   rR   r   -  r  zTypecastNode.is_ephemeralc                 C   s   | j p| j S rJ   )r   r  r8  rT   rQ   rQ   rR   r8  -  r   z!TypecastNode.nonlocally_immutablec                 C   s,   | j r| j jr| jr|   d S d S d S d S rJ   )r   rp   r   rN  r   rQ   rQ   rR   rO  -  s   zTypecastNode.nogil_checkc                 C   r  rJ   r  rT   rQ   rQ   rR   r#  -  rM  zTypecastNode.check_constc                 C   s   |  | jj| _d S rJ   )r   r  r~   rT   rQ   rQ   rR   r  -  r  z&TypecastNode.calculate_constant_resultc                 C   s   |d u r	| j  }| jjrB| j  }| j jjr0| jj| j j|}| jj| j j|}n	| jj|}d}d| jj||f S | j|S NrA  r  )	r  r   r   r  	real_typer  	real_code	imag_coder  )rU   operand_result	real_part	imag_partrQ   rQ   rR   r   -  s&   


z"TypecastNode.calculate_result_codec                 C   s   | j  }|r| j|S d S rJ   )r  r  r   r  )rU   r  rQ   rQ   rR   r  -  s   
z'TypecastNode.get_constant_c_result_codec                 C   s&   | j jr| js| j|S t| |S rJ   )r   rp   r   r  r   r   r  rQ   rQ   rR   r   -  s   zTypecastNode.result_asc                 C   s>   | j r|d|  | j f  ||  |   d S d S )Nz%s = (PyObject *)%s;)r   r   r   r  rl  r  rm  rQ   rQ   rR   rv  -  s   z!TypecastNode.generate_result_coderJ   )rX   rY   rZ   r   r  r  r   r3  r   r"  r  r   r8  rO  r#  r  r   r  r   rv  rQ   rQ   rQ   rR   r  $-  s     @
r  zStart may not be givenz'Stop must be provided to indicate shapezVStrides may only be given to indicate contiguity. Consider slicing it after conversionz2Can only create cython.array from pointer or arrayz7Pointer base type does not match cython.array base typec                   @   sb   e Zd ZdZddgZdZdZdZdZe	j
Zdd Zd	d
 Zdd Zdd Zdd Zedd ZdS )r  an  
    Used when a pointer of base_type is cast to a memoryviewslice with that
    base type. i.e.

        <int[:M:1, :N]> p

    creates a fortran-contiguous cython.array.

    We leave the type set to object so coercions to object are more efficient
    and less work. Acquiring a memoryviewslice from this will be just as
    efficient. ExprNode.coerce_to() will do the additional typecheck on
    self.compile_time_type

    This also handles <int[:, :]> my_c_array


    operand             ExprNode                 the thing we're casting
    base_type_node      MemoryViewSliceTypeNode  the cast expression node
    r  shapesNTr  c                 C   s  ddl m} | j|| _| jr| j}n| jj|}| jj}t| _	g | _
t|}| jj	}| jj	js@| jj	js@t| jjt | S g }|jrU|jrT||j |j}|jsHn|jr\|j}n
t| jd|  | S ||sw|jswt| jjt | S | jj	jrt||krt| jjd|t|f  | S t|D ]\}}	|	jjst|	jjt |   S |	jjr|st|	jt |   S t| j|| |	_|	j||	_|	j| j |}
|
j!s|
"| | j
|
 |d|d fv }|	j#js/|r/|	j#||	_#|	j#j	j$s|	j#j!r|	j#j	j%st|	j#jd |   S |	j#&|dkr&t|	j#jt' |   S |dkr.d| _(q|	j#jsB|sBt|	j#jt' |   S q| jj)sO| j"|| _dgt| }| j(dkrad	|d< nd	|d
< t*+||| _,| j,-| j | .|| _	|/| |0|1|j2j3 | S )Nr)   r  zunexpected base type %s foundz/Expected %d dimensions, array has %d dimensionsr   zExpected an integer literalfortran)rm  follow)rm  Zcontigr,  )4r  r  r  r"  array_dtypebase_type_noder  r  r0   r   r  r   r  r6  r   r   ERR_NOT_POINTERr   r$  r  r  r`  ERR_BASE_TYPEr  r   r   	ERR_STARTr   ERR_NOT_STOPr=  rS  r  
shape_typer   r  r   r  r  r  	ERR_STEPSmoder   r   r  r  Zvalidate_memslice_dtypeget_cython_array_typeZuse_cython_array_utility_coder   Zget_typeinfo_to_format_coder/  r  )rU   rs   r  r  r  r  r  Zarray_dimension_sizesZaxis_noZaxisshapeZfirst_or_lastrQ   rQ   rR   r"  -  s   





zCythonArrayNode.analyse_typesc                 C   s$   | j rtd|j| jd| _ d S )Nztemp allocated multiple timesT)r   r_  rb  rc  r   rm  rQ   rQ   rR   re  E.  s   z$CythonArrayNode.allocate_temp_resultc                 C   r&  rJ   )r  r   rQ   rQ   rR   r   K.  rM  zCythonArrayNode.infer_typec                 C   s   |j j}|  |jdjS )Narray)r/  cython_scopeZload_cythonscopeZ	viewscoper  r   )rU   rs   r  rQ   rQ   rR   r  N.  s   z%CythonArrayNode.get_cython_array_typec                    s  ddl m} fddjD }jj} jtd} jtd} jtd}d|	  }|
 |}	jjjrX dj    d   jj  d	  d
||	 |jf   |t dt| }
 d||
d| |jf   |t  d  d|| |jf   d  d||f   d  d |||jj   jf     fdd}|| ||  j| d S )Nr)   r  c                    s   g | ]
} j | qS rQ   )r  r  r   )ra   r  rT   rQ   rR   r   V.  s    z8CythonArrayNode.generate_result_code.<locals>.<listcomp>Trs  z
if (!%s) {zQPyErr_SetString(PyExc_ValueError,"Cannot create cython.array from NULL pointer");r   z(%s = __pyx_format_from_typeinfo(&%s); %sz __PYX_BUILD_PY_SSIZE_T z&%s = Py_BuildValue("(" %s ")", %s); %sr>  r<  z%s = PyBytes_AsString(%s); %sr  z%s = PyBytes_AS_STRING(%s);rk  z7%s = __pyx_array_new(%s, %s, %s, "%s", (char *) %s); %sc                    s     | t  j|  d S rJ   )r  r   rb  rj  )rl  )r   rQ   rR   dispose.  r  z5CythonArrayNode.generate_result_code.<locals>.dispose)r  r  r  r  r  rb  rc  r   r.   r  Zget_type_information_cnamer  r   r  r   r   r   r   r   r  r   rA  r  r  rj  )rU   r   r  r  r  Zshapes_tempZformat_tempZformat_ptr_tempitemsize	type_infoZbuildvalue_fmtr  rQ   r`  rR   rv  S.  sb   







z$CythonArrayNode.generate_result_codec           	      C   s   |j }|j}t|}g }|jr |t||||d |j}|jst|d|d _	t
j|||d}t||||d}||}|S )z@
        Given a C array type, return a CythonArrayNode
        r/  r)   r,  )r  r  )r  r  r  )r   r   r  r6  r   r  r  r=  rS  r   r   ZMemoryViewSliceTypeNoder  r"  )	rN   Zsrc_noders   r   r  r  r  Zmemslicenoder   rQ   rQ   rR   r  .  s&   
zCythonArrayNode.from_carray)rX   rY   rZ   r$  r   r  r   r  r  r   r  r  r"  re  r   r  rv  r  r  rQ   rQ   rQ   rR   r  -  s    f@r  c                   @   s"   e Zd ZejZdd Zdd ZdS )
SizeofNodec                 C   rS   r+  rQ   rT   rQ   rQ   rR   r#  .  rW   zSizeofNode.check_constc                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  .  rW   zSizeofNode.generate_result_codeN)rX   rY   rZ   r   r[  r   r#  rv  rQ   rQ   rQ   rR   r  .  s    r  c                   @   s,   e Zd Zg ZdZdd Zdd Zdd ZdS )r|  Nc           
      C   s<   	 | j
d u r| j |}| j||\}}	|	| _
|   | S rJ   )r  module_pathr  r  r  r   r  rq   SizeofVarNoder"  r}  r  r  
check_type)
rU   rs   rf  r  r  ru  r   r  r4  r}  rQ   rQ   rR   r"  .  s   

zSizeofTypeNode.analyse_typesc                 C   s`   | j }|sd S |jr|jst| jd d S |jr t| jd d S | s.t| jd|  d S d S )Nz Cannot take sizeof Python objectzCannot take sizeof voidz'Cannot take sizeof incomplete type '%s')r}  rp   r  r   r   r`  is_complete)rU   r}  rQ   rQ   rR   r  .  s   zSizeofTypeNode.check_typec                 C   s2   | j jr| j jddd}d| S | j  }d| S )Nr  r)   )Zderef(sizeof(%s)))r}  r  r   r  )rU   r  rQ   rQ   rR   r   .  s
   
z$SizeofTypeNode.calculate_result_code)rX   rY   rZ   r   r}  r"  r  r   rQ   rQ   rQ   rR   r|  .  s    r|  c                   @   r  )	r  r  c                 C   sx   | j |}|r3|| _| jjr*z
| j|j| _W n ty)   t| j jd Y nw t	| _
|   | S | j || _ | S )NzLType cannot be specialized since it is not a fused argument to this function)r  rC  r}  rD  rF  rE  r*   r   r   r|  rP   r  r"  )rU   rs   Zoperand_as_typerQ   rQ   rR   r"  .  s    zSizeofVarNode.analyse_typesc                 C   r  )Nr  r  rT   rQ   rQ   rR   r   /  rL  z#SizeofVarNode.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  /  rW   z"SizeofVarNode.generate_result_codeN)rX   rY   rZ   r   r"  r   rv  rQ   rQ   rQ   rR   r  .  s
    r  c                   @   sR   e Zd ZdgZdZdZdZdd ZdZdd Z	d	d
 Z
dd Zdd Zdd ZdS )
TypeidNoder  Nr)   c                 C   sD   |}|j s|j}|j r|d| j}|d}ttj|jddS )Nzlibcpp.typeinfor  T)r  )	r  rH  find_moduler   r  r   r  r  r   )rU   rs   Z
env_moduleZtypeinfo_moduleZtypeinfo_entryrQ   rQ   rR   get_type_info_type/  s   
zTypeidNode.get_type_info_typeztypeid operatorc                 C   s   | j stj| _ | | | |}|s| d | S | jd u r!| S || _ | j|}|r6|| _d| _	d | _n6| j
|| _d| _	d | _| jj jrO| d | S | jj jr[| d | S | jj  sl| d| jj   | S |tdd | S )	NzKThe 'libcpp.typeinfo' module must be cimported to use the typeid() operatorTFz$Cannot use typeid on a Python objectzCannot use typeid on voidz)Cannot use typeid on incomplete type '%s'r%  r  )r   r   r0   r  r  r   r  rH  r}  rw  r"  rp   r`  r  r   r   r   )rU   rs   r  Zas_typerQ   rQ   rR   r"   /  s:   







zTypeidNode.analyse_typesc                 C   r  r  r  r  rQ   rQ   rR   r   @/  r  zTypeidNode.errorc                 C   rS   r+  rQ   rT   rQ   rQ   rR   r#  E/  rW   zTypeidNode.check_constc                 C   r   rJ   r  rT   rQ   rQ   rR   r   H/  r)  z TypeidNode.calculate_result_codec                 C   s@   | j r	| j }n| j }t|| jd| j|f d d | j d S )Nz%s = typeid(%s);)rw  r}  r  r   r   r   r   rr  )rU   r   r  rQ   rQ   rR   rv  K/  s   
zTypeidNode.generate_result_code)rX   rY   rZ   r   r}  r  r   r  Zcpp_messager"  r   r#  r   rv  rQ   rQ   rQ   rR   r  	/  s     r  c                   @   sB   e Zd ZdZeZdgZdd Zdd Zdd Z	d	d
 Z
dd ZdS )
TypeofNodeNrd  c                 C   sH   | j || _ tt| j j}t| j|d}||}||| _	| S rD  )
r  r"  r   r  rw   r   r:  r   r  rd  )rU   rs   r   rd  rQ   rQ   rR   r"  _/  s   
zTypeofNode.analyse_typesc                 C   s   | j || _ | j jS rJ   )r  r"  r   r   rQ   rQ   rR   rC  g/  s   zTypeofNode.analyse_as_typec                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  k/  rW   zTypeofNode.may_be_nonec                 C   r!  rJ   )rd  r{  rm  rQ   rQ   rR   r{  n/  r   z#TypeofNode.generate_evaluation_codec                 C   r  rJ   )rd  r   rT   rQ   rQ   rR   r   q/  rM  z TypeofNode.calculate_result_code)rX   rY   rZ   rd  r   r   r   r"  rC  r  r{  r   rQ   rQ   rQ   rR   r  T/  s    r  c                 C   s.   z| j }W n ty   |j}Y nw || |S rJ   )
__matmul__r   __rmatmul__)r  brd  rQ   rQ   rR   matmul_operator}/  s   


r  <<===r  >=>r  is_notr   r  ///<<%r   rT  **c                 C   s   | |v S rJ   rQ   xseqrQ   rQ   rR   r  /      rb  c                 C   s   | |vS rJ   rQ   r  rQ   rQ   rR   r  /  r  )>>ra  ^@innot_inc                 C   s&   t | j}|st| jd| j  |S )Nz4Binary '%s' not supported in compile-time expression)compile_time_binary_operatorsrj   r	   r   r   )r   rd  rQ   rQ   rR   get_compile_time_binop/  s   r  c                       s   e Zd ZddgZdZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Z fd$d%Zd&d' Zd(d) Z  ZS )*	BinopNoder  r  Fc                 C   s"   t | j }|| jj| jj| _d S rJ   )r  r	   r  r~   r  r  rQ   rQ   rR   r  /  s
   

z#BinopNode.calculate_constant_resultc              
   C   s^   t | }| j|}| j|}z|||W S  ty. } z| | W Y d }~d S d }~ww rJ   )r  r  r  r  r  r  )rU   r  rd  r  r  r  rQ   rQ   rR   r  /  s   zBinopNode.compile_time_valuec                 C   s   |  | j|| j||S rJ   )r  r  r   r  r   rQ   rQ   rR   r   /  s   zBinopNode.infer_typec                 C   s&   | j || _ | j|| _| |S rJ   )r  r"  r  rq  r   rQ   rQ   rR   r"  /  s   
zBinopNode.analyse_typesc                 C   s   |  |r| | jj| jj|| _| jjsJ d| _| S |  rG| | | | jj| jj|| _d| _| jj	sE| jt
}| _| ||S | S |  rR| | | S | | | S r'  )r  r  r  r   r  r;   r   r  coerce_operands_to_pyobjectsrp   r   r  r  r  r  )rU   rs   Zoriginal_typerQ   rQ   rR   rq  /  s,   





zBinopNode.analyse_operationc                 C   s   |  | jj| jjS rJ   )is_py_operation_typesr  r   r  rT   rQ   rQ   rR   r  /  r  zBinopNode.is_py_operationc                 C   s   |j p|j p|jp|jS rJ   )rp   r  rU   type1type2rQ   rQ   rR   r  /  r  zBinopNode.is_py_operation_typesc                 C   s   |  | jj| jj|S rJ   )is_pythran_operation_typesr  r   r  r   rQ   rQ   rR   r  /  r  zBinopNode.is_pythran_operationc                 C   s(   t |ot|ot|ot|pt|S rJ   )r?   r:   r;   )rU   r  r  rs   rQ   rQ   rR   r  /  s
   z$BinopNode.is_pythran_operation_typesc                 C      | j jjp	| jjjS rJ   r  r   r   r  rT   rQ   rQ   rR   r  /  r  zBinopNode.is_cpp_operationc                 C   s   | | j| j| jg}|s|   d S |j}|j| _|j| _| jdkr3d| _t	| r3|
tdd |jr9|j}t|jdkrM| j|jd j|| _n| j|jd j|| _| j|jd j|| _|j| _d S )Nr   r)   r%  r  r   )r  r	   r  r  r  r   r   r   r   r   r   r   r   r  r  r   r   r  rf  )rU   rs   r   r&  rQ   rQ   rR   r  /  s$   
zBinopNode.analyse_cpp_operationc                 C   s   |  |||rtt| j||S | ||rS|jrtj}n|jr#tj	}|jr*tj}n|jr0tj	}|j
s6|j
rQ||u rE|turE| jdv rE|S | ||}|d urQ|S tS |jsY|jr\tjS | ||S )Nz**%+|&^)r  rG   r=   r	   r  rw  r   r   rx  r   r  r   infer_builtin_types_operationr   r  r   r0   compute_c_result_type)rU   r  r  rs   r  rQ   rQ   rR   r  0  s*   zBinopNode.result_typec                 C   r   rJ   rQ   r  rQ   rQ   rR   r  *0  rW   z'BinopNode.infer_builtin_types_operationc                 C   r  rJ   r  r   rQ   rQ   rR   rO  -0  r  zBinopNode.nogil_checkc                 C   s    | j || _ | j|| _d S rJ   )r  r  r  r   rQ   rQ   rR   r  10  r  z&BinopNode.coerce_operands_to_pyobjectsc                 C      | j  o	| j S rJ   r  r#  r  rT   rQ   rQ   rR   r#  50  r  zBinopNode.check_constc                    s   t   p| j p| j S rJ   )rL   r   r  r  rT   rO   rQ   rR   r   80  s
   
zBinopNode.is_ephemeralc                 C   s  | j j}| jj}| jjrO|d |d|    | jdkr6|d|  |  | j  | j f  d S |d|  |  | j  | j| j f  d S |jsU|jr| 	|}| jdkradnd}|jrk| j 
 n| j  }|jrx| j
 n| j }|d|  ||||||  | jf  | | d S | jr|  r| jd	krt|| jd
|  |  f | jjr|  nd | j| j d S |d
|  |  f  d S d S )Nz// Pythran binoprg  r  zBnew (&%s) decltype(%s){pythonic::numpy::functor::power{}(%s, %s)};z!new (&%s) decltype(%s){%s %s %s};z	, Py_Noner  rF  r   r  )r  r   r  r;   r   r   r	   r   rp   r  r   r   r   r  r   r  r   r   r   r   rr  )rU   r   r  r  r  
extra_argsZ
op1_resultZ
op2_resultrQ   rQ   rR   rv  <0  sX   


zBinopNode.generate_result_codec                 C   s@   | j jjs| jjjst| jd| j| j j| jjf  tj| _d S )Nz'Invalid operand types for '%s' (%s; %s))	r  r   r  r  r   r   r	   r   r0   rT   rQ   rQ   rR   r  h0  s   

zBinopNode.type_error)rX   rY   rZ   r   r  r  r  r   r"  rq  r  r  r  r  r  r  r  r  rO  r  r#  r   rv  r  r[   rQ   rQ   rO   rR   r  /  s,    	,r  c                   @   ,   e Zd Zdd Zdd Zdd Zdd Zd	S )

CBinopNodec                 C   s    t | |}| rtj|_|S rJ   )r  r"  r  r   r0   r   r$  rQ   rQ   rR   r"  s0  s   zCBinopNode.analyse_typesc                 C   rS   r  rQ   rm  rQ   rQ   rR   r  y0  rW   z CBinopNode.py_operation_functionc                 C   s   d| j  | j| j f S N
(%s %s %s))r  r   r	   r  rT   rQ   rQ   rR   r   |0  s
   z CBinopNode.calculate_result_codec                 C   sD   d }|j s|jr|| j|}|d u r |j s|jr || j|}|S rJ   )r   r  r  r	   )rU   r  r  r  rQ   rQ   rR   r  0  s   z CBinopNode.compute_c_result_typeN)rX   rY   rZ   r"  r  r   r  rQ   rQ   rQ   rR   r  q0  s
    r  c                    s    fdd}|S )Nc                    s   t | fd i|S )Nr	   )r  )r   r  r	   rQ   rR   make_binop_node0  r  z,c_binop_constructor.<locals>.make_binop_noderQ   )r	   r#  rQ   r"  rR   c_binop_constructor0  s   r$  c                       s   e Zd ZdZdZdZdd Zdd Zdd	 Z fd
dZ	dd Z
dd Z fddZdd Zdd Zdd Zddddddddd d!d"d#d$d%Zd&d'd(d)d*Z  ZS )+NumBinopNodeTFNc                 C   s  | j j}| jj}| ||| _| js|   d S | jjrd| _| jjrc|jd rc| j	| j
v rc| j	dv rF| j  rF| j sF| j| j | _ | _d| _|jd | _| jj| j
| j	 || j d| _d| _| jrl|jr|jr| j | j|| _ | j| j|| _d S d S d S )NFr  )r   r   Tzoverflowcheck.fold)Z	const_rhs)r  r   r  r  r  r  r  r  rk   r	   overflow_op_namesr   overflow_checkZoverflow_foldZoverflow_check_binoprd  r   r]  r  rU   rs   r  r  rQ   rQ   rR   r  0  s<   

z NumBinopNode.analyse_c_operationc                 C   sL   |  ||r$t||}|tju r| jdvrtj}|S t|tj}|S d S )Nz|^&)c_types_okayr   rX  r  r	   rg  rU   r  r  Zwidest_typerQ   rQ   rR   r  0  s   

z"NumBinopNode.compute_c_result_typec                 C   s   |j r	t||S t||S rJ   )r  r   Z result_type_of_builtin_operationr  rQ   rQ   rR   r  0  s   z*NumBinopNode.infer_builtin_types_operationc                    sD   | j r	| j jr	dS | jj }| jj }|r|jr|r|jrdS t  S rR  )r   r  r  r  rL   r  r  rO   rQ   rR   r  0  s   
zNumBinopNode.may_be_nonec                 C   s0   | j  }| j }|r|rd|| j|f S d S r   )r  r  r  r	   )rU   Zvalue1Zvalue2rQ   rQ   rR   r  0  s
   

z'NumBinopNode.get_constant_c_result_codec                 C      |j s|jo|j p|jS rJ   )r]  r  r  rQ   rQ   rR   r)  0     
zNumBinopNode.c_types_okayc                    s   | j r| | _|jjtjdd| _|d| j  t 	| | j rE|d| j  |d ||
| j |d |j| j d S d S )NFr]  r  rK  z8PyErr_SetString(PyExc_OverflowError, "value too large");r   )r'  overflow_bit_noderb  rc  r   rg  overflow_bitr   rL   r{  r   r   rj  rm  rO   rQ   rR   r{  0  s   

z%NumBinopNode.generate_evaluation_codec                 C   s   | j d urd| j| j | j | j jf S | jjs| jrAt	| jr.| j
 | j
 }}n| j | j }}d|| j|f S | j| j}|d u rXt| jd| j| jf  d|| j | j f S )Nz%s(%s, %s, &%s)r!  z'binary operator %s not supported for %sr  )r-  rd  r  r   r  r.  r   r   r  r;   r   r	   	binary_opr   r   )rU   result1result2rd  rQ   rQ   rR   r   0  s(   

z"NumBinopNode.calculate_result_codec                 C      |j p|j pt| ||S rJ   )r  r  r  r  rQ   rQ   rR   r  1  
   z"NumBinopNode.is_py_operation_typesc                 C   s"   | j | j }| jr|dd}|S )NZ	PyNumber_ZPyNumber_InPlace)py_functionsr	   r  rz  )rU   r   r  rQ   rQ   rR   r  	1  s   z"NumBinopNode.py_operation_functionZPyNumber_OrZPyNumber_XorZPyNumber_AndZPyNumber_LshiftZPyNumber_RshiftZPyNumber_AddZPyNumber_SubtractZPyNumber_MultiplyZ__Pyx_PyNumber_MatrixMultiplyZ__Pyx_PyNumber_DivideZPyNumber_FloorDivideZPyNumber_RemainderZPyNumber_Power)rT  r
  r  r  r	  r   ra  r   r  r   r  r  r  r  r  mullshift)r   ra  r   r  )rX   rY   rZ   r  r'  r-  r  r  r  r  r  r)  r{  r   r  r  r4  r&  r[   rQ   rQ   rO   rR   r%  0  sB    r%  c                   @   r  )IntBinopNodec                 C   r+  rJ   )r  r  r  rQ   rQ   rR   r)  *1  r,  zIntBinopNode.c_types_okayN)rX   rY   rZ   r)  rQ   rQ   rQ   rR   r7  '1  r  r7  c                   @   r  )BitwiseOrNodec                 C   s   | j js| jjrdgS d S r  )r  r   r  r   rQ   rQ   rR   r  31  s   z(BitwiseOrNode.analyse_pytyping_modifiersc                 C   sn   | d ||}W d   n1 sw   Y  |sdS | s5|jr,| s,|jS t|jd|  |S )z=Analyse annotations in form `[...] | None` and `None | [...]`FNz)'[...] | None' cannot be applied to type )new_c_type_contextrC  Zcan_be_optionalr   r  r   r   )rU   rs   Zoperand_nodettyperQ   rQ   rR   _analyse_bitwise_or_none71  s   z&BitwiseOrNode._analyse_bitwise_or_nonec                 C   s0   | j jr| || jS | jjr| || j S d S rJ   )r  r   r;  r  r   rQ   rQ   rR   rC  F1  s
   zBitwiseOrNode.analyse_as_typeN)rX   rY   rZ   r  r;  rC  rQ   rQ   rQ   rR   r8  01  s    r8  c                       s8   e Zd Zdd Z fddZdd Z fddZ  ZS )	AddNodec                 C   s*   |j r|j s|jr|jrdS t| ||S r'  )rw  rx  r%  r  r  rQ   rQ   rR   r  Q1  s   zAddNode.is_py_operation_typesc                    sB   t ttf}||v r||v r|t|||| S t ||S rJ   )r   r   r   r  r;  rL   r  )rU   r  r  string_typesrO   rQ   rR   r  W1  s   
z%AddNode.infer_builtin_types_operationc                 C   sF   |j s|jr|js|jr|S |j s|jr|js|jr|S t| ||S rJ   )r  r6  r  r  r%  r  r  rQ   rQ   rR   r  `1  s   zAddNode.compute_c_result_typec                    s   | j j| jj}}d }|tu s|tu rK|tu r|tu rd}nt| j ts*t| jtr-d}nd}|rKd}| js;| j  rK|j	t
dd ||  7 }|ri| jsU| j  rY|d7 }| j  sc| j rg|d7 }|S t |S )NTFZ__Pyx_PyUnicode_ConcatZUnicodeConcatInPlacer  ZInPlaceZSafe)r  r   r  r   r}   r  r  rX  r   r   r   r   r  r  rL   r  )rU   r   r  r  rd  Zis_unicode_concatrO   rQ   rR   r  j1  s,   
zAddNode.py_operation_function)rX   rY   rZ   r  r  r  r  r[   rQ   rQ   rO   rR   r<  N1  s
    	
r<  c                   @   r  )SubNodec                 C   sH   |j s|jr|js|jr|S |j s|jr|j s|jrtjS t| ||S rJ   )r  r6  r  r  r   Zc_ptrdiff_t_typer%  r  r  rQ   rQ   rR   r  1  s   zSubNode.compute_c_result_typeN)rX   rY   rZ   r  rQ   rQ   rQ   rR   r>  1  r  r>  c                       sh   e Zd ZdZdd Zedd Zdd Zdd	 Z fd
dZ	 fddZ
 fddZ fddZ  ZS )MulNodeFc                 C   s   | j || _ | j|| _|  | _| jrQ| j }| j}|jr+|jd u r+| |||S |jr:|jd u r:| |||S |jt	v rF|
|| _n|jt	v rQ|
|| _ | |S rJ   )r  r"  r  calculate_is_sequence_mulis_sequence_mulr   r   analyse_sequence_mulr   r    r  rq  rU   rs   r  r  rQ   rQ   rR   r"  1  s   



zMulNode.analyse_typesc                 C   s   | j o
| tv o
| tuS rJ   )r  r    r   r  rQ   rQ   rR   is_builtin_seqmul_type1  rL  zMulNode.is_builtin_seqmul_typec                 C   s\   | j j}| jj}|tju s|jr||}}|tju s|jr,|js#|jr%dS | |r,dS dS r  )	r  r   r  r   rZ  r  rw  r  rD  r  rQ   rQ   rR   r@  1  s   

z!MulNode.calculate_is_sequence_mulc                 C   s.   |j d u sJ ||}|||_ ||S rJ   )r   r  r  r"  )rU   rs   r  ZmultrQ   rQ   rR   rB  1  s   

zMulNode.analyse_sequence_mulc                    sN   | j r| jjjr| j|| _d S | jjjr| j|| _d S t | d S rJ   )rA  r  r   r  r  r  rL   r  r   rO   rQ   rR   r  1  s   

z$MulNode.coerce_operands_to_pyobjectsc                    s   | j p	t ||S rJ   )rA  rL   r  r  rO   rQ   rR   r  1  r  zMulNode.is_py_operation_typesc                    s8   | j r|jtdd | jjjrdS dS t 	|S )Nr  r  Z__Pyx_PySequence_MultiplyZ__Pyx_PySequence_Multiply_Left)
rA  r   r   r   r   r  r   rp   rL   r  rm  rO   rQ   rR   r  1  s   
zMulNode.py_operation_functionc                    sJ   |j r|j r| |r|S | |r|S |jr|S |jr|S t ||S rJ   )r  rD  r  rL   r  r  rO   rQ   rR   r  1  s   

z%MulNode.infer_builtin_types_operation)rX   rY   rZ   rA  r"  r<  rD  r@  rB  r  r  r  r  r[   rQ   rQ   rO   rR   r?  1  s    

r?  c                       s,   e Zd Zdd Zdd Z fddZ  ZS )MatMultNodec                 C   rS   r+  rQ   r  rQ   rQ   rR   r  1  rW   z!MatMultNode.is_py_operation_typesc                 C   r   rJ   rQ   r  rQ   rQ   rR   r  1  r  z)MatMultNode.infer_builtin_types_operationc                    s$   |j tdd t | d S )NZMatrixMultiplyr  )r   r   r   r   rL   r{  rm  rO   rQ   rR   r{  1  s   z$MatMultNode.generate_evaluation_code)rX   rY   rZ   r  r  r{  r[   rQ   rQ   rO   rR   rE  1  s    rE  c                       s   e Zd ZdZdZdZdZdZdd Zdd Z	dd Z
d	d
 Zdd Z fddZdd Zdd Zdd Zdd Zdd Zdd Z  ZS )DivNodeNFc                 C   s>   t | j }| jdkr| jd u rt|trt|trt d }|S )Nr   r  )r  r	   truedivisionr}   r   rU   op1op2rd  rQ   rQ   rR   !find_compile_time_binary_operator2  s
   
z)DivNode.find_compile_time_binary_operatorc                 C   s,   | j j}| jj}| ||}|||| _d S rJ   )r  r~   r  rK  rH  rQ   rQ   rR   r  
2  s   z!DivNode.calculate_constant_resultc              
   C   sb   | j |}| j|}| ||}z|||W S  ty0 } z| | W Y d }~d S d }~ww rJ   )r  r  r  rK  r  r  )rU   r  r  r  rd  r  rQ   rQ   rR   r  2  s   zDivNode.compile_time_valuec                 C   s&   | j s|jd rd| _d S | j| _d S )N	cdivisionF)rL  rk   ctruedivisionrG  r   rQ   rQ   rR   _check_truedivision2  s   
zDivNode._check_truedivisionc                 C   s(   |  | | | j|| j||S rJ   )rN  r  r  r   r  r   rQ   rQ   rR   r   2  s
   

zDivNode.infer_typec                    sl   t  ||}|d ur4| jdkr4| js| jr*|tju rtjS |j	r(t
tj|S |S |tju s2|j	r4d }|S Nr   )rL   r  r	   rG  rM  r   rZ  r   rn  r  rX  )rU   r  r  r  rO   rQ   rR   r  %2  s   
z%DivNode.infer_builtin_types_operationc                 C   s   |  | t| |}|  rd| _| jjsD| jd u o,|jd  o,| j	  p,| jj
dk| _| js6|jd rD| j|| _| j|| _|S )NTrL  r   cdivision_warnings)rN  r%  rq  r  rL  r   rp   rk   r  r   r~   zerodivision_checkr  r0  rU   rs   r   rQ   rQ   rR   rq  32  s   

zDivNode.analyse_operationc                 C   sT   | j dkr#| jr#|js#|js#|js#|js#t|tj}t||}|S t| ||S rO  )	r	   rM  r   r  r   rX  rn  r%  r  r*  rQ   rQ   rR   r  H2  s   zDivNode.compute_c_result_typec                 C      | j jrdS dS )N"integer division or modulo by zerozfloat divisionr0  rT   rQ   rQ   rR   zero_division_messageP2     zDivNode.zero_division_messagec                 C   s   | j js6| j js6| jd u r%|jjd p#| j jp#| j js| j jo#| j j	 | _| js6|j
tdd| j  t| | | | d S )NrL  ZDivIntCMath.c)r   rp   r  rL  r   rk   r  r]  r  r!  r   r   r   rF  r%  r{  generate_div_warning_coderm  rQ   rQ   rR   r{  V2  s   
z DivNode.generate_evaluation_codec                 C   sb  | j }| jjs+| jr| jsd| jd| j f }nd| j  }|d|  |r0|	  |d| 
   |r?|  ||| j |d | jjr| jjr| jdkr|jtdd	 | jjjd
krsd| j  }n| jj }d|| j |f }|d| j || j f  |r|	  |d |r|  ||| j |d |jjd r-| jdkr/|jtdd |d| j | j f  dtjtjd }|r
d}|d|  |	  ||j| jdd |d||f  |  n|}||j| jdd |d|  ||j |d d S d S d S d S )Nr  zeroz%s == 0rK  z/PyErr_SetString(PyExc_ZeroDivisionError, "%s");r   r  ZUnaryNegOverflowsr  r4   zunlikely(%s == -1)z+(!(((%s)-1) > 0)) && unlikely(%s == (%s)-1)z]else if (sizeof(%s) == sizeof(long) && %s  && unlikely(__Pyx_UNARY_NEG_WOULD_OVERFLOW(%s))) {zLPyErr_SetString(PyExc_OverflowError, "value too large to perform division");rP  r   ZCDivisionWarningrW  z$if (unlikely((%s < 0) ^ (%s < 0))) {z1__Pyx_cdivision_warning(%(FILENAME)s, %(LINENO)s))ZFILENAMEZLINENOr   zint %s;T)r  r  zif (unlikely(%s)) )rr  r   rp   rQ  r  r  r  r   r   r   rU  r   r   r   r  r!  r	   r   r   r   r   r  r  rk   r   Zfilename_cnameZlineno_cnameZset_error_inforv  rU  rV  )rU   r   Zin_nogilZ	zero_testZminus1_checkZtype_of_op2Zwarning_coder_  rQ   rQ   rR   rX  d2  sz   





#z!DivNode.generate_div_warning_codec              	   C   s   | j js|  rt| S | j }| j }| j jr)| j	dkr)d| d| dS | j
s/| jrU| j
rL| j | jj kr?| j |}| j | jj krL| j |}d| d| dS | j }d| j   d| d| dt|dd	S )	Nr  zfloor(z / r  r  Z
__Pyx_div_r>  r  )r   r  r  r%  r   r  r   r  r  r	   rG  rL  r  r   specialization_namer.  rU   rI  rJ  Zb_is_constantrQ   rQ   rR   r   2  s   



*zDivNode.calculate_result_code)rX   rY   rZ   rL  rG  rM  rP  rQ  rK  r  r  rN  r   r  rq  r  rU  r{  rX  r   r[   rQ   rQ   rO   rR   rF  1  s$    	?rF  s'   %(?:%|(?:\([^)]+\))?[-+#,0-9 ]*([a-z]))>      g   i   o   b   u   a   x   c   e   E   F   f   X   G   dc                       sP   e Zd Zdd Z fddZdd Zdd Zd	d
 Zdd Z fddZ	  Z
S )ModNodec                 C   r2  rJ   )rw  r%  r  r  rQ   rQ   rR   r  2  r3  zModNode.is_py_operation_typesc                    s6   |t ttfv r|js|jr| j s|S t ||S rJ   )	r   r   r   r  rp   r  r  rL   r  r  rO   rQ   rR   r  2  s   z%ModNode.infer_builtin_types_operationc                 C   rS  )NrT  zfloat divmod()r0  rT   rQ   rQ   rR   rU  2  rV  zModNode.zero_division_messagec                 C   s`   t | |}| jjs.| jd u r|jd p| jj | _| js.| jjs.| jjs.t	| j
d| j  |S )NrL  z(mod operator not supported for type '%s')rF  rq  r   rp   rL  rk   r!  r  r  r   r   rR  rQ   rQ   rR   rq  2  s   
zModNode.analyse_operationc                 C   sr   | j js,| js,| j jr|jtdd| j  n|jtddj| j | j j	d t
| | | | d S )NZModIntrW  ZModFloat)math_h_modifier)r   rp   rL  r  r   r   r   r   rF  rl  r%  r{  rX  rm  rQ   rQ   rR   r{  2  s   
z ModNode.generate_evaluation_codec              	   C   s   | j  }| j }| jr(| jjrd| jj d| d| dS d| d| dS | j }d| j  d| d| dt	|dd	S )Nfmodr  r>  r  z % Z
__Pyx_mod_r  )
r  r   r  rL  r   r  rl  r   rZ  r.  r[  rQ   rQ   rR   r   2  s   


*zModNode.calculate_result_codec                    s\   | j j| jj}}|tu r(| j  s$|jr||s$|tu r&t| jt	s&dS dS t
 |S )NZ__Pyx_PyUnicode_FormatSafeZPyUnicode_Format)r  r   r  r   r  r  r  r   r}   r  rL   r  )rU   r   r  r  rO   rQ   rR   r  3  s   
zModNode.py_operation_function)rX   rY   rZ   r  r  rU  rq  r{  r   r  r[   rQ   rQ   rO   rR   rk  2  s    rk  c                       st   e Zd ZdZdZdd Z fddZ fddZd	d
 Zdd Z	 fddZ
dd Z fddZ fddZ  ZS )PowNodeNFc                 C   s   | j d urd S |jd | _ d S )NZcpow)is_cpowrk   r   rQ   rQ   rR   _check_cpow3  s   
zPowNode._check_cpowc                       |  | t |S rJ   )rp  rL   r   r   rO   rQ   rR   r   3     
zPowNode.infer_typec                    rq  rJ   )rp  rL   r"  r   rO   rQ   rR   r"  3  rr  zPowNode.analyse_typesc                 C   r   rJ   rQ   r  rQ   rQ   rR   r  "3  r  z%PowNode.infer_builtin_types_operationc                 C   s  t | | | jjr5| jjjr*| j| j|| _| j| j|| _| j	d| _
d S t| jd d| _
d S | jjrBd| jj | _
d S | jjrmd| j dd | _
|tdd	j| j
| j | jjrfd
pgdd d S | jjst| jd| jj| jjf  d S d S )Nr  z complex int powers not supportedr  powz__Pyx_pow_%srv  r4  ZIntPowrW  r)   r   )r  r   r!  z1got unexpected types for C power operator: %s, %s)r%  r  r   r  r  r  r  r  r  r/  pow_funcr   r   rl  r  r  rz  r   r   r   rF  r!  r  r   rQ   rQ   rR   r  &3  s0   


zPowNode.analyse_c_operationc                    s,  ddl m} d }t| jj|o| jjdkp|jo|jdk}|jp5| j o5t| jj|o5t	| jj| jjk}d}| j
rUt ||}| j sTt| jjt	oS| jjdk }n6|sY|rt ||}| j sq|joj|j}|rpd| _nt| jjt	o}| jjdk }n| ||rtj}d| _|rt|tj}|S )Nr   )RealFT)numbersru  r}   r  r~   r  r!  r  r   r   ro  rL   r  type_was_inferredr)  r   r  rX  rn  )rU   r  r  ru  Zc_result_typeZop1_is_definitely_positiveZtype2_is_intZneeds_wideningrO   rQ   rR   r  =3  sF   



zPowNode.compute_c_result_typec                    s(    fdd}d j | j| jf S )Nc                    s$    j | j kr
|  S  j |  S rJ   )r   r   r  r  rT   rQ   rR   r/   i3  s   z/PowNode.calculate_result_code.<locals>.typecastr  )rt  r  r  )rU   r/   rQ   rT   rR   r   g3  s   zPowNode.calculate_result_codec                    s\   | j jr(| jjdkr(t| jjtr(| jj tu r(|j	t
dd | jr&dS dS t |S )Nr4   ZPyNumberPow2r  Z__Pyx_PyNumber_InPlacePowerOf2Z__Pyx_PyNumber_PowerOf2)r   rp   r  r~   r}   r   r  r   r   r   r   r   r  rL   r  rm  rO   rQ   rR   r  s3  s   zPowNode.py_operation_functionc           	         s   || j kr| S | jd u rh| jrh|js|jrh| j tju r%d	 fdd	 d}n|jr/dd  d}ndd   | j\}} | j\}}|rh|rht	| j
d|  d| _|| _|| _| |}|j |krf|||}|S t ||S )
NTc                    s>   | j js| j jrd| fS |rt| tr | jdd| jfS dS )NTF)recurser  )r   r  r  r}   r  r   )r  ry  check_typesrQ   rR   r{  3  s
   z&PowNode.coerce_to.<locals>.check_typesza non-complex C numeric typec                 S   s   | j jrd| fS dS )NTr  r0  rx  rQ   rQ   rR   r{  3  s   zan integer C numeric typec                 S   rS   )Nr  rQ   rx  rQ   rQ   rR   r{  3  rW   zTreating '**' as if 'cython.cpow(True)' since it is directly assigned to a %s. This is likely to be fragile and we recommend setting 'cython.cpow' explicitly.rN  )r   ro  rw  r  r  r   r  r  r  r   r   r"  r  rL   )	rU   r  rs   Z
msg_detailZ	check_op1rI  Z	check_op2rJ  r   rO   rz  rR   r  3  s8   


zPowNode.coerce_to)rX   rY   rZ   ro  rw  rp  r   r"  r  r  r  r   r  r  r[   rQ   rQ   rO   rR   rn  3  s    *rn  c                   @   s   e Zd ZdZddgZdZdZdZdZdd Z	dd	 Z
d
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdZdd  Zd!d" Zd#d$ Zd%d& ZdS )'BoolBinopNodeag  
    Short-circuiting boolean operation.

    Note that this node provides the same code generation method as
    BoolBinopResultNode to simplify expression nesting.

    operator  string                              "and"/"or"
    operand1  BoolBinopNode/BoolBinopResultNode   left operand
    operand2  BoolBinopNode/BoolBinopResultNode   right operand
    r  r  TNc                 C   s$   | j |}| j|}t||S rJ   )r  r   r  r   independent_spanning_typer(  rQ   rQ   rR   r   3  s   zBoolBinopNode.infer_typec                 C   s(   | j dkr
| j S | j p| j S )Nor)r	   r  r  r  rT   rQ   rQ   rR   r  3  s   

zBoolBinopNode.may_be_nonec                 C   s6   | j j}| jj}| jdkr|o|| _d S |p|| _d S Nand)r  r~   r  r	   )rU   r  r  rQ   rQ   rR   r  3  s
   
z'BoolBinopNode.calculate_constant_resultc                 C   s2   | j |}| j|}| jdkr|o|S |p|S r  )r  r  r  r	   )rU   r  r  r  rQ   rQ   rR   r  3  s
   
z BoolBinopNode.compile_time_valuec                 C      | j  p	| j S rJ   )r  r   r  rT   rQ   rQ   rR   r   3  r  zBoolBinopNode.is_ephemeralc                 C   sJ   | j |}| j|}t|j|j| _| ||| _ | ||| _| S rJ   )r  r"  r  r   r}  r   _wrap_operandrC  rQ   rQ   rR   r"  3  s   zBoolBinopNode.analyse_typesc                 C   s    t |ttfst|| j|}|S rJ   )r}   r|  BoolBinopResultNoder   )rU   r  rs   rQ   rQ   rR   r  3  s   zBoolBinopNode._wrap_operandc                 C   s$   |  | j|| _|  | j|| _dS )z
        Must get called by transforms that want to create a correct BoolBinopNode
        after the type analysis phase.
        N)r  r  r  r   rQ   rQ   rR   wrap_operands3  s   zBoolBinopNode.wrap_operandsc                 C   r  rJ   r  r   r  r   rQ   rQ   rR   r-  3  rL  zBoolBinopNode.coerce_to_booleanc                 C   s2   | j ||}| j||}tj| || j||dS )N)r   r	   r  r  )r  r  r  r|  r  r	   )rU   r  rs   r  r  rQ   rQ   rR   r  3  s   zBoolBinopNode.coerce_toc           
   	   C   s   | | j ||f}| jdkr|d }	}n|d }	}| j|||||||	 |\}}||	 | j||||||| d S )Nr  Znext_andZnext_or)ru  r   r	   rT  r  generate_bool_evaluation_coderX  r  )
rU   r   final_result_tempfinal_result_type	and_labelor_label	end_labelfall_throughZouter_labelsZmy_labelrQ   rQ   rR   r  3  s   

z+BoolBinopNode.generate_bool_evaluation_codec              	   C   sX   |  | | jjrtjn| j}d  }}|d}| ||  ||||| || d S )NZbool_binop_done)	re  r   rp   r   r   rT  r  r   rX  )rU   r   r  r  r  r  rQ   rQ   rR   r{  4  s   

z&BoolBinopNode.generate_evaluation_codeTruth-testing Python objectc                 C   r  rJ   r  rT   rQ   rQ   rR   r#  4  r  zBoolBinopNode.check_constc                 C   r   rJ   rQ   rm  rQ   rQ   rR   ry  4  rW   z,BoolBinopNode.generate_subexpr_disposal_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rz   4  rW   z BoolBinopNode.free_subexpr_tempsc              	   C   sV   | j jr |jjtjdd}|d|| j |	|| j
f  n| j }|| j jfS NFr]  "%s = __Pyx_PyObject_IsTrue(%s); %s)r   rp   rb  rc  r   r  r   r  r   rs  r   r   rU   r   test_resultrQ   rQ   rR   generate_operand1_test#4  s   
z$BoolBinopNode.generate_operand1_test)rX   rY   rZ   r$  r   r   r	   r  r  r   r  r  r  r   r"  r  r  r-  r  r  r{  r  r#  ry  rz  r  rQ   rQ   rQ   rR   r|  3  s0    
r|  c                       sd   e Zd ZdZddgZdZdZdZ fddZdd	 Z	d
d Z
dd Zdd Zdd Zdd Z  ZS )r  a  
    Intermediate result of a short-circuiting and/or expression.
    Tests the result for 'truthiness' and takes care of coercing the final result
    of the overall expression to the target type.

    Note that this node provides the same code generation method as
    BoolBinopNode to simplify expression nesting.

    arg     ExprNode    the argument to test
    value   ExprNode    the coerced result value node
    r   r   TNc                    s8   | |}t|}t j|j||t|||d d S )N)r   r   r   )r0  	ProxyNoderL   r  r   r  r  )rU   r   r  rs   rO   rQ   rR   r  D4  s   

zBoolBinopResultNode.__init__c                 C   r  rJ   r  r   rQ   rQ   rR   r-  M4  rL  z%BoolBinopResultNode.coerce_to_booleanc                 C   s(   | j j }|tju r||}t|||S rJ   )r   r   r  r-  r  )rU   r  rs   r   rQ   rQ   rR   r  P4  s   

zBoolBinopResultNode.coerce_toc                 C   r   rJ   rQ   r   rQ   rQ   rR   rO  X4  r  zBoolBinopResultNode.nogil_checkc              	   C   sZ   | j jjr!|jjtjdd}|d|| j  |	|| j
f  n| j  }|| j jjfS r  )r   r   rp   rb  rc  r   r  r   r   rs  r   r   r  rQ   rQ   rR   generate_operand_test\4  s   

z)BoolBinopResultNode.generate_operand_testc                 C   sz  | | j | j| |s|rk| |\}}	|	r#|r#|r#| j| |r'dnd}
|d|
|f  |	r:|j| |	r@|r@|sF| j| |rQ||krQ|	| |rk|rb|d |	sb| j| ||krk|	| |ro|s|ss|rx|d | j
| | j
| |d|| j
|f  | j
| | j| | j
| ||kr|	| |s|r|d | j| d S )Nr  r  zif (%s%s) {rm  r  r   )ru  r   r   r{  r  r  r   rb  rj  rU  r   rn  r   r  r  )rU   r   r  r  r  r  r  r  r  Z	uses_tempZsenserQ   rQ   rR   r  j4  sF   





z1BoolBinopResultNode.generate_bool_evaluation_codec                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  4  rW   z!BoolBinopResultNode.analyse_types)rX   rY   rZ   r$  r   r   r   r   r  r-  r  rO  r  r  r"  r[   rQ   rQ   rO   rR   r  24  s    	7r  c                       s   e Zd ZdZdZdZg dZdd Zdd Zdd	 Z	d
d Z
dd Zdd Z fddZ fddZdd Zdd Zdd Zdd Zdd Zdd Z  ZS ) r  NT)r  r  r  c                 C   r  rJ   )r  r3  r  r   rQ   rQ   rR   r3  4  r  zCondExprNode.type_dependenciesc                 C   s   t | j|| j|S rJ   )r   r}  r  r   r  r   rQ   rQ   rR   r   4  s   

zCondExprNode.infer_typec                 C   s$   | j jr| jj| _d S | jj| _d S rJ   )r  r~   r  r  rT   rQ   rQ   rR   r  4  rB  z&CondExprNode.calculate_constant_resultc                 C   r  rJ   )r  r   r  rT   rQ   rQ   rR   r   4  r  zCondExprNode.is_ephemeralc                 C   s4   | j || _ | j|| _| j|| _| |S rJ   )r  r1  r  r"  r  r  r   rQ   rQ   rR   r"  4  s   
zCondExprNode.analyse_typesc                 C   s   | j j}| jj}t||| _| jjrt| jj| _| jjr#t	| _
n| jjr?| j  r3t| j jd | j r?t| jjd |jsI|jsI| jjre|| jkrW| j | j|| _ || jkre| j| j|| _| jjrm|   | S )NzPUnsafe C derivative of temporary Python reference used in conditional expression)r  r   r  r   r}  r   r  r  rp   r   r  r  r   r   r   r  r  r  )rU   rs   Ztrue_val_typeZfalse_val_typerQ   rQ   rR   r  4  s(   



z CondExprNode.analyse_result_typec                    sr   | j jjs| j || _ | jjjs| j|| _d | _| |}|jjs7|| u r2tt||}|S ||}|S rJ   )	r  r   r  r  r  r  r  rL   r  )rU   rs   outrO   rQ   rR   r  4  s   



zCondExprNode.coerce_to_indexc                    s   | j j|kr| j ||| _ | jj|kr| j||| _d | _| |}|j|kr>|| u r8tt|||}|S |||}|S rJ   )r  r   r  r  r  r  rL   r  )rU   r  rs   r  rO   rQ   rR   r  4  s   

zCondExprNode.coerce_toc                 C   s<   | j jjs| jjjst| jd| j j| jjf  tj| _d S )Nz5Incompatible types in conditional expression (%s; %s))r  r   r  r  r   r   r   r0   rT   rQ   rQ   rR   r  5  s
   zCondExprNode.type_errorc                 C   s   | j  o| j o| j S rJ   )r  r#  r  r  rT   rQ   rQ   rR   r#  
5  s
   
zCondExprNode.check_constc                 C   s   | | j | | | j| |d| j   | || j |d | || j	 |d | j
| | j| d S )Nr  rm  r   )ru  r   re  r  r{  r   r   eval_and_getr  r  r  r  rm  rQ   rQ   rR   r{  5  s   


z%CondExprNode.generate_evaluation_codec                 C   s`   | | | jjr|| n|| |d|  ||  f  |	| |
| d S rt  )r{  r   r   rs  rn  r   r   r   r  r  r  )rU   r   r{  rQ   rQ   rR   r  5  s   

 
zCondExprNode.eval_and_getc                 C   r   rJ   rQ   rm  rQ   rQ   rR   ry  (5  rW   z+CondExprNode.generate_subexpr_disposal_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rz  +5  rW   zCondExprNode.free_subexpr_temps)rX   rY   rZ   r  r  r   r   r3  r   r  r   r"  r  r  r  r  r#  r{  r  ry  rz  r[   rQ   rQ   rO   rR   r  4  s&    
r  ZPy_LTZPy_LEZPy_EQZPy_NEZPy_GTZPy_GE)	r  r  r  r  z<>r  r  r  r  c                   @   s   e Zd ZdZdZg Zdd Zdd Zdd Zdd	 Z	d
d Z
d!ddZdd Zdd Zdd Zdd Zdd Zdd Zd"ddZdd Zdd  ZdS )#CmpNodeNc                 C   r/  rJ   r  r   rQ   rQ   rR   r   D5  r  zCmpNode.infer_typec                 C   s   t | j }| jj}t|trt|trt|t|krd S | jdv rYt| jttt	frG| jj
s7| jdk| _d S t| jtrF| jsF| j | _nt| jtrY| jjsY| jdk| _d S |||| _d S )Nr  r  r  )r  r	   r  r~   r}   any_string_typer   r  r1  r  r   cascader  r  r  )rU   Zoperand1_resultrd  Zoperand2_resultrQ   rQ   rR   "calculate_cascaded_constant_resultH5  s(   


z*CmpNode.calculate_cascaded_constant_resultc              
   C   sx   t | }| j|}z|||}W n ty* } z| | d }W Y d }~nd }~ww |r:| j}|r:|o9|||}|S rJ   )r  r  r  r  r  r  cascaded_compile_time_value)rU   r  r  rd  r  r   r  r  rQ   rQ   rR   r  `5  s   
z#CmpNode.cascaded_compile_time_valuec                 C   r  rJ   r  rT   rQ   rQ   rR   is_cpp_comparisonn5  r  zCmpNode.is_cpp_comparisonc           	      C   s   |j }|j }d}d}|jr| rd}|jr| rd}|jr%|r#|S d S |jr.|r,|S d S |r?|r?tj||fv r<tjS tjS d S r  )	r   r   r   r  r   r   r   r   r   )	rU   rs   rh  r  r  r  r  Ztype1_can_be_intZtype2_can_be_intrQ   rQ   rR   find_common_int_typeq5  s,   zCmpNode.find_common_int_typec           	      C   s  | j }|j}|j}d }|js|jrO|dvr*|js|jr*|js!|jr*t| jd t}nA|jr9|t	j
r6t	j
nt}n2|jrH|t	j
rEt	j
nt}n#t||}n|jr\|jr\t||}n|d u sc|jsk| ||||}|d u r|jsu|jrxt}na||kr|}nZ|js|jr|js|jr|||rt}nEt}nB|js|jr|||rt}n3t}n0t|rt|rt}n#| ||| t}n||r|}n||r|}n	| ||| t}|jrt|tst|trt}|d u s|jr|}nt||}| jr| j|| j||}|S )Nr  r  zcomplex types are unordered)r  r   r  r]  r   r   r0   rp   r  r   r  r   r   rX  r  r  rw  r  r  invalid_types_errorr}   r9  r   r  Zspanning_typer  find_common_typer	   )	rU   rs   rh  r  common_typer  r  r  Znew_common_typerQ   rQ   rR   r  5  sv   

zCmpNode.find_common_typec                 C   s   t | jd||j|jf  d S )NInvalid types for '%s' (%s, %s))r   r   r   )rU   r  rh  r  rQ   rQ   rR   r  5  s   
zCmpNode.invalid_types_errorc                 C   s6   |    o|   o|  p| jo| j p| jdv S Nr  )is_ptr_containsis_c_string_containshas_python_operandsr  is_python_comparisonr	   rT   rQ   rQ   rR   r  5  s   
zCmpNode.is_python_comparisonc                 C   s:   | j }|j|kr|||| _ | jr| j|| d S d S rJ   )r  r   r  r  coerce_operands_to)rU   r  rs   r  rQ   rQ   rR   r  5  s   
zCmpNode.coerce_operands_toc                 C   s@   |   r| jd u r| jdvr|   r|   p| jo| j S )N)r  r  r  r  )r  special_bool_cmp_functionr	   r  r  r  is_python_resultrT   rQ   rQ   rR   r  5  s   zCmpNode.is_python_resultc                 C   s@   | j dv o| jjjr| jjjp| jjtu p| jjjo| jjtu S r  )	r	   r  r   r  r  rw  r   r  r   rT   rQ   rQ   rR   r  5  s   



zCmpNode.is_c_string_containsc                 C   s*   | j dv r| jj}|js|jo|j S d S r  )r	   r  r   r  r6  rw  )rU   container_typerQ   rQ   rR   r  5  s   
zCmpNode.is_ptr_containsFc           	      C   s  | j dv ri|j| jj}}|s|jrg|jrg|tju s|tju r+tdd| _d| _	dS |tj
u s5|tj
u rAtdd| _d| _	dS |rgdd	lm} || j d
krQdnd| tj|| j}|rg|\| _	| _| _}dS dS | j dv r| jjtju r| jd| _tdd| _d| _	dS | jjtju r| jd| _tdd| _d| _	dS | jjtju r| jd| _tdd| _d| _	dS | jjjs| j|| _tdd| _d| _	dS dS )Nr  ZUnicodeEqualsr  Z__Pyx_PyUnicode_EqualsTZBytesEqualsZ__Pyx_PyBytes_Equalsr)   )optimise_numeric_binopr  EqZNer  r^  ZPyDictContainsr  Z__Pyx_PyDict_ContainsTFZPySetContainsZ__Pyx_PySet_ContainsTFZPyUnicodeContainsZ__Pyx_PyUnicode_ContainsTFZPySequenceContainsZ__Pyx_PySequence_ContainsTFF)r	   r   r  r  r   r   r   r   special_bool_cmp_utility_coder  r   ZOptimizer  r   r  special_bool_extra_argsr   r  r   rp   r  )	rU   rs   r  result_is_boolr  r  r  r   r4  rQ   rQ   rR   "find_special_bool_compare_function 6  sd   


z*CmpNode.find_special_bool_compare_functionc                 C   s\  | j jr|j}d| }| jr|jtdd d}n
d}n|j}d}d}| jrt|j jr1|	 }	n|
 }	|j jr>|	 }
n|
 }
ddd	 | jD }| jrW|j| j |d
||| j|	|
| jre|nt| |||| jf  d S |j jr|dvr|dvsJ || j js| j tju sJ |d|| j jrdnd|	 |	 t| |||| jf  d S |j jr|d|||dkrdpd|j d|
 |
 f  d S |j }|j }|js|jr||st}n|jrt||}n|}||}||}d|||| ||f }|  r'| jdkr't|| j|| j jr|nd | j| j  d S || d S )Nz__Pyx_XGOTREF(%s); ZPyBoolOrNullFromLongr  Z__Pyx_PyBoolOrNull_FromLongZ__Pyx_PyBool_FromLongr  r>  c                 S   r@  rQ   r9  )ra   	extra_argrQ   rQ   rR   r   M6  s    z3CmpNode.generate_operation_code.<locals>.<listcomp>z%s = %s(%s(%s, %s, %s)); %s%s)r  r  r  z-%s = PyObject_RichCompare%s(%s, %s, %s); %s%sZBoolz%s = %s(%s%s(%s, %s));r  r  eqz%s = %s(%s %s %s);r   )!r   rp   r   r  r   r   r   r   rs  r   r   rA  r  r  r   richcmp_constantsr   r   r  r  r  r  r  r   r]  rX  r   
c_operatorr  r   r   r   rr  )rU   r   r_  r  rh  r  Zerror_clauseZgot_refZcoerce_resultr0  r1  Zspecial_bool_extra_args_resultr  r  r  code1code2Z	statementrQ   rQ   rR   r  46  s   






	
	

zCmpNode.generate_operation_codec                 C   s   |dkrdS |dkrdS |S )Nr  r  r  r  rQ   )rU   rh  rQ   rQ   rR   r  6  s
   zCmpNode.c_operatorrJ   r  )rX   rY   rZ   r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  rQ   rQ   rQ   rR   r  <5  s&    
M
4Zr  c                   @   s   e Zd Zg dZdZdZdZdd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# ZdS )$r  )r  r  coerced_operand2r  r  NFc                 C   sN   | j |}| j|}t|st|r%t|r%t|r%tt| j||S tS rJ   )	r  r   r  r;   r9   rG   r=   r	   r   r(  rQ   rQ   rR   r   6  s   zPrimaryCmpNode.infer_typec                 C   rS   r  rQ   r   rQ   rQ   rR   r3  6  rW   z PrimaryCmpNode.type_dependenciesc                 C   s   | j rJ | | jj d S rJ   )r  r  r  r~   rT   rQ   rQ   rR   r  6  r  z(PrimaryCmpNode.calculate_constant_resultc                 C   s   | j |}| ||S rJ   )r  r  r  )rU   r  r  rQ   rQ   rR   r  6  s   z!PrimaryCmpNode.compile_time_valuec                 C   s$   | j }|r| j|_|j }|sd S d S rJ   )r  r   )rU   ZcdrrQ   rQ   rR   unify_cascade_type6  s
   z!PrimaryCmpNode.unify_cascade_typec                 C   s  | j || _ | j|| _|  r"| | | jr t| jd | S | j j}| jj}t	|s2t	|rIt
|rIt
|rItt| j||| _d| _| S | |rP| S | jrZ| j|| _| jdv r|  rd| _d }| jrst| jd | S | jjtu r|tdd n'| j jtju r| j tj|| _ | jjtur| jt|| _|tdd | jd| _nX|  r| jrt| jd	 tj| _| S | || j r| j jjs| j || _ d }d| _n,t }d
| _n&| || j r| j jjs| j || _ d }d| _n| !|| j| j }|j| _|d ur(|j"s(| j j|kr"| j ||| _ | #|| | jrJ| j$|| _| j%| | j&| j|}|| jurJ|| _'| ( rTtj | _ntj| _| )  | jsh| jsh| j*rkd| _+| S )Nz5Cascading comparison not yet supported for cpp types.Fr  z?Cascading comparison not yet supported for 'int_val in string'.ZPyUCS4InUnicoder  ZBytesContainsz+argument of type 'NoneType' is not iterablez?Cascading comparison not supported for 'val in sliced pointer'.Tr)   ),r  r"  r  r  analyse_cpp_comparisonr  r   r   r   r;   r9   rG   r=   r	   is_pycmp"analyse_memoryviewslice_comparisonr  r   r   r   r   r   r   r  r   r   r  r  r  r  rp   r  r   r  r  r  r0   coerce_cascaded_operands_to_tempoptimise_comparisonr  r  r  r  r   )rU   rs   r  r  r  r  rQ   rQ   rR   r"  6  s   






zPrimaryCmpNode.analyse_typesc                 C   s  | j j}| jj}d| _|| j| j | jg}|d u r/t| jd| j||f  tj	| _d| _
d S |j}|jr8|j}|j| _|j| _| jdkrUd| _t| rU|tdd t|jdkri| j|jd	 j|| _n| j |jd	 j|| _ | j|jd j|| _|j| _d S )
NFr  r  r   Tr%  r  r)   r   )r  r   r  r  r  r	   r   r   r   r0   r_  r  r  r   r   r   r   r   r   r   r   r   r  rf  )rU   rs   r  r  r   r&  rQ   rQ   rR   r  7  s2   

z%PrimaryCmpNode.analyse_cpp_comparisonc                 C   sV   | j jp| jj}| j jjp| jjj}d}|r)|r)| j|v r)d| _tj| _d| _	dS dS )N)r  r  r  r  FT)
r  r   r  r   r   r	   r  r   r  is_memslice_nonecheck)rU   rs   Z	have_noneZ
have_sliceopsrQ   rQ   rR   r  67  s   
z1PrimaryCmpNode.analyse_memoryviewslice_comparisonc                 C   sn   | j r1| j|| jddr1d| _ tj| _d| _| jr+| jj| j	|dd}|| j	ur+|| _
|   | S t| |S )NT)r  Fr)   )r  r  r  r   r  r   r   r  r  r  r  r  r   r-  )rU   rs   r  rQ   rQ   rR   r-  C7  s    
z PrimaryCmpNode.coerce_to_booleanc                 C   r  rJ   )r  r   rp   r  rT   rQ   rQ   rR   r  U7  r  z"PrimaryCmpNode.has_python_operandsc                 C   s&   | j r	|   dS | j o| j S rR  )r  rS  r  r#  r  rT   rQ   rQ   rR   r#  Y7  s   zPrimaryCmpNode.check_constc                 C   s   | j | j}}|jjr%| jdkrd}nd}d||jd| | f S |  rI|jtu r1d}nd}| jdkr;d}nd}d||| | f S t	| jrX|
 |
 }}n| | }}| jrq|jjrmd	| }nd	| }d
|| | j|f S )Nr  r  r  z(%s%s(%s, %s))r  Z__Pyx_UnicodeContainsUCS4Z__Pyx_BytesContainsr  ((PyObject *) %s.memview)r!  )r  r  r   r  r	   r/  r   r  r   r;   r   r  r   r  )rU   r  r  Znegationr  r0  r1  rQ   rQ   rR   r   `7  sH   






z$PrimaryCmpNode.calculate_result_codec                 C   s   | j | | j| | jD ]}|| q| jr]| | | ||  | j | j| j | j	rC| j	j||  | j
p<| j| j
d ud | j | | j | | j| | j| d S d S )Nneeds_evaluation)r  r{  r  r  r   re  r  r   r	   r  r  r  r  )rU   r   r  rQ   rQ   rR   r{  7  s&   

z'PrimaryCmpNode.generate_evaluation_codec                 C   r  rJ   )r  r  r  rm  rQ   rQ   rR   ry  7     z-PrimaryCmpNode.generate_subexpr_disposal_codec                 C   r  rJ   )r  r  r  rm  rQ   rQ   rR   rz  7  r  z!PrimaryCmpNode.free_subexpr_tempsc                 C   s2   | j | | j| | jr| j| d S d S rJ   )r  r  r  r  rm  rQ   rQ   rR   r  7  s
   zPrimaryCmpNode.annotate)rX   rY   rZ   r   r  r  r  r   r3  r  r  r  r"  r  r  r-  r  r#  r   r{  ry  rz  r  rQ   rQ   rQ   rR   r  6  s*    T*r  c                   @   s|   e Zd Zg dZdZdZeZdd Zdd Z	dd Z
d	d
 Zdd Zdd ZdddZdd Zdd ZdddZdd ZdS )CascadedCmpNode)r  r  r  r  Nc                 C   r/  rJ   r  r   rQ   rQ   rR   r   7  r  zCascadedCmpNode.infer_typec                 C   rS   r  rQ   r   rQ   rQ   rR   r3  7  rW   z!CascadedCmpNode.type_dependenciesc                 C   r  rJ   r	  rT   rQ   rQ   rR   r   7  r  z#CascadedCmpNode.has_constant_resultc                 C   s&   | j || _ | jr| j|| _| S rJ   )r  r"  r  r   rQ   rQ   rR   r"  7  s   zCascadedCmpNode.analyse_typesc                 C   
   | j jjS rJ   )r  r   rp   rT   rQ   rQ   rR   r  7  rM  z#CascadedCmpNode.has_python_operandsc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  7  r  z!CascadedCmpNode.is_cpp_comparisonFc                 C   sZ   |  |||rd| _tj| _|jjs||}| jr+| j| j	||}|| j	ur+|| _
|S rR  )r  r  r   r  r   rp   r  r  r  r  r  )rU   r  rs   r  r  rQ   rQ   rR   r  7  s   

z#CascadedCmpNode.optimise_comparisonc                 C   sL   | j || _ | j jtu r| jdv r| j d| _ | jr$| j| d S d S )Nr  r^  )r  r  r   r   r	   r  r  r  r   rQ   rQ   rR   r  7  s   z,CascadedCmpNode.coerce_operands_to_pyobjectsc                 C   s(   | j r| j|| _| j | d S d S rJ   )r  r  r0  r  r   rQ   rQ   rR   r  7  s   z0CascadedCmpNode.coerce_cascaded_operands_to_tempc                 C   s   | j jr|d|  ||| j  n|d|  |r!|| | j| | jD ]}|| q*| |||| j| j | j	rQ| j	j||| j
pJ| j| j
d ud |r]|| || | j| | j| |d d S )Nz if (__Pyx_PyObject_IsTrue(%s)) {r  r  r   )r   rp   r   r  r{  r  r  r  r	   r  r  r  r  )rU   r   r   r  r  r  rQ   rQ   rR   r{  7  s.   




z(CascadedCmpNode.generate_evaluation_codec                 C   s&   | j | | jr| j| d S d S rJ   )r  r  r  rm  rQ   rQ   rR   r  
8  s   zCascadedCmpNode.annotater  )rX   rY   rZ   r   r  r  r
  r~   r   r3  r   r"  r  r  r  r  r  r{  r  rQ   rQ   rQ   rR   r  7  s     


r  )r~  r  rT  r
  r  r  r	  r   ra  r   r  r   r  r  r  Fc                 K   s   t | | f||||d|S )N)r	   r  r  r  )binop_node_classes)r   r	   r  r  r  r  rQ   rQ   rR   r  #8  s   r  c                       s>   e Zd ZdgZeZ fddZdd Zdd Zdd	 Z	  Z
S )
rc  r   c                    s2   t  |j || _trtd| | jf  d S d S )Nz%s Coercing %s)rL   r  r   r   r   r  r  rO   rQ   rR   r  B8  s
   zCoercionNode.__init__c                 C   r   rJ   rQ   rT   rQ   rQ   rR   r  H8  r  z&CoercionNode.calculate_constant_resultc              	   C   s\   | j | | j j| jkr,| j\}}}||||d ftddd| j j| jf d d S d S )Nr)   Zcoercez[%s] to [%s])r%  tagr&  )r   r  r   r   r5   )rU   r   filelinecolrQ   rQ   rR   r  L8  s   zCoercionNode.annotatec                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  S8  rW   zCoercionNode.analyse_types)rX   rY   rZ   r   r  r~   r  r  r  r"  r[   rQ   rQ   rO   rR   rc  :8  s    rc  c                   @       e Zd ZdZdd Zdd ZdS )r  zc
    Coerce an object to a memoryview slice. This holds a new reference in
    a managed temp.
    c                 C   sJ   |j sJ |jj rJ t| | || _d| _d| _|| _| j| d S r  )r   r   rc  r  r   rd  r   r  rU   r   r  rs   rQ   rQ   rR   r  ]8  s   
z!CoerceToMemViewSliceNode.__init__c                 C   s(   | | j| j |  | j| d S rJ   )r   r   from_py_call_coder   r   r   r   rm  rQ   rQ   rR   rv  g8  s   

z-CoerceToMemViewSliceNode.generate_result_codeN)rX   rY   rZ   r$  r  rv  rQ   rQ   rQ   rR   r  W8  s    
r  c                   @   r  )
r  c                 C   r  rJ   )rc  r  r   )rU   r   new_typerQ   rQ   rR   r  s8  r  zCastNode.__init__c                 C   r  rJ   r  rT   rQ   rQ   rR   r  w8  rM  zCastNode.may_be_nonec                 C   s   | j | jS rJ   )r   r   r   rT   rQ   rQ   rR   r   z8  rL  zCastNode.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  }8  rW   zCastNode.generate_result_codeN)rX   rY   rZ   r  r  r   rv  rQ   rQ   rQ   rR   r  p8  s
    r  c                   @   s   e Zd ZdZd'ddZejZdZdd Z	dd	 Z
d
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&S )(r  TFc                 C   sT   |j s|jsJ d|j|f |jr||}t| | || _| | _|| _d S )Nz/PyTypeTest for %s against non extension type %s)	r  r  r   r  rc  r  r  r  r  )rU   r   r  rs   r  rQ   rQ   rR   r  8  s   


zPyTypeTestNode.__init__zPython type testc                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  8  rW   zPyTypeTestNode.analyse_typesc                 C   s   | j rdS | j S rR  )r  r   r  rT   rQ   rQ   rR   r  8  s   
zPyTypeTestNode.may_be_nonec                 C   r  rJ   r  rT   rQ   rQ   rR   r  8  rM  zPyTypeTestNode.is_simplec                 C   r  rJ   r  rT   rQ   rQ   rR   rX  8  rM  zPyTypeTestNode.result_in_tempc                 C   r  rJ   )r   r   rT   rQ   rQ   rR   r   8  rM  zPyTypeTestNode.is_ephemeralc                 C   r  rJ   r  rT   rQ   rQ   rR   r8  8  rM  z#PyTypeTestNode.nonlocally_immutablec                 C   r  rJ   )r   r  r   rQ   rQ   rR   r  8  r  zPyTypeTestNode.coerce_to_tempc                 C   sT   | j | jj ks| j s| S | j  s| S | j r'| jr'| jd| j j S | jS )Nz!Cannot convert NoneType to %.200s)r   r   rX  typeobj_is_availabler  r  r  rq   rT   rQ   rQ   rR   	reanalyse8  s   
zPyTypeTestNode.reanalysec                 C   r   rJ   rQ   rT   rQ   rQ   rR   r  8  r  z(PyTypeTestNode.calculate_constant_resultc                 C   r  rJ   r   rT   rQ   rQ   rR   r   8  rM  z$PyTypeTestNode.calculate_result_codec                 C   s   | j  st| jd d S | j }| j j}| jr)|r)| j || j| j	 | d S | j j
|jj| j	 ||r9| jndd}|jt|rFdndd |d| d|| j  d S )	NzICannot test type of extern C class without type object name specificationF)exactZRaiseUnexpectedTypeErrorZExtTypeTestr  zif (!(z)) )r   r  r   r   r  r  r  Zconvert_to_basetyper   r   Ztype_test_coderb  r  r   r   r   r   r   r   )rU   r   r  r  Z	type_testrQ   rQ   rR   rv  8  s&   



"z#PyTypeTestNode.generate_result_codec                 C   r!  rJ   r"  rm  rQ   rQ   rR   r  8  r   z,PyTypeTestNode.generate_post_assignment_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   re  8  rW   z#PyTypeTestNode.allocate_temp_resultc                 C   r   rJ   rQ   rm  rQ   rQ   rR   rk  8  rW   z"PyTypeTestNode.release_temp_resultc                 C   r!  rJ   r#  rm  rQ   rQ   rR   r  8  r   zPyTypeTestNode.free_tempsc                 C   r!  rJ   )r   rz  rm  rQ   rQ   rR   rz  8  r   z!PyTypeTestNode.free_subexpr_tempsNr  )rX   rY   rZ   r  r  r,   rN  rO  r  r"  r  r  rX  r   r8  r  r  r  r   rv  r  re  rk  r  rz  rQ   rQ   rQ   rR   r  8  s*    

r  c                       s|   e Zd ZdZdZ	d fdd	ZdZdd Zdd	 Zd
d Z	dd Z
e	dddZe	dddZdd Zdd Z  ZS )r  TNrQ   c                    s@   t  |j| |j| _| | _|| _|| _t|pd| _	d S r  )
rL   r  r   r   r  r  exception_type_cnameexception_messager   exception_format_args)rU   r   r  r  r  rO   rQ   rR   r  8  s   
zNoneCheckNode.__init__c                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  8  rB  zNoneCheckNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  9  rW   zNoneCheckNode.may_be_nonec                 C   r  rJ   )r   r  rT   rQ   rQ   rR   r  9  rM  z"NoneCheckNode.may_be_unsafe_sharedc                 C   s0   | j jr	| j S | j jrd| j  S td)Nr  zunsupported type)r   rp   r   r   r   r   r  rT   rQ   rQ   rR   	condition	9  s
   
zNoneCheckNode.conditionr  Fc                 C   s"   | ||||}||_ || d S rJ   )rr  put_nonecheck)rN   r   r   r  r  r  rr  r   rQ   rQ   rR   generate9  s   zNoneCheckNode.generatec                 C   s$   |  r| |||||| d S d S rJ   )r  r  )rN   r   r   r  r  r  rr  rQ   rQ   rR   generate_if_needed9  s   z NoneCheckNode.generate_if_neededc              
      s   | d|    | jr|  tj | jr4| d| jt| j	dd
 fdd| jD f  n| d| j | j	df  | jrK|  | || j | d d S )	Nzif (unlikely(%s == Py_None)) {zPyErr_Format(%s, "%s", %s);UTF-8r>  c                    s"   g | ]}d  t |d qS )z"%s"r  )rw   r  r   escaperQ   rR   r   +9  s    z/NoneCheckNode.put_nonecheck.<locals>.<listcomp>zPyErr_SetString(%s, "%s");r   )r   r  rr  r   r   Zescape_byte_stringr  r  r  r  rA  r   r   r   rm  rQ   r  rR   r  9  s0   


zNoneCheckNode.put_nonecheckc                 C   rJ  rJ   )r  rm  rQ   rQ   rR   rv  89  rL  z"NoneCheckNode.generate_result_code)rQ   )r  rQ   F)rX   rY   rZ   rY  r   r  rO  r"  r  r  r  r  r  r  r  rv  r[   rQ   rQ   rO   rR   r  8  s$    	r  c                   @   sP   e Zd ZeZeZdZefddZdZdd Z	dd Z
d	d
 Zdd Zdd ZdS )r  r)   c                 C   s   |j |st|jd|j   n	|j jr||}t| | |tu rK|j j	s+|j j
r1t|| _ n|j js9|j jr=t| _ n|j jrEtj| _ | j | _d S |j j	sS|j j
rq|ttfvri|jd sit|jd|j |f  | | _ | _d S || _d S )Nz$Cannot convert '%s' to Python objectr_   r  )r   r"  r   r   r  r0  rc  r  r   rw  r  rz   rx  r  r   r   r  target_typer   r   rk   )rU   r   rs   r   rQ   rQ   rR   r  D9  s0   

zCoerceToPyTypeNode.__init__zConverting to Python objectc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  c9  r  zCoerceToPyTypeNode.may_be_nonec                 C   sb   | j j}|tju s|tju r| j |S |jrt| j |S |j	s&|j
s&|jr,t| j |S t| |S rJ   )r   r   r   r  r   r>  r  rw  CoerceCStringToBooleanNoder  r  r  r  )rU   rs   r}  rQ   rQ   rR   r-  g9  s   
z$CoerceToPyTypeNode.coerce_to_booleanc                 C   r  rJ   )r   r  r   rQ   rQ   rR   r  w9  r  z"CoerceToPyTypeNode.coerce_to_indexc                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  z9  r  z CoerceToPyTypeNode.analyse_typesc                 C   sH   | d| jj| j |  | j||  | jf  | | d S )Nz%s; %s)	r   r   r   Zto_py_call_coder   r  r   r   r  rm  rQ   rQ   rR   rv  ~9  s   z'CoerceToPyTypeNode.generate_result_codeN)rX   rY   rZ   r   r   r  r   r  r  r  r-  r  r"  rv  rQ   rQ   rQ   rR   r  <9  s    r  c                   @   r  )r  r)   c                 C   s"   | |}t| | tj| _d S rJ   )r0  rc  r  r   r   r   rU   r   rs   rQ   rQ   rR   r  9  s   
zCoerceIntToBytesNode.__init__c              	   C   s   | j }| }|jtjtjtjfvr7|jjr |d||f  n|d|  |d|	| j
  |d d }|jtjurS|jjtjdd}|d||f  |}|d|  |||  | j
f  |d urp|j| | | d S )	Nzif ((%s < 0) || (%s > 255)) {zif (%s > 255) {zOPyErr_SetString(PyExc_OverflowError, "value too large to pack into a byte"); %sr   Fr]  z%s = (char)%s;z*%s = PyBytes_FromStringAndSize(&%s, 1); %s)r   r   r   r   r   r   rL  r!  r   r   r   rb  rc  r   rj  r  )rU   r   r   Z
arg_resultrl  rQ   rQ   rR   rv  9  s8   


z)CoerceIntToBytesNode.generate_result_codeN)rX   rY   rZ   r   r  rv  rQ   rQ   rQ   rR   r  9  s    r  c                   @   r  )r  Nc                 C   s   t | | || _d| _||st|jd|  | jjs!| jjrF| j	j
r8| j	jr8| j	jjr8t|jd| dd | jjrHt|jddd d S d S d S )Nr)   z$Cannot convert Python object to '%s'z=Obtaining '%s' from externally modifiable global Python valuer{   a  Py_UNICODE* has been removed in Python 3.12. This conversion to a Py_UNICODE* will no longer compile in the latest Python versions. Use Python C API functions like PyUnicode_AsWideCharString if you need to obtain a wchar_t* on Windows (and free the string manually after use).)rc  r  r   r   r  r   r   rw  rx  r   r   r   r  r   )rU   r  r   rs   rQ   rQ   rR   r  9  s(   

zCoerceFromPyTypeNode.__init__c                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  9  r  z"CoerceFromPyTypeNode.analyse_typesc                 C   s   | j jo| j j o| j S rJ   )r   Zis_unowned_viewr6  r   r   rT   rQ   rQ   rR   r   9  s   z!CoerceFromPyTypeNode.is_ephemeralc              
   C   s   d }| j jr'| jj tu r'| j jdr'd| j jtdd   }t| j|d |	| j j
| j |  | j||| jd | j jrH| | d S d S )NZ__Pyx_PyObject_AsZ__Pyx_PyBytesZ__Pyx_PyObjectzexpected bytes, NoneType found)from_py_functionspecial_none_cvalue)r   rw  r   r   r  rj  r   r  r  r   r  r   r   r   r  rp   r  )rU   r   r  rQ   rQ   rR   rv  9  s   
z)CoerceFromPyTypeNode.generate_result_codec                 C   r  )Nz0Coercion from Python not allowed without the GILr  r   rQ   rQ   rR   rO  9  r   z CoerceFromPyTypeNode.nogil_check)	rX   rY   rZ   r  r  r"  r   rv  rO  rQ   rQ   rQ   rR   r  9  s    r  c                   @   st   e Zd ZejZejdejdej	dej
dejdejdejdiZdd Zd	d
 ZdZdd Zdd Zdd Zdd ZdS )r  rh  ri  Z__Pyx_PySet_GET_SIZEZ__Pyx_PyBytes_GET_SIZEZ__Pyx_PyByteArray_GET_SIZEZ__Pyx_PyUnicode_IS_TRUEc                 C   s"   t | | |jjrd| _d S d S r'  )rc  r  r   rp   r   r  rQ   rQ   rR   r  9  s   
zCoerceToBooleanNode.__init__c                 C   s2   | j jjr| j| j jd u r|   d S d S d S rJ   )r   r   rp   _special_builtinsrj   rN  r   rQ   rQ   rR   rO  9  s   zCoerceToBooleanNode.nogil_checkr  c                 C   s   | j r	|   dS | j S rR  )r   rS  r   r#  rT   rQ   rQ   rR   r#  :  s   
zCoerceToBooleanNode.check_constc                 C   r  )Nz	(%s != 0)r   rT   rQ   rQ   rR   r   :  rL  z)CoerceToBooleanNode.calculate_result_codec              	   C   s  | j sd S | j| jj}|d url| j r,|d| j  d|   d |d |d |dt	j
 d| d| j  d	 ||d
t	j
 d| j ||   dt	j
 d |d |  d S |d|  | j ||  | jf  d S )Nr  z == Py_None) r*  elser6  zPy_ssize_t r;  r  r?  z((!CYTHON_ASSUME_SAFE_SIZE) && z < 0)z = (z != 0);r   r  )r   r  rj   r   r   r  r   r   r   r   r  r   r   rs  )rU   r   Z	test_funcrQ   rQ   rR   rv  :  s,   
"

&
z(CoerceToBooleanNode.generate_result_codec                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  &:  rW   z!CoerceToBooleanNode.analyse_typesN)rX   rY   rZ   r   r  r   r   r   r   r   Zfrozenset_typer   r   r   r  r  rO  r  r#  r   rv  r"  rQ   rQ   rQ   rR   r  9  s"    
r  c                       rH   )r  zSpecial 'CoerceToBooleanNode' for C string arguments which checks the pointer
    and additionally that the C string is non-empty.
    c                    s.   |j js	J |j ||}t || d S rJ   )r   rw  r0  rL   r  r  rO   rQ   rR   r  .:  s   
z#CoerceCStringToBooleanNode.__init__c                 C   s2   | j  }| j jjrd| dS d| d| dS )Nz((z
)[0] != 0)r  z
 != 0 && ()r   r   r   r6  r  rQ   rQ   rR   r   3:  s   

z0CoerceCStringToBooleanNode.calculate_result_code)rX   rY   rZ   r$  r  r   r[   rQ   rQ   rO   rR   r  *:  s    r  c                   @   r  )
r  c                 C   s2   |j jr	||}|| _ t| | || d S rJ   )r   r  r0  rc  r  r  r  rQ   rQ   rR   r  =:  s
   
zCoerceToComplexNode.__init__c                 C   sT   | j jjr| j j| j  }| j j| j  }n| j  }d}d| jj||f S r  )r   r   r  r  r   r  r  )rU   r  r  rQ   rQ   rR   r   D:  s   

z)CoerceToComplexNode.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  P:  rW   z(CoerceToComplexNode.generate_result_codec                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  S:  rW   z!CoerceToComplexNode.analyse_typesN)rX   rY   rZ   r  r   rv  r"  rQ   rQ   rQ   rR   r  ;:  s
    r  c                 C   s   ddl m} tjtjtdtjd tdtjd gdddd}t| j	d|t
d	d
| || j	gd}||}|j|krB|||}|S )Nr)   )HasNoGilNoder   rp  r,  T)r   r   r   Z__Pyx_SoftComplexToDoubleZSoftComplexToDoublez	Complex.c)r  r   )r  r  r   r  rn  r  r  r  rC  r   r   r   r"  r   r  )r   r  rs   r  Z
cfunc_typer  rQ   rQ   rR   r  W:  s*   


r  c                   @   s8   e Zd Zdd ZdZdd Zdd Zdd	 Zd
d ZdS )r  c                 C   s@   t | | | jj | _| jj| _d| _| jjrt| _	d S d S r'  )
rc  r  r   r   Zas_argument_typer~   r   rp   r   r  r  rQ   rQ   rR   r  s:  s   

zCoerceToTempNode.__init__z#Creating temporary Python referencec                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  }:  r  zCoerceToTempNode.analyse_typesc                 C   r  rJ   r  rT   rQ   rQ   rR   r  :  rM  zCoerceToTempNode.may_be_nonec                 C   s4   | j || _ | j  r| j S | j j| _| j| _| S rJ   )r   r-  r  r   r  r   rQ   rQ   rR   r-  :  s   

z"CoerceToTempNode.coerce_to_booleanc                 C   sj   | d|  | j|  f  | jr3| jjs$||  |   d S |j	|  | j| j
 d d S d S )Nr  ro  )r   r   r   r   r  rd  r   r   rl  rq  rr  rm  rQ   rQ   rR   rv  :  s   
z%CoerceToTempNode.generate_result_codeN)	rX   rY   rZ   r  r  r"  r  r-  rv  rQ   rQ   rQ   rR   r  n:  s    r  c                       st   e Zd ZdZdZ fddZdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Z  ZS )r  z
    A node that should not be replaced by transforms or other means,
    and hence can be useful to wrap the argument to a clone node

    MyNode    -> ProxyNode -> ArgNode
    CloneNode -^
    Nc                    s    t  | |j| _|   d S rJ   )rL   r  r~   update_type_and_entryr  rO   rQ   rR   r  :  s   zProxyNode.__init__c                 C   s   | j || _ |   | S rJ   )r   r(  r  r   rQ   rQ   rR   r"  :  s   zProxyNode.analyse_typesc                 C   r  rJ   r  r   rQ   rQ   rR   r   :  r  zProxyNode.infer_typec                 C   sB   t | jdd }|r|| _| jj| _t | jdd }|r|| _d S d S Nr   r   )r   r   r   r  r   )rU   r   	arg_entryrQ   rQ   rR   r  :  s   

zProxyNode.update_type_and_entryc                 C   r!  rJ   )r   rv  rm  rQ   rQ   rR   rv  :  r   zProxyNode.generate_result_codec                 C   r  rJ   r   rT   rQ   rQ   rR   r   :  rM  zProxyNode.resultc                 C   r  rJ   r  rT   rQ   rQ   rR   r  :  rM  zProxyNode.is_simplec                 C   r  rJ   r  rT   rQ   rQ   rR   r  :  rM  zProxyNode.may_be_nonec                 C   r!  rJ   )r   r{  rm  rQ   rQ   rR   r{  :  r   z"ProxyNode.generate_evaluation_codec                 C   r!  rJ   )r   r  rm  rQ   rQ   rR   r  :  r   z ProxyNode.generate_disposal_codec                 C   r!  rJ   r#  rm  rQ   rQ   rR   r  :  r   zProxyNode.free_temps)rX   rY   rZ   r$  rO  r  r"  r   r  rv  r   r  r  r{  r  r  r[   rQ   rQ   rO   rR   r  :  s    	r  c                       s   e Zd Zg ZdZdd Zdd Zdd Zdd	 Zd
d Z	dd Z
 fddZdd Zdd Zdd Zdd Zdd Zdd Z  ZS )r  Nc                 C   sP   t | | |j| _t|dd }|r|| _|j| _t|dd }|r&|| _d S d S r  )rc  r  r~   r   r   r  r   )rU   r   r   r  rQ   rQ   rR   r  :  s   
zCloneNode.__init__c                 C   r  rJ   r   rT   rQ   rQ   rR   r   :  rM  zCloneNode.resultc                 C   r  rJ   r  rT   rQ   rQ   rR   r  :  rM  zCloneNode.may_be_nonec                 C   r  rJ   )r   r3  r   rQ   rQ   rR   r3  :  r  zCloneNode.type_dependenciesc                 C   r  rJ   r  r   rQ   rQ   rR   r   :  r  zCloneNode.infer_typec                 C   s6   | j j| _| j j| _d| _t| j dd }|r|| _| S )Nr)   r   )r   r   r  r   r   r   )rU   rs   r  rQ   rQ   rR   r"  :  s   

zCloneNode.analyse_typesc                    s$   | j jr| j ||S t ||S rJ   )r   r   r  rL   )rU   Z	dest_typers   rO   rQ   rR   r  :  s   zCloneNode.coerce_toc                 C   rS   r+  rQ   rT   rQ   rQ   rR   r  :  rW   zCloneNode.is_simplec                 C   r   rJ   rQ   rm  rQ   rQ   rR   r{  ;  rW   z"CloneNode.generate_evaluation_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  ;  rW   zCloneNode.generate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   r  ;  rW   z CloneNode.generate_disposal_codec                 C   s"   | j r||  |   d S d S rJ   )r   rl  r   r  rm  rQ   rQ   rR   r  ;  s   z'CloneNode.generate_post_assignment_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   r  ;  rW   zCloneNode.free_temps)rX   rY   rZ   r   rO  r  r   r  r3  r   r"  r  r  r{  rv  r  r  r  r[   rQ   rQ   rO   rR   r  :  s     	r  c                       sJ   e Zd ZdZdZedd Zdd Zdd Zd	d
 Z	d fdd	Z
  ZS )CppOptionalTempCoercionz
    Used only in CoerceCppTemps - handles cases the temp is actually a OptionalCppClassType (and thus needs dereferencing when on the rhs)
    Fc                 C   r  rJ   r  rT   rQ   rQ   rR   r   ;  r\  zCppOptionalTempCoercion.typec                 C   r  rW  r   rT   rQ   rQ   rR   r   ;  rL  z-CppOptionalTempCoercion.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  ";  rW   z,CppOptionalTempCoercion.generate_result_codec                 O   r  )NziUsing C++ classes in boolean binary operators with the 'cpp_locals' directive is not currently supported.r  )rU   r   rP  rQ   rQ   rR   r  %;  r  z5CppOptionalTempCoercion.generate_bool_evaluation_codec                    s   t  j|ddS )NFr   )rL   r   r   rO   rQ   rR   r   +;  r  z-CppOptionalTempCoercion._make_move_result_rhsr  )rX   rY   rZ   r$  r   r  r   r   rv  r  r   r[   rQ   rQ   rO   rR   r  ;  s    
r  c                   @   r  )r  c                 C   s$   |j r| j|r| S t| ||S rJ   )r  r   r  r  r  r,  rQ   rQ   rR   r  7;  s   zCMethodSelfCloneNode.coerce_toN)rX   rY   rZ   r  rQ   rQ   rQ   rR   r  1;  s    r  c                   @   s8   e Zd ZeZdZg Zdd Zdd Zdd Z	dd	 Z
d
S )ModuleRefNodeFc                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  D;  rW   zModuleRefNode.analyse_typesc                 C   rS   rR  rQ   rT   rQ   rQ   rR   r  G;  rW   zModuleRefNode.may_be_nonec                 C   r  rJ   )r   r   rT   rQ   rQ   rR   r   J;  r)  z#ModuleRefNode.calculate_result_codec                 C   r   rJ   rQ   rm  rQ   rQ   rR   rv  M;  rW   z"ModuleRefNode.generate_result_codeN)rX   rY   rZ   r   r   r   r   r"  r  r   rv  rQ   rQ   rQ   rR   r  =;  s    r  c                   @   s2   e Zd ZdgZeZdZdd Zdd Zdd Z	d	S )
DocstringRefNoder  Tc                 C   s"   t | | |jjsJ || _d S rJ   )r   r  r   rp   r  )rU   r   r  rQ   rQ   rR   r  W;  s   
zDocstringRefNode.__init__c                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  \;  rW   zDocstringRefNode.analyse_typesc              
   C   sH   | d|  | j |td||  | jf  | | d S )Nz%s = __Pyx_GetAttr(%s, %s); %sr$  )	r   r   r  r  r   r  r   r   r  rm  rQ   rQ   rR   rv  _;  s   z%DocstringRefNode.generate_result_codeN)
rX   rY   rZ   r   r   r   r   r  r"  rv  rQ   rQ   rQ   rR   r  P;  s    r  c                   @   sD   e Zd Zg ZdZdZdddZdd Zdd	 Zd
d Z	dddZ
dS )AnnotationNodeTFNc                 C   sR   t | | |du r!ddlm} t|dd|}t||d}|| _|| _	dS )z6string is expected to already be a UnicodeNode or NoneNr)   r  r   )descriptionr  )
r   r  r
  r  r   r  writer:  r  r{  )rU   r   r{  r  r  Zstring_valuerQ   rQ   rR   r  y;  s   
zAnnotationNode.__init__c                 C   r(  rJ   rQ   r   rQ   rQ   rR   r"  ;  rW   zAnnotationNode.analyse_typesc                 C   s   |  |d S r'  )r  r   rQ   rQ   rR   rC  ;  s   zAnnotationNode.analyse_as_typec                 C   s  t |tr|j}|jr!||jst|jd| jj	 dd dS dS |j
r||jjr|||jjs=t|jd| jj	 dd dS |jjr_|j|}|r[||js]t|jd| jj	  dS dS dS |j|}|rx|jrzt|jd| jj	 dd dS dS dS t|jd dS )zZMethod checks for cases when user should be warned that annotation contains unknown types.z5Unknown type declaration '%s' in annotation, ignoringr)   r{   z+Unknown type declaration '%s' in annotationz0Unknown type declaration in annotation, ignoringN)r}   r  r:  r   r  rq   r   r   r  r   r  r  r  rA  r{  r  r   Zpxd_file_loaded)rU   rs   r   ru  rQ   rQ   rR   _warn_on_unknown_annotation;  s6   





z*AnnotationNode._warn_on_unknown_annotationc           
      C   s  | j rg d fS | j}d }}|jrGt|jddd |jD ]\}}|js$q|jdv r0d}|s/|}q|jdv r9d}|}q|rF|rFt|jddd nt|t	rXt|jd	dd g d fS |j
|d
W ||}|d u ry| || g |fW  d    S |jrt|jddd |r|s|js|jst|jd |jr|| |jst|tr||ng }	W d    |	|fS 1 sw   Y  |	|fS )NFzSDicts should no longer be used as type annotations. Use 'cython.int' etc. directly.r)   r{   )r   s   typeT)r  s   ctypez9Duplicate type declarations found in signature annotationzTTuples cannot be declared as simple tuples of types. Use 'tuple[type1, type2, ...]'.)ru  zWStrings should no longer be used for type declarations. Use 'cython.int' etc. directly.zOPython type declaration in signature annotation does not refer to a Python type)untypedr{  r  r   r   r  r   r   r}   r1  r9  rC  r  rp   r   r  r  r  r8  r  )
rU   rs   Zassigned_valuer   Zexplicit_pytypeZexplicit_ctyperq   r   r}  r  rQ   rQ   rR   r  ;  sd   




 
z&AnnotationNode.analyse_type_annotationrJ   )rX   rY   rZ   r   r	  r  r  r"  rC  r  r  rQ   rQ   rQ   rR   r  g;  s    

r  c                       s   e Zd ZU dZdgZddgZdZeed< dZ	e
e ed< eed< dZeed< dedef fd	d
Zedd Zedd Zdd Zdd Zdd Z fddZdd Zdd Z  ZS )AssignmentExpressionNodez
    Also known as a named expression or the walrus operator

    Arguments
    lhs - NameNode - not stored directly as an attribute of the node
    rhs - ExprNode

    Attributes
    rhs        - ExprNode
    assignment - SingleAssignmentNode
    r   r  Fr   Nassignment_is_independentrw  c                    s*   t  j|fi | t|||dd| _d S )NT)rw  r   r  )rL   r  r-   r  )rU   r   rw  r   rP  rO   rQ   rR   r  ;  s   z!AssignmentExpressionNode.__init__c                 C   s   | j d ur	| j jS | jj jS rJ   )r   r   r  rT   rQ   rQ   rR   r   ;  s   

zAssignmentExpressionNode.typec                 C   r  rJ   )r  rw  rq   rT   rQ   rQ   rR   target_name;  r  z$AssignmentExpressionNode.target_namec                 C   s   | j p| jj }||S rJ   )r   r  r   r+  rQ   rQ   rR   r   ;  r  z#AssignmentExpressionNode.infer_typec                 C   r!  rJ   )r  rK  r   rQ   rQ   rR   rK  <  r   z-AssignmentExpressionNode.analyse_declarationsc                 C   s   | j || _ | j j}| s#|jrt| j j| _d| _n||}| js;t|| _t	| j| j _| jj
|| j_
| jjrG| jrGd| j j_| S r  )r  r"  r   rX  r   r#   r  r  r  r  r   r   r   r   r+  rQ   rQ   rR   r"  <  s   	


z&AssignmentExpressionNode.analyse_typesc                    s   | j r| j||| _| S || jjjkrZ| jd usJ | jj}t|tr'|j}|||}||urZ|| j_| j  t| jjt	rXt| jjt
sX| jjj| j_| jjjj| jj_| S t ||S rJ   )r  r   r  r  r   r   r}   r  r  rc  r  rL   )rU   r  rs   Zold_rhs_argZrhs_argrO   rQ   rR   r  0<  s&   

z"AssignmentExpressionNode.coerce_toc                 C   r  rJ   )r   r   rT   rQ   rQ   rR   r   I<  rM  z.AssignmentExpressionNode.calculate_result_codec                 C   r!  rJ   )r  r  rm  rQ   rQ   rR   rv  L<  r  z-AssignmentExpressionNode.generate_result_code)rX   rY   rZ   r$  r   r   r   r.  r	  r   r(   r   r-   r  r  r  r  r   r  r   rK  r"  r  r   rv  r[   rQ   rQ   rO   rR   r  ;  s&   
 

*r  c                   @   s,   e Zd ZdgZdZejZdd Zdd Z	dS )#FirstArgumentForCriticalSectionNode	name_nodeNc                 C   sV   t | jjdk rt| jd d S t| j| jjd  d| _| j| | jj	| _	d S )Nr)   zbcritical_section directive can only be applied to a function with one or more positional argumentsr   r  )
r   Z	func_noder   r   r   r  Zdeclared_namer  rK  r   r   rQ   rQ   rR   rK  ^<  s   z8FirstArgumentForCriticalSectionNode.analyse_declarationsc                 C   s   | j r	| j |S | S rJ   )r  r(  r   rQ   rQ   rR   r(  f<  s   z7FirstArgumentForCriticalSectionNode.analyse_expressions)
rX   rY   rZ   r   r  r   r   r   rK  r(  rQ   rQ   rQ   rR   r  Q<  s    r  c                       sD   e Zd Zg dZdZeZ fddZdd Zdd Z	d	d
 Z
  ZS )TStringInterpolationNode)r   r  expression_strTc                    s8   t  j|fi | | jd u st| jtjsJ d S d S rJ   )rL   r  r  r}   r   r  rO  rO   rQ   rR   r  s<  s   
z!TStringInterpolationNode.__init__c                 C   s2   | j | | jd ur| j| | j| d S rJ   )r   rK  r  r  r   rQ   rQ   rR   rK  x<  s   
z-TStringInterpolationNode.analyse_declarationsc                 C   sh   | j ||| _ | jd ur| jd u rt| jtdd| _| jd ur+| j|| _| j	|| _	| S )Nr  r  )
r   r"  r  r  r  r:  r   r   r  r  r   rQ   rQ   rR   r"  ~<  s   
z&TStringInterpolationNode.analyse_typesc                 C   s   |j tdd | j }| j }| jr|| jnd}| j	d ur)| j	 n|
tj}||   d| d| d| d| d
 |||  | j ||  t d S )NZMakeTemplateLibInterpolation	TString.cr*  z& = __Pyx_MakeTemplateLibInterpolation(r>  r?  )r   r   r   r   r   r   r  r  r  r  r  r   r  r   r   r   r  r   )rU   r   r   
expressionr  r  rQ   rQ   rR   rv  <  s   



,z-TStringInterpolationNode.generate_result_code)rX   rY   rZ   r   r   r   r   r  rK  r"  rv  r[   rQ   rQ   rO   rR   r  m<  s    
r  c                       sN   e Zd ZdZddgZdZeZdef fddZ	dd	 Z
d
d Zdd Z  ZS )TemplateStringNodezt-stringstringsinterpolationsTr  c                   s   d }g }g }|D ]F}t |tr.|d u r!|t|jtdd n|| d }|| qt |trI|d u r:|}qt|jt|j|j d}qJ t||d u r\t|tdd}|| t	 j
|||d d S )Nr  r  )r   r   F)r  r  )r}   r  r   r:  r   r   r  r   r   rL   r  )rU   r   r  Zlast_string_noder  r  r  rO   rQ   rR   r  <  s4   





zTemplateStringNode.__init__c                 C   s0   | j D ]}|| q| jD ]}|| qd S rJ   )r  rK  r  )rU   rs   r  r  rQ   rQ   rR   rK  <  s
   

z'TemplateStringNode.analyse_declarationsc                 C   s4   t | j| jd|| _t | j| jd|| _| S r_  )r1  r   r  r"  r  r   rQ   rQ   rR   r"  <  s   z TemplateStringNode.analyse_typesc                 C   st   |j tdd | j }| j }||   d| d| d |||  | j	 |
|  t d S )NZMakeTemplateLibTemplater  z! = __Pyx_MakeTemplateLibTemplate(r>  r?  )r   r   r   r   r  r   r  r   r   r   r  r   )rU   r   r  r  rQ   rQ   rR   rv  <  s   


 z'TemplateStringNode.generate_result_code)rX   rY   rZ   r$  r   r   r   r   r   r  rK  r"  rv  r[   rQ   rQ   rO   rR   r  <  s    
r  rQ   r  r  (7  cythonZdeclarer  r#   r"   r	   Zos.pathr$   r%   r&   r'   typingr(   ZErrorsr   r   r   r   r   r
   r*   r+   ZCoder   r   Z	LineTabler!   r  r   r   r   r,   r-   r   r.   r   r/   r0   r1   r2   r   r   r   r   r   r   r   r   r   r   r3   r    r   r   r   ZAnnotater5   r6   Z	Debuggingr7   Z
DebugFlagsr   r   ZPythranr8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   ru   rw   r  rI   r  r
  r]   rn   rm   ro   Zc_py_unicode_ptr_typer  Zget_cy_pymutex_typeZget_cy_pythread_type_lock_typeri   r   rz   r   r   r   r   r   r   r   r   r   r  r%  r&  r  r.  r1  r  r7  r   r=  r8  r~  r9  r:  r  r  r  r  r'  r)  rE  r[  r_  r  r  r  ZCopyWithUpTreeRefsMixinr  r  r  r  r  r  r  r  r  r  r<  r7  r5  r4  r  r}  r|  r  r  r6  r  r  r  r  r6  r@  rC  rD  rF  rO  rR  r  r  r  r1  r  r  r  r  r  r  r  r  r  r  r  r  r!  r"  r  r  r  r  r   r?  rB  rJ  r+  r\  r2  r3  ra  rf  rk  r  r  r  r  r  r  r  r  r  not_invnegr   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r|  r  r  r  matmulr  r   ltler  negegtis_r  r  and_truedivfloordivr6  modr5  or_rs  rshiftr  xorr  r  r  r  r$  r%  r7  r8  r<  r>  r?  rE  rF  compilefindallZ_find_formatting_types	frozensetZ_safe_bytes_formatsrk  rn  r|  r  r  r  r  r  r  r  r  rc  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rQ   rQ   rQ   rR   <module>   s  $		





(4D








	1
       =9;-	  3!W 8$      #f[ g 6&=0id      q Jn 7   YC7 %     ,x  k* )    ~3    6  "<)". ,0 @$.	
:K$*  %x#3s1 "2  k2 K&
	


	 K 	;T @H  s 
  \  b
jQM(6C+6Ftv+