You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
NT build_list -> list to match AST
This commit is contained in:
@@ -17,7 +17,7 @@ def test_grammar():
|
|||||||
(lhs, rhs, tokens,
|
(lhs, rhs, tokens,
|
||||||
right_recursive, dup_rhs) = p.check_sets()
|
right_recursive, dup_rhs) = p.check_sets()
|
||||||
expect_lhs = set(['expr1024', 'pos_arg'])
|
expect_lhs = set(['expr1024', 'pos_arg'])
|
||||||
unused_rhs = set(['build_list', 'call', 'mkfunc',
|
unused_rhs = set(['list', 'call', 'mkfunc',
|
||||||
'mklambda',
|
'mklambda',
|
||||||
'unpack',])
|
'unpack',])
|
||||||
|
|
||||||
|
@@ -435,7 +435,7 @@ class PythonParser(GenericASTBuilder):
|
|||||||
expr ::= LOAD_DEREF
|
expr ::= LOAD_DEREF
|
||||||
expr ::= load_attr
|
expr ::= load_attr
|
||||||
expr ::= binary_expr
|
expr ::= binary_expr
|
||||||
expr ::= build_list
|
expr ::= list
|
||||||
expr ::= compare
|
expr ::= compare
|
||||||
expr ::= dict
|
expr ::= dict
|
||||||
expr ::= and
|
expr ::= and
|
||||||
|
@@ -226,8 +226,8 @@ class Python2Parser(PythonParser):
|
|||||||
Special handling for opcodes such as those that take a variable number
|
Special handling for opcodes such as those that take a variable number
|
||||||
of arguments -- we add a new rule for each:
|
of arguments -- we add a new rule for each:
|
||||||
|
|
||||||
build_list ::= {expr}^n BUILD_LIST_n
|
list ::= {expr}^n BUILD_LIST_n
|
||||||
build_list ::= {expr}^n BUILD_TUPLE_n
|
list ::= {expr}^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
|
||||||
@@ -277,7 +277,7 @@ class Python2Parser(PythonParser):
|
|||||||
self.add_unique_rule("expr1024 ::=%s" % (' expr32' * 32),
|
self.add_unique_rule("expr1024 ::=%s" % (' expr32' * 32),
|
||||||
opname_base, v, customize)
|
opname_base, v, customize)
|
||||||
self.seen1024 = True
|
self.seen1024 = True
|
||||||
rule = ('build_list ::= ' + 'expr1024 '*thousands +
|
rule = ('list ::= ' + 'expr1024 '*thousands +
|
||||||
'expr32 '*thirty32s + 'expr '*(v % 32) + opname)
|
'expr32 '*thirty32s + 'expr '*(v % 32) + opname)
|
||||||
elif opname_base == 'BUILD_MAP':
|
elif opname_base == 'BUILD_MAP':
|
||||||
if opname == 'BUILD_MAP_n':
|
if opname == 'BUILD_MAP_n':
|
||||||
|
@@ -563,14 +563,14 @@ class Python3Parser(PythonParser):
|
|||||||
# Even the below say _list, in the semantic rules we
|
# Even the below say _list, in the semantic rules we
|
||||||
# disambiguate tuples, and sets from lists
|
# disambiguate tuples, and sets from lists
|
||||||
|
|
||||||
build_list ::= {expr}^n BUILD_LIST_n
|
list ::= {expr}^n BUILD_LIST_n
|
||||||
build_list ::= {expr}^n BUILD_TUPLE_n
|
list ::= {expr}^n BUILD_TUPLE_n
|
||||||
build_list ::= {expr}^n BUILD_LIST_UNPACK_n
|
list ::= {expr}^n BUILD_LIST_UNPACK_n
|
||||||
build_list ::= {expr}^n BUILD_TUPLE_UNPACK_n
|
list ::= {expr}^n BUILD_TUPLE_UNPACK_n
|
||||||
|
|
||||||
# FIXME:
|
# FIXME:
|
||||||
build_list ::= {expr}^n BUILD_SET_n
|
list ::= {expr}^n BUILD_SET_n
|
||||||
build_list ::= {expr}^n BUILD_SET_UNPACK_n
|
list ::= {expr}^n BUILD_SET_UNPACK_n
|
||||||
should be
|
should be
|
||||||
build_set ::= {expr}^n BUILD_SET_n
|
build_set ::= {expr}^n BUILD_SET_n
|
||||||
build_set ::= {expr}^n BUILD_SET_UNPACK_n
|
build_set ::= {expr}^n BUILD_SET_UNPACK_n
|
||||||
@@ -712,7 +712,7 @@ class Python3Parser(PythonParser):
|
|||||||
is_LOAD_CLOSURE = False
|
is_LOAD_CLOSURE = False
|
||||||
if opname_base == 'BUILD_TUPLE':
|
if opname_base == 'BUILD_TUPLE':
|
||||||
# If is part of a "load_closure", then it is not part of a
|
# If is part of a "load_closure", then it is not part of a
|
||||||
# "build_list".
|
# "list".
|
||||||
is_LOAD_CLOSURE = True
|
is_LOAD_CLOSURE = True
|
||||||
for j in range(v):
|
for j in range(v):
|
||||||
if tokens[i-j-1].kind != 'LOAD_CLOSURE':
|
if tokens[i-j-1].kind != 'LOAD_CLOSURE':
|
||||||
@@ -722,9 +722,9 @@ class Python3Parser(PythonParser):
|
|||||||
rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname))
|
rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname))
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
if not is_LOAD_CLOSURE or v == 0:
|
if not is_LOAD_CLOSURE or v == 0:
|
||||||
rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) +
|
rule = ('list ::= ' + 'expr1024 ' * int(v//1024) +
|
||||||
'expr32 ' * int((v//32) % 32) +
|
'expr32 ' * int((v//32) % 32) +
|
||||||
'expr ' * (v % 32) + opname)
|
'expr ' * (v % 32) + opname)
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
continue
|
continue
|
||||||
elif opname_base == 'BUILD_SLICE':
|
elif opname_base == 'BUILD_SLICE':
|
||||||
|
@@ -297,7 +297,7 @@ MAP = {
|
|||||||
# or https://docs.python.org/3/reference/expressions.html
|
# or https://docs.python.org/3/reference/expressions.html
|
||||||
# for a list.
|
# for a list.
|
||||||
PRECEDENCE = {
|
PRECEDENCE = {
|
||||||
'build_list': 0,
|
'list': 0,
|
||||||
'dict': 0,
|
'dict': 0,
|
||||||
'unary_convert': 0,
|
'unary_convert': 0,
|
||||||
'dict_comp': 0,
|
'dict_comp': 0,
|
||||||
|
@@ -1397,7 +1397,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
self.prec = p
|
self.prec = p
|
||||||
self.prune()
|
self.prune()
|
||||||
|
|
||||||
def n_build_list(self, node):
|
def n_list(self, node):
|
||||||
"""
|
"""
|
||||||
prettyprint a list or tuple
|
prettyprint a list or tuple
|
||||||
"""
|
"""
|
||||||
@@ -1415,7 +1415,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
elif lastnode.startswith('ROT_TWO'):
|
elif lastnode.startswith('ROT_TWO'):
|
||||||
self.write('('); endchar = ')'
|
self.write('('); endchar = ')'
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Internal Error: n_build_list expects list or tuple')
|
raise RuntimeError('Internal Error: n_list expects list or tuple')
|
||||||
|
|
||||||
flat_elems = []
|
flat_elems = []
|
||||||
for elem in node:
|
for elem in node:
|
||||||
@@ -1828,7 +1828,7 @@ if __name__ == '__main__':
|
|||||||
# deparse_test(get_code_for_fn(gcd))
|
# deparse_test(get_code_for_fn(gcd))
|
||||||
# deparse_test(get_code_for_fn(test))
|
# deparse_test(get_code_for_fn(test))
|
||||||
# deparse_test(get_code_for_fn(FragmentsWalker.fixup_offsets))
|
# deparse_test(get_code_for_fn(FragmentsWalker.fixup_offsets))
|
||||||
# deparse_test(get_code_for_fn(FragmentsWalker.n_build_list))
|
# deparse_test(get_code_for_fn(FragmentsWalker.n_list))
|
||||||
print('=' * 30)
|
print('=' * 30)
|
||||||
deparse_test_around(408, 'n_build_list', get_code_for_fn(FragmentsWalker.n_build_list))
|
deparse_test_around(408, 'n_list', get_code_for_fn(FragmentsWalker.n_build_list))
|
||||||
# deparse_test(inspect.currentframe().f_code)
|
# deparse_test(inspect.currentframe().f_code)
|
||||||
|
@@ -446,7 +446,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
node.kind == 'async_call'
|
node.kind == 'async_call'
|
||||||
self.prune()
|
self.prune()
|
||||||
self.n_async_call = n_async_call
|
self.n_async_call = n_async_call
|
||||||
self.n_build_list_unpack = self.n_build_list
|
self.n_build_list_unpack = self.n_list
|
||||||
|
|
||||||
if version == 3.5:
|
if version == 3.5:
|
||||||
def n_call(node):
|
def n_call(node):
|
||||||
@@ -1537,7 +1537,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
n_classdefdeco2 = n_classdef
|
n_classdefdeco2 = n_classdef
|
||||||
|
|
||||||
def print_super_classes(self, node):
|
def print_super_classes(self, node):
|
||||||
if not (node == 'build_list'):
|
if not (node == 'list'):
|
||||||
return
|
return
|
||||||
|
|
||||||
n_subclasses = len(node[:-1])
|
n_subclasses = len(node[:-1])
|
||||||
@@ -1737,7 +1737,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.prec = p
|
self.prec = p
|
||||||
self.prune()
|
self.prune()
|
||||||
|
|
||||||
def n_build_list(self, node):
|
def n_list(self, node):
|
||||||
"""
|
"""
|
||||||
prettyprint a list or tuple
|
prettyprint a list or tuple
|
||||||
"""
|
"""
|
||||||
@@ -1828,7 +1828,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.prune()
|
self.prune()
|
||||||
return
|
return
|
||||||
|
|
||||||
n_build_set = n_build_list
|
n_build_set = n_list
|
||||||
|
|
||||||
def n_unpack(self, node):
|
def n_unpack(self, node):
|
||||||
if node[0].kind.startswith('UNPACK_EX'):
|
if node[0].kind.startswith('UNPACK_EX'):
|
||||||
@@ -2057,7 +2057,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
pass
|
pass
|
||||||
# handled by n_dict:
|
# handled by n_dict:
|
||||||
# if op == 'BUILD_SLICE': TABLE_R[k] = ('%C' , (0,-1,':'))
|
# if op == 'BUILD_SLICE': TABLE_R[k] = ('%C' , (0,-1,':'))
|
||||||
# handled by n_build_list:
|
# handled by n_list:
|
||||||
# if op == 'BUILD_LIST': TABLE_R[k] = ('[%C]' , (0,-1,', '))
|
# if op == 'BUILD_LIST': TABLE_R[k] = ('[%C]' , (0,-1,', '))
|
||||||
# elif op == 'BUILD_TUPLE': TABLE_R[k] = ('(%C%,)', (0,-1,', '))
|
# elif op == 'BUILD_TUPLE': TABLE_R[k] = ('(%C%,)', (0,-1,', '))
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user