From 26e1df835c639f975f48326b1b08abe6691b7130 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 1 Mar 2018 23:34:26 -0500 Subject: [PATCH] Better "continue" detection for 2.7 --- uncompyle6/scanners/scanner2.py | 19 ++++++++++++++++--- uncompyle6/scanners/scanner3.py | 4 ++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index a5627077..2fb6f207 100644 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -291,9 +291,22 @@ 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, - self.opc.POP_BLOCK)): + + # '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) or self.code[target] == self.opc.FOR_ITER diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index c2580e61..922c739b 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -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'