
    zi!                    @   d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZmZ  G d d	          Zd"dZd#dZ eddd          Z edd          Z edd          Z G d d          Zeee         ee         f         Zeeef         Zd$dZd%d!ZdS )&z!Bytecode analysis for coverage.py    )annotationsN)IterableMapping)CodeType)Optional)TArcTLineNoTOffsetc                  D    e Zd ZdZddddddZddZddZddZddZdS )
ByteParserz3Parse bytecode to understand the structure of code.N)codetextfilenamer   CodeType | Noner   
str | Noner   returnNonec               J    ||J t          ||pddd          }|| _        d S )Nz<string>execT)dont_inherit)compiler   )selfr   r   r   s       \/var/www/tmov.alphamb/tmov_inventario/venv/lib/python3.11/site-packages/coverage/bytecode.py__init__zByteParser.__init__   s;     <###4!7ZdSSSD			    Iterable[ByteParser]c                >    d |                                  D             S )a|  Iterate over all the code objects nested within this one.

        The iteration includes `self` as its first value.

        We skip code objects named `__annotate__` since they are deferred
        annotations that usually are never run.  If there are errors in the
        annotations, they will be caught by type checkers or other tools that
        use annotations.

        c              3  L   K   | ]}|j         d k    t          |          V   dS )__annotate__)r   N)co_namer   ).0cs     r   	<genexpr>z,ByteParser._child_parsers.<locals>.<genexpr>+   s:      __q19P^C^C^
"""C^C^C^C^__r   )code_objects)r   s    r   _child_parserszByteParser._child_parsers    s%     `_D,=,=,?,?____r   Iterable[CodeType]c              #     K   | j         g}|rP|                                }|j        D ],}t          |t                    r|                    |           -|V  |NdS dS )z,Iterate over all the code objects in `code`.N)r   pop	co_consts
isinstancer   append)r   stackr   r"   s       r   r$   zByteParser.code_objects-   s       	 99;;D^ $ $a** $LLOOOJJJ  	 	 	 	 	r   Iterable[TLineNo]c              #  V   K   | j                                         D ]\  }}}|r|V  dS )zyYield the line numbers possible in this code object.

        Uses co_lines() to produce a sequence: l0, l1, ...
        N)r   co_lines)r   _lines      r   _line_numberszByteParser._line_numbers9   sG      
 ),,.. 	 	JAq$ 


	 	r   c              #  l   K   |                                  D ]}|                                E d{V  dS )zFind the statements in `self.code`.

        Produce a sequence of line numbers that start statements.  Recurses
        into all code objects reachable from `self.code`.

        N)r%   r2   )r   bps     r   find_statementszByteParser.find_statementsB   sT       %%'' 	* 	*B''))))))))))	* 	*r   )r   r   r   r   r   r   r   r   )r   r   )r   r&   )r   r-   )	__name__
__module____qualname____doc__r   r%   r$   r2   r5    r   r   r   r      s        ==
 !%#
 
 
 
 
 
` ` ` `
 
 
 
   	* 	* 	* 	* 	* 	*r   r   r   r   r   dict[TOffset, TLineNo]c                v    i }|                                  D ]!\  }}}|t          ||d          D ]}|||<   "|S )z6Make a dict mapping byte code offsets to line numbers.N   )r/   range)r   b2lbstartbendlinenoboffsets         r   bytes_to_linesrD   N   sW    
C $ & &f q11 & &%GJr   op_namesstrset[int]c                 B    fd| D             }|sJ d|              |S )zMake a set of opcodes from instruction names.

    The names might not exist in this version of Python, skip those if not.
    c                V    h | ]%}t           j                            |          x#&S r:   )disopmapget)r!   nameops     r   	<setcomp>zop_set.<locals>.<setcomp>]   s1    
B
B
B$SY]]4-@-@'@r
B2
B
B
Br   z At least one opcode must exist: r:   )rE   opsrN   s     @r   op_setrQ   X   sA    
 C
B
B
B(
B
B
BC===8=====Jr   JUMP_BACKWARDJUMP_BACKWARD_NO_INTERRUPTJUMP_FORWARDRETURN_VALUERETURN_GENERATORNOP	NOT_TAKENc                  *    e Zd ZdZddZddd	ddZdS )InstructionWalkera]  Utility to step through trails of instructions.

    We have two reasons to need sequences of instructions from a code object:
    First, in strict sequence to visit all the instructions in the object.
    This is `walk(follow_jumps=False)`.  Second, we want to follow jumps to
    understand how execution will flow: `walk(follow_jumps=True)`.
    r   r   r   r   c                    || _         i | _        d }t          j        |          D ]}|| j        |j        <   |J |j        | _        d S N)r   instsrJ   get_instructionsoffset
max_offset)r   r   insts      r   r   zInstructionWalker.__init__   sY    	57
(.. 	+ 	+D&*DJt{##+r   r   Tstart_atfollow_jumpsrc   r
   rd   boolIterable[dis.Instruction]c             #    K   t                      }|}|| j        dz   k     rh||v rdS |                    |           | j                            |          x}r|V  |r|j        t          v r|j        }a|dz  }|| j        dz   k     fdS dS )z}
        Yield instructions starting from `start_at`.  Follow unconditional
        jumps if `follow_jumps` is true.
           r=   N)setr`   addr]   rL   opcodeALWAYS_JUMPSjump_target)r   rc   rd   seenr_   ra   s         r   walkzInstructionWalker.walk   s       uut***~~HHVz~~f---t 


 DK<$?$?!-FaKF t*******r   N)r   r   r   r   )rc   r
   rd   re   r   rf   )r6   r7   r8   r9   r   ro   r:   r   r   rZ   rZ   v   sW         	& 	& 	& 	& &'T       r   rZ   multiline_mapMapping[TLineNo, TLineNo]TBranchTrailsc                   	
 t          j        d           }t                     

                    d          D ]}|j        s
|j        t          v r|j        		#                    		          	d 	
fd}t          j        t                    } |||j
        dz               |||j                   |||j
        <   |                                D ]+\  }}|D ]#}||         |                             |           $,|S )a  
    Calculate branch trails for `code`.

    `multiline_map` maps line numbers to the first line number of a
    multi-line statement.

    Instructions can have a jump_target, where they might jump to next.  Some
    instructions with a jump_target are unconditional jumps (ALWAYS_JUMPS), so
    they aren't interesting to us, since they aren't the start of a branch
    possibility.

    Instructions that might or might not jump somewhere else are branch
    possibilities.  For each of those, we track a trail of instructions.  These
    are lists of instruction offsets, the next instructions that can execute.
    We follow the trail until we get to a new source line.  That gives us the
    arc from the original instruction's line to the new source line.

    c                 4    t          j        t                    S r\   )collectionsdefaultdictri   r:   r   r   <lambda>zbranch_trails.<locals>.<lambda>   s    @WX[@\@\ r   Frd   NtrailsTBranchTrailsOneSourcerc   r
   r   r   c                   t                      }d }                    |d          D ]v}|                    |j                   |j        }|	                    ||          }|r
|k    r|} n0|j        r|j        t          vr n|j        t          v r
j
         } nw|| |f                             |           d S t                      | d <   d S )NTrb   )ri   ro   rj   r_   line_numberrL   rm   rk   rl   RETURNSco_firstlinenoupdate)
ry   rc   inst_offsetsto_lineinst2l2r   	from_lineiwalkerrp   s
         r   add_one_branch_trailz+branch_trails.<locals>.add_one_branch_trail   s    
 *-LG xdKK    ...&>&**2r22B "	// GE& EL,L,LE\W,,#22GE - "	7+,33LAAAAA"uutr   r=   )rc   )ry   rz   rc   r
   r   r   )ru   rv   rZ   ro   rm   rk   rl   r|   rL   ri   r_   itemsr   )r   rp   
the_trailsra   r   ry   arcoffsetsr_   r   r   s   ``       @@r   branch_trailsr      si   , !, 78\8\ ] ]J%%G%00 38 38 	;,&&$	!%%i;;		% 	% 	% 	% 	% 	% 	% 	% 	%6 *5)@)E)EVdkAo>>>>Vd.>????"(
4; #LLNN 	8 	8LC! 8 86"3'..w77778	8 r   dict[TOffset, TOffset]c                    i }t          |           }|                    d          D ]@}|j        t          v r|j        ||j        <    |j        t          v r|j        dz   ||j        <   A|S )zMake a map of unconditional bytecodes jumping to others.

    Only include bytecodes that do no work and go to another bytecode.
    Frx   r=   )rZ   ro   rk   rl   rm   r_   NOPS)r   jumpsr   ra   s       r   always_jumpsr      sw    
 E%%G%00 1 1;,&&!%!1E$+[D  !%qE$+Lr   )r   r   r   r;   )rE   rF   r   rG   )r   r   rp   rq   r   rr   )r   r   r   r   )r9   
__future__r   ru   rJ   collections.abcr   r   typesr   typingr   coverage.typesr   r	   r
   r   rD   rQ   rl   r}   r   rZ   dictri   rz   rr   r   r   r:   r   r   <module>r      s   ( ' " " " " " "     



 - - - - - - - -             1 1 1 1 1 1 1 1 1 1:* :* :* :* :* :* :* :*z       v   &  v	 & & & & & & & &R htnc'l:; W445M M M M`     r   