DRY reducecheck code

This commit is contained in:
rocky
2020-01-10 15:36:24 -05:00
parent d1bc30e2f1
commit eba8f04e29
3 changed files with 27 additions and 24 deletions

View File

@@ -4,6 +4,10 @@ from uncompyle6.scanners.tok import Token
def ifstmts_jump(self, lhs, n, rule, ast, tokens, first, last):
if len(rule[1]) <= 1 or not ast:
return False
come_froms = ast[-1]
# Make sure all of the "come froms" offset at the
# end of the "if" come from somewhere inside the "if".

View File

@@ -1,15 +1,15 @@
# Copyright (c) 2020 Rocky Bernstein
def testtrue(self, lhs, n, rule, ast, tokens, first, last):
# FIXME: make this work for all versions
if self.version != 3.7:
return False
if rule == ("testtrue", ("expr", "jmp_true")):
pjit = tokens[min(last-1, n-2)]
pjit = tokens[min(last - 1, n - 2)]
# If we have a backwards (looping) jump then this is
# really a testfalse
if (pjit == "POP_JUMP_IF_TRUE" and
tokens[first].off2int() > pjit.attr):
assert_next = tokens[min(last+1, n-1)]
# really a testfalse. "assert"s throw this off too.
if pjit == "POP_JUMP_IF_TRUE" and tokens[first].off2int() > pjit.attr:
assert_next = tokens[min(last + 1, n - 1)]
return assert_next != "RAISE_VARARGS_1"
return False