o
    2gS                     @  s   d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
mZmZ ddlmZmZ ddlmZmZmZ ddlmZmZ G d	d
 d
eZee ZG dd dZG dd dZd%ddZd&ddZd'ddZd(ddZd)d"d#Zd$S )*z'Intermediate representation of classes.    )annotations)List
NamedTuple)PROPSET_PREFIXJsonDict)FuncDeclFuncIRFuncSignature)	DeserMapsValue)	RInstanceRTypedeserialize_type)NameGeneratorexported_namec                   @  s.   e Zd ZU ded< ded< ded< ded< d	S )
VTableMethodz	'ClassIR'clsstrnamer   methodFuncIR | Noneshadow_methodN)__name__
__module____qualname____annotations__ r   r   I/home/garg/my-data/venv/lib/python3.10/site-packages/mypyc/ir/class_ir.pyr   H   s
   
 r   c                   @  s(  e Zd ZdZ				dSdTddZdUddZedUddZdVddZdWddZ	dXddZ
dYddZdZd!d"Zd[d$d%Zd\d&d'Zd\d(d)Zd\d*d+Zd\d,d-Zd\d.d/Zd]d2d3Zd]d4d5Zdd6d^d9d:Zdd6d_d<d=Zd\d>d?Zd`d@dAZdadCdDZdbdFdGZd`dHdIZdcdKdLZedddPdQZdRS )eClassIRzpIntermediate representation of a class.

    This also describes the runtime structure of native instances.
    FTr   r   module_nameis_traitboolis_generatedis_abstractis_ext_classreturnNonec                 C  s   || _ || _|| _|| _|| _|| _d| _d| _d| _d| _	d| _
d| _d | _t|d |tg t| | _i | _g | _i | _i | _i | _i | _i | _d | _g | _i | _d | _g | _| g| _| g| _g | _t  | _!t  | _"t  | _#d| _$g | _%d S NF)&r   r   r    r"   r#   r$   is_augmentedinherits_pythonhas_dictallow_interpreted_subclassesneeds_getseters_serializablebuiltin_baser   r	   r   ctor
attributes	deletablemethod_declsmethodsglue_methods
propertiesproperty_typesvtablevtable_entriestrait_vtablesbasetraitsmrobase_mrochildrensetattrs_with_defaults_always_initialized_attrs_sometimes_initialized_attrsinit_self_leakbitmap_attrs)selfr   r   r    r"   r#   r$   r   r   r   __init__X   sD   	
zClassIR.__init__c                 C  s   dj | dS )NzClassIR(name={self.name}, module_name={self.module_name}, is_trait={self.is_trait}, is_generated={self.is_generated}, is_abstract={self.is_abstract}, is_ext_class={self.is_ext_class})rE   )formatrG   r   r   r   __repr__   s   zClassIR.__repr__c                 C  s   | j  d| j S )N.)r   r   rG   r   r   r   fullname   s   zClassIR.fullnameClassIR | Nonec                 C  s(   t | jdkr| jd js| jd S dS )z7Return the actual concrete base class, if there is one.   N)lenr<   r    rG   r   r   r   	real_base   s   
zClassIR.real_baseintc                 C  s:   | j d us	J d|| j v sJ | jd|| j | S )Nzvtable not computed yet has no attribute )r7   r   rE   r   r   r   r   vtable_entry   s   
zClassIR.vtable_entrytuple[RType, ClassIR]c                 C  sX   | j D ]}||jv r|j| |f  S ||jv r!|j| |f  S qt| jd|NrQ   )r<   r0   r6   KeyErrorr   rE   r   irr   r   r   attr_details   s   


zClassIR.attr_detailsr   c                 C  s   |  |d S )Nr   )rY   rR   r   r   r   	attr_type      zClassIR.attr_typer   c                 C  s8   | j D ]}||jv r|j|   S qt| jd|rU   )r<   r2   rV   r   rW   r   r   r   method_decl   s
   

zClassIR.method_declr	   c                 C  s   |  |jS N)r\   sigrR   r   r   r   
method_sig   s   zClassIR.method_sigc                 C  &   z|  | W dS  ty   Y dS w NFT)r\   rV   rR   r   r   r   
has_method      zClassIR.has_methodc                   sb   |   }|d u r
dS |  r%|  }|D ]}| |kr" dS qdS t fdd|D  S )NFTc                 3  s    | ]}|  V  qd S r]   )rb   ).0subcr   r   r   	<genexpr>      z*ClassIR.is_method_final.<locals>.<genexpr>)
subclassesrb   r\   any)rE   r   subsr\   re   r   rf   r   is_method_final   s   

zClassIR.is_method_finalc                 C  r`   ra   )rZ   rV   rR   r   r   r   has_attr  rc   zClassIR.has_attrc                      t  fdd| jD S )Nc                 3      | ]} |j v V  qd S r]   )r1   rd   rX   rf   r   r   rg     rh   z'ClassIR.is_deletable.<locals>.<genexpr>rj   r<   rR   r   rf   r   is_deletable     zClassIR.is_deletablec                 C  s   |  |rdS || jv S r'   )rr   rA   rR   r   r   r   is_always_defined  s   

zClassIR.is_always_definednamesr   c                 C  s   | | j| jS r]   )private_namer   r   rE   ru   r   r   r   name_prefix     zClassIR.name_prefixc                 C  s   t | j dS )NObject)r   rK   rw   r   r   r   struct_name  ry   zClassIR.struct_nameprefer_methodr}   tuple[FuncIR, ClassIR] | Nonec                C  sB   | j D ]}||jv r|j| }|s|jjr d S ||f  S qd S r]   )r<   r3   declimplicit)rE   r   r}   rX   func_irr   r   r   get_method_and_class  s   


	zClassIR.get_method_and_classr   c                C  s   | j ||d}|r|d S d S )Nr|   r   )r   )rE   r   r}   resr   r   r   
get_method+  s   zClassIR.get_methodc                   rn   )Nc                 3  ro   r]   )r2   rp   rf   r   r   rg   0  rh   z*ClassIR.has_method_decl.<locals>.<genexpr>rq   rR   r   rf   r   has_method_decl/  rs   zClassIR.has_method_declc                 C  s   | j g ko| j S r]   )r>   r+   rG   r   r   r   has_no_subclasses2     zClassIR.has_no_subclassesset[ClassIR] | Nonec                 C  sT   | j du s| jr
dS t| j }| j D ]}|j r'| }|du r" dS || q|S )zReturn all subclasses of this class, both direct and indirect.

        Return None if it is impossible to identify all subclasses, for example
        because we are performing separate compilation.
        N)r>   r+   r?   ri   update)rE   resultchild
child_subsr   r   r   ri   5  s   


zClassIR.subclasseslist[ClassIR] | Nonec                 C  s2   |   }|du r
dS dd |D }t|dd dS )zReturn all concrete (i.e. non-trait and non-abstract) subclasses.

        Include both direct and indirect subclasses. Place classes with no children first.
        Nc                 S  s   h | ]
}|j s|js|qS r   )r    r#   )rd   cr   r   r   	<setcomp>N      z.ClassIR.concrete_subclasses.<locals>.<setcomp>c                 S  s   t | jpg | jfS r]   )rN   r>   r   )r   r   r   r   <lambda>R      z-ClassIR.concrete_subclasses.<locals>.<lambda>)key)ri   sorted)rE   rk   concreter   r   r   concrete_subclassesF  s
   zClassIR.concrete_subclassesc                 C  s   t dd | jD S )Nc                 s  s    | ]}|j V  qd S r]   )r-   )rd   cir   r   r   rg   U  s    z*ClassIR.is_serializable.<locals>.<genexpr>rq   rG   r   r   r   is_serializableT  s   zClassIR.is_serializabler   c                   s  i d j d jd jd jd jd jd jd jd	 jd
 j	d j
d jd jd j ddd  j D d fdd j D ddd  j D i ddd  j D ddd  j D dt jd jdt jddd  j D d jr jjnd d d!d  jD d"d#d  jD d$d%d  jD d& j d urd'd  j D nd d( j!d)t" j#d*t" j$d+t" j%d, j&S )-Nr   r   r    r$   r#   r"   r(   r)   r*   r+   r,   r-   r.   r/   r0   c                 S     g | ]
\}}||  fqS r   	serializerd   ktr   r   r   
<listcomp>h  r   z%ClassIR.serialize.<locals>.<listcomp>r2   c                   s,   g | ]\}}|| j v r|jn| fqS r   )r3   idr   )rd   r   drG   r   r   r   k  s    r3   c                 S  s   g | ]	\}}||j fqS r   )r   )rd   r   mr   r   r   r   p  s    r4   c                 S  s$   g | ]\\}}}|j |f|jfqS r   )rK   r   )rd   cirr   r   r   r   r   r   q  s    r6   c                 S  r   r   r   r   r   r   r   r   v  r   r5   r7   r8   r9   c                 S  s   g | ]\}}|j t|fqS r   )rK   serialize_vtable)rd   r   vr   r   r   r   z  s    r:   r;   c                 S     g | ]}|j qS r   rK   rd   r   r   r   r   r         r<   c                 S  r   r   r   r   r   r   r   r     r   r=   c                 S  r   r   r   r   r   r   r   r     r   r>   c                 S  r   r   r   r   r   r   r   r     r   r1   r@   rA   rB   rC   )'r   r   r    r$   r#   r"   r(   r)   r*   r+   r,   r-   r.   r/   r   r0   itemsr2   r3   r4   r6   listr5   r7   r   r8   r9   r:   rK   r;   r<   r=   r>   r1   r   r@   rA   rB   rC   rG   r   rG   r   r   W  s   	


 
!"&'()*-
.
/
01zClassIR.serializedatactxr
   c                   s<  |d d |d  }| j v sJ d|  j | |d _|d _|d _|d _|d	 _|d
 _|d _|d _|d _	|d _
|d _t|d  _ fdd|d D _ fdd|d D _ fdd|d D _ fdd|d D _ fdd|d D _fdd|d D _|d _t|d  _ fd d|d! D _|d" }|rƈ j | nd _ fd#d$|d% D _ fd&d$|d' D _ fd(d$|d) D _|d* o fd+d$|d* D _|d, _t|d- _ t|d. _!t|d/ _"|d0 _#S )1Nr   rJ   r   zClass %s not in deser class mapr    r"   r#   r$   r(   r)   r*   r+   r,   r-   r.   r/   c                      i | ]
\}}|t | qS r   r   r   r   r   r   
<dictcomp>  r   z'ClassIR.deserialize.<locals>.<dictcomp>r0   c                   s4   i | ]\}}|t |tr j| jnt| qS r   )
isinstancer   	functionsr   r   deserializerd   r   r   r   r   r   r     s    "r2   c                   s   i | ]
\}}| j | qS r   )r   r   r   r   r   r     r   r3   c                   s*   i | ]\\}}} j | |f j| qS r   )classesr   )rd   r   r   r   r   r   r   r     s    r4   c                   r   r   r   r   r   r   r   r     r   r6   c                   s(   i | ]}| j |  j t| fqS r   )r3   getr   )rd   r   )rX   r   r   r     s    r5   r7   r8   c                   s"   i | ]\}} j | t| qS r   )r   deserialize_vtabler   r   r   r   r     s    r9   r:   c                      g | ]} j | qS r   r   rd   sr   r   r   r         z'ClassIR.deserialize.<locals>.<listcomp>r;   c                   r   r   r   r   r   r   r   r     r   r<   c                   r   r   r   r   r   r   r   r     r   r=   r>   c                   r   r   r   r   r   r   r   r     r   r1   r@   rA   rB   rC   )$r   r    r"   r#   r$   r(   r)   r*   r+   r,   r-   r.   r   r   r/   r0   r2   r3   r4   r6   r5   r7   r   r8   r9   r:   r;   r<   r=   r>   r1   r?   r@   rA   rB   rC   )r   r   r   rK   r:   r   )r   rX   r   r     sX   
















 

zClassIR.deserializeN)FFFT)r   r   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r&   )r%   r   )r%   rL   )r   r   r%   rP   )r   r   r%   rT   )r   r   r%   r   )r   r   r%   r   )r   r   r%   r	   )r   r   r%   r!   )ru   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   r
   r%   r   )r   r   r   __doc__rF   rI   propertyrK   rO   rS   rY   rZ   r\   r_   rb   rl   rm   rr   rt   rx   r{   r   r   r   r   ri   r   r   r   classmethodr   r   r   r   r   r   R   sD    	
m	


















5r   c                   @  s   e Zd ZdZdd	d
ZdS )NonExtClassInfozInformation needed to construct a non-extension class (Python class).

    Includes the class dictionary, a tuple of base classes,
    the class annotations dictionary, and the metaclass.
    dictr   basesanns	metaclassr%   r&   c                 C  s   || _ || _|| _|| _d S r]   )r   r   r   r   )rE   r   r   r   r   r   r   r   rF     s   
zNonExtClassInfo.__init__N)
r   r   r   r   r   r   r   r   r%   r&   )r   r   r   r   rF   r   r   r   r   r     s    r   entryr%   r   c                 C  s0   d| j j| j| jjj| jr| jjjdS d dS )Nr   ).classr   r   r   r   )r   rK   r   r   r   r   r   )r   r   r   r   serialize_vtable_entry  s   r   r7   VTableEntrieslist[JsonDict]c                 C  s   dd | D S )Nc                 S  s   g | ]}t |qS r   )r   )rd   r   r   r   r   r     r   z$serialize_vtable.<locals>.<listcomp>r   )r7   r   r   r   r     r[   r   r   r   r
   c                 C  sZ   | d dkr%t |j| d  | d |j| d  | d r"|j| d  S d S J d| d  )	Nr   r   r   r   r   r   FzBogus vtable .class: %s)r   r   r   r   r   r   r   r   deserialize_vtable_entry  s   r   c                   s    fdd| D S )Nc                   s   g | ]}t | qS r   )r   )rd   xr   r   r   r     r   z&deserialize_vtable.<locals>.<listcomp>r   r   r   r   r   r     r   r   class_irr   c                 C  s.   |   }|du r
dS | js| js||  |S )zFReturn all concrete classes among the class itself and its subclasses.N)r   r#   r    append)r   r   r   r   r   all_concrete_classes  s   
r   N)r   r   r%   r   )r7   r   r%   r   )r   r   r   r
   r%   r   )r   r   r   r
   r%   r   )r   r   r%   r   ) r   
__future__r   typingr   r   mypyc.commonr   r   mypyc.ir.func_irr   r   r	   mypyc.ir.opsr
   r   mypyc.ir.rtypesr   r   r   mypyc.namegenr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s&    =  q




