o
    2ga                     @  s   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
mZ ddlmZ G dd	 d	ZG d
d dZG dd deZdS )zGHelpers that store information about functions and the related classes.    )annotations)FuncItem)ClassIR)INVALID_FUNC_DEF)
BasicBlockValue)AssignmentTargetc                	   @  s   e Zd ZdZeddddddddf	d-ddZd.ddZed/ddZed/ddZ	ed0ddZ
e
jd1d dZ
ed2d"d#Zejd3d%d#Zed4d'd(Zejd5d)d(Zed6d+d,ZdS )7FuncInfoz;Contains information about functions as they are generated. NFfitemr   namestr
class_name
str | None	namespace	is_nestedboolcontains_nestedis_decorated
in_non_extadd_nested_funcs_to_envreturnNonec
           
      C  sR   || _ || _|| _|| _d | _d | _d | _d | _|| _|| _	|| _
|| _|	| _d S N)r   r   r   ns_callable_class
_env_class_generator_class_curr_env_regr   r   r   r   r   )
selfr   r   r   r   r   r   r   r   r    r    M/home/garg/my-data/venv/lib/python3.10/site-packages/mypyc/irbuild/context.py__init__   s   
zFuncInfo.__init__c                 C  s    d dd | j| j| jfD S )N_c                 s  s    | ]}|r|V  qd S r   r    ).0xr    r    r!   	<genexpr>8   s    z+FuncInfo.namespaced_name.<locals>.<genexpr>)joinr   r   r   r   r    r    r!   namespaced_name7   s    zFuncInfo.namespaced_namec                 C  s   | j jp| j jS r   )r   is_generatoris_coroutiner(   r    r    r!   r*   :   s   zFuncInfo.is_generatorc                 C  s   | j jS r   )r   r+   r(   r    r    r!   r+   >   s   zFuncInfo.is_coroutineImplicitClassc                 C     | j d usJ | j S r   r   r(   r    r    r!   callable_classB      zFuncInfo.callable_classclsc                 C  
   || _ d S r   r.   r   r1   r    r    r!   r/   G      
r   c                 C  r-   r   r   r(   r    r    r!   	env_classK   r0   zFuncInfo.env_classirc                 C  r2   r   r5   r   r7   r    r    r!   r6   P   r4   GeneratorClassc                 C  r-   r   r   r(   r    r    r!   generator_classT   r0   zFuncInfo.generator_classc                 C  r2   r   r:   r3   r    r    r!   r;   Y   r4   r   c                 C  r-   r   r   r(   r    r    r!   curr_env_reg]   r0   zFuncInfo.curr_env_reg)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )r   r   )r   r,   )r1   r,   r   r   )r   r   r7   r   r   r   )r   r9   )r1   r9   r   r   r   r   )__name__
__module____qualname____doc__r   r"   r)   propertyr*   r+   r/   setterr6   r;   r=   r    r    r    r!   r	      s>    
(r	   c                   @  st   e Zd ZdZdddZedd	d
Zejddd
ZedddZejdddZedddZ	e	jdddZ	dS )r,   a  Contains information regarding implicitly generated classes.

    Implicit classes are generated for nested functions and generator
    functions. They are not explicitly defined in the source code.

    NOTE: This is both a concrete class and used as a base class.
    r7   r   r   r   c                 C  s   || _ d | _d | _d | _d S r   )r7   	_self_regr   _prev_env_regr8   r    r    r!   r"   l   s   
zImplicitClass.__init__r   c                 C  r-   r   rF   r(   r    r    r!   self_regx   r0   zImplicitClass.self_regregc                 C  r2   r   rH   r   rJ   r    r    r!   rI   }   r4   c                 C  r-   r   r<   r(   r    r    r!   r=      r0   zImplicitClass.curr_env_regc                 C  r2   r   r<   rK   r    r    r!   r=      r4   c                 C  r-   r   rG   r(   r    r    r!   prev_env_reg   r0   zImplicitClass.prev_env_regc                 C  r2   r   rL   rK   r    r    r!   rM      r4   Nr>   r?   rJ   r   r   r   )
r@   rA   rB   rC   r"   rD   rI   rE   r=   rM   r    r    r    r!   r,   c   s    
r,   c                      s^   e Zd ZdZd fddZedd	d
Zejddd
ZedddZejdddZ  Z	S )r9   z?Contains information about implicit generator function classes.r7   r   r   r   c                   s6   t  | d | _d | _d | _d | _t | _g | _d S r   )	superr"   _next_label_reg_next_label_targetexc_regssend_arg_regr   switch_blockcontinuation_blocksr8   	__class__r    r!   r"      s   
zGeneratorClass.__init__r   c                 C  r-   r   rP   r(   r    r    r!   next_label_reg   r0   zGeneratorClass.next_label_regrJ   c                 C  r2   r   rX   rK   r    r    r!   rY      r4   r   c                 C  r-   r   rQ   r(   r    r    r!   next_label_target   r0   z GeneratorClass.next_label_targettargetc                 C  r2   r   rZ   )r   r\   r    r    r!   r[      r4   r>   r?   rN   )r   r   )r\   r   r   r   )
r@   rA   rB   rC   r"   rD   rY   rE   r[   __classcell__r    r    rV   r!   r9      s    r9   N)rC   
__future__r   
mypy.nodesr   mypyc.ir.class_irr   mypyc.ir.func_irr   mypyc.ir.opsr   r   mypyc.irbuild.targetsr   r	   r,   r9   r    r    r    r!   <module>   s    W1