o
    í@ËaS	  ã                   @   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 )	z/
Ancestors computes the ancestors of each node
é    )ÚModuleAnalysis)Úpushpopc                       s,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )Ú	Ancestorszì
    Associate each node with the list of its ancestors

    Based on the tree view of the AST: each node has the Module as parent.
    The result of this analysis is a dictionary with nodes as key,
    and list of nodes as values.
    c                    s"   t ƒ | _tƒ | _tt| ƒ ¡  d S ©N)ÚdictÚresultÚlistÚcurrentÚsuperr   Ú__init__)Úself©Ú	__class__© ú</usr/lib/python3/dist-packages/pythran/analyses/ancestors.pyr      s   zAncestors.__init__c                    sR   t | jƒ| j|< t| j|ƒ tt| ƒ |¡ W d   ƒ d S 1 s"w   Y  d S r   )r   r	   r   r   r
   r   Úgeneric_visit©r   Únoder   r   r   r      s   "ÿzAncestors.generic_visit)Ú__name__Ú
__module__Ú__qualname__Ú__doc__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S )ÚAncestorsWithBodyc                 C   s   t |dƒr|  |j¡ d S d S )NÚmetadata)Úhasattrr   r   r   r   r   r   Úvisit_metadata   s   
ÿz AncestorsWithBody.visit_metadatac                 C   s^   t |ƒ}t| jƒ| j|< t| j|ƒ |D ]}|  |¡ qW d   ƒ d S 1 s(w   Y  d S r   )Útupler   r	   r   r   r   )r   ÚbodyZbody_as_tupleZstmtr   r   r   Ú
visit_body#   s   ÿ"ÿzAncestorsWithBody.visit_bodyc                 C   óp   t | jƒ| j|< t| j|ƒ  |  |j¡ |  |¡ |  |j¡ |  |j	¡ W d   ƒ d S 1 s1w   Y  d S r   ©
r   r	   r   r   r   Útestr   r   r   Úorelser   r   r   r   Úvisit_If*   ó   
"üzAncestorsWithBody.visit_Ifc                 C   r    r   r!   r   r   r   r   Úvisit_While2   r%   zAncestorsWithBody.visit_Whilec                 C   s|   t | jƒ| j|< t| j|ƒ& |  |j¡ |  |j¡ |  |¡ |  |j	¡ |  |j
¡ W d   ƒ d S 1 s7w   Y  d S r   )r   r	   r   r   r   ÚtargetÚiterr   r   r   r#   r   r   r   r   Ú	visit_For:   s   
"ûzAncestorsWithBody.visit_Forc                 C   s†   t | jƒ| j|< t| j|ƒ+ |  |¡ |  |j¡ |jD ]}|  |¡ q|  |j	¡ |  |j
¡ W d   ƒ d S 1 s<w   Y  d S r   )r   r	   r   r   r   r   r   Úhandlersr   r#   Ú	finalbody)r   r   Zhandlerr   r   r   Ú	visit_TryC   s   

"úzAncestorsWithBody.visit_TryN)	r   r   r   r   r   r$   r&   r)   r,   r   r   r   r   r      s    	r   N)r   Zpythran.passmanagerr   Zpythran.utilsr   r   r   r   r   r   r   Ú<module>   s
    