Better CONTINUE detection on 3.x

Helps when line numbers have been stripped say in optimization
This commit is contained in:
rocky
2018-03-01 22:47:36 -05:00
parent 99d9beac76
commit 6807015526

View File

@@ -419,11 +419,21 @@ class Scanner3(Scanner):
target = self.get_target(inst.offset)
if target <= inst.offset:
next_opname = self.insts[i+1].opname
if (inst.offset in self.stmts and
# Continues include jumps to FOR_ITER that are not
# and the end of a block which follow with POP_BLOCK and COME_FROM_LOOP.
# If the JUMP_ABSOLUTE is ot a FOR_ITER and is followed by another JUMP_FORWARD
# then we'll take it as a "continue".
is_continue = (self.insts[self.offset2inst_index[target]]
.opname == 'FOR_ITER'
and self.insts[i+1].opname == 'JUMP_FORWARD')
if (is_continue or
(inst.offset in self.stmts and
(self.version != 3.0 or (hasattr(inst, 'linestart'))) and
(next_opname not in ('END_FINALLY', 'POP_BLOCK',
# Python 3.0 only uses POP_TOP
'POP_TOP'))):
'POP_TOP')))):
opname = 'CONTINUE'
else:
opname = 'JUMP_BACK'