o
    í@Ëa˜  ã                   @   s<   d Z ddlmZ ddlZG dd„ deƒZG dd„ deƒZdS )z‰
LocalNameDeclarations gathers name of declarations local to a node.
LocalNodeDeclarations gathers node of declarations local to a node.
é    )ÚNodeAnalysisNc                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚLocalNodeDeclarationsa²  
    Gathers all local symbols from a function.

    It should not be use from outside a function, but can be used on a function
    (but in that case, parameters are not taken into account)

    >>> import gast as ast
    >>> from pythran import passmanager, backend
    >>> node = ast.parse('''
    ... def foo(a):
    ...     b = a + 1''')
    >>> pm = passmanager.PassManager("test")
    >>> [name.id for name in pm.gather(LocalNodeDeclarations, node)]
    ['b']
    >>> node = ast.parse('''
    ... for c in range(n):
    ...     b = a + 1''')
    >>> pm = passmanager.PassManager("test")
    >>> sorted([name.id for name in pm.gather(LocalNodeDeclarations, node)])
    ['b', 'c']
    c                    ó   t ƒ | _tt| ƒ ¡  dS ©z% Initialize empty set as the result. N)ÚsetÚresultÚsuperr   Ú__init__©Úself©Ú	__class__© úE/usr/lib/python3/dist-packages/pythran/analyses/local_declarations.pyr	   #   ó   zLocalNodeDeclarations.__init__c                 C   s"   t |jtjƒr| j |¡ dS dS )z3 Any node with Store context is a new declaration. N)Ú
isinstanceÚctxÚastÚStorer   Úadd©r   Znoder   r   r   Ú
visit_Name(   s   ÿz LocalNodeDeclarations.visit_Name)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   Ú__classcell__r   r   r   r   r      s    r   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )ÚLocalNameDeclarationsaF  
    Gathers all local identifiers from a node.

    >>> import gast as ast
    >>> from pythran import passmanager, backend
    >>> node = ast.parse('''
    ... def foo(a):
    ...     b = a + 1''')
    >>> pm = passmanager.PassManager("test")
    >>> sorted(pm.gather(LocalNameDeclarations, node))
    ['a', 'b', 'foo']
    c                    r   r   )r   r   r   r   r	   r
   r   r   r   r	   =   r   zLocalNameDeclarations.__init__c                 C   s*   t |jtjtjfƒr| j |j¡ dS dS )z; Any node with Store or Param context is a new identifier. N)r   r   r   r   ZParamr   r   Úidr   r   r   r   r   B   s   ÿz LocalNameDeclarations.visit_Namec                 C   s   | j  |j¡ |  |¡ dS )z) Function name is a possible identifier. N)r   r   ÚnameZgeneric_visitr   r   r   r   Úvisit_FunctionDefG   s   z'LocalNameDeclarations.visit_FunctionDef)r   r   r   r   r	   r   r    r   r   r   r   r   r   .   s
    r   )r   Zpythran.passmanagerr   Zgastr   r   r   r   r   r   r   Ú<module>   s
    #