Better "continue" detection for 2.7

This commit is contained in:
rocky
2018-03-01 23:34:26 -05:00
parent 6807015526
commit 26e1df835c
2 changed files with 18 additions and 5 deletions

View File

@@ -291,8 +291,21 @@ class Scanner2(Scanner):
target = self.get_target(offset)
if target <= offset:
op_name = 'JUMP_BACK'
if (offset in self.stmts
and self.code[offset+3] not in (self.opc.END_FINALLY,
# 'Continue's include jumps to loops that are not
# and the end of a block which follow with POP_BLOCK and COME_FROM_LOOP.
# If the JUMP_ABSOLUTE is
# either to a FOR_ITER or the instruction after a SETUP_LOOP
# and it is followed by another JUMP_FORWARD
# then we'll take it as a "continue".
j = self.offset2inst_index[offset]
target_index = self.offset2inst_index[target]
is_continue = (self.insts[target_index-1].opname == 'SETUP_LOOP'
and self.insts[j+1].opname == 'JUMP_FORWARD') and False
if is_continue:
op_name = 'CONTINUE'
if (offset in self.stmts and
self.code[offset+3] not in (self.opc.END_FINALLY,
self.opc.POP_BLOCK)):
if ((offset in self.linestartoffsets and
self.code[self.prev[offset]] == self.opc.JUMP_ABSOLUTE)

View File

@@ -420,9 +420,9 @@ class Scanner3(Scanner):
if target <= inst.offset:
next_opname = self.insts[i+1].opname
# Continues include jumps to FOR_ITER that are not
# 'Continue's include jumps to loops 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
# If the JUMP_ABSOLUTE is to a FOR_ITER and it 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'