
    VhG                        d dl Z d dlZd dl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edee   deee   eee   f   fd	Zd
ee   dee   fdZ G d de      Zej(                  d        Zd Z G d de      Zd Zy)    N)dedent)Any
NamedTupleOptional)ErrorReport)SourceRangeFactoryobj	error_msgreturnc                     d}	 t        j                  |       }t        j                  |       \  }}|||fS # t        $ r!}d|  d}|r|d|z   z  }t        |      |d}~ww xY w)z{
    Wrapper around inspect.getsourcelines and inspect.getsourcefile.

    Returns: (sourcelines, file_lino, filename)
    NzCan't get source for zs. TorchScript requires source access in order to carry out compilation, make sure original .py files are available.
)inspectgetsourcefilegetsourcelinesOSError)r	   r
   filenamesourcelinesfile_linenoemsgs          >/home/dcms/DCMS/lib/python3.12/site-packages/torch/_sources.pyget_source_lines_and_filer      s     H"((-#*#9#9##> [ X--  "#C5 )  	
 4)##Ccl!"s   -6 	A AA r   c                 h   d }d}t        |       D ](  \  }}|j                         j                  d      s&|} n || S | |   }|j                  d      d   }| d| D cg c]  }| |||      z    }}| |dz   d D cg c]  }| |||      z    }	}|j	                  |       ||	z   S c c}w c c}w )a   
    This helper function accepts a list of source lines. It finds the
    indentation level of the function definition (`def`), then it indents
    all lines in the function body to a point at or greater than that
    level. This allows for comments and continued string literals that
    are at a lower indentation than the rest of the code.
    Args:
        sourcelines: function source code, separated into lines by
                        the '
' character
    Returns:
        A list of source lines that have been correctly aligned
    c                 D    | | j                  |      xr t        |      d  S N)
startswithlen)textprefixs     r   remove_prefixz-normalize_source_lines.<locals>.remove_prefix4   s"    DOOF+;F=>>    Ndefr      )	enumeratelstripr   splitappend)
r   r    idxilfn_def
whitespacesaligned_prefixaligned_suffixs
             r   normalize_source_linesr0   &   s    ? C+& 188:  'C { Fe$Q'J <Gt;L67
]1j11N  <GsQwy;Q67
]1j11N 
 &!N**s    B*?B/c                   $     e Zd Z	 	 d fd	Z xZS )SourceContextc                 T    t         |   ||||       || _        || _        || _        y r   )super__init__uses_true_divisionr   funcname)selfsourcer   r   leading_whitespace_lenr6   r7   	__class__s          r   r5   zSourceContext.__init__X   s/     	;8NO"4  r!   )TN)__name__
__module____qualname__r5   __classcell__)r;   s   @r   r2   r2   W   s      ! !r!   r2   c                      t        |  S r   )r2   )argss    r   make_source_contextrB   g   s    $r!   c                  >    t        dd dd      j                  dd      S )N r   r#   )r2   make_raw_range r!   r   
fake_rangerG   l   s     T1a(771==r!   c                   Z    e Zd ZU ej                  ed<   eed<   eed<   ee   ed<   e	ed<   y)	ParsedDefastctxr9   r   r   N)
r<   r=   r>   rJ   Module__annotations__r2   strr   intrF   r!   r   rI   rI   p   s&    	O	Ksmr!   rI   c                 *   t        | t        j                               \  }}}t        |      }dj	                  |      }t        |      }t        j                  |      }t        |j                        dk7  s't        |j                  d   t        j                        st        d| d|       t        |j                  dd      d         t        |j                  dd      d         z
  }t        ||||d| j                        }t!        |||||      S )NrD   r#   r   z&Expected a single top-level function: :r   T)r   r   
call_stackr0   joinr   rJ   parser   body
isinstanceFunctionDefRuntimeErrorr&   rB   r<   rI   )	fnr   r   r   r9   
dedent_srcpy_astr:   rK   s	            r   	parse_defr\   x   s   )B
K""$*&Kh )5KWW[!FJYYz"F
6;;1Jv{{1~s$O4XJa}M
 	
 !dA!6q!9:Sq!!$>  +'=tR[[C VS&(K@@r!   r   )rJ   	functoolsr   textwrapr   typingr   r   r   torch._Cr   torch._C._jit_tree_viewsr   rN   tuplelistrO   r   r0   r2   cacherB   rG   rI   r\   rF   r!   r   <module>re      s    
    , ,   7
  $.	.}. 49c8C=().4,+S	 ,+d3i ,+b!& !     >
 Ar!   