Add 3.7ish "or" check

This commit is contained in:
rocky
2020-04-16 16:35:27 -04:00
parent ebd0eaa609
commit 2fd61b1016
3 changed files with 17 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ from xdis import next_offset
from uncompyle6.parser import PythonParserSingle, nop_func from uncompyle6.parser import PythonParserSingle, nop_func
from uncompyle6.parsers.parse2 import Python2Parser from uncompyle6.parsers.parse2 import Python2Parser
from uncompyle6.parsers.reducecheck import ( from uncompyle6.parsers.reducecheck import (
or_check,
ifelsestmt, ifelsestmt,
tryelsestmt, tryelsestmt,
) )
@@ -101,8 +102,9 @@ class Python27Parser(Python2Parser):
ret_or ::= expr JUMP_IF_TRUE_OR_POP ret_expr_or_cond COME_FROM 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 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 expr_jitop ::= expr JUMP_IF_TRUE_OR_POP
and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM 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_chained{1,2} is used exclusively in chained_compare
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP 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 # FIXME: Put more in this table
self.reduce_check_table = { self.reduce_check_table = {
# "ifelsestmt": ifelsestmt, # "ifelsestmt": ifelsestmt,
"or": or_check,
"tryelsestmt": tryelsestmt, "tryelsestmt": tryelsestmt,
"tryelsestmtl": tryelsestmt, "tryelsestmtl": tryelsestmt,
} }
@@ -239,7 +242,7 @@ class Python27Parser(Python2Parser):
self.check_reduce["except_handler"] = "tokens" self.check_reduce["except_handler"] = "tokens"
self.check_reduce["except_handler_else"] = "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["raise_stmt1"] = "AST"
self.check_reduce["iflaststmtl"] = "AST" self.check_reduce["iflaststmtl"] = "AST"
self.check_reduce["ifelsestmt"] = "AST" self.check_reduce["ifelsestmt"] = "AST"

View File

@@ -2,7 +2,10 @@
ASSERT_OPS = frozenset(["LOAD_ASSERT", "RAISE_VARARGS_1"]) ASSERT_OPS = frozenset(["LOAD_ASSERT", "RAISE_VARARGS_1"])
def or_check(self, lhs, n, rule, ast, tokens, first, last): 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: if tokens[last] in ASSERT_OPS or tokens[last-1] in ASSERT_OPS:
return True return True
@@ -18,7 +21,13 @@ def or_check(self, lhs, n, rule, ast, tokens, first, last):
return True return True
first_offset = tokens[first].off2int() 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 jmp_true_target < first_offset
if jmp_true_target < first_offset: if jmp_true_target < first_offset: