Ñò
#8Zc           @   sN  d  Z  d d k l Z d d k l Z l Z l Z l Z l Z d d k	 l
 Z
 d d k Z d d k Z d Z d d d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d d „  ƒ  YZ d „  Z e d j o4d d k Z d d k l Z l Z d d k Z d „  Z xúe i d D]çZ e GHe e ƒ Z e i ƒ  Z  e i! ƒ  e i e  e d ƒ Z" e e" ƒ Z# e e ƒ Z$ e ƒ  Z% e e$ e% ƒ e% i& e$ i ƒ  Z' e e# e' ƒ p1 Hd Ge GHe( e# ƒ GHe( e' ƒ GHe i) d ƒ n h  Z* e* i+ e% i& ƒ e* e$ =e* i, ƒ  Z& [* xô e" i- ƒ  D]æ Z% e% i. ƒ  oÓ g  Z/ e& D]' Z0 e0 i1 e% i2 ƒ  j o e/ e0 qvqv[/ Z3 e4 e3 ƒ d j o d Ge% i2 ƒ  GHq>e e e% i5 ƒ  ƒ e3 d i ƒ  ƒ pH e% i2 ƒ  GHe( e e% i5 ƒ  ƒ ƒ GHe( e3 d i ƒ  ƒ GHe i) d ƒ q>qXqXWq[Wn d S(    s   Module symbol-table generatoriÿÿÿÿ(   t   ast(   t   SC_LOCALt	   SC_GLOBALt   SC_FREEt   SC_CELLt
   SC_UNKNOWN(   t   mangleNi   t   Scopec           B   s¤   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sÁ   | |  _  | |  _ h  |  _ h  |  _ h  |  _ h  |  _ h  |  _ h  |  _ g  |  _ d  |  _
 d  |  _ d  |  _ | d  j	 oD xA t t | ƒ ƒ D]) } | | d j o | | |  _ PqŒ qŒ Wn d  S(   Nt   _(   t   namet   modulet   defst   usest   globalst   paramst   freest   cellst   childrent   Nonet   nestedt	   generatort   klasst   ranget   len(   t   selfR	   R
   R   t   i(    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   __init__   s$    												 c         C   s   d |  i  i |  i f S(   Ns   <%s: %s>(   t	   __class__t   __name__R	   (   R   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   __repr__$   s    c         C   s%   |  i  d  j o | St | |  i  ƒ S(   N(   R   R   R   (   R   R	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR   '   s    c         C   s   d |  i  |  i | ƒ <d  S(   Ni   (   R   R   (   R   R	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   add_def,   s    c         C   s   d |  i  |  i | ƒ <d  S(   Ni   (   R   R   (   R   R	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   add_use/   s    c         C   s~   |  i  | ƒ } | |  i j p | |  i j o n | |  i j o t d | |  i f ‚ n d |  i | <|  i i | ƒ d  S(   Ns    %s in %s is global and parameteri   (	   R   R   R   R   t   SyntaxErrorR	   R   R
   R   (   R   R	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt
   add_global2   s     c         C   s-   |  i  | ƒ } d |  i | <d |  i | <d  S(   Ni   (   R   R   R   (   R   R	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt	   add_param<   s    c         C   s@   h  } | i  |  i ƒ | i  |  i ƒ | i  |  i ƒ | i ƒ  S(   N(   t   updateR   R   R   t   keys(   R   t   d(    (    s&   /usr/lib/python2.6/compiler/symbols.pyt	   get_namesA   s
    c         C   s   |  i  i | ƒ d  S(   N(   R   t   append(   R   t   child(    (    s&   /usr/lib/python2.6/compiler/symbols.pyt	   add_childH   s    c         C   s   |  i  S(   N(   R   (   R   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   get_childrenK   s    c         C   s™   t  i |  i I|  i o d p d IJt  i d I|  i IJt  i d I|  i IJt  i d I|  i IJt  i d I|  i IJt  i d I|  i IJd  S(   NR   t    s
   	globals: s   	cells: s   	defs: s   	uses: s   	frees:(	   t   syst   stderrR	   R   R   R   R   R   R   (   R   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   DEBUGN   s    'c         C   s…   | |  i  j o t S| |  i j o t S| |  i j o t S|  i o% | |  i j p | |  i j o t	 S|  i o t
 St Sd S(   sb   Return scope of name.

        The scope of a name could be LOCAL, GLOBAL, FREE, or CELL.
        N(   R   R   R   R   R   R   R   R   R   R   R   (   R   R	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt
   check_nameV   s    *
c         C   sw   |  i  p d Sh  } | i |  i ƒ xE |  i i ƒ  D]4 } | |  i j o | |  i j o d | | <q5 q5 W| i ƒ  S(   Ni   (    (   R   R#   R   R   R$   R   R   (   R   t   freeR	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   get_free_varsh   s    
  c         C   sQ   xJ |  i  D]? } | i ƒ  } |  i | ƒ } x | D] } | i | ƒ q2 Wq
 Wd  S(   N(   R   R1   t	   add_freest   force_global(   R   R(   R   R   R	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   handle_childrenr   s    
  c         C   sj   d |  i  | <| |  i j o |  i | =n x8 |  i D]- } | i | ƒ t j o | i | ƒ q5 q5 Wd S(   sÞ  Force name to be global in scope.

        Some child of the current node had a free reference to name.
        When the child was processed, it was labelled a free
        variable.  Now that all its enclosing scope have been
        processed, the name is known to be a global or builtin.  So
        walk back down the child chain and set the name to be global
        rather than free.

        Be careful to stop if a child does not think the name is
        free.
        i   N(   R   R   R   R/   R   R3   (   R   R	   R(   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR3   y   s    
 c         C   s  g  } x| D]} |  i  | ƒ } |  i o© | t j p | t j p t |  t ƒ o d |  i | <q| t j o | i | ƒ qt |  t	 ƒ o | t
 j o d |  i | <q| t j o | i | ƒ qq | t
 j o d |  i | <q | t j o | i | ƒ q q W| S(   sþ   Process list of free vars from nested scope.

        Returns a list of names that are either 1) declared global in the
        parent or 2) undefined in a top-level parent.  In either case,
        the nested scope should treat them as globals.
        i   (   R/   R   R   R   t
   isinstancet
   ClassScopeR   R   R'   t   FunctionScopeR   R   R   (   R   t   namest   child_globalsR	   t   sc(    (    s&   /usr/lib/python2.6/compiler/symbols.pyR2      s&     
c         C   s   |  i  i ƒ  S(   N(   R   R$   (   R   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   get_cell_vars¨   s    N(   R   t
   __module__R   R   R   R   R   R   R!   R"   R&   R)   R*   R.   R/   R1   R4   R3   R2   R;   (    (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR      s"   					
							
			t   ModuleScopec           B   s   e  Z e i Z d  „  Z RS(   c         C   s   |  i  d |  ƒ d  S(   Nt   global(   t   _ModuleScope__super_init(   R   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR   ®   s    (   R   R<   R   R   R?   (    (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR=   «   s   	R7   c           B   s   e  Z RS(    (   R   R<   (    (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR7   ±   s   t   GenExprScopec           B   s,   e  Z e i Z d  Z d d „ Z d „  Z RS(   i   c         C   s@   |  i  } |  i  d 7_  |  i d | | | ƒ |  i d ƒ d  S(   Ni   s   generator expression<%d>s   .0(   t   _GenExprScope__countert   _GenExprScope__super_initR"   (   R   R
   R   R   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR   ¹   s    	c         C   s   t  i |  ƒ } | S(   N(   R   R&   (   R   R$   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR&   ¿   s    N(   R   R<   R   R   RB   RA   R   R&   (    (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR@   ´   s   	t   LambdaScopec           B   s#   e  Z e i Z d  Z d d „ Z RS(   i   c         C   s3   |  i  } |  i  d 7_  |  i d | | | ƒ d  S(   Ni   s	   lambda.%d(   t   _LambdaScope__countert   _LambdaScope__super_init(   R   R
   R   R   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR   È   s    	N(   R   R<   R   R   RE   RD   R   (    (    (    s&   /usr/lib/python2.6/compiler/symbols.pyRC   Ã   s   	R6   c           B   s   e  Z e i Z d  „  Z RS(   c         C   s   |  i  | | | ƒ d  S(   N(   t   _ClassScope__super_init(   R   R	   R
   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR   Ð   s    (   R   R<   R   R   RF   (    (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR6   Í   s   	t   SymbolVisitorc           B   s  e  Z d  „  Z d „  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d d „ Z
 d	 „  Z d
 „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z d d „ Z d d „ Z d „  Z e i e i e i f Z d „  Z d „  Z RS(   c         C   s   h  |  _  d  |  _ d  S(   N(   t   scopesR   R   (   R   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyR   Ô   s    	c         C   s2   t  ƒ  } |  _ |  i | <|  i | i | ƒ d  S(   N(   R=   R
   RH   t   visitt   node(   R   RJ   t   scope(    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitModuleÚ   s    c         C   sÞ   | i  o |  i | i  | ƒ n | i | i ƒ x! | i D] } |  i | | ƒ q; Wt | i |  i |  i ƒ } | i p t	 | t ƒ o d | _ n | |  i
 | <|  i | | i ƒ |  i | i | ƒ |  i | | ƒ d  S(   Ni   (   t
   decoratorsRI   R   R	   t   defaultsR7   R
   R   R   R5   RH   t   _do_argst   argnamest   codet   handle_free_vars(   R   RJ   t   parentt   nRK   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitFunctionà   s    

 c         C   s€   t  |  i |  i ƒ } | i p  t | t ƒ p t | t  ƒ o d | _ n | |  i | <|  i | i | ƒ |  i	 | | ƒ d  S(   Ni   (
   R@   R
   R   R   R5   R7   RH   RI   RQ   RR   (   R   RJ   RS   RK   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitGenExprî   s    c         C   s;   x! | i  D] } |  i | | ƒ q
 W|  i | i | ƒ d  S(   N(   t   qualsRI   t   expr(   R   RJ   RK   t   genfor(    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitGenExprInnerù   s    
 c         C   sQ   |  i  | i | d ƒ |  i  | i | ƒ x! | i D] } |  i  | | ƒ q3 Wd  S(   Ni   (   RI   t   assignt   itert   ifs(   R   RJ   RK   t   if_(    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitGenExprForÿ   s
    
 c         C   s   |  i  | i | ƒ d  S(   N(   RI   t   test(   R   RJ   RK   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitGenExprIf  s    i    c         C   s¶   | p t  ‚ x! | i D] } |  i | | ƒ q Wt |  i |  i ƒ } | i p t | t ƒ o d | _ n | |  i	 | <|  i
 | | i ƒ |  i | i | ƒ |  i | | ƒ d  S(   Ni   (   t   AssertionErrorRN   RI   RC   R
   R   R   R5   R7   RH   RO   RP   RQ   RR   (   R   RJ   RS   R[   RT   RK   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitLambda  s    
 c         C   sL   xE | D]= } t  | ƒ t i j o |  i | | ƒ q | i | ƒ q Wd  S(   N(   t   typet   typest	   TupleTypeRO   R"   (   R   RK   t   argsR	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyRO     s
     c         C   s   | i  | ƒ | i ƒ  d  S(   N(   R)   R4   (   R   RK   RS   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyRR     s    c         C   sð   | i  | i ƒ x! | i D] } |  i | | ƒ q Wt | i |  i ƒ } | i p t | t ƒ o d | _ n | i	 d  j	 o | i  d ƒ n | i  d ƒ | |  i | <|  i } | i |  _ |  i | i | ƒ | |  _ |  i | | ƒ d  S(   Ni   t   __doc__R<   (   R   R	   t   basesRI   R6   R
   R   R5   R7   t   docR   RH   R   RQ   RR   (   R   RJ   RS   RT   RK   t   prev(    (    s&   /usr/lib/python2.6/compiler/symbols.pyt
   visitClass#  s     
 		c         C   s/   | o | i  | i ƒ n | i | i ƒ d  S(   N(   R   R	   R   (   R   RJ   RK   R[   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt	   visitName:  s    c         C   sa   |  i  | i | d ƒ |  i  | i | ƒ |  i  | i | ƒ | i o |  i  | i | ƒ n d  S(   Ni   (   RI   R[   t   listt   bodyt   else_(   R   RJ   RK   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitForB  s
    
c         C   sF   x? | i  D]4 \ } } | d j o q
 n | i | p | ƒ q
 Wd  S(   Nt   *(   R8   R   (   R   RJ   RK   R	   t   asname(    (    s&   /usr/lib/python2.6/compiler/symbols.pyt	   visitFromI  s
    
 c         C   s\   xU | i  D]J \ } } | i d ƒ } | d j o | |  } n | i | p | ƒ q
 Wd  S(   Nt   .iÿÿÿÿ(   R8   t   findR   (   R   RJ   RK   R	   Rs   R   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitImportO  s    
 c         C   s%   x | i  D] } | i | ƒ q
 Wd  S(   N(   R8   R!   (   R   RJ   RK   R	   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitGlobalV  s    
 c         C   s>   x$ | i  D] } |  i | | d ƒ q
 W|  i | i | ƒ d S(   s.  Propagate assignment flag down to child nodes.

        The Assign node doesn't itself contains the variables being
        assigned to.  Instead, the children in node.nodes are visited
        with the assign flag set to true.  When the names occur in
        those nodes, they are marked as defs.

        Some names that occur in an assignment target are not bound by
        the assignment, e.g. a name occurring inside a slice.  The
        visitor handles these nodes specially; they do not propagate
        the assign flag to their children.
        i   N(   t   nodesRI   RX   (   R   RJ   RK   RT   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitAssignZ  s    
 i   c         C   s   | i  | i ƒ d  S(   N(   R   R	   (   R   RJ   RK   R[   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitAssNamek  s    c         C   s   |  i  | i | d ƒ d  S(   Ni    (   RI   RX   (   R   RJ   RK   R[   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitAssAttrn  s    c         C   sA   |  i  | i | d ƒ x$ | i D] } |  i  | | d ƒ q  Wd  S(   Ni    (   RI   RX   t   subs(   R   RJ   RK   R[   RT   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitSubscriptq  s    
 c         C   sb   |  i  | i | d ƒ | i o |  i  | i | d ƒ n | i o |  i  | i | d ƒ n d  S(   Ni    (   RI   RX   t   lowert   upper(   R   RJ   RK   R[   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt
   visitSlicev  s
    

c         C   sZ   |  i  | i | ƒ t | i t i ƒ o |  i  | i | d ƒ n |  i  | i | ƒ d  S(   Ni   (   RI   RJ   R5   R    t   NameRX   (   R   RJ   RK   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitAugAssign}  s    c         C   s¤   x| | i  D]q \ } } t | t i ƒ o2 t | i ƒ |  i j o | i p q
 qW q[ n |  i | | ƒ |  i | | ƒ q
 W| i o |  i | i | ƒ n d  S(   N(	   t   testsR5   R    t   ConstRd   t   valuet   _const_typesRI   Rp   (   R   RJ   RK   R`   Ro   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   visitIf‰  s    
 

c         C   s    d | _  |  i | i | ƒ d  S(   Ni   (   R   RI   R†   (   R   RJ   RK   (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt
   visitYield–  s    	(    R   R<   R   RL   t   visitExpressionRU   RV   RZ   R_   Ra   Rc   RO   RR   Rl   Rm   Rq   Rt   Rw   Rx   Rz   R{   R|   R~   R   Rƒ   Re   t
   StringTypet   IntTypet	   FloatTypeR‡   Rˆ   R‰   (    (    (    s&   /usr/lib/python2.6/compiler/symbols.pyRG   Ó   s4   																
	c         C   s   t  |  ƒ t  | ƒ j S(   N(   t   sorted(   t   l1t   l2(    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   list_eqš  s    t   __main__(   t	   parseFilet   walkc         C   sj   g  } g  } |  i  ƒ  D] } | | i ƒ  q ~ D]1 } | i d ƒ p | i d ƒ p | | q2 q2 ~ S(   Ns   _[Ru   (   t   get_symbolst   get_namet
   startswith(   t   symst   _[1]t   _[2]t   s(    (    s&   /usr/lib/python2.6/compiler/symbols.pyR&   ¢  s    8i   t   exect   oopst   skippingi    (    (    (6   Rh   t   compilerR    t   compiler.constsR   R   R   R   R   t   compiler.miscR   Re   R,   t
   MANGLE_LENR   R=   R7   R@   RC   R6   RG   R‘   R   R“   R”   t   symtableR&   t   argvt   filet   opent   ft   readt   buft   closeR˜   t	   mod_namest   treeR›   RH   t   names2RŽ   t   exitR%   R#   t   valuesR•   t   is_namespaceR™   R:   R	   R–   t   lR   t   get_namespace(    (    (    s&   /usr/lib/python2.6/compiler/symbols.pyt   <module>   sn   (ž
Ç		 
		 *