diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 48ba6734..0b347477 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -255,7 +255,7 @@ class PythonParser(GenericASTBuilder): c_stmts_opt ::= pass l_stmts ::= _stmts - l_stmts ::= return_stmts + l_stmts ::= returns l_stmts ::= continues l_stmts ::= _stmts lastl_stmt l_stmts ::= lastl_stmt @@ -269,7 +269,7 @@ class PythonParser(GenericASTBuilder): l_stmts_opt ::= pass suite_stmts ::= _stmts - suite_stmts ::= return_stmts + suite_stmts ::= returns suite_stmts ::= continues suite_stmts_opt ::= suite_stmts @@ -280,7 +280,7 @@ class PythonParser(GenericASTBuilder): else_suite ::= suite_stmts else_suitel ::= l_stmts else_suitec ::= c_stmts - else_suitec ::= return_stmts + else_suitec ::= returns stmt ::= assert @@ -308,15 +308,15 @@ class PythonParser(GenericASTBuilder): del_stmt ::= DELETE_GLOBAL - stmt ::= return_stmt - return_stmt ::= ret_expr RETURN_VALUE + stmt ::= return + return ::= ret_expr RETURN_VALUE - # return_stmts are a sequence of statements that ends in a RETURN statement. + # returns are a sequence of statements that ends in a RETURN statement. # In later Python versions with jump optimization, this can cause JUMPs # that would normally appear to be omitted. - return_stmts ::= return_stmt - return_stmts ::= _stmts return_stmt + returns ::= return + returns ::= _stmts return """ pass diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 8fdf7ab0..a9ac4ac9 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -54,7 +54,7 @@ class Python2Parser(PythonParser): def p_grammar(self, args): ''' sstmt ::= stmt - sstmt ::= return_stmt RETURN_LAST + sstmt ::= return RETURN_LAST return_if_stmts ::= return_if_stmt return_if_stmts ::= _stmts return_if_stmt @@ -157,10 +157,10 @@ class Python2Parser(PythonParser): except_suite ::= c_stmts_opt JUMP_FORWARD except_suite ::= c_stmts_opt jmp_abs - except_suite ::= return_stmts + except_suite ::= returns except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt _jump - except ::= POP_TOP POP_TOP POP_TOP return_stmts + except ::= POP_TOP POP_TOP POP_TOP returns jmp_abs ::= JUMP_ABSOLUTE jmp_abs ::= JUMP_BACK @@ -483,7 +483,7 @@ class Python2Parser(PythonParser): if stmt == '_stmts': stmt = stmt[0] assert stmt == 'stmt' - if stmt[0] == 'return_stmt': + if stmt[0] == 'return': return i+1 != len(ast) pass return False diff --git a/uncompyle6/parsers/parse21.py b/uncompyle6/parsers/parse21.py index 8b1bbe0c..dbb70453 100644 --- a/uncompyle6/parsers/parse21.py +++ b/uncompyle6/parsers/parse21.py @@ -15,7 +15,7 @@ class Python21Parser(Python22Parser): """ for_iter ::= LOAD_CONST FOR_LOOP for ::= SETUP_LOOP expr for_iter store - return_stmts + returns POP_BLOCK COME_FROM for ::= SETUP_LOOP expr for_iter store l_stmts_opt _jump_back diff --git a/uncompyle6/parsers/parse24.py b/uncompyle6/parsers/parse24.py index 02717072..2677b1a4 100644 --- a/uncompyle6/parsers/parse24.py +++ b/uncompyle6/parsers/parse24.py @@ -58,8 +58,8 @@ class Python24Parser(Python25Parser): kvlist ::= kvlist kv3 while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM - while1stmt ::= SETUP_LOOP return_stmts COME_FROM - whilestmt ::= SETUP_LOOP testexpr return_stmts POP_BLOCK COME_FROM + while1stmt ::= SETUP_LOOP returns COME_FROM + whilestmt ::= SETUP_LOOP testexpr returns POP_BLOCK COME_FROM with_cleanup ::= LOAD_FAST DELETE_FAST WITH_CLEANUP END_FINALLY with_cleanup ::= LOAD_NAME DELETE_NAME WITH_CLEANUP END_FINALLY withasstmt ::= expr setupwithas store suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM with_cleanup diff --git a/uncompyle6/parsers/parse25.py b/uncompyle6/parsers/parse25.py index 0632fb59..f3b9bdfa 100644 --- a/uncompyle6/parsers/parse25.py +++ b/uncompyle6/parsers/parse25.py @@ -68,8 +68,8 @@ class Python25Parser(Python26Parser): return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP return_if_stmt ::= ret_expr RETURN_END_IF POP_TOP return_if_stmts ::= return_if_stmt - return_stmt ::= ret_expr RETURN_END_IF POP_TOP - return_stmt ::= ret_expr RETURN_VALUE POP_TOP + return ::= ret_expr RETURN_END_IF POP_TOP + return ::= ret_expr RETURN_VALUE POP_TOP return_stmt_lambda ::= ret_expr RETURN_VALUE_LAMBDA setupwithas ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 setup_finally stmt ::= classdefdeco diff --git a/uncompyle6/parsers/parse26.py b/uncompyle6/parsers/parse26.py index 5a29ccd0..97b5fcea 100644 --- a/uncompyle6/parsers/parse26.py +++ b/uncompyle6/parsers/parse26.py @@ -135,14 +135,14 @@ class Python26Parser(Python2Parser): whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK _come_froms whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop bp_come_from - whilestmt ::= SETUP_LOOP testexpr return_stmts POP_BLOCK COME_FROM + whilestmt ::= SETUP_LOOP testexpr returns POP_BLOCK COME_FROM whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK else_suite COME_FROM while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM - return_stmt ::= ret_expr RETURN_END_IF POP_TOP - return_stmt ::= ret_expr RETURN_VALUE POP_TOP + return ::= ret_expr RETURN_END_IF POP_TOP + return ::= ret_expr RETURN_VALUE POP_TOP return_if_stmt ::= ret_expr RETURN_END_IF POP_TOP iflaststmtl ::= testexpr c_stmts_opt JUMP_BACK come_from_pop @@ -174,8 +174,8 @@ class Python26Parser(Python2Parser): jmp_false_then ::= JUMP_IF_FALSE THEN POP_TOP jmp_true_then ::= JUMP_IF_TRUE THEN POP_TOP - while1stmt ::= SETUP_LOOP return_stmts COME_FROM - for_block ::= return_stmts _come_froms + while1stmt ::= SETUP_LOOP returns COME_FROM + for_block ::= returns _come_froms """ def p_comp26(self, args): @@ -241,7 +241,7 @@ class Python26Parser(Python2Parser): ret_cond ::= expr jmp_false_then expr ret_expr_or_cond return_if_stmt ::= ret_expr RETURN_END_IF POP_TOP - return_stmt ::= ret_expr RETURN_VALUE POP_TOP + return ::= ret_expr RETURN_VALUE POP_TOP # FIXME: split into Python 2.5 ret_or ::= expr jmp_true ret_expr_or_cond come_froms diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index 8d22455e..adbc2195 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -106,7 +106,7 @@ class Python27Parser(Python2Parser): # assert condition, expr assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1 - for_block ::= return_stmts _come_froms + for_block ::= returns _come_froms withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM_WITH @@ -116,7 +116,7 @@ class Python27Parser(Python2Parser): POP_BLOCK LOAD_CONST COME_FROM_WITH WITH_CLEANUP END_FINALLY - while1stmt ::= SETUP_LOOP return_stmts bp_come_from + while1stmt ::= SETUP_LOOP returns bp_come_from while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK _come_froms while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 33af1ed2..cd230ce5 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -82,7 +82,7 @@ class Python3Parser(PythonParser): ''' sstmt ::= stmt sstmt ::= ifelsestmtr - sstmt ::= return_stmt RETURN_LAST + sstmt ::= return RETURN_LAST return_if_stmts ::= return_if_stmt come_from_opt return_if_stmts ::= _stmts return_if_stmt @@ -157,7 +157,7 @@ class Python3Parser(PythonParser): ifelsestmtc ::= testexpr c_stmts_opt JUMP_ABSOLUTE else_suitec ifelsestmtc ::= testexpr c_stmts_opt jump_absolute_else else_suitec - ifelsestmtr ::= testexpr return_if_stmts return_stmts + ifelsestmtr ::= testexpr return_if_stmts returns ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel ifelsestmtl ::= testexpr c_stmts_opt cf_jump_back else_suitel @@ -224,7 +224,7 @@ class Python3Parser(PythonParser): except_var_finalize ::= POP_BLOCK POP_EXCEPT LOAD_CONST COME_FROM_FINALLY LOAD_CONST store del_stmt - except_suite ::= return_stmts + except_suite ::= returns except_cond1 ::= DUP_TOP expr COMPARE_OP jmp_false POP_TOP POP_TOP POP_TOP @@ -233,7 +233,7 @@ class Python3Parser(PythonParser): jmp_false POP_TOP store POP_TOP except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt POP_EXCEPT _jump - except ::= POP_TOP POP_TOP POP_TOP return_stmts + except ::= POP_TOP POP_TOP POP_TOP returns jmp_abs ::= JUMP_ABSOLUTE jmp_abs ::= JUMP_BACK @@ -346,7 +346,7 @@ class Python3Parser(PythonParser): whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM_LOOP - whilestmt ::= SETUP_LOOP testexpr return_stmts POP_BLOCK + whilestmt ::= SETUP_LOOP testexpr returns POP_BLOCK COME_FROM_LOOP while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK @@ -574,13 +574,13 @@ class Python3Parser(PythonParser): self.addRule(""" stmt ::= assign3_pypy stmt ::= assign2_pypy - assign3_pypy ::= expr expr expr store store store - assign2_pypy ::= expr expr store store + assign3_pypy ::= expr expr expr store store store + assign2_pypy ::= expr expr store store return_if_lambda ::= RETURN_END_IF_LAMBDA - return_stmt_lambda ::= ret_expr RETURN_VALUE_LAMBDA - stmt ::= conditional_lambda + return_lambda ::= ret_expr RETURN_VALUE_LAMBDA + stmt ::= conditional_lambda conditional_lambda ::= expr jmp_false expr return_if_lambda - return_stmt_lambda LAMBDA_MARKER + return_lambda LAMBDA_MARKER """, nop_func) has_get_iter_call_function1 = False diff --git a/uncompyle6/parsers/parse30.py b/uncompyle6/parsers/parse30.py index d4efb7f3..c72fb827 100644 --- a/uncompyle6/parsers/parse30.py +++ b/uncompyle6/parsers/parse30.py @@ -18,7 +18,7 @@ class Python30Parser(Python31Parser): # FIXME: combine with parse3.2 whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP - whileTruestmt ::= SETUP_LOOP return_stmts + whileTruestmt ::= SETUP_LOOP returns COME_FROM_LOOP # In many ways Python 3.0 code generation is more like Python 2.6 than diff --git a/uncompyle6/parsers/parse35.py b/uncompyle6/parsers/parse35.py index 35af247a..7620f49d 100644 --- a/uncompyle6/parsers/parse35.py +++ b/uncompyle6/parsers/parse35.py @@ -25,7 +25,7 @@ class Python35Parser(Python34Parser): while1stmt ::= SETUP_LOOP l_stmts POP_BLOCK COME_FROM_LOOP while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK else_suite COME_FROM_LOOP - whilestmt ::= SETUP_LOOP testexpr return_stmts POP_BLOCK COME_FROM_LOOP + whilestmt ::= SETUP_LOOP testexpr returns POP_BLOCK COME_FROM_LOOP # The following rule is for Python 3.5+ where we can have stuff like # while .. diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 3117b0f7..74ec3da1 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -42,14 +42,14 @@ class Python36Parser(Python35Parser): # In 3.6+, A sequence of statements ending in a RETURN can cause # JUMP_FORWARD END_FINALLY to be omitted from try middle - except_return ::= POP_TOP POP_TOP POP_TOP return_stmts + except_return ::= POP_TOP POP_TOP POP_TOP returns except_handler ::= JUMP_FORWARD COME_FROM_EXCEPT except_return - # Try middle following a return_stmts + # Try middle following a returns except_handler36 ::= COME_FROM_EXCEPT except_stmts END_FINALLY stmt ::= try_except36 - try_except36 ::= SETUP_EXCEPT return_stmts except_handler36 opt_come_from_except + try_except36 ::= SETUP_EXCEPT returns except_handler36 opt_come_from_except """ def customize_grammar_rules(self, tokens, customize): diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index b95d39d7..95d6bdb5 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -19,14 +19,14 @@ LINE_LENGTH = 80 # Some ASTs used for comparing code fragments (like 'return None' at # the end of functions). -RETURN_LOCALS = AST('return_stmt', +RETURN_LOCALS = AST('return', [ AST('ret_expr', [AST('expr', [ Token('LOAD_LOCALS') ])]), Token('RETURN_VALUE')]) NONE = AST('expr', [ NoneToken ] ) RETURN_NONE = AST('stmt', - [ AST('return_stmt', + [ AST('return', [ NONE, Token('RETURN_VALUE')]) ]) PASS = AST('stmts', @@ -231,8 +231,8 @@ TABLE_DIRECT = { 'raise_stmt0': ( '%|raise\n', ), 'raise_stmt1': ( '%|raise %c\n', 0), 'raise_stmt3': ( '%|raise %c, %c, %c\n', 0, 1, 2), -# 'yield': ( 'yield %c', 0), -# 'return_stmt': ( '%|return %c\n', 0), +# 'yield': ( 'yield %c', 0), +# 'return': ( '%|return %c\n', 0), 'return_if_stmt': ( 'return %c\n', 0), 'ifstmt': ( '%|if %c:\n%+%c%-', 0, 1 ), diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index a84dfcea..a77a6c81 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -206,7 +206,7 @@ class FragmentsWalker(pysource.SourceWalker, object): n_tryelsestmt = n_tryelsestmtc = n_tryelsestmtl = n_tryfinallystmt = n_try_except - def n_return_stmt(self, node): + def n_return(self, node): start = len(self.f.getvalue()) + len(self.indent) if self.params['is_lambda']: self.preorder(node[0]) @@ -217,7 +217,7 @@ class FragmentsWalker(pysource.SourceWalker, object): else: start = len(self.f.getvalue()) + len(self.indent) self.write(self.indent, 'return') - if self.return_none or node != AST('return_stmt', [AST('ret_expr', [NONE]), Token('RETURN_VALUE')]): + if self.return_none or node != AST('return', [AST('ret_expr', [NONE]), Token('RETURN_VALUE')]): self.write(' ') self.last_finish = len(self.f.getvalue()) self.preorder(node[0]) @@ -243,7 +243,7 @@ class FragmentsWalker(pysource.SourceWalker, object): else: start = len(self.f.getvalue()) + len(self.indent) self.write(self.indent, 'return') - if self.return_none or node != AST('return_stmt', [AST('ret_expr', [NONE]), Token('RETURN_END_IF')]): + if self.return_none or node != AST('return', [AST('ret_expr', [NONE]), Token('RETURN_END_IF')]): self.write(' ') self.preorder(node[0]) if hasattr(node[-1], 'offset'): diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index fa29331e..abd52a41 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -817,7 +817,7 @@ class SourceWalker(GenericASTTraversal, object): # FIXME: should the AST expression be folded into # the global RETURN_NONE constant? return (ret or - node == AST('return_stmt', + node == AST('return', [AST('ret_expr', [NONE]), Token('RETURN_VALUE')])) # Python 3.x can have be dead code as a result of its optimization? @@ -834,7 +834,7 @@ class SourceWalker(GenericASTTraversal, object): self.preorder(node[0]) self.prune() - def n_return_stmt(self, node): + def n_return(self, node): if self.params['is_lambda']: self.preorder(node[0]) self.prune()