o
    í@Ëa¹  ã                   @   s@   d Z ddlmZ ddlmZ G dd„ deƒZG dd„ deƒZdS )	z4 GlobalDeclarations gathers top-level declarations. é    )ÚModuleAnalysis)ÚDefUseChainsc                   @   s   e Zd Zdd„ ZdS )ÚSilentDefUseChainsc                 C   s   d S )N© )ÚselfÚnameÚnoder   r   úF/usr/lib/python3/dist-packages/pythran/analyses/global_declarations.pyÚunbound_identifier	   s   z%SilentDefUseChains.unbound_identifierN)Ú__name__Ú
__module__Ú__qualname__r
   r   r   r   r	   r      s    r   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚGlobalDeclarationsaò   Gather all kind of identifier defined at global scope.

    >>> import gast as ast
    >>> from pythran import passmanager
    >>> from pythran.analyses import GlobalDeclarations
    >>> node = ast.parse('''
    ... import math
    ... import math as maths
    ... from math import cos
    ... c = 12
    ... def foo(a):
    ...     b = a + 1''')
    >>> pm = passmanager.PassManager("test")
    >>> sorted(pm.gather(GlobalDeclarations, node).keys())
    ['c', 'cos', 'foo', 'math', 'maths']

    c                    s   t ƒ | _tt| ƒ ¡  dS )z3 Result is an identifier with matching definition. N)ÚdictÚresultÚsuperr   Ú__init__)r   ©Ú	__class__r   r	   r   !   s   zGlobalDeclarations.__init__c                 C   s*   t ƒ }| |¡ dd„ |j| D ƒ| _dS )z+ Import module define a new variable name. c                 S   s   i | ]}|  ¡ |j“qS r   )r   r   )Ú.0Údr   r   r	   Ú
<dictcomp>*   s    ÿz3GlobalDeclarations.visit_Module.<locals>.<dictcomp>N)r   ZvisitÚlocalsr   )r   r   Zducr   r   r	   Úvisit_Module&   s
   
ÿzGlobalDeclarations.visit_Module)r   r   r   Ú__doc__r   r   Ú__classcell__r   r   r   r	   r      s    r   N)r   Zpythran.passmanagerr   Zbenigetr   r   r   r   r   r   r	   Ú<module>   s
    