From 976705fc0a39ba3110818cdd4a23a4a15aac453b Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 7 Oct 2022 22:05:59 +0200 Subject: [PATCH 1/2] Add: Python 2.7: ifelsestmtc --- uncompyle6/parsers/parse27.py | 6 +++- uncompyle6/parsers/reducecheck/ifelsestmt.py | 29 ++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index b2765eef..86986d7d 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -142,6 +142,7 @@ class Python27Parser(Python2Parser): def p_stmt27(self, args): """ stmt ::= ifelsestmtr + stmt ::= ifelsestmtc # assert condition assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1 @@ -194,6 +195,7 @@ class Python27Parser(Python2Parser): ifstmt ::= testexpr return_if_stmts COME_FROM ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD else_suite come_froms ifelsestmtc ::= testexpr c_stmts_opt JUMP_ABSOLUTE else_suitec + ifelsestmtc ::= testexpr c_stmts_opt JUMP_FORWARD else_suite come_froms ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel ifelsestmtl ::= testexpr c_stmts_opt CONTINUE else_suitel @@ -242,6 +244,7 @@ class Python27Parser(Python2Parser): "except_handler": except_handler, "for_block": for_block_check.for_block_invalid, "ifelsestmt": ifelsestmt, + "ifelsestmtc": ifelsestmt, "or": or_check, "tryelsestmt": tryelsestmt, "tryelsestmtl": tryelsestmt, @@ -258,8 +261,9 @@ class Python27Parser(Python2Parser): self.check_reduce["or"] = "AST" self.check_reduce["raise_stmt1"] = "AST" - self.check_reduce["iflaststmtl"] = "AST" self.check_reduce["ifelsestmt"] = "AST" + self.check_reduce["ifelsestmtc"] = "AST" + self.check_reduce["iflaststmtl"] = "AST" self.check_reduce["list_if_not"] = "AST" self.check_reduce["list_if"] = "AST" self.check_reduce["comp_if"] = "AST" diff --git a/uncompyle6/parsers/reducecheck/ifelsestmt.py b/uncompyle6/parsers/reducecheck/ifelsestmt.py index 133df853..072e4f21 100644 --- a/uncompyle6/parsers/reducecheck/ifelsestmt.py +++ b/uncompyle6/parsers/reducecheck/ifelsestmt.py @@ -4,7 +4,7 @@ from uncompyle6.scanners.tok import Token IFELSE_STMT_RULES = frozenset( [ - ( + ( "ifelsestmt", ( "testexpr", @@ -52,6 +52,15 @@ IFELSE_STMT_RULES = frozenset( "else_suitec", ), ), + ( + "ifelsestmtc", + ( + "testexpr", + "c_stmts_opt", + "JUMP_ABSOLUTE", + "else_suitec", + ), + ), ( "ifelsestmt", ( @@ -74,7 +83,13 @@ IFELSE_STMT_RULES = frozenset( ), ( "ifelsestmt", - ("testexpr", "c_stmts", "come_froms", "else_suite", "come_froms",), + ( + "testexpr", + "c_stmts", + "come_froms", + "else_suite", + "come_froms", + ), ), ( "ifelsestmt", @@ -112,7 +127,8 @@ IFELSE_STMT_RULES = frozenset( "stmts", "jf_cfs", "\\e_else_suite_opt", - "\\e_opt_come_from_except") + "\\e_opt_come_from_except", + ), ), ( "ifelsestmt", @@ -121,9 +137,12 @@ IFELSE_STMT_RULES = frozenset( "stmts", "jf_cfs", "\\e_else_suite_opt", - "opt_come_from_except") + "opt_come_from_except", + ), ), - ]) + ] +) + def ifelsestmt(self, lhs, n, rule, tree, tokens, first, last): From 512c5008103d4a8e5693831d0958d125c58c2dea Mon Sep 17 00:00:00 2001 From: Berbe <4251220+Berbe@users.noreply.github.com> Date: Mon, 10 Oct 2022 04:54:19 +0200 Subject: [PATCH 2/2] Add: Tests: CONTINUE in else block in a for loop --- .../07_for_if_else-continue.pyc | Bin 0 -> 962 bytes .../bug27+/07_for_if_else-continue.py | 33 ++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/bytecode_2.7_run/07_for_if_else-continue.pyc create mode 100644 test/simple_source/bug27+/07_for_if_else-continue.py diff --git a/test/bytecode_2.7_run/07_for_if_else-continue.pyc b/test/bytecode_2.7_run/07_for_if_else-continue.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e4894c380486739a4e84ddc28e0ec8960f35589f GIT binary patch literal 962 zcmb`E&u-H|5XNWiG-)CIBSEhyy;(vbP!;u3wV<|$UQA_zDpf)zU2jq=jyLSCMUm1& zfhXa>3-SVdvq{yaa6w>uza7nvXJ>vB{#?HIKpjX)vnRm*0?Yn@WJIUX8fAjM2|5kD z9e6t=6_BdYK+spg#xNkeM{a?#kUd}EM9g&nk_;EgewYtHhWaeSEZ}NB02%HCe4h)z zUvHxYuJ;k7d!F0Y*yw@jjao3RD*A1CuH-N;2OE-m3$b|L$Fe(+i{~^UI(Xlv%YY^U znFi~npmLQyHproW-y!;$p2CUmWFl}gXNv7Q=X(=(kK%WStx~&IUl)b`q_Rlh#H~PH zTC0r9b$MuvHW63h_^{{Ics+~YATM@{1C(_gn~%nYO0BMpRGqVGu(|!X^K?7yYm?^v zR25dWr7m4wR_e+4Gw@G;eCDC7aYnH$>S8GfMH72N{Ep!SK^MnU46ko6-0A+$Joc|? z;o4iM{)$k-ReB}~Gf9|g!ifGSkWFS`A3{73;8>j@SrTi)@{o>7sf|$*1H|~^r~#j2 zNz+WrG<7xDu`X4@M&ePk)iss!J$U-BdYH*g<^MR(MdaTZ>8vW$F5hLFkh*BzZ?0?z Get!YW;k$qU literal 0 HcmV?d00001 diff --git a/test/simple_source/bug27+/07_for_if_else-continue.py b/test/simple_source/bug27+/07_for_if_else-continue.py new file mode 100644 index 00000000..3944232a --- /dev/null +++ b/test/simple_source/bug27+/07_for_if_else-continue.py @@ -0,0 +1,33 @@ +# Issue #413 on 2.7 +# Bug in handling CONTINUE in else block of if-then-else in a for loop + +"""This program is self-checking!""" +def test1(a, r = None): + for b in a: + if b: + r = b + else: + continue + raise AssertionError("CONTINUE not followed") + if b: + pass + return r + +def test2(a, r = None): + for b in a: + if b: + #pass # No payload + continue + raise AssertionError("CONTINUE not followed") + else: + continue + raise AssertionError("CONTINUE not followed") + if b: + r = b + raise AssertionError("CONTINUE not followed") + return r + +assert test1([True]) == True, "Incorrect flow" +assert test2([True]) is None, "Incorrect flow" +assert test1([False]) is None, "Incorrect flow" +assert test2([False]) is None, "Incorrect flow"