o
    2gs                     @  sV  d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZmZ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mZmZmZ ddlmZ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(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ededef dZ0eee0ge0f e1dZ2e2d1d'd(Z3d2d.d/Z4d0S )3a?  Transform a mypy AST to the IR form (Intermediate Representation).

For example, consider a function like this:

   def f(x: int) -> int:
       return x * 2 + 1

It would be translated to something that conceptually looks like this:

   r0 = 2
   r1 = 1
   r2 = x * r0 :: int
   r3 = r2 + r1 :: int
   return r3

This module deals with the module-level IR transformation logic and
putting it all together. The actual IR is implemented in mypyc.ir.

For the core of the IR transform implementation, look at build_ir()
below, mypyc.irbuild.builder, and mypyc.irbuild.visitor.
    )annotations)AnyCallableTypeVarcast)Graph)ClassDef
ExpressionMypyFile)state)Type)analyze_always_defined_attrs)TOP_LEVEL_NAME)Errors)FuncDeclFuncIRFuncSignature)ModuleIR	ModuleIRs)none_rprimitive)	IRBuilder)Mapper)PreBuildVisitor)build_type_map"find_singledispatch_register_impls)IRBuilderVisitor)compute_vtable)CompilerOptionsF.)boundTmoduleslist[MypyFile]graphr   typesdict[Expression, Type]mapperr   optionsr   errorsr   returnr   c                 C  s   t || |||| t| |}i }g }| D ]C}	t||	|j}
|	|
 t }t|	j|||||
|||j	}||_	t
||	 t|	jt|j|j|j|j|j}|||	j< ||j qt| |D ]	}|jrgt| q^|S )zBuild basic IR for a set of modules that have been type-checked by mypy.

    The returned IR is not complete and requires additional
    transformations, such as the insertion of refcount handling.
    )r   r   r   decorators_to_removeacceptr   r   fullnamesingledispatch_implsbuildertransform_mypy_filer   listimports	functionsclassesfinal_namestype_var_namesextendr   is_ext_classr   )r    r"   r#   r%   r&   r'   singledispatch_inforesult	class_irsmodulepbvvisitorr-   	module_ircir r?   J/home/garg/my-data/venv/lib/python3.10/site-packages/mypyc/irbuild/main.pybuild_ir3   sJ   



rA   r-   r   mypyfiler
   Nonec                 C  s   |j dv rdS | |j |j dd |jD }|D ]}| jj|j }| j| q| 	d | 
dd |jD ]}| | q7|   |  \}}}}	}tg t}
tttd| j|
||dd}| j| dS )	z Generate IR for a single module.)typingabcNc                 S  s   g | ]	}t |tr|qS r?   )
isinstancer   ).0noder?   r?   r@   
<listcomp>   s    z'transform_mypy_file.<locals>.<listcomp>z<module>builtins)traceback_name)r+   
set_modulepathdefsr%   
type_to_irinfor2   appendenter
gen_importr*   maybe_add_implicit_returnleaver   r   r   r   r   module_namer1   )r-   rB   r2   clsirrH   args_blocksret_typesigfunc_irr?   r?   r@   r.   u   s*   



r.   N)r    r!   r"   r   r#   r$   r%   r   r&   r   r'   r   r(   r   )r-   r   rB   r
   r(   rC   )5__doc__
__future__r   rD   r   r   r   r   
mypy.buildr   
mypy.nodesr   r	   r
   
mypy.stater   
mypy.typesr   mypyc.analysis.attrdefinedr   mypyc.commonr   mypyc.errorsr   mypyc.ir.func_irr   r   r   mypyc.ir.module_irr   r   mypyc.ir.rtypesr   mypyc.irbuild.builderr   mypyc.irbuild.mapperr   mypyc.irbuild.prebuildvisitorr   mypyc.irbuild.preparer   r   mypyc.irbuild.visitorr   mypyc.irbuild.vtabler   mypyc.optionsr   r   strict_optional_setstrict_optional_decrA   r.   r?   r?   r?   r@   <module>   s2    A