From 4260deea11d702f13cf51b3100611f123937c1ab Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 29 Aug 2022 05:29:57 -0400 Subject: [PATCH] Tidy ifelsemstmt check --- .../bytecode_3.7_run/10_extendedargifelse.pyc | Bin 2777 -> 2779 bytes .../bug37/10_extendedargifelse.py | 10 +++++++++- uncompyle6/parsers/reducecheck/ifelsestmt.py | 12 +++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/test/bytecode_3.7_run/10_extendedargifelse.pyc b/test/bytecode_3.7_run/10_extendedargifelse.pyc index 5ec444e959208a8f6de11d5127d3472754750a51..3dda1b31e325f4339ed13941fa4dcad10dfcd35c 100644 GIT binary patch delta 44 xcmca9dRvs&iIr=3`=D*nE-W598#MTmnoii~t9P3q$|_ delta 41 ucmcaDdQ+6wiIrE&%||Z3;vH diff --git a/test/simple_source/bug37/10_extendedargifelse.py b/test/simple_source/bug37/10_extendedargifelse.py index 15d5adc1..d8c95091 100644 --- a/test/simple_source/bug37/10_extendedargifelse.py +++ b/test/simple_source/bug37/10_extendedargifelse.py @@ -1,3 +1,10 @@ +# This is RUNNABLE! + +"""This program is self-checking!""" + +# Bug was handling if which has EXTENDED_ARG +# See https://github.com/rocky/python-uncompyle6/pull/406 + aa = 0 ab = 0 ac = 0 @@ -261,4 +268,5 @@ var = True if var: aa = 1 else: - aa = 2 \ No newline at end of file + aa = 2 +assert aa == 1 diff --git a/uncompyle6/parsers/reducecheck/ifelsestmt.py b/uncompyle6/parsers/reducecheck/ifelsestmt.py index e0921b09..133df853 100644 --- a/uncompyle6/parsers/reducecheck/ifelsestmt.py +++ b/uncompyle6/parsers/reducecheck/ifelsestmt.py @@ -136,6 +136,8 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): # print(tokens[t]) # print("=" * 30) + first_offset = tokens[first].off2int() + if rule not in IFELSE_STMT_RULES: # print("XXX", rule) return False @@ -151,7 +153,7 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): ): return True - # Make sure all of the "come froms" offset at the + # Make sure all the offsets from the "come froms" at the # end of the "if" come from somewhere inside the "if". # Since the come_froms are ordered so that lowest # offset COME_FROM is last, it is sufficient to test @@ -163,8 +165,8 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): end_come_froms = end_come_froms[0] if not isinstance(end_come_froms, Token): if len(end_come_froms): - return tokens[first].off2int() > end_come_froms[-1].attr - elif tokens[first].off2int() > end_come_froms.attr: + return first_offset > end_come_froms[-1].attr + elif first_offset > end_come_froms.attr: return True # FIXME: There is weirdness in the grammar we need to work around. @@ -173,7 +175,7 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): last_token = tree[-1] else: last_token = tokens[last] - if last_token == "COME_FROM" and tokens[first].off2int() > last_token.attr: + if last_token == "COME_FROM" and first_offset > last_token.attr: if self.version < (3, 0) and self.insts[self.offset2inst_index[last_token.attr]].opname != "SETUP_LOOP": return True @@ -237,7 +239,7 @@ def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): if jump_else_end[-1].off2int() != jmp_target: return True - if tokens[first].off2int() > jmp_target: + if first_offset > jmp_target: return True return (jmp_target > last_offset) and tokens[last] != "JUMP_FORWARD"