B
    ž†\Øð ã               @   sN  d dl mZ d dlZejeeeeeeeeeeeeeeeeeeed d dlZd dlZd dlZd dlm	Z	 ddl
mZ ddlmZmZmZmZ ddl
mZ dd	l
mZ dd
l
mZ ddlmZmZ ddlmZmZmZmZmZmZmZ ddlmZ ddl m!Z! ddl
m"Z" ddl
m#Z# ddl
m$Z$ ddl%m&Z&m'Z'm(Z( ddl)m*Z* ej+d  dkrVe,Z-ne,e.fZ-dd„ Z/dd„ Z0dúdd„Z1dd„ Z2G dd„ de3ƒZ4G d d!„ d!e3ƒZ5d"d#„ Z6e6G d$d%„ d%eƒƒZ7G d&d'„ d'e7ƒZ8G d(d)„ d)eƒZ9G d*d+„ d+e7ƒZ:G d,d-„ d-e7ƒZ;G d.d/„ d/e;ƒZ<G d0d1„ d1e7ƒZ=G d2d3„ d3e=ƒZ>G d4d5„ d5e=ƒZ?G d6d7„ d7e=ƒZ@G d8d9„ d9e=ƒZAG d:d;„ d;e=ƒZBG d<d=„ d=e=ƒZCG d>d?„ d?e7ƒZDG d@dA„ dAe7ƒZEG dBdC„ dCe7ƒZFG dDdE„ dEeEƒZGG dFdG„ dGeEƒZHG dHdI„ dIeEƒZIG dJdK„ dKeEƒZJG dLdM„ dMeEƒZKG dNdO„ dOeEƒZLG dPdQ„ dQeEƒZMG dRdS„ dSeEƒZNG dTdU„ dUe;ƒZOG dVdW„ dWe;ƒZPG dXdY„ dYePe9ƒZQG dZd[„ d[e;ƒZRG d\d]„ d]e;ƒZSG d^d_„ d_e;ƒZTG d`da„ dae;e9ƒZUG dbdc„ dceUƒZVG ddde„ dee7ƒZWG dfdg„ dge7ƒZXG dhdi„ dieUƒZYG djdk„ dkeUƒZZG dldm„ dmeYƒZ[G dndo„ doe[ƒZ\G dpdq„ dqe\ƒZ]G drds„ dse\ƒZ^G dtdu„ dueYƒZ_G dvdw„ dwe;ƒZ`G dxdy„ dye;e9ƒZaG dzd{„ d{eaƒZbG d|d}„ d}eaƒZcG d~d„ de;ƒZdG d€d„ de;ƒZeG d‚dƒ„ dƒe;ƒZfG d„d…„ d…e;ƒZgG d†d‡„ d‡e;ƒZhG dˆd‰„ d‰ehƒZiG dŠd‹„ d‹ehƒZjG dŒd„ dehƒZkG dŽd„ dehƒZlG dd‘„ d‘e;ƒZmG d’d“„ d“e;ƒZnG d”d•„ d•e;ƒZoG d–d—„ d—e;ƒZpG d˜d™„ d™e:ƒZqG dšd›„ d›e;ƒZrG dœd„ de;ƒZsG dždŸ„ dŸe;ƒZtG d d¡„ d¡e;ƒZuG d¢d£„ d£e;ƒZvG d¤d¥„ d¥e;ƒZwG d¦d§„ d§e;ƒZxG d¨d©„ d©e7ƒZyG dªd«„ d«e;ƒZzG d¬d­„ d­e;ƒZ{G d®d¯„ d¯eƒZ|G d°d±„ d±e|e;ƒZ}G d²d³„ d³e7ƒZ~G d´dµ„ dµe7ƒZd¶d·„ Z€G d¸d¹„ d¹e|e;ƒZG dºd»„ d»eƒZ‚G d¼d½„ d½eƒZƒG d¾d¿„ d¿e|e;ƒZ„G dÀdÁ„ dÁe;ƒZ…G dÂdÃ„ dÃehƒZ†G dÄdÅ„ dÅe;ƒZ‡G dÆdÇ„ dÇe7ƒ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ŒƒZdÒdÓ„ ZŽdÔdÕ„ dÖdÕ„ eŽd×œZdØdÙdÚœZG dÛdÜ„ dÜe;ƒZ‘G dÝdÞ„ dÞe;ƒZ’G dßdà„ dàe;ƒZ“G dádâ„ dâe7ƒZ”G dãdä„ däe;e”ƒZ•G dådæ„ dæe•ƒZ–G dçdè„ dèe•ƒZ—G dédê„ dêe;ƒZ˜e#j™rÖdëZšndìZše ›dídî¡Zœe ›dïdî¡Ze ›dðdñ¡Zže ›dòdñ¡ZŸe ›dódñ¡Z e ›dôdñ¡Z¡e ›dõdñ¡Z¢e ›dödñ¡Z£ed÷døe gdùZ¤dS )ûé    )Úabsolute_importN)ÚsysÚosÚcopyÚBuiltinÚerrorÚwarningÚNamingÚ
PyrexTypesÚpy_object_typeÚModuleScopeÚ
LocalScopeÚClosureScopeÚStructOrUnionScopeÚPyClassScopeÚCppClassScopeÚUtilityCodeÚEncodedStringÚ
error_typeÚ_py_int_types)Úchainé   )r   )r   r   ÚInternalErrorÚCompileError)r	   )r
   )Ú	TypeSlots)r   r   )r   r   r   r   r   r   ÚTemplateScope)r   )r   )ÚFuture)ÚOptions)Ú
DebugFlags)Úhas_np_pythranÚpythran_typeÚis_pythran_bufferé   )Úadd_metaclassé   c             C   s   | d   ¡ | d fS )Nr   r   )Zget_filenametable_entry)Úpos© r&   ú4lib/python3.7/site-packages/Cython/Compiler/Nodes.pyÚrelative_position)   s    r(   c             C   s„   t js
|S dt| ƒ }|d kr&t|ƒS |j}|d k	r\y| |¡ W n tk
rZ   d }Y nX |sjt|ƒ}nt|d | ƒ}||_|S )NzFile: %s (starting at line %s)Ú
)r   Zembed_pos_in_docstringr(   r   ÚencodingÚencodeÚUnicodeEncodeError)r%   Z	docstringZpos_liner*   Údocr&   r&   r'   Úembed_position-   s     

r.   c             C   sz  d }d}d }}| j r|t| jdƒ xD| jD ]:\}}|js:q*|jdkrRd}|sd|} q*|jdkr*d}|} q*W |r||r|t| jdƒ |  |¡}	| jrø| jsø| j	dkrø|d k	rÎ|	d k	rÎ|	j
sÎ| |¡}
|
rÎ|
j
rÎd}d }	|	tjtjtjfkrö| j	dkròtjnt}	n|	d k	r| jrt| jd	ƒ |	d k	rR|r@|s@|	j
s@t| jd
ƒ t| j|	dd}n |rft| jdƒ nt| jdƒ ||	fS )NFzSDicts should no longer be used as type annotations. Use 'cython.int' etc. directly.)Útypes   typeT)Zctypes   ctypez9Duplicate type declarations found in signature annotation)ÚintÚlongÚfloatr2   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)r/   Úis_argz'Ambiguous types in annotation, ignoringz0Unknown type declaration in annotation, ignoring)Úis_dict_literalr   r%   Úkey_value_pairsZis_string_literalÚvalueÚanalyse_as_typeÚis_nameZcython_attributeÚnameÚis_pyobjectZ
infer_typer
   Úc_long_typeÚ
c_int_typeÚc_float_typeZc_double_typer   ÚCAnalysedBaseTypeNode)Ú
annotationÚenvÚassigned_valueÚ	base_typeZis_ambiguousZexplicit_pytypeZexplicit_ctyper9   r6   Úarg_typeZassigned_typer&   r&   r'   Úanalyse_type_annotationG   sP    





rD   c                s   ‡ ‡fdd„}|S )Nc                 sâ   t | ƒdkrÔt| d ˆ ƒrÔ| d d… \}}dd|j |jjˆj|jdd … f }|jj ¡ }| 	|¡ |jj ¡ }| jd7  _ˆ| |Ž}| jd8  _||jj ¡ kr¸|jj 
|¡ n| ddd¡}| 	|¡ |S ˆ| |ŽS d S )Nr   r"   z(                    /* %s -> %s.%s %s */ú é   z->z<-)ÚlenÚ
isinstanceZ
call_levelÚ	__class__Ú__name__r%   ÚbufferÚstreamÚtellÚputlnÚtruncateÚreplace)ÚargsÚkwdsÚnodeÚcodeÚmarkerZpristineÚstartÚres)Úcodewriter_classÚfuncr&   r'   Úfw   s&    


zwrite_func_call.<locals>.fr&   )rY   rX   rZ   r&   )rX   rY   r'   Úwrite_func_callv   s    r[   c                   s   e Zd Z‡ fdd„Z‡  ZS )ÚVerboseCodeWriterc                sd   ddl m} ddlm} t|ƒ}x,| ¡ D ] \}}t||ƒr*t||ƒ||< q*W tt	| ƒ 
| |||¡S )Nr   )ÚFunctionTyper   )ÚCCodeWriter)Útypesr]   ÚCoder^   ÚdictÚitemsrH   r[   Úsuperr\   Ú__new__)Úclsr9   ÚbasesÚattrsr]   r^   ÚmnameÚm)rI   r&   r'   rd   –   s    
zVerboseCodeWriter.__new__)rJ   Ú
__module__Ú__qualname__rd   Ú__classcell__r&   r&   )rI   r'   r\   “   s   r\   c                   s.   e Zd ZdZedddgƒZ‡ fdd„Z‡  ZS )ÚCheckAnalyserszCMetaclass to check that type analysis functions return a node.
    Úanalyse_typesÚanalyse_expressionsÚanalyse_target_typesc                sj   ddl m} dd„ }t|ƒ}x6| ¡ D ]*\}}t||ƒr&|| jkr&|||ƒ||< q&W tt| ƒ | |||¡S )Nr   )r]   c                s   ‡ ‡fdd„}|S )Nc                 s(   ˆ | |Ž}|d kr$t dˆ| |f ƒ |S )Nz%s %s %s)Úprint)rQ   ÚkwargsZretval)rY   r9   r&   r'   Úcallª   s    
z3CheckAnalysers.__new__.<locals>.check.<locals>.callr&   )r9   rY   rs   r&   )rY   r9   r'   Úcheck©   s    z%CheckAnalysers.__new__.<locals>.check)	r_   r]   ra   rb   rH   Úmethodsrc   rm   rd   )re   r9   rf   rg   r]   rt   rh   ri   )rI   r&   r'   rd   §   s    zCheckAnalysers.__new__)rJ   rj   rk   Ú__doc__Úsetru   rd   rl   r&   r&   )rI   r'   rm       s
   rm   c             C   s   t jrttƒ| ƒS | S )N)r   Zdebug_trace_code_generationr#   r\   )re   r&   r&   r'   Ú_with_metaclass¸   s    rx   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d„ ZdZdZdZd d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d„Zd"dd„ZdS )#ÚNoder   FNc             K   s   || _ | j |¡ d S )N)r%   Ú__dict__Úupdate)Úselfr%   Úkwr&   r&   r'   Ú__init__Ý   s    zNode.__init__Z	Operationc             C   s   t | jd| j ƒ d S )Nz%s not allowed without gil)r   r%   Úgil_message)r|   r@   r&   r&   r'   Ú	gil_erroræ   s    zNode.gil_errorc             C   s   |  ¡ s|  ¡  d S )N)Zis_cppÚ	cpp_error)r|   r@   r&   r&   r'   Ú	cpp_checkë   s    zNode.cpp_checkc             C   s   t | jd| j ƒ d S )Nz%s only allowed in c++)r   r%   Úcpp_message)r|   r&   r&   r'   r   ï   s    zNode.cpp_errorc             C   sH   t   | ¡}x8|jD ].}t||ƒ}t|tƒrt||dd„ |D ƒƒ qW |S )ac  Clone the node. This is defined as a shallow copy, except for member lists
           amongst the child attributes (from get_child_accessors) which are also
           copied. Lists containing child nodes are thus seen as a way for the node
           to hold multiple children directly; the list is not treated as a separate
           level in the tree.c             S   s   g | ]}|‘qS r&   r&   )Ú.0Úxr&   r&   r'   ú
<listcomp>ü   s    z#Node.clone_node.<locals>.<listcomp>)r   Úchild_attrsÚgetattrrH   ÚlistÚsetattr)r|   ÚresultZattrnamer6   r&   r&   r'   Ú
clone_nodeò   s    


zNode.clone_nodec             C   s   d S )Nr&   )r|   r@   r&   r&   r'   Úanalyse_declarations  s    zNode.analyse_declarationsc             C   s   t d| jj ƒ‚d S )Nz*analyse_expressions not implemented for %s)r   rI   rJ   )r|   r@   r&   r&   r'   ro     s    zNode.analyse_expressionsc             C   s   t d| jj ƒ‚d S )Nz$generate_code not implemented for %s)r   rI   rJ   )r|   rT   r&   r&   r'   Úgenerate_code  s    zNode.generate_codec             C   s   t | tƒr| j |¡ d S )N)rH   Ú	BlockNodeÚbodyÚannotate)r|   rT   r&   r&   r'   r‘   "  s    
zNode.annotatec          	   C   s–   y| j S  tk
r   | j}| js,|| _ |S xX| jD ]N}t| |ƒ}|d krLq4t|tƒrtx*|D ]}t|| ¡ ƒ}q\W q4t|| ¡ ƒ}q4W || _ |S X d S )N)	Z_end_posÚAttributeErrorr%   r‡   rˆ   rH   r‰   ÚmaxÚend_pos)r|   r%   ÚattrZchildÚcr&   r&   r'   r”   '  s"    


zNode.end_pos©r%   éd   c       
   	      sð   ˆ dkrdS ˆdkrt ƒ ‰t| ƒˆkr:d| jjt| ƒf S ˆ t| ƒ¡ ‡ ‡‡‡fdd„‰‡fdd„| j ¡ D ƒ}t|ƒdkr’d	| jjt| ƒf S d
| }d| jjt| ƒf }x,|D ]$\}}	|d||ˆ|	|d ƒf 7 }q´W |d| 7 }|S dS )zYDebug helper method that returns a recursive string representation of this node.
        r   z<...nesting level cutoff...>Nz<%s (0x%x) -- already output>c                sR   t | tƒr|  ˆ ˆˆd ˆ¡S t | tƒrFdd ‡‡ fdd„| D ƒ¡ S t| ƒS d S )Nr   z[%s]z, c                s   g | ]}ˆ |ˆƒ‘qS r&   r&   )r„   Úitem)Ú
dump_childÚlevelr&   r'   r†   K  s    z1Node.dump.<locals>.dump_child.<locals>.<listcomp>)rH   ry   Údumpr‰   ÚjoinÚrepr)r…   r›   )Úcutoffrš   ÚencounteredÚ
filter_out)r›   r'   rš   G  s
    

zNode.dump.<locals>.dump_childc                s    g | ]\}}|ˆ kr||f‘qS r&   r&   )r„   Úkeyr6   )r¡   r&   r'   r†   O  s    zNode.dump.<locals>.<listcomp>z<%s (0x%x)>z  z<%s (0x%x)
z%s  %s: %s
r   z%s>)rw   ÚidrI   rJ   Úaddrz   rb   rG   )
r|   r›   r¡   rŸ   r    rg   ÚindentrW   r¢   r6   r&   )rŸ   rš   r    r¡   r'   rœ   <  s"     z	Node.dumpú(#)c       	      C   s    | j s
dS | j \}}}|jddd}|td|d ƒ|… }|d }|rb|d|… | ||d…  }| ¡ d	 |d< ||||d
 … 7 }d| ¡ ||d |¡f S )z[Debug helper method that returns the source code context of this node as a string.
        Ú ÚASCIIÚignore)r*   Zerror_handlingr   r$   éÿÿÿÿNz             # <<<<<<<<<<<<<<
r"   z"%s":%d:%d
%s
)r%   Ú	get_linesr“   ÚrstripZget_escaped_descriptionr   )	r|   Zmark_columnrU   Zsource_descÚlineÚcolÚcontentsÚlinesÚcurrentr&   r&   r'   Údump_posZ  s    zNode.dump_pos)N)r   r—   r˜   N)Fr¦   )rJ   rj   rk   r8   Úis_noneZis_nonecheckÚ
is_literalÚis_terminatorÚ
is_wrapperÚtempsr‡   Úouter_attrsZcf_stateZcoercion_typer~   r   Únogil_checkÚin_nogil_contextr€   rƒ   r‚   r   rŒ   r   ro   rŽ   r‘   r”   rœ   r²   r&   r&   r&   r'   ry   ¿   s6   
%
ry   c               @   s>   e Zd ZdZdgZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚCompilerDirectivesNodez9
    Sets compiler directives for the children nodes
    r   c             C   s$   |j }| j |_ | j |¡ ||_ d S )N)Ú
directivesr   r   )r|   r@   Úoldr&   r&   r'   r   t  s    z+CompilerDirectivesNode.analyse_declarationsc             C   s&   |j }| j |_ | j |¡| _||_ | S )N)r¼   r   ro   )r|   r@   r½   r&   r&   r'   ro   z  s
    z*CompilerDirectivesNode.analyse_expressionsc             C   s8   |j }|jj }| j |j_ | j ||¡ ||_ ||j_ d S )N)r¼   Úglobalstater   Úgenerate_function_definitions)r|   r@   rT   Zenv_oldZcode_oldr&   r&   r'   r¿     s    
z4CompilerDirectivesNode.generate_function_definitionsc             C   s*   |j j}| j|j _| j |¡ ||j _d S )N)r¾   r¼   r   Úgenerate_execution_code)r|   rT   r½   r&   r&   r'   rÀ   ‰  s    
z.CompilerDirectivesNode.generate_execution_codec             C   s*   |j j}| j|j _| j |¡ ||j _d S )N)r¾   r¼   r   r‘   )r|   rT   r½   r&   r&   r'   r‘     s    
zCompilerDirectivesNode.annotateN)
rJ   rj   rk   rv   r‡   r   ro   r¿   rÀ   r‘   r&   r&   r&   r'   r»   k  s   r»   c               @   s   e Zd Zdd„ Zdd„ ZdS )r   c             C   s2   |  ¡ j}x|D ]}|j |¡ qW |d d …= d S )N)Úglobal_scopeZundeclared_cached_builtinsr¾   Zadd_cached_builtin_decl)r|   r@   rT   ÚentriesÚentryr&   r&   r'   Úgenerate_cached_builtins_decls˜  s    

z(BlockNode.generate_cached_builtins_declsc             C   s    x|j D ]}| ||¡ qW d S )N)Zlambda_defsr¿   )r|   r@   rT   rS   r&   r&   r'   Úgenerate_lambda_definitionsž  s    z%BlockNode.generate_lambda_definitionsN)rJ   rj   rk   rÄ   rÅ   r&   r&   r&   r'   r   •  s   r   c               @   sF   e Zd ZdgZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dS )ÚStatListNodeÚstatsc             O   s   t | f|ž|Ž}|S )N)rÆ   )r%   r@   rQ   r}   rS   r&   r&   r'   Úcreate_analysed§  s    zStatListNode.create_analysedc             C   s   x| j D ]}| |¡ qW d S )N)rÇ   r   )r|   r@   Ústatr&   r&   r'   r   ¬  s    z!StatListNode.analyse_declarationsc                s   ‡ fdd„| j D ƒ| _ | S )Nc                s   g | ]}|  ˆ ¡‘qS r&   )ro   )r„   rÉ   )r@   r&   r'   r†   ³  s   z4StatListNode.analyse_expressions.<locals>.<listcomp>)rÇ   )r|   r@   r&   )r@   r'   ro   ±  s    
z StatListNode.analyse_expressionsc             C   s    x| j D ]}| ||¡ qW d S )N)rÇ   r¿   )r|   r@   rT   rÉ   r&   r&   r'   r¿   ·  s    z*StatListNode.generate_function_definitionsc             C   s*   x$| j D ]}| |j¡ | |¡ qW d S )N)rÇ   Úmark_posr%   rÀ   )r|   rT   rÉ   r&   r&   r'   rÀ   ¼  s    z$StatListNode.generate_execution_codec             C   s   x| j D ]}| |¡ qW d S )N)rÇ   r‘   )r|   rT   rÉ   r&   r&   r'   r‘   Â  s    zStatListNode.annotateN)rJ   rj   rk   r‡   ÚstaticmethodrÈ   r   ro   r¿   rÀ   r‘   r&   r&   r&   r'   rÆ   ¢  s   rÆ   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚStatNodec             C   s   d S )Nr&   )r|   r@   rT   r&   r&   r'   r¿   Ô  s    z&StatNode.generate_function_definitionsc             C   s   t d| jj ƒ‚d S )Nz.generate_execution_code not implemented for %s)r   rI   rJ   )r|   rT   r&   r&   r'   rÀ   ×  s    z StatNode.generate_execution_codeN)rJ   rj   rk   r¿   rÀ   r&   r&   r&   r'   rÌ   Ç  s   rÌ   c               @   s2   e Zd ZdgZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚCDefExternNoder   c             C   st   |j }d|_ | j |¡ ||_ | js*| jrp| jj}|jd sBd}n|sLd}ntdd„ |D ƒƒ}| | j| j|¡ d S )Nr   Zpreliminary_late_includes_cy28Fc             s   s   | ]}t |tƒV  qd S )N)rH   ÚCVarDefNode)r„   rS   r&   r&   r'   ú	<genexpr>ò  s    z6CDefExternNode.analyse_declarations.<locals>.<genexpr>)	Úin_cincluder   r   Zinclude_fileZverbatim_includerÇ   r¼   ÚallÚadd_include_file)r|   r@   Zold_cinclude_flagrÇ   Zlater&   r&   r'   r   ã  s    
z#CDefExternNode.analyse_declarationsc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   õ  s    z"CDefExternNode.analyse_expressionsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÀ   ø  s    z&CDefExternNode.generate_execution_codec             C   s   | j  |¡ d S )N)r   r‘   )r|   rT   r&   r&   r'   r‘   û  s    zCDefExternNode.annotateN)rJ   rj   rk   r‡   r   ro   rÀ   r‘   r&   r&   r&   r'   rÍ   Ü  s
   rÍ   c               @   s   e Zd Zg ZdZdd„ ZdS )ÚCDeclaratorNoder§   c             C   s   d S )Nr&   )r|   r&   r&   r'   Úanalyse_templates  s    z!CDeclaratorNode.analyse_templatesN)rJ   rj   rk   r‡   Úcalling_conventionrÔ   r&   r&   r&   r'   rÓ   ÿ  s   rÓ   c               @   s    e Zd ZdgZdZddd„ZdS )ÚCNameDeclaratorNodeÚdefaultNr   Fc             C   s~   |rX| j dkrX|js |js |jr.t| jdƒ n*|jrBt| jdƒ n|jdddd| _ t}|j	rp|j
rp| |j
¡}|| _| |fS )Nr§   zMissing argument namezJUse spam() rather than spam(void) to declare a function with no arguments.r   )Zfor_displayZpyrex)r9   Úis_ptrÚis_arrayÚ	is_bufferr   r%   Úis_voidÚdeclaration_coder   Úis_fusedÚfused_to_specificÚ
specializer/   )r|   rB   r@   ÚnonemptyÚ
visibilityÚin_pxdr&   r&   r'   Úanalyse  s    zCNameDeclaratorNode.analyse)r   NF)rJ   rj   rk   r‡   r×   rã   r&   r&   r&   r'   rÖ     s   rÖ   c               @   s$   e Zd ZdgZdd„ Zd	dd„ZdS )
ÚCPtrDeclaratorNodeÚbasec             C   s
   | j  ¡ S )N)rå   rÔ   )r|   r&   r&   r'   rÔ   5  s    z$CPtrDeclaratorNode.analyse_templatesr   NFc             C   s2   |j rt| jdƒ t |¡}| jj|||||dS )Nz+Pointer base type cannot be a Python object)rà   rá   râ   )r:   r   r%   r
   Ú
c_ptr_typerå   rã   )r|   rB   r@   rà   rá   râ   Zptr_typer&   r&   r'   rã   8  s    
zCPtrDeclaratorNode.analyse)r   NF)rJ   rj   rk   r‡   rÔ   rã   r&   r&   r&   r'   rä   0  s   rä   c               @   s$   e Zd ZdgZdd„ Zd	dd„ZdS )
ÚCReferenceDeclaratorNoderå   c             C   s
   | j  ¡ S )N)rå   rÔ   )r|   r&   r&   r'   rÔ   D  s    z*CReferenceDeclaratorNode.analyse_templatesr   NFc             C   s2   |j rt| jdƒ t |¡}| jj|||||dS )Nz-Reference base type cannot be a Python object)rà   rá   râ   )r:   r   r%   r
   Z
c_ref_typerå   rã   )r|   rB   r@   rà   rá   râ   Zref_typer&   r&   r'   rã   G  s    
z CReferenceDeclaratorNode.analyse)r   NF)rJ   rj   rk   r‡   rÔ   rã   r&   r&   r&   r'   rç   ?  s   rç   c               @   s   e Zd ZddgZddd„ZdS )	ÚCArrayDeclaratorNoderå   Ú	dimensionr   NFc                sf  |j r| ¡ s|jrœddlm} t| j|ƒr6| jj}n| jf}‡ fdd„|D ƒ}d |krx| d ¡}	t	||	 j
dƒ t}n| | j
|¡}| jj|ˆ |||dS | jrþ| j ˆ ¡| _| jjjsÈt	| jj
dƒ | j ¡ }
|
d k	rüyt|
ƒ}
W n tk
rú   Y nX nd }
| ¡ st	| j
d| ƒ |jr0t	| j
d	ƒ |jrDt	| j
d
ƒ t ||
¡}| jj|ˆ |||dS )Nr   )Ú	TupleNodec                s   g | ]}|  ˆ ¡‘qS r&   )r7   )r„   Úv)r@   r&   r'   r†   [  s    z0CArrayDeclaratorNode.analyse.<locals>.<listcomp>zTemplate parameter not a type)rà   rá   râ   zArray dimension not integerz%Array element type '%s' is incompletez'Array element cannot be a Python objectz"Array element cannot be a function)Úis_cpp_classÚis_template_typeÚis_cfunctionÚ	ExprNodesrê   rH   ré   rQ   Úindexr   r%   r   Úspecialize_hererå   rã   Úanalyse_const_expressionr/   Úis_intÚget_constant_c_result_coder0   Ú
ValueErrorÚis_completer:   r
   Zc_array_type)r|   rB   r@   rà   rá   râ   rê   rQ   ÚvaluesÚixÚsizeZ
array_typer&   )r@   r'   rã   T  s>    




zCArrayDeclaratorNode.analyse)r   NF)rJ   rj   rk   r‡   rã   r&   r&   r&   r'   rè   N  s   rè   c               @   sB   e Zd ZdddgZdZdZdZdZdd„ Zdd	d
„Z	ddd„Z
dS )ÚCFuncDeclaratorNoderå   rQ   Úexception_valuer   Nc             C   s°   t | jtƒr¨ddlm}m} | jj}t ||ƒr6|j}n"t ||ƒrH|g}nt|j	dƒ d S g | _
x8|D ]0}t ||ƒrˆ| j
 t |j¡¡ qdt|j	dƒ qdW | jj| _| j
S d S d S )Nr   )rê   ÚNameNodez*Template arguments must be a list of names)rH   rå   rè   rï   rê   rü   ré   rQ   r   r%   Ú	templatesÚappendr
   ÚTemplatePlaceholderTyper9   )r|   rê   rü   Útemplate_nodeZtemplate_nodesÚtemplater&   r&   r'   rÔ   Œ  s"    




z%CFuncDeclaratorNode.analyse_templatesFc                sä  |d kri }|r|d8 }g }x>t ˆjƒD ].\}}	|	jˆ ||dkoRˆ joRdˆ jkd\}
}|
j}||krÆ|| }| ˆ ¡}|d kr’t|jdƒ n4|t	j
k	rÂ| |¡sÂtˆjjdƒ t|jdƒ n|}|
jrØtˆjdƒ |dkròˆ jrò|jròˆ j}|jrt	 |j¡}|jrt|	jd	ƒ | t	 |||	j¡¡ |	jrHˆ jd7  _q*ˆjr*tˆjd
ƒ q*W d }d}ˆjdkršˆ  d¡ ˆ  d¡ ˆ  d¡ ˆ  d¡ |jrÎˆjs²ˆjrÎˆjdkrÎtˆjdƒ nHˆjd kr2ˆjr2ˆjdkr2|jd k	r2|dkr2|s2ˆ js2ddlm} |ˆj|j|dˆ_ˆjrˆj ˆ ¡ˆ_ˆjdkr¶ˆjj}|j s®|js®|j!r†|j"js†|jr®|t	j#kr ˆjj$dks®tˆjjdƒ ˆj}nZˆj %|ˆ ¡ ˆ ¡ˆ_ˆj &¡ }|d kròt'dˆjj(j) ƒ‚| *ˆjj¡stˆjjdƒ ˆj}|j!r*tˆjdƒ t	j+||ˆj,ˆj||ˆjj-ˆj.ˆj/ˆj0ˆj1ˆj2d}ˆjr|j3r„‡ ‡fdd„}||_4nˆ 5|ˆ ¡ ˆ jd }|rÐ|j-}|rÊ||krÊtˆjd||f ƒ ||_-ˆjj|ˆ ||dS )Nr   r   rË   )rà   Úis_self_argz
Not a typez2Signature does not agree with previous declarationzPrevious declaration herez2Function argument cannot have C name specificationzJUse spam() rather than spam(void) to declare a function with no arguments.z-Non-default argument follows default argumentú+ZiosÚnewZ	stdexceptZtypeinfozAException clause not allowed for function returning Python objectÚextern)Ú	ConstNode)r6   r/   Ú*zSException value must be a Python exception or cdef function with no arguments or *.z1get_constant_c_result_code not implemented for %sz6Exception value incompatible with function return typez!Function cannot return a function)	Úoptional_arg_countrû   Úexception_checkrÕ   ÚnogilÚwith_gilÚis_overridableÚis_const_methodrý   c                s   ˆ  | ˆ |¡ d S )N)Údeclare_optional_arg_struct)Ú	func_typeÚfused_cname)r@   r|   r&   r'   Údeclare_opt_arg_struct
  s    z;CFuncDeclaratorNode.analyse.<locals>.declare_opt_arg_structÚcallspecz2cannot have both '%s' and '%s' calling conventions)rá   râ   )6Ú	enumeraterQ   rã   Úis_c_class_scoper¼   r9   r7   r   r%   r
   r   Úsame_asrå   ÚcnameZis_unspecifiedÚparent_typerÙ   ræ   rB   rÛ   rþ   ÚCFuncTypeArgr×   r  r	  rÒ   r:   rû   rï   r  rò   r/   Úis_errorrî   Úreturn_typeÚc_char_typer6   Ú	coerce_torô   r   rI   rJ   Úassignable_fromÚ	CFuncTypeÚhas_varargsrÕ   r
  r  Úoverridabler  rý   rÝ   r  r  )r|   r  r@   rà   Údirective_localsrá   râ   Zfunc_type_argsÚiZarg_nodeÚname_declaratorr/   r9   Ú	type_nodeÚ
other_typeZexc_valÚ	exc_checkr  Zexc_val_typer  r  r  r±   r&   )r@   r|   r'   rã   ¢  sÆ     






 




zCFuncDeclaratorNode.analysec       	      C   sÀ   t ƒ }dtj }| |tj| j¡ x<|jt|jƒ| j	 d… D ]}|j|j
|j|jddd q>W | tj| jj
¡}|dk	r†t ||¡}| ¡ j|d|d| j|d}d|_d|_t |j¡|_dS )	a  
        Declares the optional argument struct (the struct used to hold the
        values for optional arguments). For fused cdef functions, this is
        deferred as analyse_declarations is called only once (on the fused
        cdef function).
        z%snNT)Zallow_pyobjectZallow_memoryviewÚstructr   )r9   ÚkindÚscopeÚtypedef_flagr%   r  r   )r   r	   Úpyrex_prefixÚdeclare_varr
   r<   r%   rQ   rG   r  r9   r/   ÚmangleZopt_arg_prefixrå   Zget_fused_cnamerÁ   Údeclare_struct_or_unionÚdefined_in_pxdÚusedræ   Úop_arg_struct)	r|   r  r@   r  r)  Zarg_count_memberÚargZstruct_cnameZop_args_structr&   r&   r'   r    s$    
 z/CFuncDeclaratorNode.declare_optional_arg_struct)r   NNF)N)rJ   rj   rk   r‡   r   r  r  rý   rÔ   rã   r  r&   r&   r&   r'   rú   z  s   

xrú   c               @   s   e Zd ZdgZddd„ZdS )ÚCConstDeclaratorNoderå   r   NFc             C   s2   |j rt| jdƒ t |¡}| jj|||||dS )Nz)Const base type cannot be a Python object)rà   rá   râ   )r:   r   r%   r
   Úc_const_typerå   rã   )r|   rB   r@   rà   rá   râ   Zconstr&   r&   r'   rã   @  s
    
zCConstDeclaratorNode.analyse)r   NF)rJ   rj   rk   r‡   rã   r&   r&   r&   r'   r3  ;  s   r3  c               @   sx   e Zd ZddddgZddg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	d
„Zdd„ Zdd„ Zdd„ Zddd„ZdS )ÚCArgDeclNoderB   Ú
declaratorr×   r?   r   r   NFc       
      C   sx  |rd | j _| _| jd krht| jtƒr†| jjdkr†|r€| j jr\| j j|dd}| 	¡ }n| j j}t
|ƒ| j_d | j _d| j _d}nd}d| j _| j j||d}t| j dƒrÂ| j jrÂ| j j| j_|jrt| j tƒrt| jtƒr| j}xt|jtƒr|j}qîW | j j|_|j }| jrV|rV|jd rV| j jd krV|  |¡}	|	d k	rV|	}| jj|||dS | j| jfS d S )NTr§   )Úcould_be_nameFÚarg_nameÚannotation_typing)rà   )rB   r  r/   rH   r6  rÖ   r9   Úis_basic_c_typerã   Úempty_declaration_coder   r3   Úhasattrr8  rÙ   ÚTemplatedTypeNoderè   rå   Úarray_declaratorr?   r¼   Úinject_type_from_annotationsr#  )
r|   r@   rà   r  r/   r8  r7  rB   r6  rC   r&   r&   r'   rã   g  s@    


(

zCArgDeclNode.analysec             C   s4   | j }|sd S t||| jd\}}|d k	r0|| _|S )N)rA   )r?   rD   r×   rB   )r|   r@   r?   rB   rC   r&   r&   r'   r?  •  s    z)CArgDeclNode.inject_type_from_annotationsc             C   sJ   | j d krD| jrD| jjr6| j |¡ | j | j ¡ ¡S | | j¡| _ | j S )N)Údefault_valuer×   r´   Úgenerate_evaluation_coder/   Ú	cast_coder‹   Zget_argument_default_const)r|   rT   r&   r&   r'   Úcalculate_default_value_codež  s    
z)CArgDeclNode.calculate_default_value_codec             C   s   | j r| j  |¡ d S )N)r×   r‘   )r|   rT   r&   r&   r'   r‘   ¨  s    zCArgDeclNode.annotatec             C   s–   | j }|d ks|jrd S |d kr*|  |¡}| |¡ | |¡ |rJ| ¡ n
| | j¡}| d||f ¡ | jj	r~| 
| ¡ ¡ | |¡ | |¡ d S )Nz%s = %s;)r×   r´   rC  rA  Úmake_owned_referencer‹   Ú	result_asr/   rN   r:   Úput_giverefÚgenerate_post_assignment_codeÚ
free_temps)r|   rT   ÚtargetÚoverloaded_assignmentr×   r‹   r&   r&   r'   Úgenerate_assignment_code¬  s    



z%CArgDeclNode.generate_assignment_code)r   F)NF)rJ   rj   rk   r‡   r¸   r  Úis_type_argÚ
is_genericÚkw_onlyÚnot_noneÚor_noner/   r#  r@  r?   Ú
is_dynamicrã   r?  rC  r‘   rK  r&   r&   r&   r'   r5  H  s$   
.	
r5  c               @   s   e Zd Zdd„ ZdS )ÚCBaseTypeNodec             C   s
   |   |¡S )N)rã   )r|   r@   r&   r&   r'   r7   Ä  s    zCBaseTypeNode.analyse_as_typeN)rJ   rj   rk   r7   r&   r&   r&   r'   rR  ¼  s   rR  c               @   s   e Zd Zg Zddd„ZdS )r>   Fc             C   s   | j S )N)r/   )r|   r@   r7  r&   r&   r'   rã   Í  s    zCAnalysedBaseTypeNode.analyseN)F)rJ   rj   rk   r‡   rã   r&   r&   r&   r'   r>   È  s   r>   c               @   s*   e Zd Zg ZdZg ZdZdZddd„ZdS )ÚCSimpleBaseTypeNodeNFc             C   sð  d }| j r2t | j| j| j¡}|s.t| jdƒ nN| jdkrJ| jsJt	}n6| jd krp| j
rh|jrh|j}nt	}n| jrØ|}x6| jD ],}| |¡}|d k	r¨|jr¨|jj}q‚d }P q‚W |d krÜ| | j| j¡}|rÜ|j|_n|}|r€|jrð| ¡ }| | j¡}|d k	rnx|r8| j
r&|jr&|j}nt	}t| jƒ| _nH| jrn| j| jkr`t| jd| j ƒ t | j¡}nt| jd| j ƒ | jrº|jr˜|jr¤t| jdƒ t |¡}| |¡ n"|tjkrÜtj }| |¡ d| _|ræ|S tj!S d S )Nz&Unrecognised type modifier combinationÚobjectz'%s' is not a type identifierz#can only complexify c numeric typesT)"r:  r
   Zsimple_c_typeÚsignedZlongnessr9   r   r%   Úmodule_pathr   r  r  r  Úlookuprì   r/   r)  Úfind_imported_modulerÞ   rÁ   Zlookup_typer   r8  rý   rÿ   ÚcomplexÚ
is_numericÚ
is_complexZCComplexTypeZcreate_declaration_utility_coder   Zcomplex_typeZc_double_complex_typer   )r|   r@   r7  r/   r)  r™   rÃ   r&   r&   r'   rã   á  sh    






zCSimpleBaseTypeNode.analyse)F)	rJ   rj   rk   r‡   r8  rV  r:  rY  rã   r&   r&   r&   r'   rS  Ñ  s   
rS  c               @   s*   e Zd ZdZddgZd
dd„Zdd„ Zd	S )ÚMemoryViewSliceTypeNodeÚ
memoryviewÚbase_type_nodeÚaxesFc          
   C   s´   | j  |¡}|jr|S ddlm} y| || j¡}W n< tk
rp } zt|j	|j
ƒ t ¡ | _| jS d }~X Y nX | | j|¡sˆt| _n&t ||¡| _| j | j¡ |  |¡ | jS )Nr   )Ú
MemoryView)r^  rã   r  r§   r`  Zget_axes_specsr_  r   r   ZpositionZmessage_onlyr
   Z	ErrorTyper/   Zvalidate_axesr%   r   ZMemoryViewSliceTypeZvalidate_memslice_dtypeÚuse_memview_utilities)r|   r@   r7  rB   r`  Z
axes_specsÚer&   r&   r'   rã   4  s      

zMemoryViewSliceTypeNode.analysec             C   s   ddl m} | |j¡ d S )Nr   )r`  )r§   r`  Úuse_utility_codeÚview_utility_code)r|   r@   r`  r&   r&   r'   ra  K  s    z-MemoryViewSliceTypeNode.use_memview_utilitiesN)F)rJ   rj   rk   r9   r‡   rã   ra  r&   r&   r&   r'   r\  /  s   
r\  c               @   s   e Zd ZdgZddd„ZdS )ÚCNestedBaseTypeNoderB   Nc             C   sr   | j  |¡}|tjkrtjS |js8t| jd| ƒ tjS |j | j	¡}|rP|j
slt| jd|| j	f ƒ tjS |jS )Nz'%s' is not a valid type scopez '%s.%s' is not a type identifier)rB   rã   r
   r   rì   r   r%   r)  Úlookup_herer9   Úis_typer/   )r|   r@   r7  rB   Ú
type_entryr&   r&   r'   rã   X  s    

zCNestedBaseTypeNode.analyse)N)rJ   rj   rk   r‡   rã   r&   r&   r&   r'   re  P  s   re  c               @   s*   e Zd ZddddgZdZdZd	dd„ZdS )
r=  r^  Úpositional_argsÚkeyword_argsÚ
dtype_nodeNFc             C   sÚ  |d kr| j  |¡}|jr|S |jr¤| ¡ r¤| jrP| jjrPt| jdƒ t	j
| _nPg }x:| jD ]0}| |¡}|d kr‚t|jdƒ t
}| |¡ q\W | | j|¡| _n|jr4ddlm} | | j|| j| j|j¡}tjd dk rötdd„ | ¡ D ƒƒ}t	j|f|Ž| _t|ƒr²t| jƒr²t	 t| jƒ| j¡| _n~t| jd	d d
}	t| jƒdks^| jjrtt| jdƒ t	j
| _n>| js‚d }
n
| jd }
t | j|	|
d| _!| j! ||¡d | _| jj"rÔ|j#rÔ| j $|j#¡| _| jS )Nz+c++ templates cannot take keyword argumentsz!unknown type in template argumentr   )ÚBufferr   r$   c             S   s   g | ]\}}|  d ¡|f‘qS )r¨   )r+   )r„   r9   r6   r&   r&   r'   r†   —  s   z-TemplatedTypeNode.analyse.<locals>.<listcomp>r§   )r9   r  zinvalid array declaration)rå   ré   )%r^  rã   r  rì   rí   rj  r5   r   r%   r
   r   r/   ri  r7   rþ   rñ   r:   r§   rl  Úanalyse_buffer_optionsÚbuffer_defaultsr   Úversion_infora   rb   Z
BufferTyper   r!   ZPythranExprr    rÖ   rG   rè   r>  rÝ   rÞ   rß   )r|   r@   r7  rB   Útemplate_typesr   r/   rl  ZoptionsZempty_declaratorré   r&   r&   r'   rã   v  sZ     




zTemplatedTypeNode.analyse)FN)rJ   rj   rk   r‡   rk  r9   rã   r&   r&   r&   r'   r=  f  s
   	r=  c               @   s   e Zd ZddgZddd„ZdS )ÚCComplexBaseTypeNoderB   r6  Fc             C   s$   | j  ||¡}| j ||¡\}}|S )N)rB   rã   r6  )r|   r@   r7  rå   Ú_r/   r&   r&   r'   rã   ½  s    zCComplexBaseTypeNode.analyseN)F)rJ   rj   rk   r‡   rã   r&   r&   r&   r'   rq  ·  s   rq  c               @   s   e Zd ZdgZddd„ZdS )ÚCTupleBaseTypeNodeÚ
componentsFc             C   sX   g }x8| j D ].}| |¡}|jr0t|jdƒ tS | |¡ qW | | j|¡}d|_|j	S )Nz/Tuple types can't (yet) contain Python objects.T)
rt  rã   r:   r   r%   r   rþ   Zdeclare_tuple_typer0  r/   )r|   r@   r7  Zcomponent_typesr–   r/   rÃ   r&   r&   r'   rã   È  s    
zCTupleBaseTypeNode.analyseN)F)rJ   rj   rk   r‡   rã   r&   r&   r&   r'   rs  Ã  s   rs  c               @   s&   e Zd ZdZg Zdd„ Zddd„ZdS )	ÚFusedTypeNodea  
    Represents a fused type in a ctypedef statement:

        ctypedef cython.fused_type(int, long, long long) integral

    name            str                     name of this fused type
    types           [CSimpleBaseTypeNode]   is the list of types to be fused
    c             C   s&   |   |¡}| | j|| j¡}d|_d S )NT)rã   Údeclare_typedefr9   r%   rÐ   )r|   r@   r/   rÃ   r&   r&   r'   r   á  s    
z"FusedTypeNode.analyse_declarationsFc             C   s`   g }xJ| j D ]@}| |¡}|s,t|jdƒ q||krBt|jdƒ q| |¡ qW tj|| jdS )Nz
Not a typezType specified multiple times)r9   )r_   r7   r   r%   rþ   r
   Ú	FusedTyper9   )r|   r@   r7  r_   r$  r/   r&   r&   r'   rã   è  s    
zFusedTypeNode.analyseN)F)rJ   rj   rk   rv   r‡   r   rã   r&   r&   r&   r'   ru  Õ  s   ru  c               @   s   e Zd ZdgZddd„ZdS )ÚCConstTypeNoderB   Fc             C   s*   | j  ||¡}|jr t| jdƒ t |¡S )Nz)Const base type cannot be a Python object)rB   rã   r:   r   r%   r
   r4  )r|   r@   r7  rå   r&   r&   r'   rã     s
    zCConstTypeNode.analyseN)F)rJ   rj   rk   r‡   rã   r&   r&   r&   r'   rx  ü  s   rx  c               @   s&   e Zd ZddgZdZdZddd„ZdS )rÎ   rB   ÚdeclaratorsNc             C   s  | j d kri | _ |s|}|| _| jr4| jd  ¡ }nd }|d k	rª| jdkrVt| jdƒ t| jƒdkrvt| jd jdƒ td|ƒ}|j	j
|_
x|D ]}| |j|| j¡ qW | j |¡}|jrÞ| jsÞ|jsÎ|jrÞt| jdƒ tS d | _| j}x| jD ]
}t| jƒdkr0t|tƒs0|j
d r0t|jd	dƒ | joH| jdkoH|j}|rVd
|_t|tƒr€|j||| j || jd\}	}
n|j|||| jd\}	}
|
 ¡ sÎ| jdkr¶|
jsÎ|
jsÎt|jd|
 ƒ | jdkrî|
jrît|jdƒ |	j}|	j}|dkrt|jdƒ d S |
jr4| jdkr4t|jdƒ |
j r²d|j
krNd|
_!|j"||
|j|| j| j| j#| j$| jd	| _| jd k	r”t% %| j ¡| j_ |r | jj& '|¡ d| j_(qô| j rÆt| jdƒ |j)||
|j||| j| j#dd| _t*j+rôt,| j| j-ƒ| j_-qôW d S )Nr   r  zOnly extern functions allowedr   z%Can't multiply declare template typesZfunc_templatezFused types not allowed herezwarn.multiple_declaratorsz‰Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.F)r!  rá   râ   )rá   râ   z Variable type '%s' is incompletez'Python object cannot be declared externr§   zMissing name in declaration.z8C++ references cannot be declared; use a pointer insteadrË   T)r  rá   râ   ÚapiÚ	modifiersr   z,Decorators can only be followed by functions)r  rá   râ   rz  Úis_cdef).r!  Ú
dest_scopery  rÔ   rá   r   r%   rG   r   Úouter_scoper¼   Zdeclare_typer9   rB   rã   rÝ   râ   r  Úis_module_scoper   rÃ   rH   rÖ   r   r   rú   rö   rÙ   Úis_memoryviewslicer:   r  Zis_referencerî   Úis_static_methodÚdeclare_cfunctionrz  r{  r   r/   Úcreate_to_py_utility_codeÚcreate_wrapperr,  r   Ú
docstringsr.   r-   )r|   r@   r}  rý   Ztemplate_paramrB   rá   r6  Zcreate_extern_wrapperr#  r/   r9   r  r&   r&   r'   r     s”    








z CVarDefNode.analyse_declarations)N)rJ   rj   rk   r‡   Ú
decoratorsr!  r   r&   r&   r&   r'   rÎ   	  s   rÎ   c               @   s4   e Zd ZdgZddd„Zdd„ Zdd„ Zd	d
„ ZdS )ÚCStructOrUnionDefNodeÚ
attributesNc             C   s2   |j | j| j|| j| j| j| j| j| jd	| _	d S )N)rá   rz  Úpacked)
r.  r9   r(  r*  r%   r  rá   rz  r‰  rÃ   )r|   r@   r)  r&   r&   r'   Údeclare  s    zCStructOrUnionDefNode.declarec             C   s¬   d }| j d k	rt| jƒ}|  ||¡ | j d k	r¨| jrB|jsBd| j_x| j D ]}| ||¡ qJW | j	dkr¨x>|j
D ]4}|j}x|jrŠ|j}q|W || jjkrpt|jdƒ qpW d S )Nr   r  z)Struct cannot contain itself as a member.)rˆ  r   r9   rŠ  râ   rÐ   rÃ   r/  r   rá   Úvar_entriesr/   rÙ   rB   r   r%   )r|   r@   r)  r•   r/   r&   r&   r'   r   ‡  s     




z*CStructOrUnionDefNode.analyse_declarationsc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   ™  s    z)CStructOrUnionDefNode.analyse_expressionsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÀ   œ  s    z-CStructOrUnionDefNode.generate_execution_code)N)rJ   rj   rk   r‡   rŠ  r   ro   rÀ   r&   r&   r&   r'   r‡  s  s
   
r‡  c               @   s@   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 )ÚCppClassNodeNc          	   C   sˆ   | j d krd }nRdd„ | j D ƒ}tdd„ | j D ƒƒ}|rbtdd„ | j d | … D ƒƒsbt| jdƒ |j| jd | j| jg | j|d| _	d S )Nc             S   s   g | ]\}}t  || ¡‘qS r&   )r
   rÿ   )r„   Útemplate_nameÚrequiredr&   r&   r'   r†   ²  s   z(CppClassNode.declare.<locals>.<listcomp>c             s   s   | ]\}}| V  qd S )Nr&   )r„   rr  rŽ  r&   r&   r'   rÏ   ´  s    z'CppClassNode.declare.<locals>.<genexpr>c             s   s   | ]\}}|V  qd S )Nr&   )r„   rr  rŽ  r&   r&   r'   rÏ   µ  s    zGRequired template parameters must precede optional template parameters.)Úbase_classesrá   rý   )
rý   ÚsumrÑ   r   r%   Údeclare_cpp_classr9   r  rá   rÃ   )r|   r@   rp  Znum_optional_templatesr&   r&   r'   rŠ  ®  s    

"zCppClassNode.declarec       
   	      s€  ˆj d krd  }}n dd„ ˆj D ƒ}dd„ ˆj D ƒ}d ‰ˆjd k	rRtˆjˆ |d‰‡fdd„}t|‡ ‡fdd„ˆjD ƒƒ}ˆ jˆjˆˆjˆj|ˆj	|dˆ_
ˆj
d krªd S d	ˆj
_ˆd k	rÄˆj
jˆ_g }‡fd
d„‰ˆjd k	rfˆjrôˆ jsôd	ˆj
_x4ˆjD ]*}t|dd ƒ}|r| ˆ¡ | ˆ¡ qüW x:ˆˆjƒD ],}	| |	¡ ˆj d k	r6dd |¡ |	_q6W tˆj|dˆ_ˆˆ_d S )Nc             S   s   g | ]\}}|‘qS r&   r&   )r„   r  rr  r&   r&   r'   r†   ¿  s    z5CppClassNode.analyse_declarations.<locals>.<listcomp>c             S   s   g | ]\}}t  || ¡‘qS r&   )r
   rÿ   )r„   r  rŽ  r&   r&   r'   r†   À  s   )rý   c                s$   | j s| jrdS tˆ jd|  ƒ d S )NTz&Base class '%s' not a struct or class.)rì   Ú	is_structr   r%   )Z
base_class)r|   r&   r'   Úbase_okÅ  s    z2CppClassNode.analyse_declarations.<locals>.base_okc                s   g | ]}|  ˆpˆ ¡‘qS r&   )rã   )r„   Úb)r@   r)  r&   r'   r†   Ê  s    )rá   rý   r   c             3   sJ   xD| D ]<}t |tƒr|V  qt |tƒrxˆ |jjƒD ]
}|V  q4W qW d S )N)rH   ÚCFuncDefNoder»   r   rÇ   )rˆ  r•   Zsub_attr)Úfunc_attributesr&   r'   r–  Ô  s    


z:CppClassNode.analyse_declarations.<locals>.func_attributesrŠ  ztemplate <typename %s>z, typename )rÇ   )rý   rˆ  r   r9   Úfilterr  r‘  r%   r  rá   rÃ   rì   r/   râ   rÐ   r/  rˆ   rŠ  r   rþ   r   Útemplate_declarationrÆ   r   r)  )
r|   r@   rp  Ztemplate_namesr“  Zbase_class_typesZdefined_funcsr•   rŠ  rY   r&   )r@   r–  r)  r|   r'   r   »  sD    








z!CppClassNode.analyse_declarationsc             C   s   | j  | jjj¡| _ | S )N)r   ro   rÃ   r/   r)  )r|   r@   r&   r&   r'   ro   ê  s    z CppClassNode.analyse_expressionsc             C   s   | j  | jjj|¡ d S )N)r   r¿   rÃ   r/   r)  )r|   r@   rT   r&   r&   r'   r¿   î  s    z*CppClassNode.generate_function_definitionsc             C   s   | j  |¡ d S )N)r   rÀ   )r|   rT   r&   r&   r'   rÀ   ñ  s    z$CppClassNode.generate_execution_codec             C   s   | j  |¡ d S )N)r   r‘   )r|   rT   r&   r&   r'   r‘   ô  s    zCppClassNode.annotate)
rJ   rj   rk   r†  rŠ  r   ro   r¿   rÀ   r‘   r&   r&   r&   r'   rŒ     s   /rŒ  c               @   s2   e Zd ZdgZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚCEnumDefNoderb   c          	   C   s,   |j | j| j| j| j| j| j| jd| _d S )N)r  r*  rá   rz  r„  )	Zdeclare_enumr9   r%   r  r*  rá   rz  r„  rÃ   )r|   r@   r&   r&   r'   rŠ    s
    zCEnumDefNode.declarec             C   s@   | j d k	r<| jr|jsd| j_x| j D ]}| || j¡ q&W d S )Nr   )rb   râ   rÐ   rÃ   r/  r   )r|   r@   r™   r&   r&   r'   r     s
    
z!CEnumDefNode.analyse_declarationsc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro     s    z CEnumDefNode.analyse_expressionsc          
   C   sª   | j dks| jr¦| | j¡ |jjtjdd}xj| jj	D ]^}| 
d||j| ||j¡f ¡ | |¡ | 
dtj|j|| |j¡f ¡ | |tj¡ q8W |j |¡ d S )NÚpublicT)Ú
manage_refz%s = PyInt_FromLong(%s); %sz.if (PyDict_SetItemString(%s, "%s", %s) < 0) %s)rá   rz  rÊ   r%   Ú	funcstateÚallocate_tempr
   r   rÃ   Úenum_valuesrN   r  Úerror_goto_if_nullÚ
put_gotrefr	   Zmoddict_cnamer9   Ú
error_gotoÚput_decref_clearÚrelease_temp)r|   rT   Útempr™   r&   r&   r'   rÀ     s     
z$CEnumDefNode.generate_execution_codeN)rJ   rj   rk   r‡   rŠ  r   ro   rÀ   r&   r&   r&   r'   r™  ø  s
   r™  c               @   s   e Zd ZdgZdd„ ZdS )ÚCEnumDefItemNoder6   c          
   C   s˜   | j r>| j  |¡| _ | j jjs>| j  tj|¡| _ | j  |¡| _ |j| j|j| j | j	| j
|j|j|jol|jd kd}|j |¡ |jr”|jj |j¡ d S )N)r  rá   rz  r„  )r6   rò   r/   ró   r  r
   r<   Zdeclare_constr9   r%   r  rá   rz  r„  rž  rþ   r÷   )r|   r@   Z
enum_entryrÃ   r&   r&   r'   r   0  s    
z%CEnumDefItemNode.analyse_declarationsN)rJ   rj   rk   r‡   r   r&   r&   r&   r'   r¥  )  s   r¥  c               @   s,   e Zd ZddgZdd„ Zdd„ Zdd„ Zd	S )
ÚCTypeDefNoderB   r6  c             C   sr   | j  |¡}| jj||| j| jd\}}|j}|j}|j||| j|| j| j	d}|j
r\d|_| jrn|jsnd|_d S )N)rá   râ   )r  rá   rz  Tr   )rB   rã   r6  rá   râ   r9   r  rv  r%   rz  rÝ   rÐ   r/  )r|   r@   rå   r#  r/   r9   r  rÃ   r&   r&   r'   r   I  s    z!CTypeDefNode.analyse_declarationsc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   Z  s    z CTypeDefNode.analyse_expressionsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÀ   ]  s    z$CTypeDefNode.generate_execution_codeN)rJ   rj   rk   r‡   r   ro   rÀ   r&   r&   r&   r'   r¦  @  s   r¦  c               @   sØ   e Zd ZdZdZdZdZdZdZdZ	g 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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 ))ÚFuncDefNodeNFc             C   sz   d}xp| j D ]f}|jrVd}|jrB|j |¡|_|j |j|¡|_qrt|jdƒ d |_q|jrbd}q|rt|jdƒ qW d S )Nr   r   z)This argument cannot have a default valuez/Non-default argument following default argument)	rQ   r×   rM  rn   r  r/   r   r%   rN  )r|   r@   Zdefault_seenr2  r&   r&   r'   Úanalyse_default_values„  s    z"FuncDefNode.analyse_default_valuesc             C   s2   |d krd S |j d r$| |¡d kr.| |¡}|S )Nr9  )r¼   r7   rn   )r|   r@   r?   r&   r&   r'   Úanalyse_annotation”  s
    
zFuncDefNode.analyse_annotationc             C   s*   x$| j D ]}|jr|  ||j¡|_qW d S )N)rQ   r?   r©  )r|   r@   r2  r&   r&   r'   Úanalyse_annotationsœ  s    zFuncDefNode.analyse_annotationsc             C   s¶   | j }|j}|j|kr,||j }| |¡}n<t|tƒrd|jrd|jd rd|j}| |¡}|d krh|S n|S |d kr~t	|j
dƒ n4|tk	r¬| |¡s¬t	|jj
dƒ t	|j
dƒ n||_|S )Nr9  z
Not a typez2Signature does not agree with previous declarationzPrevious declaration here)r!  r/   r9   r7   rH   r5  r?   r¼   r?  r   r%   r   r  rB   )r|   r@   r2  r!  Z	orig_typer$  r%  r&   r&   r'   Úalign_argument_type¡  s$    


zFuncDefNode.align_argument_typec             C   s   dS )Nr   r&   )r|   Úlenvr&   r&   r'   Úneed_gil_acquisition¸  s    z FuncDefNode.need_gil_acquisitionc             C   s†   |}x|j s|jr|j}qW | jr<t| jj||| jjd}nt| jj||d}| j	|_	| jj
}|jrt|jop|j |_|| _|j|_|S )N)r9   r~  Úparent_scopeZ
scope_name)r9   r~  r®  )Úis_py_class_scoper  r~  Úneeds_closurer   rÃ   r9   r  r   r  r/   rî   r
  r  Úlocal_scoper¼   )r|   r@   Úgenvr¬  r/   r&   r&   r'   Úcreate_local_scope»  s$    
zFuncDefNode.create_local_scopec             C   s   | j  |¡ d S )N)r   rÀ   )r|   r@   rT   r&   r&   r'   Úgenerate_function_bodyÐ  s    z"FuncDefNode.generate_function_bodyc       '      C   sî  ddl m} | jjr ddl m} | j}|jrD|jsDdtj	tj
f }ntj
}| |¡ | j ||¡ |  ||¡ | jjdko‚| jjj}| jjdko˜| jjj}|p |}	|	r¾d| jkr¾| jdg | _|  ¡ }
|jjd }|jjd	 }|sæ|rú|j t d
d¡¡ | |¡ | ¡ |_|j |j_|  | j!¡ |  "||¡ | #d¡ |
rL| #|
¡ |  $||¡p^| j%}| j&rz| j&j'||dd | j'||d |}x|j(sž|jr¨|j)}qŽW | j*rÔ| +|j,j- .tj	¡¡ | #d¡ nP| j/r$|jr| +|j,j- .tj	¡¡ | #d¡ | +|j,j- .tj
¡¡ | #d¡ |  0||¡ x*|j1D ] }|j2s8|j3s8| 4|¡ q8W d}| jj5sª| jj6rzd}n| jjrŽd|j7 }| #d| j .tj8¡|f ¡ | 9¡ }|  :|¡ | j;}| j*pÎ| j/}x |j<D ]}|j-j6rØd}P qØW dd„ |j=D ƒ}|jo|j>o|p|}|jo0|j>o0| }|j p@|j>}|sN|r`| ?¡  d|j_n|jrx|j>rx| @¡  |s„|r¶| jAs¶| B¡  | jCr¨| jC D|¡nd }| E|¡ |rÆ|  F|¡ |ræ| G¡  |jH| jj|d |rö|  I|¡ | j*rÆtJ Kdd¡}tJ L|j,j-j|¡}|s0d|j,j-jM }| #dtj	|j,j- N¡ ||j,j-jMtjOf ¡ | #dtj	 ¡ | #dtj	|j,j- Pd¡f ¡ | QdtR¡ | #| S| j!¡¡ | #d¡ | Ttj	¡ | #d¡ | j/rT| jUrö| #d ||j,j- N¡ tjVf ¡ n| #d!||j,j- N¡ tjVf ¡ |jr2| #dtj	|f ¡ n"| j*rT| Q||j,j-¡ | W|¡ |s`|r¦| jAsž| jXr~| jjd" }n| jj}|jY|| j!|jj d# d|j_Z|  [||¡ t\| t]ƒ}xx|j<D ]n}|j-j6rü|sèt^|j_ƒdkr0|j2s0| `|¡ n4|rÄ|j-jrÄt^|j_ƒdkrÄ|ja|jb|jjd$ qÄW xN|j1D ]D}|j3r>t^|j_ƒdkr>|j2s>|jcrv| d|¡ n
| `|¡ q>W x8|j1|j< D ](}|j-jer”|jfjgjhr”| i||¡ q”W |  j|¡ x*|j<D ] }|j-jerÒ| k||| j!¡ qÒW |r| l¡  d%|j_|  m||¡ |j | j!d%d& | #d¡ | #d'¡ | jjns¤| jj6rftj8}| o|| j¡ n>| jjp}|rŠ| #dtj8|f ¡ n| jj5s¤| #d(tj8 ¡ |jq|jrk	rÀ| jjnsÈ| s|jt¡ | u|jq¡ x,|j v¡ D ]\} }!|jw| |!|j d$ qàW t^|ƒd)k}"|"rn|j tx¡ | #d*¡ | #d+¡ | #d,¡ | #d-¡ x|D ]}| y||¡ qNW | #d.¡ | jjrŽ| ztj8|¡ tj8}#n|  {¡ }#|  |¡ }$|#d k	s®|$	r|jrÐ|j>sÐ| #d/¡ | ?¡  | }| jj~¡ |j	r,|j>	s,| l¡  | #d¡ n*t| jj!d0| jj~ d)ƒ | €| jj~|j¡ | jjp}%|#d k	rH|%	rH|%}#|#d k		rt|#tj8k	rŽ| #dtj8|#f ¡ n| jj5	sŽ| #d(tj8 ¡ |	rž|  |¡ |"	s´|	s´| jj	rÀ| s|j¡ | u|jt¡ x|D ]}| y||¡ 	qÒW |	rø|  ‚|¡ | jj
rX| ƒ| j „tj8¡¡}&| #d1|& ¡ |j
r4| ?¡  | #d2¡ |j
rN| l¡  | #d¡ | u|j¡ x„|j1D ]z}|jh
rl|j2
r„
ql|j-j
r¤|j…|jb|j d$ n@|j-j6
rl|j3
rÆt^|j_ƒdk
rl|jc
rÚ| †|¡ n
| ‡|¡ 
qlW xx|j<D ]n}|j-j6r*|st^|j_ƒdkr^|j2s^| ‡|¡ n4|j-j
rò|rJt^|j_ƒdk
rò|j…|jb|j d$ 
qòW | j*r~| ˆtj	|j,j-¡ |jsÈ| jjp}%|  {¡ }#|#d krª|%rª|%}#| jj6rÈ| ‰| j Štj8¡¡ | jj‹rö| jjd3krö| #d4tj8tj8f ¡ |s|rHd%|j_Z| jAsH| jj6r4|jŒtj8|jj d# n|jŒd|jj d# |jsX| ¡  |sn|jr~|j>r~| l¡  d%|j_| jj5s˜| #d5tj8 ¡ | #d¡ |
r¶| #d6|
 ¡ | Ž|j¡ | ¡  | j&rà| j& ||¡ |  |¡ d S )7Nr   )rl  )r`  z%s->%sÚ__getbuffer__Ú__releasebuffer__Zcython_unusedÚprofileÚ	linetraceZProfilez	Profile.cr§   T)Úwith_pymethdefÚ
proto_only)r¹  ú;z = NULLz = z%s%s;c             S   s   g | ]}|j r|‘qS r&   )r0  )r„   rÃ   r&   r&   r'   r†   :  s    z=FuncDefNode.generate_function_definitions.<locals>.<listcomp>)Úacquire_gilZtp_newrd   z
%s->tp_newz%s = (%s)%s(%s, %s, NULL);zif (unlikely(!%s)) {z%s = %s;ÚPy_Nonez} else {Ú}z*%s = (%s) __Pyx_CyFunction_GetClosure(%s);z%s = (%s) %s;z
 (wrapper))r
  )Úhave_gilF)Útracez/* function exit code */z!__Pyx_pretend_to_initialize(&%s);r   z0{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;Ú__Pyx_PyThreadState_declareÚ__Pyx_PyThreadState_assignz5__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);z5__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}Ú{z&Unraisable exception in function '%s'.z	if (%s) {zOPyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");Ú__hash__z5if (unlikely(%s == -1) && !PyErr_Occurred()) %s = -2;z
return %s;z#endif /*!(%s)*/)‘r§   rl  r  r€  r`  r±  Úis_closure_scopeZis_passthroughr	   Úcur_scope_cnameÚouter_scope_cnameZmangle_closure_cnamesr   r¿   rÅ   rÃ   r9   r)  r  r{  Úget_preprocessor_guardr¾   r¼   rc  r   Úload_cachedÚenter_cfunc_scopeÚ	new_labelÚreturn_from_error_cleanup_labelr
  rœ  Ú	gil_ownedrÊ   r%   rÄ   rN   Úneeds_assignment_synthesisÚpymethdef_requiredÚpy_funcÚgenerate_function_headerr¯  r~  r°  ÚputÚscope_classr/   rÜ   Úneeds_outer_scopeÚgenerate_argument_declarationsr‹  Ú
in_closurer3   Úput_var_declarationrÛ   r:   Zmemslice_entry_initÚretval_cnameÚinsertion_pointÚgenerate_keyword_listr¼  Úarg_entriesZbuffer_entriesÚhas_with_gil_blockÚput_ensure_gilÚdeclare_gilstateÚis_generatorÚput_trace_declarationsÚcode_objectÚcalculate_result_codeÚput_trace_frame_initÚgetbuffer_checkÚput_declare_refcount_contextÚput_setup_refcount_contextÚgetbuffer_initr   ZConstructorSlotZget_slot_functionÚtypeptr_cnamer;  Úempty_tuplerB  Ú
put_increfr   r¡  r   Úis_cyfunctionÚ
self_cnamerF  r¶   Úput_trace_callÚ	can_traceÚgenerate_argument_parsing_coderH   r•  rG   Úcf_assignmentsÚput_var_increfÚput_incref_memoryviewslicer  Úxdecref_cleanupZput_var_xincrefrÚ   Z
buffer_auxZbuflocal_nd_varr0  Zput_init_varsÚgenerate_argument_type_testsZput_acquire_arg_bufferÚput_release_ensured_gilr´  rµ   Úput_init_to_py_noner@  Úerror_labelÚlabels_usedÚput_gotoÚreturn_labelÚ	put_labelÚall_managed_tempsÚput_xdecrefÚrestore_exception_utility_codeZput_release_buffer_codeZput_init_entryÚerror_valueÚcaller_will_check_exceptionsÚput_add_tracebackÚqualified_namer   Zput_unraisableÚgetbuffer_error_cleanupÚgetbuffer_normal_cleanupÚunlikelyZerror_conditionÚput_xdecref_memoryviewsliceZput_var_xdecrefÚput_var_decrefÚ
put_decrefÚput_xgiverefÚas_pyobjectÚ
is_specialÚput_trace_returnÚput_finish_refcount_contextÚput_temp_declarationsÚexit_cfunc_scopeÚgenerate_wrapper_functions)'r|   r@   rT   rl  r`  r¬  rÇ  Zis_getbuffer_slotZis_releasebuffer_slotZis_buffer_slotÚpreprocessor_guardr·  r¸  r¹  ÚcenvrÃ   ÚinitÚtempvardecl_coder¼  Zhave_object_argsr2  Zused_buffer_entriesZacquire_gil_for_var_decls_onlyZacquire_gil_for_refnanny_onlyZuse_refnannyrá  Ztp_slotZslot_func_cnameZ
trace_namer|  ÚlhsÚvalr  r/   Zbuffers_presentÚerr_valr&  Zdefault_retvalÚcondr&   r&   r'   r¿   Ó  sF   





























  






























z)FuncDefNode.generate_function_definitionsc             C   sh   |j jrt|jdƒ n,|j  ¡ sB|j jsB|j jsBt|jd|j  ƒ | |j|j |j¡}|j	rd|j	|_	|S )NzInvalid use of 'void'z Argument type '%s' is incomplete)
r/   rÛ   r   r%   rö   rÙ   r€  Zdeclare_argr9   r?   )r|   r@   r2  rÃ   r&   r&   r'   Údeclare_argument€  s    zFuncDefNode.declare_argumentc             C   sv   |j  ¡ rf|j t dd¡¡ |j j}d|jj }| 	d|||j
|j|j joR|j j| |j¡f ¡ nt|jdƒ d S )NZArgTypeTestzFunctionArguments.cz((PyObject *)%s)z:if (unlikely(!__Pyx_ArgTypeTest(%s, %s, %d, "%s", %s))) %szICannot test type of extern C class without type object name specification)r/   Ztypeobj_is_availabler¾   rc  r   rÉ  rè  rÃ   r  rN   Úaccept_noner9   Úis_builtin_typeZrequire_exactr¡  r%   r   )r|   r2  rT   rè  Úarg_coder&   r&   r'   Úgenerate_arg_type_testŠ  s    
z"FuncDefNode.generate_arg_type_testc             C   sd   |j jrd|jj }n|jj}| d| ¡ | dtdt|jƒƒ|j| |j	¡f ¡ | d¡ d S )Nz
%s.memviewz,if (unlikely(((PyObject *)%s) == Py_None)) {zMPyErr_Format(PyExc_TypeError, "Argument '%%.%ds' must not be None", "%s"); %séÈ   r¾  )
r/   r€  rÃ   r  rN   r“   rG   r9   r¡  r%   )r|   r2  rT   r  r&   r&   r'   Úgenerate_arg_none_checkœ  s    z#FuncDefNode.generate_arg_none_checkc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   r  ©  s    z&FuncDefNode.generate_wrapper_functionsc             C   s0   |  | j¡ x| jD ]}|js| |¡ qW d S )N)rÊ   r%   rQ   rQ  rK  )r|   rT   r2  r&   r&   r'   rÀ   ¬  s    z#FuncDefNode.generate_execution_codec          	   C   sH   | j jd }y|jjjjd j}W n ttfk
r>   d }Y nX ||fS )Nr   Úobj)r±  rÛ  r/   rB   r)  rÂ   r’   ÚKeyError)r|   Ú	py_bufferÚobj_typer&   r&   r'   Ú_get_py_buffer_info¶  s    
zFuncDefNode._get_py_buffer_infoc             C   sB   |   ¡ \}}|j}| d| ¡ | d¡ | d¡ | d¡ d S )Nzif (%s == NULL) {zZPyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");z
return -1;r¾  )r$  r  rN   )r|   rT   r"  rr  Úviewr&   r&   r'   rä  Æ  s    

zFuncDefNode.getbuffer_checkc             C   sN   |   ¡ \}}|j}|r<|jr<| d| |¡ | d| ¡ n| d| ¡ d S )Nz%s->objz%s->obj = NULL;)r$  r  r:   rö  rF  rN   )r|   rT   r"  r#  r%  r&   r&   r'   rç  Ï  s    
zFuncDefNode.getbuffer_initc             C   sf   |   ¡ \}}|j}|rT|jrT| d| ¡ | d| ¡ | d| |¡ | d¡ n| d| ¡ d S )Nzif (%s->obj != NULL) {z%s->objr¾  zPy_CLEAR(%s->obj);)r$  r  r:   rN   r   r¢  )r|   rT   r"  r#  r%  r&   r&   r'   r  Ø  s    
z#FuncDefNode.getbuffer_error_cleanupc             C   sV   |   ¡ \}}|j}|rR|jrR| d| ¡ | d| ¡ | d| |¡ | d¡ d S )Nzif (%s->obj == Py_None) {z%s->objr¾  )r$  r  r:   rN   r   r¢  )r|   rT   r"  r#  r%  r&   r&   r'   r  ã  s    
z$FuncDefNode.getbuffer_normal_cleanupc             C   s`   | j jsd S | j j}tj |¡}|s(d S |dkrB| j j d¡sBd S |dkrX| j jjrXd S | 	¡ S )NZ__long__Ú__int__)rµ  r¶  )
rÃ   r  r9   r   Úmethod_name_to_slotÚgetr)  rf  r  Úpreprocessor_guard_code)r|   r9   Úslotr&   r&   r'   rÈ  ì  s    z"FuncDefNode.get_preprocessor_guard)#rJ   rj   rk   rÐ  r°  rÔ  rÏ  rß  Úis_generator_bodyZis_async_defr{  Úhas_fused_argumentsÚstar_argÚstarstar_argrë  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§  a  sF      0

			r§  c                   sò   e Zd ZddddgZdZdZdZdZdZdZ	dZ
dZdd„ Zed	d
„ ƒZdd„ Zdd„ Zdd„ Zd3dd„Zdd„ Zdd„ Zdd„ Zdd„ Zd4dd„Zd5d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/d0„ Z d1d2„ Z!‡  Z"S )6r•  rB   r6  r   Úpy_func_statFNc             C   s   | j jS )N)rÃ   r9   )r|   r&   r&   r'   Úunqualified_name	  s    zCFuncDefNode.unqualified_namec             C   s   | j r| j jS d S )N)rÐ  rá  )r|   r&   r&   r'   rá   	  s    zCFuncDefNode.code_objectc             C   sR  |j | _| jd kri | _| j |j di ¡¡ | jd k	rb| j |¡}|d krnt| jj	dƒ t
j}n| j |¡}d|jko‚| d¡ | _t| jtƒr¼| jj||d| jd k	 | j| jd\}}n$| jj||d| jd k	 | jd\}}|jsòt| j	dƒ || _| j|_| j}xt|dƒs|j}qW || _|j| _| jj}| jd	ksJ| jr^|r^t| jj	d
ƒ |jdkr„| jdkr„t | jj	dƒ xÌt!| j|jƒD ]º\}}|  "||¡ |j|_|j#|_#|j$|_$|  %|j|j	|¡ |jj&râd| _'|jj(rd| j)krt |j	ddƒ |jj(s|jj*r”| jj+r2t|j	dƒ nd| j)kr”t |j	ddƒ q”W |  %|j,| j	|¡ |j#}	|j$}
| j-|_-| j|_|j.|	|| j	|
| j| j| jd k	| j)| jd	| _/| j0| j/_1|j,| _,| j,j2râ| jdkrât| j	dƒ | j,j3rü| j, 4| j	d¡ | jr:|j5s:| js:t6| jƒdk s4| jd jj7s:d| _|  8|¡ |  9|¡ d S )NÚlocalsz
Not a typerË   r"   )rà   r!  rá   )rà   rá   z*Suite attached to non-function declarationrQ   rš  zBFunction with optional arguments may not be declared public or apir  r  z/Only extern functions can throw C++ exceptions.TZinlinez$Buffer unpacking not optimized away.r   zUBuffer may not be acquired without the GIL. Consider using memoryview slices instead.)r  rá   rz  Údefiningr{  r   zFunction cannot return an arrayzused as a return valuer   F):r  Úis_c_class_methodr!  r{   r¼   r(  Údirective_returnsr7   r   r%   r
   r   rB   rã   rf  r  rH   r6  rú   r   rá   rî   r/   r   r  r<  rå   Zcfunc_declaratorrQ   r  rz  r	  r   Úzipr«  r9   r  Ú_validate_type_visibilityrÝ   r,  rÚ   r{  Úis_pythran_exprr
  r  r  r‚  rÃ   Úinline_in_pxdZinline_func_in_pxdrÙ   rì   Zcheck_nullary_constructorr  rG   r:   Údeclare_cpdef_wrapperr³  )r|   r@   rB   r#  r/   r6  Zopt_arg_countÚ
formal_argÚtype_argr9   r  r&   r&   r'   r   %	  sŒ    






 
z!CFuncDefNode.analyse_declarationsc             C   sH  | j rD| jrt| jdƒ | jj}| j|jd}| jrnddlm	} t
| j|| jdddg}|d j |¡ ng }t| j| jj| jd d | j||dd		| _|j| j_| j |¡ d
| jj_t| j| jgd| _tj| j_| jj| j_d
 | j_| jj_| j|j|< | jjsD|jrtjrDt| j| jd| _t| j| j| j gd| _ d S )Nz&static cpdef methods not yet supported)r  r   )rü   rË   )r9   )Ú	decoratorr   )	r%   r9   rQ   r-  r.  r-   r   r†  r¶   T)rÇ   )rÐ  )!r   r  r   r%   rÃ   r9   Úcall_self_noder  rï   rü   ÚDecoratorNoder<  rn   ÚDefNoderQ   r-   rÐ  r   r  rÆ   r/  r
   r   r/   Úas_variabler0  rÂ   Úis_final_cmethodr   Úlookup_module_cpdefÚOverrideCheckNodeÚoverrider   )r|   r@   r9   Zpy_func_bodyrü   r†  r&   r&   r'   r9  ‚	  s>    




z"CFuncDefNode.declare_cpdef_wrapperc             C   sN   | j dkp| j}t|ddƒ}|rJ|rJ|jrJ|j dksJ|jsJ|jsJt|dƒ dS )zo
        Ensure that types used in cdef functions are public or api, or
        defined in a C header.
        rš  rÃ   N)rš  r  z:Function declared public or api may not have private types)rá   rz  rˆ   r  rÐ   r   )r|   r/   r%   r@   Zpublic_or_apirÃ   r&   r&   r'   r6  ¦	  s    
z&CFuncDefNode._validate_type_visibilityr   c                s*  ddl m‰  ˆjj}|r0|d t|ƒˆjj … }dd„ |D ƒ}|rbˆ jˆjˆjj	d}|}t
j}n†ˆjjrªˆjjjj}ˆ jˆj|j	d}	||	_ˆ jˆj|	ˆjj	d}d}n>ˆjjd jj}
ˆ jˆj|
j	d}|
|_ˆ jˆj|ˆjj	d}| pòt
j}ˆ jˆj|‡ ‡fd	d„|D ƒ|d
}tˆjtj|dS )Nr   )rï   c             S   s   g | ]
}|j ‘qS r&   )r9   )r„   r2  r&   r&   r'   r†   ·	  s    z/CFuncDefNode.call_self_node.<locals>.<listcomp>)r9   )r   Z	attributeTr   c                s   g | ]}ˆ j ˆj|d ‘qS ))r9   )rü   r%   )r„   Ún)rï   r|   r&   r'   r†   Í	  s    )ÚfunctionrQ   Zwrapper_call)r%   r  r6   )r§   rï   r/   rQ   rG   r  rü   r%   rÃ   r9   r   rB  r  r)  r  ZAttributeNodeÚSimpleCallNodeÚReturnStatNoder
   r   )r|   Zomit_optional_argsr  rQ   Z	arg_namesÚcfuncZcall_arg_namesZskip_dispatchZclass_entryZ
class_noderh  r;  Zc_callr&   )rï   r|   r'   r=  ²	  s4    zCFuncDefNode.call_self_nodec             C   s4   x.| j jD ]"}|js t|jdƒ |  ||¡ q
W d S )NzMissing argument name)r/   rQ   r9   r   r%   r  )r|   r@   r2  r&   r&   r'   Údeclare_argumentsÑ	  s    zCFuncDefNode.declare_argumentsc             C   s   | j jS )N)r/   r  )r|   r¬  r&   r&   r'   r­  ×	  s    z!CFuncDefNode.need_gil_acquisitionc             C   sZ   | j }|j}|jrV|sV|jjr*t| jdƒ x*| jjD ]}|j jr4|j	s4t| jdƒ q4W d S )Nz9Function with Python return type cannot be declared nogilz8Function declared nogil has Python locals or temporaries)
r/   r  r
  r  r:   r   r%   r±  r‹  Zin_with_gil_block)r|   r@   r/   r  rÃ   r&   r&   r'   r¹   Ú	  s    
zCFuncDefNode.nogil_checkc             C   sd   |j | j_ | jd k	r$| j |¡| _n.| jd k	r>| j |¡| _n|  |¡ |  |¡ |  | j¡| _| S )N)	r¼   r±  r/  ro   rÐ  r¨  rª  r­  r¼  )r|   r@   r&   r&   r'   ro   å	  s    




z CFuncDefNode.analyse_expressionsc             C   s   dS )NFr&   )r|   r@   rT   r&   r&   r'   rÎ  ó	  s    z'CFuncDefNode.needs_assignment_synthesisr   c             C   s¤  | j }g }| j}xN|jd t|jƒ|j … D ]0}	|	 ¡ }
| |	j¡}|jsRd|
 }
| 	|
¡ q,W |r˜| j
r˜tj tj¡}| jrŠ| 	|¡ n| 	d| ¡ |jr¶|r¶| 	|j tj¡¡ |jrÆ| 	d¡ |sÐdg}|d krà| jj}| |d |¡¡}| jjdkrd|krd}nd}d }| | jj¡}| jj||d	}| j}| jrj|r^|jjd
  | j¡ | | j¡ |rŒ|jjd
  d|||f ¡ | d|||f ¡ d S )NzCYTHON_UNUSED %sz...Úvoidz, Úprivatez::zstatic r§   )Údll_linkageZmodule_declarationsz%s%s%s; /* proto*/z%s%s%s {) r±  r/   rQ   rG   r  rÜ   rW  r9   Úcf_usedrþ   r   r
   r<   r	   Úskip_dispatch_cnamerD  r1  Úoptional_args_cnamer  rÃ   Ú
func_cnameZfunction_header_coder   rá   Zbuild_function_modifiersZfunc_modifiersr  r3  r˜  r¾   ÚpartsrN   )r|   rT   r¹  Úwith_opt_argsÚwith_dispatchr  r)  Z	arg_declsr/   r2  Zarg_declrÃ   Zdispatch_argZentityZstorage_classrM  r{  ÚheaderZneeds_protor&   r&   r'   rÑ  ö	  sN     


z%CFuncDefNode.generate_function_headerc             C   s^   | j }xR| jD ]H}|jr| |j¡}| js0|jr| |¡}| d|j	 
|j¡|f ¡ qW d S )Nz%s = %s;)r±  rQ   r×   rW  r9   rD  rN  rC  rN   r/   rÜ   r  )r|   r@   rT   r)  r2  rÃ   r‹   r&   r&   r'   rÕ  #
  s    
z+CFuncDefNode.generate_argument_declarationsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÚ  -
  s    z"CFuncDefNode.generate_keyword_listc       
   	      s  d}d}| j }| jjràˆ dtj ¡ x’| jD ]ˆ‰ ˆ jr.| ˆ j	¡}| j
sP|jr®ˆ dtjtj|f ¡ ˆ j}xt|dƒs‚|j}qpW ˆ dˆ jtj| j |j	¡f ¡ |d7 }|d7 }q.W xt|ƒD ]}ˆ d¡ qÄW ˆ d¡ ‡ ‡fdd	„}	x| jD ]‰ |	| ˆ j	¡ƒ qöW d S )
Nr   z	if (%s) {zif (%s->%sn > %s) {r9   z%s = %s->%s;r   r¾  c                s:   | j r6ˆ js6ˆ d| j| jf ¡ ˆ | ¡ ˆ | ¡ d S )Nz%s = %s;)rÖ  r×   rN   r  Úoriginal_cnamerñ  Úput_var_giveref)rÃ   )r2  rT   r&   r'   Úput_into_closureJ
  s    
zECFuncDefNode.generate_argument_parsing_code.<locals>.put_into_closure)r±  r/   r  rN   r	   rP  rQ   r×   rW  r9   rD  rN  r+  r6  r<  rå   r  Zopt_arg_cnameÚrangerf  )
r|   r@   rT   r"  r0  r)  rÃ   r6  rr  rX  r&   )r2  rT   r'   rï  0
  s4    

z+CFuncDefNode.generate_argument_parsing_codec             C   s   d S )Nr&   )r|   rT   r&   r&   r'   Ú!generate_argument_conversion_codeS
  s    z.CFuncDefNode.generate_argument_conversion_codec             C   sD   x>| j jD ]2}|jr"|  ||¡ q
|j jr
|js
|  ||¡ q
W d S )N)r/   rQ   Úneeds_type_testr  r:   r  r  )r|   rT   r2  r&   r&   r'   rô  V
  s
    z)CFuncDefNode.generate_argument_type_testsc                s&   t t| ƒ |¡ | jr"| j |¡ d S )N)rc   r•  rÀ   r/  )r|   rT   )rI   r&   r'   rÀ   _
  s    z$CFuncDefNode.generate_execution_codec             C   s   | j jrdS | jjjS d S )NÚ0)r  r:   rÃ   r/   rû   )r|   r&   r&   r'   rÿ  d
  s    zCFuncDefNode.error_valuec             C   s
   | j jjS )N)rÃ   r/   r	  )r|   r&   r&   r'   r   k
  s    z)CFuncDefNode.caller_will_check_exceptionsc             C   s   d}| j }|j}x|jd k	r|d7 }|j}d| j jtj|f |_| ¡  | j|d|jj|jj	|jd | j
js|| d¡ | jj}dd„ |d t|ƒ| jj	 … D ƒ}|jjr¼| tj¡ n|jrÌ| d¡ |jj	râ| tj¡ n|j	rò| d	¡ | d
| j jd |¡f ¡ | d¡ qW d S )Nr   r   z%s%swrap_%s)rT  rS  r  zreturn c             S   s   g | ]
}|j ‘qS r&   )r  )r„   r2  r&   r&   r'   r†   
  s    z;CFuncDefNode.generate_wrapper_functions.<locals>.<listcomp>r\  ÚNULLz%s(%s);z, r¾  )rÃ   r/   Z
prev_entryrQ  r	   r+  rN   rÑ  r  r  r  rÛ   rÒ  rQ   rG   rþ   rO  rP  r   )r|   rT   ÚkrÃ   r  rQ   Zarglistr&   r&   r'   r  n
  s6    

"

z'CFuncDefNode.generate_wrapper_functions)r   r   )N)r   r   N)#rJ   rj   rk   r‡   r8  r†  r!  r4  rD  r˜  r  r/  r0  Úpropertyrá  r   r9  r6  r=  rJ  r­  r¹   ro   rÎ  rÑ  rÕ  rÚ  rï  rZ  rô  rÀ   rÿ  r   r  rl   r&   r&   )rI   r'   r•  ú  s<   ]$


-
#	r•  c               @   s    e Zd Zg ZdZdZdd„ ZdS )ÚPyArgDeclNodeFc             C   s   | j  ||¡ d S )N)rÃ   r¿   )r|   r@   rT   r&   r&   r'   r¿   ™
  s    z+PyArgDeclNode.generate_function_definitionsN)rJ   rj   rk   r‡   r  rL  r¿   r&   r&   r&   r'   r`  Ž
  s   r`  c               @   s   e Zd ZdgZdS )r>  r<  N)rJ   rj   rk   r‡   r&   r&   r&   r'   r>  
  s   r>  c               @   s&  e Zd ZddddddgZddg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d„ Zd6d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%d7d$d%„Z&d&d'„ Z'd(d)„ Z(d*d+„ Z)d8d,d-„Z*d.d/„ Z+d0d1„ Z,d2d3„ Z-d4d5„ Z.dS )9r?  rQ   r-  r.  r   r†  Úreturn_type_annotationFNr\  r   Tc             K   sl   t j| |f|Ž d } }}x8| jD ].}|jrD|d7 }|jsD|d7 }|js$|d7 }q$W || _|| _|| _d S )Nr   r   )r§  r~   rQ   rN  r×   Únum_kwonly_argsÚnum_required_kw_argsÚnum_required_args)r|   r%   rR   r^  ZrkÚrr2  r&   r&   r'   r~   Ö
  s    zDefNode.__init__c	             C   s  | j rt| j jdƒ | jr(t| jjdƒ |p.d\}	}
|d kr¬g }x@| jD ]6}|j|dd\}}| tj|j	d |j
t|jd¡ qHW tjt|dd |
|||d}t| j|d	}n°|d krº|j}|j}t| jƒt|jƒksÚ|jròt| jd
ƒ t|jdƒ xhtt| j|jƒƒD ]R\}\}}|j|d|dko(|jd\}}|d ksH|tjkr|j|_||_qW |	d kr’|jd k	r’ddlm} || j|j|jd}	t| jt| j| j	d d| jd|j|	|j|jd}t| j|pÐg t | j|jd	|| j!| j"|j#||j|jddt$|di ƒ|dS )Nz'cdef function cannot have star argumentz+cdef function cannot have starstar argument)NFr   )rà   )r9   r  r?   r/   r%   F)r  rQ   r  rû   r	  r
  r  r  )r/   zwrong number of argumentszprevious declaration herer   )rà   r  )r  )r6   r/   )r9   r  )rå   rQ   r  r	  rû   r  r
  rL  r!  )r{  rB   r6  r   r-   r   r/   r  r
  rá   rz  r!  r4  )%r-  r   r%   r.  rQ   rã   rþ   r
   r  r9   r?   r   r  rÎ   r)  r/   rG   r  r  r5  r  r#  rû   rï   r  r  rú   rÖ   r	  r  r
  r•  r>   r   r-   r  rˆ   )r|   rI  r)  r   ZreturnsZ
except_valr{  r
  r  rû   r	  Z
cfunc_argsr:  r#  r/   Z
cfunc_typer"  r;  r  r6  r&   r&   r'   Úas_cfunctionä
  sz     

zDefNode.as_cfunctionc             C   s   | j r
dS | js| jrdS dS )z·Determines if the function's signature is compatible with a
        cdef function.  This can be used before calling
        .as_cfunction() to see if that will be successful.
        FT)r°  r-  r.  )r|   r&   r&   r'   Úis_cdef_func_compatible'  s
    zDefNode.is_cdef_func_compatiblec          	   C   s\  | j rJxB| j D ]8}|j}|jr|  j|jdkO  _|  j|jdkO  _qW | jr`| d¡r`d| _| jrv| d¡rvd| _| jdkrŒ|jrŒd| _|  |¡ | jdkr¬|  	|¡ n
|  
|¡ |  |¡ | jj ¡ | _| jtkr| jr|jd r| jjst| j|ƒ\}}|r|jr|| _|  |¡ t| j| | jj| j| j| j| jd| _| j |¡ d S )	NÚclassmethodrË   Frd   r   z<lambda>r9  )rI  r9   rQ   r-  r.  r  )r†  r<  r8   Úis_classmethodr9   Úis_staticmethodrf  r¯  Úanalyse_argument_typesÚdeclare_lambda_functionÚdeclare_pyfunctionÚanalyse_signaturerÃ   Ú	signaturer  r   ra  r¼   r  rD   r:   r³  ÚDefNodeWrapperr%   rQ   r-  r.  Ú
py_wrapperr   )r|   r@   r<  rY   rr  r  r&   r&   r'   r   2  sB    




zDefNode.analyse_declarationsc             C   sÔ  |j  di ¡| _|j d }|j}d |_xx| jD ]l}t|dƒrFd }nV|j |¡}t|ƒrp|j	rpt
 ||jg¡}|j ||¡\}}|j|_||_|jrœd| _|  ||¡ |r¾|jr¾t| jdƒ |j ¡ |_d |_d|_d|_d|_|jjsü|jjsü|jjrr|jrd|_nd|j rd|_nT|jj!sD|jj"sD|jjsD|jjrj|j#rb|j#j$d krbd|_n||_nd|_q0d|_|j rŒt|jd	ƒ |jr0t|jd
ƒ q0W ||_t|ƒrÊdd„ t%| jƒD ƒ| _&ng | _&d S )Nr1  Úallow_none_for_extension_argsr9   Tz9Python function argument cannot have C name specificationr   r   Fz.Only Python type arguments can have 'not None'z-Only Python type arguments can have 'or None'c             S   s   g | ]\}}|j jr|‘qS r&   )r/   Zis_numpy_buffer)r„   r"  Úar&   r&   r'   r†   ›  s    z2DefNode.analyse_argument_types.<locals>.<listcomp>)'r¼   r(  r!  rÞ   rQ   r<  rB   rã   r   r7  r
   rw  Z
org_bufferr6  r9   r/   rÝ   r,  r«  r  r   r%   Zas_argument_typeÚhdr_typeÚneeds_conversionr[  rM  r:   rÚ   r€  rP  r  rO  Úis_extension_typer  r×   Úconstant_resultr  Únp_args_idx)r|   r@   rr  Zf2sr2  r#  rB   r/   r&   r&   r'   rk  _  sZ    




zDefNode.analyse_argument_typesc             C   s2  | j jr<| jrt| jdƒ t| jƒdko4| jp2| j | j _	nÞ|j
d s| js| js| j jtjkr¶t| jƒdkr€tj| j _n4t| jƒdkr´| jd jd kr´| jd js´tj| j _nd| j jtjkrt| jƒdkràtj| j _n:t| jƒdkr| jd jd kr| jd jstj| j _| j j}| ¡ }|tjkrp|dkrpt| jƒdkrp| jrptj }| j _d| _d}| jr®|jr®d}d| _t |¡ | j _}d|_d|_d|_| js¾| jrÜ| jrÜ|jrÜ| jjd d …= xàt t!|t| jƒƒƒD ]È}| j| }d|_"| #|¡rT| jsT| jr8d|_$t%j& |_'|_(nd|_#|j) |_'|_(d|_*n>| +|¡|_'|j( ,|j'¡s’|j'j-rŒ|j(j-rŒd|_.nd|_*|j*rªt/j0|j1 |_2nt/j3|j1 |_2qòW |t| jƒkrÚ|  4¡  d S |t| jƒk r.|jsú|  4¡  x2| jD ](}|j"r|j(j5s"|j(j6rd|_.qW d S )Nz8special functions of cdef classes cannot have decoratorsr   Zalways_allow_keywordsr   r"   Tr  )7rÃ   r  r†  r   r%   rG   rQ   r-  r.  Ztrivial_signaturer¼   ro  r   Zpyfunction_signatureZpyfunction_noargsr×   rN  Zpyfunction_oneargZpymethod_signatureZ	unaryfuncZibinaryfuncÚnum_fixed_argsÚself_in_starargrj  r  r   Zfixed_arg_formatÚhas_generic_argsri  r,  Zdecorator_indirectionrÇ   rY  ÚminrM  r  rL  r   Z	type_typert  r/   r  ru  Zfixed_arg_typer  r:   r[  r	   Z
arg_prefixr9   Ú	hdr_cnameZ
var_prefixÚbad_signaturerv  r  )r|   r@   ÚsigZnfixedr"  r2  r&   r&   r'   rn  Ÿ  sz    " 

zDefNode.analyse_signaturec             C   sj   | j j}d| ¡  }|jr"|d7 }| j}| d¡rB| d¡rBd}nd}t| jd|| jt	| j
ƒ|f ƒ d S )Nz%dz or moreÚ__zSpecial methodZMethodz>%s %s has wrong number of arguments (%d declared, %s expected))rÃ   ro  ry  r{  r9   Ú
startswithÚendswithr   r%   rG   rQ   )r|   r  Zexpected_strr9   Zdescr&   r&   r'   r~  ì  s    zDefNode.bad_signaturec             C   s   | j }| |¡}|rP|jr.|jjs.t| jdƒ |jjrP|j	sP| j
sPt| jddƒ |j|| j| j
 d}|| _| |j¡}tj| | | j_tjröt| j| jƒ|_tj| | |_|jrü|j tjksÜ|jrÜ|j dkrä|jd räd |_qütj| | |_nd |_d S )Nz:Only final types can have final Python (def/cpdef) methodsz'Overriding cdef method with def method.é   )Zallow_redefineÚ__getattr__Zfast_getattr)r9   rf  rA  r  Úis_final_typer   r%   r/   rî   Zis_builtin_cmethodr¶   r   rm  rÃ   Únext_idÚscope_prefixr	   Zpyfunc_prefixÚpyfunc_cnamer   r…  r.   r-   Zfuncdoc_prefixÚ	doc_cnamer  r   Z	invisibler¼   Úwrapperbase_cnameZwrapperbase_prefix)r|   r@   r9   rÃ   Úprefixr&   r&   r'   rm  ù  s(    
zDefNode.declare_pyfunctionc             C   s*   |  | j| j¡}d |_|| _|j| j_d S )N)rl  Úlambda_namer%   r-   rÃ   r  rˆ  )r|   r@   rÃ   r&   r&   r'   rl    s    zDefNode.declare_lambda_functionc             C   s˜   xv| j D ]l}|jst|jdƒ |jrL| |j|j|j¡|_|jjrZd|j_	n|  
||¡|_d|j_d|j_|j|j_qW |  || j¡ |  || j¡ d S )NzMissing argument namer\  r   )rQ   r9   r   r%   ru  r,  r/   rÃ   r:   r  r  r3   r0  r  Údeclare_python_argr-  r.  )r|   r@   r2  r&   r&   r'   rJ    s    
zDefNode.declare_argumentsc             C   sR   |rN|j d dkrtj}nt}| |j||j¡}d|_d|_d|_	d|_
||_d S )NZinfer_typesFr   r\  )r¼   r
   Zunspecified_typer   r,  r9   r%   r3   r0  r  ró  rÃ   )r|   r@   r2  r/   rÃ   r&   r&   r'   r  (  s    zDefNode.declare_python_argc             C   s|   |j | j_ |  |¡ |  |¡ | jr4|  || j¡| _|  |¡sl| jrlx&| jd d d… D ]}|j 	|¡|_qVW | j
 |¡ | S )Nrª   )r¼   r±  r¨  rª  ra  r©  rÎ  r†  r<  ro   rq  Úprepare_argument_coercion)r|   r@   r<  r&   r&   r'   ro   5  s    


zDefNode.analyse_expressionsc             C   sv   | j r
dS | js| jjrdS | jr&dS | jjr2dS | jjr>dS |jsJ|jrj|d kr^| j	j
d S |jj
d S |jpt|jS )NTFZbinding)rj  Úspecialized_cpdefsrÃ   Zis_fused_specializedÚno_assignment_synthesisr  Zis_anonymousr  r  r±  r¼   r¾   r¯  rÅ  )r|   r@   rT   r&   r&   r'   rÎ  C  s    z"DefNode.needs_assignment_synthesisc             C   s
   | j jjS )N)rÃ   ro  rÿ  )r|   r&   r&   r'   rÿ  U  s    zDefNode.error_valuec             C   s
   | j jjS )N)rÃ   ro  r	  )r|   r&   r&   r'   r   X  s    z$DefNode.caller_will_check_exceptionsc             C   sJ   | j r| j  | ¡ |¡ | jr8| jj| j_| j ||¡ t | ||¡ d S )N)Údefaults_getterr¿   rÁ   Úpy_wrapper_requiredrÃ   rQ  rq  r§  )r|   r@   rT   r&   r&   r'   r¿   [  s    z%DefNode.generate_function_definitionsc             C   s  |r| j r| j ||d¡ d S g }| jjjrNdtj }| jsDd| }| 	|¡ dd„ }x| j
D ]}| 	||ƒ¡ q^W | jrŠ| 	|| jƒ¡ | jr | 	|| jƒ¡ |r°d |¡}nd}| j | jj¡}	|jd }
|  ¡ }|rä|
 |¡ |
 d	|	|f ¡ |r|
 d
¡ | d|	|f ¡ d S )NTzPyObject *%szCYTHON_UNUSED c             S   s8   | j }|jr|j}n|j}|j |¡}|js4d| }|S )NzCYTHON_UNUSED )rÃ   rÖ  rV  r  r/   rÜ   rN  )r2  rÃ   r  Zdeclr&   r&   r'   Úarg_decl_codet  s    z7DefNode.generate_function_header.<locals>.arg_decl_codez, rK  Zdeclszstatic %s(%s); /* proto */z#endifzstatic %s(%s) {)r’  rq  rÑ  rÃ   ro  Úhas_dummy_argr	   rì  rÔ  rþ   rQ   r-  r.  r   r  rÜ   rˆ  r¾   rÈ  rN   )r|   rT   r¹  rº  Úarg_code_listÚself_argr“  r2  r  ÚdcZ
decls_coder  r&   r&   r'   rÑ  g  s>    






z DefNode.generate_function_headerc             C   s   d S )Nr&   )r|   r@   rT   r&   r&   r'   rÕ  •  s    z&DefNode.generate_argument_declarationsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÚ  ˜  s    zDefNode.generate_keyword_listc                sN   ‡ fdd„}x| j D ]}||jƒ qW x"| j| jfD ]}|r4||jƒ q4W d S )Nc                s4   | j r0ˆ  d| j| jf ¡ ˆ  | ¡ ˆ  | ¡ d S )Nz%s = %s;)rÖ  rN   r  rV  rñ  rW  )rÃ   )rT   r&   r'   rX    s    
z@DefNode.generate_argument_parsing_code.<locals>.put_into_closure)rQ   rÃ   r-  r.  )r|   r@   rT   rX  r2  r&   )rT   r'   rï  ›  s    z&DefNode.generate_argument_parsing_codec             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rô  ¨  s    z$DefNode.generate_argument_type_tests)NNTNNNFF)N)r   )/rJ   rj   rk   r‡   r¸   rj  ri  rŒ  Zreqd_kw_flags_cnamer¶   r  r†  ra  rÃ   r¼  rz  Zpy_cfunc_nodeÚrequires_classobjÚdefaults_structr-   Úfused_py_funcr  rq  r’  rQ  r‘  r~   rf  rg  r   rk  rn  r~  rm  rl  rJ  r  ro   rÎ  rÿ  r   r¿   rÑ  rÕ  rÚ  rï  rô  r&   r&   r&   r'   r?  ¤
  sZ    
B-@M

.r?  c               @   sÞ   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d5d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/d0„ Zd1d2„ Zd3d4„ ZdS )6rp  Nc             O   sD   t j| f|ž|Ž | jj| _| jj| _| jj| _| jj| _d | _d S )N)r§  r~   rI  rb  rc  rd  rz  ro  )r|   rQ   rr   r&   r&   r'   r~   ²  s    



zDefNodeWrapper.__init__c             C   sP   | j j}| j}| |j¡}tj| | |_tj| | |_	|j
| _
| j j| _d S )N)rI  rÃ   r9   r†  r‡  r	   Zpywrap_prefixrQ  Zpymethdef_prefixÚpymethdef_cnamero  rx  )r|   r@   Ztarget_entryr9   r‹  r&   r&   r'   r   º  s    z#DefNodeWrapper.analyse_declarationsc             C   sˆ   x>| j D ]4}|jjs"|j |¡s<q|jr|jjs|j |¡sqW | jr„| jjjs„| jj}d|_	x$|j
D ]}|jsf|jjrfd|j_qfW d S )Nr   T)rQ   r/   r:   Úcreate_from_py_utility_codert  rƒ  r.  rÃ   rN  ró  rð  r3   r  r8   Zcf_maybe_null)r|   r@   r2  rÃ   Zassr&   r&   r'   rŽ  Å  s    z(DefNodeWrapper.prepare_argument_coercionc             C   s:   t | jƒ}|dks2|dkr6| jd js2| jd jr6dS dS )Nr   r   )rG   rQ   r  rL  )r|   Zargcountr&   r&   r'   Úsignature_has_nongeneric_argsÛ  s    
z,DefNodeWrapper.signature_has_nongeneric_argsc             C   s   | j jS )N)ro  r{  )r|   r&   r&   r'   Úsignature_has_generic_argsã  s    z)DefNodeWrapper.signature_has_generic_argsc             C   sÖ   g }| j jr| tj¡ xR| jD ]H}|jrZ|jjsZ|jj	sZ|jj
sZ| |j |jj¡¡ q | |jj¡ q W | jr‚| | jjj¡ | jr˜| | jjj¡ d |¡}| jjsº| dtj ¡ | d| jjj|f ¡ d S )Nz, z%s = z%s(%s);)ro  r”  rþ   r	   rì  rQ   rt  r/   r€  r’  r[  rB  rÃ   r  r-  r.  r   r  rÛ   rÒ  rØ  rN   rI  rˆ  )r|   rT   rQ   r2  r&   r&   r'   r´  æ  s$    
z%DefNodeWrapper.generate_function_bodyc             C   s  | j j}| | j¡ | d¡ | d¡ | j  ¡ }|r@| |¡ | |¡ | ¡ |_| j  	||¡ph| j j
}|  ||¡ |  ||¡ | ¡ }| jjr˜d}nd}| jjsÀ| d| j tj¡|f ¡ | ¡  | d| j ¡ |  ||¡ |  |¡ |  |¡ | |j¡ | | j¡ | d¡ | d¡ |j|jkr–| |j¡ |  |j¡ x$|j !¡ D ]\}}	| "||	¡ qVW |  #¡ }
|
d k	r–| dtj|
f ¡ |  |j¡ x,|j$D ]"}|j%rª|j&jrª| '|¡ qªW | (¡  | jjsò| dtj ¡ | d	¡ | )¡  |r| d
| ¡ d S )Nr§   z/* Python wrapper */z = 0z%s%s;z%s (wrapper)z/* function exit code */z%s = %s;z
return %s;r¾  z#endif /*!(%s)*/)*rI  r±  rÊ   r%   rN   rÈ  rÊ  rË  rÌ  rÎ  rÏ  rÑ  rÕ  rÙ  r  r:   rÛ   rÜ   r	   rØ  rå  ræ  r9   rï  rô  r´  r  rœ  r÷  rø  rù  rú  rû  rü  rý  rÿ  r‹  r3   r/   r  r  r  )r|   r@   rT   r¬  r  r¹  r  Zretval_initr  r/   r  rÃ   r&   r&   r'   r¿   û  sb    













z,DefNodeWrapper.generate_function_definitionsr   c             C   sF  g }| j }|js| jr8dtj }|js.d| }| |¡ xF| jD ]<}|js@|jsV|j	rh| d|j
 ¡ q@| |j |j
¡¡ q@W | jj}|js¨| ¡ tjgkr¨| d¡ |jjrÄ|jdkrÄ| d¡ |jrà| dtjtjf ¡ d |¡}d}	|jdkr|jjrd}	d	}| j |j¡}
d
|	|
|f }| d| ¡ |r^| jjrZ| jjj||dd d S tj r |j!r | jjs |jj"s |jr’|j#r |j!}|j$r¨| %¡ }|jr¼|jdksÔ| d|j&| '¡ f ¡ |jr | d¡ | d|j# ¡ | d¡ |s| jjr4| (d|j) ¡ |j*| jjdd	d | d| ¡ d S )NzPyObject *%szCYTHON_UNUSED zCYTHON_UNUSED PyObject *unusedÚ__ipow__zPyObject *%s, PyObject *%sz, r§   )rµ  r¶  Fzstatic %s%s(%s)z%s; /*proto*/T)rº  zstatic char %s[] = %s;z#if CYTHON_COMPILING_IN_CPYTHONzstruct wrapperbase %s;z#endifzstatic PyMethodDef %s = r»  )Z
allow_skipz%s {)+ro  r”  rz  r	   rì  rþ   rQ   rM  r  rL  r}  rt  rÜ   rI  rÃ   r  Zmethod_flagsr   Zmethod_noargsr)  r  r9   r{  Ú
args_cnameÚ
kwds_cnamer   r  rQ  rN   rš  rÑ  r   r…  r-   Zis_property_scoperŠ  Z
is_unicodeZas_utf8_stringr‰  Zas_c_string_literalrÒ  r›  Zput_pymethoddef)r|   rT   r¹  rº  r•  r  r  r2  rÃ   Zmfr—  rU  Zdocstrr&   r&   r'   rÑ  <  sr    










z'DefNodeWrapper.generate_function_headerc             C   s^   x8| j D ].}|jr|jr*| d|j ¡ q| |j¡ qW x|jD ]}|jrB| |¡ qBW d S )NzPyObject *%s = 0;)	rQ   rM  ru  rN   r}  r×  rÃ   r‹  r3   )r|   r@   rT   r2  rÃ   r&   r&   r'   rÕ  ‡  s    z-DefNodeWrapper.generate_argument_declarationsc       	      C   s`  |  ¡ }|j}| d¡}| jdk}| jd k	p8| jd k	p8|}x"| jD ]}|jjsB|j 	|¡sBqBW |  
¡ s‚|rvt| jdƒ |  |¡ n$|  ¡ s–|  |¡ n|  | j||¡ ||_| |¡rF| |¡sÌ| |¡ | |¡ |r|  | j|¡ | jr| jjjr| | jj¡ n| | jj¡ | | jjj¡ | ¡  | d|  ¡  ¡ | |¡r\| |¡ d S )NZargument_unpacking_doner   z.This method cannot have * or keyword argumentsz
return %s;)Únew_error_labelr÷  rË  rb  r-  r.  rQ   r/   r:   rœ  rž  r   r%   rZ  r  Úgenerate_stararg_copy_codeÚ'generate_tuple_and_keyword_parsing_codeÚ
label_usedrù  rû  Úgenerate_arg_decrefrÃ   ró  Úput_var_xdecref_clearÚput_var_decref_clearr  rI  r  r  rN   rÿ  )	r|   r@   rT   Úold_error_labelÚour_error_labelÚ	end_labelZhas_kwonly_argsZhas_star_or_kw_argsr2  r&   r&   r'   rï  ’  sB    





z-DefNodeWrapper.generate_argument_parsing_codec             C   s   |r|  |j¡ d S )N)r§  rÃ   )r|   r2  rT   r&   r&   r'   Úgenerate_arg_xdecrefÀ  s    z#DefNodeWrapper.generate_arg_xdecrefc             C   s   |r|  |j¡ d S )N)r¨  rÃ   )r|   r2  rT   r&   r&   r'   r¦  Ä  s    z"DefNodeWrapper.generate_arg_decrefc          	   C   sj  | j sP|j t dd¡¡ | dtj ¡ | d| j	tj|  
¡ f ¡ | d¡ | jr~| j sf| jjjsrdtj }qŽdtj }ndtjtjf }|j t d	d¡¡ | d
|tj| j	t| jƒ|  
¡ f ¡ | jrÆ| jjjrÆtdd„ | jjjD ƒƒrr| d| ¡ | d| jjjtj| jjj|  
¡ f ¡ | | jjj¡ | d¡ | d| jjjf ¡ | d¡ d| jj_nT| d| jjjtjtjf ¡ | d| jjj|  
¡ f ¡ d| jj_| | jjj¡ | jr,| jjs,| d| j jjtj| j jjf ¡ | jrH| jjjrH| d¡ | | jjjt¡ | d|  
¡  ¡ | d¡ n| d|  
¡  ¡ | | j jj¡ | tjt¡ | tj¡ | d| j jjtjf ¡ |jjtj dd}| d||tj|f ¡ | dtj|f ¡ | dt¡ | d¡ | d| j jj|f ¡ | d¡ |j !|¡ d| j j_n:| j rf| tjt¡ | d| j jjtjf ¡ d| j j_d S ) NÚRaiseArgTupleInvalidzFunctionArguments.cz)if (unlikely(PyTuple_GET_SIZE(%s) > 0)) {zK__Pyx_RaiseArgtupleInvalid("%s", 1, 0, 0, PyTuple_GET_SIZE(%s)); return %s;r¾  zunlikely(%s)z%sz-unlikely(%s) && unlikely(PyDict_Size(%s) > 0)ZKeywordStringCheckzHif (%s && unlikely(!__Pyx_CheckKeywordStrings(%s, "%s", %d))) return %s;c             s   s   | ]}|j jV  qd S )N)rS   Z
allow_null)r„   Úrefr&   r&   r'   rÏ   â  s    z<DefNodeWrapper.generate_stararg_copy_code.<locals>.<genexpr>z	if (%s) {z3%s = PyDict_Copy(%s); if (unlikely(!%s)) return %s;z} else {z
%s = NULL;r   z,%s = (%s) ? PyDict_Copy(%s) : PyDict_New(); zif (unlikely(!%s)) return %s;r   z=%s = PyTuple_New(PyTuple_GET_SIZE(%s)+1); if (unlikely(!%s)) rÃ  z
return %s;zPyTuple_SET_ITEM(%s, 0, %s);F)r›  z-for (%s=0; %s < PyTuple_GET_SIZE(%s); %s++) {z*PyObject* item = PyTuple_GET_ITEM(%s, %s);r™   z!PyTuple_SET_ITEM(%s, %s+1, item);z%s = %s;)"r-  r¾   rc  r   rÉ  rN   r	   r   rÒ  r9   rÿ  r.  rÃ   rN  r¡  ÚboolrÑ   Zcf_referencesr  r   ró  rz  rI  rj  Úput_xdecref_clearr   rê  rì  rF  rœ  r  r
   Úc_py_ssize_t_typer£  )r|   rT   Zkwarg_checkr¤  r&   r&   r'   r£  È  s–    








z)DefNodeWrapper.generate_stararg_copy_codec          	      s˜  ˆ   d¡}g }g }g }xj|D ]b}|jr|jrV|js~|js~|jrJ| |¡ q~| |¡ q|jrh| |¡ q|js|js| |¡ qW || }	| j| j }
t	|ƒdkr¾|d js¶|d jr¾|
d8 }
t	|ƒ}| j
 oÔ|
|k}t|	ƒ}| jsê| j
rö|  |ˆ ¡ ˆ  d¡ t|ƒt|	ƒ }ˆ  dtjd ‡ fdd„|D ƒ¡f ¡ |  |ˆ ¡ ˆ  d	| jdkr\d
p^dtjf ¡ |  |
|||||ˆ ¡ | jr’|
dksœ|
|krØ|
|kr´| j
s´d}nd}ˆ  dtj||
f ¡ ˆ  |¡ | jr†||
kr| j
sˆ  dtj|f ¡ ˆ  |¡ ˆ  d¡ xft|	ƒD ]Z\}}|js$ˆ  |j¡}ˆ j t dd¡¡ ˆ  d| j|f ¡ ˆ  ˆ   | j!¡¡ P q$W nnˆ  d¡ |
|krÌx,t|ƒD ] \}}ˆ  d|tj|f ¡ q¤W n(ˆ  dtj ¡ | j
rîˆ  d¡ t"t|ƒƒd d d… }xd|D ]\\}}||
d krN||d d kr<ˆ  d¡ ˆ  d|d  ¡ ˆ  d|tj|f ¡ q
W |
dkrˆˆ  d¡ ˆ  d¡ ˆ  d¡ | j
rÖ|
rêx(t#|
d ddƒD ]}ˆ  d| ¡ q²W ˆ  |¡ nˆ  d¡ ˆ  |¡ ˆ  d¡ ˆ  d¡ x(t|ƒD ]\}}|  $|d| ˆ ¡ qW ˆ  d¡ ˆ  %|¡r”ˆ  |¡ ˆ  &|¡ ˆ j t d d¡¡ ˆ  d!| j||
|tjf ¡ ˆ  ˆ   | j!¡¡ d S )"NZargtuple_errorr   r   rÃ  z static PyObject **%s[] = {%s,0};ú,c                s   g | ]}d ˆ   |j¡ ‘qS )z&%s)Úintern_identifierr9   )r„   r2  )rT   r&   r'   r†   C  s   zJDefNodeWrapper.generate_tuple_and_keyword_parsing_code.<locals>.<listcomp>zif (%s(%s)) {Úlikelyr  z!=ú<z(} else if (PyTuple_GET_SIZE(%s) %s %d) {z'} else if (PyTuple_GET_SIZE(%s) > %d) {z} else {ÚRaiseKeywordRequiredzFunctionArguments.cz&__Pyx_RaiseKeywordRequired("%s", %s); z&values[%d] = PyTuple_GET_ITEM(%s, %d);zswitch (PyTuple_GET_SIZE(%s)) {zdefault:rª   zCYTHON_FALLTHROUGH;z
case %2d: z	case  0: zbreak;z	case %2d:z	default: r¾  z
values[%d]r­  zD__Pyx_RaiseArgtupleInvalid("%s", %d, %d, %d, PyTuple_GET_SIZE(%s)); )'rË  rM  r×   r  rL  rN  rþ   rd  rc  rG   r-  r¯  r.  Úgenerate_stararg_init_coderN   Útupler	   Úpykwdlist_cnamer   Ú#generate_argument_values_setup_coder¡  Úgenerate_keyword_unpacking_coder   rù  r  r³  r9   r¾   rc  r   rÉ  rÒ  r¡  r%   r‰   rY  Úgenerate_arg_assignmentr¥  rû  )r|   rQ   Zsuccess_labelrT   Úargtuple_error_labelri  Zrequired_kw_only_argsZoptional_kw_only_argsr2  Zkw_only_argsÚmin_positional_argsÚmax_positional_argsÚhas_fixed_positional_countÚhas_kw_only_argsÚall_argsZcomparer"  Úpystring_cnameZreversed_argsr&   )rT   r'   r¤    sÌ    

 








 












z6DefNodeWrapper.generate_tuple_and_keyword_parsing_codec             C   sÞ   |j jr<|jr t |j tj|¡}|j}| d|j|f ¡ nž|j j	rÈ|j
rX| d| ¡ | |j  ||jj|j|¡¡ |j
rÚ| d¡ | d|jj| |¡f ¡ |j jr¼|j|jjdd | d¡ nt|jd|j  ƒ d S )Nz%s = %s;z	if (%s) {z} else {T)r¿  r¾  z2Cannot convert Python object argument to type '%s')r/   r:   rM  r
   Ztypecastr   rÃ   rN   r  Úfrom_py_functionr×   Úfrom_py_call_coder%   rC  r€  rò  r   )r|   r2  r™   rT   rÃ   r&   r&   r'   r¼  °  s(    


z&DefNodeWrapper.generate_arg_assignmentc             C   s*  | j rDd| j j_| d| j jj| j jj|  ¡ f ¡ | | j jj¡ | jr&d| jj_| dtj	|f ¡ | d| jjjtj	|tj	f ¡ | d| jjj ¡ | j r¶| 
| j jjt¡ | ¡  | d|  ¡  ¡ | d¡ | | jjj¡ | d¡ | d	| jjjtjf ¡ | tjt¡ | d¡ d S )
Nr   z0%s = PyDict_New(); if (unlikely(!%s)) return %s;z if (PyTuple_GET_SIZE(%s) > %d) {z4%s = PyTuple_GetSlice(%s, %d, PyTuple_GET_SIZE(%s));zif (unlikely(!%s)) {z
return %s;r¾  z} else {z	%s = %s; )r.  rÃ   ró  rN   r  rÿ  r   r-  r	   r   r¢  r   r  rÒ  ré  rê  )r|   r¿  rT   r&   r&   r'   r·  Ê  s4    




z)DefNodeWrapper.generate_stararg_init_codec             C   sš   t |ƒ}| d|d d| ¡f ¡ | jjrN| d| jjtj| jjtjf ¡ xFt|ƒD ]:\}}|j	rX|j
jrX| |¡}| d||j
 |¡f ¡ qXW d S )NzPyObject* values[%d] = {%s};r²  r\  z+%s *%s = __Pyx_CyFunction_Defaults(%s, %s);zvalues[%d] = %s;)rG   rN   r   rI  r™  r	   Zdynamic_args_cnamerì  r  r×   r/   r:   rC  r
  )r|   rQ   rT   Zmax_argsr"  r2  r@  r&   r&   r'   rº  æ  s    

z2DefNodeWrapper.generate_argument_values_setup_codec             C   sš  |  d¡ |  dtj ¡ |  d¡ | jr4|  d¡ xJt|d ddƒD ]6}| d|d  ¡ |  d|tj|f ¡ |  d	¡ qFW |  d
¡ | js¤| d¡ | |¡ |  d¡ |  dtj ¡ | jsÎ|dkrìd}	xt	|ƒD ]\}}
|
j
sÜ|}	qÜW |	|k r|d }	|dkr|  d¡ x¼t	|d |	d … ƒD ]¢\}}
|dkrŽ||krŽ|dkrb|  d	¡ | jr€||kr€|  d¡ n|  d| ¡ | |
j¡}|
j
ræ|
jr®q0|  d¡ |  dtj|f ¡ |  d| ¡ |  d¡ nì|  d|tj|f ¡ ||k r||dkr&| d¡ | |¡ nT|  d¡ |j t dd¡¡ | d| j||||f ¡ |  | | j¡¡ |  d¡ nV|
jr0|  d¡ |j t dd¡¡ | d| j|f ¡ |  | | j¡¡ |  d¡ q0W |dkrì|  d¡ |rþ|  ||¡ |  d¡ |dkrd}n$| jr8|  d||f ¡ d}nd}|j t d d¡¡ |  d!tjtj| jrr| jjjptd|| j| | j¡f ¡ |  d¡ d S )"NzPy_ssize_t kw_args;z1const Py_ssize_t pos_args = PyTuple_GET_SIZE(%s);zswitch (pos_args) {zdefault:r   rª   z
case %2d: z&values[%d] = PyTuple_GET_ITEM(%s, %d);zCYTHON_FALLTHROUGH;zcase  0: break;z	default: r¾  zkw_args = PyDict_Size(%s);r   z	case %2d:zif (kw_args > 0) {z2PyObject* value = __Pyx_PyDict_GetItemStr(%s, %s);z-if (value) { values[%d] = value; kw_args--; }zKif (likely((values[%d] = __Pyx_PyDict_GetItemStr(%s, %s)) != 0)) kw_args--;zelse zelse {r­  zFunctionArguments.cz2__Pyx_RaiseArgtupleInvalid("%s", %d, %d, %d, %d); r¶  z&__Pyx_RaiseKeywordRequired("%s", %s); zif (unlikely(kw_args > 0)) {r\  zAconst Py_ssize_t used_pos_args = (pos_args < %d) ? pos_args : %d;Zused_pos_argsZpos_argsZParseKeywordszOif (unlikely(__Pyx_ParseOptionalKeywords(%s, %s, %s, values, %s, "%s") < 0)) %s)rN   r	   r   r-  rY  rÒ  rù  r¡  rd  r  r×   r³  r9   rN  r¾   rc  r   rÉ  r¡  r%   Ú,generate_optional_kwonly_args_unpacking_coder¹  r.  rÃ   r  )r|   r¾  r¿  rÀ  rÁ  rÂ  r½  rT   r"  Zlast_required_argr2  rÃ  Zpos_arg_countr&   r&   r'   r»  ù  sª    









"











z.DefNodeWrapper.generate_keyword_unpacking_codec             C   sô   g }d}x6t |ƒD ]*\}}|jr|js(q|s0|}| |j¡ qW |rðt|ƒdkr˜| d| j rbdpddt|ƒf ¡ | d¡ | d||t|ƒ f ¡ n| d¡ | d	| ¡ | d
tj	tj
f ¡ | d¡ t|ƒdkræ| d¡ | d¡ d S )Nrª   r   z'if (kw_args > 0 && %s(kw_args <= %d)) {r´  r§   zPy_ssize_t index;z6for (index = %d; index < %d && kw_args > 0; index++) {zif (kw_args == 1) {zconst Py_ssize_t index = %d;z:PyObject* value = __Pyx_PyDict_GetItemStr(%s, *%s[index]);z0if (value) { values[index] = value; kw_args--; }r¾  )r  rN  r×   rþ   r9   rG   rN   r.  r	   r¡  r¹  )r|   rÂ  rT   Zoptional_argsZfirst_optional_argr"  r2  r&   r&   r'   rÆ  r  s0    



z;DefNodeWrapper.generate_optional_kwonly_args_unpacking_codec             C   s&   x | j D ]}|jr|  ||¡ qW d S )N)rQ   ru  Úgenerate_arg_conversion)r|   rT   r2  r&   r&   r'   rZ  ‘  s    z0DefNodeWrapper.generate_argument_conversion_codec             C   s¢   |j }|j}|jrR|jr*| d|j ¡ n| d|j ¡ |  ||¡ | d¡ nL|jrf|  ||¡ n8| |¡rŠ| d|j	j
|jf ¡ nt|jd||f ƒ d S )Nz	if (%s) {zassert(%s); {r¾  z%s = %s;z+Cannot convert 1 argument from '%s' to '%s')rt  r/   r:   r×   rN   r}  Ú%generate_arg_conversion_from_pyobjectÚ#generate_arg_conversion_to_pyobjectr  rÃ   r  r   r%   )r|   r2  rT   Úold_typeÚnew_typer&   r&   r'   rÇ  ™  s    
z&DefNodeWrapper.generate_arg_conversionc             C   s@   |j }|jr,| | |j|jj|j|¡¡ nt|jd| ƒ d S )Nz2Cannot convert Python object argument to type '%s')	r/   rÄ  rN   rÅ  r}  rÃ   r  r%   r   )r|   r2  rT   rË  r&   r&   r'   rÈ  ¬  s    
z4DefNodeWrapper.generate_arg_conversion_from_pyobjectc          
   C   s\   |j }|j}|rH| d|jj||j| |jj|j¡f ¡ | |j¡ nt	|jd| ƒ d S )Nz%s = %s(%s); %sz5Cannot convert argument of type '%s' to Python object)
rt  Zto_py_functionrN   rÃ   r  r}  rŸ  r%   Zput_var_gotrefr   )r|   r2  rT   rÊ  rY   r&   r&   r'   rÉ  ¹  s    z2DefNodeWrapper.generate_arg_conversion_to_pyobjectc             C   sR   xL| j D ]B}|jr |  ||¡ q|js|jjs>|jjs>|jjr|  ||¡ qW d S )N)	rQ   r[  r  r  r/   r:   rÚ   r€  r  )r|   rT   r2  r&   r&   r'   rô  Æ  s    z+DefNodeWrapper.generate_argument_type_testsc             C   s   | j jS )N)ro  rÿ  )r|   r&   r&   r'   rÿ  Ò  s    zDefNodeWrapper.error_value)r   )rJ   rj   rk   ZdefnoderI  r~   r   rŽ  r  rž  r´  r¿   rÑ  rÕ  rï  r¬  r¦  r£  r¤  r¼  r·  rº  r»  rÆ  rZ  rÇ  rÈ  rÉ  rô  rÿ  r&   r&   r&   r'   rp  ¬  s8   A
K.U yrp  c                   s`   e Zd ZdZdZdZdZdZdZe	j
dg Z
‡ fdd„Z‡ fdd„Zd	d
„ Z‡ fdd„Z‡  ZS )ÚGeneratorDefNodeTFÚ	GeneratorÚgbodyc                s*   t |g dd|d< tt| ƒj|f|Ž d S )NT)rÇ   rµ   r   )rÆ   rc   rÌ  r~   )r|   r%   rr   )rI   r&   r'   r~   å  s    zGeneratorDefNode.__init__c                s*   t t| ƒ |¡ | j| j_| j |¡ d S )N)rc   rÌ  r   r±  rÎ  )r|   r@   )rI   r&   r'   r   ê  s    
z%GeneratorDefNode.analyse_declarationsc             C   sØ   | j jj}| | j¡}| | j¡}| | j¡}| d¡ | d| j|| j	rV| j	 
|¡ndtj|||| d| j¡f ¡ | tjt¡ | jr¸d}| d|tjf ¡ | |t¡ | |¡ | ¡  | d¡ | d¡ d S )	NrÃ  zk__pyx_CoroutineObject *gen = __Pyx_%s_New((__pyx_coroutine_body_t) %s, %s, (PyObject *) %s, %s, %s, %s); %sr]  Úgenzgen->classobjz&%s = __Pyx_CyFunction_GetClassObj(%s);zreturn (PyObject *) gen;r¾  )rÎ  rÃ   rQ  r³  r9   ÚqualnameÚmodule_namerN   Úgen_type_namerá  râ  r	   rÆ  rŸ  r%   r  r   r˜  rì  rê  rF  r  )r|   r@   rT   Z
body_cnamer9   rÐ  rÑ  Zclassobj_cnamer&   r&   r'   r´  ï  s(    




z'GeneratorDefNode.generate_function_bodyc                sH   |  t | jd¡¡ | jj|dd tt| ƒ ||¡ | j ||¡ d S )NzCoroutine.cT)Úproto)	rc  r   rÉ  rÒ  rÎ  rÑ  rc   rÌ  r¿   )r|   r@   rT   )rI   r&   r'   r¿     s    z.GeneratorDefNode.generate_function_definitions)rJ   rj   rk   rß  Úis_coroutineÚis_iterable_coroutineÚis_asyncgenrÒ  r°  r?  r‡   r~   r   r´  r¿   rl   r&   r&   )rI   r'   rÌ  Ö  s   rÌ  c               @   s   e Zd ZdZdZdS )ÚAsyncDefNodeÚ	CoroutineTN)rJ   rj   rk   rÒ  rÔ  r&   r&   r&   r'   r×    s   r×  c               @   s   e Zd ZdZdZdS )ÚIterableAsyncDefNodeZIterableCoroutineTN)rJ   rj   rk   rÒ  rÕ  r&   r&   r&   r'   rÙ    s   rÙ  c               @   s   e Zd ZdZdZdS )ÚAsyncGenNodeZAsyncGenTN)rJ   rj   rk   rÒ  rÖ  r&   r&   r&   r'   rÚ    s   rÚ  c                   sP   e Zd ZdZdZdZdZd‡ fdd„	Zdd„ Zdd	„ Z	dd
d„Z
dd„ Z‡  ZS )ÚGeneratorBodyDefNodeTFNc          
      s$   t t| ƒj||||d g d d d d S )N)r%   r   r9   Úis_async_gen_bodyr-   rQ   r-  r.  )rc   rÛ  r~   )r|   r%   r9   r   rÜ  )rI   r&   r'   r~   &  s    
zGeneratorBodyDefNode.__init__c             C   sV   |  |j¡}|  d¡}tj| | }|jd t| j|dd}||_t| j	ƒ|_
|| _d S )NÚ	generatorrL  )r  rá   )r†  r‡  r	   Zgenbody_prefixr,  r   r%   rQ  r   r9   r  rÃ   )r|   r@   r‹  r9   r  rÃ   r&   r&   r'   Údeclare_generator_body+  s    

z+GeneratorBodyDefNode.declare_generator_bodyc             C   s   |   |¡ |  |¡ d S )N)rk  rÞ  )r|   r@   r&   r&   r'   r   5  s    
z)GeneratorBodyDefNode.analyse_declarationsc             C   s@   d| j jtjtjtjf }|r.| d| ¡ n| d| ¡ d S )Nz]static PyObject *%s(__pyx_CoroutineObject *%s, CYTHON_UNUSED PyThreadState *%s, PyObject *%s)z%s; /* proto */z%s /* generator body */
{)rÃ   rQ  r	   Úgenerator_cnameZlocal_tstate_cnameÚsent_value_cnamerN   )r|   rT   rÓ  rU  r&   r&   r'   rÑ  9  s    
z-GeneratorBodyDefNode.generate_function_headerc          	   C   sØ  | j }| j ||¡ | |¡ | ¡ |_| | j¡ |  ||¡ | 	d¡ |  
|¡ | ¡ }| 	dtj ¡ | ¡ }| ¡  | | jjpŽ| jj¡ |jjd }|jjd }|s²|râ| ¡  d|j_| jrÔ| j |¡nd }| |¡ |j |jjj¡ | ¡ }	| d¡}
| |
¡ |  |
¡ | 	d| !tj"| j¡ ¡ | j#r¾| j$d k	r¾| j$}|t%j&kr`d}n0|t%j'krrd	}n|t%j(kr„d
}nt)d| ƒ‚| 	dtj|| !tj| j¡f ¡ | *tj¡ |  +||¡ |jjjj,r| 	d|jj -tj.¡|jj /dtj0 ¡f ¡ | 	dtj. ¡ |s"|r*d|j_| | j¡ | 	d¡ | 	d¡ | j#s’| jj1s’| j2rx|j 3t4 5dd¡¡ | 	d| j2rŠdnd ¡ | 6|j7¡rT| jj1s¶| 8|j9¡ |  |j7¡ | j#rä| j$d k	rä| :tjt;¡ t<j=| >¡ j?j@kr |j 3t4 5dd¡¡ | 	dtA| j2ƒ ¡ x$|j B¡ D ]\}}| C||¡ q,W | D| jj¡ |  |j9¡ | j#rv| Etj¡ n| :tjt;¡ | 	d¡ | 	dtj0 ¡ | 	d¡ | 	dtj0 ¡ | 	dtj0 ¡ |sÔ|rê|jFtj|jjG d | H¡  | 	dtj ¡ | 	d ¡ | I|j¡ |s$|r@|	jJ| jj| j|jjG d |	 	d!tj0 ¡ |	 	d"|
 ¡ x&|jKD ]\}}|	 	d#||f ¡ qfW |	 	d$¡ |sœ|r°|	jFd%|jjG d |	 H¡  |	 	d&¡ |	 	d ¡ | L¡  d S )'Nr§   zPyObject *%s = NULL;r·  r¸  TZ	first_runz%szPyList_New(0)zPySet_New(NULL)zPyDict_New()z)invalid type of inlined comprehension: %sz%s = %s; %sz%s = %s;z%s->closurezCYTHON_MAYBE_UNUSED_VAR(%s);Fz/* function exit code */ÚStopAsyncIterationzCoroutine.czPyErr_SetNone(%s);Z__Pyx_PyExc_StopAsyncIterationZPyExc_StopIterationZpep479z*__Pyx_Generator_Replace_StopIteration(%d);z#if !CYTHON_USE_EXC_INFO_STACKz+__Pyx_Coroutine_ResetAndClearException(%s);z#endifz%s->resume_label = -1;z%__Pyx_Coroutine_clear((PyObject*)%s);)r
  z
return %s;r¾  zswitch (%s->resume_label) {zcase 0: goto %s;zcase %d: goto %s;z2default: /* CPython raises the right error here */r½  zreturn NULL;)Mr±  r   r¿   rÊ  rË  rÌ  rÊ   r%   rÄ   rN   rÑ  rÙ  r	   rØ  rå  ræ  rÃ   r9   r  r¾   r¼   rà  rœ  rî  rá  râ  rã  Zinit_closure_tempsrÓ  r/   r)  Z	use_labelrû  rŸ  rà  Ú
is_inlinedÚinlined_comprehension_typer   Z	list_typeZset_typeZ	dict_typer   r   r´  r‹  rÜ   rÆ  rB  rß  rµ   rÜ  rc  r   rÉ  r¥  r÷  rù  rú  r°  r   r   Zgenerator_stoprÁ   ÚcontextZfuture_directivesr¯  rü  rý  r  r	  r  rÍ  r  r  rí  Zyield_labelsr  )r|   r@   rT   r¬  Zclosure_init_coder  r·  r¸  rá  Zresume_codeZfirst_run_labelÚtarget_typeZ	comp_initr  r/   r"  Úlabelr&   r&   r'   r¿   D  sÎ    



















z2GeneratorBodyDefNode.generate_function_definitions)NNNF)F)rJ   rj   rk   r+  râ  rÜ  rã  r~   rÞ  r   rÑ  r¿   rl   r&   r&   )rI   r'   rÛ    s   

rÛ  c               @   s&   e Zd ZdgZdZdd„ Zdd„ ZdS )rC  r   Nc                sÀ   |j ˆ_ˆjjrd}nd}ddlm‰  ˆ  ˆjt¡ˆ_	ˆ j
ˆjˆj	‡ ‡fdd„ˆj|d … D ƒd}|jjst|jjržtˆjtˆj|dtˆjd dgd	ˆ_ntˆj|dˆ_ˆj |¡ˆ_ˆS )
Nr   r   )rï   c                s   g | ]}ˆ j ˆj|jd ‘qS ))r9   )rü   r%   r9   )r„   r2  )rï   r|   r&   r'   r†   é  s   z9OverrideCheckNode.analyse_expressions.<locals>.<listcomp>)rF  rQ   )Úexpr)r6   )rÇ   )rÛ  rQ   rÐ  r  r§   rï   ÚRawCNameExprNoder%   r   Ú	func_noderG  r  rÛ   Úis_returncoderÆ   ÚExprStatNoderH  r   ro   )r|   r@   Z	first_argZ	call_noder&   )rï   r|   r'   ro   ß  s"    z%OverrideCheckNode.analyse_expressionsc             C   s@  |  | jjj¡}| jjr$dtj }nd| jd j }| 	d¡ | 	dtj
 ¡ | 	d¡ | jjrl| 	d¡ n| 	d||f ¡ | 	d¡ |j t d	d
¡¡ | 	dtjtjf ¡ | 	d|tjtjf ¡ | 	dtj|f ¡ | 	d¡ |jjtdd}| j |¡ |j t dd
¡¡ | || j¡}| 	d||||f ¡ | |¡ d| }d|| jjjf }| 	d||f ¡ | j |¡ | 	d¡ | 	d¡ | 	dtj|f ¡ | 	dtj|f ¡ | 	dtjtjf ¡ | 	dtjtjf ¡ | 	d¡ | 	d¡ | |tj¡ |j |¡ | 	d¡ | 	d¡ | 	d¡ | 	d¡ d S )Nz((PyObject *)%s)r   z /* Check if called by wrapper */zif (unlikely(%s)) ;z#/* Check if overridden in Python */zelse {zƒelse if (unlikely((Py_TYPE(%s)->tp_dictoffset != 0) || (Py_TYPE(%s)->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {zQ#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSZPyDictVersioningzObjectHandling.czNstatic PY_UINT64_T %s = __PYX_DICT_VERSION_INIT, %s = __PYX_DICT_VERSION_INIT;z?if (unlikely(!__Pyx_object_dict_version_matches(%s, %s, %s))) {z/PY_UINT64_T %s = __Pyx_get_tp_dict_version(%s);z#endifT)r›  ZPyObjectGetAttrStrz*%s = __Pyx_PyObject_GetAttrStr(%s, %s); %szPyCFunction_Check(%s)z8(PyCFunction_GET_FUNCTION(%s) != (PyCFunction)(void*)%s)zif (!%s || %s) {r¾  z#%s = __Pyx_get_tp_dict_version(%s);z'%s = __Pyx_get_object_dict_version(%s);zif (unlikely(%s != %s)) {z"%s = %s = __PYX_DICT_VERSION_INIT;) r³  rÐ  rÃ   r9   r  r	   Úmodule_cnamerQ   r  rN   rO  r¾   rc  r   rÉ  Ztp_dict_version_tempZobj_dict_version_tempZtype_dict_guard_temprœ  r  r   ré  Ú	set_cnamerŸ  r%   r   rQ  r   rÀ   r¢  r
   r£  )r|   rT   Zinterned_attr_cnamer–  Zfunc_node_tempÚerrZis_builtin_function_or_methodZis_overriddenr&   r&   r'   rÀ   ô  sh    











z)OverrideCheckNode.generate_execution_code)rJ   rj   rk   r‡   r   ro   rÀ   r&   r&   r&   r'   rC  Ñ  s   
rC  c               @   s   e Zd ZdS )ÚClassDefNodeN)rJ   rj   rk   r&   r&   r&   r'   rï  C  s   rï  c            	   @   sp   e Zd Zddddddddd	g	Zd
Zd
ZdZd
Z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
S )ÚPyClassDefNoder   ra   Ú	metaclassÚmkwrf   Úclass_resultrI  Ú
class_cellr†  NFc	             C   s  t  | |¡ || _|| _|| _|| _|| _ddlm}	 | jr`t	j
r`t| j| jƒ}|	j||d}
nd }
| }|rd}d| _|jrö|jræxVtt|jƒƒd d d… D ]:\}}|jjdkr | jd k	rÊt|jdƒ |j| _|j|= q W || _n| jd k	sôt‚n|	 |¡| _|s | js | js | jrÆ| jd kr||rB|jsB| j}nd }|sb| jjrb| jjsbn|	j||| jd	| _d}nd}|	j|||
| j| j| jd
| _|	j||| j| j|
| j| j||d	| _ n(|	j!|g d| _|	j"|||| j|
d| _ |	j#||d| _$|	 %| j¡| _&d S )Nr   )rï   )r6   FTrª   rñ  z2keyword argument 'metaclass' passed multiple times)rò  rf   )r9   r-   rñ  rf   rò  )r9   rf   ra   r-   rñ  rò  Zcalculate_metaclassÚallow_py2_metaclass)r5   )r9   rf   ra   r-   )r9   )'rÌ   r~   r9   r-   r   r†  rf   r§   rï   r   r…  r.   r%   Z
StringNodeÚis_py3_style_classr4   r5   r‰   r  r¢   r6   rñ  r   rò  ÚAssertionErrorÚ	ProxyNodeZis_sequence_constructorrQ   ZPyClassMetaclassNodeZPyClassNamespaceNodera   ZPy3ClassNodeÚclassobjÚDictNodeZ	ClassNoderü   rI  ZClassCellInjectorNoderô  )r|   r%   r9   rf   r-   r   r†  rj  Zforce_py3_semanticsrï   Zdoc_noderõ  r"  r™   ZmkdictZneeds_metaclass_calculationr&   r&   r'   r~   _  sl    "



zPyClassDefNode.__init__c             C   s\   | j rt| jjdƒ dS ddlm} t| jdd| j| jjpH|j	| jg d| j
| jd| jd	S )	zO
        Return this node as if it were declared as an extension class
        z7Python3 style class could not be represented as C classNr   )rï   rL  )rQ   F)rá   rÑ  Ú
class_namerf   r†  r   râ   r-   )rö  r   rù  r%   r§   rï   ÚCClassDefNoder9   rf   rê   r†  r   r-   )r|   rï   r&   r&   r'   Ú	as_cclass©  s    zPyClassDefNode.as_cclassc             C   s4   |}x|j s|jr|j}qW t| j|d }| _|S )N)r9   r~  )r¯  r  r~  r   r9   r)  )r|   r@   r²  r  r&   r&   r'   Úcreate_scope¼  s
    
zPyClassDefNode.create_scopec             C   s˜   | j }| jrLddlm} x,| jd d d… D ]}||j|j|gd}q*W d | _|| _| j |¡ | j 	|¡ |  
|¡}|j|_| jjj|_| j |¡ d S )Nr   )rG  rª   )rF  rQ   )rù  r†  rï   rG  r%   r<  ró  r   rI  Úanalyse_target_declarationrþ  r¼   rÃ   r  Úclass_obj_cnamer   )r|   r@   ró  rG  r<  r  r&   r&   r'   r   Ã  s     
z#PyClassDefNode.analyse_declarationsc             C   sŽ   | j r| j  |¡| _ | jr(| j |¡| _| jr<| j |¡| _| j |¡| _| j |¡| _| j}| j |¡| _| j 	|| j
¡ | j |¡| _| S )N)rf   ro   rñ  rò  ra   ró  r)  r   rI  Úanalyse_target_expressionrù  rô  )r|   r@   r  r&   r&   r'   ro   Õ  s    z"PyClassDefNode.analyse_expressionsc             C   s"   |   | j|¡ | j | j|¡ d S )N)rÅ   r)  r   r¿   )r|   r@   rT   r&   r&   r'   r¿   ä  s    z,PyClassDefNode.generate_function_definitionsc             C   s^  |  | j¡ |j | ¡ | j}| jr0| j |¡ | jrB| j |¡ | jrT| j |¡ | j	 |¡ | j	 
¡  |_|_| j |¡ | j |¡ | j |¡ | j || j 
¡ ¡ | j |¡ | j 
¡  |_|_| j | j|¡ | j	 |¡ | j	 |¡ | jr| j |¡ | j |¡ | jr0| j |¡ | j |¡ | jrP| j |¡ | j |¡ |j ¡  d S )N)rÊ   r%   Zpyclass_stackrþ   r)  rf   rA  rò  rñ  ra   r‹   Únamespace_cnamer   rô  r   rÀ   ró  Zgenerate_injection_codeÚgenerate_disposal_coderù  rI  rK  rH  Úpop)r|   rT   r  r&   r&   r'   rÀ   è  s>    z&PyClassDefNode.generate_execution_code)NNF)rJ   rj   rk   r‡   r†  ró  rö  rñ  rò  r~   rý  rþ  r   ro   r¿   rÀ   r&   r&   r&   r'   rð  G  s   
 
Irð  c               @   s|   e Zd Zdg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dd„ Zeddd„ƒZdd„ ZdS )rü  r   NFc             C   sD   t | dƒs>ddlm} | jr8|j| j|g | jdd| _nd | _| jS )NÚ_buffer_defaultsr   )rl  F)Zneed_complete)r<  r§   rl  Úbuffer_defaults_noderm  Úbuffer_defaults_posr  )r|   r@   rl  r&   r&   r'   rn  +  s    
zCClassDefNode.buffer_defaultsc             C   s~   | j r4| jdkr4| j  d¡}| || j¡}|s8d S n|}|j| j| jdd| j d | j| j| j| j	| j
| j|  |¡| jd| _d S )Nr  Ú.r   )r9   r%   r2  ÚimplementingrÑ  rB   Úobjstruct_cnameÚtypeobj_cnamerá   r*  Ú
check_sizerz  rn  Úshadow)rÑ  rá   ÚsplitrX  r%   Údeclare_c_classrû  Úobjstruct_nameÚtypeobj_namer*  r  rz  rn  r  rÃ   )r|   r@   rV  Ú
home_scoper&   r&   r'   rŠ  7  s*    zCClassDefNode.declarec                s  ˆ j rˆjstˆjdƒ ˆjr0tˆjdˆj ƒ d ˆ_ˆjr”d ˆ_x ˆ j	D ]}|j
ˆjkrJ|ˆ_qJW ˆjd kr”tˆjd ˆ jƒˆ_dˆj_ˆ  ˆj¡ ˆjjrâˆjjd }| ˆ ¡}|tjtjtjfkrØˆ  | ¡ ¡j}|d krôt|jdˆj ƒ nÀ|tjkrd }n®|js0|jr|js0t|jd| ƒ n„| ¡ sTt|jd|j
ˆjf ƒ n`|jr†|jjr†|j r†t|jd|ˆjf ƒ n.|jr®|j
d	kr®t|jd
|j
 ƒ n|ˆ_ˆ j !dd¡dkrâ|tjkrât"ˆjddƒ ˆj#d k	}|r ˆjr ˆjjs ˆjj$ %‡ ‡fdd„¡ d S ˆjrZˆj&dkrZˆj 'd¡}ˆ  (|ˆj¡}|s^d S nˆ }ˆj&dkr¬ˆjdkr¬ˆjt)j*kr¬ˆ j+d d… dkr¬t"ˆjdˆj dƒ |j,ˆjˆj|oÂˆj-|oÎˆj- ˆjˆjˆjˆj.ˆj/ˆj&ˆj0ˆj1ˆ 2ˆ ¡ˆj3dˆ_4ˆj3rˆj4| ˆj¡_5|ˆ k	rDˆj&dkrDˆ  6ˆjˆj4ˆj¡ ˆj4jj ˆ_}	|	d k	rfˆ j|	_ˆj7r†t8j9r†t:ˆjˆj7ƒ|	_7|rúˆj# ;|	¡ ˆj <d¡}
|
rä|
j=rä|	j>sä|	j?säˆj @d¡|
_Aˆj Bd|
j7|
j¡ ˆj-rôd|	_>nd|	_?tCˆjjƒdkr®|rˆj-r.tˆjjd jdƒ x2ˆjjdd … D ]}| ˆ ¡r@t|jdƒ q@W dˆj4j_DddlEmF} |jGˆj|jHˆjˆjdˆj|jIˆjg dgdˆ_Jn8ˆjrÖˆjjKpÆˆjjDˆj4j_Dd ˆ_Jndˆj4j_Dd ˆ_Jˆ  Lˆj4¡ xˆj4jj$D ]}|ƒ  qþW d S )NzTObject struct name specification required for C class defined in 'extern from' blockz:Decorators not allowed on cdef classes (used on type '%s')r   r   z+First base of '%s' is not an extension typez'%s' is not an extension typez*Base class '%s' of type '%s' is incompletez%Base class '%s' of type '%s' is final)r¸  ÚstrÚbyteszGinheritance from PyVarObject types like '%s' is not currently supportedZfreelistzIfreelists cannot be used on subtypes, only the base class can manage themc                  s
   ˆ  ˆ ¡S )N)r   r&   )r@   r|   r&   r'   Ú<lambda>‡  s    z4CClassDefNode.analyse_declarations.<locals>.<lambda>r  r  Z__builtin__é   zcpython.z %s already a builtin Cython type)r9   r%   r2  r	  rÑ  rB   r
  r  r  rá   r*  rz  rn  r  rz   Z__dict__getterz'Only declare first base in declaration.z+Only one extension type base class allowed.)rï   )r6   )r5   )rQ   )MrÐ   r  r   r%   r†  rû  rB   rÑ  ÚmoduleZcimported_modulesr9   r   rä  Zhas_extern_classÚadd_imported_modulerf   rQ   r7   r
   r<   r;   r=   rW  Zsign_and_namer/   r   rv  r  r
  rö   r)  r¼   r…  r(  r   r   Zdefered_declarationsrþ   rá   r  rX  r   Zbuiltin_typesr  r  râ   r  r  r*  rz  rn  r  rÃ   r@  Úadd_imported_entryr-   r   r…  r.   r   rf  Zis_variableZdefinedZimplementedZmangle_internalZgetter_cnameÚdeclare_propertyrG   Ú
early_initr§   rï   rê   ZIdentifierStringNoderú  Útype_init_argsZis_externalZallocate_vtable_names)r|   r@   r  rå   rB   Zbase_class_scopeZhas_bodyrV  r  r)  Z
dict_entryZ
other_baserï   Zthunkr&   )r@   r|   r'   r   P  sÚ    




 




z"CClassDefNode.analyse_declarationsc             C   s4   | j r| jjj}| j  |¡| _ | jr0| j |¡ | S )N)r   rÃ   r/   r)  ro   r  )r|   r@   r)  r&   r&   r'   ro   Ù  s    
z!CClassDefNode.analyse_expressionsc             C   s(   | j r$|  | j|¡ | j  | j|¡ d S )N)r   rÅ   r)  r¿   )r|   r@   rT   r&   r&   r'   r¿   á  s    z+CClassDefNode.generate_function_definitionsc             C   sZ  |  | j¡ | jr| j |¡ | jjjsV| jrF| j |¡ d| j 	¡  }d| }|j
 tjd¡}| d|| j 	¡ f ¡ | | || j¡¡ | |¡ | d||f ¡ | d¡ | d||f ¡ | | | j¡¡ | d¡ |j
 |¡ | |tj¡ | |¡ | d	| jjj|f ¡ | |tj¡ | j |¡ | j |¡ |  | j|d¡ d S )
NzPyTuple_GET_ITEM(%s, 1)z(((PyTypeObject*)PyTuple_GET_ITEM(%s, 0))Tz0%s = PyType_Type.tp_new(&PyType_Type, %s, NULL);z*if (((PyTypeObject*) %s)->tp_base != %s) {zPPyErr_Format(PyExc_TypeError, "best base '%s' must be equal to first base '%s'",zB             ((PyTypeObject*) %s)->tp_base->tp_name, %s->tp_name);r¾  z%s.tp_bases = %s;)rÊ   r%   r   rÀ   rÃ   r/   r  r  rA  r‹   rœ  r  r
   r   rN   rŸ  r   r¡  r£  rê  rF  r  r¢  r  rH  Úgenerate_type_ready_code)r|   rT   rf   Z
first_baseZ
trial_typer&   r&   r'   rÀ   æ  s8    



z%CClassDefNode.generate_execution_codec          
   C   s´  | j }|j}|j}|sd S | jdkr’xtjD ]}| ||¡ q.W |r`|j t	 
dd¡¡ d}nd}| d||| | j¡f ¡ | d| ¡ t |d¡}t |d¡}	|d	kr|	d	kr|jrÊd
}
d}nd}
d}|j t	 
|d¡¡ | d||f ¡ | d||
f ¡ | d¡ x| j jjD ] }|jdk}|jr"tjr"|jr"|s"tj |j¡}|rl| ¡ nd }|r€| |¡ | d¡ | d¡ | d||j| d| j¡f ¡ | d¡ | d|j ¡ | d|j|jf ¡ | d|j ¡ | d¡ | d¡ | d¡ |r"| d¡ q"W |jr–|j t	 
dd¡¡ | d||j| | j¡f ¡ |r–|j t	 
dd¡¡ | d || | j¡f ¡ |jjsØ|jj d!¡sØ| d"tj | !|j"¡|| | j¡f ¡ |j#sê| $d#¡nd }|rH|j t%kr<d$| }|j&r|j'}n
d%|j' }| d&||||j(f ¡ nt)|jd'ƒ |j#s^| $d(¡r’nd r’|j t	 
d)d¡¡ | d*|| | j¡f ¡ |jr°| d+|j*|jf ¡ d S ),Nr  ZPyType_ReadyzExtensionTypes.cZ__Pyx_PyType_Readyzif (%s(&%s) < 0) %sz%s.tp_print = 0;Ztp_getattroZtp_dictoffsetr\  Z#__Pyx_PyObject_GenericGetAttrNoDictZPyObject_GenericGetAttrNoDictZ__Pyx_PyObject_GenericGetAttrZPyObject_GenericGetAttrzObjectHandling.cz„if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!%s.tp_dictoffset && %s.tp_getattro == PyObject_GenericGetAttr)) {z%s.tp_getattro = %s;r¾  )rµ  r¶  z#if CYTHON_COMPILING_IN_CPYTHONrÃ  zEPyObject *wrapper = PyObject_GetAttrString((PyObject *)&%s, "%s"); %sÚwrapperz/if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {z0%s = *((PyWrapperDescrObject *)wrapper)->d_base;z%s.doc = %s;z0((PyWrapperDescrObject *)wrapper)->d_base = &%s;z#endifZ	SetVTablezImportExport.cz+if (__Pyx_SetVtable(%s.tp_dict, %s) < 0) %sZMergeVTablesz#if (__Pyx_MergeVtables(&%s) < 0) %sZinternalz5if (PyObject_SetAttr(%s, %s, (PyObject *)&%s) < 0) %sÚ__weakref__z%s.tp_weaklistoffsetz	struct %sz#if (%s == 0) %s = offsetof(%s, %s);z)__weakref__ slot must be of type 'object'Z__reduce_cython__ZSetupReducez.if (__Pyx_setup_reduce((PyObject*)&%s) < 0) %sz	%s = &%s;)+r/   r  r)  rá   r   Z
slot_tableZgenerate_dynamic_init_coder¾   rc  r   rÉ  rN   r¡  r%   Zget_slot_code_by_namer…  Zpyfunc_entriesr9   r  r   r…  rŠ  r'  r(  r)  rŸ  r‰  Zvtable_cnameZvtabptr_cnameZis_internalr¼   r	   rì  r³  rû  Zis_closure_class_scoperf  r   r*  r
  r  r   rè  )rÃ   rT   Zheap_type_basesr/   r  r)  r*  Z	readyfuncZgetattr_slot_funcZdictoffset_slot_funcZpy_cfuncZutility_funcrY   rÚ   r  Zweakref_entryZtp_weaklistoffsetZ	objstructr&   r&   r'   r  	  sÖ    











z&CClassDefNode.generate_type_ready_codec             C   s(   | j r| j  |¡ | jr$| j |¡ d S )N)r  r‘   r   )r|   rT   r&   r&   r'   r‘     s    zCClassDefNode.annotate)F)rJ   rj   rk   r‡   r  r  r*  rz  r  r  r  r†  r  rn  rŠ  r   ro   r¿   rÀ   rË   r  r‘   r&   r&   r&   r'   rü  
  s*    
# rü  c               @   s:   e Zd ZdgZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚPropertyNoder   c             C   s6   |  | j| j| j¡| _|j| jj_| j | jj¡ d S )N)	r  r9   r-   r%   rÃ   r¼   r)  r   r   )r|   r@   r&   r&   r'   r      s    z!PropertyNode.analyse_declarationsc             C   s   | j  |¡| _ | S )N)r   ro   )r|   r@   r&   r&   r'   ro   ¥  s    z PropertyNode.analyse_expressionsc             C   s   | j  ||¡ d S )N)r   r¿   )r|   r@   rT   r&   r&   r'   r¿   ©  s    z*PropertyNode.generate_function_definitionsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÀ   ¬  s    z$PropertyNode.generate_execution_codec             C   s   | j  |¡ d S )N)r   r‘   )r|   rT   r&   r&   r'   r‘   ¯  s    zPropertyNode.annotateN)	rJ   rj   rk   r‡   r   ro   r¿   rÀ   r‘   r&   r&   r&   r'   r   –  s   r   c               @   s(   e Zd Zg Zdd„ Zdd„ Zdd„ ZdS )Ú
GlobalNodec             C   s"   x| j D ]}| || j¡ qW d S )N)ÚnamesZdeclare_globalr%   )r|   r@   r9   r&   r&   r'   r   º  s    zGlobalNode.analyse_declarationsc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   ¾  s    zGlobalNode.analyse_expressionsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÀ   Á  s    z"GlobalNode.generate_execution_codeN)rJ   rj   rk   r‡   r   ro   rÀ   r&   r&   r&   r'   r!  ³  s   r!  c               @   s(   e Zd Zg Zdd„ Zdd„ Zdd„ ZdS )ÚNonlocalNodec             C   s"   x| j D ]}| || j¡ qW d S )N)r"  Zdeclare_nonlocalr%   )r|   r@   r9   r&   r&   r'   r   Ì  s    z!NonlocalNode.analyse_declarationsc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   Ð  s    z NonlocalNode.analyse_expressionsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÀ   Ó  s    z$NonlocalNode.generate_execution_codeN)rJ   rj   rk   r‡   r   ro   rÀ   r&   r&   r&   r'   r#  Å  s   r#  c               @   sF   e Zd ZdgZdd„ Zdd„ Zdd„ ZdZd	d
„ Zdd„ Z	dd„ Z
dS )rë  rç  c       
      C   sà   ddl m} | j}t||jƒr¢|j ¡ }|dkrÜ| ¡ \}}t|ƒrPt	|j
dƒ xH|jD ]>\}}| |¡}	|	d kr€t	|j
dƒ qX|j|j|	|j
dd qXW t| _n:t|dd ƒd k	rÜ|jrÊ| |¡ t| _n|jsÖ|jrÜt| _d S )	Nr   )rï   rŠ  z!Variable names must be specified.zUnknown typeT)r|  r?   )r§   rï   rç  rH   ZGeneralCallNoderF  Úas_cython_attributeÚexplicit_args_kwdsrG   r   r%   r5   r7   r,  r6   ÚPassStatNoderI   rˆ   r8   Zdeclare_from_annotationÚis_attributeÚis_subscript)
r|   r@   rï   rç  rY   rQ   rR   Úvarr$  r/   r&   r&   r'   r   Þ  s(    


z!ExprStatNode.analyse_declarationsc             C   s"   d| j _| j  |¡| _ d| j _| S )NF)rç  Úresult_is_usedro   )r|   r@   r&   r&   r'   ro   ÷  s    z ExprStatNode.analyse_expressionsc             C   s   | j jjr| j jr|  ¡  d S )N)rç  r/   r:   Úis_tempr€   )r|   r@   r&   r&   r'   r¹   þ  s    zExprStatNode.nogil_checkzDiscarding owned Python objectc             C   sx   |  | j¡ d| j_| j |¡ | jjs\| j ¡ r\| j ¡ }| jjjsNd| }| 	d| ¡ | j 
|¡ | j |¡ d S )NFz
(void)(%s)z%s;)rÊ   r%   rç  r*  rA  r+  r‹   r/   rÛ   rN   r  rH  )r|   rT   r‹   r&   r&   r'   rÀ     s    

z$ExprStatNode.generate_execution_codec             C   s   | j  ||¡ d S )N)rç  r¿   )r|   r@   rT   r&   r&   r'   r¿     s    z*ExprStatNode.generate_function_definitionsc             C   s   | j  |¡ d S )N)rç  r‘   )r|   rT   r&   r&   r'   r‘     s    zExprStatNode.annotateN)rJ   rj   rk   r‡   r   ro   r¹   r   rÀ   r¿   r‘   r&   r&   r&   r'   rë  ×  s   rë  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚAssignmentNodec             C   sB   |   |¡}t|tƒr>t|tƒs>|jjjr>|j ¡ r>t| j	dƒ |S )Nz9Storing unsafe C derivative of temporary Python reference)
rn   rH   r,  ÚParallelAssignmentNodeÚrhsr/   rØ   Zis_ephemeralr   r%   )r|   r@   rS   r&   r&   r'   ro      s
    
z"AssignmentNode.analyse_expressionsc             C   s$   |  | j¡ |  |¡ |  |¡ d S )N)rÊ   r%   Úgenerate_rhs_evaluation_coderK  )r|   rT   r&   r&   r'   rÀ   +  s    
z&AssignmentNode.generate_execution_codeN)rJ   rj   rk   ro   rÀ   r&   r&   r&   r'   r,    s   	r,  c               @   st   e 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d„Zdd„ Zdd„ ZdS )ÚSingleAssignmentNoder  r.  Fc             C   s  ddl m} t| j|jƒr| jj ¡ }|r| j ¡ \}}|dkr°t|ƒdkrft	|d j
dƒ d S |d k	r¢| d ¡}|dksˆd|kr˜t	|j
dƒ d S |d }nd	}|d
  |¡}|d krÐt	|d
 j
dƒ d S | j}	|dkrvt|	|jƒrü|	j|	j
fg}
n0t|	|jƒrdd„ |	jD ƒ}
nt	|	j
dƒ d S x&|
D ]\}}|j|||d|d q2W t|ƒdkrn|d | _nd| _n6d| _t|	|jƒs–t	|	j
dƒ |j|	j|| j
d	d nR|dkr¼d| _t|ƒd
ksØ|d krêt	| jj
dƒ d S g }xJ|jD ]@\}}| |¡}|d kr t	|j
dƒ n| |j||j
f¡ qöW t|ƒt|jƒk rRd S t| j|jƒspt	| jj
dƒ | jj}t|ƒ}| |||d| jj
¡ xj|D ]\}}}| |||¡ qœW nF|dkrd| _|rât	| jjj
dƒ t| jj
| jj|d}| |¡ | jrd S | j |¡ d S )Nr   )rï   )rŠ  Útypedefr"   zInvalid positional argument.r1  rá   zInvalid keyword argument.rL  r   zUnknown typerŠ  c             S   s   g | ]}|j |jf‘qS r&   )r9   r%   )r„   r)  r&   r&   r'   r†   _  s    z=SingleAssignmentNode.analyse_declarations.<locals>.<listcomp>zInvalid declarationT)r|  rá   zInvalid declaration.)rá   )r'  Úunionz.Struct or union members must be given by name.FZ
fused_typez*fused_type does not take keyword arguments)r9   r_   )r§   rï   rH   r.  ZCallNoderF  r$  r%  rG   r   r%   Úcompile_time_valuer7   r  rü   r9   rê   rQ   r,  Údeclaration_onlyrv  r5   rþ   r6   r   r.  ru  r   rÿ  )r|   r@   rï   Z	func_namerQ   rR   Zkwdictrá   r/   r  Úvarsr)  r%   ÚmembersÚmemberr$  r9   r)  Z	fusednoder&   r&   r'   r   B  sˆ    









z)SingleAssignmentNode.analyse_declarationsr   c             C   s¸  ddl m} | j |¡| _|  |¡}|r,|S | j |¡| _| j |¡ |  |¡}|rX|S t	| j|j
ƒr†| j | j¡ | j | j¡| _n@| jjjrÆt	| j|jƒsÆ|j| jj| jd d d| _| j |¡| _| jjjrT| | jd| jj| jjg¡}|r@| j}d| _|jj| _|jj| _| jdkrR| jd krR| t dd¡¡ n| j | jj|¡}n| j | jj|¡}|sŽ|jsŽ|jsš|jsš|jjrš| |¡}n|jjr®| |¡}|| _| S )	Nr   )rï   )rå   rV   Ústopú=Tr  ZCppExceptionConversionzCppSupport.cpp) r§   rï   r.  rn   Ú
unroll_rhsr  rp   Úgil_assignment_checkÚ
unroll_lhsrH   ZMemoryViewIndexNodeZanalyse_broadcast_operationZ$analyse_as_memview_scalar_assignmentr/   rÙ   ÚSliceIndexNoder%   rì   Zlookup_operator_for_typesÚis_overloaded_assignmentr	  rû   rc  r   rÉ  r  r'  r8   r´   r:   Úcoerce_to_tempÚcoerce_to_simple)r|   r@   Úuse_temprï   Zunrolled_assignmentÚopr.  r&   r&   r'   rn   –  sH    







z"SingleAssignmentNode.analyse_typesc          	   C   s6  ddl m}m} |}d  } } }	}
|jjr8|jj}nj|jjsJ|jjržx&t||j	ƒrp|j
sp|jsp|j }}qLW t||j	ƒrt|j}|j
}|rž| tj|¡}|j}|r¸| tj|¡}nT|jjrü|jjrü|j| jt|jjƒt|jjtƒrð|jjn|jd}nt| jdƒ d S d }	|	r$|	 tj|¡}	dd„ }y"||d ƒ||dƒ ||	dƒ }W n" tk
rp   t| jdƒ d S X n(|jjr˜|jj}t|tƒsœd S nd S nd S ||krÄt| jd	||f ƒ d S g }| |¡}|g}|rú|jsú| |¡}| |¡ |r|js| |¡}| |¡ |	r>|	js>| |	¡}	| |	¡ xìt|ƒD ]à}|j| jt|ƒ|tjd
}|	d k	r²|	 ¡ rž|j|	j }|j| jt|ƒ|d}n|j| jd|	|d}|d k	r| ¡ rô| ¡ rô|j|j }|j| jt|ƒ|d}n|j| jd||d}| |j| j||  |¡d¡ qHW |
||fS )Nr   )rï   Ú	UtilNodes)r6   rw  z*C array iteration requires known end indexc             S   s&   | d kr|S |   ¡ r| jS tdƒ‚d S )NzNot a constant.)Úhas_constant_resultrw  rõ   )rS   Z
none_valuer&   r&   r'   Ú	get_constè  s
    z.SingleAssignmentNode.unroll.<locals>.get_constr   z5C array assignment currently requires known endpointsz=Assignment to/from slice of wrong length, expected %s, got %s)r6   rw  r/   r  )ÚoperatorZoperand1Zoperand2r  )rå   rð   )!r§   rï   rC  r/   Ú	is_ctuplerù   rØ   rÙ   rH   r=  rV   r8  rå   r  r
   r±  ZIntNoder%   r  r   Zconstant_value_not_setr   rõ   Z
LetRefNoder´   rþ   rY  rD  rw  ZMulNodeZAddNodeZ	IndexNodern   )r|   rS   Ztarget_sizer@   rï   rC  rå   Z
start_nodeZ	stop_nodeZ	step_nodeÚ
check_nodeZ
slice_sizerE  rb   Úrefsrø   Zix_nodeZ
step_valueZindex_valuer&   r&   r'   ÚunrollÆ  sŠ    "











$zSingleAssignmentNode.unrollc          	   C   s”   ddl m} g }x0t||ƒD ]"\}}	| t| j||	| jd¡ qW t| j|d |¡}
|rlt	| j||
gd}
x"|d d d… D ]}| 
||
¡}
q|W |
S )Nr   )rC  )r  r.  Úfirst)r%   rÇ   rª   )r§   rC  r5  rþ   r0  r%   rK  r-  ro   rÆ   ZLetNode)r|   rI  rH  Úlhs_listZrhs_listr@   rC  Úassignmentsr  r.  rS   r®  r&   r&   r'   Úunroll_assignments$  s    z'SingleAssignmentNode.unroll_assignmentsc             C   sx   ddl m} t| j|jƒsd S tdd„ | jjD ƒƒr8d S |  | jt	| jjƒ|¡}|sXd S |\}}}|  
||| jj||¡S )Nr   )rï   c             s   s   | ]}|j V  qd S )N)Z
is_starred)r„   r2  r&   r&   r'   rÏ   4  s    z2SingleAssignmentNode.unroll_rhs.<locals>.<genexpr>)r§   rï   rH   r  rê   ÚanyrQ   rJ  r.  rG   rN  )r|   r@   rï   ÚunrolledrH  rI  r.  r&   r&   r'   r:  0  s    
zSingleAssignmentNode.unroll_rhsc             C   sl   | j jjrd S ddlm} t| j|jƒs,d S |  | j t	| jj
ƒ|¡}|sLd S |\}}}|  |||| jj
|¡S )Nr   )rï   )r  r/   rG  r§   rï   rH   r.  rê   rJ  rG   rQ   rN  )r|   r@   rï   rP  rH  rI  r  r&   r&   r'   r<  =  s    

zSingleAssignmentNode.unroll_lhsc             C   s   | j  |¡ d S )N)r.  rA  )r|   rT   r&   r&   r'   r/  K  s    z1SingleAssignmentNode.generate_rhs_evaluation_codec             C   s:   | j r&| jj| j|| j | j| jd n| j | j|¡ d S )N)rJ  r	  rû   )r>  r  rK  r.  r	  rû   )r|   rT   rJ  r&   r&   r'   rK  N  s    z-SingleAssignmentNode.generate_assignment_codec             C   s   | j  ||¡ d S )N)r.  r¿   )r|   r@   rT   r&   r&   r'   r¿   Y  s    z2SingleAssignmentNode.generate_function_definitionsc             C   s   | j  |¡ | j |¡ d S )N)r  r‘   r.  )r|   rT   r&   r&   r'   r‘   \  s    zSingleAssignmentNode.annotateN)r   )F)rJ   rj   rk   r‡   rK  r>  r4  r   rn   rJ  rN  r:  r<  r/  rK  r¿   r‘   r&   r&   r&   r'   r0  1  s   T
0^
r0  c               @   sX   e Zd ZddddgZdZdZdZdd„ Zdd	d
„Zdd„ Z	ddd„Z
dd„ Zdd„ ZdS )ÚCascadedAssignmentNoderL  r.  Úcoerced_valuesÚcloned_valuesNc             C   s   x| j D ]}| |¡ qW d S )N)rL  rÿ  )r|   r@   r  r&   r&   r'   r   t  s    z+CascadedAssignmentNode.analyse_declarationsr   c             C   sÒ  ddl m}m} tƒ }x@t| jƒD ]2\}}| |¡ }| j|< | |¡ | |j	¡ q"W | j
 |¡}t|ƒdkr¶tt|ƒƒjr¦| d|| j
g¡}	|	s¶| | ¡ |¡}n| | ¡ |¡}|jsà|jsà|sÔ|jsÔ|j	jrà| |¡}n
| |¡}|jrø||ƒn|| _
g | _i }
g | _x†| jD ]|}|j	jo4| d|| j
g¡}| j |¡ |j	|
kr|j	|j	kr|| j
ƒ}|sz| |j	|¡}| j |¡ ||
|j	< qW g | _x0| jD ]&}|
 |j	| j
¡}| j ||ƒ¡ q¤W | S )Nr   )Ú	CloneNoderø  r9  )rï   rT  rø  rw   r  rL  rp   r;  r¤   r/   r.  rn   rG   ÚnextÚiterrì   Zlookup_operatorr  r  r8   r´   r'  r:   r?  r@  r+  rR  Úassignment_overloadsrþ   rS  r(  )r|   r@   rA  rT  rø  Z	lhs_typesr"  r  r.  rB  rR  Z
overloadedr&   r&   r'   rn   x  sF    


z$CascadedAssignmentNode.analyse_typesc             C   s   | j  |¡ d S )N)r.  rA  )r|   rT   r&   r&   r'   r/  ©  s    z3CascadedAssignmentNode.generate_rhs_evaluation_codeFc             C   s–   x| j D ]}| |¡ qW x:t| j| j| jƒD ]$\}}}| |¡ |j|||d q.W x"| j D ]}| |¡ | |¡ q^W | j	 |¡ | j	 |¡ d S )N)rJ  )
rR  rA  r5  rL  rS  rW  rK  r  rH  r.  )r|   rT   rJ  r.  r  ZoverloadZ	rhs_valuer&   r&   r'   rK  ¬  s    

z/CascadedAssignmentNode.generate_assignment_codec             C   s   | j  ||¡ d S )N)r.  r¿   )r|   r@   rT   r&   r&   r'   r¿   »  s    z4CascadedAssignmentNode.generate_function_definitionsc             C   sZ   x| j D ]}| |¡ qW x.t| j| jƒD ]\}}| |¡ | |¡ q*W | j |¡ d S )N)rR  r‘   r5  rL  rS  r.  )r|   rT   r.  r  r&   r&   r'   r‘   ¾  s    
zCascadedAssignmentNode.annotate)r   )F)rJ   rj   rk   r‡   rS  rR  rW  r   rn   r/  rK  r¿   r‘   r&   r&   r&   r'   rQ  a  s   
1
rQ  c               @   s:   e Zd ZdgZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )r-  rÇ   c             C   s   x| j D ]}| |¡ qW d S )N)rÇ   r   )r|   r@   rÉ   r&   r&   r'   r   ×  s    z+ParallelAssignmentNode.analyse_declarationsc                s   ‡ fdd„| j D ƒ| _ | S )Nc                s   g | ]}|j ˆ d d‘qS )r   )rA  )rn   )r„   rÉ   )r@   r&   r'   r†   Ü  s   z>ParallelAssignmentNode.analyse_expressions.<locals>.<listcomp>)rÇ   )r|   r@   r&   )r@   r'   ro   Û  s    
z*ParallelAssignmentNode.analyse_expressionsc             C   sD   |  | j¡ x| jD ]}| |¡ qW x| jD ]}| |¡ q.W d S )N)rÊ   r%   rÇ   r/  rK  )r|   rT   rÉ   r&   r&   r'   rÀ   æ  s
    z.ParallelAssignmentNode.generate_execution_codec             C   s    x| j D ]}| ||¡ qW d S )N)rÇ   r¿   )r|   r@   rT   rÉ   r&   r&   r'   r¿   í  s    z4ParallelAssignmentNode.generate_function_definitionsc             C   s   x| j D ]}| |¡ qW d S )N)rÇ   r‘   )r|   rT   rÉ   r&   r&   r'   r‘   ñ  s    zParallelAssignmentNode.annotateN)	rJ   rj   rk   r‡   r   ro   rÀ   r¿   r‘   r&   r&   r&   r'   r-  Ç  s   r-  c               @   s<   e Zd ZddgZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚInPlaceAssignmentNoder  r.  c             C   s   | j  |¡ d S )N)r  rÿ  )r|   r@   r&   r&   r'   r   
  s    z*InPlaceAssignmentNode.analyse_declarationsc             C   sl   | j  |¡| _ | j |¡| _| jjs,| jjrB| j  | jj|¡| _ n&| jjjrh| j	dkrh| j  t
j|¡| _ | S )Nz+-)r.  rn   r  rp   Úis_memview_indexÚis_buffer_accessr  r/   Z	is_stringrF  r
   r±  )r|   r@   r&   r&   r'   rn     s    z#InPlaceAssignmentNode.analyse_typesc             C   s
  |  | j¡ | j| j }}| |¡ | |¡ | j}|dkrBd}n|dkrVt| jdƒ |jsb|j	r®|j
jrvt| jdƒ |dkrž|j
jrž|jjd sžt| jdƒ | |||¡ n0|jrÂt| jd	ƒ n| d
| ¡ || ¡ f ¡ | |¡ | |¡ | |¡ | |¡ d S )Nz//ú/z**zNo C inplace power operatorzAIn-place operators not allowed on object buffers in this release.)r[  ú%Z	cdivisionz;In-place non-c divide operators not allowed on int buffers.z4Inplace operators not supported on memoryview slicesz
%s %s= %s;)rÊ   r%   r  r.  rA  Z generate_subexpr_evaluation_coderF  r   rZ  rY  r/   r:   ró   r¾   r¼   Zgenerate_buffer_setitem_codeZis_memview_slicerN   r‹   Zgenerate_subexpr_disposal_codeZfree_subexpr_tempsr  rH  )r|   rT   r  r.  Zc_opr&   r&   r'   rÀ     s,    




z-InPlaceAssignmentNode.generate_execution_codec             C   s   | j  |¡ | j |¡ d S )N)r  r‘   r.  )r|   rT   r&   r&   r'   r‘   4  s    zInPlaceAssignmentNode.annotatec             C   s$   ddl m} | | j| j| j| j¡S )Nr   )rï   )r§   rï   Z
binop_noder%   rF  r  r.  )r|   rï   r&   r&   r'   Úcreate_binop_node8  s    z'InPlaceAssignmentNode.create_binop_nodeN)	rJ   rj   rk   r‡   r   rn   rÀ   r‘   r]  r&   r&   r&   r'   rX  ö  s   rX  c               @   s>   e Zd ZddgZdd„ ZejZdZdd„ Z	dd	„ Z
d
d„ ZdS )ÚPrintStatNodeÚ	arg_tuplerL   c             C   sd   | j r| j  |¡}| |¡| _ | j |¡}| |¡| _| t¡ t| jjƒdkr`| jr`| t	¡ | S )Nr   )
rL   ro   Úcoerce_to_pyobjectr_  rc  Úprinting_utility_coderG   rQ   Úappend_newlineÚprinting_one_utility_code)r|   r@   rL   r_  r&   r&   r'   ro   F  s    

z!PrintStatNode.analyse_expressionszPython print statementc          	   C   sü   |  | j¡ | jr*| j |¡ | j ¡ }nd}t| jjƒdkr| jr| jjd }| |¡ | 	d|| ¡ | 
| j¡f ¡ | |¡ | |¡ nJ| j |¡ | 	d|| j ¡ | j| 
| j¡f ¡ | j |¡ | j |¡ | jrø| j |¡ | j |¡ d S )Nr\  r   r   z"if (__Pyx_PrintOne(%s, %s) < 0) %sz#if (__Pyx_Print(%s, %s, %d) < 0) %s)rÊ   r%   rL   rA  Ú	py_resultrG   r_  rQ   rb  rN   r¡  r  rH  )r|   rT   Zstream_resultr2  r&   r&   r'   rÀ   T  s6    

z%PrintStatNode.generate_execution_codec             C   s&   | j r| j  ||¡ | j ||¡ d S )N)rL   r¿   r_  )r|   r@   rT   r&   r&   r'   r¿   u  s    z+PrintStatNode.generate_function_definitionsc             C   s"   | j r| j  |¡ | j |¡ d S )N)rL   r‘   r_  )r|   rT   r&   r&   r'   r‘   z  s    zPrintStatNode.annotateN)rJ   rj   rk   r‡   ro   ry   r€   r¹   r   rÀ   r¿   r‘   r&   r&   r&   r'   r^  =  s   !r^  c               @   s4   e Zd ZdgZdd„ ZejZdZdd„ Z	dd„ Z
d	S )
ÚExecStatNoderQ   c             C   sF   x4t | jƒD ]&\}}| |¡}| |¡}|| j|< qW | tj¡ | S )N)r  rQ   ro   r`  rc  r   Zpyexec_utility_code)r|   r@   r"  r2  r&   r&   r'   ro   ‡  s    

z ExecStatNode.analyse_expressionszPython exec statementc             C   sÜ   |  | j¡ g }x&| jD ]}| |¡ | | ¡ ¡ qW t|ddgd dt|ƒ …  ƒ}|jj	t
jdd}| d|f|  ¡ x"| jD ]}| |¡ | |¡ q†W | | || j¡¡ | |¡ | |t¡ |j |¡ d S )Nr\  r$   T)r›  z%s = __Pyx_PyExec3(%s, %s, %s);)rÊ   r%   rQ   rA  rþ   rd  r¸  rG   rœ  r  r
   r   rN   r  rH  rŸ  r   r¢  r£  )r|   rT   rQ   r2  Ztemp_resultr&   r&   r'   rÀ   ’  s     
 

z$ExecStatNode.generate_execution_codec             C   s   x| j D ]}| |¡ qW d S )N)rQ   r‘   )r|   rT   r2  r&   r&   r'   r‘   ¤  s    zExecStatNode.annotateN)rJ   rj   rk   r‡   ro   ry   r€   r¹   r   rÀ   r‘   r&   r&   r&   r'   re  €  s   re  c               @   sB   e Zd ZdgZdZdd„ Zdd„ Zdd„ Zd	Zd
d„ Z	dd„ Z
dS )ÚDelStatNoderQ   Fc             C   s   x| j D ]}| |¡ qW d S )N)rQ   rÿ  )r|   r@   r2  r&   r&   r'   r   ±  s    z DelStatNode.analyse_declarationsc             C   sº   x´t | jƒD ]¦\}}| |d ¡ }| j|< |jjs@|jr\|jjr\|jr²|jjr²t	|j
dƒ q|jjrz|jjjrz|  |¡ q|jjrt	|j
dƒ q|jr¦|jjtjkr¦qt	|j
dƒ qW | S )NzDeletion of global C variablezDeletion of non-heap C++ objectz&Deletion of non-Python, non-C++ object)r  rQ   r  r/   r:   r8   r€  rÃ   Z
is_cglobalr   r%   rØ   rB   rì   r‚   r(  rå   r   Úbytearray_type)r|   r@   r"  r2  r&   r&   r'   ro   µ  s    zDelStatNode.analyse_expressionsc             C   s$   x| j D ]}|jjr|  ¡  qW d S )N)rQ   r/   r:   r€   )r|   r@   r2  r&   r&   r'   r¹   Æ  s    zDelStatNode.nogil_checkzDeleting Python objectc             C   sŽ   |  | j¡ x|| jD ]r}|jjs<|jjs<|jrN|jjtj	krN|j
|| jd q|jjr|jjjr| |¡ | d| ¡  ¡ | |¡ qW d S )N)Úignore_nonexistingz
delete %s;)rÊ   r%   rQ   r/   r:   r€  r(  rå   r   rg  Zgenerate_deletion_coderh  rØ   rB   rì   rA  rN   r‹   r  )r|   rT   r2  r&   r&   r'   rÀ   Í  s    
z#DelStatNode.generate_execution_codec             C   s   x| j D ]}| |¡ qW d S )N)rQ   r‘   )r|   rT   r2  r&   r&   r'   r‘   Û  s    zDelStatNode.annotateN)rJ   rj   rk   r‡   rh  r   ro   r¹   r   rÀ   r‘   r&   r&   r&   r'   rf  ©  s   rf  c               @   s    e Zd Zg Zdd„ Zdd„ ZdS )r&  c             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   å  s    z PassStatNode.analyse_expressionsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÀ   è  s    z$PassStatNode.generate_execution_codeN)rJ   rj   rk   r‡   ro   rÀ   r&   r&   r&   r'   r&  à  s   r&  c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚIndirectionNodez†
    This adds an indirection so that the node can be shared and a subtree can
    be removed at any time by clearing self.stats.
    c                s   t t| ƒj|d j|d d S )Nr   )rÇ   )rc   ri  r~   r%   )r|   rÇ   )rI   r&   r'   r~   ò  s    zIndirectionNode.__init__)rJ   rj   rk   rv   r~   rl   r&   r&   )rI   r'   ri  ì  s   ri  c               @   s$   e Zd Zg ZdZdd„ Zdd„ ZdS )ÚBreakStatNodeTc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   û  s    z!BreakStatNode.analyse_expressionsc             C   s0   |  | j¡ |js t| jdƒ n| |j¡ d S )Nzbreak statement not inside loop)rÊ   r%   Úbreak_labelr   rù  )r|   rT   r&   r&   r'   rÀ   þ  s    z%BreakStatNode.generate_execution_codeN)rJ   rj   rk   r‡   rµ   ro   rÀ   r&   r&   r&   r'   rj  ö  s   rj  c               @   s$   e Zd Zg ZdZdd„ Zdd„ ZdS )ÚContinueStatNodeTc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro     s    z$ContinueStatNode.analyse_expressionsc             C   s2   |j st| jdƒ d S | | j¡ | |j ¡ d S )Nz"continue statement not inside loop)Úcontinue_labelr   r%   rÊ   rù  )r|   rT   r&   r&   r'   rÀ     s
    z(ContinueStatNode.generate_execution_codeN)rJ   rj   rk   r‡   rµ   ro   rÀ   r&   r&   r&   r'   rl    s   rl  c               @   sV   e Zd ZdgZdZdZdZdZdd„ Zdd„ Z	dZ
d	d
„ Zdd„ Zdd„ Zdd„ ZdS )rH  r6   TFc             C   s˜   |j }|| _ |s t| jdƒ | S | jrv| jr8t| jdƒ | j |¡| _|jsR|jrbt| jjdƒ q”| j |j |¡| _n|js”|j	s”|js”t| jdƒ | S )Nz!Return not inside a function bodyz$Return with value in async generatorz"Return with value in void functionzReturn value required)
r  r   r%   r6   Úin_async_genrn   rÛ   rê  r  r:   )r|   r@   r  r&   r&   r'   ro   &  s"    z"ReturnStatNode.analyse_expressionsc             C   s   | j jr|  ¡  d S )N)r  r:   r€   )r|   r@   r&   r&   r'   r¹   ;  s    zReturnStatNode.nogil_checkzReturning Python objectc             C   sª  |  | j¡ | jsd S | j}| jjrB| tj| j¡ |rB|jrBd }|rþ| 	|¡ | jj
r„ddlm} |jtj| j|j||| jd nd| jrÂ|j t dd¡¡ | dtj| ¡ f ¡ | |¡ n&| |¡ | dtj| | j¡f ¡ | |¡ | |¡ nv| jjrZ| jrH| jr6|j t dd¡¡ | d	¡ | d
tj ¡ n| tj| j¡ n| jjrt|  || jj ¡ x$|j! "¡ D ]\}}| #||¡ q€W | $|j%¡ d S )Nr   )r`  )Z	lhs_cnameZlhs_typeZlhs_posr.  rT   r¿  ZReturnWithStopIterationzCoroutine.cz-%s = NULL; __Pyx_ReturnWithStopIteration(%s);z%s = %s;rá  z/PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration); z
%s = NULL;)&rÊ   r%   r  r6   r:   rý  r	   rØ  r³   rA  r€  r§   r`  Zput_acquire_memoryviewslicerº   Úin_generatorr¾   rc  r   rÉ  rN   rd  r  rD  rE  rG  rH  rn  rÒ  rö  rê  Ú
put_returnr@  rœ  Ztemps_holding_referencer¢  rù  rú  )r|   rT   r6   r`  r  r/   r&   r&   r'   rÀ   A  sZ    






z&ReturnStatNode.generate_execution_codec             C   s(   | j r| d¡ | dtj|f ¡ d S )Nz%#pragma omp critical(__pyx_returning)z%s = %s;)Úin_parallelÚputln_openmprN   r	   rØ  )r|   rT   r6   r&   r&   r'   rp  z  s    
zReturnStatNode.put_returnc             C   s   | j d k	r| j  ||¡ d S )N)r6   r¿   )r|   r@   rT   r&   r&   r'   r¿     s    
z,ReturnStatNode.generate_function_definitionsc             C   s   | j r| j  |¡ d S )N)r6   r‘   )r|   rT   r&   r&   r'   r‘   ƒ  s    zReturnStatNode.annotateN)rJ   rj   rk   r‡   rµ   ro  rn  rq  ro   r¹   r   rÀ   rp  r¿   r‘   r&   r&   r&   r'   rH    s   9rH  c               @   sF   e Zd ZddddgZdZdd„ ZejZdZ	d	d
„ Z
dd„ Zdd„ ZdS )ÚRaiseStatNodeÚexc_typeÚ	exc_valueÚexc_tbÚcauseTc             C   sö   | j r| j  |¡}| |¡| _ | jr<| j |¡}| |¡| _| jrZ| j |¡}| |¡| _| jrx| j |¡}| |¡| _d | _| j rò| jsò| jsò| j }ddlm} t	||j
ƒrÌ|jsÌ|jd k	rÆ|jjsÌ|j}|jrò|jjrò|j| _| jdkròd | _ | S )Nr   )rï   ÚMemoryError)rt  rn   r`  ru  rv  rw  Úbuiltin_exc_namer§   rï   rH   rG  rQ   r_  rF  r8   rÃ   Ú
is_builtinr9   )r|   r@   rt  ru  rv  rw  Úexcrï   r&   r&   r'   ro   “  s0    
z!RaiseStatNode.analyse_expressionszRaising exceptionc             C   sB  |  | j¡ | jdkr0| d| | j¡ ¡ d S | jrf| j |¡ | j ¡ }| jjrj|j	 
| jj¡ nd}| jrˆ| j |¡ | j ¡ }nd}| jrª| j |¡ | j ¡ }nd}| jrÌ| j |¡ | j ¡ }nd}|j	 t¡ | d||||f ¡ x8| j| j| j| jfD ] }|r| |¡ | |¡ qW | | | j¡¡ d S )Nrx  zPyErr_NoMemory(); %sr\  z__Pyx_Raise(%s, %s, %s, %s);)rÊ   r%   ry  rN   r¡  rt  rA  rd  r8   r¾   Zuse_entry_utility_coderÃ   ru  rv  rw  rc  Úraise_utility_coder  rH  )r|   rT   Z	type_codeZ
value_codeZtb_codeZ
cause_coder   r&   r&   r'   rÀ   ±  sF    



z%RaiseStatNode.generate_execution_codec             C   sd   | j d k	r| j  ||¡ | jd k	r0| j ||¡ | jd k	rH| j ||¡ | jd k	r`| j ||¡ d S )N)rt  r¿   ru  rv  rw  )r|   r@   rT   r&   r&   r'   r¿   Û  s    



z+RaiseStatNode.generate_function_definitionsc             C   sL   | j r| j  |¡ | jr$| j |¡ | jr6| j |¡ | jrH| j |¡ d S )N)rt  r‘   ru  rv  rw  )r|   rT   r&   r&   r'   r‘   å  s    zRaiseStatNode.annotateN)rJ   rj   rk   r‡   rµ   ro   ry   r€   r¹   r   rÀ   r¿   r‘   r&   r&   r&   r'   rs  ˆ  s   *
rs  c               @   s.   e Zd Zg ZdZdd„ ZejZdZ	dd„ Z
dS )ÚReraiseStatNodeTc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   õ  s    z#ReraiseStatNode.analyse_expressionszRaising exceptionc             C   sÆ   |  | j¡ |jj}|r˜|j t¡ | |d ¡ | |d ¡ | |d ¡ | 	dt
|ƒ ¡ x|D ]}| d| ¡ qfW | 	¡  | 	| | j¡¡ n*|j t dd¡¡ | 	d| | j¡ ¡ d S )	Nr   r   r"   z&__Pyx_ErrRestoreWithState(%s, %s, %s);z%s = 0; ZReRaiseExceptionzExceptions.cz__Pyx_ReraiseException(); %s)rÊ   r%   rœ  Úexc_varsr¾   rc  rþ  rF  r	  rN   r¸  rÒ  r¡  r   rÉ  )r|   rT   r5  Zvarnamer&   r&   r'   rÀ   û  s    
z'ReraiseStatNode.generate_execution_codeN)rJ   rj   rk   r‡   rµ   ro   ry   r€   r¹   r   rÀ   r&   r&   r&   r'   r}  ð  s   r}  c               @   s>   e Zd ZddgZdd„ ZejZdZdd„ Z	dd	„ Z
d
d„ ZdS )ÚAssertStatNoder  r6   c             C   sz   | j  |¡| _ | jrv| j |¡}|jtjks4|jjsjddlm	} ||j
|gdd}|j|dd |¡| _n| |¡| _| S )Nr   )rê   T)rQ   Zslow)Zskip_children)r  Zanalyse_boolean_expressionr6   rn   r/   r   Z
tuple_typer  rï   rê   r%   r`  )r|   r@   r6   rê   r&   r&   r'   ro     s    z"AssertStatNode.analyse_expressionszRaising exceptionc             C   sÖ   |  d¡ |  d¡ | | j¡ | j |¡ |  d| j ¡  ¡ | jr€| j |¡ |  d| j ¡  ¡ | j |¡ | j 	|¡ n
|  d¡ |  | 
| j¡¡ |  d¡ | j |¡ | j 	|¡ |  d¡ |  d¡ d S )Nz!#ifndef CYTHON_WITHOUT_ASSERTIONSz!if (unlikely(!Py_OptimizeFlag)) {zif (unlikely(!%s)) {z*PyErr_SetObject(PyExc_AssertionError, %s);z$PyErr_SetNone(PyExc_AssertionError);r¾  z#endif)rN   rÊ   r%   r  rA  r‹   r6   rd  r  rH  r¡  )r|   rT   r&   r&   r'   rÀ   &  s.    

z&AssertStatNode.generate_execution_codec             C   s*   | j  ||¡ | jd k	r&| j ||¡ d S )N)r  r¿   r6   )r|   r@   rT   r&   r&   r'   r¿   @  s    
z,AssertStatNode.generate_function_definitionsc             C   s"   | j  |¡ | jr| j |¡ d S )N)r  r‘   r6   )r|   rT   r&   r&   r'   r‘   E  s    zAssertStatNode.annotateN)rJ   rj   rk   r‡   ro   ry   r€   r¹   r   rÀ   r¿   r‘   r&   r&   r&   r'   r    s   r  c               @   sF   e Zd ZddgZdd„ Zdd„ Zdd„ Zdd
d„Zdd„ Zdd„ Z	dS )Ú
IfStatNodeÚ
if_clausesÚelse_clausec             C   s0   x| j D ]}| |¡ qW | jr,| j |¡ d S )N)r  r   r‚  )r|   r@   Ú	if_clauser&   r&   r'   r   S  s    zIfStatNode.analyse_declarationsc                s.   ‡ fdd„| j D ƒ| _ | jr*| j ˆ ¡| _| S )Nc                s   g | ]}|  ˆ ¡‘qS r&   )ro   )r„   rƒ  )r@   r&   r'   r†   Z  s    z2IfStatNode.analyse_expressions.<locals>.<listcomp>)r  r‚  ro   )r|   r@   r&   )r@   r'   ro   Y  s    zIfStatNode.analyse_expressionsc             C   sÂ   |  | j¡ | ¡ }t| jƒ}| jr>| j| jd | jdd n|d8 }x8t| jƒD ]*\}}|  ||j¡ |j	||||kd qRW | jr´|  | jj¡ | 
d¡ | j 	|¡ | 
d¡ | |¡ d S )Nrª   T)Úinverser   )Úis_lastz
/*else*/ {r¾  )rÊ   r%   rË  rG   r  r‚  Ú_set_branch_hintr  r   rÀ   rN   rû  )r|   rT   r«  Zlastr"  rƒ  r&   r&   r'   rÀ   _  s    


z"IfStatNode.generate_execution_codeFc             C   s†   |j s
d S t|tƒr|jsd S t|jd ttfƒr‚t|jƒdkrtttt	t
tf}x$|jd d… D ]}t||ƒs^d S q^W |r|dnd|_d S )Nrª   r   r´  r  )rµ   rH   rÆ   rÇ   rs  r}  rG   rë  r,  rf  r!  r#  Úbranch_hint)r|   ÚclauseZstatements_noder„  Znon_branch_nodesrS   r&   r&   r'   r†  r  s    
zIfStatNode._set_branch_hintc             C   s8   x| j D ]}| ||¡ qW | jd k	r4| j ||¡ d S )N)r  r¿   r‚  )r|   r@   rT   rˆ  r&   r&   r'   r¿     s    
z(IfStatNode.generate_function_definitionsc             C   s0   x| j D ]}| |¡ qW | jr,| j |¡ d S )N)r  r‘   r‚  )r|   rT   rƒ  r&   r&   r'   r‘   ‡  s    zIfStatNode.annotateN)F)
rJ   rj   rk   r‡   r   ro   rÀ   r†  r¿   r‘   r&   r&   r&   r'   r€  K  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S )ÚIfClauseNodeÚ	conditionr   Nc             C   s   | j  |¡ d S )N)r   r   )r|   r@   r&   r&   r'   r   —  s    z!IfClauseNode.analyse_declarationsc             C   s    | j  |¡| _ | j |¡| _| S )N)rŠ  Úanalyse_temp_boolean_expressionr   ro   )r|   r@   r&   r&   r'   ro   š  s    z IfClauseNode.analyse_expressionsc             C   sœ   | j  |¡ | | j¡ | j  ¡ }| jr6d| j|f }| d| ¡ | j  |¡ | j  |¡ | j	 
|¡ |j| jdd |sŽ| j	jsŽ| |¡ | d¡ d S )Nz%s(%s)z	if (%s) {F)rÀ  r¾  )rŠ  rA  rÊ   r%   r‹   r‡  rN   r  rH  r   rÀ   rµ   rù  )r|   rT   r«  r…  rŠ  r&   r&   r'   rÀ   Ÿ  s    

z$IfClauseNode.generate_execution_codec             C   s    | j  ||¡ | j ||¡ d S )N)rŠ  r¿   r   )r|   r@   rT   r&   r&   r'   r¿   ®  s    z*IfClauseNode.generate_function_definitionsc             C   s   | j  |¡ | j |¡ d S )N)rŠ  r‘   r   )r|   rT   r&   r&   r'   r‘   ²  s    zIfClauseNode.annotate)
rJ   rj   rk   r‡   r‡  r   ro   rÀ   r¿   r‘   r&   r&   r&   r'   r‰  Ž  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 )ÚSwitchCaseNodeÚ
conditionsr   c             C   s   x| j D ]}| |¡ qW d S )N)r  rA  )r|   rT   r  r&   r&   r'   Ú"generate_condition_evaluation_code¿  s    z1SwitchCaseNode.generate_condition_evaluation_codec             C   sŽ   t | jƒ}|jjd }xLt| jdƒD ]<\}}| d| ¡  ¡ | |j¡ |r$||k r$| d¡ q$W | j	 
|¡ |j| jdd | d¡ d S )Nr¸  r   zcase %s:zCYTHON_FALLTHROUGH;F)rÀ  zbreak;)rG   r  r¾   r¼   r  rN   r‹   rÊ   r%   r   rÀ   )r|   rT   Znum_conditionsZline_tracing_enabledr"  r  r&   r&   r'   rÀ   Ã  s    
z&SwitchCaseNode.generate_execution_codec             C   s.   x| j D ]}| ||¡ qW | j ||¡ d S )N)r  r¿   r   )r|   r@   rT   r  r&   r&   r'   r¿   Ð  s    z,SwitchCaseNode.generate_function_definitionsc             C   s*   x| j D ]}| |¡ qW | j |¡ d S )N)r  r‘   r   )r|   rT   r  r&   r&   r'   r‘   Õ  s    zSwitchCaseNode.annotateN)rJ   rj   rk   r‡   rŽ  rÀ   r¿   r‘   r&   r&   r&   r'   rŒ  ·  s
   rŒ  c               @   s.   e Zd ZdddgZdd„ Zdd„ Zdd	„ Zd
S )ÚSwitchStatNodeÚtestÚcasesr‚  c             C   s¤   | j  |¡ x| jD ]}| |¡ qW | | j¡ | d| j  ¡  ¡ x| jD ]}| |¡ qNW | j	d k	rŒ| d¡ | j	 |¡ | d¡ n
| d¡ | d¡ d S )Nzswitch (%s) {zdefault:zbreak;zdefault: break;r¾  )
r  rA  r‘  rŽ  rÊ   r%   rN   r‹   rÀ   r‚  )r|   rT   Úcaser&   r&   r'   rÀ   ä  s    


z&SwitchStatNode.generate_execution_codec             C   sF   | j  ||¡ x| jD ]}| ||¡ qW | jd k	rB| j ||¡ d S )N)r  r¿   r‘  r‚  )r|   r@   rT   r’  r&   r&   r'   r¿   ù  s
    
z,SwitchStatNode.generate_function_definitionsc             C   s@   | j  |¡ x| jD ]}| |¡ qW | jd k	r<| j |¡ d S )N)r  r‘   r‘  r‚  )r|   rT   r’  r&   r&   r'   r‘      s
    
zSwitchStatNode.annotateN)rJ   rj   rk   r‡   rÀ   r¿   r‘   r&   r&   r&   r'   r  Û  s   
r  c               @   s   e Zd ZdS )ÚLoopNodeN)rJ   rj   rk   r&   r&   r&   r'   r“    s   r“  c               @   s>   e Zd ZdddgZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )ÚWhileStatNoderŠ  r   r‚  c             C   s"   | j  |¡ | jr| j |¡ d S )N)r   r   r‚  )r|   r@   r&   r&   r'   r     s    z"WhileStatNode.analyse_declarationsc             C   s:   | j r| j  |¡| _ | j |¡| _| jr6| j |¡| _| S )N)rŠ  r‹  r   ro   r‚  )r|   r@   r&   r&   r'   ro     s    z!WhileStatNode.analyse_expressionsc             C   sÐ   |  | j¡ | ¡ }| d¡ | jr\| j |¡ | j |¡ | d| j ¡  ¡ | j |¡ | j	 
|¡ | |j¡ | d¡ |j}| |¡ | jrÂ|  | jj¡ | d¡ | j 
|¡ | d¡ | |¡ d S )Nzwhile (1) {zif (!%s) break;r¾  z
/*else*/ {)rÊ   r%   Únew_loop_labelsrN   rŠ  rA  r  r‹   rH  r   rÀ   rû  rm  rk  Úset_loop_labelsr‚  )r|   rT   Úold_loop_labelsrk  r&   r&   r'   rÀ   "  s*    



z%WhileStatNode.generate_execution_codec             C   s>   | j r| j  ||¡ | j ||¡ | jd k	r:| j ||¡ d S )N)rŠ  r¿   r   r‚  )r|   r@   rT   r&   r&   r'   r¿   9  s
    
z+WhileStatNode.generate_function_definitionsc             C   s4   | j r| j  |¡ | j |¡ | jr0| j |¡ d S )N)rŠ  r‘   r   r‚  )r|   rT   r&   r&   r'   r‘   @  s
    zWhileStatNode.annotateN)	rJ   rj   rk   r‡   r   ro   rÀ   r¿   r‘   r&   r&   r&   r'   r”    s   
r”  c            
   @   s\   e Zd Zddddddddd	d
g
Zd ZZd ZZd ZZ	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚDictIterationNextNodeÚdict_objÚexpected_sizeÚpos_index_varÚcoerced_key_varÚcoerced_value_varÚcoerced_tuple_varÚ
key_targetÚvalue_targetÚtuple_targetÚis_dict_flagNc             C   s(   t j| |j|||||||dtjd d S )NT)	r™  rš  r›  rŸ  r   r¡  r¢  r+  r/   )ry   r~   r%   r
   Úc_bint_type)r|   r™  rš  r›  rŸ  r   r¡  r¢  r&   r&   r'   r~   T  s    zDictIterationNextNode.__init__c             C   s  ddl m} | j |¡| _| j |¡| _| jr<| j |¡| _| jrx| j |¡| _| | jj	t
j¡| _| j | jj|¡| _| jr¶| j |¡| _|j| jj	t
jd| _| j | jj|¡| _| jrò| j |¡| _| | jj	t
j¡| _| j | jj|¡| _| j |¡| _| S )Nr   )rï   )r/   )r§   rï   r™  rn   rš  r›  rŸ  rp   ÚTempNoder%   r
   r   Úkey_refr  r/   rœ  r   Ú	value_refr  r¡  Ú	tuple_refrž  r¢  )r|   r@   rï   r&   r&   r'   ro   b  s&    z)DictIterationNextNode.analyse_expressionsc             C   s   | j  ||¡ d S )N)r™  r¿   )r|   r@   rT   r&   r&   r'   r¿   w  s    z3DictIterationNextNode.generate_function_definitionsc       	      C   sœ  |j  t dd¡¡ | j |¡ g }g }xz| j| j| jf| j	| j
| jf| j| j| jfgD ]H\}}}|d krpd}n&| |||f¡ | |¡ d| ¡  }| |¡ qXW |j tjd¡}| d|| j ¡ | j ¡ | j ¡ |d |d |d	 | j ¡ f ¡ | d
| ¡ | | d| | j¡¡ |j |¡ x"|D ]\}}}| | ¡ ¡ q.W x|D ]\}}}| |¡ qRW x*|D ]"\}}}| ||¡ |  |¡ qrW d S )NZ	dict_iterz
Optimize.cr]  z&%sFz7%s = __Pyx_dict_iter_next(%s, %s, &%s, %s, %s, %s, %s);r   r   r"   zif (unlikely(%s == 0)) break;z%s == -1)!r¾   rc  r   rÉ  r™  rA  r¥  rœ  rŸ  r¦  r  r   r§  rž  r¡  rþ   Úallocater‹   rœ  r  r
   r<   rN   rd  rš  r›  r¢  Úerror_goto_ifr%   r£  r   rK  Úrelease)	r|   rT   rM  Ztemp_addressesr)  r‹   rI  ZaddrÚresult_tempr&   r&   r'   rÀ   z  sB    
z-DictIterationNextNode.generate_execution_code)rJ   rj   rk   r‡   rœ  r¥  r  r¦  rž  r§  r~   ro   r¿   rÀ   r&   r&   r&   r'   r˜  H  s   r˜  c               @   sD   e Zd ZddddddgZd ZZdd	„ Zd
d„ Zdd„ Zdd„ Z	dS )ÚSetIterationNextNodeÚset_objrš  r›  r  r   Úis_set_flagNc             C   s$   t j| |j|||||dtjd	 d S )NT)r­  rš  r›  r   r®  r+  r/   )ry   r~   r%   r
   r£  )r|   r­  rš  r›  r   r®  r&   r&   r'   r~   ¬  s    zSetIterationNextNode.__init__c             C   s€   ddl m} | j |¡| _| j |¡| _| j |¡| _| j |¡| _|j| jj	t
jd| _| j | jj|¡| _| j |¡| _| S )Nr   )rï   )r/   )r§   rï   r­  rn   rš  r›  r   rp   r¤  r%   r
   r   r¦  r  r/   r  r®  )r|   r@   rï   r&   r&   r'   ro   ·  s    z(SetIterationNextNode.analyse_expressionsc             C   s   | j  ||¡ d S )N)r­  r¿   )r|   r@   rT   r&   r&   r'   r¿   Â  s    z2SetIterationNextNode.generate_function_definitionsc          
   C   sà   |j  t dd¡¡ | j |¡ | j}| |¡ |j 	t
jd¡}| d|| j ¡ | j ¡ | j ¡ | ¡ | j ¡ f ¡ | d| ¡ | | d| | j¡¡ |j |¡ | | ¡ ¡ | j |¡ | j | j|¡ | |¡ d S )NZset_iterz
Optimize.cFz/%s = __Pyx_set_iter_next(%s, %s, &%s, &%s, %s);zif (unlikely(%s == 0)) break;z%s == -1)r¾   rc  r   rÉ  r­  rA  r¦  r¨  rœ  r  r
   r<   rN   rd  rš  r‹   r›  r®  r©  r%   r£  r   r  r   rK  rª  )r|   rT   r¦  r«  r&   r&   r'   rÀ   Å  s&    
z,SetIterationNextNode.generate_execution_code)
rJ   rj   rk   r‡   r  r¦  r~   ro   r¿   rÀ   r&   r&   r&   r'   r¬  ¤  s   
r¬  c             K   s<   d|kr,|d j rt| f|ŽS t| f|ŽS nt| f|ŽS d S )NÚiterator)Úis_asyncÚAsyncForStatNodeÚForInStatNodeÚForFromStatNode)r%   r}   r&   r&   r'   ÚForStatNodeà  s
    
r´  c               @   sR   e Zd Zdddd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S )Ú_ForInStatNoderI  r™   r¯  r   r‚  NFc             C   s   t dƒ‚d S )Nz!must be implemented by subclasses)ÚNotImplementedError)r|   r&   r&   r'   Ú_create_item_nodeø  s    z _ForInStatNode._create_item_nodec             C   s6   | j  |¡ | j |¡ | jr*| j |¡ |  ¡  d S )N)rI  rÿ  r   r   r‚  r·  )r|   r@   r&   r&   r'   r   û  s
    z#_ForInStatNode.analyse_declarationsc             C   sš   | j  |¡| _ | j |¡| _|  ¡  | j |¡| _| js`| jjjsL| jjj	r`| j j 
| jj¡r`n| j | j j|¡| _| j |¡| _| jr–| j |¡| _| S )N)rI  rp   r¯  ro   r·  r™   r°  r/   rØ   rÙ   r  r  r   r‚  )r|   r@   r&   r&   r'   ro     s    z"_ForInStatNode.analyse_expressionsc             C   sL  |  | j¡ | ¡ }| j |¡ | d¡ | j |¡ | j | j|¡ | j	 
|¡ |  | j¡ | |j¡ | d¡ |j}| |¡ | jr|j}| d¡|_| d¡ | j 
|¡ | d¡ | |j¡r| |¡ |  | j¡ | |j¡ | j |¡ | |¡ | |¡ |  | j¡ | |¡r0| |¡ | j |¡ | j |¡ d S )Nz
for (;;) {r¾  Zouter_continuez
/*else*/ {)rÊ   r%   r•  r¯  rA  rN   r™   rI  rK  r   rÀ   rû  rm  rk  r–  r‚  rË  r¥  rù  r  rH  )r|   rT   r—  rk  Zorig_continue_labelr&   r&   r'   rÀ     s<    








z&_ForInStatNode.generate_execution_codec             C   sF   | j  ||¡ | j ||¡ | j ||¡ | jd k	rB| j ||¡ d S )N)rI  r¿   r¯  r   r‚  )r|   r@   rT   r&   r&   r'   r¿   ;  s
    
z,_ForInStatNode.generate_function_definitionsc             C   sF   | j  |¡ | j |¡ | j |¡ | jr6| j |¡ | j |¡ d S )N)rI  r‘   r¯  r   r‚  r™   )r|   rT   r&   r&   r'   r‘   B  s    z_ForInStatNode.annotate)rJ   rj   rk   r‡   r™   r°  r·  r   ro   rÀ   r¿   r‘   r&   r&   r&   r'   rµ  ê  s   
(rµ  c               @   s   e Zd ZdZdd„ ZdS )r²  Fc             C   s   ddl m} || jƒ| _d S )Nr   )ÚNextNode)rï   r¸  r¯  r™   )r|   r¸  r&   r&   r'   r·  P  s    zForInStatNode._create_item_nodeN)rJ   rj   rk   r°  r·  r&   r&   r&   r'   r²  K  s   r²  c               @   s    e Zd ZdZdd„ Zdd„ ZdS )r±  Tc             K   sD   d|kst ‚ddlm} |j|d jd d|d< tj| |f|Ž d S )Nr™   r   )rï   r¯  )r2  )r÷  r§   rï   ZAwaitIterNextExprNoder%   rµ  r~   )r|   r%   r}   rï   r&   r&   r'   r~   ]  s    zAsyncForStatNode.__init__c             C   s    ddl m} | | j¡| j_d S )Nr   )rï   )r§   rï   ZAsyncNextNoder¯  r™   r2  )r|   rï   r&   r&   r'   r·  d  s    z"AsyncForStatNode._create_item_nodeN)rJ   rj   rk   r°  r~   r·  r&   r&   r&   r'   r±  U  s   r±  c               @   sv   e Zd Zdddd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„ Zdd„ ZdddddœZdd„ Zdd„ ZdS )r³  rI  Úbound1Úbound2Ústepr   r‚  FNz&For-loop using object bounds or targetc             C   s.   x(| j | j| jfD ]}|jjr|  ¡  qW d S )N)rI  r¹  rº  r/   r:   r€   )r|   r@   r…   r&   r&   r'   r¹   „  s    zForFromStatNode.nogil_checkc             C   s.   | j  |¡ | j |¡ | jr*| j |¡ d S )N)rI  rÿ  r   r   r‚  )r|   r@   r&   r&   r'   r   ‰  s    z$ForFromStatNode.analyse_declarationsc             C   s¾   ddl m} | j |¡| _| j |¡| _| j |¡| _| jd k	rlt| j|j	ƒr^t
| jjddƒ | j |¡| _|  |¡ | jj}|js˜|js˜t| jjdƒ | j |¡| _| jrº| j |¡| _| S )Nr   )rï   zdProbable infinite loop in for-from-by statement. Consider switching the directions of the relations.r"   z>for-from loop variable must be c numeric type or Python object)r§   rï   rI  rp   r¹  rn   rº  r»  rH   ZUnaryMinusNoder   r%   Úset_up_loopr/   r:   rZ  r   r   ro   r‚  )r|   r@   rï   rå  r&   r&   r'   ro     s"    


z#ForFromStatNode.analyse_expressionsc             C   s|  ddl m} | jj}|jr |}n~|jr4t| jjdƒ |jr@t	j
nt	j}| jjjs`t	 || jj¡}| jjjszt	 || jj¡}| jd k	rž| jjjsžt	 || jj¡}| j ||¡| _| j ||¡| _| jjsÔ| j |¡| _| jd k	r| j ||¡| _| jjs| j |¡| _|js|jrJd| _t| j|jƒr:t| jdƒ‚| j| _d | _n.d| _| | j||¡}|| _| |¡ |¡| _d S )Nr   )rï   zWInteger loops over enum values are fragile. Please cast to a safe integer type instead.FzEBuffer or memoryview slicing/indexing not allowed as for-loop target.T)r§   rï   rI  r/   rZ  Úis_enumr   r%   r:   r
   r;   r<   r¹  Úwidest_numeric_typerº  r»  r  r´   r?  Úis_py_targetrH   ZBufferIndexNoder   Úloopvar_nodeÚpy_loopvar_noder¤  rT  r`  )r|   r@   rï   rå  Z	loop_typeZc_loopvar_noder&   r&   r'   r¼  ¤  s@    


zForFromStatNode.set_up_loopc             C   s  |  | j¡ | ¡ }| j}| j |¡ | j |¡ | j| j \}}| j	d k	rt| j	 |¡ | j	 
¡ }d|d |f }nd}ddlm} t| j|jƒrž| j |¡ t| j|jƒr¸| j |¡ | jjjrÈtjn| jj}|rê| jsê|j |d¡}	n
| j 
¡ }	|jrF|jsF| jd dkrF| d|	| j 
¡ |||	| j| j 
¡ ||	|f
 ¡ n,| d	|	| j 
¡ ||	| j| j 
¡ |	|f ¡ | j}
|
d krš|rš| | jj||	¡}
|
d k	r¼|
 |¡ | j |
|¡ | j  !|¡ | "|j#¡ |sô| jrô| jj$j%rž| &| jjd ¡}| |¡ | '| jj$j(¡}| jj$j)j*r@|j+ ,t- .d
d¡¡ d}n&|j+ ,t- .dd¡¡ d /| jj$j)j0¡}| || 
¡ || 1| 
¡ | jj¡f ¡ | 2| 
¡ ¡ n| j}| 3| jj|| jj$j)¡}|	|_4| 5|¡ | jj$j%rô| 6| 
¡ |j¡ | 7|¡ | d¡ |s(| jr(| j |¡ | j | j|¡ |rB| jsB|j 8|	¡ |j9}| :|¡ | j;rz| d¡ | j; !|¡ | d¡ | "|¡ | j <|¡ | j =|¡ | j <|¡ | j =|¡ t| j|jƒrÐ| j 7|¡ t| j|jƒrì| j 7|¡ | j	d k	r| j	 <|¡ | j	 =|¡ d S )Nz%s=%sr   Ú1r   )rï   Fú>z-for (%s = %s%s + %s; %s %s %s + %s; ) { %s%s;z!for (%s = %s%s; %s %s %s; %s%s) {ZGetModuleGlobalNamezObjectHandling.cz%__Pyx_GetModuleGlobalName(%s, %s); %sZGetNameInClassz$__Pyx_GetNameInClass(%s, {}, %s); %sr¾  z
/*else*/ {)>rÊ   r%   r•  Ú
from_ranger¹  rA  rº  Úrelation_tableZ	relation1r»  r‹   r§   rï   rH   rÀ  r¤  r¨  rÁ  rI  r/   r½  r
   r;   r¿  rœ  r  ró   rU  Z	relation2rN   rè  rK  r   rÀ   rû  rm  rÃ   Zis_pyglobalZ
PyTempNoder³  r9   r)  r  r¾   rc  r   rÉ  Úformatr  rŸ  r   ZCoerceFromPyTypeNodeZ	temp_codeÚgenerate_result_coder  rª  r£  rk  r–  r‚  r  rH  )r|   rT   r—  rÄ  ÚoffsetZincopr»  rï   Zloopvar_typeZloopvar_nameZcoerced_loopvar_nodeZtarget_nodeZinterned_cnameZlookup_funcZfrom_py_noderk  r&   r&   r'   rÀ   Ê  s²    



 










z'ForFromStatNode.generate_execution_code)r§   z++)z+1z++)r§   z--)z-1z--)z<=rµ  z>=rÃ  c             C   sl   | j  ||¡ | j ||¡ | j ||¡ | jd k	rB| j ||¡ | j ||¡ | jd k	rh| j ||¡ d S )N)rI  r¿   r¹  rº  r»  r   r‚  )r|   r@   rT   r&   r&   r'   r¿   C  s    

z-ForFromStatNode.generate_function_definitionsc             C   sX   | j  |¡ | j |¡ | j |¡ | jr6| j |¡ | j |¡ | jrT| j |¡ d S )N)rI  r‘   r¹  rº  r»  r   r‚  )r|   rT   r&   r&   r'   r‘   M  s    zForFromStatNode.annotate)rJ   rj   rk   r‡   r¿  rÀ  rÁ  rÄ  r   r¹   r   ro   r¼  rÀ   rÅ  r¿   r‘   r&   r&   r&   r'   r³  i  s"   &s
r³  c               @   sD   e Zd ZdZddddgZdZdZdd„ Zd	d
„ Zdd„ Z	dd„ Z
dS )ÚWithStatNodea  
    Represents a Python with statement.

    Implemented by the WithTransform as follows:

        MGR = EXPR
        EXIT = MGR.__exit__
        VALUE = MGR.__enter__()
        EXC = True
        try:
            try:
                TARGET = VALUE  # optional
                BODY
            except:
                EXC = False
                if not EXIT(*EXCINFO):
                    raise
        finally:
            if EXC:
                EXIT(None, None, None)
            MGR = EXIT = VALUE = None
    ÚmanagerÚ
enter_callrI  r   Nc             C   s(   | j  |¡ | j |¡ | j |¡ d S )N)rÊ  r   rË  r   )r|   r@   r&   r&   r'   r   z  s    z!WithStatNode.analyse_declarationsc             C   sT   | j  |¡| _ | j |¡| _| jrBddlm} || jj| jjƒ| _| j	 
|¡| _	| S )Nr   )r¤  )rÊ  rn   rË  rI  rï   r¤  r%   r/   Útarget_tempr   ro   )r|   r@   r¤  r&   r&   r'   ro     s    z WithStatNode.analyse_expressionsc             C   s.   | j  ||¡ | j ||¡ | j ||¡ d S )N)rÊ  r¿   rË  r   )r|   r@   rT   r&   r&   r'   r¿   ‰  s    z*WithStatNode.generate_function_definitionsc          
   C   sž  |  | j¡ | d¡ | j |¡ |jjtdd| _|j	 
t dd¡¡ | d| j| j ¡ | t| jrjdndƒ¡| | j| j¡f ¡ | | j¡ | ¡ }|j}| j |¡ | jrö| j |¡ | j |¡ | d	| j ¡ | j ¡ f ¡ | j |¡ n| j |¡ | j |¡ | j |¡ | j |¡ ||_| j |¡ |  |¡r‚| !¡ }| "|¡ | #|¡ | $| jt¡ | "|¡ | #|¡ |j %| j¡ | d
¡ d S )Nz/*with:*/ {F)r›  ZPyObjectLookupSpecialzObjectHandling.cz-%s = __Pyx_PyObject_LookupSpecial(%s, %s); %sÚ	__aexit__Ú__exit__z%s = %s;r¾  )&rÊ   r%   rN   rÊ  rA  rœ  r  r   Zexit_varr¾   rc  r   rÉ  rd  r³  r   r°  rŸ  r   r¢  r÷  rË  rI  rÌ  r¨  rD  r‹   rG  r  rH  r   rÀ   r¥  rË  rù  rû  r¢  r£  )r|   rT   r©  Zintermediate_error_labelZstep_over_labelr&   r&   r'   rÀ   Ž  sF    




z$WithStatNode.generate_execution_code)rJ   rj   rk   rv   r‡   rË  rÌ  r   ro   r¿   rÀ   r&   r&   r&   r'   rÉ  X  s   
rÉ  c               @   s<   e Zd ZddgZdZdZdd„ Zdd„ Zdd	„ Zd
d„ Z	dS )ÚWithTargetAssignmentStatNoder.  r  Nc             C   s   | j  |¡ d S )N)r  rÿ  )r|   r@   r&   r&   r'   r   Í  s    z1WithTargetAssignmentStatNode.analyse_declarationsc             C   s4   | j  |¡| _ | j  |¡ | jj | j j|¡| _| S )N)r  rp   r;  Ú	with_noderÌ  r  r/   r.  )r|   r@   r&   r&   r'   ro   Ð  s    z0WithTargetAssignmentStatNode.analyse_expressionsc             C   s.   | j  |¡ | j | j |¡ | jj |¡ d S )N)r.  rA  r  rK  rÐ  rÌ  rª  )r|   rT   r&   r&   r'   rÀ   Ö  s    z4WithTargetAssignmentStatNode.generate_execution_codec             C   s   | j  |¡ | j |¡ d S )N)r  r‘   r.  )r|   rT   r&   r&   r'   r‘   Û  s    z%WithTargetAssignmentStatNode.annotate)
rJ   rj   rk   r‡   rÐ  r.  r   ro   rÀ   r‘   r&   r&   r&   r'   rÏ  ¿  s   
rÏ  c               @   sL   e Zd ZdddgZdZdd„ Zdd„ ZejZ	d	Z
d
d„ Zdd„ Zdd„ ZdS )ÚTryExceptStatNoder   Úexcept_clausesr‚  Fc             C   s<   | j  |¡ x| jD ]}| |¡ qW | jr8| j |¡ d S )N)r   r   rÒ  r‚  )r|   r@   Úexcept_clauser&   r&   r'   r   ê  s
    z&TryExceptStatNode.analyse_declarationsc             C   sv   | j  |¡| _ d}xDt| jƒD ]6\}}| |¡ }| j|< |rJt|jdƒ |jsd}qW || _| jrr| j |¡| _| S )Nr   zdefault 'except:' must be lastr   )	r   ro   r  rÒ  r   r%   ÚpatternÚhas_default_clauser‚  )r|   r@   Zdefault_clause_seenr"  rÓ  r&   r&   r'   ro   ñ  s    z%TryExceptStatNode.analyse_expressionszTry-except statementc                s¼  ˆ   | j¡ ˆ  d¡ ˆ j}ˆ j}ˆ j}ˆ  ¡ }ˆ j}ˆ  d¡}ˆ  d¡}ˆ  d¡}	ˆ  d¡}
|rlˆ  d¡nd }|r~ˆ  d¡nd }ˆ  d¡}‡ fd	d
„t	dƒD ƒ‰ˆ  
¡ }ˆ  d¡ |
ˆ _|ˆ _|ˆ _| j ˆ ¡ ˆ j | jdd ˆ  d¡ ˆ j ¡ }ˆ  |¡}|rvˆ j t¡ | js.| d¡ | d¡ | dd dd
„ ˆD ƒ¡ ¡ xˆD ]}| |¡ qRW ‡ ‡fdd„}n*dd
„ ˆD ƒ}| dd |¡ ¡ dd„ }|ˆ _|	ˆ _| jj}| jrøˆ   | jj¡ ˆ  d¡ | j ˆ ¡ ˆ  d¡ |sø| jj}|rœ|s*xˆD ]}ˆ  |t¡ q
W ˆ  |¡ ˆ  |¡ x|D ]\}}ˆ  ||¡ q:W ˆ jj}| ˆ j_x| jD ]}| ˆ |¡ qlW |ˆ j_| jsœˆ  |¡ xˆ||f||f||f|
|f|	|fgD ]b\}}ˆ  |¡rÀ|sðˆ  |¡sðˆ  |¡ ˆ  |¡ ˆ j | jdd |r|ƒ  ˆ  |¡ qÀW ˆ  |¡rd|sNˆ  |¡sNˆ  |¡ ˆ  |¡ |rd|ƒ  ˆ  |¡rzˆ  |¡ ˆ  d¡ xˆD ]}ˆ j  |¡ qŠW |ˆ _|ˆ _|ˆ _|ˆ _d S )NrÃ  Zexception_handledZexcept_errorZexcept_returnZ
try_returnZ	try_breakZtry_continueZtry_endc                s   g | ]}ˆ j  td ¡‘qS )F)rœ  r  r   )r„   rr  )rT   r&   r'   r†     s   z=TryExceptStatNode.generate_execution_code.<locals>.<listcomp>r$   z
/*try:*/ {F)rÀ  r¾  rÁ  rÂ  z__Pyx_ExceptionSave(%s);z, c             S   s   g | ]}d | ‘qS )z&%sr&   )r„   r)  r&   r&   r'   r†   )  s    c                 s0   xˆD ]} ˆ   | ¡ qW ˆ  dd ˆ¡ ¡ d S )Nz__Pyx_ExceptionReset(%s);z, )r	  rN   r   )r9   )rT   Úexc_save_varsr&   r'   Úrestore_saved_exception-  s    
zJTryExceptStatNode.generate_execution_code.<locals>.restore_saved_exceptionc             S   s   g | ]}d | ‘qS )z	(void)%s;r&   )r„   r)  r&   r&   r'   r†   5  s    z%s /* mark used */rE   c               S   s   d S )Nr&   r&   r&   r&   r'   r×  8  s    z/*else:*/ {)!rÊ   r%   rN   rú  rk  rm  r¢  r÷  rË  rY  rÙ  r   rÀ   rœ  Úall_free_managed_tempsr¥  r¾   rc  Úreset_exception_utility_codero  r   Úput_xgotrefrµ   r‚  r°  r   rù  rû  Zcurrent_exceptrÒ  Úgenerate_handling_coderÕ  r£  )r|   rT   Úold_return_labelÚold_break_labelÚold_continue_labelr©  rª  Zexcept_end_labelZexcept_error_labelZexcept_return_labelZtry_return_labelZtry_break_labelZtry_continue_labelZtry_end_labelZsave_excÚtemps_to_clean_upZ	can_raiser)  r×  Zmark_vars_usedZnormal_case_terminatesÚ	temp_nameÚ	temp_typeZouter_exceptrÓ  Z
exit_labelÚ	old_labelr  r&   )rT   rÖ  r'   rÀ     sÀ    






















z)TryExceptStatNode.generate_execution_codec             C   sF   | j  ||¡ x| jD ]}| ||¡ qW | jd k	rB| j ||¡ d S )N)r   r¿   rÒ  r‚  )r|   r@   rT   rÓ  r&   r&   r'   r¿   {  s
    
z/TryExceptStatNode.generate_function_definitionsc             C   s<   | j  |¡ x| jD ]}| |¡ qW | jr8| j |¡ d S )N)r   r‘   rÒ  r‚  )r|   rT   Zexcept_noder&   r&   r'   r‘   ‚  s
    zTryExceptStatNode.annotateN)rJ   rj   rk   r‡   ro  r   ro   ry   r€   r¹   r   rÀ   r¿   r‘   r&   r&   r&   r'   rÑ  à  s   
yrÑ  c               @   sL   e Zd Zdd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S )ÚExceptClauseNoderÔ  rI  r   ru  NFc             C   s"   | j r| j  |¡ | j |¡ d S )N)rI  rÿ  r   r   )r|   r@   r&   r&   r'   r   ¡  s    z%ExceptClauseNode.analyse_declarationsc             C   s„   |j | _| jr@x0t| jƒD ]"\}}| |¡}| |¡| j|< qW | jrrddlm} | 	| j
¡| _| j || j¡| _| j |¡| _| S )Nr   )rï   )r  Úfunction_namerÔ  r  ro   r`  rI  r§   rï   ZExcValueNoder%   ru  r  r   )r|   r@   r"  rÔ  rï   r&   r&   r'   ro   ¦  s    
z$ExceptClauseNode.analyse_expressionsc                sà  ˆ   | j¡ | jr’tdd„ | jD ƒƒ }|rŒ‡ fdd„tdƒD ƒ}ˆ j t dd¡¡ ˆ  	dt
|ƒ ¡ ˆ j t d	d
¡¡ d|d  }nd}ˆ j t dd¡¡ d}g }x*| jD ] }| ˆ ¡ | || ¡  ¡ q´W ˆ jjtjdd}ˆ  	d|d |¡f ¡ x$| jD ]}| ˆ ¡ | ˆ ¡ q
W |rvˆ  	dt
|ƒ ¡ ˆ  	d dd„ |D ƒ¡¡ x|D ]}	ˆ j |	¡ q`W ˆ  	d| ¡ ˆ j |¡ n
ˆ  	d¡ t| jddƒsú| jd krú| jd krúˆ j t dd¡¡ ˆ  	d¡ ˆ  |¡ ˆ  	d¡ d S ‡ fdd„tdƒD ƒ}ˆ  | j¡ ˆ j t¡ dt
|ƒ }
ˆ  	d|
ˆ  | j¡f ¡ x|D ]}ˆ  |¡ qTW | jrœ| j  !|d  ¡ | j  ˆ ¡ | j "| j ˆ ¡ | jd k	rÐx&t#|| jj$ƒD ]\}}| !|¡ q¸W ˆ j%ˆ j& }}ˆ  'd!¡ˆ _%ˆ  'd"¡ˆ _&ˆ jj(}|ˆ j_(| j )ˆ ¡ |ˆ j_(| jj*sJx|D ]}ˆ  +|t,¡ q*W ˆ  |¡ x^ˆ j%|fˆ j&|fgD ]F\}}ˆ  -|¡r`ˆ  .|¡ x|D ]}ˆ  /|t,¡ q„W ˆ  |¡ q`W |ˆ _%|ˆ _&x|D ]}	ˆ j |	¡ q¼W ˆ  	d¡ d S )#Nc             s   s$   | ]}|j p| ¡ o|j V  qd S )N)r´   Ú	is_simpler+  )r„   rÔ  r&   r&   r'   rÏ   »  s   z:ExceptClauseNode.generate_handling_code.<locals>.<genexpr>c                s   g | ]}ˆ j jtd d‘qS )T)r›  )rœ  r  r   )r„   rr  )rT   r&   r'   r†   À  s   z;ExceptClauseNode.generate_handling_code.<locals>.<listcomp>r$   ÚPyErrFetchRestorezExceptions.cz__Pyx_ErrFetch(&%s, &%s, &%s);ZFastTypeCheckszModuleSetupCode.cz*__Pyx_PyErr_GivenExceptionMatches(%s, %%s)r   r&   ZPyErrExceptionMatchesz __Pyx_PyErr_ExceptionMatches(%s)F)r›  z%s = %s;z || z__Pyx_ErrRestore(%s, %s, %s);rE   c             S   s   g | ]}d | ‘qS )z%s = 0;r&   )r„   r)  r&   r&   r'   r†   Ø  s    z	if (%s) {z/*except:*/ {rÇ   Tz__Pyx_ErrRestore(0,0,0);r¾  c                s   g | ]}ˆ j jtd d‘qS )T)r›  )rœ  r  r   )r„   rr  )rT   r&   r'   r†   î  s   z&%s, &%s, &%sz"if (__Pyx_GetException(%s) < 0) %sr   Zexcept_breakZexcept_continue)0rÊ   r%   rÔ  rÑ   rY  r¾   rc  r   rÉ  rN   r¸  rA  rþ   rd  rœ  r  r
   r<   r   r  rH  r£  rˆ   r   Úexcinfo_targetrI  rù  r  rä  Úget_exception_utility_coder¡  r   ru  Zset_varrK  r5  rQ   rk  rm  rË  r~  rÀ   rµ   r°  r   r¥  rû  r¢  )r|   rT   r«  Zhas_non_literalsr~  Zexc_test_funcZ	exc_testsrÔ  Z
match_flagr¤  Zexc_argsr)  ZtempvarrS   rÝ  rÞ  Úold_exc_varsrË  râ  r&   )rT   r'   rÛ  ¶  s¤    
















z'ExceptClauseNode.generate_handling_codec             C   s*   | j d k	r| j  ||¡ | j ||¡ d S )N)rI  r¿   r   )r|   r@   rT   r&   r&   r'   r¿   "  s    
z.ExceptClauseNode.generate_function_definitionsc             C   sB   | j r x| j D ]}| |¡ qW | jr2| j |¡ | j |¡ d S )N)rÔ  r‘   rI  r   )r|   rT   rÔ  r&   r&   r'   r‘   '  s    zExceptClauseNode.annotate)rJ   rj   rk   r‡   ru  rç  Zis_except_asr   ro   rÛ  r¿   r‘   r&   r&   r&   r'   rã  Š  s   lrã  c               @   sˆ   e Zd ZdddgZdZdZdZdZdZdZ	e
dd	„ ƒZd
d„ Zdd„ ZejZdZdd„ Zdd„ Zddd„Zddd„Zdd„ Zdd„ ZdS )ÚTryFinallyStatNoder   Úfinally_clauseÚfinally_except_clauser   TNFc             C   s   t | ||d}|S )N)r   rë  )rê  )r%   r@   r   rë  rS   r&   r&   r'   rÈ   J  s    z"TryFinallyStatNode.create_analysedc             C   s6   | j  |¡ t | j¡| _| j |¡ | j |¡ d S )N)r   r   r   Údeepcopyrë  rì  )r|   r@   r&   r&   r'   r   O  s    z'TryFinallyStatNode.analyse_declarationsc             C   sD   | j  |¡| _ | j |¡| _| j |¡| _|jr@|jjs@|j| _| S )N)r   ro   rë  rì  r  rÛ   Úfunc_return_type)r|   r@   r&   r&   r'   ro   U  s    z&TryFinallyStatNode.analyse_expressionszTry-finally statementc                s€  ˆ   ˆj¡ ˆ  d¡ ˆ j}ˆ  ¡ }ˆ  ¡ }ˆ j}ˆjs>|ˆ _ˆ  ¡ }ˆ jj	}dˆ j_	ˆj
 ˆ ¡ |ˆ j_	ˆ  d¡ ˆ  |¡ ˆ j ¡ }ˆ   ˆjj¡ ˆ  d¡ ˆjgf‡fdd„	}	ˆjoÂˆ  |¡}
ˆjj }ˆj
jsˆ  d¡ |	ƒ  ˆ ¡ ˆjjsˆ  |¡ ˆ  d¡ |
rÌˆ  |¡ ˆ  d¡ ˆjs8ˆ  d	¡ ˆjrHˆ  ¡  |rˆt‡ fd
d„tdƒD ƒƒ}ˆ jjt t tj¡¡dd}nd  }}t‡ fdd„tdƒD ƒƒ}ˆ ˆ ||||¡ ˆ  ¡ }ˆ  d¡ ˆ jj}|d d… ˆ j_ˆj  ˆ ¡ |ˆ j_ˆ  d¡ |rXˆ !ˆ |||¡ |r<x|D ]}ˆ j "|¡ q&W |rNˆ j "|¡ ˆ  |¡ xLt#ˆ  ¡ |ƒD ]:\}}ˆ  |¡s€qhˆ  |¡ ˆ $ˆ |¡ ˆ  |¡ qhW x|D ]}ˆ j "|¡ q¬W ˆ  d¡ ˆ  |¡ ˆ j%}d}x„t&t#||ƒƒD ]p\}\}}ˆ  |¡sqò||kr$|
r$qòˆ  d| ¡ d }||krØˆjrpt‡ fdd„tdƒD ƒƒ}ˆ ˆ g |¡ ˆjjsØˆj'rØˆjsØt(ˆjt)ƒsØˆ jjˆj'dd}ˆ  d|t*j+f ¡ ˆj'j,rØˆ  dt*j+ ¡ |	ƒ  ˆ ¡ ||krD|r0ˆ  dt*j+|f ¡ ˆj'j,r ˆ  d| ¡ ˆ j "|¡ d }ˆjrDˆ !ˆ |¡ ˆjjsXˆ  |¡ ˆ  d¡ qòW ˆ  |¡ ˆ  d¡ d S )Nz
/*try:*/ {r   r¾  z/*finally:*/ {c                s.   | d }t  |¡}|ˆ jkr&|| d< n|}|S )Nr   )r   rí  rë  )Z_nextrS   Z	node_copy)r|   r&   r'   Úfresh_finally_clausey  s    


zHTryFinallyStatNode.generate_execution_code.<locals>.fresh_finally_clausez/*normal exit:*/{z/*exception exit:*/{rÁ  c                s   g | ]}ˆ j jtjd d‘qS )F)r›  )rœ  r  r
   r<   )r„   rr  )rT   r&   r'   r†   –  s   z>TryFinallyStatNode.generate_execution_code.<locals>.<listcomp>r"   F)r›  c                s   g | ]}ˆ j jtd d‘qS )F)r›  )rœ  r  r   )r„   rr  )rT   r&   r'   r†   ž  s   é   rÃ  r$   r&   z%s: {c                s   g | ]}ˆ j jtd d‘qS )F)r›  )rœ  r  r   )r„   rr  )rT   r&   r'   r†   Ï  s   z%s = %s;z%s = 0;)-rÊ   r%   rN   r÷  Zall_new_labelsÚget_all_labelsÚhandle_error_caserË  rœ  Zin_try_finallyr   rÀ   Úset_all_labelsrØ  rë  Úpreserve_exceptionr¥  rµ   rù  rû  ro  Úis_try_finally_in_nogilrÞ  r¸  rY  r  r
   ZCPtrTyper4  r  Úput_error_catcherr~  rì  Úput_error_uncatcherr£  r5  Úput_error_cleanerrú  r  rî  rH   ÚGILExitNoder	   rØ  r:   )r|   rT   r©  Z
old_labelsZ
new_labelsr¢  Zcatch_labelZwas_in_try_finallyrß  rï  Zpreserve_errorZneeds_success_cleanupÚexc_lineno_cnamesÚexc_filename_cnamer~  Zfinally_old_labelsré  r  rË  râ  rú  r"  Zret_tempr&   )rT   r|   r'   rÀ   `  sà    

























 








z*TryFinallyStatNode.generate_execution_codec             C   s    | j  ||¡ | j ||¡ d S )N)r   r¿   rë  )r|   r@   rT   r&   r&   r'   r¿   ò  s    z0TryFinallyStatNode.generate_function_definitionsc       	   	   C   sþ   |j  t¡ |j  t¡ |j  t¡ | jr6|jdd | d¡ | d dd„ |D ƒ¡¡ x|D ]\}}| 	||¡ q`W | d|dd …  ¡ | d	|d d… d
  ¡ x|D ]}| 
|¡ q®W |rì| d|d tj|d tj|tjf ¡ | jrú| ¡  d S )NF)rÞ  rÂ  rE   c             S   s   g | ]}d | ‘qS )z%s = 0;r&   )r„   r)  r&   r&   r'   r†      s    z8TryFinallyStatNode.put_error_catcher.<locals>.<listcomp>z>if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&%s, &%s, &%s);r$   zmif ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&%s, &%s, &%s) < 0)) __Pyx_ErrFetch(&%s, &%s, &%s);r"   z%s = %s; %s = %s; %s = %s;r   r   )r¾   rc  rþ  rè  Úswap_exception_utility_coderõ  rÝ  rN   r   r°  rÚ  r	   Úlineno_cnameÚclineno_cnameÚfilename_cnamerõ  )	r|   rT   rß  r~  rú  rû  rà  r/   r)  r&   r&   r'   rö  ö  s,    



z$TryFinallyStatNode.put_error_catcherc          	   C   s  |j  t¡ |j  t¡ | jr*|jdd | d¡ x|dd … D ]}| |¡ qBW | d|dd …  ¡ | d¡ x|d d… D ]}| |¡ q‚W | d|d d…  ¡ | jr¸| ¡  | d 	d	d
„ |D ƒ¡¡ |rþ| dt
j|d t
j|d t
j|f ¡ d S )NF)rÞ  zif (PY_MAJOR_VERSION >= 3) {r$   z!__Pyx_ExceptionReset(%s, %s, %s);r¾  z__Pyx_ErrRestore(%s, %s, %s);rE   c             S   s   g | ]}d | ‘qS )z%s = 0;r&   )r„   r)  r&   r&   r'   r†   -  s    z:TryFinallyStatNode.put_error_uncatcher.<locals>.<listcomp>z%s = %s; %s = %s; %s = %s;r   r   )r¾   rc  rþ  rÙ  rõ  rÝ  rN   r	  rõ  r   r	   rý  rþ  rÿ  )r|   rT   r~  rú  rû  r)  r&   r&   r'   r÷    s(    



z&TryFinallyStatNode.put_error_uncatcherc             C   s¾   |j  t¡ | jr|jdd | d¡ x|dd … D ]}| |¡ q6W | d|dd …  ¡ | d¡ x |d d… D ]}| |t¡ qvW | jr˜| 	¡  | d 
dgd ¡|dd …  ¡ d S )	NF)rÞ  zif (PY_MAJOR_VERSION >= 3) {r$   z!__Pyx_ExceptionReset(%s, %s, %s);r¾  rE   z%s = 0;)r¾   rc  rÙ  rõ  rÝ  rN   r	  r°  r   rõ  r   )r|   rT   r~  r)  r&   r&   r'   rø  4  s    

z$TryFinallyStatNode.put_error_cleanerc             C   s   | j  |¡ | j |¡ d S )N)r   r‘   rë  )r|   rT   r&   r&   r'   r‘   F  s    zTryFinallyStatNode.annotate)NN)NN)rJ   rj   rk   r‡   rô  rò  rî  rì  rõ  ro  rË   rÈ   r   ro   ry   r€   r¹   r   rÀ   r¿   rö  r÷  rø  r‘   r&   r&   r&   r'   rê  0  s&   
 
!
rê  c               @   s   e Zd ZdZdZdZdS )ÚNogilTryFinallyStatNodezJ
    A try/finally statement that may be used in nogil code sections.
    FN)rJ   rj   rk   rv   rô  r¹   r&   r&   r&   r'   r   K  s   r   c                   s@   e Zd ZdZdd„ Zdd„ Z‡ fdd„Zdd	„ Zd
d„ Z‡  Z	S )ÚGILStatNodeNc          	   C   s6   || _ |  |||¡ tj| ||t||| jdd d S )N)ÚstateÚ
state_temp)r   rë  )r  Úcreate_state_temp_if_neededrê  r~   rù  r  )r|   r%   r  r   r&   r&   r'   r~   [  s    zGILStatNode.__init__c             C   sZ   ddl m} |ƒ }| |¡ |js&d S |dkr6tj}ntj}ddlm} | 	||¡| _
d S )Nr   )ÚYieldNodeCollectorÚgil)rï   )ZParseTreeTransformsr  ZvisitchildrenZyieldsr
   Zc_gilstate_typeZc_threadstate_ptr_typer§   rï   r¤  r  )r|   r%   r  r   r  Z	collectorrá  rï   r&   r&   r'   r  d  s    
z'GILStatNode.create_state_temp_if_neededc                s,   | j dk|_| j dkrd|_tt| ƒ |¡S )Nr  T)r  Z_in_with_gil_blockrÜ  rc   r  r   )r|   r@   )rI   r&   r'   r   r  s    
z GILStatNode.analyse_declarationsc             C   s:   |  t dd¡¡ |j}| jdk|_t | |¡}||_|S )NZForceInitThreadszModuleSetupCode.cr
  )rc  r   rÉ  r
  r  rê  ro   )r|   r@   Ú	was_nogilrS   r&   r&   r'   ro   y  s    zGILStatNode.analyse_expressionsc             C   s¤   |  | j¡ | ¡  | jr2| j |¡ | j ¡ }nd }|jj}| jdkr^|j	|d d|j_n|j
|d d|j_t | |¡ | jr| j |¡ ||j_| ¡  d S )Nr  )ÚvariableTF)rÊ   r%   Úbegin_blockr  r¨  r‹   rœ  rÍ  r  rÝ  Zput_release_gilrê  rÀ   rª  Ú	end_block)r|   rT   r  Zold_gil_configr&   r&   r'   rÀ   ‚  s"    

z#GILStatNode.generate_execution_code)
rJ   rj   rk   r  r~   r  r   ro   rÀ   rl   r&   r&   )rI   r'   r  T  s   		r  c               @   s(   e Zd ZdZg ZdZdd„ Zdd„ ZdS )rù  z]
    Used as the 'finally' block in a GILStatNode

    state   string   'gil' or 'nogil'
    Nc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   ¦  s    zGILExitNode.analyse_expressionsc             C   s:   | j r| j  ¡ }nd }| jdkr,| |¡ n
| |¡ d S )Nr  )r  r‹   r  rõ  Zput_acquire_gil)r|   rT   r  r&   r&   r'   rÀ   ©  s    
z#GILExitNode.generate_execution_code)rJ   rj   rk   rv   r‡   r  ro   rÀ   r&   r&   r&   r'   rù  œ  s
   rù  c               @   s   e Zd ZdZdd„ ZdS )ÚEnsureGILNodezI
    Ensure the GIL in nogil functions for cleanup before returning.
    c             C   s   |j dd d S )NF)rÞ  )rÝ  )r|   rT   r&   r&   r'   rÀ   º  s    z%EnsureGILNode.generate_execution_codeN)rJ   rj   rk   rv   rÀ   r&   r&   r&   r'   r  µ  s   r  c              C   s   ddl m}  | jS )Nr   )r`  )r§   r`  rd  )r`  r&   r&   r'   Úcython_view_utility_code¾  s    r  c               C   s   t  dd¡S )NÚArrayAPIzarrayarray.h)r   rÉ  r&   r&   r&   r'   r  Æ  s    r  c               C   s   t  dd¡S )Nr  zarrayarray.h)r   rÉ  r&   r&   r&   r'   r  Ç  s    )zcpython.arrayzcpython.array.arrayzcython.view)Z__Pyx_patch_asyncioZPatchAsyncIOzCoroutine.c)Z__Pyx_patch_inspectZPatchInspectzCoroutine.c)ZasyncioÚinspectc               @   s,   e Zd Zg ZdZdd„ Zdd„ Zdd„ ZdS )	ÚCImportStatNodeFc             C   s  |j st| jdƒ d S |j| j| j| jr,dndd}d| jkrÖdd„ | j d¡D ƒ}|d }|j |¡}|}x2|dd … D ]"}| |¡}| 	||| j¡ |}qzW | j
rº| 	| j
|| j¡ qò| |¡ | 	||| j¡ n| j
pà| j}| 	||| j¡ | jtkr| t| j ƒ ¡ d S )	Nz$cimport only allowed at module levelr   rª   )Úrelative_levelr  c             S   s   g | ]}t |ƒ‘qS r&   )r   )r„   r9   r&   r&   r'   r†   ä  s    z8CImportStatNode.analyse_declarations.<locals>.<listcomp>r   )r  r   r%   Úfind_modulerÑ  Úis_absoluter  rä  Zfind_submoduleÚdeclare_moduleÚas_namer  Úutility_code_for_cimportsrc  )r|   r@   Úmodule_scoper"  Ztop_nameZtop_module_scoper9   Úsubmodule_scoper&   r&   r'   r   Ý  s,    


z$CImportStatNode.analyse_declarationsc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   ÷  s    z#CImportStatNode.analyse_expressionsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÀ   ú  s    z'CImportStatNode.generate_execution_codeN)rJ   rj   rk   r‡   r  r   ro   rÀ   r&   r&   r&   r'   r  Ó  s
   r  c               @   s<   e Zd Zg ZdZdZdZdd„ Zdd„ Zdd„ Z	dd	„ Z
dS )
ÚFromCImportStatNodeNc             C   s  |j st| jdƒ d S | jr>| j|j d¡kr>t| jdƒ d S |j| j| j| jd}|j}| |¡ x(| j	D ]\}}}}|dkr°x(t
|j ¡ ƒD ]\}}	| ||	|¡ q”W qn| |¡}	|	rà|rØ|  |	|¡sØ|	 |¡ d|	_n|dksò|dkr|j||d d	|d
}	nh|dkr$|j|||d}	nL|jj||| jdd}
|
j|kr^| |pR||
| j¡ nt|d||f ƒ |	rn|p||}| ||	|¡ qnW | d¡s¨| d¡r|tkrÂ| t| ƒ ¡ x>| j	D ]4\}}}}d||f }|tkrÊ| t| ƒ ¡ qÊW d S )Nz$cimport only allowed at module levelr  z3relative cimport beyond main package is not allowed)r  r  r   r'  r2  r   )r(  r)  r*  r%   Úclass)r%   rÑ  F)Zrelative_tor%   Zabsolute_fallbackz%Name '%s' not declared in module '%s'ZcpythonÚcythonz%s.%s)r  r   r%   r  r  Úcountr  rÑ  r  Úimported_namesr‰   rÂ   rb   r  rW  Údeclaration_matchesZ
redeclaredr0  r.  r  rä  Úparent_moduler  r  r  rc  )r|   r@   r  rÑ  r%   r9   r  r(  Z
local_namerÃ   r  rr  Zfqnamer&   r&   r'   r   
  sL    






z(FromCImportStatNode.analyse_declarationsc             C   s@   |j s
dS |j}|dkr$|js<dS n|js.dS ||jkr<dS dS )Nr   r  r   )rg  r/   rv  Zis_struct_or_unionr(  )r|   rÃ   r(  r/   r&   r&   r'   r  8  s    
z'FromCImportStatNode.declaration_matchesc             C   s   | S )Nr&   )r|   r@   r&   r&   r'   ro   F  s    z'FromCImportStatNode.analyse_expressionsc             C   s   d S )Nr&   )r|   rT   r&   r&   r'   rÀ   I  s    z+FromCImportStatNode.generate_execution_code)rJ   rj   rk   r‡   rÑ  r  r  r   r  ro   rÀ   r&   r&   r&   r'   r  þ  s   .r  c               @   s.   e Zd ZdgZdZdd„ Zdd„ Zdd„ Zd	S )
ÚFromImportStatNoder  r   c             C   sN   xH| j D ]>\}}|dkr<|js.t| jdƒ d S d|_d| _q| |¡ qW d S )Nr  z%import * only allowed at module levelr   )rb   r  r   r%   Zhas_import_starÚimport_starrÿ  )r|   r@   r9   rI  r&   r&   r'   r   Y  s    z'FromImportStatNode.analyse_declarationsc       	   	   C   s\  ddl m} | j |¡| _| | jt¡| _g | _x$| j	D ]\}}|dkrˆx8|j
 	¡ D ]*\}}|jsX|jjrX| t dd¡¡ P qXW q:| |j¡}|jr|jj|krt|jdƒr|jj| jjjkrÌq:y0|j| jjj| j| jjd}|jj|jkrúw:W n tk
r   Y nX | |d ¡}|jtkr2d }n| j |j|¡}| j |||f¡ q:W | S )Nr   )rï   r  ZExtTypeTestzObjectHandling.crÑ  )r%   r  )r§   rï   r  ro   rè  r%   r   r™   Úinterned_itemsrb   rÂ   rg  r/   rv  rc  r   rÉ  rW  r9   r<  rÑ  r6   r  r›   r  r’   r  r  rþ   )	r|   r@   rï   r9   rI  rr  rÃ   r  Úcoerced_itemr&   r&   r'   ro   d  s8    z&FromImportStatNode.analyse_expressionsc             C   s0  |  | j¡ | j |¡ | jrB| dtj| j ¡ | | j¡f ¡ |j	j
tdd}| j |¡ | jrx|j t dd¡¡ xŽ| jD ]„\}}}| d|| j ¡ | |¡| || j¡f ¡ | |¡ |d krØ| | j|¡ n | |¡ | |¡ | ||¡ | |t¡ q€W |j	 |¡ | j |¡ | j |¡ d S )Nzif (%s(%s) < 0) %s;T)r›  Z
ImportFromzImportExport.cz!%s = __Pyx_ImportFrom(%s, %s); %s)rÊ   r%   r  rA  r   rN   r	   rd  r¡  rœ  r  r   r™   rí  r!  r¾   rc  r   rÉ  r³  rŸ  r   rK  Zallocate_temp_resultrÇ  r¢  r£  r  rH  )r|   rT   Z	item_tempr9   rI  r"  r&   r&   r'   rÀ   ‡  s<    


z*FromImportStatNode.generate_execution_codeN)rJ   rj   rk   r‡   r   r   ro   rÀ   r&   r&   r&   r'   r  M  s
   	#r  c               @   s   e Zd ZdZdZdS )ÚParallelNodez4
    Base class for cython.parallel constructs.
    N)rJ   rj   rk   rv   r¹   r&   r&   r&   r'   r#  ©  s   r#  c                   sH  e Zd ZdZddgZdZdZdZdZdZ	dZ
ejejejfZejejejfZejejejfZdZ‡ f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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,d0d1„ Z-d>d2d3„Z.d4Z/d5Z0d6e/e0f Z1d7d8„ Z2d9d:„ Z3‡  Z4S )?ÚParallelStatNodea  
    Base class for 'with cython.parallel.parallel():' and 'for i in prange():'.

    assignments     { Entry(var) : (var.pos, inplace_operator_or_None) }
                    assignments to variables in this parallel section

    parent          parent ParallelStatNode or None
    is_parallel     indicates whether this node is OpenMP parallel
                    (true for #pragma omp parallel for and
                              #pragma omp parallel)

    is_parallel is true for:

        #pragma omp parallel
        #pragma omp parallel for

    sections, but NOT for

        #pragma omp for

    We need this to determine the sharing attributes.

    privatization_insertion_point   a code insertion point used to make temps
                                    private (esp. the "nsteps" temp)

    args         tuple          the arguments passed to the parallel construct
    kwargs       DictNode       the keyword arguments passed to the parallel
                                construct (replaced by its compile time value)
    r   Únum_threadsNFr   c                s<   t t| ƒj|f|Ž | d¡p i | _tƒ | _i | _g | _d S )NrM  )	rc   r$  r~   r(  rM  rw   Úseen_closure_varsÚprivatesÚassigned_nodes)r|   r%   rr   )rI   r&   r'   r~   ð  s
    zParallelStatNode.__init__c          
   C   sJ  | j  |¡ d | _| jrüg }tƒ }xŠ| jjD ]~}|jj|krPt| j	d|jj ƒ | 
|jj¡ |jjdkr||jjsª|j| _q,| jr |jjdkr |jjsª|j| _q,| |¡ q,W || j_y| j |¡| _W n0 tk
rø } zt| jj	dƒ W d d }~X Y nX ni | _xB| j ¡ D ]4\}}|| jkr4t| j	d| ƒ nt| ||ƒ qW d S )Nz$Duplicate keyword argument found: %sr%  Ú	chunksizez=Only compile-time values may be supplied as keyword argumentszInvalid keyword argument: %s)r   r   r%  rr   rw   r5   r¢   r6   r   r%   r¤   r³   Ú	is_pranger)  rþ   r3  Ú	Exceptionrb   Úvalid_keyword_argumentsrŠ   )r|   r@   ZpairsÚseenZdictitemrb  r}   r  r&   r&   r'   r      s4    

"z%ParallelStatNode.analyse_declarationsc             C   sì   | j r| j  |¡| _ | jr(| j |¡| _| j |¡| _|  |¡ | j d k	rè| jrr| jj d k	rr| jjsrt| jdƒ nJ| jrŽ| jjsŽt| jdƒ n.| j j	j
r¼| j jr¼| j  |¡dkr¼t| jdƒ | j  ¡ rÐ| j j	jrè| j  tj|¡ |¡| _ | S )Nz-num_threads already declared in outer sectionz;num_threads must be declared in the parent parallel sectionr   z.argument to num_threads must be greater than 0)r%  ro   r)  r   Úanalyse_sharing_attributesÚparentr*  r   r%   r/   ró   r´   r3  rå  r:   r  r
   r<   r?  )r|   r@   r&   r&   r'   ro   '   s&    


z$ParallelStatNode.analyse_expressionsc             C   sn   xh| j  ¡ D ]Z\}\}}| jr<| js<|| jj kr<t|dƒ q| jsR|rRt|dƒ qd}|  ||||¡ qW dS )z·
        Analyse the privates for this block and set them in self.privates.
        This should be called in a post-order fashion during the
        analyse_expressions phase
        z0Cannot assign to private of outer parallel blockz*Reductions not allowed for parallel blocksTN)rM  rb   r*  Úis_parallelr/  r   Úpropagate_var_privatization)r|   r@   rÃ   r%   rB  Úlastprivater&   r&   r'   r.  @   s    


z+ParallelStatNode.analyse_sharing_attributesc             C   sl   ||f| j |< |jjr$t|dƒ dS | jrh| jsF|| jjkrF| jj}n| j}|rh|sX|rh| ||||¡ dS )a
  
        Propagate the sharing attributes of a variable. If the privatization is
        determined by a parent scope, done propagate further.

        If we are a prange, we propagate our sharing attributes outwards to
        other pranges. If we are a prange in parallel block and the parallel
        block does not determine the variable private, we propagate to the
        parent of the parent. Recursion stops at parallel blocks, as they have
        no concept of lastprivate or reduction.

        So the following cases propagate:

            sum is a reduction for all loops:

                for i in prange(n):
                    for j in prange(n):
                        for k in prange(n):
                            sum += i * j * k

            sum is a reduction for both loops, local_var is private to the
            parallel with block:

                for i in prange(n):
                    with parallel:
                        local_var = ... # private to the parallel
                        for j in prange(n):
                            sum += i * j

        Nested with parallel blocks are disallowed, because they wouldn't
        allow you to propagate lastprivates or reductions:

            #pragma omp parallel for lastprivate(i)
            for i in prange(n):

                sum = 0

                #pragma omp parallel private(j, sum)
                with parallel:

                    #pragma omp parallel
                    with parallel:

                        #pragma omp for lastprivate(j) reduction(+:sum)
                        for j in prange(n):
                            sum += i

                    # sum and j are well-defined here

                # sum and j are undefined here

            # sum and j are undefined here
        z9Memoryview slices can only be shared in parallel sectionsN)	r'  r/   r€  r   r*  r0  r/  rM  r1  )r|   rÃ   r%   rB  r2  r/  r&   r&   r'   r1  Z   s    5

z,ParallelStatNode.propagate_var_privatizationc             C   s€   | j r| j  ||¡S |j| jkr&|jS |j |jd¡}| j |j¡ | j |¡ | j 	||jf¡ | 
d||jf ¡ ||_dS )zo
        Helper function that allocate a temporary for a closure variable that
        is assigned to.
        Tz%s = %s;N)r/  Ú_allocate_closure_tempr  r&  rœ  r  r/   r¤   Úmodified_entriesrþ   rN   )r|   rT   rÃ   r  r&   r&   r'   r3  ¡   s    z'ParallelStatNode._allocate_closure_tempc             C   st   d}xjt | j ¡ ƒD ]X\}\}}|s|r0||kr|j ¡ }|r|rP| d¡ d}| d|j|j |¡f ¡ qW d S )NTz4/* Initialize private variables to invalid values */Fz%s = %s;)Úsortedr'  rb   r/   Úinvalid_valuerN   r  rB  )r|   rT   ÚexcluderK  rÃ   rB  r2  r6  r&   r&   r'   Úinitialize_privates_to_nan·   s    


z+ParallelStatNode.initialize_privates_to_nanc             C   s0   | j }|jj}||j_| |¡ ||j_| ¡ S )N)Ú1begin_of_parallel_control_block_point_after_declsrœ  ÚownerrA  r‹   )r|   rT   rç  r–   r:  r&   r&   r'   Úevaluate_before_blockÆ   s    
z&ParallelStatNode.evaluate_before_blockc             C   s&   | j dk	r"| d|  || j ¡ ¡ dS )zS
        Write self.num_threads if set as the num_threads OpenMP directive
        Nz num_threads(%s))r%  rÒ  r;  )r|   rT   r&   r&   r'   Úput_num_threadsÒ   s    
z ParallelStatNode.put_num_threadsc             C   s6   g | _ x*t| jƒD ]}|js"|jr|  ||¡ qW dS )a  
        If a variable is in a scope object, we need to allocate a temp and
        assign the value from the temp to the variable in the scope object
        after the parallel section. This kind of copying should be done only
        in the outermost parallel section.
        N)r4  r5  rM  Zfrom_closurerÖ  r3  )r|   rT   rÃ   r&   r&   r'   Údeclare_closure_privatesÚ   s    z)ParallelStatNode.declare_closure_privatesc             C   s@   x:| j D ]0\}}| d||jf ¡ |j |j¡ ||_qW dS )zÁ
        Release any temps used for variables in scope objects. As this is the
        outermost parallel block, we don't need to delete the cnames from
        self.seen_closure_vars.
        z%s = %s;N)r4  rN   r  rœ  r£  )r|   rT   rÃ   rV  r&   r&   r'   Úrelease_closure_privatesç   s    z)ParallelStatNode.release_closure_privatesr&   c       
      C   sÜ   | j }d| _ | jrØ|j ¡  | _}g g  }}x6t|ƒD ]*\}}|jsJ|jrV| |¡ q6| |¡ q6W |r|| 	dd 
|¡ ¡ |r”| 	dd 
|¡ ¡ | jrØtjg}	| jrÄ|	 | j¡ | 	d| j ¡ | 	dd 
|	¡ ¡ dS )z’
        Make any used temporaries private. Before the relevant code block
        code.start_collecting_temps() should have been called.
        Nz private(%s)z, z firstprivate(%s)z private(%s, %s, %s)z shared(%s))Úprivatization_insertion_pointr0  rœ  Zstop_collecting_tempsr·   r5  r:   r€  rþ   rÒ  r   Úbreaking_label_usedr	   Úparallel_whyÚerror_label_usedÚextendÚparallel_excÚpos_info)
r|   rT   Zexclude_tempsr–   r·   r'  Zfirstprivatesr¤  r/   Zshared_varsr&   r&   r'   Úprivatize_tempsò   s&    
z ParallelStatNode.privatize_tempsc             C   sh   | j rd| jsd| d¡ xLt| jƒD ]>\}}|jr@|j|dd q"|jr"| ||¡ | d| ¡ q"W d S )Nz/* Clean up any temporaries */F)r¿  z
%s = NULL;)	r0  Úis_nested_prangerN   r5  r·   r€  r  r:   rý  )r|   rT   r¤  r/   r&   r&   r'   Úcleanup_temps!  s    
zParallelStatNode.cleanup_tempsc             C   sT   |  ¡ | _| ¡ | _|j| _|jdd|_| ¡  | ¡ | _	| ¡ | _
|  |¡ dS )a¥  
        Sets up a block that surrounds the parallel block to determine
        how the parallel section was exited. Any kind of return is
        trapped (break, continue, return, exceptions). This is the idea:

        {
            int why = 0;

            #pragma omp parallel
            {
                return # -> goto new_return_label;
                goto end_parallel;

            new_return_label:
                why = 3;
                goto end_parallel;

            end_parallel:;
                #pragma omp flush(why) # we need to flush for every iteration
            }

            if (why == 3)
                goto old_return_label;
        }
        Úreturn)r9   N)r•  r—  r¢  r©  rú  rÜ  rË  r	  rÙ  Ú%begin_of_parallel_control_block_pointr9  Ú"undef_builtin_expect_apple_gcc_bug)r|   rT   r&   r&   r'   Ú!setup_parallel_control_flow_block!  s    



z2ParallelStatNode.setup_parallel_control_flow_blockc             C   s   |  ¡ | _dS )aœ  
        Each OpenMP thread in a parallel section that contains a with gil block
        must have the thread-state initialized. The call to
        PyGILState_Release() then deallocates our threadstate. If we wouldn't
        do this, each with gil block would allocate and deallocate one, thereby
        losing exception information before it can be saved before leaving the
        parallel section.
        N)rÙ  Úbegin_of_parallel_block)r|   rT   r&   r&   r'   Úbegin_parallel_block@!  s    	z%ParallelStatNode.begin_parallel_blockc             C   s®   | j }d| _ | jrª|}| d¡ |jdd | d¡ | d¡ | d¡ | d¡ | d¡ | d	¡ | ¡  | d¡ |  |¡ | ¡  | d
¡ | d¡ | d¡ dS )a–  
        To ensure all OpenMP threads have thread states, we ensure the GIL
        in each thread (which creates a thread state if it doesn't exist),
        after which we release the GIL.
        On exit, reacquire the GIL and release the thread state.

        If compiled without OpenMP support (at the C level), then we still have
        to acquire the GIL to decref any object temporaries.
        Nz#ifdef _OPENMPT)rÞ  ZPy_BEGIN_ALLOW_THREADSz#endif /* _OPENMP */ZPy_END_ALLOW_THREADSz#elsez{
z#ifndef _OPENMPz}
)rM  rB  rN   rÝ  Zput_saferH  rõ  )r|   rT   Z
begin_codeZend_coder&   r&   r'   Úend_parallel_blockK!  s&    











z#ParallelStatNode.end_parallel_blockc       	      C   s^  |  ¡ }|  ¡ }d| _d| _d| _g | _| ¡ }x.|D ]&}| |¡r6| jpR||jk| _d| _q6W | jrp| |¡ x”t	|ƒD ]ˆ\}}| |¡sŽqz||jk}| 
|¡ |rª|sÜ||jkrÄd| _|  |¡ | dtj|d f ¡ | jrø| jrø|sø| |¡ qz| |¡ qzW | jrZ| jr2| jr2| 
|¡ |  |¡ | 
|¡ |rZ| jrZ| dtj ¡ dS )að  
        Trap any kind of return inside a parallel construct. 'should_flush'
        indicates whether the variable should be flushed, which is needed by
        prange to skip the loop. It also indicates whether we need to register
        a continue (we need this for parallel blocks, but not for prange
        loops, as it is a direct jump there).

        It uses the same mechanism as try/finally:
            1 continue
            2 break
            3 return
            4 error
        FTz%s = %d;r   z#pragma omp flush(%s)N)rË  Úany_label_usedr@  rB  Úparallel_private_tempsrñ  r¥  rm  rù  r  rû  r÷  Úfetch_parallel_exceptionrN   r	   rA  r*  Úsave_parallel_varsrr  )	r|   rT   Úshould_flushZsave_lastprivates_labelZdont_return_labelZ
all_labelsræ  r"  Zis_continue_labelr&   r&   r'   Útrap_parallel_exitl!  sF    











z#ParallelStatNode.trap_parallel_exitc             C   sì   d| j  }| d| ¡ t j d7  _ | ¡  | j}d}x¦t| j ¡ ƒD ]”\}\}}|rH|jj	rbqH|j 
¡ }d| }	|j}
|d7 }|j ¡ }|r¢d|j |¡ }nd}| d||	|f ¡ | d	|	|
f ¡ | j |	|
f¡ qHW | ¡  d
S )a¨  
        The following shenanigans are instated when we break, return or
        propagate errors from a prange. In this case we cannot rely on
        lastprivate() to do its job, as no iterations may have executed yet
        in the last thread, leaving the values undefined. It is most likely
        that the breaking thread has well-defined values of the lastprivate
        variables, so we keep those values.
        z__pyx_parallel_lastprivates%dz#pragma omp critical(%s)r   r   z__pyx_parallel_temp%dz = r§   z%s %s%s;z%s = %s;N)Úcritical_section_counterrr  r$  r	  rJ  r5  r'  rb   r/   r:   r;  r  r6  rB  rN   rQ  rþ   r
  )r|   rT   Zsection_namer–   Z
temp_countrÃ   rB  r2  Z	type_declÚ
temp_cnameÚprivate_cnamer6  r  r&   r&   r'   rS  ¯!  s*    	


z#ParallelStatNode.save_parallel_varsc             C   sš   |  ¡  |jdd | dtj ¡ | dtj ¡ | d| j ¡ tt| j	| j
ƒŽ }d|j_| dt|ƒ ¡ | tj¡ | d¡ | ¡  | ¡  dS )	a^  
        As each OpenMP thread may raise an exception, we need to fetch that
        exception from the threadstate and save it for after the parallel
        section where it can be re-raised in the master thread.

        Although it would seem that __pyx_filename, __pyx_lineno and
        __pyx_clineno are only assigned to under exception conditions (i.e.,
        when we have the GIL), and thus should be allowed to be shared without
        any race condition, they are in fact subject to the same race
        conditions that they were previously when they were global variables
        and functions were allowed to release the GIL:

            thread A                thread B
                acquire
                set lineno
                release
                                        acquire
                                        set lineno
                                        release
                acquire
                fetch exception
                release
                                        skip the fetch

                deallocate threadstate  deallocate threadstate
        T)rÞ  z#pragma omp flush(%s)z
if (!%s) {z'__Pyx_ErrFetchWithState(&%s, &%s, &%s);z%s = %s; %s = %s; %s = %s;r¾  N)r	  rÝ  rr  r	   Úparallel_exc_typerN   rD  r   r5  Úparallel_pos_inforE  rœ  Zuses_error_indicatorr¸  r   rõ  r
  )r|   rT   rE  r&   r&   r'   rR  Ú!  s    z)ParallelStatNode.fetch_parallel_exceptionc             C   sh   |  ¡  |jdd | tj¡ | d| j ¡ tt| j	| j
ƒŽ }| dt|ƒ ¡ | ¡  | ¡  dS )zRe-raise a parallel exceptionT)rÞ  z&__Pyx_ErrRestoreWithState(%s, %s, %s);z%s = %s; %s = %s; %s = %s;N)r	  rÝ  rF  r	   rY  rN   rD  r   r5  rE  rZ  r¸  rõ  r
  )r|   rT   rE  r&   r&   r'   Úrestore_parallel_exception"  s    z+ParallelStatNode.restore_parallel_exceptionc             C   s   |  | j| j| jf ¡ dS )z›
        Restore all old labels. Call this before the 'else' clause to for
        loops and always before ending the parallel control flow block.
        N)ró  r—  rÜ  r©  )r|   rT   r&   r&   r'   Úrestore_labels"  s    zParallelStatNode.restore_labelsc       	      C   sœ  | j }d| _ d| _| jrl| d| j ¡ | d| j ¡ | dtj ¡ | d¡ | dtj ¡ | d¡ |rx| j	}n| j
}|r†| dtj ¡ | d	tj ¡ | dtj ¡ x$| jD ]\}}| d
||f ¡ q¼W | dtj ¡ |r| d¡ | |j¡ |r"| d¡ | |j¡ |r>| d¡ | |j¡ | jrr|j t¡ | d¡ |  |¡ | |j¡ | d¡ | d¡ | ¡  |  |¡ dS )aÕ  
        This ends the parallel control flow block and based on how the parallel
        section was exited, takes the corresponding action. The break_ and
        continue_ parameters indicate whether these should be propagated
        outwards:

            for i in prange(...):
                with cython.parallel.parallel():
                    continue

        Here break should be trapped in the parallel block, and propagated to
        the for loop.
        Nz*const char *%s = NULL; int %s = 0, %s = 0;z,PyObject *%s = NULL, *%s = NULL, *%s = NULL;z	if (%s) {zg/* This may have been overridden by a continue, break or return in another thread. Prefer the error. */z%s = 4;r¾  zint %s;z%s = 0;z%s = %s;zswitch (%s) {z    case 1: z    case 2: z    case 3: z    case 4:)rJ  r9  rB  rN   rZ  rD  r	   rY  rA  rP  r@  rQ  rÒ  rù  rm  rk  rú  r¾   rc  rþ  r[  r÷  r
  Ú"redef_builtin_expect_apple_gcc_bug)	r|   rT   Úbreak_Ú	continue_Úreturn_r–   rP  rW  rX  r&   r&   r'   Úend_parallel_control_flow_block"  sT    






z0ParallelStatNode.end_parallel_control_flow_blockz((defined(__APPLE__) || defined(__OSX__))zQ(defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))))z
(%s && %s)c             C   s   | j s| | j¡ dS )z]
        A bug on OS X Lion disallows __builtin_expect macros. This code avoids them
        N)r/  Zundef_builtin_expectÚredef_condition)r|   rT   r&   r&   r'   rK  m"  s    z3ParallelStatNode.undef_builtin_expect_apple_gcc_bugc             C   s   | j s| | j¡ d S )N)r/  Zredef_builtin_expectrb  )r|   rT   r&   r&   r'   r]  t"  s    z3ParallelStatNode.redef_builtin_expect_apple_gcc_bug)N)r&   )F)FFF)5rJ   rj   rk   rv   r‡   r   r*  rG  rB  r%  r)  r	   rY  Zparallel_exc_valueZparallel_exc_tbrD  Zparallel_filenameZparallel_linenoZparallel_clinenorZ  rÿ  rý  rþ  rE  rV  r~   r   ro   r.  r1  r3  r8  r;  r<  r=  r>  rF  rH  rL  rN  rO  rU  rS  rR  r[  r\  ra  Zbuggy_platform_macro_conditionZhave_expect_conditionrb  rK  r]  rl   r&   r&   )rI   r'   r$  ±  sZ   &G

%!
C+.	
Jr$  c                   s2   e Zd ZdZdgZdZ‡ fdd„Zdd„ Z‡  ZS )ÚParallelWithBlockNodezI
    This node represents a 'with cython.parallel.parallel():' block
    r%  Nc                s&   t t| ƒ |¡ | jr"t| jdƒ d S )Nz=cython.parallel.parallel() does not take positional arguments)rc   rc  r   rQ   r   r%   )r|   r@   )rI   r&   r'   r   ‚"  s    z*ParallelWithBlockNode.analyse_declarationsc             C   s$  |   |¡ |  |¡ | d¡ | d¡ | jrVdd„ | jD ƒ}| dd t|ƒ¡ ¡ | ¡ | _|  	|¡ | d¡ | d¡ | 
¡  |  |¡ |  |¡ |j ¡  | j |¡ |  |¡ |  |¡ |  |¡ | ¡  | |j¡}| |j¡}| |j¡}|  |¡ | j||||d	 |  |¡ d S )
Nz#ifdef _OPENMPz#pragma omp parallel c             S   s   g | ]}|j js|j‘qS r&   )r/   r:   r  )r„   rb  r&   r&   r'   r†   "  s    zAParallelWithBlockNode.generate_execution_code.<locals>.<listcomp>zprivate(%s)z, r§   z#endif /* _OPENMP */)r^  r_  r`  )r=  rL  rN   rÒ  r'  r   r5  rÙ  r?  r<  r	  rN  r8  rœ  Ústart_collecting_tempsr   rÀ   rU  rF  rO  r
  r¥  rm  rk  rú  r\  ra  r>  )r|   rT   r'  r_  r^  r`  r&   r&   r'   rÀ   ˆ"  s8    














z-ParallelWithBlockNode.generate_execution_code)	rJ   rj   rk   rv   r,  r%  r   rÀ   rl   r&   r&   )rI   r'   rc  y"  s
   rc  c                   s”   e Zd ZdZddddddgZd Z Z ZZd Z	 Z
Zd	ZdZdZd
dddgZ‡ fdd„Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚParallelRangeNodezÌ
    This node represents a 'for i in cython.parallel.prange():' construct.

    target       NameNode       the target iteration variable
    else_clause  Node or None   the else clause of this loop
    r   rI  r‚  rQ   r%  r)  NTÚscheduler
  c                s"   t t| ƒj|f|Ž t|ƒ| _d S )N)rc   re  r~   r&  r¯  )r|   r%   rR   )rI   r&   r'   r~   Å"  s    zParallelRangeNode.__init__c                sÜ   t t| ƒ |¡ | j |¡ | jd k	r2| j |¡ | jrFt| jƒdkrVt| j	dƒ d S t| jƒdkrp| j\| _
n0t| jƒdkrŽ| j\| _| _
n| j\| _| _
| _t| jdƒrº| j d¡| _| jdkrØt| j	d| jf ƒ d S )	Nr$   z0Invalid number of positional arguments to pranger   r"   ÚdecodeÚascii)NZstaticZdynamicZguidedÚruntimez'Invalid schedule argument to prange: %s)rc   re  r   rI  rÿ  r‚  rQ   rG   r   r%   r8  rV   r»  r<  rf  rg  )r|   r@   )rI   r&   r'   r   Ê"  s     

z&ParallelRangeNode.analyse_declarationsc                sp  |j }| j rd|_ | jd kr,t| jdƒ | S | j |¡| _| jjjsn| jjjsdt| jjd| jj ƒ tj	| _
n$| jj| _
| j
js’t| jjddd d| _| j| j| jf}xtt|| jƒD ]d\}}|d k	r¶| |¡ |jjsêt|jd| ƒ q¶|js| |¡}t| ||ƒ t | j
|j¡| _
q¶W | jd k	r8| j |¡| _t| jd	ƒr\| jjd f| j| jj< tt| ƒ |¡}|jrö|jsŒt|jjd
ƒ nR|jdkr¨t|jjdƒ n6|jjj rÞ|jjrÞ|j !|¡dkrÞt|jjdƒ |j "tj#|¡ |¡|_|j r||_ |j$o|j$j%|_&|j&rl|}x|j$r@|j$j%r@|j$}q$W |j '|j¡ |j( '|j(¡ |j) *|j)¡ |S )NTz/prange() can only be used as part of a for loopzMust be of numeric type, not %sz1Unsigned index type not allowed before OpenMP 3.0r"   )r›   )rV   r8  r»  z%s argument must be numericrÃ   z$Must provide schedule with chunksizeri  z,Chunksize not valid for the schedule runtimer   zChunksize must not be negative)+r
  rI  r   r%   rp   r/   rZ  r:   r
   r±  Ú
index_typerU  r   r"  rV   r8  r»  r5  rn   r´   r?  rŠ   r¾  r‚  ro   r<  rM  rÃ   rc   re  r)  rf  ró   r3  r  r<   r/  r*  rG  r{   r'  r(  rC  )r|   r@   r  Ústart_stop_steprS   r9   r/  )rI   r&   r'   ro   á"  sv    







z%ParallelRangeNode.analyse_expressionsc             C   sT   d}| j | j| j| jf}x6t||ƒD ](\}}|d k	r$|jjr$t|jd| ƒ q$W d S )N)rV   r8  r»  rI  z6%s may not be a Python object as we don't have the GIL)	rV   r8  r»  rI  r5  r/   r:   r   r%   )r|   r@   r"  Znodesr9   rS   r&   r&   r'   r¹   :#  s    zParallelRangeNode.nogil_checkc             C   sÊ  |   |¡ | jjj}|| jj ¡ dœ}| j| j| jf}d}xTt	|| j
|ƒD ]B\}}}|dkrb|}	n"|jrr| ¡ }	n| |¡ | ¡ }	|	||< qJW |j | jd¡|d< |j | jd¡|d< | d| ¡ |  |¡ | d| ¡ | d	| ¡ | ¡  |  ||¡ | ¡  |  |¡ | jrX| jr2| d
tj ¡ | ¡  | d¡ | j |¡ | ¡  |  |¡ x8|| j| j f D ]$}
|
dk	rt|
 !|¡ |
 "|¡ qtW |j #|d ¡ |j #|d ¡ |  $|¡ dS )a,  
        Generate code in the following steps

            1)  copy any closure variables determined thread-private
                into temporaries

            2)  allocate temps for start, stop and step

            3)  generate a loop that calculates the total number of steps,
                which then computes the target iteration variable for every step:

                    for i in prange(start, stop, step):
                        ...

                becomes

                    nsteps = (stop - start) / step;
                    i = start;

                    #pragma omp parallel for lastprivate(i)
                    for (temp = 0; temp < nsteps; temp++) {
                        i = start + step * temp;
                        ...
                    }

                Note that accumulation of 'i' would have a data dependency
                between iterations.

                Also, you can't do this

                    for (i = start; i < stop; i += step)
                        ...

                as the '<' operator should become '>' for descending loops.
                'for i from x < i < y:' does not suffer from this problem
                as the relational operator is known at compile time!

            4) release our temps and write back any private closure variables
        )rI  rå  )r\  r\  rÂ  NFr"  Znstepszif (%(step)s == 0) abort();zS%(nsteps)s = (%(stop)s - %(start)s + %(step)s - %(step)s/abs(%(step)s)) / %(step)s;zif (%(nsteps)s > 0)zif (%s < 2)z
/* else */)%r=  rI  rÃ   r  r/   r;  rV   r8  r»  r5  r"  r´   rô   rA  r‹   rœ  r  rj  rN   rL  r	  Úgenerate_loopr
  r\  r‚  r@  rÒ  r	   rA  rÀ   ra  r)  r%  r  rH  r£  r>  )r|   rT   Ztarget_index_cnameÚfmt_dictrk  ÚdefaultsrS   r9   r×   r‹   r¤  r&   r&   r'   rÀ   B#  sN    (









z)ParallelRangeNode.generate_execution_codec       
      C   sˆ  | j r| d¡ n
| d¡ | js@| d¡ | ¡ | _| jj}nf| d¡ | ¡ | _| j}| d¡ | d¡ | ¡  |  |¡ | j r’| d¡ n
| d¡ | d¡ xÄt	| j
 ¡ ƒD ]²\}\}}|r|dkr|| jjkr|jjröt| jdƒ n| d	||jf ¡ q¶|| jjkr<| d
|j ¡ | d|j ¡ q¶|jjs¶|rPd}nd}| d||jf ¡ q¶W | jr¨| jrd|  || j¡ }nd}| d| j|f ¡ |  |¡ | d¡ | d¡ | d| ¡ | ¡  | ¡ }	| ¡  | d| ¡ | j|| jjd | jr|j ¡  | j |¡ | j|dd |  |¡ | jrZ|	 dtj  ¡ | !¡  | !¡  | jr„|  "|¡ | !¡  d S )Nz#if 0z#ifdef _OPENMPz#pragma omp forz#pragma omp parallelr§   z#endif /* _OPENMP */z+*-&^|z#Python objects cannot be reductionsz reduction(%s:%s)z firstprivate(%s)z lastprivate(%s)r2  rL  z %s(%s)z, %sz schedule(%s%s)z,for (%(i)s = 0; %(i)s < %(nsteps)s; %(i)s++)z=%(target)s = (%(target_type)s)(%(start)s + %(step)s * %(i)s);)r7  T)rT  zif (%s < 2))#rG  rN   r0  rÒ  rÙ  r?  r/  r	  rN  r5  r'  rb   rI  rÃ   r/   r:   r   r%   r  rf  r)  r;  r<  r8  rœ  rd  r   rÀ   rU  rF  r@  r	   rA  r
  rO  )
r|   rT   rm  Zreduction_codepointrÃ   rB  r2  rL  r)  Zguard_around_body_codepointr&   r&   r'   rl  µ#  sv    
















zParallelRangeNode.generate_loop)rJ   rj   rk   rv   r‡   r   rI  r‚  rQ   rV   r8  r»  r*  r
  rf  r,  r~   r   ro   r¹   rÀ   rl  rl   r&   r&   )rI   r'   re  ¯"  s   
Ysre  c               @   s>   e Zd ZdZdgZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚCnameDecoratorNodea?  
    This node is for the cname decorator in CythonUtilityCode:

        @cname('the_cname')
        cdef func(...):
            ...

    In case of a cdef class the cname specifies the objstruct_cname.

    node        the node to which the cname decorator is applied
    cname       the cname the node should get
    rS   c             C   sD  | j  |¡ | j }t|tƒr(|jjd }t|tƒ| _t|tt	fƒ}|j
}| jr„| j|_| j|_d|_|jr‚d|jkr‚|  |j¡|_n¼|rš| j |_|j_n¦|j}| j|_| jd |j_tj| j |j_| jd |j_|jj|jj_|jj|j_| jd |_xD|j ¡ D ]6\}}|jr$|  |j¡|_|jr|  |j¡|_qW d S )Nr   Tr  Z_objZ_typerr  )rS   r   rH   r»   r   rÇ   r§  Úis_functionr‡  r™  rÃ   r  rQ  r0  rˆ  r-  r/   r)  r
  r	   Ztypeobj_prefixr  rè  r  r@  r‡  rÂ   rb   )r|   r@   rS   Zis_struct_or_enumrb  r)  r9   rÃ   r&   r&   r'   r   '$  s8    
z'CnameDecoratorNode.analyse_declarationsc             C   s$   d|kr|  d¡d }d| j|f S )Nr  rª   z%s_%s)r  r  )r|   r  r&   r&   r'   r-  M$  s    zCnameDecoratorNode.manglec             C   s   | j  |¡| _ | S )N)rS   ro   )r|   r@   r&   r&   r'   ro   S$  s    z&CnameDecoratorNode.analyse_expressionsc             C   s†   | j rt|jrt|jd }t| jtƒr6| jj|ddd n>ddlm} | jj	}|j
}|j|_
|j|| ¡ |dd ||_
| j ||¡ dS )	z=Ensure a prototype for every @cname method in the right placeZutility_code_protoFT)r¹  rº  r   )Ú
ModuleNode)Z
definitionN)rp  r  r¾   rH   rS   r?  rÑ  r§   rq  rÃ   r  rQ  Zgenerate_cfunction_declarationrÁ   r¿   )r|   r@   rT   Zh_coderq  rÃ   r  r&   r&   r'   r¿   W$  s     
z0CnameDecoratorNode.generate_function_definitionsc             C   s   | j  |¡ d S )N)rS   rÀ   )r|   rT   r&   r&   r'   rÀ   p$  s    z*CnameDecoratorNode.generate_execution_codeN)
rJ   rj   rk   rv   r‡   r   r-  ro   r¿   rÀ   r&   r&   r&   r'   ro  $  s   &ro  aC  
/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
z1
#define likely(x)   (x)
#define unlikely(x) (x)
ZPrintz
Printing.cZPrintOneræ  zExceptions.cZRaiseExceptionZGetExceptionZSwapExceptionZSaveResetExceptionZAddTracebackzR
static PyObject *__Pyx_GetExceptionTuple(PyThreadState *__pyx_tstate); /*proto*/
a1  
static PyObject *__Pyx_GetExceptionTuple(CYTHON_UNUSED PyThreadState *__pyx_tstate) {
    PyObject *type = NULL, *value = NULL, *tb = NULL;
    if (__Pyx_GetException(&type, &value, &tb) == 0) {
        PyObject* exc_info = PyTuple_New(3);
        if (exc_info) {
            Py_INCREF(type);
            Py_INCREF(value);
            Py_INCREF(tb);
            PyTuple_SET_ITEM(exc_info, 0, type);
            PyTuple_SET_ITEM(exc_info, 1, value);
            PyTuple_SET_ITEM(exc_info, 2, tb);
            return exc_info;
        }
    }
    return NULL;
}
)rÓ  ÚimplZrequires)N)¥Z
__future__r   r  rŠ  rT  r   r   r   Ú	itertoolsr   r§   r   ZErrorsr   r   r   r   r	   r
   r   r   r   ZSymtabr   r   r   r   r   r   r   r`   r   ZStringEncodingr   r   r   r   ZPythranr   r    r!   ZUtilsr#   ro  r0   r   r1   r(   r.   rD   r[   r/   r\   rm   rx   ry   r»   r   rÆ   rÌ   rÍ   rÓ   rÖ   rä   rç   rè   rú   r3  r5  rR  r>   rS  r\  re  r=  rq  rs  ru  rx  rÎ   r‡  rŒ  r™  r¥  r¦  r§  r•  r`  r>  r?  rp  rÌ  r×  rÙ  rÚ  rÛ  rC  rï  rð  rü  r   r!  r#  rë  r,  r0  rQ  r-  rX  r^  re  rf  r&  ri  rj  rl  rH  rs  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  r  Zutility_code_for_importsr  r  r  r#  r$  rc  re  ro  Zgcc_branch_hintsZbranch_prediction_macrosrÉ  ra  rc  rþ  r|  rè  rü  rÙ  Ztraceback_utility_codeZ get_exception_tuple_utility_coder&   r&   r&   r'   Ú<module>   sz  


$
/ ,*%#, Bt	^!Q'j-X1!                  08 5r D   @  2f/GC)7
rh=C)$-<\<
a
 pg! + '  	H	+O\     M6  jc