From 659f37585b3a9099083098ab82e71a88eac07d96 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 12 Nov 2019 16:31:43 -0500 Subject: [PATCH] Bug in 3.0 rule in "jump_absolute_else" ... and disallowing "else" to the wrong place. --- test/bytecode_3.0/03_ifelse.pyc | Bin 1386 -> 1641 bytes test/simple_source/bug30/03_ifelse.py | 13 +++++++++++++ uncompyle6/parsers/parse30.py | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/test/bytecode_3.0/03_ifelse.pyc b/test/bytecode_3.0/03_ifelse.pyc index fa86044c03c436fc60a1020c1bcd65c16795a348..aa09846c53bed72615dd511444fccf712df43377 100644 GIT binary patch delta 284 zcmaFG^^!;4nunK*PvvxMG6ND|0}*149%GLkb&1um<}^|3;SjWM-&Z z79b5`JA>5%i3(kY8U_ZJSXG8vW`-I@hI|PI#u_Gud>$YLK_cuNCl3!dCp!RAy%0M9 diff --git a/test/simple_source/bug30/03_ifelse.py b/test/simple_source/bug30/03_ifelse.py index fcb813fd..a5b9d655 100644 --- a/test/simple_source/bug30/03_ifelse.py +++ b/test/simple_source/bug30/03_ifelse.py @@ -35,3 +35,16 @@ def __instancecheck__(subtype, subclass, cls): if subtype: if (cls and subclass): return False + + +# Adapted from 3.0.1 abc.py +# Bug was rule in "jump_absolute_else" and disasllowing +# "else" to the wrong place. + +def _strptime(locale_time, found_zone, time): + for tz_values in locale_time: + if found_zone: + if (time and found_zone): + break + else: + break diff --git a/uncompyle6/parsers/parse30.py b/uncompyle6/parsers/parse30.py index 779768fe..7b4023d6 100644 --- a/uncompyle6/parsers/parse30.py +++ b/uncompyle6/parsers/parse30.py @@ -43,7 +43,11 @@ class Python30Parser(Python31Parser): else_suitel ::= l_stmts COME_FROM_LOOP JUMP_BACK + jump_absolute_else ::= COME_FROM JUMP_ABSOLUTE COME_FROM POP_TOP + + ifelsestmtc ::= testexpr c_stmts_opt jump_absolute_else else_suitec ifelsestmtl ::= testexpr c_stmts_opt jb_pop_top else_suitel + iflaststmtl ::= testexpr c_stmts_opt jb_pop_top iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE COME_FROM POP_TOP @@ -187,7 +191,7 @@ class Python30Parser(Python31Parser): self.check_reduce["iflaststmtl"] = "AST" self.check_reduce['ifstmt'] = "AST" - # self.check_reduce["ifelsestmt"] = "AST" + self.check_reduce["ifelsestmtc"] = "AST" return def reduce_is_invalid(self, rule, ast, tokens, first, last): @@ -197,12 +201,17 @@ class Python30Parser(Python31Parser): if invalid: return invalid if ( - rule[0] in ("iflaststmtl", "ifstmt") and ast[0] == "testexpr" + rule[0] in ("iflaststmtl", "ifstmt", "ifelsestmtc") and ast[0] == "testexpr" ): testexpr = ast[0] if testexpr[0] == "testfalse": testfalse = testexpr[0] - if testfalse[1] == "jmp_false": + if rule[0] == "ifelsestmtc" and ast[2] == "jump_absolute_else": + jump_absolute_else = ast[2] + come_from = jump_absolute_else[2] + return come_from == "COME_FROM" and come_from.attr < tokens[first].offset + pass + elif testfalse[1] == "jmp_false": jmp_false = testfalse[1] if last == len(tokens): last -= 1