]> git.cworth.org Git - apitrace/blob - specs/stdapi.py
Merge remote-tracking branch 'github/master' into profile-gui
[apitrace] / specs / stdapi.py
1 ##########################################################################
2 #
3 # Copyright 2008-2010 VMware, Inc.
4 # All Rights Reserved.
5 #
6 # 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:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # 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.
23 #
24 ##########################################################################/
25
26 """C basic types"""
27
28
29 import debug
30
31
32 class Type:
33     """Base class for all types."""
34
35     __tags = set()
36
37     def __init__(self, expr, tag = None):
38         self.expr = expr
39
40         # Generate a default tag, used when naming functions that will operate
41         # on this type, so it should preferrably be something representative of
42         # the type.
43         if tag is None:
44             if expr is not None:
45                 tag = ''.join([c for c in expr if c.isalnum() or c in '_'])
46             else:
47                 tag = 'anonynoums'
48         else:
49             for c in tag:
50                 assert c.isalnum() or c in '_'
51
52         # Ensure it is unique.
53         if tag in Type.__tags:
54             suffix = 1
55             while tag + str(suffix) in Type.__tags:
56                 suffix += 1
57             tag += str(suffix)
58
59         assert tag not in Type.__tags
60         Type.__tags.add(tag)
61
62         self.tag = tag
63
64     def __str__(self):
65         """Return the C/C++ type expression for this type."""
66         return self.expr
67
68     def visit(self, visitor, *args, **kwargs):
69         raise NotImplementedError
70
71     def mutable(self):
72         '''Return a mutable version of this type.
73
74         Convenience wrapper around MutableRebuilder.'''
75         visitor = MutableRebuilder()
76         return visitor.visit(self)
77
78
79 class _Void(Type):
80     """Singleton void type."""
81
82     def __init__(self):
83         Type.__init__(self, "void")
84
85     def visit(self, visitor, *args, **kwargs):
86         return visitor.visitVoid(self, *args, **kwargs)
87
88 Void = _Void()
89
90
91 class Literal(Type):
92     """Class to describe literal types.
93
94     Types which are not defined in terms of other types, such as integers and
95     floats."""
96
97     def __init__(self, expr, kind):
98         Type.__init__(self, expr)
99         self.kind = kind
100
101     def visit(self, visitor, *args, **kwargs):
102         return visitor.visitLiteral(self, *args, **kwargs)
103
104
105 Bool = Literal("bool", "Bool")
106 SChar = Literal("signed char", "SInt")
107 UChar = Literal("unsigned char", "UInt")
108 Short = Literal("short", "SInt")
109 Int = Literal("int", "SInt")
110 Long = Literal("long", "SInt")
111 LongLong = Literal("long long", "SInt")
112 UShort = Literal("unsigned short", "UInt")
113 UInt = Literal("unsigned int", "UInt")
114 ULong = Literal("unsigned long", "UInt")
115 ULongLong = Literal("unsigned long long", "UInt")
116 Float = Literal("float", "Float")
117 Double = Literal("double", "Double")
118 SizeT = Literal("size_t", "UInt")
119
120 Char = Literal("char", "SInt")
121 WChar = Literal("wchar_t", "SInt")
122
123 Int8 = Literal("int8_t", "SInt")
124 UInt8 = Literal("uint8_t", "UInt")
125 Int16 = Literal("int16_t", "SInt")
126 UInt16 = Literal("uint16_t", "UInt")
127 Int32 = Literal("int32_t", "SInt")
128 UInt32 = Literal("uint32_t", "UInt")
129 Int64 = Literal("int64_t", "SInt")
130 UInt64 = Literal("uint64_t", "UInt")
131
132
133 class Const(Type):
134
135     def __init__(self, type):
136         # While "const foo" and "foo const" are synonymous, "const foo *" and
137         # "foo * const" are not quite the same, and some compilers do enforce
138         # strict const correctness.
139         if type.expr.startswith("const ") or '*' in type.expr:
140             expr = type.expr + " const"
141         else:
142             # The most legible
143             expr = "const " + type.expr
144
145         Type.__init__(self, expr, 'C' + type.tag)
146
147         self.type = type
148
149     def visit(self, visitor, *args, **kwargs):
150         return visitor.visitConst(self, *args, **kwargs)
151
152
153 class Pointer(Type):
154
155     def __init__(self, type):
156         Type.__init__(self, type.expr + " *", 'P' + type.tag)
157         self.type = type
158
159     def visit(self, visitor, *args, **kwargs):
160         return visitor.visitPointer(self, *args, **kwargs)
161
162
163 class IntPointer(Type):
164     '''Integer encoded as a pointer.'''
165
166     def visit(self, visitor, *args, **kwargs):
167         return visitor.visitIntPointer(self, *args, **kwargs)
168
169
170 class ObjPointer(Type):
171     '''Pointer to an object.'''
172
173     def __init__(self, type):
174         Type.__init__(self, type.expr + " *", 'P' + type.tag)
175         self.type = type
176
177     def visit(self, visitor, *args, **kwargs):
178         return visitor.visitObjPointer(self, *args, **kwargs)
179
180
181 class LinearPointer(Type):
182     '''Pointer to a linear range of memory.'''
183
184     def __init__(self, type, size = None):
185         Type.__init__(self, type.expr + " *", 'P' + type.tag)
186         self.type = type
187         self.size = size
188
189     def visit(self, visitor, *args, **kwargs):
190         return visitor.visitLinearPointer(self, *args, **kwargs)
191
192
193 class Reference(Type):
194     '''C++ references.'''
195
196     def __init__(self, type):
197         Type.__init__(self, type.expr + " &", 'R' + type.tag)
198         self.type = type
199
200     def visit(self, visitor, *args, **kwargs):
201         return visitor.visitReference(self, *args, **kwargs)
202
203
204 class Handle(Type):
205
206     def __init__(self, name, type, range=None, key=None):
207         Type.__init__(self, type.expr, 'P' + type.tag)
208         self.name = name
209         self.type = type
210         self.range = range
211         self.key = key
212
213     def visit(self, visitor, *args, **kwargs):
214         return visitor.visitHandle(self, *args, **kwargs)
215
216
217 def ConstPointer(type):
218     return Pointer(Const(type))
219
220
221 class Enum(Type):
222
223     __id = 0
224
225     def __init__(self, name, values):
226         Type.__init__(self, name)
227
228         self.id = Enum.__id
229         Enum.__id += 1
230
231         self.values = list(values)
232
233     def visit(self, visitor, *args, **kwargs):
234         return visitor.visitEnum(self, *args, **kwargs)
235
236
237 def FakeEnum(type, values):
238     return Enum(type.expr, values)
239
240
241 class Bitmask(Type):
242
243     __id = 0
244
245     def __init__(self, type, values):
246         Type.__init__(self, type.expr)
247
248         self.id = Bitmask.__id
249         Bitmask.__id += 1
250
251         self.type = type
252         self.values = values
253
254     def visit(self, visitor, *args, **kwargs):
255         return visitor.visitBitmask(self, *args, **kwargs)
256
257 Flags = Bitmask
258
259
260 class Array(Type):
261
262     def __init__(self, type, length):
263         Type.__init__(self, type.expr + " *")
264         self.type = type
265         self.length = length
266
267     def visit(self, visitor, *args, **kwargs):
268         return visitor.visitArray(self, *args, **kwargs)
269
270
271 class Blob(Type):
272
273     def __init__(self, type, size):
274         Type.__init__(self, type.expr + ' *')
275         self.type = type
276         self.size = size
277
278     def visit(self, visitor, *args, **kwargs):
279         return visitor.visitBlob(self, *args, **kwargs)
280
281
282 class Struct(Type):
283
284     __id = 0
285
286     def __init__(self, name, members):
287         Type.__init__(self, name)
288
289         self.id = Struct.__id
290         Struct.__id += 1
291
292         self.name = name
293         self.members = []
294
295         # Eliminate anonymous unions
296         for type, name in members:
297             if name is not None:
298                 self.members.append((type, name))
299             else:
300                 assert isinstance(type, Union)
301                 assert type.name is None
302                 self.members.extend(type.members)
303
304     def visit(self, visitor, *args, **kwargs):
305         return visitor.visitStruct(self, *args, **kwargs)
306
307
308 class Union(Type):
309
310     __id = 0
311
312     def __init__(self, name, members):
313         Type.__init__(self, name)
314
315         self.id = Union.__id
316         Union.__id += 1
317
318         self.name = name
319         self.members = members
320
321
322 class Alias(Type):
323
324     def __init__(self, expr, type):
325         Type.__init__(self, expr)
326         self.type = type
327
328     def visit(self, visitor, *args, **kwargs):
329         return visitor.visitAlias(self, *args, **kwargs)
330
331 class Arg:
332
333     def __init__(self, type, name, input=True, output=False):
334         self.type = type
335         self.name = name
336         self.input = input
337         self.output = output
338         self.index = None
339
340     def __str__(self):
341         return '%s %s' % (self.type, self.name)
342
343
344 def In(type, name):
345     return Arg(type, name, input=True, output=False)
346
347 def Out(type, name):
348     return Arg(type, name, input=False, output=True)
349
350 def InOut(type, name):
351     return Arg(type, name, input=True, output=True)
352
353
354 class Function:
355
356     # 0-3 are reserved to memcpy, malloc, free, and realloc
357     __id = 4
358
359     def __init__(self, type, name, args, call = '', fail = None, sideeffects=True, internal=False):
360         self.id = Function.__id
361         Function.__id += 1
362
363         self.type = type
364         self.name = name
365
366         self.args = []
367         index = 0
368         for arg in args:
369             if not isinstance(arg, Arg):
370                 if isinstance(arg, tuple):
371                     arg_type, arg_name = arg
372                 else:
373                     arg_type = arg
374                     arg_name = "arg%u" % index
375                 arg = Arg(arg_type, arg_name)
376             arg.index = index
377             index += 1
378             self.args.append(arg)
379
380         self.call = call
381         self.fail = fail
382         self.sideeffects = sideeffects
383         self.internal = internal
384
385     def prototype(self, name=None):
386         if name is not None:
387             name = name.strip()
388         else:
389             name = self.name
390         s = name
391         if self.call:
392             s = self.call + ' ' + s
393         if name.startswith('*'):
394             s = '(' + s + ')'
395         s = self.type.expr + ' ' + s
396         s += "("
397         if self.args:
398             s += ", ".join(["%s %s" % (arg.type, arg.name) for arg in self.args])
399         else:
400             s += "void"
401         s += ")"
402         return s
403
404     def argNames(self):
405         return [arg.name for arg in self.args]
406
407
408 def StdFunction(*args, **kwargs):
409     kwargs.setdefault('call', '__stdcall')
410     return Function(*args, **kwargs)
411
412
413 def FunctionPointer(type, name, args, **kwargs):
414     # XXX: We should probably treat function pointers (callbacks or not) in a generic fashion
415     return Opaque(name)
416
417
418 class Interface(Type):
419
420     def __init__(self, name, base=None):
421         Type.__init__(self, name)
422         self.name = name
423         self.base = base
424         self.methods = []
425
426     def visit(self, visitor, *args, **kwargs):
427         return visitor.visitInterface(self, *args, **kwargs)
428
429     def getMethodByName(self, name):
430         for method in self.iterMethods():
431             if method.name == name:
432                 return method
433         return None
434
435     def iterMethods(self):
436         if self.base is not None:
437             for method in self.base.iterMethods():
438                 yield method
439         for method in self.methods:
440             yield method
441         raise StopIteration
442
443     def iterBases(self):
444         iface = self
445         while iface is not None:
446             yield iface
447             iface = iface.base
448         raise StopIteration
449
450     def iterBaseMethods(self):
451         if self.base is not None:
452             for iface, method in self.base.iterBaseMethods():
453                 yield iface, method
454         for method in self.methods:
455             yield self, method
456         raise StopIteration
457
458
459 class Method(Function):
460
461     def __init__(self, type, name, args, call = '__stdcall', const=False, sideeffects=True):
462         Function.__init__(self, type, name, args, call = call, sideeffects=sideeffects)
463         for index in range(len(self.args)):
464             self.args[index].index = index + 1
465         self.const = const
466
467     def prototype(self, name=None):
468         s = Function.prototype(self, name)
469         if self.const:
470             s += ' const'
471         return s
472
473
474 def StdMethod(*args, **kwargs):
475     kwargs.setdefault('call', '__stdcall')
476     return Method(*args, **kwargs)
477
478
479 class String(Type):
480     '''Human-legible character string.'''
481
482     def __init__(self, type = Char, length = None, wide = False):
483         assert isinstance(type, Type)
484         Type.__init__(self, type.expr + ' *')
485         self.type = type
486         self.length = length
487         self.wide = wide
488
489     def visit(self, visitor, *args, **kwargs):
490         return visitor.visitString(self, *args, **kwargs)
491
492
493 class Opaque(Type):
494     '''Opaque pointer.'''
495
496     def __init__(self, expr):
497         Type.__init__(self, expr)
498
499     def visit(self, visitor, *args, **kwargs):
500         return visitor.visitOpaque(self, *args, **kwargs)
501
502
503 def OpaquePointer(type, *args):
504     return Opaque(type.expr + ' *')
505
506 def OpaqueArray(type, size):
507     return Opaque(type.expr + ' *')
508
509 def OpaqueBlob(type, size):
510     return Opaque(type.expr + ' *')
511
512
513 class Polymorphic(Type):
514
515     def __init__(self, switchExpr, switchTypes, defaultType, contextLess=True):
516         Type.__init__(self, defaultType.expr)
517         self.switchExpr = switchExpr
518         self.switchTypes = switchTypes
519         self.defaultType = defaultType
520         self.contextLess = contextLess
521
522     def visit(self, visitor, *args, **kwargs):
523         return visitor.visitPolymorphic(self, *args, **kwargs)
524
525     def iterSwitch(self):
526         cases = [['default']]
527         types = [self.defaultType]
528
529         for expr, type in self.switchTypes:
530             case = 'case %s' % expr
531             try:
532                 i = types.index(type)
533             except ValueError:
534                 cases.append([case])
535                 types.append(type)
536             else:
537                 cases[i].append(case)
538
539         return zip(cases, types)
540
541
542 def EnumPolymorphic(enumName, switchExpr, switchTypes, defaultType, contextLess=True):
543     enumValues = [expr for expr, type in switchTypes]
544     enum = Enum(enumName, enumValues)
545     polymorphic = Polymorphic(switchExpr, switchTypes, defaultType, contextLess)
546     return enum, polymorphic
547
548
549 class Visitor:
550     '''Abstract visitor for the type hierarchy.'''
551
552     def visit(self, type, *args, **kwargs):
553         return type.visit(self, *args, **kwargs)
554
555     def visitVoid(self, void, *args, **kwargs):
556         raise NotImplementedError
557
558     def visitLiteral(self, literal, *args, **kwargs):
559         raise NotImplementedError
560
561     def visitString(self, string, *args, **kwargs):
562         raise NotImplementedError
563
564     def visitConst(self, const, *args, **kwargs):
565         raise NotImplementedError
566
567     def visitStruct(self, struct, *args, **kwargs):
568         raise NotImplementedError
569
570     def visitArray(self, array, *args, **kwargs):
571         raise NotImplementedError
572
573     def visitBlob(self, blob, *args, **kwargs):
574         raise NotImplementedError
575
576     def visitEnum(self, enum, *args, **kwargs):
577         raise NotImplementedError
578
579     def visitBitmask(self, bitmask, *args, **kwargs):
580         raise NotImplementedError
581
582     def visitPointer(self, pointer, *args, **kwargs):
583         raise NotImplementedError
584
585     def visitIntPointer(self, pointer, *args, **kwargs):
586         raise NotImplementedError
587
588     def visitObjPointer(self, pointer, *args, **kwargs):
589         raise NotImplementedError
590
591     def visitLinearPointer(self, pointer, *args, **kwargs):
592         raise NotImplementedError
593
594     def visitReference(self, reference, *args, **kwargs):
595         raise NotImplementedError
596
597     def visitHandle(self, handle, *args, **kwargs):
598         raise NotImplementedError
599
600     def visitAlias(self, alias, *args, **kwargs):
601         raise NotImplementedError
602
603     def visitOpaque(self, opaque, *args, **kwargs):
604         raise NotImplementedError
605
606     def visitInterface(self, interface, *args, **kwargs):
607         raise NotImplementedError
608
609     def visitPolymorphic(self, polymorphic, *args, **kwargs):
610         raise NotImplementedError
611         #return self.visit(polymorphic.defaultType, *args, **kwargs)
612
613
614 class OnceVisitor(Visitor):
615     '''Visitor that guarantees that each type is visited only once.'''
616
617     def __init__(self):
618         self.__visited = set()
619
620     def visit(self, type, *args, **kwargs):
621         if type not in self.__visited:
622             self.__visited.add(type)
623             return type.visit(self, *args, **kwargs)
624         return None
625
626
627 class Rebuilder(Visitor):
628     '''Visitor which rebuild types as it visits them.
629
630     By itself it is a no-op -- it is intended to be overwritten.
631     '''
632
633     def visitVoid(self, void):
634         return void
635
636     def visitLiteral(self, literal):
637         return literal
638
639     def visitString(self, string):
640         string_type = self.visit(string.type)
641         if string_type is string.type:
642             return string
643         else:
644             return String(string_type, string.length, string.wide)
645
646     def visitConst(self, const):
647         const_type = self.visit(const.type)
648         if const_type is const.type:
649             return const
650         else:
651             return Const(const_type)
652
653     def visitStruct(self, struct):
654         members = [(self.visit(type), name) for type, name in struct.members]
655         return Struct(struct.name, members)
656
657     def visitArray(self, array):
658         type = self.visit(array.type)
659         return Array(type, array.length)
660
661     def visitBlob(self, blob):
662         type = self.visit(blob.type)
663         return Blob(type, blob.size)
664
665     def visitEnum(self, enum):
666         return enum
667
668     def visitBitmask(self, bitmask):
669         type = self.visit(bitmask.type)
670         return Bitmask(type, bitmask.values)
671
672     def visitPointer(self, pointer):
673         pointer_type = self.visit(pointer.type)
674         if pointer_type is pointer.type:
675             return pointer
676         else:
677             return Pointer(pointer_type)
678
679     def visitIntPointer(self, pointer):
680         return pointer
681
682     def visitObjPointer(self, pointer):
683         pointer_type = self.visit(pointer.type)
684         if pointer_type is pointer.type:
685             return pointer
686         else:
687             return ObjPointer(pointer_type)
688
689     def visitLinearPointer(self, pointer):
690         pointer_type = self.visit(pointer.type)
691         if pointer_type is pointer.type:
692             return pointer
693         else:
694             return LinearPointer(pointer_type)
695
696     def visitReference(self, reference):
697         reference_type = self.visit(reference.type)
698         if reference_type is reference.type:
699             return reference
700         else:
701             return Reference(reference_type)
702
703     def visitHandle(self, handle):
704         handle_type = self.visit(handle.type)
705         if handle_type is handle.type:
706             return handle
707         else:
708             return Handle(handle.name, handle_type, range=handle.range, key=handle.key)
709
710     def visitAlias(self, alias):
711         alias_type = self.visit(alias.type)
712         if alias_type is alias.type:
713             return alias
714         else:
715             return Alias(alias.expr, alias_type)
716
717     def visitOpaque(self, opaque):
718         return opaque
719
720     def visitInterface(self, interface, *args, **kwargs):
721         return interface
722
723     def visitPolymorphic(self, polymorphic):
724         switchExpr = polymorphic.switchExpr
725         switchTypes = [(expr, self.visit(type)) for expr, type in polymorphic.switchTypes]
726         defaultType = self.visit(polymorphic.defaultType)
727         return Polymorphic(switchExpr, switchTypes, defaultType, polymorphic.contextLess)
728
729
730 class MutableRebuilder(Rebuilder):
731     '''Type visitor which derives a mutable type.'''
732
733     def visitString(self, string):
734         return string
735
736     def visitConst(self, const):
737         # Strip out const qualifier
738         return const.type
739
740     def visitAlias(self, alias):
741         # Tear the alias on type changes
742         type = self.visit(alias.type)
743         if type is alias.type:
744             return alias
745         return type
746
747     def visitReference(self, reference):
748         # Strip out references
749         return reference.type
750
751
752 class Traverser(Visitor):
753     '''Visitor which all types.'''
754
755     def visitVoid(self, void, *args, **kwargs):
756         pass
757
758     def visitLiteral(self, literal, *args, **kwargs):
759         pass
760
761     def visitString(self, string, *args, **kwargs):
762         pass
763
764     def visitConst(self, const, *args, **kwargs):
765         self.visit(const.type, *args, **kwargs)
766
767     def visitStruct(self, struct, *args, **kwargs):
768         for type, name in struct.members:
769             self.visit(type, *args, **kwargs)
770
771     def visitArray(self, array, *args, **kwargs):
772         self.visit(array.type, *args, **kwargs)
773
774     def visitBlob(self, array, *args, **kwargs):
775         pass
776
777     def visitEnum(self, enum, *args, **kwargs):
778         pass
779
780     def visitBitmask(self, bitmask, *args, **kwargs):
781         self.visit(bitmask.type, *args, **kwargs)
782
783     def visitPointer(self, pointer, *args, **kwargs):
784         self.visit(pointer.type, *args, **kwargs)
785
786     def visitIntPointer(self, pointer, *args, **kwargs):
787         pass
788
789     def visitObjPointer(self, pointer, *args, **kwargs):
790         self.visit(pointer.type, *args, **kwargs)
791
792     def visitLinearPointer(self, pointer, *args, **kwargs):
793         self.visit(pointer.type, *args, **kwargs)
794
795     def visitReference(self, reference, *args, **kwargs):
796         self.visit(reference.type, *args, **kwargs)
797
798     def visitHandle(self, handle, *args, **kwargs):
799         self.visit(handle.type, *args, **kwargs)
800
801     def visitAlias(self, alias, *args, **kwargs):
802         self.visit(alias.type, *args, **kwargs)
803
804     def visitOpaque(self, opaque, *args, **kwargs):
805         pass
806
807     def visitInterface(self, interface, *args, **kwargs):
808         if interface.base is not None:
809             self.visit(interface.base, *args, **kwargs)
810         for method in interface.iterMethods():
811             for arg in method.args:
812                 self.visit(arg.type, *args, **kwargs)
813             self.visit(method.type, *args, **kwargs)
814
815     def visitPolymorphic(self, polymorphic, *args, **kwargs):
816         self.visit(polymorphic.defaultType, *args, **kwargs)
817         for expr, type in polymorphic.switchTypes:
818             self.visit(type, *args, **kwargs)
819
820
821 class Collector(Traverser):
822     '''Visitor which collects all unique types as it traverses them.'''
823
824     def __init__(self):
825         self.__visited = set()
826         self.types = []
827
828     def visit(self, type):
829         if type in self.__visited:
830             return
831         self.__visited.add(type)
832         Visitor.visit(self, type)
833         self.types.append(type)
834
835
836
837 class API:
838     '''API abstraction.
839
840     Essentially, a collection of types, functions, and interfaces.
841     '''
842
843     def __init__(self, name = None):
844         self.name = name
845         self.headers = []
846         self.functions = []
847         self.interfaces = []
848
849     def getAllTypes(self):
850         collector = Collector()
851         for function in self.functions:
852             for arg in function.args:
853                 collector.visit(arg.type)
854             collector.visit(function.type)
855         for interface in self.interfaces:
856             collector.visit(interface)
857             for method in interface.iterMethods():
858                 for arg in method.args:
859                     collector.visit(arg.type)
860                 collector.visit(method.type)
861         return collector.types
862
863     def getAllInterfaces(self):
864         types = self.getAllTypes()
865         interfaces = [type for type in types if isinstance(type, Interface)]
866         for interface in self.interfaces:
867             if interface not in interfaces:
868                 interfaces.append(interface)
869         return interfaces
870
871     def addFunction(self, function):
872         self.functions.append(function)
873
874     def addFunctions(self, functions):
875         for function in functions:
876             self.addFunction(function)
877
878     def addInterface(self, interface):
879         self.interfaces.append(interface)
880
881     def addInterfaces(self, interfaces):
882         self.interfaces.extend(interfaces)
883
884     def addApi(self, api):
885         self.headers.extend(api.headers)
886         self.addFunctions(api.functions)
887         self.addInterfaces(api.interfaces)
888
889     def getFunctionByName(self, name):
890         for function in self.functions:
891             if function.name == name:
892                 return function
893         return None
894
895
896 # C string (i.e., zero terminated)
897 CString = String(Char)
898 WString = String(WChar, wide=True)
899 ConstCString = String(Const(Char))
900 ConstWString = String(Const(WChar), wide=True)