Skip to content

Commit 06b8320

Browse files
author
Bruno da Silva de Oliveira
committed
- Added exception specifiers (patch by Gottfried).
[SVN r19645]
1 parent 7f3acea commit 06b8320

7 files changed

Lines changed: 42 additions & 13 deletions

File tree

pyste/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
16 August 2003
2+
Applied a patch by Gottfried Ganssauge that adds exception specifiers to
3+
wrapper functions and pointer declarations. Thanks a lot Gottfried!!
4+
15
10 August 2003
26
Support for incremental generation of the code has been added. This changes
37
how --multiple works; documentation of this new feature will follow. Thanks

pyste/src/Pyste/ClassExporter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ def Declaration(self, method, indent):
695695
constantness = ' const'
696696

697697
# call_method callback
698-
decl = indent + '%s %s(%s)%s {\n' % (result, method.name, params, constantness)
698+
decl = indent + '%s %s(%s)%s%s {\n' % (result, method.name, params, constantness, method.Exceptions())
699699
param_names_str = ', '.join(param_names)
700700
if param_names_str:
701701
param_names_str = ', ' + param_names_str
@@ -804,15 +804,16 @@ def IsVirtual(m):
804804
# them.
805805
def MethodSig(method):
806806
if method.const:
807-
const = 'const'
807+
const = ' const'
808808
else:
809809
const = ''
810810
if method.result:
811811
result = method.result.FullName()
812812
else:
813813
result = ''
814814
params = ', '.join([x.FullName() for x in method.parameters])
815-
return '%s %s(%s) %s' % (result, method.name, params, const)
815+
return '%s %s(%s)%s%s' % (
816+
result, method.name, params, const, method.Exceptions())
816817

817818
already_added = {}
818819
self.virtual_methods = []

pyste/src/Pyste/FunctionExporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def ExportDeclaration(self, decl, unique, codeunit):
4444
codeunit.Write('module', self.INDENT + defs + '\n')
4545
# add the code of the wrapper
4646
if wrapper and wrapper.code:
47-
codeunit.Write('declaration', code + '\n')
47+
codeunit.Write('declaration', wrapper.code + '\n')
4848

4949

5050
def OverloadName(self, decl):

pyste/src/Pyste/GCCXMLParser.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ def GetArguments(self, element):
193193
return args
194194

195195

196+
def GetExceptions(self, exception_list):
197+
if exception_list is None:
198+
return None
199+
200+
exceptions = []
201+
for t in exception_list.split():
202+
exceptions.append(self.GetType(t))
203+
204+
return exceptions
205+
206+
196207
def ParseFunction(self, id, element, functionType=Function):
197208
'''functionType is used because a Operator is identical to a normal
198209
function, only the type of the function changes.'''
@@ -202,7 +213,8 @@ def ParseFunction(self, id, element, functionType=Function):
202213
location = self.GetLocation(element.get('location'))
203214
params = self.GetArguments(element)
204215
incomplete = bool(int(element.get('incomplete', 0)))
205-
function = functionType(name, namespace, returns, params)
216+
throws = self.GetExceptions(element.get('throw', None))
217+
function = functionType(name, namespace, returns, params, throws)
206218
function.location = location
207219
self.AddDecl(function)
208220
self.Update(id, function)
@@ -366,9 +378,10 @@ def ParseMethod(self, id, element, methodType=Method):
366378
abstract = bool(int(element.get('pure_virtual', '0')))
367379
const = bool(int(element.get('const', '0')))
368380
location = self.GetLocation(element.get('location'))
381+
throws = self.GetExceptions(element.get('throw', None))
369382
params = self.GetArguments(element)
370383
method = methodType(
371-
name, classname, result, params, visib, virtual, abstract, static, const)
384+
name, classname, result, params, visib, virtual, abstract, static, const, throws)
372385
method.location = location
373386
self.Update(id, method)
374387

pyste/src/Pyste/SingleCodeUnit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def Section(self, section):
5050
return self.code[section]
5151

5252

53-
def SetCurrent(self, current):
53+
def SetCurrent(self, *args):
5454
pass
5555

5656

pyste/src/Pyste/declarations.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,24 @@ class Function(Declaration):
196196
'''The declaration of a function.
197197
@ivar _result: instance of L{Type} or None.
198198
@ivar _parameters: list of L{Type} instances.
199+
@ivar _throws: exception specifiers or None
199200
'''
200201

201-
def __init__(self, name, namespace, result, params):
202+
def __init__(self, name, namespace, result, params, throws=None):
202203
Declaration.__init__(self, name, namespace)
203204
# the result type: instance of Type, or None (constructors)
204205
self.result = result
205206
# the parameters: instances of Type
206207
self.parameters = params
208+
# the exception specification
209+
self.throws = throws
210+
211+
212+
def Exceptions(self):
213+
if self.throws is None:
214+
return ""
215+
else:
216+
return " throw(%s)" % ', '.join (self.throws)
207217

208218

209219
def PointerDeclaration(self, force=False):
@@ -264,10 +274,11 @@ class Method(Function):
264274
@ivar _static: if this method is static.
265275
@ivar _class: the full name of the class where this method was declared.
266276
@ivar _const: if this method is declared as const.
277+
@ivar _throws: list of exception specificiers or None
267278
'''
268279

269-
def __init__(self, name, class_, result, params, visib, virtual, abstract, static, const):
270-
Function.__init__(self, name, None, result, params)
280+
def __init__(self, name, class_, result, params, visib, virtual, abstract, static, const, throws=None):
281+
Function.__init__(self, name, None, result, params, throws)
271282
self.visibility = visib
272283
self.virtual = virtual
273284
self.abstract = abstract
@@ -296,8 +307,8 @@ def PointerDeclaration(self, force=False):
296307
const = ''
297308
if self.const:
298309
const = 'const'
299-
return '(%s (%s::*)(%s) %s)&%s' %\
300-
(result, self.class_, params, const, self.FullName())
310+
return '(%s (%s::*)(%s) %s%s)&%s' %\
311+
(result, self.class_, params, const, self.Exceptions(), self.FullName())
301312

302313

303314
#==============================================================================

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
from declarations import Typedef
4545

46-
__VERSION__ = '0.9.12'
46+
__VERSION__ = '0.9.13'
4747

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

0 commit comments

Comments
 (0)