blob: 7044c3818d94ef88f3bc217becc485b0867076f1 [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
29import debug
30
31
José Fonseca6fac5ae2010-11-29 16:09:13 +000032class Type:
José Fonseca02c25002011-10-15 13:17:26 +010033 """Base class for all types."""
José Fonseca6fac5ae2010-11-29 16:09:13 +000034
José Fonseca02c25002011-10-15 13:17:26 +010035 __tags = set()
José Fonseca6fac5ae2010-11-29 16:09:13 +000036
José Fonseca02c25002011-10-15 13:17:26 +010037 def __init__(self, expr, tag = None):
José Fonseca6fac5ae2010-11-29 16:09:13 +000038 self.expr = expr
José Fonseca6fac5ae2010-11-29 16:09:13 +000039
José Fonseca02c25002011-10-15 13:17:26 +010040 # 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 tag = ''.join([c for c in expr if c.isalnum() or c in '_'])
45 else:
46 for c in tag:
47 assert c.isalnum() or c in '_'
José Fonseca6fac5ae2010-11-29 16:09:13 +000048
José Fonseca02c25002011-10-15 13:17:26 +010049 # Ensure it is unique.
50 if tag in Type.__tags:
51 suffix = 1
52 while tag + str(suffix) in Type.__tags:
53 suffix += 1
54 tag += str(suffix)
55
56 assert tag not in Type.__tags
57 Type.__tags.add(tag)
58
59 self.tag = tag
José Fonseca6fac5ae2010-11-29 16:09:13 +000060
61 def __str__(self):
José Fonseca02c25002011-10-15 13:17:26 +010062 """Return the C/C++ type expression for this type."""
José Fonseca6fac5ae2010-11-29 16:09:13 +000063 return self.expr
64
65 def visit(self, visitor, *args, **kwargs):
66 raise NotImplementedError
67
68
69
70class _Void(Type):
José Fonseca02c25002011-10-15 13:17:26 +010071 """Singleton void type."""
José Fonseca6fac5ae2010-11-29 16:09:13 +000072
73 def __init__(self):
74 Type.__init__(self, "void")
75
76 def visit(self, visitor, *args, **kwargs):
77 return visitor.visit_void(self, *args, **kwargs)
78
79Void = _Void()
80
81
82class Literal(Type):
83
José Fonseca74163462011-10-15 11:21:15 +010084 def __init__(self, expr, format):
José Fonseca6fac5ae2010-11-29 16:09:13 +000085 Type.__init__(self, expr)
86 self.format = format
87
88 def visit(self, visitor, *args, **kwargs):
89 return visitor.visit_literal(self, *args, **kwargs)
90
91
92class Const(Type):
93
94 def __init__(self, type):
José Fonseca903c2ca2011-09-23 09:43:05 +010095 # While "const foo" and "foo const" are synonymous, "const foo *" and
96 # "foo * const" are not quite the same, and some compilers do enforce
97 # strict const correctness.
98 if isinstance(type, String) or type is WString:
99 # For strings we never intend to say a const pointer to chars, but
100 # rather a point to const chars.
101 expr = "const " + type.expr
102 elif type.expr.startswith("const ") or '*' in type.expr:
José Fonseca6fac5ae2010-11-29 16:09:13 +0000103 expr = type.expr + " const"
104 else:
José Fonseca903c2ca2011-09-23 09:43:05 +0100105 # The most legible
José Fonseca6fac5ae2010-11-29 16:09:13 +0000106 expr = "const " + type.expr
107
José Fonseca02c25002011-10-15 13:17:26 +0100108 Type.__init__(self, expr, 'C' + type.tag)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000109
110 self.type = type
111
112 def visit(self, visitor, *args, **kwargs):
113 return visitor.visit_const(self, *args, **kwargs)
114
115
116class Pointer(Type):
117
118 def __init__(self, type):
José Fonseca02c25002011-10-15 13:17:26 +0100119 Type.__init__(self, type.expr + " *", 'P' + type.tag)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000120 self.type = type
121
122 def visit(self, visitor, *args, **kwargs):
123 return visitor.visit_pointer(self, *args, **kwargs)
124
125
126class Handle(Type):
127
José Fonseca8a844ae2010-12-06 18:50:52 +0000128 def __init__(self, name, type, range=None, key=None):
José Fonseca02c25002011-10-15 13:17:26 +0100129 Type.__init__(self, type.expr, 'P' + type.tag)
José Fonseca6fac5ae2010-11-29 16:09:13 +0000130 self.name = name
131 self.type = type
132 self.range = range
José Fonseca8a844ae2010-12-06 18:50:52 +0000133 self.key = key
José Fonseca6fac5ae2010-11-29 16:09:13 +0000134
135 def visit(self, visitor, *args, **kwargs):
136 return visitor.visit_handle(self, *args, **kwargs)
137
138
139def ConstPointer(type):
140 return Pointer(Const(type))
141
142
143class Enum(Type):
144
José Fonseca02c25002011-10-15 13:17:26 +0100145 __id = 0
146
José Fonseca6fac5ae2010-11-29 16:09:13 +0000147 def __init__(self, name, values):
148 Type.__init__(self, name)
José Fonseca02c25002011-10-15 13:17:26 +0100149
150 self.id = Enum.__id
151 Enum.__id += 1
152
José Fonseca6fac5ae2010-11-29 16:09:13 +0000153 self.values = list(values)
José Fonseca02c25002011-10-15 13:17:26 +0100154
José Fonseca6fac5ae2010-11-29 16:09:13 +0000155 def visit(self, visitor, *args, **kwargs):
156 return visitor.visit_enum(self, *args, **kwargs)
157
158
159def FakeEnum(type, values):
160 return Enum(type.expr, values)
161
162
163class Bitmask(Type):
164
José Fonseca02c25002011-10-15 13:17:26 +0100165 __id = 0
166
José Fonseca6fac5ae2010-11-29 16:09:13 +0000167 def __init__(self, type, values):
168 Type.__init__(self, type.expr)
José Fonseca02c25002011-10-15 13:17:26 +0100169
170 self.id = Bitmask.__id
171 Bitmask.__id += 1
172
José Fonseca6fac5ae2010-11-29 16:09:13 +0000173 self.type = type
174 self.values = values
175
176 def visit(self, visitor, *args, **kwargs):
177 return visitor.visit_bitmask(self, *args, **kwargs)
178
179Flags = Bitmask
180
181
182class Array(Type):
183
184 def __init__(self, type, length):
185 Type.__init__(self, type.expr + " *")
186 self.type = type
187 self.length = length
188
189 def visit(self, visitor, *args, **kwargs):
190 return visitor.visit_array(self, *args, **kwargs)
191
192
193class Blob(Type):
194
195 def __init__(self, type, size):
196 Type.__init__(self, type.expr + ' *')
197 self.type = type
198 self.size = size
199
200 def visit(self, visitor, *args, **kwargs):
201 return visitor.visit_blob(self, *args, **kwargs)
202
203
204class Struct(Type):
205
José Fonseca02c25002011-10-15 13:17:26 +0100206 __id = 0
207
José Fonseca6fac5ae2010-11-29 16:09:13 +0000208 def __init__(self, name, members):
209 Type.__init__(self, name)
José Fonseca02c25002011-10-15 13:17:26 +0100210
211 self.id = Struct.__id
212 Struct.__id += 1
213
José Fonseca6fac5ae2010-11-29 16:09:13 +0000214 self.name = name
215 self.members = members
216
217 def visit(self, visitor, *args, **kwargs):
218 return visitor.visit_struct(self, *args, **kwargs)
219
220
221class Alias(Type):
222
223 def __init__(self, expr, type):
224 Type.__init__(self, expr)
225 self.type = type
226
227 def visit(self, visitor, *args, **kwargs):
228 return visitor.visit_alias(self, *args, **kwargs)
229
230
231def Out(type, name):
232 arg = Arg(type, name, output=True)
233 return arg
234
235
236class Arg:
237
238 def __init__(self, type, name, output=False):
239 self.type = type
240 self.name = name
241 self.output = output
242 self.index = None
243
244 def __str__(self):
245 return '%s %s' % (self.type, self.name)
246
247
248class Function:
249
José Fonseca46a48392011-10-14 11:34:27 +0100250 # 0-3 are reserved to memcpy, malloc, free, and realloc
251 __id = 4
José Fonseca6fac5ae2010-11-29 16:09:13 +0000252
José Fonsecabca0f412011-04-24 20:53:38 +0100253 def __init__(self, type, name, args, call = '', fail = None, sideeffects=True):
José Fonseca6fac5ae2010-11-29 16:09:13 +0000254 self.id = Function.__id
255 Function.__id += 1
256
257 self.type = type
258 self.name = name
259
260 self.args = []
261 index = 0
262 for arg in args:
José Fonseca8384ccb2011-05-25 10:12:02 +0100263 if not isinstance(arg, Arg):
264 if isinstance(arg, tuple):
265 arg_type, arg_name = arg
266 else:
267 arg_type = arg
268 arg_name = "arg%u" % index
José Fonseca6fac5ae2010-11-29 16:09:13 +0000269 arg = Arg(arg_type, arg_name)
270 arg.index = index
271 index += 1
272 self.args.append(arg)
273
274 self.call = call
275 self.fail = fail
276 self.sideeffects = sideeffects
José Fonseca6fac5ae2010-11-29 16:09:13 +0000277
278 def prototype(self, name=None):
279 if name is not None:
280 name = name.strip()
281 else:
282 name = self.name
283 s = name
284 if self.call:
285 s = self.call + ' ' + s
286 if name.startswith('*'):
287 s = '(' + s + ')'
288 s = self.type.expr + ' ' + s
289 s += "("
290 if self.args:
291 s += ", ".join(["%s %s" % (arg.type, arg.name) for arg in self.args])
292 else:
293 s += "void"
294 s += ")"
295 return s
296
297
298def StdFunction(*args, **kwargs):
299 kwargs.setdefault('call', '__stdcall')
300 return Function(*args, **kwargs)
301
302
303def FunctionPointer(type, name, args, **kwargs):
304 # XXX: We should probably treat function pointers (callbacks or not) in a generic fashion
305 return Opaque(name)
306
307
308class Interface(Type):
309
310 def __init__(self, name, base=None):
311 Type.__init__(self, name)
312 self.name = name
313 self.base = base
314 self.methods = []
315
316 def visit(self, visitor, *args, **kwargs):
317 return visitor.visit_interface(self, *args, **kwargs)
318
319 def itermethods(self):
320 if self.base is not None:
321 for method in self.base.itermethods():
322 yield method
323 for method in self.methods:
324 yield method
325 raise StopIteration
326
327
328class Method(Function):
329
330 def __init__(self, type, name, args):
331 Function.__init__(self, type, name, args, call = '__stdcall')
332 for index in range(len(self.args)):
333 self.args[index].index = index + 1
334
335
José Fonseca6fac5ae2010-11-29 16:09:13 +0000336class String(Type):
337
338 def __init__(self, expr = "char *", length = None):
339 Type.__init__(self, expr)
340 self.length = length
341
342 def visit(self, visitor, *args, **kwargs):
343 return visitor.visit_string(self, *args, **kwargs)
344
345# C string (i.e., zero terminated)
346CString = String()
347
348
349class Opaque(Type):
350 '''Opaque pointer.'''
351
352 def __init__(self, expr):
353 Type.__init__(self, expr)
354
355 def visit(self, visitor, *args, **kwargs):
356 return visitor.visit_opaque(self, *args, **kwargs)
357
358
359def OpaquePointer(type, *args):
360 return Opaque(type.expr + ' *')
361
362def OpaqueArray(type, size):
363 return Opaque(type.expr + ' *')
364
365def OpaqueBlob(type, size):
366 return Opaque(type.expr + ' *')
José Fonseca8a56d142008-07-09 12:18:08 +0900367
José Fonseca501f2862010-11-19 20:41:18 +0000368
José Fonseca16d46dd2011-10-13 09:52:52 +0100369class Polymorphic(Type):
370
371 def __init__(self, default_type, switch_expr, switch_types):
372 Type.__init__(self, default_type.expr)
373 self.default_type = default_type
374 self.switch_expr = switch_expr
375 self.switch_types = switch_types
376
377 def visit(self, visitor, *args, **kwargs):
378 return visitor.visit_polymorphic(self, *args, **kwargs)
379
José Fonseca46161112011-10-14 10:04:55 +0100380 def iterswitch(self):
381 cases = [['default']]
382 types = [self.default_type]
383
384 for expr, type in self.switch_types:
385 case = 'case %s' % expr
386 try:
387 i = types.index(type)
388 except ValueError:
389 cases.append([case])
390 types.append(type)
391 else:
392 cases[i].append(case)
393
394 return zip(cases, types)
395
José Fonseca16d46dd2011-10-13 09:52:52 +0100396
José Fonseca501f2862010-11-19 20:41:18 +0000397class Visitor:
398
399 def visit(self, type, *args, **kwargs):
400 return type.visit(self, *args, **kwargs)
401
José Fonsecac356d6a2010-11-23 14:27:25 +0000402 def visit_void(self, void, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000403 raise NotImplementedError
404
José Fonsecac356d6a2010-11-23 14:27:25 +0000405 def visit_literal(self, literal, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000406 raise NotImplementedError
407
José Fonsecac356d6a2010-11-23 14:27:25 +0000408 def visit_string(self, string, *args, **kwargs):
José Fonseca2defc982010-11-22 16:59:10 +0000409 raise NotImplementedError
410
José Fonsecac356d6a2010-11-23 14:27:25 +0000411 def visit_const(self, const, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000412 raise NotImplementedError
413
José Fonsecac356d6a2010-11-23 14:27:25 +0000414 def visit_struct(self, struct, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000415 raise NotImplementedError
416
José Fonsecac356d6a2010-11-23 14:27:25 +0000417 def visit_array(self, array, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000418 raise NotImplementedError
419
José Fonsecac356d6a2010-11-23 14:27:25 +0000420 def visit_blob(self, blob, *args, **kwargs):
José Fonseca885f2652010-11-20 11:22:25 +0000421 raise NotImplementedError
422
José Fonsecac356d6a2010-11-23 14:27:25 +0000423 def visit_enum(self, enum, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000424 raise NotImplementedError
425
José Fonsecac356d6a2010-11-23 14:27:25 +0000426 def visit_bitmask(self, bitmask, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000427 raise NotImplementedError
428
José Fonsecac356d6a2010-11-23 14:27:25 +0000429 def visit_pointer(self, pointer, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000430 raise NotImplementedError
431
José Fonseca50d78d82010-11-23 22:13:14 +0000432 def visit_handle(self, handle, *args, **kwargs):
433 raise NotImplementedError
434
José Fonsecac356d6a2010-11-23 14:27:25 +0000435 def visit_alias(self, alias, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000436 raise NotImplementedError
437
José Fonsecac356d6a2010-11-23 14:27:25 +0000438 def visit_opaque(self, opaque, *args, **kwargs):
José Fonseca501f2862010-11-19 20:41:18 +0000439 raise NotImplementedError
440
José Fonsecac356d6a2010-11-23 14:27:25 +0000441 def visit_interface(self, interface, *args, **kwargs):
442 raise NotImplementedError
443
José Fonseca16d46dd2011-10-13 09:52:52 +0100444 def visit_polymorphic(self, polymorphic, *args, **kwargs):
445 raise NotImplementedError
446 #return self.visit(polymorphic.default_type, *args, **kwargs)
447
José Fonsecac356d6a2010-11-23 14:27:25 +0000448
449class OnceVisitor(Visitor):
450
451 def __init__(self):
452 self.__visited = set()
453
454 def visit(self, type, *args, **kwargs):
455 if type not in self.__visited:
456 self.__visited.add(type)
457 return type.visit(self, *args, **kwargs)
458 return None
459
José Fonseca501f2862010-11-19 20:41:18 +0000460
José Fonsecac9edb832010-11-20 09:03:10 +0000461class Rebuilder(Visitor):
462
463 def visit_void(self, void):
464 return void
465
466 def visit_literal(self, literal):
467 return literal
468
José Fonseca2defc982010-11-22 16:59:10 +0000469 def visit_string(self, string):
470 return string
471
José Fonsecac9edb832010-11-20 09:03:10 +0000472 def visit_const(self, const):
473 return Const(const.type)
474
475 def visit_struct(self, struct):
José Fonseca06aa2842011-05-05 07:55:54 +0100476 members = [(self.visit(type), name) for type, name in struct.members]
José Fonsecac9edb832010-11-20 09:03:10 +0000477 return Struct(struct.name, members)
478
479 def visit_array(self, array):
480 type = self.visit(array.type)
481 return Array(type, array.length)
482
José Fonseca885f2652010-11-20 11:22:25 +0000483 def visit_blob(self, blob):
484 type = self.visit(blob.type)
485 return Blob(type, blob.size)
486
José Fonsecac9edb832010-11-20 09:03:10 +0000487 def visit_enum(self, enum):
488 return enum
489
490 def visit_bitmask(self, bitmask):
491 type = self.visit(bitmask.type)
492 return Bitmask(type, bitmask.values)
493
494 def visit_pointer(self, pointer):
495 type = self.visit(pointer.type)
496 return Pointer(type)
497
José Fonseca50d78d82010-11-23 22:13:14 +0000498 def visit_handle(self, handle):
499 type = self.visit(handle.type)
José Fonseca8a844ae2010-12-06 18:50:52 +0000500 return Handle(handle.name, type, range=handle.range, key=handle.key)
José Fonseca50d78d82010-11-23 22:13:14 +0000501
José Fonsecac9edb832010-11-20 09:03:10 +0000502 def visit_alias(self, alias):
503 type = self.visit(alias.type)
504 return Alias(alias.expr, type)
505
506 def visit_opaque(self, opaque):
507 return opaque
508
José Fonseca16d46dd2011-10-13 09:52:52 +0100509 def visit_polymorphic(self, polymorphic):
510 default_type = self.visit(polymorphic.default_type)
511 switch_expr = polymorphic.switch_expr
512 switch_types = [(expr, self.visit(type)) for expr, type in polymorphic.switch_types]
513 return Polymorphic(default_type, switch_expr, switch_types)
514
José Fonsecac9edb832010-11-20 09:03:10 +0000515
José Fonsecae6a50bd2010-11-24 10:12:22 +0000516class Collector(Visitor):
517 '''Collect.'''
518
519 def __init__(self):
520 self.__visited = set()
521 self.types = []
522
523 def visit(self, type):
524 if type in self.__visited:
525 return
526 self.__visited.add(type)
527 Visitor.visit(self, type)
528 self.types.append(type)
529
530 def visit_void(self, literal):
531 pass
532
533 def visit_literal(self, literal):
534 pass
535
536 def visit_string(self, string):
537 pass
538
539 def visit_const(self, const):
540 self.visit(const.type)
541
542 def visit_struct(self, struct):
543 for type, name in struct.members:
544 self.visit(type)
545
546 def visit_array(self, array):
547 self.visit(array.type)
548
549 def visit_blob(self, array):
550 pass
551
552 def visit_enum(self, enum):
553 pass
554
555 def visit_bitmask(self, bitmask):
556 self.visit(bitmask.type)
557
558 def visit_pointer(self, pointer):
559 self.visit(pointer.type)
560
561 def visit_handle(self, handle):
562 self.visit(handle.type)
563
564 def visit_alias(self, alias):
565 self.visit(alias.type)
566
567 def visit_opaque(self, opaque):
568 pass
569
570 def visit_interface(self, interface):
José Fonseca87d1cc62010-11-29 15:57:25 +0000571 if interface.base is not None:
572 self.visit(interface.base)
573 for method in interface.itermethods():
574 for arg in method.args:
575 self.visit(arg.type)
576 self.visit(method.type)
José Fonsecae6a50bd2010-11-24 10:12:22 +0000577
José Fonseca16d46dd2011-10-13 09:52:52 +0100578 def visit_polymorphic(self, polymorphic):
579 self.visit(polymorphic.default_type)
580 for expr, type in polymorphic.switch_types:
581 self.visit(type)
582
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000583
584class API:
585
José Fonseca68ec4122011-02-20 11:25:25 +0000586 def __init__(self, name = None):
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000587 self.name = name
588 self.headers = []
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000589 self.functions = []
590 self.interfaces = []
591
José Fonsecae6a50bd2010-11-24 10:12:22 +0000592 def all_types(self):
593 collector = Collector()
594 for function in self.functions:
595 for arg in function.args:
596 collector.visit(arg.type)
597 collector.visit(function.type)
598 for interface in self.interfaces:
599 collector.visit(interface)
José Fonseca87d1cc62010-11-29 15:57:25 +0000600 for method in interface.itermethods():
José Fonsecae6a50bd2010-11-24 10:12:22 +0000601 for arg in method.args:
602 collector.visit(arg.type)
603 collector.visit(method.type)
604 return collector.types
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000605
606 def add_function(self, function):
607 self.functions.append(function)
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000608
609 def add_functions(self, functions):
610 for function in functions:
611 self.add_function(function)
612
613 def add_interface(self, interface):
614 self.interfaces.append(interface)
615
616 def add_interfaces(self, interfaces):
617 self.interfaces.extend(interfaces)
618
José Fonseca68ec4122011-02-20 11:25:25 +0000619 def add_api(self, api):
620 self.headers.extend(api.headers)
621 self.add_functions(api.functions)
622 self.add_interfaces(api.interfaces)
623
José Fonsecaeccec3e2011-02-20 09:01:25 +0000624 def get_function_by_name(self, name):
625 for function in self.functions:
626 if function.name == name:
627 return function
628 return None
629
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000630
José Fonseca51c1ef82010-11-15 16:09:14 +0000631Bool = Literal("bool", "Bool")
632SChar = Literal("signed char", "SInt")
633UChar = Literal("unsigned char", "UInt")
634Short = Literal("short", "SInt")
635Int = Literal("int", "SInt")
636Long = Literal("long", "SInt")
637LongLong = Literal("long long", "SInt")
638UShort = Literal("unsigned short", "UInt")
639UInt = Literal("unsigned int", "UInt")
640ULong = Literal("unsigned long", "UInt")
José Fonseca28f034f2010-11-22 20:31:25 +0000641ULongLong = Literal("unsigned long long", "UInt")
José Fonseca51c1ef82010-11-15 16:09:14 +0000642Float = Literal("float", "Float")
José Fonseca9ff74442011-05-07 01:17:49 +0100643Double = Literal("double", "Double")
José Fonseca51c1ef82010-11-15 16:09:14 +0000644SizeT = Literal("size_t", "UInt")
645WString = Literal("wchar_t *", "WString")
José Fonsecad626cf42008-07-07 07:43:16 +0900646
José Fonseca2250a0e2010-11-26 15:01:29 +0000647Int8 = Literal("int8_t", "SInt")
648UInt8 = Literal("uint8_t", "UInt")
649Int16 = Literal("int16_t", "SInt")
650UInt16 = Literal("uint16_t", "UInt")
651Int32 = Literal("int32_t", "SInt")
652UInt32 = Literal("uint32_t", "UInt")
653Int64 = Literal("int64_t", "SInt")
654UInt64 = Literal("uint64_t", "UInt")