
    L-Ph                       d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZmZ ddZddZ eddd          Z edd          Z G d d          Zeee         ee         f         Zeeee         f         ZddZdS )z!Bytecode analysis for coverage.py    )annotationsN)CodeType)IterableOptional)Iterator)TArcTOffsetcoder   returnIterator[CodeType]c              #     K   | g}|rP|                                 } | j        D ],}t          |t                    r|                    |           -| V  |NdS dS )z,Iterate over all the code objects in `code`.N)pop	co_consts
isinstancer   append)r
   stackcs      Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/coverage/bytecode.pycode_objectsr      s~      FE
  yy{{ 	  	 A!X&&  Q


          op_namesstrset[int]c                      fd| 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  )disopmapget).0nameops     r   	<setcomp>zop_set.<locals>.<setcomp>#   s1    CCC4cimmD.A.A(ACBCCCr   r   )r   r"   s    @r   op_setr$      s     
 DCCC8CCCCr   JUMP_BACKWARDJUMP_BACKWARD_NO_INTERRUPTJUMP_FORWARDRETURN_VALUERETURN_GENERATORc                  *    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   Nonec                    || _         i | _        d }t          j        |          D ]}|| j        |j        <   |J |j        | _        d S )N)r
   instsr   get_instructionsoffset
max_offset)selfr
   insts      r   __init__zInstructionWalker.__init__;   sY    	57
(.. 	+ 	+D&*DJt{##+r   r   T)start_atfollow_jumpsr5   r	   r6   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.
              N)setr1   addr.   r   opcodeALWAYS_JUMPSjump_target)r2   r5   r6   seenr0   r3   s         r   walkzInstructionWalker.walkF   s       uut***~~HHVz~~f---t 


 DK<$?$?!-FaKF t*******r   N)r
   r   r   r,   )r5   r	   r6   r7   r   r8   )__name__
__module____qualname____doc__r4   rB   r   r   r   r+   r+   1   sW         	& 	& 	& 	& &'T       r   r+   TBranchTrailsc                x    i }t                                         d          D ]}|j        s
|j        t          v r|j        #d fd} ||j        d	z   
           ||j        
          g}|||j        <   |D ]1}|d         D ]&}||vrg ||<   ||                             |           '2|S )a  
    Calculate branch trails for `code`.

    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.

    F)r6   Nr5   r	   r   TBranchTrailc                N   t                      }d }                    |           D ]f}|                    |j                   |j        r|j        k    r	|j        } n0|j        r|j        t          vr n|j        t          v r
j	         } ng|||ffS t                      d fS )Nr5   )
r<   rB   r=   r0   line_numberr@   r>   r?   RETURNSco_firstlineno)r5   inst_offsetsto_lineinst2r
   	from_lineiwalkers       r   walk_one_branchz&branch_trails.<locals>.walk_one_branch}   s    ),LG x88 	 	  ...$ ):i)G)G#/GE& EL,L,LE\W,,#22GE - "#i%999uud{"r   r;   rK   r   )r5   r	   r   rI   )r+   rB   r@   r>   r?   rL   r0   r   )	r
   
the_trailsr3   rT   trailstrailr0   rR   rS   s	   `      @@r   branch_trailsrX   _   s4     !#J%%G%00 /1 /1 	;,&&$		# 	# 	# 	# 	# 	# 	# 	#, OT[1_555OT%5666
 #)
4;  	1 	1E( 1 1++)+Jv&6"))%00001	1 r   )r
   r   r   r   )r   r   r   r   )r
   r   r   rG   )rF   
__future__r   r   typesr   typingr   r   collections.abcr   coverage.typesr   r	   r   r$   r?   rM   r+   tupler<   rI   dictlistrG   rX   r   r   r   <module>ra      sR   ( ' " " " " " " 



       % % % % % % % % $ $ $ $ $ $ ( ( ( ( ( ( ( (
 
 
 
D D D D v   &!3
4
4' ' ' ' ' ' ' 'T S\8D>12Wd<001C C C C C Cr   