You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
NT call_function -> call 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_function', 'mkfunc',
|
unused_rhs = set(['build_list', 'call', 'mkfunc',
|
||||||
'mklambda',
|
'mklambda',
|
||||||
'unpack',])
|
'unpack',])
|
||||||
|
|
||||||
|
@@ -437,7 +437,7 @@ class PythonParser(GenericASTBuilder):
|
|||||||
expr ::= and
|
expr ::= and
|
||||||
expr ::= or
|
expr ::= or
|
||||||
expr ::= unary_expr
|
expr ::= unary_expr
|
||||||
expr ::= call_function
|
expr ::= call
|
||||||
expr ::= unary_not
|
expr ::= unary_not
|
||||||
expr ::= binary_subscr
|
expr ::= binary_subscr
|
||||||
expr ::= binary_subscr2
|
expr ::= binary_subscr2
|
||||||
|
@@ -320,7 +320,7 @@ class Python2Parser(PythonParser):
|
|||||||
args_kw = (v >> 8) & 0xff # keyword parameters
|
args_kw = (v >> 8) & 0xff # keyword parameters
|
||||||
# number of apply equiv arguments:
|
# number of apply equiv arguments:
|
||||||
nak = ( len(opname_base)-len('CALL_FUNCTION') ) // 3
|
nak = ( len(opname_base)-len('CALL_FUNCTION') ) // 3
|
||||||
rule = 'call_function ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
|
rule = 'call ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
|
||||||
+ 'expr ' * nak + opname
|
+ 'expr ' * nak + opname
|
||||||
elif opname_base == 'CALL_METHOD':
|
elif opname_base == 'CALL_METHOD':
|
||||||
# PyPy only - DRY with parse3
|
# PyPy only - DRY with parse3
|
||||||
@@ -328,7 +328,7 @@ class Python2Parser(PythonParser):
|
|||||||
args_kw = (v >> 8) & 0xff # keyword parameters
|
args_kw = (v >> 8) & 0xff # keyword parameters
|
||||||
# number of apply equiv arguments:
|
# number of apply equiv arguments:
|
||||||
nak = ( len(opname_base)-len('CALL_METHOD') ) // 3
|
nak = ( len(opname_base)-len('CALL_METHOD') ) // 3
|
||||||
rule = 'call_function ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
|
rule = 'call ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
|
||||||
+ 'expr ' * nak + opname
|
+ 'expr ' * nak + opname
|
||||||
elif opname == 'CONTINUE_LOOP':
|
elif opname == 'CONTINUE_LOOP':
|
||||||
self.add_unique_rule('continue_stmt ::= CONTINUE_LOOP',
|
self.add_unique_rule('continue_stmt ::= CONTINUE_LOOP',
|
||||||
|
@@ -119,7 +119,7 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
# Python3 introduced LOAD_BUILD_CLASS
|
# Python3 introduced LOAD_BUILD_CLASS
|
||||||
# Other definitions are in a custom rule
|
# Other definitions are in a custom rule
|
||||||
build_class ::= LOAD_BUILD_CLASS mkfunc expr call_function CALL_FUNCTION_3
|
build_class ::= LOAD_BUILD_CLASS mkfunc expr call CALL_FUNCTION_3
|
||||||
|
|
||||||
stmt ::= classdefdeco
|
stmt ::= classdefdeco
|
||||||
classdefdeco ::= classdefdeco1 designator
|
classdefdeco ::= classdefdeco1 designator
|
||||||
@@ -486,10 +486,10 @@ class Python3Parser(PythonParser):
|
|||||||
possible_class_decorator,
|
possible_class_decorator,
|
||||||
seen_GET_AWAITABLE_YIELD_FROM, next_token):
|
seen_GET_AWAITABLE_YIELD_FROM, next_token):
|
||||||
"""
|
"""
|
||||||
call_function ::= expr {expr}^n CALL_FUNCTION_n
|
call ::= expr {expr}^n CALL_FUNCTION_n
|
||||||
call_function ::= expr {expr}^n CALL_FUNCTION_VAR_n
|
call ::= expr {expr}^n CALL_FUNCTION_VAR_n
|
||||||
call_function ::= expr {expr}^n CALL_FUNCTION_VAR_KW_n
|
call ::= expr {expr}^n CALL_FUNCTION_VAR_KW_n
|
||||||
call_function ::= expr {expr}^n CALL_FUNCTION_KW_n
|
call ::= expr {expr}^n CALL_FUNCTION_KW_n
|
||||||
|
|
||||||
classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc {expr}^n-1 CALL_FUNCTION_n
|
classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc {expr}^n-1 CALL_FUNCTION_n
|
||||||
"""
|
"""
|
||||||
@@ -517,31 +517,31 @@ class Python3Parser(PythonParser):
|
|||||||
kw = 'expr '
|
kw = 'expr '
|
||||||
else:
|
else:
|
||||||
kw = ''
|
kw = ''
|
||||||
rule = ('call_function ::= expr expr ' +
|
rule = ('call ::= expr expr ' +
|
||||||
('pos_arg ' * args_pos) +
|
('pos_arg ' * args_pos) +
|
||||||
('kwarg ' * args_kw) + kw + token.kind)
|
('kwarg ' * args_kw) + kw + token.kind)
|
||||||
self.add_unique_rule(rule, token.kind, uniq_param, customize)
|
self.add_unique_rule(rule, token.kind, uniq_param, customize)
|
||||||
if self.version >= 3.6 and opname == 'CALL_FUNCTION_EX_KW':
|
if self.version >= 3.6 and opname == 'CALL_FUNCTION_EX_KW':
|
||||||
rule = ('call_function36 ::= '
|
rule = ('call36 ::= '
|
||||||
'expr build_tuple_unpack_with_call build_map_unpack_with_call '
|
'expr build_tuple_unpack_with_call build_map_unpack_with_call '
|
||||||
'CALL_FUNCTION_EX_KW_1')
|
'CALL_FUNCTION_EX_KW_1')
|
||||||
self.add_unique_rule(rule, token.kind, uniq_param, customize)
|
self.add_unique_rule(rule, token.kind, uniq_param, customize)
|
||||||
rule = 'call_function ::= call_function36'
|
rule = 'call ::= call36'
|
||||||
else:
|
else:
|
||||||
rule = ('call_function ::= expr ' +
|
rule = ('call ::= expr ' +
|
||||||
('pos_arg ' * args_pos) +
|
('pos_arg ' * args_pos) +
|
||||||
('kwarg ' * args_kw) +
|
('kwarg ' * args_kw) +
|
||||||
'expr ' * nak + token.kind)
|
'expr ' * nak + token.kind)
|
||||||
|
|
||||||
self.add_unique_rule(rule, token.kind, uniq_param, customize)
|
self.add_unique_rule(rule, token.kind, uniq_param, customize)
|
||||||
if self.version >= 3.5 and seen_GET_AWAITABLE_YIELD_FROM:
|
if self.version >= 3.5 and seen_GET_AWAITABLE_YIELD_FROM:
|
||||||
rule = ('async_call_function ::= expr ' +
|
rule = ('async_call ::= expr ' +
|
||||||
('pos_arg ' * args_pos) +
|
('pos_arg ' * args_pos) +
|
||||||
('kwarg ' * args_kw) +
|
('kwarg ' * args_kw) +
|
||||||
'expr ' * nak + token.kind +
|
'expr ' * nak + token.kind +
|
||||||
' GET_AWAITABLE LOAD_CONST YIELD_FROM')
|
' GET_AWAITABLE LOAD_CONST YIELD_FROM')
|
||||||
self.add_unique_rule(rule, token.kind, uniq_param, customize)
|
self.add_unique_rule(rule, token.kind, uniq_param, customize)
|
||||||
self.add_unique_rule('expr ::= async_call_function', token.kind, uniq_param, customize)
|
self.add_unique_rule('expr ::= async_call', token.kind, uniq_param, customize)
|
||||||
|
|
||||||
if possible_class_decorator:
|
if possible_class_decorator:
|
||||||
if next_token == 'CALL_FUNCTION' and next_token.attr == 1:
|
if next_token == 'CALL_FUNCTION' and next_token.attr == 1:
|
||||||
@@ -584,7 +584,7 @@ class Python3Parser(PythonParser):
|
|||||||
build_set ::= {expr}^n BUILD_SET_UNPACK_n
|
build_set ::= {expr}^n BUILD_SET_UNPACK_n
|
||||||
|
|
||||||
load_closure ::= {LOAD_CLOSURE}^n BUILD_TUPLE_n
|
load_closure ::= {LOAD_CLOSURE}^n BUILD_TUPLE_n
|
||||||
# call_function (see custom_classfunc_rule)
|
# call (see custom_classfunc_rule)
|
||||||
|
|
||||||
# ------------
|
# ------------
|
||||||
# Python <= 3.2 omits LOAD_CONST before MAKE_
|
# Python <= 3.2 omits LOAD_CONST before MAKE_
|
||||||
@@ -623,7 +623,7 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
For PYPY:
|
For PYPY:
|
||||||
load_attr ::= expr LOOKUP_METHOD
|
load_attr ::= expr LOOKUP_METHOD
|
||||||
call_function ::= expr CALL_METHOD
|
call ::= expr CALL_METHOD
|
||||||
"""
|
"""
|
||||||
seen_LOAD_BUILD_CLASS = False
|
seen_LOAD_BUILD_CLASS = False
|
||||||
seen_LOAD_DICTCOMP = False
|
seen_LOAD_DICTCOMP = False
|
||||||
@@ -770,7 +770,7 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
# number of apply equiv arguments:
|
# number of apply equiv arguments:
|
||||||
nak = ( len(opname_base)-len('CALL_METHOD') ) // 3
|
nak = ( len(opname_base)-len('CALL_METHOD') ) // 3
|
||||||
rule = ('call_function ::= expr ' +
|
rule = ('call ::= expr ' +
|
||||||
('pos_arg ' * args_pos) +
|
('pos_arg ' * args_pos) +
|
||||||
('kwarg ' * args_kw) +
|
('kwarg ' * args_kw) +
|
||||||
'expr ' * nak + opname)
|
'expr ' * nak + opname)
|
||||||
@@ -942,7 +942,7 @@ class Python3Parser(PythonParser):
|
|||||||
if self.version >= 3.6:
|
if self.version >= 3.6:
|
||||||
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST %s' %
|
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST %s' %
|
||||||
(('pos_arg ' * (args_pos)),
|
(('pos_arg ' * (args_pos)),
|
||||||
('call_function ' * (annotate_args-1)), opname))
|
('call ' * (annotate_args-1)), opname))
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST %s' %
|
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST %s' %
|
||||||
(('pos_arg ' * (args_pos)),
|
(('pos_arg ' * (args_pos)),
|
||||||
@@ -953,7 +953,7 @@ class Python3Parser(PythonParser):
|
|||||||
# Yes this is a little hacky
|
# Yes this is a little hacky
|
||||||
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
|
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
|
||||||
(('pos_arg ' * (args_pos)),
|
(('pos_arg ' * (args_pos)),
|
||||||
('call_function ' * (annotate_args-1)), opname))
|
('call ' * (annotate_args-1)), opname))
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
|
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
|
||||||
(('pos_arg ' * (args_pos)),
|
(('pos_arg ' * (args_pos)),
|
||||||
@@ -966,7 +966,7 @@ class Python3Parser(PythonParser):
|
|||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST EXTENDED_ARG %s' %
|
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST EXTENDED_ARG %s' %
|
||||||
(('pos_arg ' * (args_pos)),
|
(('pos_arg ' * (args_pos)),
|
||||||
('call_function ' * (annotate_args-1)), opname))
|
('call ' * (annotate_args-1)), opname))
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
elif opname_base in ('UNPACK_EX',):
|
elif opname_base in ('UNPACK_EX',):
|
||||||
before_count, after_count = token.attr
|
before_count, after_count = token.attr
|
||||||
|
@@ -157,7 +157,7 @@ class Python35Parser(Python34Parser):
|
|||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
call_token = tokens[i+1]
|
call_token = tokens[i+1]
|
||||||
if self.version == 3.5:
|
if self.version == 3.5:
|
||||||
rule = 'call_function ::= expr unmapexpr ' + call_token.kind
|
rule = 'call ::= expr unmapexpr ' + call_token.kind
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
@@ -24,14 +24,14 @@ class Python36Parser(Python35Parser):
|
|||||||
fstring_expr_or_strs ::= fstring_expr_or_str+
|
fstring_expr_or_strs ::= fstring_expr_or_str+
|
||||||
|
|
||||||
func_args36 ::= expr BUILD_TUPLE_0
|
func_args36 ::= expr BUILD_TUPLE_0
|
||||||
call_function ::= func_args36 unmapexpr CALL_FUNCTION_EX
|
call ::= func_args36 unmapexpr CALL_FUNCTION_EX
|
||||||
call_function ::= func_args36 build_map_unpack_with_call CALL_FUNCTION_EX_KW_1
|
call ::= func_args36 build_map_unpack_with_call CALL_FUNCTION_EX_KW_1
|
||||||
|
|
||||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST
|
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST
|
||||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||||
|
|
||||||
call_function ::= expr expr CALL_FUNCTION_EX
|
call ::= expr expr CALL_FUNCTION_EX
|
||||||
call_function ::= expr expr expr CALL_FUNCTION_EX_KW_1
|
call ::= expr expr expr CALL_FUNCTION_EX_KW_1
|
||||||
|
|
||||||
# This might be valid in < 3.6
|
# This might be valid in < 3.6
|
||||||
and ::= expr jmp_false expr
|
and ::= expr jmp_false expr
|
||||||
@@ -103,7 +103,7 @@ class Python36Parser(Python35Parser):
|
|||||||
seen_GET_AWAITABLE_YIELD_FROM, next_token):
|
seen_GET_AWAITABLE_YIELD_FROM, next_token):
|
||||||
if opname.startswith('CALL_FUNCTION_KW'):
|
if opname.startswith('CALL_FUNCTION_KW'):
|
||||||
values = 'expr ' * token.attr
|
values = 'expr ' * token.attr
|
||||||
rule = 'call_function ::= expr kwargs_only_36 {token.kind}'.format(**locals())
|
rule = 'call ::= expr kwargs_only_36 {token.kind}'.format(**locals())
|
||||||
self.add_unique_rule(rule, token.kind, token.attr, customize)
|
self.add_unique_rule(rule, token.kind, token.attr, customize)
|
||||||
rule = 'kwargs_only_36 ::= {values} LOAD_CONST'.format(**locals())
|
rule = 'kwargs_only_36 ::= {values} LOAD_CONST'.format(**locals())
|
||||||
self.add_unique_rule(rule, token.kind, token.attr, customize)
|
self.add_unique_rule(rule, token.kind, token.attr, customize)
|
||||||
|
@@ -288,7 +288,7 @@ MAP_R = (TABLE_R, -1)
|
|||||||
|
|
||||||
MAP = {
|
MAP = {
|
||||||
'stmt': MAP_R,
|
'stmt': MAP_R,
|
||||||
'call_function': MAP_R,
|
'call': MAP_R,
|
||||||
'del_stmt': MAP_R,
|
'del_stmt': MAP_R,
|
||||||
'designator': MAP_R,
|
'designator': MAP_R,
|
||||||
'exprlist': MAP_R0,
|
'exprlist': MAP_R0,
|
||||||
@@ -316,7 +316,7 @@ PRECEDENCE = {
|
|||||||
'slice3': 2,
|
'slice3': 2,
|
||||||
'buildslice2': 2,
|
'buildslice2': 2,
|
||||||
'buildslice3': 2,
|
'buildslice3': 2,
|
||||||
'call_function': 2,
|
'call': 2,
|
||||||
|
|
||||||
'BINARY_POWER': 4,
|
'BINARY_POWER': 4,
|
||||||
|
|
||||||
|
@@ -1623,10 +1623,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
# 2. subroutine calls. It the last op is the call and for purposes of printing
|
# 2. subroutine calls. It the last op is the call and for purposes of printing
|
||||||
# we don't need to print anything special there. However it encompases the
|
# we don't need to print anything special there. However it encompases the
|
||||||
# entire string of the node fn(...)
|
# entire string of the node fn(...)
|
||||||
match = re.search(r'^call_function', startnode.kind)
|
if startnode.kind == 'call':
|
||||||
if match:
|
|
||||||
last_node = startnode[-1]
|
last_node = startnode[-1]
|
||||||
# import traceback; traceback.print_stack()
|
|
||||||
self.set_pos_info(last_node, startnode_start, self.last_finish)
|
self.set_pos_info(last_node, startnode_start, self.last_finish)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@@ -435,21 +435,21 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
'trystmt36': ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
|
'trystmt36': ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
|
||||||
})
|
})
|
||||||
|
|
||||||
def n_async_call_function(node):
|
def n_async_call(node):
|
||||||
self.f.write('async ')
|
self.f.write('async ')
|
||||||
node.kind == 'call_function'
|
node.kind == 'call'
|
||||||
p = self.prec
|
p = self.prec
|
||||||
self.prec = 80
|
self.prec = 80
|
||||||
self.template_engine(('%c(%P)', 0,
|
self.template_engine(('%c(%P)', 0,
|
||||||
(1, -4, ', ', 100)), node)
|
(1, -4, ', ', 100)), node)
|
||||||
self.prec = p
|
self.prec = p
|
||||||
node.kind == 'async_call_function'
|
node.kind == 'async_call'
|
||||||
self.prune()
|
self.prune()
|
||||||
self.n_async_call_function = n_async_call_function
|
self.n_async_call = n_async_call
|
||||||
self.n_build_list_unpack = self.n_build_list
|
self.n_build_list_unpack = self.n_build_list
|
||||||
|
|
||||||
if version == 3.5:
|
if version == 3.5:
|
||||||
def n_call_function(node):
|
def n_call(node):
|
||||||
mapping = self._get_mapping(node)
|
mapping = self._get_mapping(node)
|
||||||
table = mapping[0]
|
table = mapping[0]
|
||||||
key = node
|
key = node
|
||||||
@@ -472,7 +472,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
args_pos = kwarg_pos
|
args_pos = kwarg_pos
|
||||||
kwarg_pos += 1
|
kwarg_pos += 1
|
||||||
self.default(node)
|
self.default(node)
|
||||||
self.n_call_function = n_call_function
|
self.n_call = n_call
|
||||||
|
|
||||||
def n_funcdef(node):
|
def n_funcdef(node):
|
||||||
if self.version == 3.6:
|
if self.version == 3.6:
|
||||||
|
Reference in New Issue
Block a user