You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Add Python 2.3 rule for "if 1: ..."
Fully fixes #97 for Python 2.3. Python 2.4 was fixed in a previous commit.
This commit is contained in:
BIN
test/bytecode_2.3/03_if1.pyc
Normal file
BIN
test/bytecode_2.3/03_if1.pyc
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2016 Rocky Bernstein
|
||||
# Copyright (c) 2016-2017 Rocky Bernstein
|
||||
# Copyright (c) 2000-2002 by hartmut Goebel <hartmut@goebel.noris.de>
|
||||
# Copyright (c) 1999 John Aycock
|
||||
|
||||
@@ -14,6 +14,17 @@ class Python23Parser(Python24Parser):
|
||||
|
||||
def p_misc23(self, args):
|
||||
'''
|
||||
# Python 2.4 only adds something like the below for if 1:
|
||||
# However we will just treat it as a noop (which of course messes up
|
||||
# simple verify of bytecode.
|
||||
# See also below in reduce_is_invalid where we check that the JUMP_FORWARD
|
||||
# target matches the COME_FROM target
|
||||
stmt ::= if1_stmt
|
||||
if1_stmt ::= JUMP_FORWARD JUMP_IF_FALSE THEN POP_TOP COME_FROM
|
||||
stmts
|
||||
JUMP_FORWARD COME_FROM POP_TOP COME_FROM
|
||||
|
||||
|
||||
# Used to keep semantic positions the same across later versions
|
||||
# of Python
|
||||
_while1test ::= SETUP_LOOP JUMP_FORWARD JUMP_IF_FALSE POP_TOP COME_FROM
|
||||
@@ -33,6 +44,23 @@ class Python23Parser(Python24Parser):
|
||||
lc_body ::= LOAD_FAST expr LIST_APPEND
|
||||
'''
|
||||
|
||||
def add_custom_rules(self, tokens, customize):
|
||||
super(Python23Parser, self).add_custom_rules(tokens, customize)
|
||||
|
||||
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||
invalid = super(Python24Parser,
|
||||
self).reduce_is_invalid(rule, ast,
|
||||
tokens, first, last)
|
||||
if invalid:
|
||||
return invalid
|
||||
|
||||
# FiXME: this code never gets called...
|
||||
lhs = rule[0]
|
||||
if lhs == 'nop_stmt':
|
||||
return not int(tokens[first].pattr) == tokens[last].offset
|
||||
|
||||
return False
|
||||
|
||||
class Python23ParserSingle(Python23Parser, PythonParserSingle):
|
||||
pass
|
||||
|
||||
|
@@ -218,6 +218,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
'importlist2': ( '%C', (0, maxint, ', ') ),
|
||||
})
|
||||
if version <= 2.4:
|
||||
if version == 2.3:
|
||||
TABLE_DIRECT.update({
|
||||
'if1_stmt': ( '%|if 1\n%+%c%-', 5 )
|
||||
})
|
||||
|
||||
global NAME_MODULE
|
||||
NAME_MODULE = AST('stmt',
|
||||
[ AST('assign',
|
||||
|
Reference in New Issue
Block a user