o
    @a                     @   sh   d 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G d	d
 d
eZdS )z3 ConstantExpressions gathers constant expression.      )Aliases)Globals)Locals)PureExpressions)FunctionIntr)NodeAnalysisNc                       s   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZeZdd Zdd Zdd Zdd Zdd ZeZeZdd Zdd Z  ZS ) ConstantExpressionszIdentify constant expressions.c                    s"   t  | _tt| tttt d S N)	setresultsuperr   __init__r   r   r   r   self	__class__ G/usr/lib/python3/dist-packages/pythran/analyses/constant_expressions.pyr      s   zConstantExpressions.__init__c                 C   s   | j | dS )NT)r   addr   noder   r   r   r      s   zConstantExpressions.addc                    "   t  fdd|jD o |S )Nc                       g | ]}  |qS r   visit.0xr   r   r   
<listcomp>       z4ConstantExpressions.visit_BoolOp.<locals>.<listcomp>)allvaluesr   r   r   r   r   visit_BoolOp      "z ConstantExpressions.visit_BoolOpc                    s,   t  fdd|j|jfD }|o |S )Nc                    r   r   r   r   r   r   r   r      r   z3ConstantExpressions.visit_BinOp.<locals>.<listcomp>)r    leftrightr   r   r   Zrecr   r   r   visit_BinOp      zConstantExpressions.visit_BinOpc                 C      |  |jo
| |S r	   )r   operandr   r   r   r   r   visit_UnaryOp!      z!ConstantExpressions.visit_UnaryOpc                    s0   t  fdd|j|j|jfD }|o |S )Nc                    r   r   r   r   r   r   r   r   %   r   z3ConstantExpressions.visit_IfExp.<locals>.<listcomp>)r    testbodyorelser   r&   r   r   r   visit_IfExp$   s   "zConstantExpressions.visit_IfExpc                    s.   t  fdd|jg|j D }|o |S )Nc                    r   r   r   r   r   r   r   r   )   r   z5ConstantExpressions.visit_Compare.<locals>.<listcomp>)r    r$   comparatorsr   r&   r   r   r   visit_Compare(       z!ConstantExpressions.visit_Comparec                    s.   t  fdd|j|jg D }|o |S )Nc                    r   r   r   r   r   r   r   r   -   r   z2ConstantExpressions.visit_Call.<locals>.<listcomp>)r    argsfuncr   r&   r   r   r   
visit_Call,   r3   zConstantExpressions.visit_Callc                    s>   t  fdd|j|jfD }t|jtjo|}|o |S )Nc                    r   r   r   r   r   r   r   r   3   r   z7ConstantExpressions.visit_Subscript.<locals>.<listcomp>)r    valueslice
isinstancectxastLoadr   r&   r   r   r   visit_Subscript2   s   z#ConstantExpressions.visit_Subscriptc                    s   |j v r@t|jtjsdS tj | dkrdS |jjvr!dS |jj| v r+dS dd  t	 fddj | D }|S dS )NF   c                 S   s   t | ttjtjfS r	   )r9   r   r;   ZFunctionDefalias)r   r   r   r   is_functionG   s   z3ConstantExpressions.visit_Name.<locals>.is_functionc                 3   s"    | ]}|j v o |V  qd S r	   )Zpure_expressions)r   r?   r@   r   r   r   	<genexpr>L   s    

z1ConstantExpressions.visit_Name.<locals>.<genexpr>)
aliasesr9   r:   r;   r<   lenidglobalslocalsr    )r   r   Zpure_funr   rA   r   
visit_Name7   s   
zConstantExpressions.visit_Namec                 C   s   t | o| |S r	   )r   Zaccess_pathZisconstr   r   r   r   r   visit_AttributeS   s   z#ConstantExpressions.visit_Attributec                    s,   t  fdd|j|j D }|o |S )Nc                    r   r   r   r   r   r   r   r   W   r   z2ConstantExpressions.visit_Dict.<locals>.<listcomp>)r    keysr!   r   r&   r   r   r   
visit_DictV   r(   zConstantExpressions.visit_Dictc                    r   )Nc                    r   r   r   r   r   r   r   r   [   r   z2ConstantExpressions.visit_List.<locals>.<listcomp>)r    eltsr   r   r   r   r   
visit_ListZ   r#   zConstantExpressions.visit_Listc                    s,   t  fdd|j|j|jfD o |S )Nc                    s   g | ]}|d u p  |qS r	   r   r   r   r   r   r   a   s    z3ConstantExpressions.visit_Slice.<locals>.<listcomp>)r    lowerupperstepr   r   r   r   r   visit_Slice`   s
   zConstantExpressions.visit_Slicec                 C   r)   r	   )r   r7   r   r   r   r   r   visit_Indexd   r,   zConstantExpressions.visit_Index)__name__
__module____qualname____doc__r   r   r"   r'   r+   r0   r2   r6   Zvisit_Constantr=   rH   rI   rK   rM   Zvisit_TupleZ	visit_SetrQ   rR   __classcell__r   r   r   r   r      s(    r   )rV   Zpythran.analyses.aliasesr   Z!pythran.analyses.globals_analysisr   Z pythran.analyses.locals_analysisr   Z!pythran.analyses.pure_expressionsr   Zpythran.intrinsicr   Zpythran.passmanagerr   Zgastr;   r   r   r   r   r   <module>   s    