Skip to content

Commit acbc019

Browse files
author
Bruno da Silva de Oliveira
committed
- Fixed a bug where the code for a virtual method wrapper defined inside a Pyste file was not being declared in the generated code
[SVN r19776]
1 parent 7ec78ee commit acbc019

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

pyste/src/Pyste/ClassExporter.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def __init__(self, info, parser_tail=None):
3939
self.sections['include'] = []
4040
# a list of Constructor instances
4141
self.constructors = []
42-
self.wrapper_generator = None
4342
# a list of code units, generated by nested declarations
4443
self.nested_codeunits = []
4544

@@ -92,7 +91,7 @@ def Export(self, codeunit, exported_names):
9291
self.ExportBases(exported_names)
9392
self.ExportConstructors()
9493
self.ExportVariables()
95-
self.ExportVirtualMethods()
94+
self.ExportVirtualMethods(codeunit)
9695
self.ExportMethods()
9796
self.ExportOperators()
9897
self.ExportNestedClasses(exported_names)
@@ -111,7 +110,6 @@ def InheritMethods(self, exported_names):
111110
base classes.
112111
'''
113112
valid_members = (Method, ClassVariable, NestedClass, ClassEnumeration)
114-
# these don't work INVESTIGATE!: (ClassOperator, ConverterOperator)
115113
fullnames = [x.FullName() for x in self.class_]
116114
pointers = [x.PointerDeclaration(True) for x in self.class_ if isinstance(x, Method)]
117115
fullnames = dict([(x, None) for x in fullnames])
@@ -387,7 +385,7 @@ def IsExportable(m):
387385
# add wrapper code if this method has one
388386
wrapper = method_info.wrapper
389387
if wrapper and wrapper.code:
390-
self.Add('declaration', wrapper.code)
388+
self.Add('declaration-outside', wrapper.code)
391389

392390
# export staticmethod statements
393391
for name in staticmethods:
@@ -404,7 +402,7 @@ def MakeNonVirtual(self):
404402
member.virtual = not self.info[member.name].no_override
405403

406404

407-
def ExportVirtualMethods(self):
405+
def ExportVirtualMethods(self, codeunit):
408406
# check if this class has any virtual methods
409407
has_virtual_methods = False
410408
for member in self.class_:
@@ -414,7 +412,7 @@ def ExportVirtualMethods(self):
414412

415413
holder = self.info.holder
416414
if has_virtual_methods:
417-
generator = _VirtualWrapperGenerator(self.class_, self.ClassBases(), self.info)
415+
generator = _VirtualWrapperGenerator(self.class_, self.ClassBases(), self.info, codeunit)
418416
if holder:
419417
self.Add('template', holder(generator.FullName()))
420418
else:
@@ -505,7 +503,7 @@ def HandleSpecialOperator(operator):
505503
if wrapper:
506504
pointer = '&' + wrapper.FullName()
507505
if wrapper.code:
508-
self.Add('declaration', wrapper.code)
506+
self.Add('declaration-outside', wrapper.code)
509507
else:
510508
pointer = operator.PointerDeclaration()
511509
rename = self.info['operator'][operator.name].rename
@@ -655,13 +653,14 @@ def _ParamsInfo(m, count=None):
655653
class _VirtualWrapperGenerator(object):
656654
'Generates code to export the virtual methods of the given class'
657655

658-
def __init__(self, class_, bases, info):
656+
def __init__(self, class_, bases, info, codeunit):
659657
self.class_ = copy.deepcopy(class_)
660658
self.bases = bases[:]
661659
self.info = info
662660
self.wrapper_name = makeid(class_.FullName()) + '_Wrapper'
663661
self.virtual_methods = None
664662
self._method_count = {}
663+
self.codeunit = codeunit
665664
self.GenerateVirtualMethods()
666665

667666

@@ -723,6 +722,8 @@ def DefaultImpl(method, param_names):
723722
return indent2 + '%s%s(%s);\n' % \
724723
(return_str, method.FullName(), ', '.join(param_names))
725724
else:
725+
if wrapper.code:
726+
self.codeunit.Write('declaration-outside', wrapper.code)
726727
# return a call for the wrapper
727728
params = ', '.join(['this'] + param_names)
728729
return indent2 + '%s%s(%s);\n' % (return_str, wrapper.FullName(), params)

pyste/src/Pyste/pyste.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import time
4444
import declarations
4545

46-
__version__ = '0.9.20'
46+
__version__ = '0.9.21'
4747

4848
def RecursiveIncludes(include):
4949
'Return a list containg the include dir and all its subdirectories'

0 commit comments

Comments
 (0)