2929from xdis .code import iscode
3030from xdis .bytecode import Bytecode
3131from uncompyle6 .scanner import Token , parse_fn_counts
32+ from uncompyle6 .scanners .controlflow import ControlFlow
3233
3334# Get all the opcodes into globals
3435import xdis .opcodes .opcode_33 as op3
@@ -102,6 +103,11 @@ def __init__(self, version, show_asm=None, is_pypy=False):
102103 varargs_ops .add (self .opc .CALL_METHOD )
103104 self .varargs_ops = frozenset (varargs_ops )
104105
106+ self .setup_ops = frozenset ([
107+ self .opc .SETUP_LOOP ,
108+ self .opc .SETUP_EXCEPT , self .opc .SETUP_FINALLY ,
109+ self .opc .SETUP_WITH ])
110+
105111 # Not really a set, but still clasification-like
106112 self .statement_opcode_sequences = [
107113 (self .opc .POP_JUMP_IF_FALSE , self .opc .JUMP_FORWARD ),
@@ -127,7 +133,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
127133 """
128134
129135 show_asm = self .show_asm if not show_asm else show_asm
130- # show_asm = 'both '
136+ # show_asm = 'after '
131137 if show_asm in ('both' , 'before' ):
132138 bytecode = Bytecode (co , self .opc )
133139 for instr in bytecode .get_instructions (co ):
@@ -179,13 +185,24 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
179185 # Format: {target offset: [jump offsets]}
180186 jump_targets = self .find_jump_targets ()
181187
188+ offset_action = ControlFlow (self ).detect_control_flow (co )
182189 for inst in bytecode :
183190
184191 argval = inst .argval
185192 if inst .offset in jump_targets :
186193 jump_idx = 0
187194 for jump_offset in jump_targets [inst .offset ]:
188- tokens .append (Token ('COME_FROM' , None , repr (jump_offset ),
195+ come_from_name = 'COME_FROM'
196+ if (inst .offset in offset_action
197+ and offset_action [inst .offset ].type == 'end'
198+ # Adjust the grammar and remove the below
199+ and offset_action [inst .offset ].name in ['EXCEPT' ]
200+ ):
201+ come_from_name = '%s_%s' % (
202+ (come_from_name , offset_action [inst .offset ].name ))
203+ pass
204+ tokens .append (Token (come_from_name ,
205+ None , repr (jump_offset ),
189206 offset = '%s_%s' % (inst .offset , jump_idx ),
190207 has_arg = True , opc = self .opc ))
191208 jump_idx += 1
0 commit comments