From 680701552677bbec4f1ffe7d7c3af95b4732927b Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 1 Mar 2018 22:47:36 -0500 Subject: [PATCH] Better CONTINUE detection on 3.x Helps when line numbers have been stripped say in optimization --- uncompyle6/scanners/scanner3.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index 3253139b..c2580e61 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -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'