You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Better "continue" detection on Python 3.0
This commit is contained in:
@@ -34,6 +34,7 @@ class Python30Parser(Python31Parser):
|
|||||||
|
|
||||||
ifelsestmtl ::= testexpr c_stmts_opt jb_pop_top else_suitel
|
ifelsestmtl ::= testexpr c_stmts_opt jb_pop_top else_suitel
|
||||||
iflaststmtl ::= testexpr c_stmts_opt jb_pop_top
|
iflaststmtl ::= testexpr c_stmts_opt jb_pop_top
|
||||||
|
iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE POP_TOP
|
||||||
|
|
||||||
withasstmt ::= expr setupwithas store suite_stmts_opt
|
withasstmt ::= expr setupwithas store suite_stmts_opt
|
||||||
POP_BLOCK LOAD_CONST COME_FROM_FINALLY
|
POP_BLOCK LOAD_CONST COME_FROM_FINALLY
|
||||||
@@ -76,8 +77,10 @@ class Python30Parser(Python31Parser):
|
|||||||
def customize_grammar_rules(self, tokens, customize):
|
def customize_grammar_rules(self, tokens, customize):
|
||||||
super(Python30Parser, self).customize_grammar_rules(tokens, customize)
|
super(Python30Parser, self).customize_grammar_rules(tokens, customize)
|
||||||
self.remove_rules("""
|
self.remove_rules("""
|
||||||
iflaststmtl ::= testexpr c_stmts_opt JUMP_BACK COME_FROM_LOOP
|
iflaststmtl ::= testexpr c_stmts_opt JUMP_BACK COME_FROM_LOOP
|
||||||
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel
|
||||||
|
iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE
|
||||||
|
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_froms
|
||||||
jump_forward_else ::= JUMP_FORWARD ELSE
|
jump_forward_else ::= JUMP_FORWARD ELSE
|
||||||
jump_absolute_else ::= JUMP_ABSOLUTE ELSE
|
jump_absolute_else ::= JUMP_ABSOLUTE ELSE
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
|
||||||
|
@@ -73,8 +73,10 @@ class Scanner3(Scanner):
|
|||||||
|
|
||||||
if self.version == 3.0:
|
if self.version == 3.0:
|
||||||
self.pop_jump_tf = frozenset([self.opc.JUMP_IF_FALSE, self.opc.JUMP_IF_TRUE])
|
self.pop_jump_tf = frozenset([self.opc.JUMP_IF_FALSE, self.opc.JUMP_IF_TRUE])
|
||||||
|
self.not_continue_follow = ('END_FINALLY', 'POP_BLOCK', 'POP_TOP')
|
||||||
else:
|
else:
|
||||||
self.pop_jump_tf = frozenset([self.opc.PJIF, self.opc.PJIT])
|
self.pop_jump_tf = frozenset([self.opc.PJIF, self.opc.PJIT])
|
||||||
|
self.not_continue_follow = ('END_FINALLY', 'POP_BLOCK')
|
||||||
|
|
||||||
self.setup_ops_no_loop = frozenset(setup_ops) - frozenset([self.opc.SETUP_LOOP])
|
self.setup_ops_no_loop = frozenset(setup_ops) - frozenset([self.opc.SETUP_LOOP])
|
||||||
|
|
||||||
@@ -387,13 +389,9 @@ class Scanner3(Scanner):
|
|||||||
.opname == 'FOR_ITER'
|
.opname == 'FOR_ITER'
|
||||||
and self.insts[i+1].opname == 'JUMP_FORWARD')
|
and self.insts[i+1].opname == 'JUMP_FORWARD')
|
||||||
|
|
||||||
|
|
||||||
if (is_continue or
|
if (is_continue or
|
||||||
(inst.offset in self.stmts and
|
(inst.offset in self.stmts and (inst.starts_line and
|
||||||
(self.version != 3.0 or (hasattr(inst, 'linestart'))) and
|
next_opname not in self.not_continue_follow))):
|
||||||
(next_opname not in ('END_FINALLY', 'POP_BLOCK',
|
|
||||||
# Python 3.0 only uses POP_TOP
|
|
||||||
'POP_TOP')))):
|
|
||||||
opname = 'CONTINUE'
|
opname = 'CONTINUE'
|
||||||
else:
|
else:
|
||||||
opname = 'JUMP_BACK'
|
opname = 'JUMP_BACK'
|
||||||
|
Reference in New Issue
Block a user