o
    2g                     @  s   d Z ddlmZ ddl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 dd
lmZ ddlmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ G dd deZ G dd de Z!G dd de Z"dS )z!Runner for IR optimization tests.    )annotationsN)CompileError)test_temp_dir)DataDrivenTestCase)TOP_LEVEL_NAME)FuncIR)format_func)CompilerOptions)ICODE_GEN_BUILTINSMypycDataSuiteassert_test_outputbuild_ir_for_single_fileremove_comment_linesuse_custom_builtins)do_copy_propagation)do_flag_elimination)insert_uninit_checksc                   @  s(   e Zd ZdZeZdddZdd
dZdS )OptimizationSuitez~Base class for IR optimization test suites.

    To use this, add a base class and define "files" and "do_optimizations".
    testcaser   returnNonec                 C  s   t tj| jt|U t|j}zt|j	}W n t
y- } z	|j}W Y d }~n(d }~ww g }|D ]}|jtkr@|jds@q2t| | | |t| q2t||d| W d    d S 1 scw   Y  d S )N	_toplevelzInvalid source code output)r   ospathjoindata_prefixr
   r   outputr   inputr   messagesnamer   endswithr   do_optimizationsextendr   r   )selfr   expected_outputireactualfn r)   U/home/garg/my-data/venv/lib/python3.10/site-packages/mypyc/test/test_optimizations.pyrun_case#   s"   

"zOptimizationSuite.run_caser(   r   c                 C  s   t N)NotImplementedErrorr#   r(   r)   r)   r*   r!   5   s   z"OptimizationSuite.do_optimizationsN)r   r   r   r   r(   r   r   r   )__name__
__module____qualname____doc__r   	base_pathr+   r!   r)   r)   r)   r*   r      s
    
r   c                   @     e Zd ZdgZd	ddZdS )
TestCopyPropagationzopt-copy-propagation.testr(   r   r   r   c                 C     t |t  d S r,   )r   r	   r.   r)   r)   r*   r!   <      z$TestCopyPropagation.do_optimizationsNr/   r0   r1   r2   filesr!   r)   r)   r)   r*   r6   9       r6   c                   @  r5   )
TestFlagEliminationzopt-flag-elimination.testr(   r   r   r   c                 C  r7   r,   )r   r	   r.   r)   r)   r*   r!   C   r8   z$TestFlagElimination.do_optimizationsNr/   r9   r)   r)   r)   r*   r<   @   r;   r<   )#r3   
__future__r   os.pathr   mypy.errorsr   mypy.test.configr   mypy.test.datar   mypyc.commonr   mypyc.ir.func_irr   mypyc.ir.pprintr   mypyc.optionsr	   mypyc.test.testutilr
   r   r   r   r   r    mypyc.transform.copy_propagationr    mypyc.transform.flag_eliminationr   mypyc.transform.uninitr   r   r6   r<   r)   r)   r)   r*   <module>   s"     