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 except clause parsing bug
This commit is contained in:
BIN
test/bytecode_3.4/08_while_except_bug.pyc
Normal file
BIN
test/bytecode_3.4/08_while_except_bug.pyc
Normal file
Binary file not shown.
9
test/simple_source/looping/08_while_except_bug.py
Normal file
9
test/simple_source/looping/08_while_except_bug.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# From python 3.4 contextlib
|
||||||
|
# JUMP_BACK in while causes a problem
|
||||||
|
while exit_callbacks:
|
||||||
|
try:
|
||||||
|
if cb:
|
||||||
|
exc_details = 5
|
||||||
|
except:
|
||||||
|
exc_details = new_exc_details
|
||||||
|
pass
|
@@ -40,8 +40,13 @@ class PythonParser(GenericASTBuilder):
|
|||||||
setattr(self, i, None)
|
setattr(self, i, None)
|
||||||
|
|
||||||
def error(self, tokens, index):
|
def error(self, tokens, index):
|
||||||
start = index - 2 if index - 2 > 0 else 0
|
# Find the last line boundary
|
||||||
finish = index +2 if index + 2 < len(tokens) else len(tokens)
|
for start in range(index, -1, -1):
|
||||||
|
if tokens[start].linestart: break
|
||||||
|
pass
|
||||||
|
for finish in range(index+1, len(tokens)):
|
||||||
|
if tokens[finish].linestart: break
|
||||||
|
pass
|
||||||
err_token = tokens[index]
|
err_token = tokens[index]
|
||||||
print("Token context:")
|
print("Token context:")
|
||||||
for i in range(start, finish):
|
for i in range(start, finish):
|
||||||
@@ -118,6 +123,19 @@ class PythonParser(GenericASTBuilder):
|
|||||||
genexpr_func ::= LOAD_FAST FOR_ITER designator comp_iter JUMP_BACK
|
genexpr_func ::= LOAD_FAST FOR_ITER designator comp_iter JUMP_BACK
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
def p_jump(self, args):
|
||||||
|
"""
|
||||||
|
_jump ::= JUMP_ABSOLUTE
|
||||||
|
_jump ::= JUMP_FORWARD
|
||||||
|
_jump ::= JUMP_BACK
|
||||||
|
|
||||||
|
# Note: Python < 2.7 doesn't have POP_JUMP_IF ...
|
||||||
|
jmp_false ::= POP_JUMP_IF_FALSE
|
||||||
|
jmp_false ::= JUMP_IF_FALSE
|
||||||
|
jmp_true ::= POP_JUMP_IF_TRUE
|
||||||
|
jmp_true ::= JUMP_IF_TRUE
|
||||||
|
"""
|
||||||
|
|
||||||
def p_dictcomp(self, args):
|
def p_dictcomp(self, args):
|
||||||
'''
|
'''
|
||||||
expr ::= dictcomp
|
expr ::= dictcomp
|
||||||
|
@@ -189,15 +189,6 @@ class Python2Parser(PythonParser):
|
|||||||
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
|
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
|
||||||
classdefdeco2 ::= LOAD_CONST expr mkfunc CALL_FUNCTION_0 BUILD_CLASS
|
classdefdeco2 ::= LOAD_CONST expr mkfunc CALL_FUNCTION_0 BUILD_CLASS
|
||||||
|
|
||||||
_jump ::= JUMP_ABSOLUTE
|
|
||||||
_jump ::= JUMP_FORWARD
|
|
||||||
_jump ::= JUMP_BACK
|
|
||||||
|
|
||||||
jmp_false ::= POP_JUMP_IF_FALSE
|
|
||||||
jmp_false ::= JUMP_IF_FALSE
|
|
||||||
jmp_true ::= POP_JUMP_IF_TRUE
|
|
||||||
jmp_true ::= JUMP_IF_TRUE
|
|
||||||
|
|
||||||
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1
|
||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2
|
||||||
@@ -270,8 +261,7 @@ class Python2Parser(PythonParser):
|
|||||||
except_cond2 ::= DUP_TOP expr COMPARE_OP
|
except_cond2 ::= DUP_TOP expr COMPARE_OP
|
||||||
jmp_false POP_TOP designator POP_TOP
|
jmp_false POP_TOP designator POP_TOP
|
||||||
|
|
||||||
except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt JUMP_FORWARD
|
except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt _jump
|
||||||
except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt jmp_abs
|
|
||||||
except ::= POP_TOP POP_TOP POP_TOP return_stmts
|
except ::= POP_TOP POP_TOP POP_TOP return_stmts
|
||||||
|
|
||||||
jmp_abs ::= JUMP_ABSOLUTE
|
jmp_abs ::= JUMP_ABSOLUTE
|
||||||
|
@@ -195,15 +195,6 @@ class Python3Parser(PythonParser):
|
|||||||
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
|
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
|
||||||
classdefdeco2 ::= LOAD_CONST expr mkfunc CALL_FUNCTION_0 BUILD_CLASS
|
classdefdeco2 ::= LOAD_CONST expr mkfunc CALL_FUNCTION_0 BUILD_CLASS
|
||||||
|
|
||||||
_jump ::= JUMP_ABSOLUTE
|
|
||||||
_jump ::= JUMP_FORWARD
|
|
||||||
_jump ::= JUMP_BACK
|
|
||||||
|
|
||||||
jmp_false ::= POP_JUMP_IF_FALSE
|
|
||||||
jmp_false ::= JUMP_IF_FALSE
|
|
||||||
jmp_true ::= POP_JUMP_IF_TRUE
|
|
||||||
jmp_true ::= JUMP_IF_TRUE
|
|
||||||
|
|
||||||
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1
|
||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr RAISE_VARARGS_2
|
||||||
@@ -293,15 +284,14 @@ class Python3Parser(PythonParser):
|
|||||||
except_cond2 ::= DUP_TOP expr COMPARE_OP
|
except_cond2 ::= DUP_TOP expr COMPARE_OP
|
||||||
jmp_false POP_TOP designator POP_TOP
|
jmp_false POP_TOP designator POP_TOP
|
||||||
|
|
||||||
except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt POP_EXCEPT JUMP_FORWARD
|
except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt POP_EXCEPT _jump
|
||||||
except ::= POP_TOP POP_TOP POP_TOP return_stmts
|
except ::= POP_TOP POP_TOP POP_TOP return_stmts
|
||||||
|
|
||||||
except_pop_except ::= POP_TOP POP_TOP POP_TOP POP_EXCEPT c_stmts_opt JUMP_FORWARD
|
|
||||||
except_pop_except ::= POP_TOP POP_TOP POP_TOP POP_EXCEPT c_stmts_opt jmp_abs
|
|
||||||
|
|
||||||
jmp_abs ::= JUMP_ABSOLUTE
|
jmp_abs ::= JUMP_ABSOLUTE
|
||||||
jmp_abs ::= JUMP_BACK
|
jmp_abs ::= JUMP_BACK
|
||||||
|
|
||||||
|
|
||||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt
|
||||||
POP_BLOCK LOAD_CONST COME_FROM
|
POP_BLOCK LOAD_CONST COME_FROM
|
||||||
WITH_CLEANUP END_FINALLY
|
WITH_CLEANUP END_FINALLY
|
||||||
@@ -314,7 +304,6 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
def p_misc(self, args):
|
def p_misc(self, args):
|
||||||
"""
|
"""
|
||||||
_jump ::= NOP
|
|
||||||
try_middle ::= JUMP_FORWARD COME_FROM except_stmts END_FINALLY NOP COME_FROM
|
try_middle ::= JUMP_FORWARD COME_FROM except_stmts END_FINALLY NOP COME_FROM
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@@ -331,7 +331,6 @@ TABLE_DIRECT = {
|
|||||||
'tf_trystmt': ( '%c%-%c%+', 1, 3 ),
|
'tf_trystmt': ( '%c%-%c%+', 1, 3 ),
|
||||||
'tf_tryelsestmt': ( '%c%-%c%|else:\n%+%c', 1, 3, 4 ),
|
'tf_tryelsestmt': ( '%c%-%c%|else:\n%+%c', 1, 3, 4 ),
|
||||||
'except': ('%|except:\n%+%c%-', 3 ),
|
'except': ('%|except:\n%+%c%-', 3 ),
|
||||||
'except_pop_except': ('%|except:\n%+%c%-', 4 ),
|
|
||||||
'except_cond1': ( '%|except %c:\n', 1 ),
|
'except_cond1': ( '%|except %c:\n', 1 ),
|
||||||
'except_cond2': ( '%|except %c as %c:\n', 1, 5 ),
|
'except_cond2': ( '%|except %c as %c:\n', 1, 5 ),
|
||||||
'except_suite': ( '%+%c%-%C', 0, (1, maxint, '') ),
|
'except_suite': ( '%+%c%-%C', 0, (1, maxint, '') ),
|
||||||
|
Reference in New Issue
Block a user