You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Isolate pseudo op IMPORT_NAME_CONT
I think this is a holdover from pre 2.3 days. Possibly it can be dropped altogether.
This commit is contained in:
@@ -322,8 +322,6 @@ class PythonParser(GenericASTBuilder):
|
||||
importstmt ::= LOAD_CONST LOAD_CONST import_as
|
||||
importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME IMPORT_STAR
|
||||
importfrom ::= LOAD_CONST LOAD_CONST IMPORT_NAME importlist2 POP_TOP
|
||||
importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT IMPORT_STAR
|
||||
importfrom ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT importlist2 POP_TOP
|
||||
importmultiple ::= LOAD_CONST LOAD_CONST import_as imports_cont
|
||||
|
||||
imports_cont ::= imports_cont import_cont
|
||||
|
@@ -202,6 +202,15 @@ class Python2Parser(PythonParser):
|
||||
genexpr ::= LOAD_GENEXPR MAKE_FUNCTION_0 expr GET_ITER CALL_FUNCTION_1
|
||||
'''
|
||||
|
||||
def p_import2(self, args):
|
||||
'''
|
||||
# These might be relevant for only Python 2.0 or so.
|
||||
# Not relevant for Python 3.
|
||||
importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT IMPORT_STAR
|
||||
importfrom ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT importlist2 POP_TOP
|
||||
'''
|
||||
|
||||
|
||||
def p_expr2(self, args):
|
||||
'''
|
||||
expr ::= LOAD_LOCALS
|
||||
|
@@ -116,16 +116,6 @@ class Scanner2(scan.Scanner):
|
||||
last_stmt = i
|
||||
i = self.next_stmt[i]
|
||||
|
||||
imports = self.all_instr(0, n, (self.opc.IMPORT_NAME, self.opc.IMPORT_FROM,
|
||||
self.opc.IMPORT_STAR))
|
||||
if len(imports) > 1:
|
||||
last_import = imports[0]
|
||||
for i in imports[1:]:
|
||||
if self.lines[last_import].next > i:
|
||||
if self.code[last_import] == self.opc.IMPORT_NAME == self.code[i]:
|
||||
replace[i] = 'IMPORT_NAME_CONT'
|
||||
last_import = i
|
||||
|
||||
extended_arg = 0
|
||||
for offset in self.op_range(0, n):
|
||||
if offset in cf:
|
||||
|
@@ -159,7 +159,9 @@ class Scanner26(scan.Scanner2):
|
||||
imports = self.all_instr(0, codelen,
|
||||
(self.opc.IMPORT_NAME, self.opc.IMPORT_FROM,
|
||||
self.opc.IMPORT_STAR))
|
||||
if len(imports) > 1:
|
||||
# Changes IMPORT_NAME to IMPORT_NAME_CONT.
|
||||
# Possibly a Python 2.0 hangover
|
||||
if len(imports) > 1 and self.version < 2.3:
|
||||
last_import = imports[0]
|
||||
for i in imports[1:]:
|
||||
if self.lines[last_import].next > i:
|
||||
|
@@ -712,7 +712,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.preorder(node[0])
|
||||
# 3.5 does jump optimization. The RETURN_END_IF in the return
|
||||
# statement means to dedent. Earlier versions will just have
|
||||
# RETURN_VALUE
|
||||
# RETURN_VALUE it is done by a nonterminal in the grammar.
|
||||
if self.version >= 3.5 and node[-1] == 'RETURN_END_IF':
|
||||
self.indentLess()
|
||||
self.println()
|
||||
|
Reference in New Issue
Block a user