blob: de0cc93afc6419fdecadd4436df1b72c83ebf719 [file] [log] [blame]
José Fonseca7ad40262009-09-30 17:17:12 +01001##########################################################################
José Fonseca95442442008-07-08 10:32:53 +09002#
José Fonseca6fac5ae2010-11-29 16:09:13 +00003# Copyright 2008-2010 VMware, Inc.
José Fonseca7ad40262009-09-30 17:17:12 +01004# All Rights Reserved.
José Fonseca95442442008-07-08 10:32:53 +09005#
José Fonseca7ad40262009-09-30 17:17:12 +01006# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal
8# in the Software without restriction, including without limitation the rights
9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
José Fonseca95442442008-07-08 10:32:53 +090012#
José Fonseca7ad40262009-09-30 17:17:12 +010013# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
José Fonseca95442442008-07-08 10:32:53 +090015#
José Fonseca7ad40262009-09-30 17:17:12 +010016# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.
José Fonseca95442442008-07-08 10:32:53 +090023#
José Fonseca7ad40262009-09-30 17:17:12 +010024##########################################################################/
José Fonseca95442442008-07-08 10:32:53 +090025
José Fonsecad626cf42008-07-07 07:43:16 +090026"""C basic types"""
27
José Fonseca8a56d142008-07-09 12:18:08 +090028
Jose Fonsecafdcd30b2016-02-01 14:13:40 +000029import sys
30
José Fonseca8a56d142008-07-09 12:18:08 +090031import debug
32
33
José Fonseca6fac5ae2010-11-29 16:09:13 +000034class Type:
José Fonseca02c25002011-10-15 13:17:26 +010035 """Base class for all types."""
José Fonseca6fac5ae2010-11-29 16:09:13 +000036
José Fonseca02c25002011-10-15 13:17:26 +010037 __tags = set()
José Fonseca6fac5ae2010-11-29 16:09:13 +000038
José Fonseca02c25002011-10-15 13:17:26 +010039 def __init__(self, expr, tag = None):
José Fonseca6fac5ae2010-11-29 16:09:13 +000040 self.expr = expr
José Fonseca6fac5ae2010-11-29 16:09:13 +000041
José Fonseca02c25002011-10-15 13:17:26 +010042 # Generate a default tag, used when naming functions that will operate
43 # on this type, so it should preferrably be something representative of
44 # the type.
45 if tag is None:
José Fonseca5b6fb752012-04-14 14:56:45 +010046 if expr is not None:
47 tag = ''.join([c for c in expr if c.isalnum() or c in '_'])
48 else:
49 tag = 'anonynoums'
José Fonseca02c25002011-10-15 13:17:26 +010050 else:
51 for c in tag:
52 assert c.isalnum() or c in '_'
José Fonseca6fac5ae2010-11-29 16:09:13 +000053
José Fonseca02c25002011-10-15 13:17:26 +010054 # Ensure it is unique.
55 if tag in Type.__tags:
56 suffix = 1
57 while tag + str(suffix) in Type.__tags:
58 suffix += 1
59 tag += str(suffix)
60
61 assert tag not in Type.__tags
62 Type.__tags.add(tag)
63
64 self.tag = tag
José Fonseca6fac5ae2010-11-29 16:09:13 +000065
66 def __str__(self):
José Fonseca02c25002011-10-15 13:17:26 +010067 """Return the C/C++ type expression for this type."""
José Fonseca6fac5ae2010-11-29 16:09:13 +000068 return self.expr
69
70 def visit(self, visitor, *args, **kwargs):
71 raise NotImplementedError
72
José Fonseca0075f152012-04-14 20:25:52 +010073 def mutable(self):
74 '''Return a mutable version of this type.
75
76 Convenience wrapper around MutableRebuilder.'''
77 visitor = MutableRebuilder()
78 return visitor.visit(self)
José Fonseca6fac5ae2010-11-29 16:09:13 +000079
José Fonseca13b93432014-11-18 20:21:23 +000080 def depends(self, other):
81 '''Whether this type depends on another.'''
82
83 collector = Collector()
84 collector.visit(self)
85 return other in collector.types
86
José Fonseca6fac5ae2010-11-29 16:09:13 +000087
88class _Void(Type):
José Fonseca02c25002011-10-15 13:17:26 +010089 """Singleton void type."""
José Fonseca6fac5ae2010-11-29 16:09:13 +000090
91 def __init__(self):
92 Type.__init__(self, "void")
93
94 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +000095 return visitor.visitVoid(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +000096
97Void = _Void()
98
99
100class Literal(Type):
José Fonseca2f2ea482011-10-15 15:10:06 +0100101 """Class to describe literal types.
José Fonseca6fac5ae2010-11-29 16:09:13 +0000102
José Fonseca2f2ea482011-10-15 15:10:06 +0100103 Types which are not defined in terms of other types, such as integers and
104 floats."""
105
106 def __init__(self, expr, kind):
José Fonseca6fac5ae2010-11-29 16:09:13 +0000107 Type.__init__(self, expr)
José Fonseca2f2ea482011-10-15 15:10:06 +0100108 self.kind = kind
José Fonseca6fac5ae2010-11-29 16:09:13 +0000109
110 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000111 return visitor.visitLiteral(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000112
113
José Fonsecabcfc81b2012-08-07 21:07:22 +0100114Bool = Literal("bool", "Bool")
115SChar = Literal("signed char", "SInt")
116UChar = Literal("unsigned char", "UInt")
117Short = Literal("short", "SInt")
118Int = Literal("int", "SInt")
119Long = Literal("long", "SInt")
120LongLong = Literal("long long", "SInt")
121UShort = Literal("unsigned short", "UInt")
122UInt = Literal("unsigned int", "UInt")
123ULong = Literal("unsigned long", "UInt")
124ULongLong = Literal("unsigned long long", "UInt")
125Float = Literal("float", "Float")
126Double = Literal("double", "Double")
127SizeT = Literal("size_t", "UInt")
128
129Char = Literal("char", "SInt")
130WChar = Literal("wchar_t", "SInt")
131
132Int8 = Literal("int8_t", "SInt")
133UInt8 = Literal("uint8_t", "UInt")
134Int16 = Literal("int16_t", "SInt")
135UInt16 = Literal("uint16_t", "UInt")
136Int32 = Literal("int32_t", "SInt")
137UInt32 = Literal("uint32_t", "UInt")
138Int64 = Literal("int64_t", "SInt")
139UInt64 = Literal("uint64_t", "UInt")
140
José Fonsecacb9d2e02012-10-19 14:51:48 +0100141IntPtr = Literal("intptr_t", "SInt")
142UIntPtr = Literal("uintptr_t", "UInt")
José Fonsecabcfc81b2012-08-07 21:07:22 +0100143
José Fonseca6fac5ae2010-11-29 16:09:13 +0000144class Const(Type):
145
146 def __init__(self, type):
José Fonseca903c2ca2011-09-23 09:43:05 +0100147 # While "const foo" and "foo const" are synonymous, "const foo *" and
148 # "foo * const" are not quite the same, and some compilers do enforce
149 # strict const correctness.
José Fonsecabcfc81b2012-08-07 21:07:22 +0100150 if type.expr.startswith("const ") or '*' in type.expr:
José Fonseca6fac5ae2010-11-29 16:09:13 +0000151 expr = type.expr + " const"
152 else:
José Fonseca903c2ca2011-09-23 09:43:05 +0100153 # The most legible
José Fonseca6fac5ae2010-11-29 16:09:13 +0000154 expr = "const " + type.expr
155
José Fonseca02c25002011-10-15 13:17:26 +0100156 Type.__init__(self, expr, 'C' + type.tag)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000157
158 self.type = type
159
160 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000161 return visitor.visitConst(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000162
163
164class Pointer(Type):
165
166 def __init__(self, type):
José Fonseca02c25002011-10-15 13:17:26 +0100167 Type.__init__(self, type.expr + " *", 'P' + type.tag)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000168 self.type = type
169
170 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000171 return visitor.visitPointer(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000172
173
José Fonseca59ee88e2012-01-15 14:24:10 +0000174class IntPointer(Type):
175 '''Integer encoded as a pointer.'''
176
177 def visit(self, visitor, *args, **kwargs):
178 return visitor.visitIntPointer(self, *args, **kwargs)
179
180
José Fonsecafbcf6832012-04-05 07:10:30 +0100181class ObjPointer(Type):
182 '''Pointer to an object.'''
183
184 def __init__(self, type):
185 Type.__init__(self, type.expr + " *", 'P' + type.tag)
186 self.type = type
187
188 def visit(self, visitor, *args, **kwargs):
189 return visitor.visitObjPointer(self, *args, **kwargs)
190
191
José Fonseca59ee88e2012-01-15 14:24:10 +0000192class LinearPointer(Type):
José Fonsecafbcf6832012-04-05 07:10:30 +0100193 '''Pointer to a linear range of memory.'''
José Fonseca59ee88e2012-01-15 14:24:10 +0000194
195 def __init__(self, type, size = None):
196 Type.__init__(self, type.expr + " *", 'P' + type.tag)
197 self.type = type
198 self.size = size
199
200 def visit(self, visitor, *args, **kwargs):
201 return visitor.visitLinearPointer(self, *args, **kwargs)
202
203
José Fonsecab89c5932012-04-01 22:47:11 +0200204class Reference(Type):
205 '''C++ references.'''
206
207 def __init__(self, type):
208 Type.__init__(self, type.expr + " &", 'R' + type.tag)
209 self.type = type
210
211 def visit(self, visitor, *args, **kwargs):
212 return visitor.visitReference(self, *args, **kwargs)
213
214
José Fonseca6fac5ae2010-11-29 16:09:13 +0000215class Handle(Type):
216
José Fonseca8a844ae2010-12-06 18:50:52 +0000217 def __init__(self, name, type, range=None, key=None):
José Fonseca02c25002011-10-15 13:17:26 +0100218 Type.__init__(self, type.expr, 'P' + type.tag)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000219 self.name = name
220 self.type = type
221 self.range = range
José Fonseca8a844ae2010-12-06 18:50:52 +0000222 self.key = key
José Fonseca6fac5ae2010-11-29 16:09:13 +0000223
224 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000225 return visitor.visitHandle(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000226
227
228def ConstPointer(type):
229 return Pointer(Const(type))
230
231
232class Enum(Type):
233
José Fonseca02c25002011-10-15 13:17:26 +0100234 __id = 0
235
José Fonseca6fac5ae2010-11-29 16:09:13 +0000236 def __init__(self, name, values):
237 Type.__init__(self, name)
José Fonseca02c25002011-10-15 13:17:26 +0100238
239 self.id = Enum.__id
240 Enum.__id += 1
241
José Fonseca6fac5ae2010-11-29 16:09:13 +0000242 self.values = list(values)
José Fonseca02c25002011-10-15 13:17:26 +0100243
José Fonseca6fac5ae2010-11-29 16:09:13 +0000244 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000245 return visitor.visitEnum(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000246
247
248def FakeEnum(type, values):
249 return Enum(type.expr, values)
250
251
252class Bitmask(Type):
253
José Fonseca02c25002011-10-15 13:17:26 +0100254 __id = 0
255
José Fonseca6fac5ae2010-11-29 16:09:13 +0000256 def __init__(self, type, values):
257 Type.__init__(self, type.expr)
José Fonseca02c25002011-10-15 13:17:26 +0100258
259 self.id = Bitmask.__id
260 Bitmask.__id += 1
261
José Fonseca6fac5ae2010-11-29 16:09:13 +0000262 self.type = type
263 self.values = values
264
265 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000266 return visitor.visitBitmask(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000267
268Flags = Bitmask
269
270
271class Array(Type):
272
Jose Fonsecaa9b61382015-06-10 22:04:45 +0100273 def __init__(self, type_, length):
274 Type.__init__(self, type_.expr + " *")
275 self.type = type_
José Fonseca6fac5ae2010-11-29 16:09:13 +0000276 self.length = length
Jose Fonsecaa9b61382015-06-10 22:04:45 +0100277 if not isinstance(length, int):
278 assert isinstance(length, basestring)
279 # Check if length is actually a valid constant expression
280 try:
281 eval(length, {}, {})
282 except:
283 pass
284 else:
285 raise ValueError("length %r should be an integer" % length)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000286
287 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000288 return visitor.visitArray(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000289
290
Andreas Hartmetzba7bb0d2013-07-07 22:51:12 +0200291class AttribArray(Type):
292
José Fonseca48a92b92013-07-20 15:34:24 +0100293 def __init__(self, baseType, valueTypes, terminator = '0'):
José Fonseca77c10d82013-07-20 15:27:29 +0100294 self.baseType = baseType
José Fonseca48a92b92013-07-20 15:34:24 +0100295 Type.__init__(self, (Pointer(self.baseType)).expr)
Andreas Hartmetzba7bb0d2013-07-07 22:51:12 +0200296 self.valueTypes = valueTypes
Andreas Hartmetz7a0de292013-07-09 22:38:29 +0200297 self.terminator = terminator
298 self.hasKeysWithoutValues = False
299 for key, value in valueTypes:
300 if value is None:
301 self.hasKeysWithoutValues = True
Andreas Hartmetzba7bb0d2013-07-07 22:51:12 +0200302
303 def visit(self, visitor, *args, **kwargs):
304 return visitor.visitAttribArray(self, *args, **kwargs)
305
306
José Fonseca6fac5ae2010-11-29 16:09:13 +0000307class Blob(Type):
308
309 def __init__(self, type, size):
310 Type.__init__(self, type.expr + ' *')
311 self.type = type
312 self.size = size
313
314 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000315 return visitor.visitBlob(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000316
317
318class Struct(Type):
319
José Fonseca02c25002011-10-15 13:17:26 +0100320 __id = 0
321
José Fonseca6fac5ae2010-11-29 16:09:13 +0000322 def __init__(self, name, members):
323 Type.__init__(self, name)
José Fonseca02c25002011-10-15 13:17:26 +0100324
325 self.id = Struct.__id
326 Struct.__id += 1
327
José Fonseca6fac5ae2010-11-29 16:09:13 +0000328 self.name = name
José Fonsecadbf714b2012-11-20 17:03:43 +0000329 self.members = members
José Fonseca6fac5ae2010-11-29 16:09:13 +0000330
331 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000332 return visitor.visitStruct(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000333
334
José Fonsecadbf714b2012-11-20 17:03:43 +0000335def Union(kindExpr, kindTypes, contextLess=True):
José Fonsecaeb216e62012-11-20 11:08:08 +0000336 switchTypes = []
337 for kindCase, kindType, kindMemberName in kindTypes:
338 switchType = Struct(None, [(kindType, kindMemberName)])
339 switchTypes.append((kindCase, switchType))
340 return Polymorphic(kindExpr, switchTypes, contextLess=contextLess)
341
José Fonseca5b6fb752012-04-14 14:56:45 +0100342
José Fonseca6fac5ae2010-11-29 16:09:13 +0000343class Alias(Type):
344
345 def __init__(self, expr, type):
346 Type.__init__(self, expr)
347 self.type = type
348
349 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000350 return visitor.visitAlias(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000351
José Fonseca6fac5ae2010-11-29 16:09:13 +0000352class Arg:
353
José Fonseca9dd8f702012-04-07 10:42:50 +0100354 def __init__(self, type, name, input=True, output=False):
José Fonseca6fac5ae2010-11-29 16:09:13 +0000355 self.type = type
356 self.name = name
José Fonseca9dd8f702012-04-07 10:42:50 +0100357 self.input = input
José Fonseca6fac5ae2010-11-29 16:09:13 +0000358 self.output = output
359 self.index = None
360
361 def __str__(self):
362 return '%s %s' % (self.type, self.name)
363
364
José Fonseca9dd8f702012-04-07 10:42:50 +0100365def In(type, name):
366 return Arg(type, name, input=True, output=False)
367
368def Out(type, name):
369 return Arg(type, name, input=False, output=True)
370
371def InOut(type, name):
372 return Arg(type, name, input=True, output=True)
373
374
José Fonseca6fac5ae2010-11-29 16:09:13 +0000375class Function:
376
Jose Fonsecafdcd30b2016-02-01 14:13:40 +0000377 def __init__(self, type, name, args, call = '', fail = None, sideeffects=True, internal=False, overloaded=False):
José Fonseca6fac5ae2010-11-29 16:09:13 +0000378 self.type = type
379 self.name = name
380
381 self.args = []
382 index = 0
383 for arg in args:
José Fonseca8384ccb2011-05-25 10:12:02 +0100384 if not isinstance(arg, Arg):
385 if isinstance(arg, tuple):
386 arg_type, arg_name = arg
387 else:
388 arg_type = arg
389 arg_name = "arg%u" % index
José Fonseca6fac5ae2010-11-29 16:09:13 +0000390 arg = Arg(arg_type, arg_name)
391 arg.index = index
392 index += 1
393 self.args.append(arg)
394
395 self.call = call
396 self.fail = fail
397 self.sideeffects = sideeffects
José Fonseca84cea3b2012-05-09 21:12:30 +0100398 self.internal = internal
Jose Fonsecafdcd30b2016-02-01 14:13:40 +0000399 self.overloaded = overloaded
José Fonseca6fac5ae2010-11-29 16:09:13 +0000400
401 def prototype(self, name=None):
402 if name is not None:
403 name = name.strip()
404 else:
405 name = self.name
406 s = name
407 if self.call:
408 s = self.call + ' ' + s
409 if name.startswith('*'):
410 s = '(' + s + ')'
411 s = self.type.expr + ' ' + s
412 s += "("
413 if self.args:
414 s += ", ".join(["%s %s" % (arg.type, arg.name) for arg in self.args])
415 else:
416 s += "void"
417 s += ")"
418 return s
419
Jose Fonsecafdcd30b2016-02-01 14:13:40 +0000420 def sigName(self):
421 name = self.name
422 if self.overloaded:
423 # suffix used to make overloaded functions/methods unique
424 suffix = ','.join([str(arg.type) for arg in self.args])
425 suffix = suffix.replace(' *', '*')
426 suffix = suffix.replace(' &', '&')
427 suffix = '(' + suffix + ')'
428 name += suffix
429 return name
430
José Fonseca568ecc22012-01-15 13:57:03 +0000431 def argNames(self):
432 return [arg.name for arg in self.args]
433
José Fonseca999284f2013-02-19 13:29:26 +0000434 def getArgByName(self, name):
435 for arg in self.args:
436 if arg.name == name:
437 return arg
438 return None
439
José Fonseca50c2a142015-01-15 13:10:46 +0000440 def getArgByType(self, type):
441 for arg in self.args:
442 if arg.type is type:
443 return arg
444 return None
445
José Fonseca6fac5ae2010-11-29 16:09:13 +0000446
447def StdFunction(*args, **kwargs):
448 kwargs.setdefault('call', '__stdcall')
449 return Function(*args, **kwargs)
450
451
452def FunctionPointer(type, name, args, **kwargs):
453 # XXX: We should probably treat function pointers (callbacks or not) in a generic fashion
454 return Opaque(name)
455
456
457class Interface(Type):
458
459 def __init__(self, name, base=None):
460 Type.__init__(self, name)
461 self.name = name
462 self.base = base
463 self.methods = []
464
465 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000466 return visitor.visitInterface(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000467
José Fonsecabd086342012-04-18 19:58:32 +0100468 def getMethodByName(self, name):
José Fonsecad275d0a2012-04-30 23:18:05 +0100469 for method in self.iterMethods():
470 if method.name == name:
471 return method
José Fonsecabd086342012-04-18 19:58:32 +0100472 return None
473
José Fonseca54f304a2012-01-14 19:33:08 +0000474 def iterMethods(self):
José Fonseca6fac5ae2010-11-29 16:09:13 +0000475 if self.base is not None:
José Fonseca54f304a2012-01-14 19:33:08 +0000476 for method in self.base.iterMethods():
José Fonseca6fac5ae2010-11-29 16:09:13 +0000477 yield method
478 for method in self.methods:
479 yield method
480 raise StopIteration
481
José Fonseca143e9252012-04-15 09:31:18 +0100482 def iterBases(self):
483 iface = self
484 while iface is not None:
485 yield iface
486 iface = iface.base
487 raise StopIteration
488
José Fonseca5abf5602013-05-30 14:00:44 +0100489 def hasBase(self, *bases):
490 for iface in self.iterBases():
491 if iface in bases:
492 return True
493 return False
494
José Fonseca4220b1b2012-02-03 19:05:29 +0000495 def iterBaseMethods(self):
496 if self.base is not None:
497 for iface, method in self.base.iterBaseMethods():
498 yield iface, method
499 for method in self.methods:
500 yield self, method
501 raise StopIteration
502
José Fonseca6fac5ae2010-11-29 16:09:13 +0000503
504class Method(Function):
505
Jose Fonsecafdcd30b2016-02-01 14:13:40 +0000506 def __init__(self, type, name, args, call = '', const=False, sideeffects=True, overloaded=False):
José Fonseca43aa19f2012-11-10 09:29:38 +0000507 assert call == '__stdcall'
Jose Fonsecafdcd30b2016-02-01 14:13:40 +0000508 Function.__init__(self, type, name, args, call = call, sideeffects=sideeffects, overloaded=overloaded)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000509 for index in range(len(self.args)):
510 self.args[index].index = index + 1
José Fonseca9dbeda62012-02-03 19:05:54 +0000511 self.const = const
512
513 def prototype(self, name=None):
514 s = Function.prototype(self, name)
515 if self.const:
516 s += ' const'
517 return s
José Fonseca6fac5ae2010-11-29 16:09:13 +0000518
José Fonsecabcb26b22012-04-15 08:42:25 +0100519
José Fonseca5b6fb752012-04-14 14:56:45 +0100520def StdMethod(*args, **kwargs):
521 kwargs.setdefault('call', '__stdcall')
522 return Method(*args, **kwargs)
523
José Fonseca6fac5ae2010-11-29 16:09:13 +0000524
José Fonseca6fac5ae2010-11-29 16:09:13 +0000525class String(Type):
José Fonsecabcfc81b2012-08-07 21:07:22 +0100526 '''Human-legible character string.'''
José Fonseca6fac5ae2010-11-29 16:09:13 +0000527
José Fonsecabcfc81b2012-08-07 21:07:22 +0100528 def __init__(self, type = Char, length = None, wide = False):
529 assert isinstance(type, Type)
530 Type.__init__(self, type.expr + ' *')
531 self.type = type
José Fonseca6fac5ae2010-11-29 16:09:13 +0000532 self.length = length
José Fonsecabcfc81b2012-08-07 21:07:22 +0100533 self.wide = wide
José Fonseca6fac5ae2010-11-29 16:09:13 +0000534
535 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000536 return visitor.visitString(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000537
José Fonseca6fac5ae2010-11-29 16:09:13 +0000538
539class Opaque(Type):
540 '''Opaque pointer.'''
541
542 def __init__(self, expr):
543 Type.__init__(self, expr)
544
545 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000546 return visitor.visitOpaque(self, *args, **kwargs)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000547
548
549def OpaquePointer(type, *args):
550 return Opaque(type.expr + ' *')
551
552def OpaqueArray(type, size):
553 return Opaque(type.expr + ' *')
554
555def OpaqueBlob(type, size):
556 return Opaque(type.expr + ' *')
José Fonseca8a56d142008-07-09 12:18:08 +0900557
José Fonseca501f2862010-11-19 20:41:18 +0000558
José Fonseca16d46dd2011-10-13 09:52:52 +0100559class Polymorphic(Type):
560
José Fonsecaeb216e62012-11-20 11:08:08 +0000561 def __init__(self, switchExpr, switchTypes, defaultType=None, contextLess=True):
562 if defaultType is None:
563 Type.__init__(self, None)
564 contextLess = False
565 else:
566 Type.__init__(self, defaultType.expr)
José Fonseca54f304a2012-01-14 19:33:08 +0000567 self.switchExpr = switchExpr
568 self.switchTypes = switchTypes
José Fonsecab95e3722012-04-16 14:01:15 +0100569 self.defaultType = defaultType
570 self.contextLess = contextLess
José Fonseca16d46dd2011-10-13 09:52:52 +0100571
572 def visit(self, visitor, *args, **kwargs):
José Fonseca54f304a2012-01-14 19:33:08 +0000573 return visitor.visitPolymorphic(self, *args, **kwargs)
José Fonseca16d46dd2011-10-13 09:52:52 +0100574
José Fonseca54f304a2012-01-14 19:33:08 +0000575 def iterSwitch(self):
José Fonsecaeb216e62012-11-20 11:08:08 +0000576 cases = []
577 types = []
578
579 if self.defaultType is not None:
580 cases.append(['default'])
581 types.append(self.defaultType)
José Fonseca46161112011-10-14 10:04:55 +0100582
José Fonseca54f304a2012-01-14 19:33:08 +0000583 for expr, type in self.switchTypes:
José Fonseca46161112011-10-14 10:04:55 +0100584 case = 'case %s' % expr
585 try:
586 i = types.index(type)
587 except ValueError:
588 cases.append([case])
589 types.append(type)
590 else:
591 cases[i].append(case)
592
593 return zip(cases, types)
594
José Fonseca16d46dd2011-10-13 09:52:52 +0100595
José Fonsecab95e3722012-04-16 14:01:15 +0100596def EnumPolymorphic(enumName, switchExpr, switchTypes, defaultType, contextLess=True):
597 enumValues = [expr for expr, type in switchTypes]
598 enum = Enum(enumName, enumValues)
599 polymorphic = Polymorphic(switchExpr, switchTypes, defaultType, contextLess)
600 return enum, polymorphic
601
602
José Fonseca501f2862010-11-19 20:41:18 +0000603class Visitor:
José Fonseca9c4a2572012-01-13 23:21:10 +0000604 '''Abstract visitor for the type hierarchy.'''
José Fonseca501f2862010-11-19 20:41:18 +0000605
606 def visit(self, type, *args, **kwargs):
607 return type.visit(self, *args, **kwargs)
608
José Fonseca54f304a2012-01-14 19:33:08 +0000609 def visitVoid(self, void, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000610 raise NotImplementedError
611
José Fonseca54f304a2012-01-14 19:33:08 +0000612 def visitLiteral(self, literal, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000613 raise NotImplementedError
614
José Fonseca54f304a2012-01-14 19:33:08 +0000615 def visitString(self, string, *args, **kwargs):
José Fonseca2defc982010-11-22 16:59:10 +0000616 raise NotImplementedError
617
José Fonseca54f304a2012-01-14 19:33:08 +0000618 def visitConst(self, const, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000619 raise NotImplementedError
620
José Fonseca54f304a2012-01-14 19:33:08 +0000621 def visitStruct(self, struct, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000622 raise NotImplementedError
623
José Fonseca54f304a2012-01-14 19:33:08 +0000624 def visitArray(self, array, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000625 raise NotImplementedError
626
Andreas Hartmetzba7bb0d2013-07-07 22:51:12 +0200627 def visitAttribArray(self, array, *args, **kwargs):
628 raise NotImplementedError
629
José Fonseca54f304a2012-01-14 19:33:08 +0000630 def visitBlob(self, blob, *args, **kwargs):
José Fonseca885f2652010-11-20 11:22:25 +0000631 raise NotImplementedError
632
José Fonseca54f304a2012-01-14 19:33:08 +0000633 def visitEnum(self, enum, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000634 raise NotImplementedError
635
José Fonseca54f304a2012-01-14 19:33:08 +0000636 def visitBitmask(self, bitmask, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000637 raise NotImplementedError
638
José Fonseca54f304a2012-01-14 19:33:08 +0000639 def visitPointer(self, pointer, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000640 raise NotImplementedError
641
José Fonseca59ee88e2012-01-15 14:24:10 +0000642 def visitIntPointer(self, pointer, *args, **kwargs):
643 raise NotImplementedError
644
José Fonsecafbcf6832012-04-05 07:10:30 +0100645 def visitObjPointer(self, pointer, *args, **kwargs):
646 raise NotImplementedError
647
José Fonseca59ee88e2012-01-15 14:24:10 +0000648 def visitLinearPointer(self, pointer, *args, **kwargs):
649 raise NotImplementedError
650
José Fonsecab89c5932012-04-01 22:47:11 +0200651 def visitReference(self, reference, *args, **kwargs):
652 raise NotImplementedError
653
José Fonseca54f304a2012-01-14 19:33:08 +0000654 def visitHandle(self, handle, *args, **kwargs):
José Fonseca50d78d82010-11-23 22:13:14 +0000655 raise NotImplementedError
656
José Fonseca54f304a2012-01-14 19:33:08 +0000657 def visitAlias(self, alias, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000658 raise NotImplementedError
659
José Fonseca54f304a2012-01-14 19:33:08 +0000660 def visitOpaque(self, opaque, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000661 raise NotImplementedError
662
José Fonseca54f304a2012-01-14 19:33:08 +0000663 def visitInterface(self, interface, *args, **kwargs):
José Fonsecac356d6a2010-11-23 14:27:25 +0000664 raise NotImplementedError
665
José Fonseca54f304a2012-01-14 19:33:08 +0000666 def visitPolymorphic(self, polymorphic, *args, **kwargs):
José Fonseca16d46dd2011-10-13 09:52:52 +0100667 raise NotImplementedError
José Fonseca54f304a2012-01-14 19:33:08 +0000668 #return self.visit(polymorphic.defaultType, *args, **kwargs)
José Fonseca16d46dd2011-10-13 09:52:52 +0100669
José Fonsecac356d6a2010-11-23 14:27:25 +0000670
671class OnceVisitor(Visitor):
José Fonseca9c4a2572012-01-13 23:21:10 +0000672 '''Visitor that guarantees that each type is visited only once.'''
José Fonsecac356d6a2010-11-23 14:27:25 +0000673
674 def __init__(self):
675 self.__visited = set()
676
677 def visit(self, type, *args, **kwargs):
678 if type not in self.__visited:
679 self.__visited.add(type)
680 return type.visit(self, *args, **kwargs)
681 return None
682
José Fonseca501f2862010-11-19 20:41:18 +0000683
José Fonsecac9edb832010-11-20 09:03:10 +0000684class Rebuilder(Visitor):
José Fonseca9c4a2572012-01-13 23:21:10 +0000685 '''Visitor which rebuild types as it visits them.
686
687 By itself it is a no-op -- it is intended to be overwritten.
688 '''
José Fonsecac9edb832010-11-20 09:03:10 +0000689
José Fonseca54f304a2012-01-14 19:33:08 +0000690 def visitVoid(self, void):
José Fonsecac9edb832010-11-20 09:03:10 +0000691 return void
692
José Fonseca54f304a2012-01-14 19:33:08 +0000693 def visitLiteral(self, literal):
José Fonsecac9edb832010-11-20 09:03:10 +0000694 return literal
695
José Fonseca54f304a2012-01-14 19:33:08 +0000696 def visitString(self, string):
José Fonsecabcfc81b2012-08-07 21:07:22 +0100697 string_type = self.visit(string.type)
698 if string_type is string.type:
699 return string
700 else:
701 return String(string_type, string.length, string.wide)
José Fonseca2defc982010-11-22 16:59:10 +0000702
José Fonseca54f304a2012-01-14 19:33:08 +0000703 def visitConst(self, const):
José Fonsecaf182eda2012-04-05 19:59:56 +0100704 const_type = self.visit(const.type)
705 if const_type is const.type:
706 return const
707 else:
708 return Const(const_type)
José Fonsecac9edb832010-11-20 09:03:10 +0000709
José Fonseca54f304a2012-01-14 19:33:08 +0000710 def visitStruct(self, struct):
José Fonseca06aa2842011-05-05 07:55:54 +0100711 members = [(self.visit(type), name) for type, name in struct.members]
José Fonsecac9edb832010-11-20 09:03:10 +0000712 return Struct(struct.name, members)
713
José Fonseca54f304a2012-01-14 19:33:08 +0000714 def visitArray(self, array):
José Fonsecac9edb832010-11-20 09:03:10 +0000715 type = self.visit(array.type)
716 return Array(type, array.length)
717
José Fonseca54f304a2012-01-14 19:33:08 +0000718 def visitBlob(self, blob):
José Fonseca885f2652010-11-20 11:22:25 +0000719 type = self.visit(blob.type)
720 return Blob(type, blob.size)
721
José Fonseca54f304a2012-01-14 19:33:08 +0000722 def visitEnum(self, enum):
José Fonsecac9edb832010-11-20 09:03:10 +0000723 return enum
724
José Fonseca54f304a2012-01-14 19:33:08 +0000725 def visitBitmask(self, bitmask):
José Fonsecac9edb832010-11-20 09:03:10 +0000726 type = self.visit(bitmask.type)
727 return Bitmask(type, bitmask.values)
728
José Fonseca54f304a2012-01-14 19:33:08 +0000729 def visitPointer(self, pointer):
José Fonsecaf182eda2012-04-05 19:59:56 +0100730 pointer_type = self.visit(pointer.type)
731 if pointer_type is pointer.type:
732 return pointer
733 else:
734 return Pointer(pointer_type)
José Fonsecac9edb832010-11-20 09:03:10 +0000735
José Fonseca59ee88e2012-01-15 14:24:10 +0000736 def visitIntPointer(self, pointer):
737 return pointer
738
José Fonsecafbcf6832012-04-05 07:10:30 +0100739 def visitObjPointer(self, pointer):
José Fonsecaf182eda2012-04-05 19:59:56 +0100740 pointer_type = self.visit(pointer.type)
741 if pointer_type is pointer.type:
742 return pointer
743 else:
744 return ObjPointer(pointer_type)
José Fonsecafbcf6832012-04-05 07:10:30 +0100745
José Fonseca59ee88e2012-01-15 14:24:10 +0000746 def visitLinearPointer(self, pointer):
José Fonsecaf182eda2012-04-05 19:59:56 +0100747 pointer_type = self.visit(pointer.type)
748 if pointer_type is pointer.type:
749 return pointer
750 else:
751 return LinearPointer(pointer_type)
José Fonseca59ee88e2012-01-15 14:24:10 +0000752
José Fonsecab89c5932012-04-01 22:47:11 +0200753 def visitReference(self, reference):
José Fonsecaf182eda2012-04-05 19:59:56 +0100754 reference_type = self.visit(reference.type)
755 if reference_type is reference.type:
756 return reference
757 else:
758 return Reference(reference_type)
José Fonsecab89c5932012-04-01 22:47:11 +0200759
José Fonseca54f304a2012-01-14 19:33:08 +0000760 def visitHandle(self, handle):
José Fonsecaf182eda2012-04-05 19:59:56 +0100761 handle_type = self.visit(handle.type)
762 if handle_type is handle.type:
763 return handle
764 else:
765 return Handle(handle.name, handle_type, range=handle.range, key=handle.key)
José Fonseca50d78d82010-11-23 22:13:14 +0000766
José Fonseca54f304a2012-01-14 19:33:08 +0000767 def visitAlias(self, alias):
José Fonsecaf182eda2012-04-05 19:59:56 +0100768 alias_type = self.visit(alias.type)
769 if alias_type is alias.type:
770 return alias
771 else:
772 return Alias(alias.expr, alias_type)
José Fonsecac9edb832010-11-20 09:03:10 +0000773
José Fonseca54f304a2012-01-14 19:33:08 +0000774 def visitOpaque(self, opaque):
José Fonsecac9edb832010-11-20 09:03:10 +0000775 return opaque
776
José Fonseca7814edf2012-01-31 10:55:49 +0000777 def visitInterface(self, interface, *args, **kwargs):
778 return interface
779
José Fonseca54f304a2012-01-14 19:33:08 +0000780 def visitPolymorphic(self, polymorphic):
José Fonseca54f304a2012-01-14 19:33:08 +0000781 switchExpr = polymorphic.switchExpr
782 switchTypes = [(expr, self.visit(type)) for expr, type in polymorphic.switchTypes]
José Fonsecaeb216e62012-11-20 11:08:08 +0000783 if polymorphic.defaultType is None:
784 defaultType = None
785 else:
786 defaultType = self.visit(polymorphic.defaultType)
José Fonsecab95e3722012-04-16 14:01:15 +0100787 return Polymorphic(switchExpr, switchTypes, defaultType, polymorphic.contextLess)
José Fonseca16d46dd2011-10-13 09:52:52 +0100788
José Fonsecac9edb832010-11-20 09:03:10 +0000789
José Fonseca0075f152012-04-14 20:25:52 +0100790class MutableRebuilder(Rebuilder):
791 '''Type visitor which derives a mutable type.'''
792
José Fonsecabcfc81b2012-08-07 21:07:22 +0100793 def visitString(self, string):
794 return string
795
José Fonseca0075f152012-04-14 20:25:52 +0100796 def visitConst(self, const):
797 # Strip out const qualifier
798 return const.type
799
800 def visitAlias(self, alias):
801 # Tear the alias on type changes
802 type = self.visit(alias.type)
803 if type is alias.type:
804 return alias
805 return type
806
807 def visitReference(self, reference):
808 # Strip out references
Jose Fonsecafdcd30b2016-02-01 14:13:40 +0000809 return self.visit(reference.type)
José Fonseca0075f152012-04-14 20:25:52 +0100810
811
812class Traverser(Visitor):
813 '''Visitor which all types.'''
814
815 def visitVoid(self, void, *args, **kwargs):
816 pass
817
818 def visitLiteral(self, literal, *args, **kwargs):
819 pass
820
821 def visitString(self, string, *args, **kwargs):
822 pass
823
824 def visitConst(self, const, *args, **kwargs):
825 self.visit(const.type, *args, **kwargs)
826
827 def visitStruct(self, struct, *args, **kwargs):
828 for type, name in struct.members:
829 self.visit(type, *args, **kwargs)
830
831 def visitArray(self, array, *args, **kwargs):
832 self.visit(array.type, *args, **kwargs)
833
Andreas Hartmetzba7bb0d2013-07-07 22:51:12 +0200834 def visitAttribArray(self, attribs, *args, **kwargs):
835 for key, valueType in attribs.valueTypes:
Andreas Hartmetz7a0de292013-07-09 22:38:29 +0200836 if valueType is not None:
837 self.visit(valueType, *args, **kwargs)
Andreas Hartmetzba7bb0d2013-07-07 22:51:12 +0200838
José Fonseca0075f152012-04-14 20:25:52 +0100839 def visitBlob(self, array, *args, **kwargs):
840 pass
841
842 def visitEnum(self, enum, *args, **kwargs):
843 pass
844
845 def visitBitmask(self, bitmask, *args, **kwargs):
846 self.visit(bitmask.type, *args, **kwargs)
847
848 def visitPointer(self, pointer, *args, **kwargs):
849 self.visit(pointer.type, *args, **kwargs)
850
851 def visitIntPointer(self, pointer, *args, **kwargs):
852 pass
853
854 def visitObjPointer(self, pointer, *args, **kwargs):
855 self.visit(pointer.type, *args, **kwargs)
856
857 def visitLinearPointer(self, pointer, *args, **kwargs):
858 self.visit(pointer.type, *args, **kwargs)
859
860 def visitReference(self, reference, *args, **kwargs):
861 self.visit(reference.type, *args, **kwargs)
862
863 def visitHandle(self, handle, *args, **kwargs):
864 self.visit(handle.type, *args, **kwargs)
865
866 def visitAlias(self, alias, *args, **kwargs):
867 self.visit(alias.type, *args, **kwargs)
868
869 def visitOpaque(self, opaque, *args, **kwargs):
870 pass
871
872 def visitInterface(self, interface, *args, **kwargs):
873 if interface.base is not None:
874 self.visit(interface.base, *args, **kwargs)
875 for method in interface.iterMethods():
876 for arg in method.args:
877 self.visit(arg.type, *args, **kwargs)
878 self.visit(method.type, *args, **kwargs)
879
880 def visitPolymorphic(self, polymorphic, *args, **kwargs):
José Fonseca0075f152012-04-14 20:25:52 +0100881 for expr, type in polymorphic.switchTypes:
882 self.visit(type, *args, **kwargs)
José Fonsecaeb216e62012-11-20 11:08:08 +0000883 if polymorphic.defaultType is not None:
884 self.visit(polymorphic.defaultType, *args, **kwargs)
José Fonseca0075f152012-04-14 20:25:52 +0100885
886
887class Collector(Traverser):
José Fonseca9c4a2572012-01-13 23:21:10 +0000888 '''Visitor which collects all unique types as it traverses them.'''
José Fonsecae6a50bd2010-11-24 10:12:22 +0000889
890 def __init__(self):
891 self.__visited = set()
892 self.types = []
893
894 def visit(self, type):
895 if type in self.__visited:
896 return
897 self.__visited.add(type)
898 Visitor.visit(self, type)
899 self.types.append(type)
900
José Fonseca16d46dd2011-10-13 09:52:52 +0100901
José Fonsecadbf714b2012-11-20 17:03:43 +0000902class ExpanderMixin:
903 '''Mixin class that provides a bunch of methods to expand C expressions
904 from the specifications.'''
905
906 __structs = None
907 __indices = None
908
909 def expand(self, expr):
910 # Expand a C expression, replacing certain variables
911 if not isinstance(expr, basestring):
912 return expr
913 variables = {}
914
915 if self.__structs is not None:
916 variables['self'] = '(%s)' % self.__structs[0]
917 if self.__indices is not None:
918 variables['i'] = self.__indices[0]
919
920 expandedExpr = expr.format(**variables)
921 if expandedExpr != expr and 0:
922 sys.stderr.write(" %r -> %r\n" % (expr, expandedExpr))
923 return expandedExpr
924
925 def visitMember(self, member, structInstance, *args, **kwargs):
926 memberType, memberName = member
927 if memberName is None:
928 # Anonymous structure/union member
929 memberInstance = structInstance
930 else:
931 memberInstance = '(%s).%s' % (structInstance, memberName)
932 self.__structs = (structInstance, self.__structs)
933 try:
934 return self.visit(memberType, memberInstance, *args, **kwargs)
935 finally:
936 _, self.__structs = self.__structs
937
938 def visitElement(self, elementIndex, elementType, *args, **kwargs):
939 self.__indices = (elementIndex, self.__indices)
940 try:
941 return self.visit(elementType, *args, **kwargs)
942 finally:
943 _, self.__indices = self.__indices
944
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000945
José Fonseca81301932012-11-11 00:10:20 +0000946class Module:
947 '''A collection of functions.'''
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000948
José Fonseca68ec4122011-02-20 11:25:25 +0000949 def __init__(self, name = None):
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000950 self.name = name
951 self.headers = []
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000952 self.functions = []
953 self.interfaces = []
954
José Fonseca54f304a2012-01-14 19:33:08 +0000955 def addFunctions(self, functions):
José Fonseca81301932012-11-11 00:10:20 +0000956 self.functions.extend(functions)
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000957
José Fonseca54f304a2012-01-14 19:33:08 +0000958 def addInterfaces(self, interfaces):
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000959 self.interfaces.extend(interfaces)
960
José Fonseca81301932012-11-11 00:10:20 +0000961 def mergeModule(self, module):
962 self.headers.extend(module.headers)
963 self.functions.extend(module.functions)
964 self.interfaces.extend(module.interfaces)
José Fonseca68ec4122011-02-20 11:25:25 +0000965
José Fonseca1b6c8752012-04-15 14:33:00 +0100966 def getFunctionByName(self, name):
José Fonsecaeccec3e2011-02-20 09:01:25 +0000967 for function in self.functions:
968 if function.name == name:
969 return function
970 return None
971
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000972
José Fonseca81301932012-11-11 00:10:20 +0000973class API:
974 '''API abstraction.
975
976 Essentially, a collection of types, functions, and interfaces.
977 '''
978
979 def __init__(self, modules = None):
980 self.modules = []
981 if modules is not None:
982 self.modules.extend(modules)
983
984 def getAllTypes(self):
985 collector = Collector()
986 for module in self.modules:
987 for function in module.functions:
988 for arg in function.args:
989 collector.visit(arg.type)
990 collector.visit(function.type)
991 for interface in module.interfaces:
992 collector.visit(interface)
993 for method in interface.iterMethods():
994 for arg in method.args:
995 collector.visit(arg.type)
996 collector.visit(method.type)
997 return collector.types
998
999 def getAllFunctions(self):
1000 functions = []
1001 for module in self.modules:
1002 functions.extend(module.functions)
1003 return functions
1004
1005 def getAllInterfaces(self):
1006 types = self.getAllTypes()
1007 interfaces = [type for type in types if isinstance(type, Interface)]
1008 for module in self.modules:
1009 for interface in module.interfaces:
1010 if interface not in interfaces:
1011 interfaces.append(interface)
1012 return interfaces
1013
1014 def addModule(self, module):
1015 self.modules.append(module)
1016
1017 def getFunctionByName(self, name):
1018 for module in self.modules:
1019 for function in module.functions:
1020 if function.name == name:
1021 return function
1022 return None
1023
1024
José Fonseca280a1762012-01-31 15:10:13 +00001025# C string (i.e., zero terminated)
José Fonsecabcfc81b2012-08-07 21:07:22 +01001026CString = String(Char)
1027WString = String(WChar, wide=True)
1028ConstCString = String(Const(Char))
1029ConstWString = String(Const(WChar), wide=True)