a
    Ä38b]]  ã                   @   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   ú0lib/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   Z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ú&rE   r<   r   r   r   Úvisit_CReferenceDeclaratorNodeg   s    
z0DeclarationWriter.visit_CReferenceDeclaratorNodec                 C   s:   |   |j¡ |  d¡ |jd ur,|   |j¡ |  d¡ d S ©Nú[ú]©r$   rF   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 rJ   rM   r<   r   r   r   rN   r   s
    

c                 C   s0   |   |j¡ |  d¡ |  |j¡ |  d¡ d S ©Nú(ú))r$   rF   r   r8   Ú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   ZsignedZlongnessrU   r<   r   r   r   Úvisit_CSimpleBaseTypeNodeƒ   s    

z+DeclarationWriter.visit_CSimpleBaseTypeNodec                 C   s0   |   d¡ |  |j¡ |  |j¡ |   d¡ d S rO   )r   r$   Ú	base_typeÚ
declaratorr<   r   r   r   Úvisit_CComplexBaseTypeNode   s    
z,DeclarationWriter.visit_CComplexBaseTypeNodec                 C   s&   |   |j¡ |  d¡ |  |j¡ d S )NÚ.)r$   rX   r   rU   r<   r   r   r   Úvisit_CNestedBaseTypeNode“   s    
z+DeclarationWriter.visit_CNestedBaseTypeNodec                 C   s8   |   |j¡ |  d¡ |  |j|jj ¡ |  d¡ d S rJ   )r$   Zbase_type_noder   r8   Ú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)r6   )r,   r$   rX   r   r8   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 )Nrb   ú "%s"ú:Úpass)	r,   rU   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 ra   Zpubliczpublic zpacked )Ztypedef_flagÚ
visibilityZpackedÚkindrl   rj   )r   r=   rh   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]r2   z(%s)zcdef cppclass)Z	templatesÚjoinZbase_classesrl   rj   )r   r=   ri   r   r   r   Úvisit_CppClassNodeÄ   s    z$DeclarationWriter.visit_CppClassNodec                 C   s   |   |dd |j¡ d S )Nz	cdef enum)rl   r5   r<   r   r   r   Úvisit_CEnumDefNodeÌ   s    z$DeclarationWriter.visit_CEnumDefNodec                 C   sJ   |   |j¡ |jr"|  d|j ¡ |jr>|  d¡ |  |j¡ |  ¡  d S )Nrd   r1   )r,   rU   rg   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 rP   r[   rQ   re   )Úmodule_nameZ
decoratorsr$   r,   r   Ú
class_nameZbase_class_nameZbase_class_moduler-   r)   rB   r*   )r   r=   Ú	decoratorr   r   r   Úvisit_CClassDefNodeØ   s"    






z%DeclarationWriter.visit_CClassDefNodec                 C   s8   |   d¡ |  |j¡ |  d¡ |  |j¡ |  ¡  d S )Nrm   rb   )r,   r$   rX   r   rY   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,   rU   r8   rR   r-   r)   r$   rB   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 )Nrb   r1   )rX   rU   r$   r   rY   r4   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   rv   Ú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 TFr2   r}   )r,   r   rv   Zimported_namesr-   )r   r=   ÚfirstÚposrU   r~   ro   r   r   r   Úvisit_FromCImportStatNode  s    




z+DeclarationWriter.visit_FromCImportStatNodec                 C   s   |   |j¡ d S r   rT   r<   r   r   r   Úvisit_NameNode  s    z DeclarationWriter.visit_NameNodec                 C   s   |   |j¡ d S r   ©r   rt   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 rQ   )r   r$   Úoperandr<   r   r   r   Úvisit_NotNode%  s    
zDeclarationWriter.visit_NotNodec                 C   s"   |   d¡ |  |j¡ |  ¡  d S )Nú@)r,   r$   rx   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   rk   r<   r   r   r   Úvisit_AttributeNode4  s    z%DeclarationWriter.visit_AttributeNodec                 C   s   |   t|jƒ¡ d S r   ©r   Ústrrt   r<   r   r   r   Úvisit_BoolNode8  s    z DeclarationWriter.visit_BoolNodec                 C   s.   |j }|jd ur| |j¡}|  t|ƒ¡ d S r   )rt   ÚencodingÚencoder   Úrepr)r   r=   rt   r   r   r   Úvisit_StringNode<  s    
z"DeclarationWriter.visit_StringNodec                 C   s   |   d¡ |  ¡  d S )Nrf   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-   r/   r8   r>   r@   rA   rD   rG   rI   rN   rS   rV   rW   rZ   r\   r`   rc   rl   rp   rr   rs   ru   ry   rz   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 ©Nr1   )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,   r8   Z	arg_tuplerR   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 re   úelse:)r,   r$   Útargetr   ÚiteratorÚsequencer-   r)   rB   r*   Úelse_clauser/   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   re   r   zelif r©   )
r,   r$   Ú
if_clausesÚ	conditionr-   r)   rB   r*   r­   r/   )r   r=   Zclauser   r   r   Úvisit_IfStatNodem  s$    






zCodeWriter.visit_IfStatNodec                 C   s   |   |j¡ d S r   )r8   rR   r<   r   r   r   Úvisit_SequenceNodeƒ  s    zCodeWriter.visit_SequenceNodec                 C   s0   |   |j¡ |  d¡ |  |j¡ |  d¡ d S rO   ©r$   Úfunctionr   r8   rR   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 )NrP   r   r2   ú=zNot implemented yetrQ   )r$   r´   r   r]   Ú
isinstanceÚAsTupleNodeÚargr8   rR   r^   ÚDictNodeÚ	enumerater_   Ú	Exception)r   r=   ZposargÚirU   rt   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}   re   )	r,   r   r$   Zmanagerrª   r-   r)   rB   r*   r<   r   r   r   Úvisit_WithStatNode¬  s    



zCodeWriter.visit_WithStatNodec                 C   sP   |   d¡ |  ¡  |  |j¡ |  ¡  |   d¡ |  ¡  |  |j¡ |  ¡  d S )Nútry:zfinally:)r/   r)   r$   rB   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Ã   )r/   r)   r$   rB   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Úexceptrb   r2   re   )	r,   Úpatternr   r$   rª   r-   r)   rB   r*   r<   r   r   r   Úvisit_ExceptClauseNodeÌ  s    





z!CodeWriter.visit_ExceptClauseNodec                 C   s"   |   d¡ |  |j¡ |  ¡  d S )Nzreturn )r,   r$   rt   r-   r<   r   r   r   Úvisit_ReturnStatNodeÙ  s    
zCodeWriter.visit_ReturnStatNodec                 C   s   |   d¡ d S )NÚraise)r/   r<   r   r   r   Úvisit_ReraiseStatNodeÞ  s    z CodeWriter.visit_ReraiseStatNodec                 C   s   |   d|jj ¡ d S )Nz(import %s))r   rv   rt   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$   rB   )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Ú
)Úprintrq   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 )NZinlinezcpdef ra   Zprivaterb   zapi )Z	modifiersZoverridabler,   rn   r   Zapir$   rY   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   Úendswithr3   r   r   r   r   Úremove  s    zExpressionWriter.removec                 C   sD   t |ƒdkr@|d d… D ]}|  |¡ |  d¡ q|  |d ¡ d S )Nr   r0   r2   )r3   r$   r   )r   r5   r7   r   r   r   r8      s
    
z%ExpressionWriter.comma_separated_listc                 C   s   t d| ƒ‚d S r9   r:   r<   r   r   r   r>   '  s    zExpressionWriter.visit_Nodec                 C   s   |   |j¡ d S r   rT   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œ   rt   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   r8   )r   r=   ÚparensÚ
open_parenÚclose_parenr5   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())r3   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   rt   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==ú|ú^rH   z<<z>>rü   rý   r   rŒ   ú/z//ú%ú**c                 C   s,   | j d }||kr|  d¡ | j  |¡ d S )Nr0   rP   )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éþÿÿÿrQ   )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=   ÚopZ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Ž   Ú_rb   )
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 rJ   )r$   rF   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 )NrK   re   rL   )r$   rF   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 )Nre   )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 r“   r”   r<   r   r   r   r–   Ì  s    z$ExpressionWriter.visit_AttributeNodec                 C   s0   |   |j¡ |  d¡ |  |j¡ |  d¡ d S rO   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 )Nr2   r   )r·   ZAddNodeÚemit_pos_argsr   r‘   r&  rè   r$   r   r¸   r¹   ©r   r=   r¿   r   r   r   r1  Ö  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=r2   r  )	r·   ZMergedDictNoderè   Úemit_kwd_argsrº   r   rö   rt   r$   r2  r   r   r   r3  è  s    



zExpressionWriter.emit_kwd_argsc                 C   sF   |   |j¡ |  d¡ |  |j¡ |  |j¡ |  d¡ |  d¡ d S )NrP   r2   rQ   )r$   r´   r   r1  r]   r3  r^   rÛ   r<   r   r   r   r¾   ø  s    

z&ExpressionWriter.visit_GeneralCallNodec                 C   sj   |\}}|   |¡ |  |¡ |   d¡ |  |¡ |   d¡ |  |¡ |r\|   d¡ |  |¡ |   |¡ d S )Nz for r¨   r.  )r   r$   )r   rB   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ÚlooprB   rª   r«   r¬   Úhasattrr¯   r°   r4  )r   r=   Ztpmapré   rB   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;  rB   rª   r«   r¬   r<  r¯   r°   r¿   r¹   r4  )r   r=   rB   rª   r¬   r°   r   r   r   Úvisit_GeneratorExpressionNode$  s    


z.ExpressionWriter.visit_GeneratorExpressionNode)N)r	   )rç   )rç   )1r   r   r   r   r&   r   rÛ   r8   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  r–   rµ   r1  r3  r¾   r4  r5  r6  r=  r>  rŸ   r   r   r!   r   rØ     st   

þ
ô		

 þ
rØ   N)Ú__doc__Z
__future__r   r   ZCompiler.Visitorr   ZCompiler.ExprNodesÚobjectr   r   r    rÒ   rØ   r   r   r   r   Ú<module>   s     ) 0