Skip to content

Commit 27653b7

Browse files
author
Bruno da Silva de Oliveira
committed
- Applied a patch by Paul Bridger that solves some problems for wrapper
methods. - Applied a patch by Baptiste Lepilleur that allows the user to inject code inside the class definition. - Applied another patch by Baptiste Lepilleur that inserts two new command-line options that helps with writing makefiles. [SVN r23725]
1 parent af15309 commit 27653b7

8 files changed

Lines changed: 73 additions & 25 deletions

File tree

pyste/NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
18 July 2004
2+
- Applied a patch by Paul Bridger that solves some problems for wrapper
3+
methods.
4+
- Applied a patch by Baptiste Lepilleur that allows the user to inject
5+
code inside the class definition.
6+
- Applied another patch by Baptiste Lepilleur that inserts two new command-line
7+
options that helps with writing makefiles.
8+
19
27 May 2004
210
Applied patch by Paul Bridger that solves a problem on windows regarding
311
spaces on paths. Thanks Paul!

pyste/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ generate C++ code.
1010
The documentation can be found in the file index.html accompaning this README.
1111

1212
Enjoy!
13-
Bruno da Silva de Oliveira (nicodemus@globalite.com.br)
13+
Bruno da Silva de Oliveira (nicodemus@esss.com.br)
1414

1515
Thanks
1616
======
@@ -26,6 +26,6 @@ Bugs
2626
====
2727

2828
Pyste is a young tool, so please help it to get better! Send bug reports to
29-
nicodemus@globalite.com.br, accompaining the stack trace in case of exceptions.
29+
nicodemus@esss.com.br, accompaining the stack trace in case of exceptions.
3030
If possible, run pyste with --debug, and send the resulting xmls too (pyste
3131
will output a xml file with the same of each header it parsed).

pyste/src/Pyste/.cvsignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.pyc
2+
.project

pyste/src/Pyste/ClassExporter.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def Export(self, codeunit, exported_names):
103103
self.ExportNestedEnums(exported_names)
104104
self.ExportSmartPointer()
105105
self.ExportOpaquePointerPolicies()
106+
self.ExportAddedCode()
106107
self.Write(codeunit)
107108
exported_names[self.Name()] = 1
108109

@@ -372,7 +373,7 @@ def IsExportable(m):
372373
policy = ', %s%s()' % (namespaces.python, policy.Code())
373374
# check for overloads
374375
overload = ''
375-
if method.minArgs != method.maxArgs:
376+
if method.minArgs != method.maxArgs and not method_info.wrapper:
376377
# add the overloads for this method
377378
DeclareOverloads(method)
378379
overload_name = self.OverloadName(method)
@@ -637,6 +638,11 @@ def ExportOpaquePointerPolicies(self):
637638
if macro:
638639
self.Add('declaration-outside', macro)
639640

641+
def ExportAddedCode(self):
642+
if self.info.__code__:
643+
for code in self.info.__code__:
644+
self.Add('inside', code)
645+
640646

641647
#==============================================================================
642648
# Virtual Wrapper utils
@@ -670,6 +676,9 @@ def __init__(self, class_, bases, info, codeunit):
670676
self.GenerateVirtualMethods()
671677

672678

679+
SELF = 'py_self'
680+
681+
673682
def DefaultImplementationNames(self, method):
674683
'''Returns a list of default implementations for this method, one for each
675684
number of default arguments. Always returns at least one name, and return from
@@ -706,8 +715,11 @@ def Declaration(self, method, indent):
706715
param_names_str = ', '.join(param_names)
707716
if param_names_str:
708717
param_names_str = ', ' + param_names_str
709-
decl += indent*2 + '%s%scall_method< %s >(self, "%s"%s);\n' %\
710-
(return_str, python, result, rename, param_names_str)
718+
719+
self_str = self.SELF
720+
721+
decl += indent*2 + '%(return_str)s%(python)scall_method< %(result)s >' \
722+
'(%(self_str)s, "%(rename)s"%(param_names_str)s);\n' % locals()
711723
decl += indent + '}\n'
712724

713725
# default implementations (with overloading)
@@ -775,8 +787,12 @@ def MethodDefinition(self, method):
775787
if method.abstract:
776788
pointer = namespaces.python + ('pure_virtual(%s)' % pointer)
777789

790+
# warn the user if this method needs a policy and doesn't have one
791+
method_info = self.info[method.name]
792+
method_info.policy = exporterutils.HandlePolicy(method, method_info.policy)
793+
778794
# Add policy to overloaded methods also
779-
policy = self.info[method.name].policy or ''
795+
policy = method_info.policy or ''
780796
if policy:
781797
policy = ', %s%s()' % (namespaces.python, policy.Code())
782798

@@ -880,10 +896,10 @@ def GenerateVirtualWrapper(self, indent):
880896
params, param_names, param_types = _ParamsInfo(cons, argNum)
881897
if params:
882898
params = ', ' + params
883-
cons_code += indent + '%s(PyObject* self_%s):\n' % \
884-
(self.wrapper_name, params)
885-
cons_code += indent*2 + '%s(%s), self(self_) {}\n\n' % \
886-
(class_name, ', '.join(param_names))
899+
cons_code += indent + '%s(PyObject* %s_%s):\n' % \
900+
(self.wrapper_name, self.SELF, params)
901+
cons_code += indent*2 + '%s(%s), %s(%s_) {}\n\n' % \
902+
(class_name, ', '.join(param_names), self.SELF, self.SELF)
887903
code += cons_code
888904
# generate the body
889905
body = []
@@ -893,6 +909,6 @@ def GenerateVirtualWrapper(self, indent):
893909
body = '\n'.join(body)
894910
code += body + '\n'
895911
# add the self member
896-
code += indent + 'PyObject* self;\n'
912+
code += indent + 'PyObject* %s;\n' % self.SELF
897913
code += '};\n'
898914
return code

pyste/src/Pyste/CppParser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ class CppParserError(Exception): pass
2525
class CppParser:
2626
'Parses a header file and returns a list of declarations'
2727

28-
def __init__(self, includes=None, defines=None, cache_dir=None, version=None):
28+
def __init__(self, includes=None, defines=None, cache_dir=None, version=None, gccxml_path = 'gccxml'):
2929
'includes and defines ar the directives given to gcc'
3030
if includes is None:
3131
includes = []
3232
if defines is None:
3333
defines = []
3434
self.includes = includes
35+
self.gccxml_path = gccxml_path
3536
self.defines = defines
3637
self.version = version
3738
#if cache_dir is None:
@@ -111,10 +112,10 @@ def ParseWithGCCXML(self, header, tail):
111112
includes = self._IncludeParams(filename)
112113
defines = self._DefineParams()
113114
# call gccxml
114-
cmd = 'gccxml %s %s "%s" -fxml=%s'
115+
cmd = '%s %s %s "%s" -fxml=%s'
115116
filename = self.Unixfy(filename)
116117
xmlfile = self.Unixfy(xmlfile)
117-
status = os.system(cmd % (includes, defines, filename, xmlfile))
118+
status = os.system(cmd % (self.gccxml_path, includes, defines, filename, xmlfile))
118119
if status != 0 or not os.path.isfile(xmlfile):
119120
raise CppParserError, 'Error executing gccxml'
120121
# parse the resulting xml

pyste/src/Pyste/GCCXMLParser.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@ def GetMembers(self, member_list):
278278
for member in member_list.split():
279279
decl = self.GetDecl(member)
280280
if type(decl) in Class.ValidMemberTypes():
281-
if type(decl) is str:
282-
print decl
283281
members.append(decl)
284282
return members
285283

@@ -309,8 +307,6 @@ def ParseClass(self, id, element):
309307
class_.bases = class_.hierarchy[0]
310308
members = self.GetMembers(element.get('members'))
311309
for member in members:
312-
if type(member) is str:
313-
print member
314310
class_.AddMember(member)
315311

316312

@@ -407,7 +403,12 @@ def ParseConstructor(self, id, element):
407403
classname = self.GetDecl(element.get('context')).FullName()
408404
location = self.GetLocation(element.get('location'))
409405
params = self.GetArguments(element)
410-
ctor = Constructor(name, classname, params, visib)
406+
artificial = element.get('artificial', False)
407+
if not artificial:
408+
ctor = Constructor(name, classname, params, visib)
409+
else:
410+
# we don't want artificial constructors
411+
ctor = Unknown('__Unknown_Element_%s' % id)
411412
ctor.location = location
412413
self.Update(id, ctor)
413414

pyste/src/Pyste/infos.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ def add_method(info, name, rename=None):
243243
else:
244244
added.append((name, rename))
245245

246+
247+
def class_code(info, code):
248+
added = info._Attribute('__code__')
249+
if added is None:
250+
info._Attribute('__code__', [code])
251+
else:
252+
added.append(code)
253+
246254
def final(info):
247255
info._Attribute('no_override', True)
248256

pyste/src/Pyste/pyste.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
--file-list A file with one pyste file per line. Use as a
3232
substitute for passing the files in the command
3333
line.
34+
--gccxml-path=<path> Path to gccxml executable (default: gccxml)
35+
--no-default-include Do not use INCLUDE environment variable for include
36+
files to pass along gccxml.
3437
-h, --help Print this help and exit
3538
-v, --version Print version information
3639
"""
@@ -51,7 +54,7 @@
5154
import time
5255
import declarations
5356

54-
__version__ = '0.9.29'
57+
__version__ = '0.9.30'
5558

5659
def RecursiveIncludes(include):
5760
'Return a list containg the include dir and all its subdirectories'
@@ -104,20 +107,23 @@ def Usage():
104107
sys.argv[1:],
105108
'R:I:D:vh',
106109
['module=', 'multiple', 'out=', 'no-using', 'pyste-ns=', 'debug', 'cache-dir=',
107-
'only-create-cache', 'version', 'generate-main', 'file-list=', 'help'])
110+
'only-create-cache', 'version', 'generate-main', 'file-list=', 'help',
111+
'gccxml-path=', 'no-default-include'])
108112
except getopt.GetoptError, e:
109113
print
110114
print 'ERROR:', e
111115
Usage()
112116

113-
includes = GetDefaultIncludes()
117+
default_includes = GetDefaultIncludes()
118+
includes = []
114119
defines = []
115120
module = None
116121
out = None
117122
multiple = False
118123
cache_dir = None
119124
create_cache = False
120125
generate_main = False
126+
gccxml_path = 'gccxml'
121127

122128
for opt, value in options:
123129
if opt == '-I':
@@ -152,10 +158,15 @@ def Usage():
152158
sys.exit(2)
153159
elif opt == '--generate-main':
154160
generate_main = True
161+
elif opt == '--gccxml-path':
162+
gccxml_path = value
163+
elif opt == '--no-default-include':
164+
default_includes = []
155165
else:
156166
print 'Unknown option:', opt
157167
Usage()
158168

169+
includes[0:0] = default_includes
159170
if not files:
160171
Usage()
161172
if not module:
@@ -180,7 +191,8 @@ def Usage():
180191
sys.exit(3)
181192

182193
ProcessIncludes(includes)
183-
return includes, defines, module, out, files, multiple, cache_dir, create_cache, generate_main
194+
return includes, defines, module, out, files, multiple, cache_dir, create_cache, \
195+
generate_main, gccxml_path
184196

185197

186198
def PCHInclude(*headers):
@@ -227,17 +239,18 @@ def CreateContext():
227239
context['Wrapper'] = exporterutils.FunctionWrapper
228240
context['declaration_code'] = lambda code: infos.CodeInfo(code, 'declaration-outside')
229241
context['module_code'] = lambda code: infos.CodeInfo(code, 'module')
242+
context['class_code'] = infos.class_code
230243
return context
231244

232245

233246
def Begin():
234247
# parse arguments
235-
includes, defines, module, out, interfaces, multiple, cache_dir, create_cache, generate_main = ParseArguments()
248+
includes, defines, module, out, interfaces, multiple, cache_dir, create_cache, generate_main, gccxml_path = ParseArguments()
236249
# run pyste scripts
237250
for interface in interfaces:
238251
ExecuteInterface(interface)
239252
# create the parser
240-
parser = CppParser(includes, defines, cache_dir, declarations.version)
253+
parser = CppParser(includes, defines, cache_dir, declarations.version, gccxml_path)
241254
try:
242255
if not create_cache:
243256
if not generate_main:

0 commit comments

Comments
 (0)