Skip to content

Commit

Permalink
fixes 151
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Jan 29, 2018
1 parent 5edcc7c commit 5039a71
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Binary file added test/bytecode_2.7/05_while_if_continue.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions test/simple_source/bug27+/05_while_if_continue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Issue 151 for Python 2.7
# Bug was two-fold. Not having a rile for a while loop with an ending return statement
# and allowing iflastsmtl to have an optional c_stmt which allowed the "if" to get
# comined into the "while". A separate analysis for control flow should make this
# simpiler.
def func(a, b, c):
while a:
if b:
continue
return False
return True
2 changes: 1 addition & 1 deletion uncompyle6/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def p_stmt(self, args):
stmt ::= return
return ::= ret_expr RETURN_VALUE
# returns are a sequence of statements that ends in a RETURN statement.
# "returns" nonterminal is a sequence of statements that ends in a RETURN statement.
# In later Python versions with jump optimization, this can cause JUMPs
# that would normally appear to be omitted.
Expand Down
6 changes: 4 additions & 2 deletions uncompyle6/parsers/parse27.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def p_try27(self, args):

def p_jump27(self, args):
"""
iflaststmtl ::= testexpr c_stmts_opt
iflaststmtl ::= testexpr c_stmts
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD come_froms
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD come_froms
bp_come_from ::= POP_BLOCK COME_FROM
# FIXME: Common with 3.0+
Expand Down Expand Up @@ -119,6 +119,8 @@ def p_stmt27(self, args):
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY
whilestmt ::= SETUP_LOOP testexpr returns POP_BLOCK COME_FROM
while1stmt ::= SETUP_LOOP returns bp_come_from
while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK _come_froms
Expand Down

0 comments on commit 5039a71

Please # to comment.