You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 08:49:51 +08:00
verify scanner2 vs scanner3 small changes...
verify.py: allow LOAD_CONST None to make LOAD_NAME 'None' scanner{2,3}.py: make them look more alike
This commit is contained in:
@@ -25,6 +25,7 @@ from __future__ import print_function
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from array import array
|
from array import array
|
||||||
|
|
||||||
|
from uncompyle6.scanner import op_has_argument
|
||||||
from xdis.code import iscode
|
from xdis.code import iscode
|
||||||
|
|
||||||
import uncompyle6.scanner as scan
|
import uncompyle6.scanner as scan
|
||||||
@@ -175,7 +176,7 @@ class Scanner2(scan.Scanner):
|
|||||||
opname = self.opc.opname[op]
|
opname = self.opc.opname[op]
|
||||||
|
|
||||||
oparg = None; pattr = None
|
oparg = None; pattr = None
|
||||||
has_arg = (op >= self.opc.HAVE_ARGUMENT)
|
has_arg = op_has_argument(op, self.opc)
|
||||||
if has_arg:
|
if has_arg:
|
||||||
oparg = self.get_argument(offset) + extended_arg
|
oparg = self.get_argument(offset) + extended_arg
|
||||||
extended_arg = 0
|
extended_arg = 0
|
||||||
@@ -814,20 +815,23 @@ class Scanner2(scan.Scanner):
|
|||||||
self.fixed_jumps[pos] = self.restrict_to_parent(target, parent)
|
self.fixed_jumps[pos] = self.restrict_to_parent(target, parent)
|
||||||
|
|
||||||
def find_jump_targets(self):
|
def find_jump_targets(self):
|
||||||
'''
|
"""
|
||||||
Detect all offsets in a byte code which are jump targets
|
Detect all offsets in a byte code which are jump targets
|
||||||
where we might insert a COME_FROM instruction.
|
where we might insert a COME_FROM instruction.
|
||||||
|
|
||||||
Return the list of offsets. An instruction can be jumped
|
Return the list of offsets. An instruction can be jumped
|
||||||
to in from multiple instructions.
|
to in from multiple instructions.
|
||||||
'''
|
"""
|
||||||
|
code = self.code
|
||||||
n = len(self.code)
|
n = len(code)
|
||||||
self.structs = [{'type': 'root',
|
self.structs = [{'type': 'root',
|
||||||
'start': 0,
|
'start': 0,
|
||||||
'end': n-1}]
|
'end': n-1}]
|
||||||
self.loops = [] # All loop entry points
|
# All loop entry points
|
||||||
self.fixed_jumps = {} # Map fixed jumps to their real destination
|
self.loops = []
|
||||||
|
|
||||||
|
# Map fixed jumps to their real destination
|
||||||
|
self.fixed_jumps = {}
|
||||||
self.ignore_if = set()
|
self.ignore_if = set()
|
||||||
self.build_stmt_indices()
|
self.build_stmt_indices()
|
||||||
|
|
||||||
@@ -837,13 +841,13 @@ class Scanner2(scan.Scanner):
|
|||||||
|
|
||||||
targets = {}
|
targets = {}
|
||||||
for offset in self.op_range(0, n):
|
for offset in self.op_range(0, n):
|
||||||
op = self.code[offset]
|
op = code[offset]
|
||||||
|
|
||||||
# Determine structures and fix jumps in Python versions
|
# Determine structures and fix jumps in Python versions
|
||||||
# since 2.3
|
# since 2.3
|
||||||
self.detect_structure(offset, op)
|
self.detect_structure(offset, op)
|
||||||
|
|
||||||
if op >= self.opc.HAVE_ARGUMENT:
|
if op_has_argument(op, self.opc):
|
||||||
label = self.fixed_jumps.get(offset)
|
label = self.fixed_jumps.get(offset)
|
||||||
oparg = self.get_argument(offset)
|
oparg = self.get_argument(offset)
|
||||||
|
|
||||||
@@ -867,16 +871,16 @@ class Scanner2(scan.Scanner):
|
|||||||
# does now start a new statement
|
# does now start a new statement
|
||||||
# Otherwise, we have want to add a "COME_FROM"
|
# Otherwise, we have want to add a "COME_FROM"
|
||||||
if not (self.version < 2.7 and
|
if not (self.version < 2.7 and
|
||||||
self.code[label] == self.opc.POP_TOP and
|
code[label] == self.opc.POP_TOP and
|
||||||
self.code[self.prev[label]] == self.opc.RETURN_VALUE):
|
code[self.prev[label]] == self.opc.RETURN_VALUE):
|
||||||
# In Python < 2.7, don't add a COME_FROM, for:
|
# In Python < 2.7, don't add a COME_FROM, for:
|
||||||
# JUMP_FORWARD, END_FINALLY
|
# JUMP_FORWARD, END_FINALLY
|
||||||
# or:
|
# or:
|
||||||
# JUMP_FORWARD, POP_TOP, END_FINALLY
|
# JUMP_FORWARD, POP_TOP, END_FINALLY
|
||||||
if not (self.version < 2.7 and op == self.opc.JUMP_FORWARD
|
if not (self.version < 2.7 and op == self.opc.JUMP_FORWARD
|
||||||
and ((self.code[offset+3] == self.opc.END_FINALLY)
|
and ((code[offset+3] == self.opc.END_FINALLY)
|
||||||
or (self.code[offset+3] == self.opc.POP_TOP
|
or (code[offset+3] == self.opc.POP_TOP
|
||||||
and self.code[offset+4] == self.opc.END_FINALLY))):
|
and code[offset+4] == self.opc.END_FINALLY))):
|
||||||
|
|
||||||
# FIXME: rocky: I think we need something like this...
|
# FIXME: rocky: I think we need something like this...
|
||||||
if offset not in set(self.ignore_if) or self.version == 2.7:
|
if offset not in set(self.ignore_if) or self.version == 2.7:
|
||||||
|
@@ -403,12 +403,13 @@ class Scanner3(Scanner):
|
|||||||
|
|
||||||
def find_jump_targets(self):
|
def find_jump_targets(self):
|
||||||
"""
|
"""
|
||||||
Detect all offsets in a byte code which are jump targets.
|
Detect all offsets in a byte code which are jump targets
|
||||||
|
where we might insert a COME_FROM instruction.
|
||||||
|
|
||||||
Return the list of offsets.
|
Return the list of offsets.
|
||||||
|
|
||||||
This procedure is modelled after dis.findlabels(), but here
|
Return the list of offsets. An instruction can be jumped
|
||||||
for each target the number of jumps is counted.
|
to in from multiple instructions.
|
||||||
"""
|
"""
|
||||||
code = self.code
|
code = self.code
|
||||||
n = len(code)
|
n = len(code)
|
||||||
|
@@ -316,9 +316,12 @@ def cmp_code_objects(version, is_pypy, code_obj1, code_obj2,
|
|||||||
i1 += 2
|
i1 += 2
|
||||||
i2 += 2
|
i2 += 2
|
||||||
continue
|
continue
|
||||||
|
elif tokens1[i1].type == 'LOAD_NAME' and tokens2[i2].type == 'LOAD_CONST' \
|
||||||
raise CmpErrorCode(name, tokens1[i1].offset, tokens1[i1],
|
and tokens1[i1].pattr == 'None' and tokens2[i2].pattr == None:
|
||||||
tokens2[i2], tokens1, tokens2)
|
pass
|
||||||
|
else:
|
||||||
|
raise CmpErrorCode(name, tokens1[i1].offset, tokens1[i1],
|
||||||
|
tokens2[i2], tokens1, tokens2)
|
||||||
elif tokens1[i1].type in JUMP_OPs and tokens1[i1].pattr != tokens2[i2].pattr:
|
elif tokens1[i1].type in JUMP_OPs and tokens1[i1].pattr != tokens2[i2].pattr:
|
||||||
dest1 = int(tokens1[i1].pattr)
|
dest1 = int(tokens1[i1].pattr)
|
||||||
dest2 = int(tokens2[i2].pattr)
|
dest2 = int(tokens2[i2].pattr)
|
||||||
|
Reference in New Issue
Block a user