You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
grammar tree -> parse tree
This commit is contained in:
@@ -135,7 +135,7 @@ class Python3Parser(PythonParser):
|
|||||||
iflaststmtl ::= testexpr c_stmts_opt JUMP_BACK COME_FROM_LOOP
|
iflaststmtl ::= testexpr c_stmts_opt JUMP_BACK COME_FROM_LOOP
|
||||||
iflaststmtl ::= testexpr c_stmts_opt JUMP_BACK POP_BLOCK
|
iflaststmtl ::= testexpr c_stmts_opt JUMP_BACK POP_BLOCK
|
||||||
|
|
||||||
# These are used to keep grammar tree indices the same
|
# These are used to keep parse tree indices the same
|
||||||
jump_forward_else ::= JUMP_FORWARD ELSE
|
jump_forward_else ::= JUMP_FORWARD ELSE
|
||||||
jump_absolute_else ::= JUMP_ABSOLUTE ELSE
|
jump_absolute_else ::= JUMP_ABSOLUTE ELSE
|
||||||
|
|
||||||
|
@@ -100,7 +100,7 @@ def align_deparse_code(version, co, out=sys.stderr, showasm=False, showast=False
|
|||||||
debug_parser['reduce'] = showgrammar
|
debug_parser['reduce'] = showgrammar
|
||||||
debug_parser['errorstack'] = True
|
debug_parser['errorstack'] = True
|
||||||
|
|
||||||
# Build a grammar tree from tokenized and massaged disassembly.
|
# Build a parse tree from tokenized and massaged disassembly.
|
||||||
deparsed = AligningWalker(version, scanner, out, showast=showast,
|
deparsed = AligningWalker(version, scanner, out, showast=showast,
|
||||||
debug_parser=debug_parser, compile_mode=compile_mode,
|
debug_parser=debug_parser, compile_mode=compile_mode,
|
||||||
is_pypy = is_pypy)
|
is_pypy = is_pypy)
|
||||||
@@ -125,7 +125,7 @@ def align_deparse_code(version, co, out=sys.stderr, showasm=False, showast=False
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# What we've been waiting for: Generate Python source from the grammar tree!
|
# What we've been waiting for: Generate Python source from the parse tree!
|
||||||
deparsed.gen_source(deparsed.ast, co.co_name, customize)
|
deparsed.gen_source(deparsed.ast, co.co_name, customize)
|
||||||
|
|
||||||
for g in deparsed.mod_globs:
|
for g in deparsed.mod_globs:
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Python grammar tree checker.
|
Python parse tree checker.
|
||||||
|
|
||||||
Our rules sometimes give erroneous results. Until we have perfect rules,
|
Our rules sometimes give erroneous results. Until we have perfect rules,
|
||||||
This checker will catch mistakes in decompilation we've made.
|
This checker will catch mistakes in decompilation we've made.
|
||||||
|
@@ -16,7 +16,7 @@ else:
|
|||||||
|
|
||||||
LINE_LENGTH = 80
|
LINE_LENGTH = 80
|
||||||
|
|
||||||
# Some grammar trees created below are used for comparing code
|
# Some parse trees created below are used for comparing code
|
||||||
# fragments (like 'return None' at the end of functions).
|
# fragments (like 'return None' at the end of functions).
|
||||||
|
|
||||||
RETURN_LOCALS = AST('return',
|
RETURN_LOCALS = AST('return',
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
# Copyright (c) 2015-2018 by Rocky Bernstein
|
# Copyright (c) 2015-2018 by Rocky Bernstein
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Creates Python source code from an uncompyle6 grammar tree,
|
Creates Python source code from an uncompyle6 parse tree,
|
||||||
and indexes fragments which can be accessed by instruction offset
|
and indexes fragments which can be accessed by instruction offset
|
||||||
address.
|
address.
|
||||||
|
|
||||||
@@ -1050,7 +1050,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
n_classdefdeco2 = n_classdef
|
n_classdefdeco2 = n_classdef
|
||||||
|
|
||||||
def gen_source(self, ast, name, customize, is_lambda=False, returnNone=False):
|
def gen_source(self, ast, name, customize, is_lambda=False, returnNone=False):
|
||||||
"""convert grammar tree to Python source code"""
|
"""convert parse tree to Python source code"""
|
||||||
|
|
||||||
rn = self.return_none
|
rn = self.return_none
|
||||||
self.return_none = returnNone
|
self.return_none = returnNone
|
||||||
@@ -1116,7 +1116,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
if len(tokens) == 0:
|
if len(tokens) == 0:
|
||||||
return PASS
|
return PASS
|
||||||
|
|
||||||
# Build grammar tree from tokenized and massaged disassembly.
|
# Build parse tree from tokenized and massaged disassembly.
|
||||||
try:
|
try:
|
||||||
# FIXME: have p.insts update in a better way
|
# FIXME: have p.insts update in a better way
|
||||||
# modularity is broken here
|
# modularity is broken here
|
||||||
@@ -1719,7 +1719,7 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
|
|||||||
pass a file like object, into which the asm will be
|
pass a file like object, into which the asm will be
|
||||||
written).
|
written).
|
||||||
:param showast: Flag which determines whether the constructed
|
:param showast: Flag which determines whether the constructed
|
||||||
grammar tree is written to sys.stdout or
|
parse tree is written to sys.stdout or
|
||||||
not. (It is also to pass a file like object, into
|
not. (It is also to pass a file like object, into
|
||||||
which the ast will be written).
|
which the ast will be written).
|
||||||
:param showgrammar: Flag which determines whether the grammar reduction rules
|
:param showgrammar: Flag which determines whether the grammar reduction rules
|
||||||
|
@@ -25,7 +25,8 @@ def find_all_globals(node, globs):
|
|||||||
return globs
|
return globs
|
||||||
|
|
||||||
def find_globals(node, globs):
|
def find_globals(node, globs):
|
||||||
"""search grammar-tree node to find variable names that need a 'global' added."""
|
"""search a node of parse tree to find variable names that need a
|
||||||
|
'global' added."""
|
||||||
for n in node:
|
for n in node:
|
||||||
if isinstance(n, AST):
|
if isinstance(n, AST):
|
||||||
globs = find_globals(n, globs)
|
globs = find_globals(n, globs)
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||||
# Copyright (c) 1999 John Aycock
|
# Copyright (c) 1999 John Aycock
|
||||||
|
|
||||||
"""Creates Python source code from an uncompyle6 grammar tree.
|
"""Creates Python source code from an uncompyle6 parse tree.
|
||||||
|
|
||||||
The terminal symbols are CPython bytecode instructions. (See the
|
The terminal symbols are CPython bytecode instructions. (See the
|
||||||
python documentation under module "dis" for a list of instructions
|
python documentation under module "dis" for a list of instructions
|
||||||
@@ -47,7 +47,7 @@ Python.
|
|||||||
# In the diagram below, N is a nonterminal name, and K also a nonterminal
|
# In the diagram below, N is a nonterminal name, and K also a nonterminal
|
||||||
# name but the one used as a key in the table.
|
# name but the one used as a key in the table.
|
||||||
# we show where those are with respect to each other in the
|
# we show where those are with respect to each other in the
|
||||||
# grammar tree for N.
|
# parse tree for N.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# N&K N N
|
# N&K N N
|
||||||
@@ -2587,7 +2587,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
if len(tokens) == 0:
|
if len(tokens) == 0:
|
||||||
return PASS
|
return PASS
|
||||||
|
|
||||||
# Build a grammar tree from a tokenized and massaged disassembly.
|
# Build a parse tree from a tokenized and massaged disassembly.
|
||||||
try:
|
try:
|
||||||
# FIXME: have p.insts update in a better way
|
# FIXME: have p.insts update in a better way
|
||||||
# modularity is broken here
|
# modularity is broken here
|
||||||
|
@@ -23,7 +23,7 @@ def maybe_show_tree(show_tree, ast):
|
|||||||
Show the ast based on the showast flag (or file object), writing to the
|
Show the ast based on the showast flag (or file object), writing to the
|
||||||
appropriate stream depending on the type of the flag.
|
appropriate stream depending on the type of the flag.
|
||||||
|
|
||||||
:param show_tree: Flag which determines whether the grammar tree is
|
:param show_tree: Flag which determines whether the parse tree is
|
||||||
written to sys.stdout or not. (It is also to pass a file
|
written to sys.stdout or not. (It is also to pass a file
|
||||||
like object, into which the ast will be written).
|
like object, into which the ast will be written).
|
||||||
:param ast: The ast to show.
|
:param ast: The ast to show.
|
||||||
|
Reference in New Issue
Block a user