
    -Phy                        d dl Z d dl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 dd	lm	Z	 d dl
Z
 e
j        eeeeeef          Z G d
 d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d          Zi ddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:j        Zd;d<d=d>d?j        Z G d@ dAe          Z G dB dCe          ZdD Z G dE dFe          ZdG Z dH Z! G dI dJe          Z"e#dKk    rd dl$Z$ e$j%                     dS dS )L    N   )	TypeSlots)Builtin)Nodes)	ExprNodes)Errors)
DebugFlags)Futurec                        e Zd ZdZ fdZd Zd Zd Zej	        d             Z
d Zej	        d             Zej	        d	             ZddZej	        d             Z xZS )TreeVisitora  
    Base class for writing visitors for a Cython tree, contains utilities for
    recursing such trees using visitors. Each node is
    expected to have a child_attrs iterable containing the names of attributes
    containing child nodes or lists of child nodes. Lists are not considered
    part of the tree structure (i.e. contained nodes are considered direct
    children of the parent node).

    visit_children visits each of the children of a given node (see the visit_children
    documentation). When recursing the tree using visit_children, an attribute
    access_path is maintained which gives information about the current location
    in the tree as a stack of tuples: (parent_node, attrname, index), representing
    the node, attribute and optional list index that was taken in each step in the path to
    the current node.

    Example:

    >>> class SampleNode(object):
    ...     child_attrs = ["head", "body"]
    ...     def __init__(self, value, head=None, body=None):
    ...         self.value = value
    ...         self.head = head
    ...         self.body = body
    ...     def __repr__(self): return "SampleNode(%s)" % self.value
    ...
    >>> tree = SampleNode(0, SampleNode(1), [SampleNode(2), SampleNode(3)])
    >>> class MyVisitor(TreeVisitor):
    ...     def visit_SampleNode(self, node):
    ...         print("in %s %s" % (node.value, self.access_path))
    ...         self.visitchildren(node)
    ...         print("out %s" % node.value)
    ...
    >>> MyVisitor().visit(tree)
    in 0 []
    in 1 [(SampleNode(0), 'head', None)]
    out 1
    in 2 [(SampleNode(0), 'body', 0)]
    out 2
    in 3 [(SampleNode(0), 'body', 1)]
    out 3
    out 0
    c                 d    t                                                       i | _        g | _        d S N)super__init__dispatch_tableaccess_path)self	__class__s    W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/Compiler/Visitor.pyr   zTreeVisitor.__init__D   s/         c                    t          |j        pg           g dz   }g }t          |dd           }|rc|d         }|r0dd l}|j                            |                                          }|                    |d|d         d|d                    t          |          }|D ]}||v r|	                    d          s|
                    d          r2	 t          ||          }	n# t          $ r Y Pw xY w|	|	dk    r]t          |	t                     rdt          |	          z  }	n%t          |	t                    st          |	          }	|                    |d	|	           |j        j        d
d                    |          dS )N)child_attrsposgil_messagecpp_messagesubexprsr   r   :r      _z[...]/%d = (z,
    ))listr   getattros.pathpathbasenameget_descriptionappenddir
startswithendswithAttributeError
isinstancelen
_PRINTABLEreprr   __name__join)
r   nodeignoredvaluesr   sourceosattribute_namesattrvalues
             r   	dump_nodezTreeVisitor.dump_nodeI   s   t'-2.. 2L 2L 2L LdE4(( 	AVF D))&*@*@*B*BCCMMAA?@@@d))# 	5 	5Dws## t}}S'9'9 d++!   }

E4(( $"SZZ/z22 $UMMtttUU34444>222INN64J4J4J4JKKs   C))
C65C6c                 z   dd l }|}g }t          |d          r|j        }|j                            d          }t          |t          j                  rN|j        }|j	        }|j
                            |j                  |j        f}	|                    |||	f           |}|j        }t          |d          ||fS )Nr   tb_framer   )r%   hasattrr>   f_localsgetr.   r   Nodef_codeco_namer&   r'   co_filenamef_linenor)   tb_next)
r   
stacktracer8   last_tracebacknodesframer4   codemethod_namer   s
             r   _find_node_pathzTreeVisitor._find_node_pathi   s    #j*-- 
	,'E>%%f--D$
++ ,|"lw''(899~'dK5666!+#+J j*-- 
	, &&r   c                 V   dg}| j         D ]d\  }}}t          ||          }|d}n||         }d|z  }|                    |j        j        d||d|                     |                     e|                     t          j                    d                   \  }}	|}
|	D ]C\  }}}|}
|                    d|d         |d         ||                     |          fz             Dt          j
        t          |
d	d           | j        j        d
                    |          ||          )N z[%d].r    r   zFile '%s', line %d, in %s: %sr   r   r   
)r   r$   r)   r   r2   r<   rN   sysexc_infor   CompilerCrashr3   )r   childetraceparent	attributeindexr4   rH   called_nodes	last_noderM   r   s                r   _raise_compiler_errorz!TreeVisitor._raise_compiler_errorz   sj   (,(8 		' 		'$FIu69--D}E{LL )))99eeet$$$& ' ' ' ' $(#7#7q8I#J#J 
L	&2 	D 	D"D+sILL8AAT^^D-A-A<C C D D D D"Iud++T^-DIIea- - 	-r   c                    t          |          }t          j        |          }|D ]!}t          | d|j        z   d           }||c S "t          t          |           |           | j        r^t          | j                   t          | j        d         d         j                   t          | j        d         d         j                   t          d| d|          )Nvisit_r   zVisitor z does not accept object: )
typeinspectgetmror$   r2   printr   r   __dict__RuntimeError)r   objclsmromro_clshandler_methods         r   find_handlerzTreeVisitor.find_handler   s     3iinS!! 	& 	&G$T8g6F+FMMN)%%%% * 	d4jj# 	4$"###$"2&q)-...$"2&q)2333ldddCCPQQQr   c                 ,    |                      |          S r   _visit)r   rh   s     r   visitzTreeVisitor.visit   s    {{3r   c                 |   	 	 | j         t          |                   }n<# t          $ r/ |                     |          }|| j         t          |          <   Y nw xY w ||          S # t          j        $ r  t          j        $ r  t          $ r.}t          j	        r | 
                    ||           Y d }~d S d }~ww xY wr   )r   rb   KeyErrorrm   r   CompileError
AbortError	Exceptionr	   debug_no_exception_interceptr^   )r   rh   rl   rW   s       r   rp   zTreeVisitor._visit   s   	/@!%!4T#YY!? @ @ @!%!2!23!7!71?#DII...@ ">#&&&" 	 	 	  	 	 	 	/ 	/ 	/6 &&sA.........	/s2    A% 6AA% AA% %(B;#B66B;c                     | j                             |||f           |                     |          }| j                                          |S r   )r   r)   rp   pop)r   rV   rY   attrnameidxresults         r   _visitchildzTreeVisitor._visitchild   sM     	3 7888U##r   Nc                 0    |                      |||          S r   )_visitchildrenr   rY   attrsexcludes       r   visitchildrenzTreeVisitor.visitchildren   s    ""65':::r   c                 X    dS i }j         D ]||vr	||v rt                    }|vt          |          t          u r fdt	          |          D             }n=                     |d          }t          |t                    rJ dd            ||<   |S )af  
        Visits the children of the given parent. If parent is None, returns
        immediately (returning None).

        The return value is a dictionary giving the results for each
        child (mapping the attribute name to either the return value
        or a list of return values (in the case of multiple children
        in an attribute)).
        Nc                 F    g | ]\  }}                     ||          S  )r}   ).0r{   xr:   rY   r   s      r   
<listcomp>z.TreeVisitor._visitchildren.<locals>.<listcomp>   s2    "i"i"ifcST4#3#3AvtS#I#I"i"i"ir   zCannot insert list here: z in )r   r$   rb   r#   	enumerater}   r.   )r   rY   r   r   r|   rV   childretvalr:   s   ``     @r   r   zTreeVisitor._visitchildren   s     >$$& 
	+ 
	+D T%6%6"twFD))E ;;$&&"i"i"i"i"i"iXabgXhXh"i"i"iKK"&"2"25&$"M"MK)+t<<rrreieieikqkq>rrrr*tr   NN)r2   
__module____qualname____doc__r   r<   rN   r^   cythonfinalrm   rq   rp   r}   r   r   __classcell__r   s   @r   r   r      s       ) )T    
L L L@' ' '"- - -, \R R \R       \/ / \/$ \  \; ; ; ; \  \    r   r   c                   p    e Zd ZdZd
dZej        d
d            Zej        d             ZddZ	d Z
d	 ZdS )VisitorTransforma  
    A tree transform is a base class for visitors that wants to do stream
    processing of the structure (rather than attributes etc.) of a tree.

    It implements __call__ to simply visit the argument node.

    It requires the visitor methods to return the nodes which should take
    the place of the visited node in the result tree (which can be the same
    or one or more replacement). Specifically, if the return value from
    a visitor method is:

    - [] or None; the visited node will be removed (set to None if an attribute and
    removed if in a list)
    - A single node; the visited node will be replaced by the returned node.
    - A list of nodes; the visited nodes will be replaced by all the nodes in the
    list. This will only work if the node was already a member of a list; if it
    was not, an exception will be raised. (Typically you want to ensure that you
    are within a StatListNode or similar before doing this.)
    Nc                 0    |                      |||          S r   _process_childrenr   s       r   r   zVisitorTransform.visitchildren   s    %%feW===r   c                     |                      |||          }|                                D ]A\  }}t          |          t          u r|                     |          }t          |||           B|S r   )r   itemsrb   r#   _flatten_listsetattr)r   rY   r   r   r|   r:   newnodes          r   r   z"VisitorTransform._process_children   st     $$VUG<<#\\^^ 	+ 	+MD'G}}$$,,W55FD'****r   c                     g }|D ]E}|At          |          t          u r|                    |           0|                    |           F|S r   )rb   r#   extendr)   )r   	orig_listnewlistr   s       r   r   zVisitorTransform._flatten_list  sY      	& 	&A}77d??NN1%%%%NN1%%%r   r   c                     t          ||          }|/|                     ||||          }||urt          |||           |}|S r   )r$   r}   r   )r   rY   r:   r{   rV   r4   s         r   
visitchildzVisitorTransform.visitchild  sW    %%##E64==D5  d+++Er   c                 0    |                      |           |S r   r   r   r4   s     r   recurse_to_childrenz$VisitorTransform.recurse_to_children      t$$$r   c                 ,    |                      |          S r   ro   )r   roots     r   __call__zVisitorTransform.__call__  s    {{4   r   r   )r   )r2   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s         &> > > > \   \ \	 	 \	     ! ! ! ! !r   r   c                   8     e Zd ZdZ fdZ fdZd Zd Z xZS )CythonTransformz
    Certain common conventions and utilities for Cython transforms.

     - Sets up the context of the pipeline in self.context
     - Tracks directives in effect in self.current_directives
    c                 V    t                                                       || _        d S r   )r   r   context)r   r   r   s     r   r   zCythonTransform.__init__)  s$    r   c                     ddl m } t          ||          r|j        | _        t	                                          |          S )Nr   )
ModuleNode)r   r.   
directivescurrent_directivesr   r   )r   r4   r   r   s      r   r   zCythonTransform.__call__-  sI    ******dJ'' 	6&*oD#ww%%%r   c                 d    | j         }|j        | _         |                     |           || _         |S r   )r   r   r   )r   r4   olds      r   visit_CompilerDirectivesNodez,CythonTransform.visit_CompilerDirectivesNode3  s5    %"&/t$$$"%r   c                 0    |                      |           |S r   r   r   s     r   
visit_NodezCythonTransform.visit_Node:  r   r   )	r2   r   r   r   r   r   r   r   r   r   s   @r   r   r   "  sy             & & & & &        r   r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )ScopeTrackingTransformc                 L    d| _         || _        |                     |           |S )Nmodule
scope_type
scope_noder   r   s     r   visit_ModuleNodez'ScopeTrackingTransform.visit_ModuleNodeD  s)    "t$$$r   c                     | j         | j        f}|| _         || _        |                     |           |\  | _         | _        |S r   r   )r   r4   r   prevs       r   visit_scopez"ScopeTrackingTransform.visit_scopeJ  sE    /$t$$$+/(r   c                 .    |                      |d          S )Ncclassr   r   s     r   visit_CClassDefNodez*ScopeTrackingTransform.visit_CClassDefNodeR      h///r   c                 .    |                      |d          S )Npyclassr   r   s     r   visit_PyClassDefNodez+ScopeTrackingTransform.visit_PyClassDefNodeU  s    i000r   c                 .    |                      |d          S )Nfunctionr   r   s     r   visit_FuncDefNodez(ScopeTrackingTransform.visit_FuncDefNodeX  s    j111r   c                 .    |                      |d          S )Nstructr   r   s     r   visit_CStructOrUnionDefNodez2ScopeTrackingTransform.visit_CStructOrUnionDefNode[  r   r   N)	r2   r   r   r   r   r   r   r   r   r   r   r   r   r   ?  sn        
    0 0 01 1 12 2 20 0 0 0 0r   r   c                   j     e Zd ZdZ f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 xZS )EnvTransformz@
    This transformation keeps a stack of the environments.
    c                     g | _         |                     ||j                   t                                          |          S r   )	env_stackenter_scopescoper   r   )r   r   r   s     r   r   zEnvTransform.__call__c  s:    tz***ww%%%r   c                 (    | j         d         d         S )Nra   r   r   r   s    r   current_envzEnvTransform.current_envh      ~b!!$$r   c                 (    | j         d         d         S )Nra   r   r   r   s    r   current_scope_nodezEnvTransform.current_scope_nodek  r   r   c                 N    |                                                                  S r   )r   global_scoper   s    r   r   zEnvTransform.global_scopen  s     !!..000r   c                 >    | j                             ||f           d S r   )r   r)   )r   r4   r   s      r   r   zEnvTransform.enter_scopeq  s"    tUm,,,,,r   c                 8    | j                                          d S r   )r   ry   r   s    r   
exit_scopezEnvTransform.exit_scopet  s    r   c                     |                      |           |                     ||j                   |                     |d |j                   |                                  |S )N)r   r   )visit_func_outer_attrsr   local_scoper   outer_attrsr   r   s     r   r   zEnvTransform.visit_FuncDefNodew  sb    ##D)))t/0004tT5EFFFr   c                 >    |                      ||j                   d S )N)r   )r   r   r   s     r   r   z#EnvTransform.visit_func_outer_attrs~  s$    4t'788888r   c                 0    |                      |           |S r   r   r   s     r   visit_GeneratorBodyDefNodez'EnvTransform.visit_GeneratorBodyDefNode  r   r   c                     |                      ||j                   |                     |           |                                  |S r   r   r   r   r   r   s     r   visit_ClassDefNodezEnvTransform.visit_ClassDefNode  C    tz***t$$$r   c                     |                      ||j                   |                     |           |                                  |S r   r   r   s     r   r   z(EnvTransform.visit_CStructOrUnionDefNode  r   r   c                     |j         rE|                     ||j                    |                     |           |                                  n|                     |           |S r   )
expr_scoper   r   r   r   s     r   visit_ScopedExprNodez!EnvTransform.visit_ScopedExprNode  sd    ? 	)T4?333""4(((OO""4(((r   c                 <   |j         rd |j        D             }|                     ||           |                     ||                                 j                   |                     |d           |                                  n|                     |           |S )Nc                     g | ]
}|d k    |S defaultr   )r   r:   s     r   r   z3EnvTransform.visit_CArgDeclNode.<locals>.<listcomp>  s"    LLLd$):K:KT:K:K:Kr   r   )r   r   r   r   r   outer_scoper   r   )r   r4   r   s      r   visit_CArgDeclNodezEnvTransform.visit_CArgDeclNode  s    < 	)LLd&6LLLE""4///T4#3#3#5#5#ABBBt\222OO""4(((r   )r2   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r   _  s         & & & & &
% % %% % %1 1 1- - -    9 9 9        
 
 
 
 
 
 
r   r   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )NodeRefCleanupMixinas  
    Clean up references to nodes that were replaced.

    NOTE: this implementation assumes that the replacement is
    done first, before hitting any further references during
    normal tree traversal.  This needs to be arranged by calling
    "self.visitchildren()" at a proper place in the transform
    and by ordering the "child_attrs" of nodes appropriately.
    c                 B     t                      j        |  i | _        d S r   )r   r   _replacements)r   argsr   s     r   r   zNodeRefCleanupMixin.__init__  s%    $r   c                     |j         }|| j        vr|                     |           | j                            ||          |_         |S r   )argr   r   rA   )r   r4   r   s      r   visit_CloneNodez#NodeRefCleanupMixin.visit_CloneNode  sJ    hd(((s###%))#s33r   c                     |j         }|	|| j        vr|                     |           |j         }| | j                            ||          |_         |S r   )
expressionr   r   rA   )r   r4   exprs      r   visit_ResultRefNodez'NodeRefCleanupMixin.visit_ResultRefNode  s[    <4t'999t$$$?D"044T4@@DOr   c                     || j         |<   |S r   )r   )r   r4   replacements      r   replacezNodeRefCleanupMixin.replace  s    #.4 r   )	r2   r   r   r   r   r   r  r  r   r   s   @r   r   r     so                            r   r   <__lt__z<=__le__z==__eq__z!=__ne__z>=__ge__>__gt__+__add__&__and__/__div__z//__floordiv__z<<
__lshift__%__mod__*__mul__|__or__z**__pow__z>>
__rshift__-__sub____xor____contains__)^in__not____inv____neg____pos__)not~r  r  c                   Z    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )MethodDispatcherTransforma  
    Base class for transformations that want to intercept on specific
    builtin functions or methods of builtin types, including special
    methods triggered by Python operators.  Must run after declaration
    analysis when entries were assigned.

    Naming pattern for handler methods is as follows:

    * builtin functions: _handle_(general|simple|any)_function_NAME

    * builtin methods: _handle_(general|simple|any)_method_TYPENAME_METHODNAME
    c                 $   |                      |           |j        }|j        j        s|S |j        }t          |t          j                  s|S |j        }|rt          |t          j	                  s|S |j
        }|                     ||||          S r   )r   r   rb   is_pyobjectpositional_argsr.   r   	TupleNodekeyword_argsDictNoder   _dispatch_to_handler)r   r4   r   	arg_tupler1  r   s         r   visit_GeneralCallNodez/MethodDispatcherTransform.visit_GeneralCallNode  s    t$$$=}( 	K(	)Y%899 	K( 	
<9K L L 	K~((x|LLLr   c                     |                      |           |j        }|j        j        r+|j        }t          |t          j                  s|S |j        }n|j        }| 	                    |||d           S r   )
r   r   rb   r.  r4  r.   r   r0  r   r3  )r   r4   r   r4  r   s        r   visit_SimpleCallNodez.MethodDispatcherTransform.visit_SimpleCallNode  su    t$$$==$ 	Ii)<== >DD9D((xtDDDr   c                 h    |j         r|                     |           |S |                     |          S r   )cascader   _visit_binop_noder   s     r   visit_PrimaryCmpNodez.MethodDispatcherTransform.visit_PrimaryCmpNode  s9    < 	""4(((K%%d+++r   c                 ,    |                      |          S r   )r:  r   s     r   visit_BinopNodez)MethodDispatcherTransform.visit_BinopNode  s    %%d+++r   c           
      ^   |                      |           t          |j                  }|r|j        |j        }}|dk    r||}}n2|dk    r,t
          j        |                                 j        j	        v rd}|j
        }|j        r|j        }nd}|                     |d d||d ||gd           }|S )Nr"  r  __truediv__objectF)r   'find_special_method_for_binary_operatoroperatoroperand1operand2r
   divisionr   r   future_directivesrb   is_builtin_typename_dispatch_to_method_handler)r   r4   special_method_namerC  rD  obj_type	type_names          r   r:  z+MethodDispatcherTransform._visit_binop_node  s    t$$$EdmTT 	8!%hH"n44%-x($	11?d&6&6&8&8&@&RRR*7'}H' %$M		$	33#T5)dXx0$8 8D r   c           
          |                      |           t          |j                  }|r<|j        }|j        }|j        r|j        }nd}|                     |d d||d |gd           }|S )Nr@  F)r   &find_special_method_for_unary_operatorrB  operandrb   rG  rH  rI  )r   r4   rJ  rO  rK  rL  s         r   visit_UnopNodez(MethodDispatcherTransform.visit_UnopNode1  s    t$$$DT]SS 		-lG|H' %$M		$	33#T5)dWIt- -D r   c                     |                                 sd S |rdnd}t          | d| d| d           }|t          | d| d           }|S )Ngeneralsimple_handle_r   _handle_any_)isasciir$   )r   
match_name
has_kwargs	call_typehandlers        r   _find_handlerz'MethodDispatcherTransform._find_handlerB  so    !!## 	4!+9II	$ C9 C Cz C CTJJ?d$?:$?$?FFGr   c                 B   |j         d         }|j        }|j        r'|j        rt	          |j        j                  dk    r|S nF|j        r=|j        j        r1|j        j        r"t	          |j        j        j                  dk    r|S n|S |                     ||||          S )Nr   r   )	cf_staterhsis_nameentryr/   cf_assignmentsis_attributerh   r3  )r   r4   r   arg_listkwargs
assignmentr;   s          r   _delegate_to_assigned_valuez5MethodDispatcherTransform._delegate_to_assigned_valueM  s    &q)
= 		; #ek&@"A"AA"E"E #F  	EI$5 	9? c%)/*H&I&IA&M&M 'N K((%6+ + 	+r   c           
      J   |j         rL|j        s|S |j        }|j        p?||                                                                                     |j                  u }|s|j        r$|j        j        r| 	                    ||||          S |ri|j
        rb|j        r[|j        j        j        rJ|j        j        |d         j        u r1|                     |j        d d|j        j        j        ||||          S |S |                     d|j         |          }||                     ||j        |||          S |r |||||          S  ||||          S |j        r|j        }|j        j        r|j        }	n9|j        r0|j        r)|j        j        }|r|j        s|S |j        }	|dd          }n|S |	j        }
d}|
j        rE|
t0          j        u r'|	j         r |r|d         j        j        r|	j        }d }	d}n|
j        }|dk    rd}nd	}|                     ||	||||||          S |S )
Nr   T)self_argis_unbound_methodrL  r4   r   rc  rd  	function_r   Fstrunicoder@  )r_  r`  
is_builtinr   builtin_scopelookup_hererH  r]  	is_singlerf  
is_cmethodr   parent_typerG  rb   rI  r[  _handle_functionrb  rZ   r.  rh   r   as_variabler   	type_type)r   r4   r   rc  rd  r`  rm  function_handler	attr_namerh  rK  ri  rL  s                r   r3  z.MethodDispatcherTransform._dispatch_to_handler]  s    A	 > NE  W))++99;;GGVVV   $ :):)D :  ;;h&: : : \ 0 \U[ \U[E\El \{.(1+2BBB#??!J&+k&=&B!%8TZ  @  \  \ \ #11+HM++V 5  5',,T8=(HV\]]] B''h&III''hAAA" !	 *I}( 
#< x~  2  E$4  K9#ABB<}H %' %w000X5E0(0W_`aWbWgWs0 !)I#H(,%% (I%% )I$	338%6	h&2 2 2 Kr   c	           	      <   |                      d| d| |          }	|	H|t          j        v s|dv r|                      d| |          }	|	|                     |||||||          S ||gt	          |          z   }|r |	|||||          }
n |	||||          }
|
S )Nmethod_r   )__new__r   slot)r[  r   special_method_names_handle_methodr#   )r   rw  rh  ri  rL  r4   r   rc  rd  method_handlerr|   s              r   rI  z5MethodDispatcherTransform._dispatch_to_method_handler  s    ++-i--)--v7 7!Y;;; $<<<!%!3!3&9&&"0 "0%**)Y/9 9 9  zDNN2H 	=#^h*;VE EFF $^h*;= =Fr   c                     |S zFallback handlerr   )r   r4   function_namer   rc  rd  s         r   rs  z*MethodDispatcherTransform._handle_function  s    r   c                     |S r  r   )r   r4   rL  rw  r   rc  ri  rd  s           r   r}  z(MethodDispatcherTransform._handle_method  s	     r   N)r2   r   r   r   r5  r7  r;  r=  r:  rP  r[  rf  r3  rI  rs  r}  r   r   r   r,  r,    s         M M M
E 
E 
E, , ,, , ,  *  "	 	 	+ + + B B BH  0      r   r,  c                   .     e Zd ZdZ fdZd Zd Z xZS )RecursiveNodeReplacerzY
    Recursively replace all occurrences of a node in a subtree by
    another node.
    c                 f    t                                                       ||c| _        | _        d S r   )r   r   	orig_nodenew_node)r   r  r  r   s      r   r   zRecursiveNodeReplacer.__init__  s-    (18%r   c                 Z    || j         u r| j        S |j        | j         u r| j        |_        |S r   )r  r  r   r   s     r   r   z%RecursiveNodeReplacer.visit_CloneNode  s4    4>!!= 8t~%%}DHr   c                 P    |                      |           || j        u r| j        S |S r   )r   r  r  r   s     r   r   z RecursiveNodeReplacer.visit_Node  s0    t$$$4>!!= Kr   )r2   r   r   r   r   r   r   r   r   s   @r   r  r    s`         < < < < <        r   r  c                 <    t          ||          } ||            d S r   )r  )treeold_noder  
replace_ins       r   recursively_replace_noder    s'    &x::JJtr   c                   (     e Zd ZdZ fdZd Z xZS )
NodeFinderz2
    Find out if a node appears in a subtree.
    c                 d    t                                                       || _        d| _        d S )NF)r   r   r4   found)r   r4   r   s     r   r   zNodeFinder.__init__  s+    	


r   c                 j    | j         rd S || j        u r	d| _         d S |                     |d d            d S )NT)r  r4   r   r   s     r   r   zNodeFinder.visit_Node  sG    : 	2DTYDJJJdD11111r   )r2   r   r   r   r   r   r   r   s   @r   r  r    sQ             
2 2 2 2 2 2 2r   r  c                 X    t          |          }|                    |            |j        S r   )r  rq   r  )r  r4   finders      r   tree_containsr    s)    F
LL<r   c                 b    | \  }}}|t          |||           dS |t          ||          |<   dS )zkReplaces a node. ptr is of the form used on the access path stack
    (parent, attrname, listidx|None)
    N)r   r$   )ptrr;   rY   rz   listidxs        r   replace_noder    sG     !$FHg%(((((-2!!'***r   c                   F    e Zd ZdZddZd Zd ZddZd Zd Z	d	 Z
d
 ZdS )	PrintTreezPrints a representation of the tree to standard output.
    Subclass and override repr_of to provide more information
    about nodes. Nc                 |    t                               |            d| _        |||pd|pdf| _        d S d | _        d S )NrP   r   i   @)r   r   _indent_line_range)r   startends      r   r   zPrintTree.__init__  sP    T""" %
CL59D#Dr   c                 &    | xj         dz  c_         d S )Nz  r  r   s    r   indentzPrintTree.indent  s    r   c                 .    | j         d d         | _         d S )Nr  r   s    r   unindentzPrintTree.unindent  s    |CRC(r   c                 T    t          d|z             |                     |           |S )NzParse tree dump at phase '%s')re   rq   )r   r  phases      r   r   zPrintTree.__call__  s-    -5666

4r   c                     |                      |           |                                  |                     |           |                                  |S r   )_print_noder  r   r  r   s     r   r   zPrintTree.visit_Node  sI    4   r   c           	         |                      |           |                                  |j        d         }| j        &| j        d         |cxk    r| j        d         k    r7n n4t	          | j        ddd|                     |j                             |                                  |                     |j                   | 	                                 | 	                                 |S )Nr   r   - r   : )
r  r  r   r  re   r  repr_ofr   r   r  )r   r4   lines      r   r   zPrintTree.visit_CloneNode$  s    x{#t'7':d'Y'Y'Y'YdFVWXFY'Y'Y'Y'Y'Y$,,,t||DH7M7M7MNOOO48$$$r   c           	      N   |j         d         }| j        '| j        d         |cxk    r| j        d         k    rmn d S t          | j                  dk    rd}n| j        d         \  }}}|d||fz  }n|}t	          | j        d|d|                     |                     d S d S )Nr   r   z(root)ra   z%s[%d]r  r  )r   r  r/   r   re   r  r  )r   r4   r  rH  rY   r:   r{   s          r   r  zPrintTree._print_node0  s    x{#t'7':d'Y'Y'Y'YdFVWXFY'Y'Y'Y'Y'Y'Y4#$$))$($4R$8!c?#tSk1DDD$,,,dll46H6H6HIJJJJJ (Z'Yr   c           	      
   |dS |j         j        }t          |t          j                  r%|dt          |j                  d|j        dz  }nt          |t          j	                  r|d|j        z  z  }nt          |t          j
                  r/|d|                                dt          |dd           dz  }nAt          |t          j                  r%|dt          |j                  d	|j        dz  }nt          |t          j        t          j        f          r$|dt          |j                  d
|j        dz  }nt          |t          j                  r|j        }|dt          |          z  z  }n|j        rz|j        }|d                                         }d|v r|                    d          d         }d|v r|                    d          d         }|d|d|d         d|d         dz  }|S )Nz(none)z(type=z, name="z")z(name="%s")z(name="z	", type="rb   z, attribute="z, value=r"   z	(type=%s)r   r  ra   \z(pos=(r   r   r   z)))r   r2   r.   r   NameNoder1   rb   rH  r   DefNodeCFuncDefNodedeclared_namer$   AttributeNoderZ   	ConstNodePyConstNoder;   ExprNoder   r(   split)r   r4   r|   tr   r&   s         r   r  zPrintTree.repr_of=  s   <8^,F$	 233 Fd49ooootyyyQQD%-00 F/DI55D%"455 F&&(((('$*E*E*E*EG GD)"9:: F4	????DNNN[[D9#6	8M"NOO F4	????DJJJOOD)"455 
FI+Q// Fh1v--//$;;::c??2.D4<<::d++B/Dc!fffc!fffEEMr   r   r   )r2   r   r   r   r   r  r  r   r   r   r  r  r   r   r   r  r    s         $ $ $ $  ) ) )     
 
 
K K K    r   r  __main__)&rS   rc   rP   r   r   r   r   r   r	   r
   r   declaretuplebytesrk  intfloatcomplexr0   r   r   r   r   r   r   rA   rA  rN  r,  r  r  r  r  r  r  r2   doctesttestmodr   r   r   <module>r     s   


                                             V^EE3UG#DEE
F F F F F F F FR=! =! =! =! =!{ =! =! =!@    &   :0 0 0 0 0_ 0 0 0@E E E E E? E E EP               F+(+(+ 	(+ 	(	+
 	(+ (+ )+ )+ )+ 	.+ 	,+ )+ )+ (+ 	)+  	,!+" )#+$ 
'+ + +( ) (0 	* *
  'W W W W W W W Wt    ,   .  
2 2 2 2 2 2 2 2"  3 3 3W W W W W W W Wr zNNNGO r   