You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Start Python3 class(superclass) handling
This commit is contained in:
BIN
test/bytecode_2.7/00_pass.pyc
Normal file
BIN
test/bytecode_2.7/00_pass.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_3.4/00_import.pyc
Normal file
BIN
test/bytecode_3.4/00_import.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/00_pass.pyc
Normal file
BIN
test/bytecode_3.4/00_pass.pyc
Normal file
Binary file not shown.
Binary file not shown.
4
test/simple_source/simple_stmts/00_import.py
Normal file
4
test/simple_source/simple_stmts/00_import.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Tests:
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from os import path
|
3
test/simple_source/simple_stmts/00_pass.py
Normal file
3
test/simple_source/simple_stmts/00_pass.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Tests:
|
||||||
|
# assign ::= expr designator
|
||||||
|
pass
|
@@ -370,9 +370,12 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
kwarg ::= LOAD_CONST expr
|
kwarg ::= LOAD_CONST expr
|
||||||
|
|
||||||
|
classdef ::= buildclass designator
|
||||||
|
|
||||||
# Python3 introduced LOAD_BUILD_CLASS
|
# Python3 introduced LOAD_BUILD_CLASS
|
||||||
classdef ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST
|
# FIXME: the below should be created by custom rules
|
||||||
CALL_FUNCTION_2 designator
|
buildclass ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST LOAD_NAME CALL_FUNCTION_3
|
||||||
|
buildclass ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST CALL_FUNCTION_2
|
||||||
|
|
||||||
stmt ::= classdefdeco
|
stmt ::= classdefdeco
|
||||||
classdefdeco ::= classdefdeco1 designator
|
classdefdeco ::= classdefdeco1 designator
|
||||||
|
@@ -1053,26 +1053,29 @@ class Walker(GenericASTTraversal, object):
|
|||||||
# class definition ('class X(A,B,C):')
|
# class definition ('class X(A,B,C):')
|
||||||
|
|
||||||
cclass = self.currentclass
|
cclass = self.currentclass
|
||||||
|
|
||||||
if self.version > 3.0:
|
if self.version > 3.0:
|
||||||
buildclass = node[1]
|
buildclass = node[1]
|
||||||
self.currentclass = str(buildclass[1].pattr)
|
build_list = node[0]
|
||||||
|
subclass = build_list[1][0].attr
|
||||||
else:
|
else:
|
||||||
buildclass = node[0]
|
buildclass = node[0]
|
||||||
self.currentclass = str(buildclass[0].pattr)
|
build_list = buildclass[1][0]
|
||||||
|
subclass = buildclass[-3][0].attr
|
||||||
|
|
||||||
self.write('\n\n')
|
self.write('\n\n')
|
||||||
|
self.currentclass = str(buildclass[0].pattr)
|
||||||
self.write(self.indent, 'class ', self.currentclass)
|
self.write(self.indent, 'class ', self.currentclass)
|
||||||
|
|
||||||
self.print_super_classes(buildclass)
|
if self.version > 3.0:
|
||||||
|
self.print_super_classes3(build_list)
|
||||||
|
else:
|
||||||
|
self.print_super_classes(build_list)
|
||||||
self.print_(':')
|
self.print_(':')
|
||||||
|
|
||||||
# class body
|
# class body
|
||||||
self.indentMore()
|
self.indentMore()
|
||||||
|
self.build_class(subclass)
|
||||||
if self.version > 3.0:
|
|
||||||
self.build_class(buildclass[0].attr)
|
|
||||||
else:
|
|
||||||
self.build_class(buildclass[-3][0].attr)
|
|
||||||
self.indentLess()
|
self.indentLess()
|
||||||
|
|
||||||
self.currentclass = cclass
|
self.currentclass = cclass
|
||||||
@@ -1086,7 +1089,6 @@ class Walker(GenericASTTraversal, object):
|
|||||||
n_classdefdeco2 = n_classdef
|
n_classdefdeco2 = n_classdef
|
||||||
|
|
||||||
def print_super_classes(self, node):
|
def print_super_classes(self, node):
|
||||||
node = node[1][0]
|
|
||||||
if not (node == 'build_list'):
|
if not (node == 'build_list'):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -1100,6 +1102,29 @@ class Walker(GenericASTTraversal, object):
|
|||||||
|
|
||||||
self.write(')')
|
self.write(')')
|
||||||
|
|
||||||
|
def print_super_classes3(self, node):
|
||||||
|
|
||||||
|
# FIXME: put blow logic into grammar
|
||||||
|
# as a custom rule
|
||||||
|
i = 0
|
||||||
|
for i, n in enumerate(node[:-1]):
|
||||||
|
if n.type == 'LOAD_NAME':
|
||||||
|
break
|
||||||
|
pass
|
||||||
|
|
||||||
|
if i == 0:
|
||||||
|
return
|
||||||
|
self.write('(')
|
||||||
|
line_separator = ', '
|
||||||
|
sep = ''
|
||||||
|
while i <= len(node) - 2:
|
||||||
|
value = self.traverse(node[i])
|
||||||
|
i += 1
|
||||||
|
self.write(sep, value)
|
||||||
|
sep = line_separator
|
||||||
|
|
||||||
|
self.write(')')
|
||||||
|
|
||||||
def n_mapexpr(self, node):
|
def n_mapexpr(self, node):
|
||||||
"""
|
"""
|
||||||
prettyprint a mapexpr
|
prettyprint a mapexpr
|
||||||
|
Reference in New Issue
Block a user