From 34117522b21cfb162ae0764ccef35aaea5bfe3ce Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 29 Nov 2017 20:20:54 -0500 Subject: [PATCH] NT importstmt -> import to match AST --- README.rst | 21 +++++++++++---------- uncompyle6/parser.py | 4 ++-- uncompyle6/parsers/parse15.py | 4 ++-- uncompyle6/parsers/parse24.py | 2 +- uncompyle6/semantics/consts.py | 2 +- uncompyle6/semantics/fragments.py | 4 ++-- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.rst b/README.rst index 6d8098ec..df61fa56 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ 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. @@ -17,12 +17,12 @@ source code. It accepts bytecodes from Python version 1.5, and 2.1 to Why this? --------- -Ok, I'll say it: this software is amazing. It is a little more than -just your normal hacky decompiler. Using compiler_ technology, the -program creates a parse tree of the program from the instructions; -nodes at the upper levels that look a little like what might come from -a Python AST. So we can really classify and understand what's going on -in sections of Python bytecode. +Ok, I'll say it: this software is amazing. It is more than your +normal hacky decompiler. Using compiler_ technology, the program +creates a parse tree of the program from the instructions; nodes at +the upper levels that look a little like what might come from a Python +AST. So we can really classify and understand what's going on in +sections of Python bytecode. Building on this, another thing that makes this different from other 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 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 -code can be also used when source-code information does not exist and -there is just bytecode. Again, my debugggers make use of this. +wants to show a location in more detail than just a line number at +runtime. This code can be also used when source-code information does +not exist and there is just bytecode. Again, my debugggers make use of +this. There were (and still are) a number of decompyle, uncompyle, uncompyle2, uncompyle3 forks around. Almost all of them come basically diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index dd20bdf2..1cea77a3 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -379,7 +379,7 @@ class PythonParser(GenericASTBuilder): def p_import20(self, args): """ - stmt ::= importstmt + stmt ::= import stmt ::= importfrom stmt ::= importstar stmt ::= importmultiple @@ -390,7 +390,7 @@ class PythonParser(GenericASTBuilder): alias ::= IMPORT_FROM 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 importfrom ::= LOAD_CONST LOAD_CONST IMPORT_NAME importlist POP_TOP importmultiple ::= LOAD_CONST LOAD_CONST alias imports_cont diff --git a/uncompyle6/parsers/parse15.py b/uncompyle6/parsers/parse15.py index b1f51c5a..2a30466f 100644 --- a/uncompyle6/parsers/parse15.py +++ b/uncompyle6/parsers/parse15.py @@ -13,8 +13,8 @@ class Python15Parser(Python21Parser): def p_import15(self, args): """ - importstmt ::= filler IMPORT_NAME STORE_FAST - importstmt ::= filler IMPORT_NAME STORE_NAME + import ::= filler IMPORT_NAME STORE_FAST + import ::= filler IMPORT_NAME STORE_NAME importfrom ::= filler IMPORT_NAME importlist importfrom ::= filler filler IMPORT_NAME importlist POP_TOP diff --git a/uncompyle6/parsers/parse24.py b/uncompyle6/parsers/parse24.py index 2c295bfd..99b177c7 100644 --- a/uncompyle6/parsers/parse24.py +++ b/uncompyle6/parsers/parse24.py @@ -26,7 +26,7 @@ class Python24Parser(Python25Parser): # 2.5+ has two LOAD_CONSTs, one for the number '.'s in a relative import # 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 importstar ::= filler LOAD_CONST IMPORT_NAME IMPORT_STAR diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 7ce65125..339a0bf7 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -274,7 +274,7 @@ TABLE_DIRECT = { 'kv': ( '%c: %c', 3, 1 ), 'kv2': ( '%c: %c', 1, 2 ), 'mapexpr': ( '{%[1]C}', (0, maxint, ', ') ), - 'importstmt': ( '%|import %c\n', 2), + 'import': ( '%|import %c\n', 2), 'importlist': ( '%C', (0, maxint, ', ') ), 'importfrom': ( '%|from %[2]{pattr} import %c\n', (3, 'importlist') ), diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index 22063d9c..eac67023 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -18,7 +18,7 @@ We add some format specifiers here not used in pysource from src to dest. 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. @@ -88,7 +88,7 @@ TABLE_DIRECT_FRAGMENT = { 'continue_stmt': ( '%|%rcontinue\n', ), 'passstmt': ( '%|%rpass\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), 'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ), 'list_for': (' for %c%x in %c%c', 2, (2, (1, )), 0, 3 ),