Skip to content

Commit 95b95d0

Browse files
author
Bruno da Silva de Oliveira
committed
- Fixed bug where a class would appear more than one in the generated code.
[SVN r20464]
1 parent 4af7d5b commit 95b95d0

File tree

7 files changed

+67
-43
lines changed

7 files changed

+67
-43
lines changed

pyste/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
23 October 2003
2+
Fixed bug where a class would appear more than one in the generated code.
3+
14
6 October 2003
25
Fixed bug reported by Niall Douglas (using his patch) about UniqueInt not
36
appearing correctly with --multiple.

pyste/src/Pyste/ClassExporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def ExportNestedClasses(self, exported_names):
598598
nested_info = self.info[nested_class.name]
599599
nested_info.include = self.info.include
600600
nested_info.name = nested_class.FullName()
601-
exporter = ClassExporter(nested_info)
601+
exporter = self.__class__(nested_info)
602602
exporter.SetDeclarations(self.declarations)
603603
codeunit = SingleCodeUnit(None, None)
604604
exporter.Export(codeunit, exported_names)

pyste/src/Pyste/SingleCodeUnit.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class SingleCodeUnit:
1717
Represents a cpp file, where other objects can write in one of the
1818
predefined sections.
1919
The avaiable sections are:
20+
pchinclude - The pre-compiled header area
2021
include - The include area of the cpp file
2122
declaration - The part before the module definition
2223
module - Inside the BOOST_PYTHON_MODULE macro
@@ -28,6 +29,8 @@ def __init__(self, modulename, filename):
2829
# define the avaiable sections
2930
self.code = {}
3031
# include section
32+
self.code['pchinclude'] = ''
33+
# include section
3134
self.code['include'] = ''
3235
# declaration section (inside namespace)
3336
self.code['declaration'] = ''
@@ -74,15 +77,17 @@ def Save(self, append=False):
7477
fout.write('\n')
7578
# includes
7679
# boost.python header
77-
fout.write(left_equals('Boost Includes'))
78-
fout.write('#include <boost/python.hpp>\n')
79-
# include numerical boost for int64 definitions
80-
fout.write('#include <boost/cstdint.hpp>\n')
81-
if settings.msvc:
82-
# include precompiled header directive
80+
if self.code['pchinclude']:
81+
fout.write(left_equals('PCH'))
82+
fout.write(self.code['pchinclude']+'\n')
8383
fout.write('#ifdef _MSC_VER\n')
8484
fout.write('#pragma hdrstop\n')
85-
fout.write('#endif\n')
85+
fout.write('#endif\n')
86+
else:
87+
fout.write(left_equals('Boost Includes'))
88+
fout.write('#include <boost/python.hpp>\n')
89+
# include numerical boost for int64 definitions
90+
fout.write('#include <boost/cstdint.hpp>\n')
8691
fout.write('\n')
8792
# other includes
8893
if self.code['include']:

pyste/src/Pyste/exporters.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
exporters = []
99

1010
current_interface = None # the current interface file being processed
11+
importing = False # whetever we are now importing a pyste file.
12+
# exporters created here shouldn't export themselves

pyste/src/Pyste/infos.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,43 @@ def _Attribute(self, name, value=None):
5151
self.__attributes[name] = value
5252

5353

54+
def AddExporter(self, exporter):
55+
if not exporters.importing:
56+
if exporter not in exporters.exporters:
57+
exporters.exporters.append(exporter)
58+
exporter.interface_file = exporters.current_interface
59+
60+
5461
#==============================================================================
5562
# FunctionInfo
5663
#==============================================================================
5764
class FunctionInfo(DeclarationInfo):
5865

59-
def __init__(self, name, include, tail=None, otherOption=None):
66+
def __init__(self, name, include, tail=None, otherOption=None,
67+
exporter_class = FunctionExporter):
6068
DeclarationInfo.__init__(self, otherOption)
6169
self._Attribute('name', name)
6270
self._Attribute('include', include)
6371
self._Attribute('exclude', False)
6472
# create a FunctionExporter
65-
exporter = FunctionExporter(InfoWrapper(self), tail)
66-
if exporter not in exporters.exporters:
67-
exporters.exporters.append(exporter)
68-
exporter.interface_file = exporters.current_interface
73+
exporter = exporter_class(InfoWrapper(self), tail)
74+
self.AddExporter(exporter)
6975

7076

7177
#==============================================================================
7278
# ClassInfo
7379
#==============================================================================
7480
class ClassInfo(DeclarationInfo):
7581

76-
def __init__(self, name, include, tail=None, otherInfo=None):
82+
def __init__(self, name, include, tail=None, otherInfo=None,
83+
exporter_class = ClassExporter):
7784
DeclarationInfo.__init__(self, otherInfo)
7885
self._Attribute('name', name)
7986
self._Attribute('include', include)
8087
self._Attribute('exclude', False)
8188
# create a ClassExporter
82-
exporter = ClassExporter(InfoWrapper(self), tail)
83-
if exporter not in exporters.exporters:
84-
exporters.exporters.append(exporter)
85-
exporter.interface_file = exporters.current_interface
89+
exporter = exporter_class(InfoWrapper(self), tail)
90+
self.AddExporter(exporter)
8691

8792

8893
#==============================================================================
@@ -96,10 +101,12 @@ def GenerateName(name, type_list):
96101

97102
class ClassTemplateInfo(DeclarationInfo):
98103

99-
def __init__(self, name, include):
104+
def __init__(self, name, include,
105+
exporter_class = ClassExporter):
100106
DeclarationInfo.__init__(self)
101107
self._Attribute('name', name)
102108
self._Attribute('include', include)
109+
self._exporter_class = exporter_class
103110

104111

105112
def Instantiate(self, type_list, rename=None):
@@ -111,7 +118,8 @@ def Instantiate(self, type_list, rename=None):
111118
tail += 'void __instantiate_%s()\n' % rename
112119
tail += '{ sizeof(%s); }\n\n' % rename
113120
# create a ClassInfo
114-
class_ = ClassInfo(rename, self._Attribute('include'), tail, self)
121+
class_ = ClassInfo(rename, self._Attribute('include'), tail, self,
122+
exporter_class = self._exporter_class)
115123
return class_
116124

117125

@@ -125,60 +133,52 @@ def __call__(self, types, rename=None):
125133
#==============================================================================
126134
class EnumInfo(DeclarationInfo):
127135

128-
def __init__(self, name, include):
136+
def __init__(self, name, include, exporter_class = EnumExporter):
129137
DeclarationInfo.__init__(self)
130138
self._Attribute('name', name)
131139
self._Attribute('include', include)
132140
self._Attribute('exclude', False)
133141
self._Attribute('export_values', False)
134-
exporter = EnumExporter(InfoWrapper(self))
135-
if exporter not in exporters.exporters:
136-
exporters.exporters.append(exporter)
137-
exporter.interface_file = exporters.current_interface
142+
exporter = exporter_class(InfoWrapper(self))
143+
self.AddExporter(exporter)
138144

139145

140146
#==============================================================================
141147
# HeaderInfo
142148
#==============================================================================
143149
class HeaderInfo(DeclarationInfo):
144150

145-
def __init__(self, include):
151+
def __init__(self, include, exporter_class = HeaderExporter):
146152
DeclarationInfo.__init__(self)
147153
self._Attribute('include', include)
148-
exporter = HeaderExporter(InfoWrapper(self))
149-
if exporter not in exporters.exporters:
150-
exporters.exporters.append(exporter)
151-
exporter.interface_file = exporters.current_interface
154+
exporter = exporter_class(InfoWrapper(self))
155+
self.AddExporter(exporter)
152156

153157

154158
#==============================================================================
155159
# VarInfo
156160
#==============================================================================
157161
class VarInfo(DeclarationInfo):
158162

159-
def __init__(self, name, include):
163+
def __init__(self, name, include, exporter_class = VarExporter):
160164
DeclarationInfo.__init__(self)
161165
self._Attribute('name', name)
162166
self._Attribute('include', include)
163-
exporter = VarExporter(InfoWrapper(self))
164-
if exporter not in exporters.exporters:
165-
exporters.exporters.append(exporter)
166-
exporter.interface_file = exporters.current_interface
167+
exporter = exporter_class(InfoWrapper(self))
168+
self.AddExporter(exporter)
167169

168170

169171
#==============================================================================
170172
# CodeInfo
171173
#==============================================================================
172174
class CodeInfo(DeclarationInfo):
173175

174-
def __init__(self, code, section):
176+
def __init__(self, code, section, exporter_class = CodeExporter):
175177
DeclarationInfo.__init__(self)
176178
self._Attribute('code', code)
177179
self._Attribute('section', section)
178-
exporter = CodeExporter(InfoWrapper(self))
179-
if exporter not in exporters.exporters:
180-
exporters.exporters.append(exporter)
181-
exporter.interface_file = exporters.current_interface
180+
exporter = exporter_class(InfoWrapper(self))
181+
self.AddExporter(exporter)
182182

183183

184184
#==============================================================================

pyste/src/Pyste/pyste.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import time
5252
import declarations
5353

54-
__version__ = '0.9.27'
54+
__version__ = '0.9.28'
5555

5656
def RecursiveIncludes(include):
5757
'Return a list containg the include dir and all its subdirectories'
@@ -182,15 +182,21 @@ def Usage():
182182
ProcessIncludes(includes)
183183
return includes, defines, module, out, files, multiple, cache_dir, create_cache, generate_main
184184

185+
186+
def PCHInclude(*headers):
187+
code = '\n'.join(['#include <%s>' % x for x in headers])
188+
infos.CodeInfo(code, 'pchinclude')
189+
185190

186191
def CreateContext():
187192
'create the context where a interface file will be executed'
188193
context = {}
189-
context['Import'] = ExecuteInterface
194+
context['Import'] = Import
190195
# infos
191196
context['Function'] = infos.FunctionInfo
192197
context['Class'] = infos.ClassInfo
193198
context['Include'] = lambda header: infos.CodeInfo('#include <%s>\n' % header, 'include')
199+
context['PCHInclude'] = PCHInclude
194200
context['Template'] = infos.ClassTemplateInfo
195201
context['Enum'] = infos.EnumInfo
196202
context['AllFromHeader'] = infos.HeaderInfo
@@ -279,6 +285,12 @@ def ExecuteInterface(interface):
279285
execfile(interface, context)
280286
exporters.current_interface = old_interface
281287

288+
289+
def Import(interface):
290+
exporters.importing = True
291+
ExecuteInterface(interface)
292+
exporters.importing = False
293+
282294

283295
def JoinTails(exports):
284296
'''Returns a dict of {(interface, header): tail}, where tail is the

pyste/src/Pyste/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def makeid(name):
4444
def remove_duplicated_lines(text):
4545
includes = text.splitlines()
4646
d = dict([(include, 0) for include in includes])
47-
return '\n'.join(d.keys())
47+
includes = d.keys()
48+
includes.sort()
49+
return '\n'.join(includes)
4850

4951

5052
#==============================================================================

0 commit comments

Comments
 (0)