You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Another 2.6 while stmt. Clean up grammar a little
This commit is contained in:
@@ -199,13 +199,7 @@ class PythonParser(GenericASTBuilder):
|
||||
_jump ::= JUMP_FORWARD
|
||||
_jump ::= JUMP_BACK
|
||||
|
||||
# Note: Python < 2.7 doesn't have POP_JUMP_IF ...
|
||||
# FIXME: segregate 2.7+
|
||||
|
||||
jmp_false ::= POP_JUMP_IF_FALSE
|
||||
jmp_true ::= POP_JUMP_IF_TRUE
|
||||
|
||||
# Zero or more COME_FROM
|
||||
# Zero or more COME_FROMs
|
||||
# loops can have this
|
||||
_come_from ::= _come_from COME_FROM
|
||||
_come_from ::=
|
||||
|
@@ -67,8 +67,6 @@ class Python26Parser(Python2Parser):
|
||||
# after one of these jumps
|
||||
def p_jumps26(self, args):
|
||||
"""
|
||||
jmp_false ::= JUMP_IF_FALSE
|
||||
jmp_true ::= JUMP_IF_TRUE
|
||||
jmp_true ::= JUMP_IF_TRUE POP_TOP
|
||||
jmp_false ::= JUMP_IF_FALSE POP_TOP
|
||||
jf_pop ::= JUMP_FORWARD come_from_pop
|
||||
@@ -82,7 +80,8 @@ class Python26Parser(Python2Parser):
|
||||
ja_cf_pop ::= JUMP_ABSOLUTE come_from_pop
|
||||
jf_cf_pop ::= JUMP_FORWARD come_froms POP_TOP
|
||||
|
||||
jb_bp_come_from ::= JUMP_BACK POP_BLOCK COME_FROM
|
||||
bp_come_from ::= POP_BLOCK COME_FROM
|
||||
jb_bp_come_from ::= JUMP_BACK bp_come_from
|
||||
|
||||
_ifstmts_jump ::= c_stmts_opt jf_pop COME_FROM
|
||||
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM come_from_pop
|
||||
@@ -92,6 +91,7 @@ class Python26Parser(Python2Parser):
|
||||
# we start a new block. For reasons I don't fully
|
||||
# understand, there is also a value on the top of the stack
|
||||
come_from_pop ::= COME_FROM POP_TOP
|
||||
|
||||
"""
|
||||
|
||||
def p_stmt26(self, args):
|
||||
@@ -133,9 +133,10 @@ class Python26Parser(Python2Parser):
|
||||
|
||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK _come_from
|
||||
|
||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop POP_BLOCK COME_FROM
|
||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop bp_come_from
|
||||
whilestmt ::= SETUP_LOOP testexpr return_stmts come_froms POP_TOP bp_come_from
|
||||
|
||||
while1stmt ::= SETUP_LOOP return_stmts POP_BLOCK COME_FROM
|
||||
while1stmt ::= SETUP_LOOP return_stmts bp_come_from
|
||||
|
||||
return_stmt ::= ret_expr RETURN_END_IF come_from_pop
|
||||
return_stmt ::= ret_expr RETURN_VALUE come_from_pop
|
||||
|
@@ -30,9 +30,11 @@ class Python27Parser(Python2Parser):
|
||||
jmp_false POP_TOP designator POP_TOP
|
||||
"""
|
||||
|
||||
def p_misc27(self, args):
|
||||
def p_jump27(self, args):
|
||||
"""
|
||||
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM
|
||||
jmp_false ::= POP_JUMP_IF_FALSE
|
||||
jmp_true ::= POP_JUMP_IF_TRUE
|
||||
"""
|
||||
|
||||
|
||||
|
@@ -247,6 +247,8 @@ class Python3Parser(PythonParser):
|
||||
"""
|
||||
come_froms ::= come_froms COME_FROM
|
||||
come_froms ::= COME_FROM
|
||||
jmp_false ::= POP_JUMP_IF_FALSE
|
||||
jmp_true ::= POP_JUMP_IF_TRUE
|
||||
"""
|
||||
|
||||
def p_stmt3(self, args):
|
||||
|
@@ -542,6 +542,8 @@ class Scanner2(scan.Scanner):
|
||||
# not myself? If so, it's part of a larger conditional.
|
||||
# rocky: if we have a conditional jump to the next instruction, then
|
||||
# possibly I am "skipping over" a "pass" or null statement.
|
||||
|
||||
## FIXME: need to handle <2.7 which has this as two instructions.
|
||||
if ( code[pre[target]] in
|
||||
(self.pop_jump_if_or_pop | self.pop_jump_if)
|
||||
and (target > pos) ):
|
||||
|
@@ -272,6 +272,8 @@ class Scanner26(scan.Scanner2):
|
||||
if offset in self.load_asserts:
|
||||
op_name = 'LOAD_ASSERT'
|
||||
elif op == self.opc.RETURN_VALUE:
|
||||
# FIXME: return_end_ifs calculation is off.
|
||||
# not taking into account "and" expressions
|
||||
if offset in self.return_end_ifs:
|
||||
op_name = 'RETURN_END_IF'
|
||||
|
||||
|
Reference in New Issue
Block a user