You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 08:49:51 +08:00
Track recent lc changes in fragment semantics
This commit is contained in:
Binary file not shown.
@@ -1,4 +1,7 @@
|
|||||||
# Tests bug in Python 3
|
# Tests closure bug in Python 3
|
||||||
|
|
||||||
|
# Note also check that *args, and **kwds are preserved
|
||||||
|
# on the call!
|
||||||
|
|
||||||
# load_closure ::= LOAD_CLOSURE BUILD_TUPLE_1
|
# load_closure ::= LOAD_CLOSURE BUILD_TUPLE_1
|
||||||
|
|
||||||
|
@@ -53,8 +53,6 @@ class Python3Parser(PythonParser):
|
|||||||
list_for ::= expr FOR_ITER designator list_iter JUMP_BACK
|
list_for ::= expr FOR_ITER designator list_iter JUMP_BACK
|
||||||
|
|
||||||
# See also common Python p_list_comprehension
|
# See also common Python p_list_comprehension
|
||||||
|
|
||||||
load_closure ::= LOAD_CLOSURE BUILD_TUPLE_1
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_setcomp3(self, args):
|
def p_setcomp3(self, args):
|
||||||
@@ -432,6 +430,9 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
build_list ::= {expr}^n BUILD_LIST_n
|
build_list ::= {expr}^n BUILD_LIST_n
|
||||||
build_list ::= {expr}^n BUILD_TUPLE_n
|
build_list ::= {expr}^n BUILD_TUPLE_n
|
||||||
|
|
||||||
|
load_closure ::= {LOAD_CLOSURE}^n BUILD_TUPLE_n
|
||||||
|
|
||||||
unpack_list ::= UNPACK_LIST {expr}^n
|
unpack_list ::= UNPACK_LIST {expr}^n
|
||||||
unpack ::= UNPACK_TUPLE {expr}^n
|
unpack ::= UNPACK_TUPLE {expr}^n
|
||||||
unpack ::= UNPACK_SEQEUENCE {expr}^n
|
unpack ::= UNPACK_SEQEUENCE {expr}^n
|
||||||
@@ -468,6 +469,10 @@ class Python3Parser(PythonParser):
|
|||||||
rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) +
|
rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) +
|
||||||
'expr32 ' * int((v//32)%32) + 'expr '*(v%32) + opname)
|
'expr32 ' * int((v//32)%32) + 'expr '*(v%32) + opname)
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
|
if opname_base == 'BUILD_TUPLE':
|
||||||
|
rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname))
|
||||||
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
|
|
||||||
elif self.version >= 3.5 and opname_base == 'BUILD_MAP':
|
elif self.version >= 3.5 and opname_base == 'BUILD_MAP':
|
||||||
kvlist_n = "kvlist_%s" % token.attr
|
kvlist_n = "kvlist_%s" % token.attr
|
||||||
rule = kvlist_n + ' ::= ' + 'expr ' * (token.attr*2)
|
rule = kvlist_n + ' ::= ' + 'expr ' * (token.attr*2)
|
||||||
|
@@ -550,8 +550,9 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
|
|
||||||
n = ast[iter_index]
|
n = ast[iter_index]
|
||||||
assert n == 'list_iter'
|
assert n == 'list_iter'
|
||||||
|
|
||||||
# find innermost node
|
# find innermost node
|
||||||
while n == 'list_iter': # list_iter
|
while n == 'list_iter':
|
||||||
n = n[0] # recurse one step
|
n = n[0] # recurse one step
|
||||||
if n == 'list_for':
|
if n == 'list_for':
|
||||||
designator = n[2]
|
designator = n[2]
|
||||||
@@ -580,6 +581,59 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
# self.preorder(ast[iter_index])
|
# self.preorder(ast[iter_index])
|
||||||
self.prec = p
|
self.prec = p
|
||||||
|
|
||||||
|
def listcomprehension_walk2(self, node):
|
||||||
|
"""List comprehensions the way they are done in Python3.
|
||||||
|
They're more other comprehensions, e.g. set comprehensions
|
||||||
|
See if we can combine code.
|
||||||
|
"""
|
||||||
|
p = self.prec
|
||||||
|
self.prec = 27
|
||||||
|
|
||||||
|
code = Code(node[1].attr, self.scanner, self.currentclass)
|
||||||
|
ast = self.build_ast(code._tokens, code._customize)
|
||||||
|
self.customize(code._customize)
|
||||||
|
ast = ast[0][0][0][0][0]
|
||||||
|
|
||||||
|
n = ast[1]
|
||||||
|
collection = node[-3]
|
||||||
|
list_if = None
|
||||||
|
assert n == 'list_iter'
|
||||||
|
|
||||||
|
# find innermost node
|
||||||
|
while n == 'list_iter':
|
||||||
|
n = n[0] # recurse one step
|
||||||
|
if n == 'list_for':
|
||||||
|
designator = n[2]
|
||||||
|
n = n[3]
|
||||||
|
elif n in ('list_if', 'list_if_not'):
|
||||||
|
# FIXME: just a guess
|
||||||
|
if n[0].type == 'expr':
|
||||||
|
list_if = n
|
||||||
|
else:
|
||||||
|
list_if = n[1]
|
||||||
|
n = n[2]
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
assert n == 'lc_body', ast
|
||||||
|
|
||||||
|
self.preorder(n[0])
|
||||||
|
self.write(' for ')
|
||||||
|
start = len(self.f.getvalue())
|
||||||
|
self.preorder(designator)
|
||||||
|
self.set_pos_info(designator, start, len(self.f.getvalue()))
|
||||||
|
self.write(' in ')
|
||||||
|
start = len(self.f.getvalue())
|
||||||
|
node[-3].parent = node
|
||||||
|
self.preorder(collection)
|
||||||
|
self.set_pos_info(collection, start, len(self.f.getvalue()))
|
||||||
|
if list_if:
|
||||||
|
start = len(self.f.getvalue())
|
||||||
|
self.preorder(list_if)
|
||||||
|
self.set_pos_info(list_if, start, len(self.f.getvalue()))
|
||||||
|
|
||||||
|
self.prec = p
|
||||||
|
|
||||||
def n_genexpr(self, node):
|
def n_genexpr(self, node):
|
||||||
start = len(self.f.getvalue())
|
start = len(self.f.getvalue())
|
||||||
self.write('(')
|
self.write('(')
|
||||||
|
@@ -1047,8 +1047,9 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
|
|
||||||
n = ast[iter_index]
|
n = ast[iter_index]
|
||||||
assert n == 'list_iter'
|
assert n == 'list_iter'
|
||||||
|
|
||||||
# find innermost node
|
# find innermost node
|
||||||
while n == 'list_iter': # list_iter
|
while n == 'list_iter':
|
||||||
n = n[0] # recurse one step
|
n = n[0] # recurse one step
|
||||||
if n == 'list_for':
|
if n == 'list_for':
|
||||||
designator = n[2]
|
designator = n[2]
|
||||||
@@ -1087,7 +1088,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
assert n == 'list_iter'
|
assert n == 'list_iter'
|
||||||
|
|
||||||
# find innermost node
|
# find innermost node
|
||||||
while n == 'list_iter': # list_iter
|
while n == 'list_iter':
|
||||||
n = n[0] # recurse one step
|
n = n[0] # recurse one step
|
||||||
if n == 'list_for':
|
if n == 'list_for':
|
||||||
designator = n[2]
|
designator = n[2]
|
||||||
|
Reference in New Issue
Block a user