From 0677ddc8fb8999f87cf5d002b69b45facfe8d6ad Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 15 Jan 2020 21:32:39 -0500 Subject: [PATCH] Constrain ifelsestmt on 2.6 more. --- test/bytecode_2.6_run/04_if_and_bug.pyc | Bin 1265 -> 1548 bytes test/simple_source/bug26/04_if_and_bug.py | 18 +++++++++ uncompyle6/parsers/parse2.py | 3 +- uncompyle6/parsers/parse26.py | 1 + uncompyle6/parsers/reducecheck/ifelsestmt.py | 38 ++++++++++++++----- 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/test/bytecode_2.6_run/04_if_and_bug.pyc b/test/bytecode_2.6_run/04_if_and_bug.pyc index a192ce701b21c7b8b62b5f7abe1d1f0d2da83466..6417b96d95fef54721bc81ee670ef477616da5a8 100644 GIT binary patch delta 330 zcmZ9Fy-LJD6ot>3OcFCh(e)2x!A`S{7V85nY`?`?C>DxjfW8yAI$pq4h0C-F6` z+)mJ!(9+5~Su1De+&Oc<;oPt2DQ-``XU+TT`eBN{70BHajaK>G{^&gd2R<@63J-+U zI90d^!BXR%pd(&G{C~uT*iB|$eonl*loIHPw5adGx206TxdAP4OBBoCje%9}u~*0d zvLN;=p$e6fEEh1ymDJqXM1-a}G~!BM%J}%~Dl6Tz>nRq8QT?epTXW(v;YT*V%+fL+ yXPb`AyB`c`lt)94S_K>=L2Y%{43~s8IrT*C)NguWr6rwcF*Y4;Ot&A!Yy1V_+A<^n delta 74 zcmeC-`N%1A@e?nXWUE|UG6NK_0ci&yF22PuQRX&tum<~PbH;RLW 0: - come_froms = come_froms[0] - if not isinstance(come_froms, Token): - if len(come_froms): - return tokens[first].offset > come_froms[-1].attr - elif tokens[first].offset > come_froms.attr: - return True + if come_froms.kind != "else_suite": + if come_froms == "opt_come_from_except" and len(come_froms) > 0: + come_froms = come_froms[0] + if not isinstance(come_froms, Token): + if len(come_froms): + return tokens[first].offset > come_froms[-1].attr + elif tokens[first].offset > come_froms.attr: + return True # For mysterious reasons a COME_FROM in tokens[last+1] might be part of the grammar rule # even though it is not found in come_froms. @@ -94,10 +104,18 @@ def ifelsestmt(self, lhs, n, rule, ast, tokens, first, last): if last == n: last -= 1 jmp = test[1] - jmp_target = jmp[0].attr + jmp_target = int(jmp[0].pattr) - # FIXME: the jump inside "else" check below should be added. - # + + # Make sure we don't jump at the end of the "then" inside the "else" + # (jf_cf_pop may be a 2.6ish specific thing.) + jf_cf_pop = ast[2] + + if jf_cf_pop == "jf_cf_pop" and jf_cf_pop[0] == "JUMP_FORWARD": + if int(jf_cf_pop[0].pattr) < tokens[last-1].off2int(): + return True + + # The jump inside "else" check below should be added. # add this until we can find out what's wrong with # not being able to parse: # if a and b or c: