From 11e2637eebf3c256d3235fc72f1d32741f99e5cc Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 29 Nov 2017 10:51:38 -0500 Subject: [PATCH] NT augassign -> aug_assign to match AST --- test/simple_source/bug22/01_ops.py | 2 +- test/simple_source/bug30/01_ops.py | 2 +- test/simple_source/stmts/01_augmented_assign.py | 4 ++-- uncompyle6/parser.py | 17 +++++++++-------- uncompyle6/parsers/parse2.py | 14 +++++++------- uncompyle6/parsers/parse3.py | 6 +++--- uncompyle6/semantics/check_ast.py | 2 +- uncompyle6/semantics/consts.py | 4 ++-- uncompyle6/semantics/fragments.py | 2 +- 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/test/simple_source/bug22/01_ops.py b/test/simple_source/bug22/01_ops.py index 4f97eadd..18efd99e 100644 --- a/test/simple_source/bug22/01_ops.py +++ b/test/simple_source/bug22/01_ops.py @@ -12,7 +12,7 @@ y ^= 1 # INPLACE_XOR `y` # UNARY_CONVERT - No in Python 3.x -# Beef up augassign and STORE_SLICE+3 +# Beef up aug_assign and STORE_SLICE+3 x = [1,2,3,4,5] x[0:1] = 1 x[0:3] += 1, 2, 3 diff --git a/test/simple_source/bug30/01_ops.py b/test/simple_source/bug30/01_ops.py index 2c3a4a80..3e03ca0b 100644 --- a/test/simple_source/bug30/01_ops.py +++ b/test/simple_source/bug30/01_ops.py @@ -10,7 +10,7 @@ y //= 1 # INPLACE_TRUE_DIVIDE y &= 1 # INPLACE_AND y ^= 1 # INPLACE_XOR -# Beef up augassign and STORE_SLICE+3 +# Beef up aug_assign and STORE_SLICE+3 x = [1,2,3,4,5] x[0:1] = 1 x[0:3] += 1, 2, 3 diff --git a/test/simple_source/stmts/01_augmented_assign.py b/test/simple_source/stmts/01_augmented_assign.py index a91f7279..5d279816 100644 --- a/test/simple_source/stmts/01_augmented_assign.py +++ b/test/simple_source/stmts/01_augmented_assign.py @@ -26,11 +26,11 @@ l[1][2][3] = 7 l[1][2][3] *= 3; # Python 2.x -# augassign1 ::= expr expr inplace_op ROT_TWO STORE_SLICE+0 +# aug_assign1 ::= expr expr inplace_op ROT_TWO STORE_SLICE+0 l[:] += [9]; # print l # Python 2.x -# augassign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+2 +# aug_assign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+2 l[:2] += [9]; # print l diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 784f6379..dd20bdf2 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -319,17 +319,18 @@ class PythonParser(GenericASTBuilder): def p_augmented_assign(self, args): ''' - stmt ::= augassign1 - stmt ::= augassign2 + stmt ::= aug_assign1 + stmt ::= aug_assign2 - # This is odd in that other augassign1's have only 3 slots + # This is odd in that other aug_assign1's have only 3 slots # The store isn't used as that's supposed to be also # indicated in the first expr - augassign1 ::= expr expr inplace_op store - - augassign1 ::= expr expr inplace_op ROT_THREE STORE_SUBSCR - augassign2 ::= expr DUP_TOP LOAD_ATTR expr - inplace_op ROT_TWO STORE_ATTR + aug_assign1 ::= expr expr + inplace_op store + aug_assign1 ::= expr expr + inplace_op ROT_THREE STORE_SUBSCR + aug_assign2 ::= expr DUP_TOP LOAD_ATTR expr + inplace_op ROT_TWO STORE_ATTR inplace_op ::= INPLACE_ADD inplace_op ::= INPLACE_SUBTRACT diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 8abb1d19..7c93af55 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -200,10 +200,10 @@ class Python2Parser(PythonParser): store ::= expr expr STORE_SLICE+2 store ::= expr expr expr STORE_SLICE+3 - augassign1 ::= expr expr inplace_op ROT_FOUR STORE_SLICE+3 - augassign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+1 - augassign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+2 - augassign1 ::= expr expr inplace_op ROT_TWO STORE_SLICE+0 + aug_assign1 ::= expr expr inplace_op ROT_FOUR STORE_SLICE+3 + aug_assign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+1 + aug_assign1 ::= expr expr inplace_op ROT_THREE STORE_SLICE+2 + aug_assign1 ::= expr expr inplace_op ROT_TWO STORE_SLICE+0 slice0 ::= expr SLICE+0 slice0 ::= expr DUP_TOP SLICE+0 @@ -430,8 +430,8 @@ class Python2Parser(PythonParser): raise Exception('unknown customize token %s' % opname) self.add_unique_rule(rule, opname_base, v, customize) pass - self.check_reduce['augassign1'] = 'AST' - self.check_reduce['augassign2'] = 'AST' + self.check_reduce['aug_assign1'] = 'AST' + self.check_reduce['aug_assign2'] = 'AST' self.check_reduce['_stmts'] = 'AST' # Dead code testing... @@ -447,7 +447,7 @@ class Python2Parser(PythonParser): # if lhs == 'while1elsestmt': # from trepan.api import debug; debug() - if lhs in ('augassign1', 'augassign2') and ast[0] and ast[0][0] == 'and': + if lhs in ('aug_assign1', 'aug_assign2') and ast[0] and ast[0][0] == 'and': return True elif lhs == '_stmts': for i, stmt in enumerate(ast): diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index ef3c5727..d5632cf5 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -972,8 +972,8 @@ class Python3Parser(PythonParser): self.add_unique_rule(rule, opname, token.attr, customize) elif opname_base == 'UNPACK_LIST': rule = 'unpack_list ::= ' + opname + ' store' * token.attr - self.check_reduce['augassign1'] = 'AST' - self.check_reduce['augassign2'] = 'AST' + self.check_reduce['aug_assign1'] = 'AST' + self.check_reduce['aug_assign2'] = 'AST' self.check_reduce['while1stmt'] = 'noAST' self.check_reduce['annotate_tuple'] = 'noAST' self.check_reduce['kwarg'] = 'noAST' @@ -983,7 +983,7 @@ class Python3Parser(PythonParser): def reduce_is_invalid(self, rule, ast, tokens, first, last): lhs = rule[0] - if lhs in ('augassign1', 'augassign2') and ast[0][0] == 'and': + if lhs in ('aug_assign1', 'aug_assign2') and ast[0][0] == 'and': return True elif lhs == 'annotate_tuple': return not isinstance(tokens[first].attr, tuple) diff --git a/uncompyle6/semantics/check_ast.py b/uncompyle6/semantics/check_ast.py index 417232d1..16773ac7 100644 --- a/uncompyle6/semantics/check_ast.py +++ b/uncompyle6/semantics/check_ast.py @@ -14,7 +14,7 @@ def checker(ast, in_loop, errors): in_loop = in_loop or ast.kind in ('while1stmt', 'whileTruestmt', 'whilestmt', 'whileelsestmt', 'while1elsestmt', 'for_block') - if ast.kind in ('augassign1', 'augassign2') and ast[0][0] == 'and': + if ast.kind in ('aug_assign1', 'aug_assign2') and ast[0][0] == 'and': text = str(ast) error_text = '\n# improper augmented assigment (e.g. +=, *=, ...):\n#\t' + '\n# '.join(text.split("\n")) + '\n' errors.append(error_text) diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 12a6a542..7ce65125 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -176,9 +176,9 @@ TABLE_DIRECT = { # The 2nd parameter should have a = suffix. # There is a rule with a 4th parameter "store" # which we don't use here. - 'augassign1': ( '%|%c %c %c\n', 0, 2, 1), + 'aug_assign1': ( '%|%c %c %c\n', 0, 2, 1), - 'augassign2': ( '%|%c.%[2]{pattr} %c %c\n', 0, -3, -4 ), + 'aug_assign2': ( '%|%c.%[2]{pattr} %c %c\n', 0, -3, -4 ), 'designList': ( '%c = %c', 0, -1 ), 'and': ( '%c and %c', 0, 2 ), 'ret_and': ( '%c and %c', 0, 2 ), diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index a23409aa..22063d9c 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -191,7 +191,7 @@ class FragmentsWalker(pysource.SourceWalker, object): raise GenericASTTraversalPruningException n_slice0 = n_slice1 = n_slice2 = n_slice3 = n_subscript = table_r_node - n_augassign_1 = n_print_item = exec_stmt = print_to_item = del_stmt = table_r_node + n_aug_assign_1 = n_print_item = exec_stmt = print_to_item = del_stmt = table_r_node n_classdefco1 = n_classdefco2 = except_cond1 = except_cond2 = table_r_node def n_passtmt(self, node):