o
    tBh                     @  sh   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZ G dd deZdS )    )annotations)
	Decorator
ExpressionFuncDefFuncItem
LambdaExpr
MemberExprMypyFileNameExpr
SymbolNodeVar)TraverserVisitor)Errorsc                      s   e Zd ZdZd- fd
dZd. fddZd/ddZd0ddZd1 fddZd2ddZ	d3d d!Z
d4d$d%Zd5d)d*Zd4d+d,Z  ZS )6PreBuildVisitorap  Mypy file AST visitor run before building the IR.

    This collects various things, including:

    * Determine relationships between nested functions and functions that
      contain nested functions
    * Find non-local variables (free variables)
    * Find property setters
    * Find decorators of functions

    The main IR build pass uses this information.
    errorsr   current_filer	   decorators_to_removedict[FuncDef, list[int]]returnNonec                   sL   t    i | _i | _g | _t | _i | _i | _i | _	|| _
|| _|| _d S N)super__init__free_variablessymbols_to_funcsfuncssetprop_settersencapsulating_funcsnested_funcsfuncs_to_decoratorsr   r   r   )selfr   r   r   	__class__ t/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypyc/irbuild/prebuildvisitor.pyr   !   s   

zPreBuildVisitor.__init__decr   c                   s   |j r@t|j d tr|j d jdkr| j|j n%|j  }|j| jv r:| j|j }t	|D ]}||= q0|s:d S || j
|j< t | d S )Nr   setter)
decorators
isinstancer   namer   addfunccopyr   reversedr    r   visit_decorator)r!   r&   decorators_to_store	to_removeir"   r$   r%   r/   K   s    
zPreBuildVisitor.visit_decoratorfdefr   c                 C     |  | d S r   
visit_func)r!   r3   r$   r$   r%   visit_func_deff   s   zPreBuildVisitor.visit_func_defexprr   c                 C  r4   r   r5   r!   r8   r$   r$   r%   visit_lambda_exprj      z!PreBuildVisitor.visit_lambda_exprr,   c                   sV   | j r| j| j d g | | j d | j|< | j | t | | j   d S N)r   r   
setdefaultappendr   r   r6   pop)r!   r,   r"   r$   r%   r6   m   s   zPreBuildVisitor.visit_funcr
   c                 C  s$   t |jttfr| |j d S d S r   )r)   noder   r   visit_symbol_noder9   r$   r$   r%   visit_name_expr~   s   zPreBuildVisitor.visit_name_exprvarr   c                 C  r4   r   )rB   )r!   rD   r$   r$   r%   	visit_var   r;   zPreBuildVisitor.visit_varsymbolr   c                 C  s   | j sd S || jv rB| j| }| | j d |r0| j d | j|< | j| j d t | d S | || j d r@| | d S d S | j d | j|< d S r<   )r   r   	is_parentr   r>   r   r+   add_free_variable)r!   rF   	orig_funcr$   r$   r%   rB      s   

 
z!PreBuildVisitor.visit_symbol_nodefitemchildboolc                 C  s0   || j v r| j | }||krdS | ||S dS )NTF)r   rG   )r!   rJ   rK   parentr$   r$   r%   rG      s   

zPreBuildVisitor.is_parentc                 C  s$   | j | }| j|t | d S r   )r   r   r>   r   r+   )r!   rF   r,   r$   r$   r%   rH      s   
z!PreBuildVisitor.add_free_variable)r   r   r   r	   r   r   r   r   )r&   r   r   r   )r3   r   r   r   )r8   r   r   r   )r,   r   r   r   )r8   r
   r   r   )rD   r   r   r   )rF   r   r   r   )rJ   r   rK   r   r   rL   )__name__
__module____qualname____doc__r   r/   r7   r:   r6   rC   rE   rB   rG   rH   __classcell__r$   r$   r"   r%   r      s    *






r   N)
__future__r   
mypy.nodesr   r   r   r   r   r   r	   r
   r   r   mypy.traverserr   mypyc.errorsr   r   r$   r$   r$   r%   <module>   s
    0