2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-29 19:52:16 +00:00

- Fixed bug where the order of instantiations in the --multiple mode could end up wrong

[SVN r18198]
This commit is contained in:
Bruno da Silva de Oliveira
2003-04-07 18:15:50 +00:00
parent 82721c77a1
commit f7f089d2d4
11 changed files with 53 additions and 27 deletions

View File

@@ -1,3 +1,7 @@
07 Apr 2003
Removed the warnings about forward declarations: it was not accurate enough.
Another strategy must be thought of.
06 Apr 2003
Support for the improved static data members support of Boost.Python.

View File

@@ -47,8 +47,8 @@ class ClassExporter(Exporter):
return makeid(self.class_.FullName()) + '_scope'
def Name(self):
return self.class_.FullName()
def Unit(self):
return makeid(self.class_.name)
def SetDeclarations(self, declarations):
@@ -76,7 +76,7 @@ class ClassExporter(Exporter):
return bases
def ID(self):
def Order(self):
'''Return the TOTAL number of bases that this class has, including the
bases' bases. Do this because base classes must be instantialized
before the derived classes in the module definition.

View File

@@ -1,5 +1,6 @@
from Exporter import Exporter
from settings import *
import utils
#==============================================================================
# EnumExporter
@@ -30,5 +31,9 @@ class EnumExporter(Exporter):
codeunit.Write('module', code)
def ID(self):
def Unit(self):
return utils.makeid(self.info.include)
def Order(self):
return self.info.name

View File

@@ -12,6 +12,10 @@ class Exporter:
self.info = info
self.parser_tail = parser_tail
def Name(self):
return self.info.name
def Parse(self, parser):
self.parser = parser
@@ -40,11 +44,8 @@ class Exporter:
pass
def Name(self):
'''Returns the name of this Exporter. The name will be added to the
list of names exported, which may have a use for other exporters.
'''
return None
def Unit(self):
raise NotImplementedError
def GetDeclarations(self, fullname):
@@ -60,9 +61,9 @@ class Exporter:
return decls[0]
def ID(self):
def Order(self):
'''Returns a string that uniquely identifies this instance. All
exporters will be sorted by ID before being exported.
exporters will be sorted by Order before being exported.
'''
raise NotImplementedError

View File

@@ -2,6 +2,7 @@ from Exporter import Exporter
from policies import *
from declarations import *
from settings import *
import utils
import exporterutils
@@ -24,10 +25,6 @@ class FunctionExporter(Exporter):
self.GenerateOverloads(decls, codeunit)
def Name(self):
return self.info.name
def ExportDeclaration(self, decl, unique, codeunit):
name = self.info.rename or decl.name
defs = namespaces.python + 'def("%s", ' % name
@@ -78,5 +75,9 @@ class FunctionExporter(Exporter):
return ''
def ID(self):
def Order(self):
return self.info.name
def Unit(self):
return utils.makeid(self.info.include)

View File

@@ -64,7 +64,11 @@ class HeaderExporter(Exporter):
exporters.exporters.append(exporter)
def ID(self):
def Unit(self):
return self.info.include
def Order(self):
return self.info.include

View File

@@ -17,7 +17,7 @@ class IncludeExporter(Exporter):
def Parse(self, parser):
pass
def ID(self):
def Order(self):
return self.info.include
def Unit(self):

View File

@@ -10,7 +10,7 @@ from SmartFile import SmartFile
class MultipleCodeUnit(object):
'''
Represents a bunch of cpp files, where each cpp file represents a header
to be exported by pyste. Another header, named _main.cpp is created too.
to be exported by pyste. Another cpp, named <module>.cpp is created too.
'''
def __init__(self, modulename, outdir):
@@ -23,6 +23,7 @@ class MultipleCodeUnit(object):
def _FunctionName(self, code_unit_name):
return '_Export_%s' % utils.makeid(code_unit_name)
def _FileName(self, code_unit_name):
filename = os.path.basename(code_unit_name)
@@ -84,7 +85,7 @@ class MultipleCodeUnit(object):
codeunit.Merge(__all__)
codeunit.Save()
# generate the main cpp
filename = os.path.join(self.outdir, '_main.cpp')
filename = os.path.join(self.outdir, self.modulename + '.cpp')
fout = SmartFile(filename, 'w')
fout.write(utils.left_equals('Include'))
fout.write('#include <boost/python.hpp>\n\n')

View File

@@ -82,7 +82,9 @@ def WarnForwardDeclarations(function):
if type.incomplete:
msg = '---> Error: %s is forward declared. Please include the ' \
'appropriate header with its definition' % type.name
if msg not in _printed_warnings:
# disable this for now... it was reporting too many false
# forward declarations to be useful
if 0 and msg not in _printed_warnings:
print msg
print
_printed_warnings[msg] = 1

View File

@@ -34,7 +34,7 @@ from policies import *
from CppParser import CppParser, CppParserError
import time
__VERSION__ = '0.7.0'
__VERSION__ = '0.7.1'
def RecursiveIncludes(include):
'Return a list containg the include dir and all its subdirectories'
@@ -161,8 +161,8 @@ def Main():
print '***', e, ': exitting'
return 2
print
# sort the exporters by its ids
exports = [(x.ID(), x) for x in exporters.exporters]
# sort the exporters by its order
exports = [(x.Order(), x) for x in exporters.exporters]
exports.sort()
exports = [x for _, x in exports]
# now generate the wrapper code

View File

@@ -1,4 +1,5 @@
from __future__ import generators
import string
#==============================================================================
# enumerate
@@ -13,12 +14,19 @@ def enumerate(seq):
#==============================================================================
# makeid
#==============================================================================
_valid_chars = string.ascii_letters + string.digits + '_'
_valid_chars = dict(zip(_valid_chars, _valid_chars))
def makeid(name):
'Returns the name as a valid identifier'
for invalidchar in ('::', '<', '>', ' ', ',', '.', '#'):
name = name.replace(invalidchar, '_')
newname = []
for char in name:
if char not in _valid_chars:
char = '_'
newname.append(char)
newname = ''.join(newname)
# avoid duplications of '_' chars
names = [x for x in name.split('_') if x]
names = [x for x in newname.split('_') if x]
return '_'.join(names)