o
    ØÝ2g¤  ã                   @  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 ddlmZmZ G d	d
„ d
ƒZddd„Zeeef ZdS )z'Intermediate representation of modules.é    )Úannotations)ÚDict)ÚJsonDict)ÚClassIR)ÚFuncDeclÚFuncIR)Ú	DeserMaps)ÚRTypeÚdeserialize_typec                   @  s2   e Zd ZdZddd„Zddd„Zeddd„ƒZdS )ÚModuleIRz(Intermediate representation of a module.ÚfullnameÚstrÚimportsú	list[str]Ú	functionsúlist[FuncIR]Úclassesúlist[ClassIR]Úfinal_namesúlist[tuple[str, RType]]Útype_var_namesÚreturnÚNonec                 C  s,   || _ | ¡ | _|| _|| _|| _|| _d S )N)r   Úcopyr   r   r   r   r   )Úselfr   r   r   r   r   r   © r   úJ/home/garg/my-data/venv/lib/python3.10/site-packages/mypyc/ir/module_ir.pyÚ__init__   s   	

zModuleIR.__init__r   c                 C  s8   | j | jdd„ | jD ƒdd„ | jD ƒdd„ | jD ƒdœS )Nc                 S  ó   g | ]}|  ¡ ‘qS r   ©Ú	serialize©Ú.0Úfr   r   r   Ú
<listcomp>(   ó    z&ModuleIR.serialize.<locals>.<listcomp>c                 S  r   r   r   ©r"   Úcr   r   r   r$   )   r%   c                 S  s   g | ]
\}}||  ¡ f‘qS r   r   ©r"   ÚkÚtr   r   r   r$   *   ó    ©r   r   r   r   r   r,   )r   r   r   r   r    $   s   ûzModuleIR.serializeÚdataÚctxr   c                   sP   t |d |d ‡ fdd„|d D ƒ‡ fdd„|d D ƒ‡ fdd„|d	 D ƒg ƒS )
Nr   r   c                   s   g | ]
}ˆ j t |¡ ‘qS r   )r   r   Úget_id_from_jsonr!   ©r.   r   r   r$   2   r+   z(ModuleIR.deserialize.<locals>.<listcomp>r   c                   s   g | ]}t  |ˆ ¡‘qS r   )r   Údeserializer&   r0   r   r   r$   3   s    r   c                   s   g | ]\}}|t |ˆ ƒf‘qS r   )r
   r(   r0   r   r   r$   4   ó    r   )r   )Úclsr-   r.   r   r0   r   r1   -   s   úzModuleIR.deserializeN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )r-   r   r.   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    Úclassmethodr1   r   r   r   r   r      s    

	r   r-   údict[str, JsonDict]r.   r   r   údict[str, ModuleIR]c                   s¾   |   ¡ D ]%}|d D ]}t|d |d ƒ}|jˆ jvs"J d|j ƒ‚|ˆ j|j< q
q|   ¡ D ]%}|d D ]}t |ˆ ¡}|jjˆ jvsKJ d|jj ƒ‚|ˆ j|jj< q4q.‡ fdd„|  	¡ D ƒS )	aG  Deserialize a collection of modules.

    The modules can contain dependencies on each other.

    Arguments:
        data: A dict containing the modules to deserialize.
        ctx: The deserialization maps to use and to populate.
             They are populated with information from the deserialized
             modules and as a precondition must have been populated by
             deserializing any dependencies of the modules being deserialized
             (outside of dependencies between the modules themselves).

    Returns a map containing the deserialized modules.
    r   ÚnameÚmodule_namezClass %s already in mapr   zMethod %s already in mapc                   s   i | ]\}}|t  |ˆ ¡“qS r   )r   r1   )r"   r)   Úvr0   r   r   Ú
<dictcomp>Y   r2   z'deserialize_modules.<locals>.<dictcomp>)
Úvaluesr   r   r   r   r1   ÚdeclÚidr   Úitems)r-   r.   Úmodr3   ÚirÚmethodÚfuncr   r0   r   Údeserialize_modules9   s   ý
ÿûrG   N)r-   r9   r.   r   r   r:   )r7   Ú
__future__r   Útypingr   Úmypyc.commonr   Úmypyc.ir.class_irr   Úmypyc.ir.func_irr   r   Úmypyc.ir.opsr   Úmypyc.ir.rtypesr	   r
   r   rG   r   Ú	ModuleIRsr   r   r   r   Ú<module>   s    
+%