You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Add 3.7ish "or" check
This commit is contained in:
@@ -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,7 +102,8 @@ 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
|
||||
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
|
||||
@@ -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"
|
||||
|
@@ -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:
|
||||
|
Reference in New Issue
Block a user