From 2fd61b10165e254e484c92e559b8420d7a5a3652 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 16 Apr 2020 16:35:27 -0400 Subject: [PATCH] Add 3.7ish "or" check --- .../{05_abc_test.pyc => 05_abc_test.pyc-notyet} | Bin uncompyle6/parsers/parse27.py | 9 ++++++--- uncompyle6/parsers/reducecheck/or_check.py | 13 +++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) rename test/bytecode_3.0/{05_abc_test.pyc => 05_abc_test.pyc-notyet} (100%) diff --git a/test/bytecode_3.0/05_abc_test.pyc b/test/bytecode_3.0/05_abc_test.pyc-notyet similarity index 100% rename from test/bytecode_3.0/05_abc_test.pyc rename to test/bytecode_3.0/05_abc_test.pyc-notyet diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index e1bb86ab..eb77c2fd 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -7,6 +7,7 @@ from xdis import next_offset from uncompyle6.parser import PythonParserSingle, nop_func from uncompyle6.parsers.parse2 import Python2Parser from uncompyle6.parsers.reducecheck import ( + or_check, ifelsestmt, tryelsestmt, ) @@ -101,8 +102,9 @@ class Python27Parser(Python2Parser): ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM ret_expr_or_cond - or ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM - and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM + expr_jitop ::= expr JUMP_IF_TRUE_OR_POP + or ::= expr_jitop expr COME_FROM + and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM # compare_chained{1,2} is used exclusively in chained_compare compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP @@ -229,6 +231,7 @@ class Python27Parser(Python2Parser): # FIXME: Put more in this table self.reduce_check_table = { # "ifelsestmt": ifelsestmt, + "or": or_check, "tryelsestmt": tryelsestmt, "tryelsestmtl": tryelsestmt, } @@ -239,7 +242,7 @@ class Python27Parser(Python2Parser): self.check_reduce["except_handler"] = "tokens" self.check_reduce["except_handler_else"] = "tokens" - # self.check_reduce["or"] = "AST" + self.check_reduce["or"] = "AST" self.check_reduce["raise_stmt1"] = "AST" self.check_reduce["iflaststmtl"] = "AST" self.check_reduce["ifelsestmt"] = "AST" diff --git a/uncompyle6/parsers/reducecheck/or_check.py b/uncompyle6/parsers/reducecheck/or_check.py index 2a35adf3..5e0c7d85 100644 --- a/uncompyle6/parsers/reducecheck/or_check.py +++ b/uncompyle6/parsers/reducecheck/or_check.py @@ -2,7 +2,10 @@ ASSERT_OPS = frozenset(["LOAD_ASSERT", "RAISE_VARARGS_1"]) def or_check(self, lhs, n, rule, ast, tokens, first, last): - if rule == ("or", ("expr_jt", "expr")): + rhs = rule[1] + if rhs in (("expr_jt", "expr"), + ("expr_jitop", "expr", "COME_FROM"), + ("expr_jit", "expr", "\\e_come_from_opt")): if tokens[last] in ASSERT_OPS or tokens[last-1] in ASSERT_OPS: return True @@ -18,7 +21,13 @@ def or_check(self, lhs, n, rule, ast, tokens, first, last): return True first_offset = tokens[first].off2int() - jmp_true_target = ast[0][1][0].attr + expr_jt = ast[0] + if expr_jt == "expr_jitop": + jump_true = expr_jt[1] + else: + jump_true = expr_jt[1][0] + + jmp_true_target = jump_true.attr jmp_true_target < first_offset if jmp_true_target < first_offset: