From eebec483083dc552b6476edd72b211c6ab93705e Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 17 Dec 2016 08:01:25 -0500 Subject: [PATCH] show-asm on python2.5 is optional make scanner2 look a little more like scanner3 --- uncompyle6/scanners/scanner2.py | 19 ++++++++++++++++--- uncompyle6/scanners/scanner25.py | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index 6ba44029..1ffbf95f 100644 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -742,7 +742,7 @@ class Scanner2(scan.Scanner): else: if (self.version < 2.7 and parent['type'] in ('root', 'for-loop', 'if-then', - 'if-else', 'try')): + 'else', 'try')): self.fixed_jumps[offset] = rtarget else: # note test for < 2.7 might be superflous although informative @@ -795,7 +795,20 @@ class Scanner2(scan.Scanner): else: rtarget = pre[rtarget] - # Does the "if" jump just beyond a jump op, then this is probably an if statement + # Does the "jump if" jump beyond a jump op? + # That is, we have something like: + # POP_JUMP_IF_FALSE HERE + # ... + # JUMP_FORWARD + # HERE: + # + # If so, this can be block inside an "if" statement + # or a conditional assignment like: + # x = 1 if x else 2 + # + # There are other contexts we may need to consider + # like whether the target is "END_FINALLY" + # or if the condition jump is to a forward location pre_rtarget = pre[rtarget] code_pre_rtarget = code[pre_rtarget] @@ -830,7 +843,7 @@ class Scanner2(scan.Scanner): self.not_continue.add(pre_rtarget) if rtarget < end: - self.structs.append({'type': 'if-else', + self.structs.append({'type': 'else', 'start': rtarget, 'end': end}) elif code_pre_rtarget == self.opc.RETURN_VALUE: diff --git a/uncompyle6/scanners/scanner25.py b/uncompyle6/scanners/scanner25.py index 446f5091..c270d003 100755 --- a/uncompyle6/scanners/scanner25.py +++ b/uncompyle6/scanners/scanner25.py @@ -18,7 +18,7 @@ JUMP_OPs = opcode_25.JUMP_OPs # The history is that 2.7 support is the cleanest, # then from that we got 2.6 and so on. class Scanner25(scan.Scanner26): - def __init__(self, show_asm): + def __init__(self, show_asm=False): # There are no differences in initialization between # 2.5 and 2.6 self.opc = opcode_25