
    {YhG                     0   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dS )    N)dedent)Any
NamedTupleOptional)ErrorReport)SourceRangeFactoryobj	error_msgreturnc                     d}	 t          j        |           }t          j        |           \  }}n2# t          $ r%}d|  d}|r|d|z   z  }t          |          |d}~ww xY w|||fS )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          `/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/_sources.pyget_source_lines_and_filer      s     H"(--#*#9##>#> [[ " " "C    	
  	$4)##Ccll!" X--s   +0 
A AAr   c                 t   d d}t          |           D ]0\  }}|                                                    d          r|} n1|| S | |         }|                    d          d         fd| d|         D             }fd| |dz   d         D             }|                    |           ||z   S )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                 Z    | |                      |          ot          |          d          S N)
startswithlen)textprefixs     r   remove_prefixz-normalize_source_lines.<locals>.remove_prefix4   s*    DOOF++;F==>>    Ndefr   c                 .    g | ]} |          z   S  r$   .0sr    
whitespaces     r   
<listcomp>z*normalize_source_lines.<locals>.<listcomp>I   7       67
]]1j111  r!   c                 .    g | ]} |          z   S r$   r$   r%   s     r   r)   z*normalize_source_lines.<locals>.<listcomp>L   r*   r!      )	enumeratelstripr   splitappend)	r   idxilfn_defaligned_prefixaligned_suffixr    r(   s	          @@r   normalize_source_linesr7   &   s"   ? ? ? C+&&  188::  '' 	CE	 { Fe$$Q'J    ;Ftt;L  N    ;FsQwyy;Q  N
 &!!!N**r!   c                   $     e Zd Z	 	 d fd	Z xZS )SourceContextTNc                 z    t                                          ||||           || _        || _        || _        d S r   )super__init__uses_true_divisionr   funcname)selfsourcer   r   leading_whitespace_lenr=   r>   	__class__s          r   r<   zSourceContext.__init__X   s>     	;8NOOO"4  r!   )TN)__name__
__module____qualname__r<   __classcell__)rB   s   @r   r9   r9   W   sE          ! ! ! ! ! ! ! ! ! !r!   r9   c                      t          |  S r   )r9   )argss    r   make_source_contextrI   g   s    $r!   c                  N    t          dd dd                              dd          S )N r   r,   )r9   make_raw_ranger$   r!   r   
fake_rangerM   l   s&    T1a((771===r!   c                   X    e Zd ZU ej        ed<   eed<   eed<   ee         ed<   e	ed<   dS )	ParsedDefastctxr@   r   r   N)
rC   rD   rE   rP   Module__annotations__r9   strr   intr$   r!   r   rO   rO   p   sN         	OOO	KKKsmr!   rO   c                 |   t          | t          j                              \  }}}t          |          }d                    |          }t          |          }t          j        |          }t          |j	                  dk    s%t          |j	        d         t          j                  st          d| d|           t          |                    dd          d                   t          |                    dd          d                   z
  }t          ||||d| j                  }t!          |||||          S )NrK   r,   r   z&Expected a single top-level function: :r   T)r   r   
call_stackr7   joinr   rP   parser   body
isinstanceFunctionDefRuntimeErrorr/   rI   rC   rO   )	fnr   r   r   r@   
dedent_srcpy_astrA   rQ   s	            r   	parse_defrb   x   s6   )B
K"$$* *&Kh )55KWW[!!FJYz""F
6;1Jv{1~s$O$OMXMMMM
 
 	
 !dA!6!6q!9::Sq!!!$> >  +'=tR[ C VS&(K@@@r!   r   )rP   	functoolsr   textwrapr   typingr   r   r   torch._Cr   torch._C._jit_tree_viewsr   rT   tuplelistrU   r   r7   r9   cacherI   rM   rO   rb   r$   r!   r   <module>rk      s   



            , , , , , , , , , ,             7 7 7 7 7 7
  $. .	.}. 49c8C=(). . . .4,+S	 ,+d3i ,+ ,+ ,+ ,+b! ! ! ! !& ! ! !       > > >    
   A A A A Ar!   