show-asm on python2.5 is optional

make scanner2 look a little more like scanner3
This commit is contained in:
rocky
2016-12-17 08:01:25 -05:00
parent da50394841
commit eebec48308
2 changed files with 17 additions and 4 deletions

View File

@@ -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:

View File

@@ -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