You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Python 3.0 while1 if bug...
Is a workaround. We really need more tagging in of SETUP_LOOP and COME_FROM.
This commit is contained in:
BIN
test/bytecode_3.0/02_while1_if_while1.pyc
Normal file
BIN
test/bytecode_3.0/02_while1_if_while1.pyc
Normal file
Binary file not shown.
9
test/simple_source/bug30/02_while1_if_while1.py
Normal file
9
test/simple_source/bug30/02_while1_if_while1.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# From python 3.4 sre.pyc
|
||||
while 1:
|
||||
if __file__:
|
||||
while 1:
|
||||
if __file__:
|
||||
break
|
||||
raise RuntimeError
|
||||
else:
|
||||
raise RuntimeError
|
@@ -337,6 +337,9 @@ class Python3Parser(PythonParser):
|
||||
|
||||
whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
|
||||
else_suite COME_FROM_LOOP
|
||||
|
||||
# FIXME: This gets confused with if/else in a loop. But while/else in Python
|
||||
# is probably pretty rare.
|
||||
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK
|
||||
else_suite COME_FROM_LOOP
|
||||
|
||||
|
@@ -23,7 +23,16 @@ class Python30Parser(Python3Parser):
|
||||
jmp_true ::= JUMP_IF_TRUE POP_TOP
|
||||
jmp_false ::= JUMP_IF_FALSE POP_TOP
|
||||
|
||||
while1elsestmt ::= SETUP_LOOP l_stmts POP_TOP else_suite COME_FROM_LOOP JUMP_BACK
|
||||
# Used to keep index order the same in semantic actions
|
||||
jb_pop_top ::= JUMP_BACK POP_TOP
|
||||
|
||||
# FIXME: Add COME_FROM designators
|
||||
# This gets confused with while1elsestmt. But this is probably more common
|
||||
while1stmt ::= SETUP_LOOP l_stmts COME_FROM_LOOP
|
||||
|
||||
else_suitel ::= l_stmts COME_FROM_LOOP JUMP_BACK
|
||||
|
||||
ifelsestmtl ::= testexpr c_stmts_opt jb_pop_top else_suitel
|
||||
|
||||
withasstmt ::= expr setupwithas designator suite_stmts_opt
|
||||
POP_BLOCK LOAD_CONST COME_FROM_FINALLY
|
||||
|
@@ -149,7 +149,7 @@ class Scanner3(Scanner):
|
||||
"""
|
||||
|
||||
show_asm = self.show_asm if not show_asm else show_asm
|
||||
# show_asm = 'before'
|
||||
# show_asm = 'after'
|
||||
if show_asm in ('both', 'before'):
|
||||
bytecode = Bytecode(co, self.opc)
|
||||
for instr in bytecode.get_instructions(co):
|
||||
@@ -314,7 +314,9 @@ class Scanner3(Scanner):
|
||||
if target <= inst.offset:
|
||||
next_opname = self.opname[self.code[inst.offset+3]]
|
||||
if (inst.offset in self.stmts and
|
||||
next_opname not in ('END_FINALLY', 'POP_BLOCK')
|
||||
next_opname not in ('END_FINALLY', 'POP_BLOCK',
|
||||
# Python 3.0 only uses POP_TOP
|
||||
'POP_TOP')
|
||||
and inst.offset not in self.not_continue):
|
||||
opname = 'CONTINUE'
|
||||
else:
|
||||
|
@@ -1772,7 +1772,7 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
|
||||
|
||||
if deparsed.ast_errors:
|
||||
deparsed.write("# NOTE: have decompilation errors.\n")
|
||||
deparsed.write("# Use -t option to show full of errors.")
|
||||
deparsed.write("# Use -t option to show full context.")
|
||||
for err in deparsed.ast_errors:
|
||||
deparsed.write(err)
|
||||
deparsed.ERROR = True
|
||||
|
@@ -311,7 +311,7 @@ TABLE_DIRECT = {
|
||||
'whileTruestmt': ( '%|while True:\n%+%c%-\n\n', 1 ),
|
||||
'whilestmt': ( '%|while %c:\n%+%c%-\n\n', 1, 2 ),
|
||||
'while1stmt': ( '%|while 1:\n%+%c%-\n\n', 1 ),
|
||||
'while1elsestmt': ( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 3 ),
|
||||
'while1elsestmt': ( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n\n', 1, -2 ),
|
||||
'whileelsestmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 2, -2 ),
|
||||
'whileelselaststmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-', 1, 2, -2 ),
|
||||
'forstmt': ( '%|for %c in %c:\n%+%c%-\n\n', 3, 1, 4 ),
|
||||
@@ -1010,7 +1010,10 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
def n_ifelsestmt(self, node, preprocess=False):
|
||||
else_suite = node[3]
|
||||
|
||||
n = else_suite[0]
|
||||
try:
|
||||
n = else_suite[0]
|
||||
except:
|
||||
from trepan.api import debug; debug()
|
||||
|
||||
if len(n) == 1 == len(n[0]) and n[0] == '_stmts':
|
||||
n = n[0][0][0]
|
||||
@@ -2322,7 +2325,7 @@ def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False,
|
||||
|
||||
if deparsed.ast_errors:
|
||||
deparsed.write("# NOTE: have decompilation errors.\n")
|
||||
deparsed.write("# Use -t option to full context of errors.")
|
||||
deparsed.write("# Use -t option to show full context.")
|
||||
for err in deparsed.ast_errors:
|
||||
deparsed.write(err)
|
||||
raise SourceWalkerError("Deparsing hit an internal grammar-rule bug")
|
||||
|
Reference in New Issue
Block a user