You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
NT importstmt -> import to match AST
This commit is contained in:
21
README.rst
21
README.rst
@@ -3,7 +3,7 @@
|
|||||||
uncompyle6
|
uncompyle6
|
||||||
==========
|
==========
|
||||||
|
|
||||||
A native Python cross-version Decompiler and Fragment Decompiler.
|
A native Python cross-version decompiler and fragment decompiler.
|
||||||
The successor to decompyle, uncompyle, and uncompyle2.
|
The successor to decompyle, uncompyle, and uncompyle2.
|
||||||
|
|
||||||
|
|
||||||
@@ -17,12 +17,12 @@ source code. It accepts bytecodes from Python version 1.5, and 2.1 to
|
|||||||
Why this?
|
Why this?
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Ok, I'll say it: this software is amazing. It is a little more than
|
Ok, I'll say it: this software is amazing. It is more than your
|
||||||
just your normal hacky decompiler. Using compiler_ technology, the
|
normal hacky decompiler. Using compiler_ technology, the program
|
||||||
program creates a parse tree of the program from the instructions;
|
creates a parse tree of the program from the instructions; nodes at
|
||||||
nodes at the upper levels that look a little like what might come from
|
the upper levels that look a little like what might come from a Python
|
||||||
a Python AST. So we can really classify and understand what's going on
|
AST. So we can really classify and understand what's going on in
|
||||||
in sections of Python bytecode.
|
sections of Python bytecode.
|
||||||
|
|
||||||
Building on this, another thing that makes this different from other
|
Building on this, another thing that makes this different from other
|
||||||
CPython bytecode decompilers is the ability to deparse just
|
CPython bytecode decompilers is the ability to deparse just
|
||||||
@@ -37,9 +37,10 @@ See this_ for more information.
|
|||||||
|
|
||||||
Python fragment deparsing given an instruction offset is useful in
|
Python fragment deparsing given an instruction offset is useful in
|
||||||
showing stack traces and can be encorporated into any program that
|
showing stack traces and can be encorporated into any program that
|
||||||
wants to show a location in more detail than just a line number. This
|
wants to show a location in more detail than just a line number at
|
||||||
code can be also used when source-code information does not exist and
|
runtime. This code can be also used when source-code information does
|
||||||
there is just bytecode. Again, my debugggers make use of this.
|
not exist and there is just bytecode. Again, my debugggers make use of
|
||||||
|
this.
|
||||||
|
|
||||||
There were (and still are) a number of decompyle, uncompyle,
|
There were (and still are) a number of decompyle, uncompyle,
|
||||||
uncompyle2, uncompyle3 forks around. Almost all of them come basically
|
uncompyle2, uncompyle3 forks around. Almost all of them come basically
|
||||||
|
@@ -379,7 +379,7 @@ class PythonParser(GenericASTBuilder):
|
|||||||
|
|
||||||
def p_import20(self, args):
|
def p_import20(self, args):
|
||||||
"""
|
"""
|
||||||
stmt ::= importstmt
|
stmt ::= import
|
||||||
stmt ::= importfrom
|
stmt ::= importfrom
|
||||||
stmt ::= importstar
|
stmt ::= importstar
|
||||||
stmt ::= importmultiple
|
stmt ::= importmultiple
|
||||||
@@ -390,7 +390,7 @@ class PythonParser(GenericASTBuilder):
|
|||||||
alias ::= IMPORT_FROM store
|
alias ::= IMPORT_FROM store
|
||||||
alias ::= IMPORT_NAME load_attrs store
|
alias ::= IMPORT_NAME load_attrs store
|
||||||
|
|
||||||
importstmt ::= LOAD_CONST LOAD_CONST alias
|
import ::= LOAD_CONST LOAD_CONST alias
|
||||||
importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME IMPORT_STAR
|
importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME IMPORT_STAR
|
||||||
importfrom ::= LOAD_CONST LOAD_CONST IMPORT_NAME importlist POP_TOP
|
importfrom ::= LOAD_CONST LOAD_CONST IMPORT_NAME importlist POP_TOP
|
||||||
importmultiple ::= LOAD_CONST LOAD_CONST alias imports_cont
|
importmultiple ::= LOAD_CONST LOAD_CONST alias imports_cont
|
||||||
|
@@ -13,8 +13,8 @@ class Python15Parser(Python21Parser):
|
|||||||
|
|
||||||
def p_import15(self, args):
|
def p_import15(self, args):
|
||||||
"""
|
"""
|
||||||
importstmt ::= filler IMPORT_NAME STORE_FAST
|
import ::= filler IMPORT_NAME STORE_FAST
|
||||||
importstmt ::= filler IMPORT_NAME STORE_NAME
|
import ::= filler IMPORT_NAME STORE_NAME
|
||||||
|
|
||||||
importfrom ::= filler IMPORT_NAME importlist
|
importfrom ::= filler IMPORT_NAME importlist
|
||||||
importfrom ::= filler filler IMPORT_NAME importlist POP_TOP
|
importfrom ::= filler filler IMPORT_NAME importlist POP_TOP
|
||||||
|
@@ -26,7 +26,7 @@ class Python24Parser(Python25Parser):
|
|||||||
# 2.5+ has two LOAD_CONSTs, one for the number '.'s in a relative import
|
# 2.5+ has two LOAD_CONSTs, one for the number '.'s in a relative import
|
||||||
# keep positions similar to simplify semantic actions
|
# keep positions similar to simplify semantic actions
|
||||||
|
|
||||||
importstmt ::= filler LOAD_CONST alias
|
import ::= filler LOAD_CONST alias
|
||||||
importfrom ::= filler LOAD_CONST IMPORT_NAME importlist POP_TOP
|
importfrom ::= filler LOAD_CONST IMPORT_NAME importlist POP_TOP
|
||||||
importstar ::= filler LOAD_CONST IMPORT_NAME IMPORT_STAR
|
importstar ::= filler LOAD_CONST IMPORT_NAME IMPORT_STAR
|
||||||
|
|
||||||
|
@@ -274,7 +274,7 @@ TABLE_DIRECT = {
|
|||||||
'kv': ( '%c: %c', 3, 1 ),
|
'kv': ( '%c: %c', 3, 1 ),
|
||||||
'kv2': ( '%c: %c', 1, 2 ),
|
'kv2': ( '%c: %c', 1, 2 ),
|
||||||
'mapexpr': ( '{%[1]C}', (0, maxint, ', ') ),
|
'mapexpr': ( '{%[1]C}', (0, maxint, ', ') ),
|
||||||
'importstmt': ( '%|import %c\n', 2),
|
'import': ( '%|import %c\n', 2),
|
||||||
'importlist': ( '%C', (0, maxint, ', ') ),
|
'importlist': ( '%C', (0, maxint, ', ') ),
|
||||||
'importfrom': ( '%|from %[2]{pattr} import %c\n',
|
'importfrom': ( '%|from %[2]{pattr} import %c\n',
|
||||||
(3, 'importlist') ),
|
(3, 'importlist') ),
|
||||||
|
@@ -18,7 +18,7 @@ We add some format specifiers here not used in pysource
|
|||||||
from src to dest.
|
from src to dest.
|
||||||
|
|
||||||
For example in:
|
For example in:
|
||||||
'importstmt': ( '%|import %c%x\n', 2, (2,(0,1)), ),
|
'import': ( '%|import %c%x\n', 2, (2,(0,1)), ),
|
||||||
|
|
||||||
node 2 range information, it in %c, is copied to nodes 0 and 1.
|
node 2 range information, it in %c, is copied to nodes 0 and 1.
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ TABLE_DIRECT_FRAGMENT = {
|
|||||||
'continue_stmt': ( '%|%rcontinue\n', ),
|
'continue_stmt': ( '%|%rcontinue\n', ),
|
||||||
'passstmt': ( '%|%rpass\n', ),
|
'passstmt': ( '%|%rpass\n', ),
|
||||||
'raise_stmt0': ( '%|%rraise\n', ),
|
'raise_stmt0': ( '%|%rraise\n', ),
|
||||||
'importstmt': ( '%|import %c%x\n', 2, (2, (0, 1)), ),
|
'import': ( '%|import %c%x\n', 2, (2, (0, 1)), ),
|
||||||
'importfrom': ( '%|from %[2]{pattr}%x import %c\n', (2, (0, 1)), 3),
|
'importfrom': ( '%|from %[2]{pattr}%x import %c\n', (2, (0, 1)), 3),
|
||||||
'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ),
|
'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ),
|
||||||
'list_for': (' for %c%x in %c%c', 2, (2, (1, )), 0, 3 ),
|
'list_for': (' for %c%x in %c%c', 2, (2, (1, )), 0, 3 ),
|
||||||
|
Reference in New Issue
Block a user