a
    ûb]]  ã                   @   s|   d Z ddlmZmZ ddlmZ ddlT G dd„ deƒZG dd	„ d	eƒZ	G d
d„ de	ƒZ
G dd„ de	ƒZG dd„ deƒZd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)Ú*c                   @   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   úa/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/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                       s  e Zd ZdZd`‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zdadd„Zdd„ Z	dd„ Z
dbdd„Zdd„ Zdcd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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+dVdW„ Z,dXdY„ Z-dZd[„ Z.d\d]„ Z/d^d_„ Z0‡  Z1S )dÚDeclarationWriterz    Nc                    s8   t t| ƒ ¡  |d u 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   Úwrite,   s    
zDeclarationWriter.writec                 C   s   |  j d7  _ d S ©Nr   ©r   r   r   r   r   Úindent0   s    zDeclarationWriter.indentc                 C   s   |  j d8  _ d S r(   r)   r   r   r   r   Údedent3   s    zDeclarationWriter.dedentr	   c                 C   s   | j  | j| j | ¡ d S r   )r   r   Úindent_stringr   r   r   r   r   Ú	startline6   s    zDeclarationWriter.startlinec                 C   s   | j  |¡ d S r   )r   r   r   r   r   r   r   9   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   Úendline?   s    zDeclarationWriter.endlinec                 C   s   |   |¡ |  ¡  d S r   ©r-   r.   r   r   r   r   ÚlineB   s    
zDeclarationWriter.lineFc                 C   sh   t |ƒdkrd|d d… D ]<}|  |¡ |rJ|jd urJ|  d¡ |  |j¡ |  d¡ q|  |d ¡ d S )Nr   éÿÿÿÿú = ú, )Úlenr$   Údefaultr   )r   ÚitemsÚ
output_rhsÚitemr   r   r   Úcomma_separated_listF   s    

z&DeclarationWriter.comma_separated_listc                 C   s   t d| ƒ‚d S ©Nz"Node not handled by serializer: %r©ÚAssertionError©r   Únoder   r   r   Ú
visit_NodeP   s    zDeclarationWriter.visit_Nodec                 C   s   |   |¡ d S r   ©Zvisitchildrenr=   r   r   r   Úvisit_ModuleNodeS   s    z"DeclarationWriter.visit_ModuleNodec                 C   s   |   |¡ d S r   r@   r=   r   r   r   Úvisit_StatListNodeV   s    z$DeclarationWriter.visit_StatListNodec                 C   sH   |j d u rd}n
d|j  }|  d| ¡ |  ¡  |  |j¡ |  ¡  d S )Nr   z"%s"zcdef extern from %s:)Zinclude_filer   r*   r$   Úbodyr+   )r   r>   Úfiler   r   r   Úvisit_CDefExternNodeY   s    

z&DeclarationWriter.visit_CDefExternNodec                 C   s   |   d¡ |  |j¡ d S )Nr   ©r   r$   Úbaser=   r   r   r   Úvisit_CPtrDeclaratorNodec   s    
z*DeclarationWriter.visit_CPtrDeclaratorNodec                 C   s   |   d¡ |  |j¡ d S )Nú&rF   r=   r   r   r   Úvisit_CReferenceDeclaratorNodeg   s    
z0DeclarationWriter.visit_CReferenceDeclaratorNodec                 C   s:   |   |j¡ |  d¡ |jd ur,|   |j¡ |  d¡ d S ©Nú[ú]©r$   rG   r   Z	dimensionr=   r   r   r   Úvisit_CArrayDeclaratorNodek   s
    

z,DeclarationWriter.visit_CArrayDeclaratorNodec                 C   s:   |   |j¡ |  d¡ |jd ur,|   |j¡ |  d¡ d S rK   rN   r=   r   r   r   rO   r   s
    

c                 C   s0   |   |j¡ |  d¡ |  |j¡ |  d¡ d S ©Nú(ú))r$   rG   r   r9   Úargsr.   r=   r   r   r   Úvisit_CFuncDeclaratorNodey   s    
z+DeclarationWriter.visit_CFuncDeclaratorNodec                 C   s   |   |j¡ d S r   ©r   Únamer=   r   r   r   Úvisit_CNameDeclaratorNode€   s    z+DeclarationWriter.visit_CNameDeclaratorNodec                 C   s^   |j rN|  d|j ¡ |jdk r4|  d|j  ¡ n|jdkrN|  d|j ¡ |  |j¡ d S )N)z	unsigned r	   zsigned r   zshort zlong )Zis_basic_c_typer   ÚsignedZlongnessrV   r=   r   r   r   Úvisit_CSimpleBaseTypeNodeƒ   s    

z+DeclarationWriter.visit_CSimpleBaseTypeNodec                 C   s0   |   d¡ |  |j¡ |  |j¡ |   d¡ d S rP   )r   r$   Ú	base_typeÚ
declaratorr=   r   r   r   Úvisit_CComplexBaseTypeNode   s    
z,DeclarationWriter.visit_CComplexBaseTypeNodec                 C   s&   |   |j¡ |  d¡ |  |j¡ d S )NÚ.)r$   rZ   r   rV   r=   r   r   r   Úvisit_CNestedBaseTypeNode“   s    
z+DeclarationWriter.visit_CNestedBaseTypeNodec                 C   s8   |   |j¡ |  d¡ |  |j|jj ¡ |  d¡ d S rK   )r$   Zbase_type_noder   r9   Úpositional_argsÚkeyword_argsÚ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)r7   )r-   r$   rZ   r   r9   Zdeclaratorsr.   r=   r   r   r   Úvisit_CVarDefNodež   s
    

z#DeclarationWriter.visit_CVarDefNodec                 C   s   |   |¡ |jr@|  d¡ |  |j¡ |jd ur@|  d|j ¡ |rN|  |¡ |  d¡ |  ¡  |sp|  d¡ n|D ]}|  |¡ qt|  ¡  d S )Nrd   ú "%s"ú:Úpass)	r-   rV   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]r3   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   r6   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   r2   )r-   rV   ri   r   Úvaluer$   r.   r=   r   r   r   Úvisit_CEnumDefItemNodeÏ   s    
z(DeclarationWriter.visit_CEnumDefItemNodec                 C   s¨   |j r
J ‚|jr&|jD ]}|  |¡ q|  d¡ |  |j¡ |jr~|  d¡ |jrh|  |j¡ |  d¡ |  |j¡ |  d¡ |  d¡ |  	¡  |  |j
¡ |  ¡  d S )Nzcdef class rQ   r]   rR   rg   )Úmodule_nameZ
decoratorsr$   r-   r   Ú
class_nameZbase_class_nameZbase_class_moduler.   r*   rC   r+   )r   r>   Ú	decoratorr   r   r   Úvisit_CClassDefNodeØ   s"    






z%DeclarationWriter.visit_CClassDefNodec                 C   s8   |   d¡ |  |j¡ |  d¡ |  |j¡ |  ¡  d S )Nro   rd   )r-   r$   rZ   r   r[   r.   r=   r   r   r   Úvisit_CTypeDefNodeë   s
    

z$DeclarationWriter.visit_CTypeDefNodec                 C   sF   |   d|j ¡ |  |j¡ |  d¡ |  ¡  |  |j¡ |  ¡  d S )Nzdef %s(z):)	r-   rV   r9   rS   r.   r*   r$   rC   r+   r=   r   r   r   Úvisit_FuncDefNodeò   s    
z#DeclarationWriter.visit_FuncDefNodec                 C   sR   |j jd ur"|  |j ¡ |  d¡ |  |j¡ |jd urN|  d¡ |  |j¡ d S )Nrd   r2   )rZ   rV   r$   r   r[   r5   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 u sBJ ‚|rLd}n
|  d¡ |  |¡ |r*|  d¡ |  |¡ q*|  ¡  d S )Nzfrom z	 cimport TFr3   r   )r-   r   rz   Zimported_namesr.   )r   r>   ÚfirstÚposrV   r‚   rs   r   r   r   Úvisit_FromCImportStatNode  s    




z+DeclarationWriter.visit_FromCImportStatNodec                 C   s   |   |j¡ d S r   rU   r=   r   r   r   Úvisit_NameNode  s    z DeclarationWriter.visit_NameNodec                 C   s   |   |j¡ d S r   ©r   rx   r=   r   r   r   Úvisit_IntNode  s    zDeclarationWriter.visit_IntNodec                 C   s   |   d¡ d S ©NÚNone©r   r=   r   r   r   Úvisit_NoneNode"  s    z DeclarationWriter.visit_NoneNodec                 C   s$   |   d¡ |  |j¡ |   d¡ d S )Nz(not rR   )r   r$   Úoperandr=   r   r   r   Úvisit_NotNode%  s    
zDeclarationWriter.visit_NotNodec                 C   s"   |   d¡ |  |j¡ |  ¡  d S )Nú@)r-   r$   r|   r.   r=   r   r   r   Úvisit_DecoratorNode*  s    
z%DeclarationWriter.visit_DecoratorNodec                 C   s,   |   |j¡ |  d|j ¡ |   |j¡ d S )Nú %s )r$   Úoperand1r   ÚoperatorÚoperand2r=   r   r   r   Úvisit_BinopNode/  s    z!DeclarationWriter.visit_BinopNodec                 C   s    |   |j¡ |  d|j ¡ d S ©Nz.%s©r$   Úobjr   rm   r=   r   r   r   Úvisit_AttributeNode4  s    z%DeclarationWriter.visit_AttributeNodec                 C   s   |   t|jƒ¡ d S r   ©r   Ústrrx   r=   r   r   r   Úvisit_BoolNode8  s    z DeclarationWriter.visit_BoolNodec                 C   s.   |j }|jd ur| |j¡}|  t|ƒ¡ d S r   )rx   ÚencodingÚencoder   Úrepr)r   r>   rx   r   r   r   Úvisit_StringNode<  s    
z"DeclarationWriter.visit_StringNodec                 C   s   |   d¡ |  ¡  d S )Nrh   r/   r=   r   r   r   Úvisit_PassStatNodeB  s    
z$DeclarationWriter.visit_PassStatNode)N)r	   )r	   )F)2r   r   r   r,   r   r'   r*   r+   r-   r   r   r.   r0   r9   r?   rA   rB   rE   rH   rJ   rO   rT   rW   rY   r\   r^   rb   re   rn   rt   rv   rw   ry   r}   r~   r   r€   rƒ   r†   r‡   r‰   r   r   r‘   r–   rš   r   r¡   r¢   Ú__classcell__r   r   r!   r   r      s^   	





		r   c                   @   s¤   e 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 )(Ú
CodeWriterc                 C   s6   |   ¡  |  |j¡ |  d¡ |  |j¡ |  ¡  d S ©Nr2   )r-   r$   Úlhsr   Úrhsr.   r=   r   r   r   Úvisit_SingleAssignmentNodeH  s
    
z%CodeWriter.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_CascadedAssignmentNodeO  s    

z'CodeWriter.visit_CascadedAssignmentNodec                 C   s4   |   d¡ |  |jj¡ |js(|  d¡ |  ¡  d S )Nzprint ú,)r-   r9   Z	arg_tuplerS   Zappend_newliner   r.   r=   r   r   r   Úvisit_PrintStatNodeW  s
    

zCodeWriter.visit_PrintStatNodec                 C   sˆ   |   d¡ |  |j¡ |  d¡ |  |jj¡ |  d¡ |  ¡  |  |j¡ |  	¡  |j
d ur„|  d¡ |  ¡  |  |j
¡ |  	¡  d S )Nzfor ú in rg   úelse:)r-   r$   Útargetr   ÚiteratorÚsequencer.   r*   rC   r+   Úelse_clauser0   r=   r   r   r   Úvisit_ForInStatNode^  s    




zCodeWriter.visit_ForInStatNodec                 C   sÌ   |   d¡ |  |jd j¡ |  d¡ |  ¡  |  |jd j¡ |  ¡  |jdd … D ]@}|   d¡ |  |j¡ |  d¡ |  ¡  |  |j¡ |  ¡  qV|jd urÈ|  	d¡ |  ¡  |  |j¡ |  ¡  d S )Nzif r   rg   r   zelif r­   )
r-   r$   Ú
if_clausesÚ	conditionr.   r*   rC   r+   r±   r0   )r   r>   Zclauser   r   r   Úvisit_IfStatNodem  s$    






zCodeWriter.visit_IfStatNodec                 C   s   |   |j¡ d S r   )r9   rS   r=   r   r   r   Úvisit_SequenceNodeƒ  s    zCodeWriter.visit_SequenceNodec                 C   s0   |   |j¡ |  d¡ |  |j¡ |  d¡ d S rP   ©r$   Úfunctionr   r9   rS   r=   r   r   r   Úvisit_SimpleCallNode†  s    
zCodeWriter.visit_SimpleCallNodec                 C   s´   |   |j¡ |  d¡ |j}t|tƒr4|   |j¡ n|  |j¡ |j	r¦t|j	t
ƒržt|j	jƒD ]<\}\}}|dkr||  d¡ |   |¡ |  d¡ |   |¡ q^ntdƒ‚|  d¡ d S )NrQ   r   r3   ú=zNot implemented yetrR   )r$   r¸   r   r_   Ú
isinstanceÚAsTupleNodeÚargr9   rS   r`   ÚDictNodeÚ	enumeratera   Ú	Exception)r   r>   ZposargÚirV   rx   r   r   r   Úvisit_GeneralCallNodeŒ  s     




z CodeWriter.visit_GeneralCallNodec                 C   s    |   ¡  |  |j¡ |  ¡  d S r   )r-   r$   Úexprr.   r=   r   r   r   Úvisit_ExprStatNode   s    zCodeWriter.visit_ExprStatNodec                 C   s<   |   ¡  |  |j¡ |  d|j ¡ |  |j¡ |  ¡  d S )Nz %s= )r-   r$   r¦   r   r”   r§   r.   r=   r   r   r   Úvisit_InPlaceAssignmentNode¥  s
    z&CodeWriter.visit_InPlaceAssignmentNodec                 C   sh   |   ¡  |  d¡ |  |j¡ |jd ur>|  d¡ |  |j¡ |  d¡ |  ¡  |  |j¡ |  ¡  d S )Nzwith r   rg   )	r-   r   r$   Úmanagerr®   r.   r*   rC   r+   r=   r   r   r   Úvisit_WithStatNode¬  s    



zCodeWriter.visit_WithStatNodec                 C   sP   |   d¡ |  ¡  |  |j¡ |  ¡  |   d¡ |  ¡  |  |j¡ |  ¡  d S )Nútry:zfinally:)r0   r*   r$   rC   r+   Zfinally_clauser=   r   r   r   Úvisit_TryFinallyStatNode¸  s    

z#CodeWriter.visit_TryFinallyStatNodec                 C   sV   |   d¡ |  ¡  |  |j¡ |  ¡  |jD ]}|  |¡ q,|jd urR|  |j¡ d S )NrÈ   )r0   r*   r$   rC   r+   Zexcept_clausesr±   )r   r>   Úxr   r   r   Úvisit_TryExceptStatNodeÂ  s    


z"CodeWriter.visit_TryExceptStatNodec                 C   st   |   d¡ |jd ur*|  d¡ |  |j¡ |jd urJ|  d¡ |  |j¡ |  d¡ |  ¡  |  |j¡ |  ¡  d S )NÚexceptrd   r3   rg   )	r-   Úpatternr   r$   r®   r.   r*   rC   r+   r=   r   r   r   Úvisit_ExceptClauseNodeÌ  s    





z!CodeWriter.visit_ExceptClauseNodec                 C   s"   |   d¡ |  |j¡ |  ¡  d S )Nzreturn )r-   r$   rx   r.   r=   r   r   r   Úvisit_ReturnStatNodeÙ  s    
zCodeWriter.visit_ReturnStatNodec                 C   s   |   d¡ d S )NÚraise)r0   r=   r   r   r   Úvisit_ReraiseStatNodeÞ  s    z CodeWriter.visit_ReraiseStatNodec                 C   s   |   d|jj ¡ d S )Nz(import %s))r   rz   rx   r=   r   r   r   Úvisit_ImportNodeá  s    zCodeWriter.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$   rC   )r   r>   ÚidxÚhandler   r   r   Úvisit_TempsBlockNodeä  s    

zCodeWriter.visit_TempsBlockNodec                 C   s   |   | j|j ¡ d S r   )r   r   rÔ   r=   r   r   r   Úvisit_TempRefNodeñ  s    zCodeWriter.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¤   F  s&   

r¤   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú	PxdWriterc                 C   s   t d |  |¡j¡ƒ |S )NÚ
)Úprintru   r'   r
   r=   r   r   r   Ú__call__ö  s    zPxdWriter.__call__c                 C   sj   d|j v rd S |jr |  d¡ n
|  d¡ |jdkrJ|  |j¡ |  d¡ |jrZ|  d¡ |  |j¡ d S )NÚinlinezcpdef rc   Úprivaterd   zapi )Ú	modifiersZoverridabler-   rq   r   Úapir$   r[   r=   r   r   r   Úvisit_CFuncDefNodeú  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Ú   rß   rà   r   r   r   r   r×   õ  s   r×   c                       s¼  e Zd Zdh‡ 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didd„Zdd„ Zdd „ Zd!d"„ Zdjd$d%„Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d0d1d1d1d2œZd3d4d5d5d5d5d5d5d5d5d5d5d6d7d8d9d9d:d:d;d;d;d;d;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&dVdW„ Z'dXdY„ Z(dZd[„ Z)d\d]„ Z*dkd^d_„Z+d`da„ Z,dbdc„ Z-ddde„ Z.dfdg„ Z/‡  Z0S )lÚExpressionWriterNc                    s,   t t| ƒ ¡  |d u 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   Úendswithr4   r   r   r   r   Úremove  s    zExpressionWriter.removec                 C   sD   t |ƒdkr@|d d… D ]}|  |¡ |  d¡ q|  |d ¡ d S )Nr   r1   r3   )r4   r$   r   )r   r6   r8   r   r   r   r9      s
    
z%ExpressionWriter.comma_separated_listc                 C   s   t d| ƒ‚d S r:   r;   r=   r   r   r   r?   '  s    zExpressionWriter.visit_Nodec                 C   s   |   |j¡ d S r   rU   r=   r   r   r   r‡   *  s    zExpressionWriter.visit_NameNodec                 C   s   |   d¡ d S rŠ   rŒ   r=   r   r   r   r   -  s    zExpressionWriter.visit_NoneNodec                 C   s   |   d¡ d S )Nz...rŒ   r=   r   r   r   Úvisit_EllipsisNode0  s    z#ExpressionWriter.visit_EllipsisNodec                 C   s   |   t|jƒ¡ d S r   r›   r=   r   r   r   r   3  s    zExpressionWriter.visit_BoolNodec                 C   s   |   t|jƒ¡ d S r   r›   r=   r   r   r   Úvisit_ConstNode6  s    z ExpressionWriter.visit_ConstNodec                 C   s   |   |j¡ |   d¡ d S )NÚjrˆ   r=   r   r   r   Úvisit_ImagNode9  s    zExpressionWriter.visit_ImagNoder	   c                 C   s8   t |jƒ}|d dv r"|dd … }|  d||f ¡ d S )Nr   Zubr   z%s%s)r    rx   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_BytesNodeC  s    z ExpressionWriter.visit_BytesNodec                 C   s   |   |¡ d S r   rì   r=   r   r   r   r¡   F  s    z!ExpressionWriter.visit_StringNodec                 C   s   |   |d¡ d S )NÚurì   r=   r   r   r   Úvisit_UnicodeNodeI  s    z"ExpressionWriter.visit_UnicodeNode©r	   r	   c                 C   s2   |\}}|  ¡ }|  |¡ |  |¡ |  |¡ d S r   )Úsubexpr_nodesr   r9   )r   r>   ÚparensÚ
open_parenÚclose_parenr6   r   r   r   Úemit_sequenceL  s
    

zExpressionWriter.emit_sequencec                 C   s   |   |d¡ d S )Nú[]©rõ   r=   r   r   r   Úvisit_ListNodeS  s    zExpressionWriter.visit_ListNodec                 C   s   |   |d¡ d S )Nú()r÷   r=   r   r   r   Úvisit_TupleNodeV  s    z ExpressionWriter.visit_TupleNodec                 C   s,   t | ¡ ƒdkr|  |d¡ n
|  d¡ d S )Nr   ú{}zset())r4   rñ   rõ   r   r=   r   r   r   Úvisit_SetNodeY  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_DictItemNodeb  s    
z#ExpressionWriter.visit_DictItemNodeé   é   )Únotú!ú+ú-ú~r   é   é   é   é   é   é   é	   é
   é   )ÚorÚandÚinZnot_inÚisÚis_notú<z<=ú>z>=z!=z==ú|ú^rI   z<<z>>r  r  r   r   ú/z//ú%ú**c                 C   s,   | j d }||kr|  d¡ | j  |¡ d S )Nr1   rQ   )râ   r   r   )r   Únew_precÚold_precr   r   r   Úoperator_enterz  s    

zExpressionWriter.operator_enterc                 C   s2   | j dd … \}}||kr$|  d¡ | j  ¡  d S )NéþÿÿÿrR   )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$   rŽ   r"  ©r   r>   ÚopÚprecr   r   r   r   †  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_UnopNodeŽ  s    

zExpressionWriter.visit_UnopNodec                 C   sX   |j }| j |d¡}|  |¡ |  |j¡ |  d| dd¡ ¡ |  |j¡ |  	¡  d S )Nr   r’   Ú_rd   )
r”   Úbinop_precedenceÚgetr  r$   r“   r   Úreplacer•   r"  r$  r   r   r   r–   –  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   sJ   |   |j¡ |  d¡ t|jtƒr0|  |j¡ n|   |j¡ |  d¡ d S rK   )r$   rG   r   r»   ÚindexÚ	TupleNoderõ   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 )NrL   rg   rM   )r$   rG   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   )r2  Zis_noner$   r   r3  Ú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 r—   r˜   r=   r   r   r   rš   Ì  s    z$ExpressionWriter.visit_AttributeNodec                 C   s0   |   |j¡ |  d¡ |  |j¡ |  d¡ d S rP   r·   r=   r   r   r   r¹   Ð  s    
z%ExpressionWriter.visit_SimpleCallNodec                 C   s¢   |d u rd S t |tƒr0|  |j¡ |  |j¡ nnt |tƒr^| ¡ D ]}|  |¡ |  d¡ qBn@t |t	ƒrŠ|  d¡ |  |j
¡ |  d¡ n|  |¡ |  d¡ d S )Nr3   r   )r»   ZAddNodeÚemit_pos_argsr“   r•   r0  rñ   r$   r   r¼   r½   ©r   r>   rÃ   r   r   r   r;  Ö  s    





zExpressionWriter.emit_pos_argsc                 C   s”   |d u 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=r3   r  )	r»   ZMergedDictNoderñ   Úemit_kwd_argsr¾   r   rÿ   rx   r$   r<  r   r   r   r=  è  s    



zExpressionWriter.emit_kwd_argsc                 C   sF   |   |j¡ |  d¡ |  |j¡ |  |j¡ |  d¡ |  d¡ d S )NrQ   r3   rR   )r$   r¸   r   r;  r_   r=  r`   rä   r=   r   r   r   rÂ   ø  s    

z&ExpressionWriter.visit_GeneralCallNodec                 C   sj   |\}}|   |¡ |  |¡ |   d¡ |  |¡ |   d¡ |  |¡ |r\|   d¡ |  |¡ |   |¡ d S )Nz for r¬   r8  )r   r$   )r   rC   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ÚlooprC   r®   r¯   r°   Úhasattrr³   r´   r>  )r   r>   Ztpmaprò   rC   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ù   )rE  rC   r®   r¯   r°   rF  r³   r´   rÃ   r½   r>  )r   r>   rC   r®   r°   r´   r   r   r   Úvisit_GeneratorExpressionNode$  s    


z.ExpressionWriter.visit_GeneratorExpressionNode)N)r	   )rð   )rð   )1r   r   r   r   r'   r   rä   r9   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.  r1  r5  r7  r:  rš   r¹   r;  r=  rÂ   r>  r?  r@  rG  rH  r£   r   r   r!   r   rá     st   

þ
ô		

 þ
rá   N)Ú__doc__Ú
__future__r   r   ZCompiler.Visitorr   ZCompiler.ExprNodesÚobjectr   r   r¤   r×   rá   r   r   r   r   Ú<module>   s     ) 0