U
    †µ“eâ_  ã                   @   sœ   d Z ddlmZmZ ddlmZ ddlT ddlm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eƒZG dd„ deeƒZdS )a  
Serializes a Cython code tree to Cython code. This is primarily useful for
debugging and testing purposes.
The output is in a strict format, no whitespace or comments from the input
is preserved (and it could not be as it is not present in the code tree).
é    )Úabsolute_importÚprint_functioné   )ÚTreeVisitor)Ú*)ÚCSimpleBaseTypeNodec                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚLinesResultc                 C   s   g | _ d| _d S ©NÚ )ÚlinesÚs©Úself© r   ú5/tmp/pip-unpacked-wheel-7k3cqui1/Cython/CodeWriter.pyÚ__init__   s    zLinesResult.__init__c                 C   s   |  j |7  _ d S ©N)r   ©r   r   r   r   r   Úput   s    zLinesResult.putc                 C   s   | j  | j¡ d| _d S r	   )r   Úappendr   r   r   r   r   Únewline   s    zLinesResult.newlinec                 C   s   |   |¡ |  ¡  d S r   )r   r   r   r   r   r   Úputline   s    
zLinesResult.putlineN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r      s   r   c                       sd  e Zd ZdZdZdV‡ fdd„	Zdd„ Zdd	„ Zd
d„ ZdWdd„Z	dd„ Z
dd„ ZdXdd„Zdd„ ZdYd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d0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z d>d?„ Z!d@dA„ Z"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&dJdK„ Z'dLdM„ Z(dNdO„ Z)dPdQ„ Z*dRdS„ Z+dTdU„ Z,‡  Z-S )ZÚDeclarationWriterzE
    A Cython code writer that is limited to declarations nodes.
    z    Nc                    s8   t t| ƒ ¡  |d krtƒ }|| _d| _i | _d| _d S )Nr   )Úsuperr   r   r   ÚresultÚ
numindentsÚ	tempnamesÚtempblockindex©r   r   ©Ú	__class__r   r   r   '   s    zDeclarationWriter.__init__c                 C   s   |   |¡ | jS r   ©Úvisitr   ©r   Útreer   r   r   Úwrite0   s    
zDeclarationWriter.writec                 C   s   |  j d7  _ d S ©Nr   ©r   r   r   r   r   Úindent4   s    zDeclarationWriter.indentc                 C   s   |  j d8  _ d S r)   r*   r   r   r   r   Údedent7   s    zDeclarationWriter.dedentr
   c                 C   s   | j  | j| j | ¡ d S r   )r   r   Úindent_stringr   r   r   r   r   Ú	startline:   s    zDeclarationWriter.startlinec                 C   s   | j  |¡ d S r   )r   r   r   r   r   r   r   =   s    zDeclarationWriter.putc                 C   s   | j  | j| j | ¡ d S r   )r   r   r-   r   r   r   r   r   r   @   s    zDeclarationWriter.putlinec                 C   s   | j  |¡ d S r   )r   r   r   r   r   r   ÚendlineC   s    zDeclarationWriter.endlinec                 C   s   |   |¡ |  ¡  d S r   ©r.   r/   r   r   r   r   ÚlineF   s    
zDeclarationWriter.lineFc                 C   s”   t |ƒdkr|d d… D ]<}|  |¡ |rJ|jd k	rJ|  d¡ |  |j¡ |  d¡ q|  |d ¡ |r|d jd k	r|  d¡ |  |d j¡ d S )Nr   éÿÿÿÿú = ú, )Úlenr%   Údefaultr   )r   ÚitemsÚ
output_rhsÚitemr   r   r   Úcomma_separated_listJ   s    


z&DeclarationWriter.comma_separated_listc                 C   s   |   ¡  |  |¡ |  ¡  d S r   )r+   r%   r,   ©r   Únoder   r   r   Ú_visit_indentedW   s    
z!DeclarationWriter._visit_indentedc                 C   s   t d| ƒ‚d S ©Nz"Node not handled by serializer: %r©ÚAssertionErrorr;   r   r   r   Ú
visit_Node\   s    zDeclarationWriter.visit_Nodec                 C   s   |   |¡ d S r   ©Zvisitchildrenr;   r   r   r   Úvisit_ModuleNode_   s    z"DeclarationWriter.visit_ModuleNodec                 C   s   |   |¡ d S r   rB   r;   r   r   r   Úvisit_StatListNodeb   s    z$DeclarationWriter.visit_StatListNodec                 C   s8   |j d krd}n
d|j  }|  d| ¡ |  |j¡ d S )Nr   z"%s"zcdef extern from %s:)Zinclude_filer   r=   Úbody)r   r<   Úfiler   r   r   Úvisit_CDefExternNodee   s
    

z&DeclarationWriter.visit_CDefExternNodec                 C   s   |   d¡ |  |j¡ d S )Nr   ©r   r%   Úbaser;   r   r   r   Úvisit_CPtrDeclaratorNodem   s    
z*DeclarationWriter.visit_CPtrDeclaratorNodec                 C   s   |   d¡ |  |j¡ d S )Nú&rH   r;   r   r   r   Úvisit_CReferenceDeclaratorNodeq   s    
z0DeclarationWriter.visit_CReferenceDeclaratorNodec                 C   s:   |   |j¡ |  d¡ |jd k	r,|   |j¡ |  d¡ d S ©Nú[ú])r%   rI   r   Z	dimensionr;   r   r   r   Úvisit_CArrayDeclaratorNodeu   s
    

z,DeclarationWriter.visit_CArrayDeclaratorNodec                 C   s0   |   |j¡ |  d¡ |  |j¡ |  d¡ d S ©Nú(ú))r%   rI   r   r:   Úargsr/   r;   r   r   r   Úvisit_CFuncDeclaratorNode|   s    
z+DeclarationWriter.visit_CFuncDeclaratorNodec                 C   s   |   |j¡ d S r   ©r   Únamer;   r   r   r   Úvisit_CNameDeclaratorNodeƒ   s    z+DeclarationWriter.visit_CNameDeclaratorNodec                 C   sh   |j rN|  d|j ¡ |jdk r4|  d|j  ¡ n|jdkrN|  d|j ¡ |jd k	rd|  |j¡ d S )N)z	unsigned r
   zsigned r   zshort zlong )Zis_basic_c_typer   ÚsignedZlongnessrW   r;   r   r   r   Úvisit_CSimpleBaseTypeNode†   s    


z+DeclarationWriter.visit_CSimpleBaseTypeNodec                 C   s   |   |j¡ |   |j¡ d S r   )r%   Ú	base_typeÚ
declaratorr;   r   r   r   Úvisit_CComplexBaseTypeNode‘   s    z,DeclarationWriter.visit_CComplexBaseTypeNodec                 C   s&   |   |j¡ |  d¡ |  |j¡ d S )NÚ.)r%   r[   r   rW   r;   r   r   r   Úvisit_CNestedBaseTypeNode•   s    
z+DeclarationWriter.visit_CNestedBaseTypeNodec                 C   s8   |   |j¡ |  d¡ |  |j|jj ¡ |  d¡ d S rM   )r%   Zbase_type_noder   r:   Úpositional_argsÚkeyword_argsZkey_value_pairsr;   r   r   r   Úvisit_TemplatedTypeNodeš   s    
z)DeclarationWriter.visit_TemplatedTypeNodec                 C   s<   |   d¡ |  |j¡ |  d¡ | j|jdd |  ¡  d S )Núcdef ú T)r8   )r.   r%   r[   r   r:   Zdeclaratorsr/   r;   r   r   r   Úvisit_CVarDefNode    s
    

z#DeclarationWriter.visit_CVarDefNodec                 C   s   |   |¡ |jr@|  d¡ |  |j¡ |jd k	r@|  d|j ¡ |rN|  |¡ |  d¡ |  ¡  |sp|  d¡ n|D ]}|  |¡ qt|  ¡  d S )Nrd   ú "%s"ú:Úpass)	r.   rW   r   Úcnamer/   r+   r   r%   r,   )r   r<   ÚdeclÚextrasÚ
attributesÚ	attributer   r   r   Ú_visit_container_node§   s    




z'DeclarationWriter._visit_container_nodec                 C   sP   |j rd}nd}|jdkr"|d7 }|jr0|d7 }||j7 }|  ||d |j¡ d S )Nú	ctypedef rc   Úpubliczpublic zpacked )Ztypedef_flagÚ
visibilityÚpackedÚkindrn   rl   )r   r<   rj   r   r   r   Úvisit_CStructOrUnionDefNodeº   s    

z-DeclarationWriter.visit_CStructOrUnionDefNodec                 C   sJ   d}|j rdd |j ¡ }|jr4|dd |j¡ 7 }|  |d||j¡ d S )Nr
   z[%s]r4   z(%s)zcdef cppclass)Z	templatesÚjoinZbase_classesrn   rl   )r   r<   rk   r   r   r   Úvisit_CppClassNodeÆ   s    z$DeclarationWriter.visit_CppClassNodec                 C   s   |   |dd |j¡ d S )Nz	cdef enum)rn   r7   r;   r   r   r   Úvisit_CEnumDefNodeÎ   s    z$DeclarationWriter.visit_CEnumDefNodec                 C   sJ   |   |j¡ |jr"|  d|j ¡ |jr>|  d¡ |  |j¡ |  ¡  d S )Nrf   r3   )r.   rW   ri   r   Úvaluer%   r/   r;   r   r   r   Úvisit_CEnumDefItemNodeÑ   s    
z(DeclarationWriter.visit_CEnumDefItemNodec                 C   s˜   |j r
t‚|jr&|jD ]}|  |¡ q|  d¡ |  |j¡ |jr~|  d¡ |jrh|  |j¡ |  d¡ |  |j¡ |  d¡ |  	d¡ |  
|j¡ d S )Nzcdef class rR   r^   rS   rg   )Úmodule_namer@   Z
decoratorsr%   r.   r   Ú
class_nameZbase_class_nameZbase_class_moduler/   r=   rE   )r   r<   Ú	decoratorr   r   r   Úvisit_CClassDefNodeÚ   s    






z%DeclarationWriter.visit_CClassDefNodec                 C   s8   |   d¡ |  |j¡ |  d¡ |  |j¡ |  ¡  d S )Nro   rd   )r.   r%   r[   r   r\   r/   r;   r   r   r   Úvisit_CTypeDefNodeë   s
    

z$DeclarationWriter.visit_CTypeDefNodec                 C   s6   |   d|j ¡ |  |j¡ |  d¡ |  |j¡ d S )Nzdef %s(ú):)r.   rW   r:   rT   r/   r=   rE   r;   r   r   r   Úvisit_FuncDefNodeò   s    
z#DeclarationWriter.visit_FuncDefNodec                 C   sÎ   |   |jrdnd¡ |jr6|  d |j¡¡ |  d¡ |jdkrV|  |j¡ |  d¡ |jrf|  d¡ |jrŽ|  |j¡ |jj	d k	rŽ|  d¡ |  |j
j¡ |  d¡ |  |j
j¡ |  d¡ |  |j¡ d S )Núcpdef rc   rd   Úprivateúapi rR   r   )r.   ÚoverridableÚ	modifiersr   ru   rq   Úapir[   r%   rW   r\   rI   r:   rT   r/   r=   rE   r;   r   r   r   Úvisit_CFuncDefNodeù   s$    






z$DeclarationWriter.visit_CFuncDefNodec                 C   sh   t |jtƒr|jjd k	r8|  |j¡ |j ¡ r8|  d¡ |  |j¡ |jd k	rd|  d¡ |  |j¡ d S )Nrd   r3   )	Ú
isinstancer[   r   rW   r%   r\   Zdeclared_namer   r6   r;   r   r   r   Úvisit_CArgDeclNode  s    
ÿ



z$DeclarationWriter.visit_CArgDeclNodec                 C   s>   |   d¡ |  |j¡ |jr2|  d¡ |  |j¡ |  ¡  d S )Nzcimport ú as )r.   r   rz   Úas_namer/   r;   r   r   r   Úvisit_CImportStatNode#  s    

z'DeclarationWriter.visit_CImportStatNodec                 C   s†   |   d¡ |  |j¡ |  d¡ d}|jD ]N\}}}}|d ksBt‚|rLd}n
|  d¡ |  |¡ |r*|  d¡ |  |¡ q*|  ¡  d S )Nzfrom z	 cimport TFr4   rŠ   )r.   r   rz   Zimported_namesr@   r/   )r   r<   ÚfirstÚposrW   r‹   rs   r   r   r   Úvisit_FromCImportStatNode+  s    




z+DeclarationWriter.visit_FromCImportStatNodec                 C   s   |   |j¡ d S r   rV   r;   r   r   r   Úvisit_NameNode<  s    z DeclarationWriter.visit_NameNodec                 C   s"   |   d¡ |  |j¡ |  ¡  d S )Nú@)r.   r%   r|   r/   r;   r   r   r   Úvisit_DecoratorNode?  s    
z%DeclarationWriter.visit_DecoratorNodec                 C   s   |   d¡ |  ¡  d S )Nrh   r0   r;   r   r   r   Úvisit_PassStatNodeD  s    
z$DeclarationWriter.visit_PassStatNode)N)r
   )r
   )F).r   r   r   Ú__doc__r-   r   r(   r+   r,   r.   r   r   r/   r1   r:   r=   rA   rC   rD   rG   rJ   rL   rP   rU   rX   rZ   r]   r_   rb   re   rn   rt   rv   rw   ry   r}   r~   r€   r‡   r‰   rŒ   r   r   r’   r“   Ú__classcell__r   r   r"   r   r       sT   	


	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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 )+ÚStatementWriterzD
    A Cython code writer for most language statement features.
    c                 C   s6   |   ¡  |  |j¡ |  d¡ |  |j¡ |  ¡  d S ©Nr3   )r.   r%   Úlhsr   Úrhsr/   r;   r   r   r   Úvisit_SingleAssignmentNodeN  s
    
z*StatementWriter.visit_SingleAssignmentNodec                 C   s@   |   ¡  |jD ]}|  |¡ |  d¡ q|  |j¡ |  ¡  d S r—   )r.   Zlhs_listr%   r   r™   r/   )r   r<   r˜   r   r   r   Úvisit_CascadedAssignmentNodeU  s    

z,StatementWriter.visit_CascadedAssignmentNodec                 C   s4   |   d¡ |  |jj¡ |js(|  d¡ |  ¡  d S )Nzprint ú,)r.   r:   Z	arg_tuplerT   Zappend_newliner   r/   r;   r   r   r   Úvisit_PrintStatNode]  s
    

z#StatementWriter.visit_PrintStatNodec                 C   s€   |   d¡ |jjr"|  |jj¡ n|  |j¡ |  d¡ |  |jj¡ |  	d¡ |  
|j¡ |jd k	r||  d¡ |  
|j¡ d S )Nzfor ú in rg   úelse:)r.   ÚtargetZis_sequence_constructorr:   rT   r%   r   ÚiteratorÚsequencer/   r=   rE   Úelse_clauser1   r;   r   r   r   Úvisit_ForInStatNoded  s    




z#StatementWriter.visit_ForInStatNodec                 C   sœ   |   d¡ |  |jd j¡ |  d¡ |  |jd j¡ |jdd … D ]0}|   d¡ |  |j¡ |  d¡ |  |j¡ qF|jd k	r˜|  d¡ |  |j¡ d S )Nzif r   rg   r   zelif rŸ   )	r.   r%   Ú
if_clausesÚ	conditionr/   r=   rE   r£   r1   )r   r<   Zclauser   r   r   Úvisit_IfStatNoder  s    





z StatementWriter.visit_IfStatNodec                 C   sP   |   d¡ |  |j¡ |  d¡ |  |j¡ |jd k	rL|  d¡ |  |j¡ d S )Nzwhile rg   rŸ   )r.   r%   r¦   r/   r=   rE   r£   r1   r;   r   r   r   Úvisit_WhileStatNode‚  s    



z#StatementWriter.visit_WhileStatNodec                 C   s   |   d¡ d S )NÚcontinue©r1   r;   r   r   r   Úvisit_ContinueStatNode‹  s    z&StatementWriter.visit_ContinueStatNodec                 C   s   |   d¡ d S )NÚbreakrª   r;   r   r   r   Úvisit_BreakStatNodeŽ  s    z#StatementWriter.visit_BreakStatNodec                 C   s   |   |j¡ d S r   )r:   rT   r;   r   r   r   Úvisit_SequenceNode‘  s    z"StatementWriter.visit_SequenceNodec                 C   s    |   ¡  |  |j¡ |  ¡  d S r   )r.   r%   Úexprr/   r;   r   r   r   Úvisit_ExprStatNode”  s    z"StatementWriter.visit_ExprStatNodec                 C   s<   |   ¡  |  |j¡ |  d|j ¡ |  |j¡ |  ¡  d S )Nz %s= )r.   r%   r˜   r   Úoperatorr™   r/   r;   r   r   r   Úvisit_InPlaceAssignmentNode™  s
    z+StatementWriter.visit_InPlaceAssignmentNodec                 C   sX   |   ¡  |  d¡ |  |j¡ |jd k	r>|  d¡ |  |j¡ |  d¡ |  |j¡ d S )Nzwith rŠ   rg   )r.   r   r%   Úmanagerr    r/   r=   rE   r;   r   r   r   Úvisit_WithStatNode   s    



z"StatementWriter.visit_WithStatNodec                 C   s0   |   d¡ |  |j¡ |   d¡ |  |j¡ d S )Nútry:zfinally:)r1   r=   rE   Zfinally_clauser;   r   r   r   Úvisit_TryFinallyStatNodeª  s    

z(StatementWriter.visit_TryFinallyStatNodec                 C   sF   |   d¡ |  |j¡ |jD ]}|  |¡ q|jd k	rB|  |j¡ d S )Nrµ   )r1   r=   rE   Zexcept_clausesr%   r£   )r   r<   Úxr   r   r   Úvisit_TryExceptStatNode°  s    


z'StatementWriter.visit_TryExceptStatNodec                 C   sd   |   d¡ |jd k	r*|  d¡ |  |j¡ |jd k	rJ|  d¡ |  |j¡ |  d¡ |  |j¡ d S )NÚexceptrd   r4   rg   )r.   Úpatternr   r%   r    r/   r=   rE   r;   r   r   r   Úvisit_ExceptClauseNode¸  s    





z&StatementWriter.visit_ExceptClauseNodec                 C   s6   |   d¡ |jd k	r*|  d¡ |  |j¡ |  ¡  d S )NÚreturnrd   )r.   rx   r   r%   r/   r;   r   r   r   Úvisit_ReturnStatNodeÃ  s
    


z$StatementWriter.visit_ReturnStatNodec                 C   s   |   d¡ d S )NÚraiserª   r;   r   r   r   Úvisit_ReraiseStatNodeÊ  s    z%StatementWriter.visit_ReraiseStatNodec                 C   s   |   d|jj ¡ d S )Nz(import %s))r   rz   rx   r;   r   r   r   Úvisit_ImportNodeÍ  s    z StatementWriter.visit_ImportNodec                 C   sJ   d}|j D ] }d| j|f | j|< |d7 }q
|  jd7  _|  |j¡ dS )zÌ
        Temporaries are output like $1_1', where the first number is
        an index of the TempsBlockNode and the second number is an index
        of the temporary which that block allocates.
        r   z$%d_%dr   N)Ztempsr    r   r%   rE   )r   r<   ÚidxÚhandler   r   r   Úvisit_TempsBlockNodeÐ  s    

z$StatementWriter.visit_TempsBlockNodec                 C   s   |   | j|j ¡ d S r   )r   r   rÂ   r;   r   r   r   Úvisit_TempRefNodeÝ  s    z!StatementWriter.visit_TempRefNodeN)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   r   r   r–   I  s*   	
r–   c                       sÐ  e Zd ZdZdm‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdnd d!„Zd"d#„ Zd$d%„ Zd&d'„ Zdod)d*„Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d5d6d6d6d7œZd8d9d:d:d:d:d:d:d:d:d:d:d;d<d=d>d>d?d?d@d@d@d@d@dAdBœZdCdD„ ZdEdF„ ZdGdH„ Z dIdJ„ Z!dKdL„ Z"dMdN„ Z#dOdP„ Z$dQdR„ Z%dSdT„ Z&dUdV„ Z'dWdX„ Z(dYdZ„ Z)d[d\„ Z*d]d^„ Z+d_d`„ Z,dadb„ Z-dpdcdd„Z.dedf„ Z/dgdh„ Z0didj„ Z1dkdl„ Z2‡  Z3S )qÚExpressionWriterzL
    A Cython code writer that is intentionally limited to expressions.
    Nc                    s,   t t| ƒ ¡  |d krd}|| _dg| _d S )Nr
   r   )r   rÅ   r   r   Ú
precedencer!   r"   r   r   r   æ  s
    zExpressionWriter.__init__c                 C   s   |   |¡ | jS r   r$   r&   r   r   r   r(   í  s    
zExpressionWriter.writec                 C   s   |  j |7  _ d S r   )r   r   r   r   r   r   ñ  s    zExpressionWriter.putc                 C   s&   | j  |¡r"| j d t|ƒ … | _ d S r   )r   Úendswithr5   r   r   r   r   Úremoveô  s    zExpressionWriter.removec                 C   sD   t |ƒdkr@|d d… D ]}|  |¡ |  d¡ q|  |d ¡ d S )Nr   r2   r4   )r5   r%   r   )r   r7   r9   r   r   r   r:   ø  s
    
z%ExpressionWriter.comma_separated_listc                 C   s   t d| ƒ‚d S r>   r?   r;   r   r   r   rA   ÿ  s    zExpressionWriter.visit_Nodec                 C   s   |   |j¡ d S r   ©r   rx   r;   r   r   r   Úvisit_IntNode  s    zExpressionWriter.visit_IntNodec                 C   s   |   |j¡ d S r   rÉ   r;   r   r   r   Úvisit_FloatNode  s    z ExpressionWriter.visit_FloatNodec                 C   s   |   d¡ d S )NÚNone©r   r;   r   r   r   Úvisit_NoneNode  s    zExpressionWriter.visit_NoneNodec                 C   s   |   |j¡ d S r   rV   r;   r   r   r   r     s    zExpressionWriter.visit_NameNodec                 C   s   |   d¡ d S )Nz...rÍ   r;   r   r   r   Úvisit_EllipsisNode  s    z#ExpressionWriter.visit_EllipsisNodec                 C   s   |   t|jƒ¡ d S r   ©r   Ústrrx   r;   r   r   r   Úvisit_BoolNode  s    zExpressionWriter.visit_BoolNodec                 C   s   |   t|jƒ¡ d S r   rÐ   r;   r   r   r   Úvisit_ConstNode  s    z ExpressionWriter.visit_ConstNodec                 C   s   |   |j¡ |   d¡ d S )NÚjrÉ   r;   r   r   r   Úvisit_ImagNode  s    zExpressionWriter.visit_ImagNoder
   c                 C   s8   t |jƒ}|d dkr"|dd … }|  d||f ¡ d S )Nr   Zubr   z%s%s)Úreprrx   r   )r   r<   ÚprefixZrepr_valr   r   r   Úemit_string  s    
zExpressionWriter.emit_stringc                 C   s   |   |d¡ d S )NÚb©rØ   r;   r   r   r   Úvisit_BytesNode!  s    z ExpressionWriter.visit_BytesNodec                 C   s   |   |¡ d S r   rÚ   r;   r   r   r   Úvisit_StringNode$  s    z!ExpressionWriter.visit_StringNodec                 C   s   |   |d¡ d S )NÚurÚ   r;   r   r   r   Úvisit_UnicodeNode'  s    z"ExpressionWriter.visit_UnicodeNode©r
   r
   c                 C   s2   |\}}|  ¡ }|  |¡ |  |¡ |  |¡ d S r   )Úsubexpr_nodesr   r:   )r   r<   ÚparensÚ
open_parenÚclose_parenr7   r   r   r   Úemit_sequence*  s
    

zExpressionWriter.emit_sequencec                 C   s   |   |d¡ d S )Nú[]©rä   r;   r   r   r   Úvisit_ListNode1  s    zExpressionWriter.visit_ListNodec                 C   s   |   |d¡ d S )Nú()ræ   r;   r   r   r   Úvisit_TupleNode4  s    z ExpressionWriter.visit_TupleNodec                 C   s,   t | ¡ ƒdkr|  |d¡ n
|  d¡ d S )Nr   ú{}zset())r5   rà   rä   r   r;   r   r   r   Úvisit_SetNode7  s    zExpressionWriter.visit_SetNodec                 C   s   |   |d¡ d S )Nrê   ræ   r;   r   r   r   Úvisit_DictNode=  s    zExpressionWriter.visit_DictNodec                 C   s&   |   |j¡ |  d¡ |   |j¡ d S ©Nz: )r%   Úkeyr   rx   r;   r   r   r   Úvisit_DictItemNode@  s    
z#ExpressionWriter.visit_DictItemNodeé   é   )Únotú!ú+ú-ú~r   é   é   é   é   é   é   é	   é
   é   )ÚorÚandÚinZnot_inÚisÚis_notú<z<=ú>z>=z!=z==ú|ú^rK   z<<z>>rô   rõ   r   r‘   ú/z//ú%ú**c                 C   s,   | j d }||kr|  d¡ | j  |¡ d S )Nr2   rR   )rÆ   r   r   )r   Únew_precÚold_precr   r   r   Úoperator_enterX  s    

zExpressionWriter.operator_enterc                 C   s2   | j dd … \}}||kr$|  d¡ | j  ¡  d S )NéþÿÿÿrS   )rÆ   r   Úpop)r   r  r  r   r   r   Úoperator_exit^  s    
zExpressionWriter.operator_exitc                 C   s:   d}| j | }|  |¡ |  d¡ |  |j¡ |  ¡  d S )Nrò   znot )Úunop_precedencer  r   r%   Úoperandr  ©r   r<   ÚopÚprecr   r   r   Úvisit_NotNoded  s    


zExpressionWriter.visit_NotNodec                 C   sB   |j }| j| }|  |¡ |  d|j  ¡ |  |j¡ |  ¡  d S )Nz%s)r±   r  r  r   r%   r  r  r  r   r   r   Úvisit_UnopNodel  s    

zExpressionWriter.visit_UnopNodec                 C   sX   |j }| j |d¡}|  |¡ |  |j¡ |  d| dd¡ ¡ |  |j¡ |  	¡  d S )Nr   z %s Ú_rd   )
r±   Úbinop_precedenceÚgetr  r%   Úoperand1r   ÚreplaceÚoperand2r  r  r   r   r   Úvisit_BinopNodet  s    
z ExpressionWriter.visit_BinopNodec                 C   s   |   |¡ d S r   ©r  r;   r   r   r   Úvisit_BoolBinopNode}  s    z$ExpressionWriter.visit_BoolBinopNodec                 C   s   |   |¡ d S r   r   r;   r   r   r   Úvisit_PrimaryCmpNode€  s    z%ExpressionWriter.visit_PrimaryCmpNodec                 C   s`   |   |j¡ |  d¡ t|jtƒrF|j ¡ r:|  |j¡ qR|  d¡ n|   |j¡ |  d¡ d S )NrN   rè   rO   )r%   rI   r   rˆ   ÚindexÚ	TupleNoderà   rä   r;   r   r   r   Úvisit_IndexNodeƒ  s    

z ExpressionWriter.visit_IndexNodec                 C   sn   |   |j¡ |  d¡ |jr(|   |j¡ |  d¡ |jrD|   |j¡ |jr`|  d¡ |   |j¡ |  d¡ d S )NrN   rg   rO   )r%   rI   r   ÚstartÚstopÚslicer;   r   r   r   Úvisit_SliceIndexNode  s    


z%ExpressionWriter.visit_SliceIndexNodec                 C   sT   |j js|  |j ¡ |  d¡ |jjs2|  |j¡ |jjsP|  d¡ |  |j¡ d S )Nrg   )r&  Zis_noner%   r   r'  Ústepr;   r   r   r   Úvisit_SliceNodeœ  s    

z ExpressionWriter.visit_SliceNodec                 C   s<   |   |j¡ |  d¡ |   |j¡ |  d¡ |   |j¡ d S )Nú if z else )r%   Ztrue_valr   ÚtestZ	false_valr;   r   r   r   Úvisit_CondExprNode¦  s
    

z#ExpressionWriter.visit_CondExprNodec                 C   s    |   |j¡ |  d|j ¡ d S )Nz.%s)r%   Úobjr   rm   r;   r   r   r   Úvisit_AttributeNode­  s    z$ExpressionWriter.visit_AttributeNodec                 C   s0   |   |j¡ |  d¡ |  |j¡ |  d¡ d S rQ   )r%   Úfunctionr   r:   rT   r;   r   r   r   Úvisit_SimpleCallNode±  s    
z%ExpressionWriter.visit_SimpleCallNodec                 C   s¢   |d krd S t |tƒr0|  |j¡ |  |j¡ nnt |tƒr^| ¡ D ]}|  |¡ |  d¡ qBn@t |t	ƒrŠ|  d¡ |  |j
¡ |  d¡ n|  |¡ |  d¡ d S )Nr4   r   )rˆ   ZAddNodeÚemit_pos_argsr  r  r$  rà   r%   r   ZAsTupleNodeÚarg©r   r<   r¯   r   r   r   r3  ·  s    





zExpressionWriter.emit_pos_argsc                 C   s”   |d krd S t |tƒr0| ¡ D ]}|  |¡ qn`t |tƒrr| ¡ D ],}|  d|jj ¡ |  |j¡ |  d¡ qBn|  d¡ |  |¡ |  d¡ d S )Nz%s=r4   r  )	rˆ   ZMergedDictNoderà   Úemit_kwd_argsZDictNoder   rî   rx   r%   r5  r   r   r   r6  É  s    



zExpressionWriter.emit_kwd_argsc                 C   sF   |   |j¡ |  d¡ |  |j¡ |  |j¡ |  d¡ |  d¡ d S )NrR   r4   rS   )r%   r1  r   r3  r`   r6  ra   rÈ   r;   r   r   r   Úvisit_GeneralCallNodeÙ  s    

z&ExpressionWriter.visit_GeneralCallNodec                 C   sj   |\}}|   |¡ |  |¡ |   d¡ |  |¡ |   d¡ |  |¡ |r\|   d¡ |  |¡ |   |¡ d S )Nz for rž   r,  )r   r%   )r   rE   r    r¢   r¦   rá   râ   rã   r   r   r   Úemit_comprehensioná  s    







z#ExpressionWriter.emit_comprehensionc                 C   s   |   |j¡ d S r   )r%   r¯   r;   r   r   r   Úvisit_ComprehensionAppendNodeð  s    z.ExpressionWriter.visit_ComprehensionAppendNodec                 C   s&   |   |j¡ |  d¡ |   |j¡ d S rí   )r%   Zkey_exprr   Z
value_exprr;   r   r   r   Ú!visit_DictComprehensionAppendNodeó  s    
z2ExpressionWriter.visit_DictComprehensionAppendNodec                 C   sp   ddddœ}||j  ¡  }|jj}|jj}|jjj}d }t|dƒrZ|jd j	}|jd j}|  
|||||¡ d S )Nrå   rê   )ÚlistÚdictÚsetr¥   r   )ÚtypeZpy_type_nameÚlooprE   r    r¡   r¢   Úhasattrr¥   r¦   r8  )r   r<   Ztpmaprá   rE   r    r¢   r¦   r   r   r   Úvisit_ComprehensionNodeø  s    

z(ExpressionWriter.visit_ComprehensionNodec                 C   sn   |j j}|j j}|j jj}d }t|dƒrF|jd j}|jd jjj	}nt|dƒrX|jj	}|  
||||d¡ d S )Nr¥   r   r¯   rè   )r?  rE   r    r¡   r¢   r@  r¥   r¦   r¯   r4  r8  )r   r<   rE   r    r¢   r¦   r   r   r   Úvisit_GeneratorExpressionNode  s    


z.ExpressionWriter.visit_GeneratorExpressionNode)N)r
   )rß   )rß   )4r   r   r   r”   r   r(   r   rÈ   r:   rA   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!  r"  r%  r)  r+  r.  r0  r2  r3  r6  r7  r8  r9  r:  rA  rB  r•   r   r   r"   r   rÅ   á  sž   

   þ               ô	

 þ
rÅ   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú	PxdWriterz\
    A Cython code writer for everything supported in pxd files.
    (currently unused)
    c                 C   s   t d |  |¡j¡ƒ |S )NÚ
)Úprintru   r(   r   r;   r   r   r   Ú__call__  s    zPxdWriter.__call__c                 C   s~   |j r|  d¡ n
|  d¡ |jr>|  d |j¡¡ |  d¡ |jdkr^|  |j¡ |  d¡ |jrn|  d¡ |  |j¡ d S )Nr   rc   rd   r‚   rƒ   )	r„   r.   r…   r   ru   rq   r†   r%   r\   r;   r   r   r   r‡     s    




zPxdWriter.visit_CFuncDefNodec                 C   s   d S r   r   r;   r   r   r   Úvisit_StatNode-  s    zPxdWriter.visit_StatNodeN)r   r   r   r”   rF  r‡   rG  r   r   r   r   rC    s   rC  c                   @   s   e Zd ZdZdS )Ú
CodeWriterz(
    A complete Cython code writer.
    N)r   r   r   r”   r   r   r   r   rH  1  s   rH  N)r”   Ú
__future__r   r   ZCompiler.Visitorr   ZCompiler.ExprNodesZCompiler.Nodesr   Úobjectr   r   r–   rÅ   rC  rH  r   r   r   r   Ú<module>   s     +   5