2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008 Johan Dahlin
4 # Copyright (C) 2008, 2009 Red Hat, Inc.
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the
18 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
24 from .message import Position
25 from .odict import odict
26 from .utils import to_underscores
29 """A Type can be either:
30 * A reference to a node (target_giname)
31 * A reference to a "fundamental" type like 'utf8'
32 * A "foreign" type - this can be any string."
33 If none are specified, then it's in an "unresolved" state. An
34 unresolved type can have two data sources; a "ctype" which comes
35 from a C type string, or a gtype_name (from g_type_name()).
41 target_fundamental=None,
44 _target_unknown=False,
48 self.gtype_name = gtype_name
49 self.origin_symbol = origin_symbol
51 assert isinstance(self, TypeUnknown)
52 elif target_fundamental:
53 assert target_giname is None
54 assert target_foreign is None
56 assert '.' in target_giname
57 assert target_fundamental is None
58 assert target_foreign is None
60 assert ctype is not None
61 assert target_giname is None
62 assert target_fundamental is None
64 assert (ctype is not None) or (gtype_name is not None)
65 self.target_fundamental = target_fundamental
66 self.target_giname = target_giname
67 self.target_foreign = target_foreign
68 self.is_const = is_const
72 return (self.target_fundamental or
77 def unresolved_string(self):
81 return self.gtype_name
86 def create_from_gtype_name(cls, gtype_name):
87 """Parse a GType name (as from g_type_name()), and return a
88 Type instance. Note that this function performs namespace lookup,
89 in contrast to the other create_type() functions."""
90 # First, is it a fundamental?
91 fundamental = type_names.get(gtype_name)
92 if fundamental is not None:
93 return cls(target_fundamental=fundamental.target_fundamental)
94 if gtype_name == 'GHashTable':
95 return Map(TYPE_ANY, TYPE_ANY, gtype_name=gtype_name)
96 elif gtype_name in ('GArray', 'GPtrArray', 'GByteArray'):
97 return Array('GLib.' + gtype_name[1:], TYPE_ANY,
98 gtype_name=gtype_name)
99 elif gtype_name == 'GStrv':
100 bare_utf8 = TYPE_STRING.clone()
101 bare_utf8.ctype = None
102 return Array(None, bare_utf8, ctype=None, gtype_name=gtype_name,
105 # Workaround for Gdk.Rectangle being boxed alias for
106 # cairo.RectangleInt. G-I does not support boxing of aliases.
107 # See https://bugzilla.gnome.org/show_bug.cgi?id=655423
108 if gtype_name == 'GdkRectangle':
109 gtype_name = 'CairoRectangleInt'
111 return cls(gtype_name=gtype_name)
113 def get_giname(self):
114 assert self.target_giname is not None
115 return self.target_giname.split('.')[1]
117 def __cmp__(self, other):
118 if self.target_fundamental:
119 return cmp(self.target_fundamental, other.target_fundamental)
120 if self.target_giname:
121 return cmp(self.target_giname, other.target_giname)
122 if self.target_foreign:
123 return cmp(self.target_foreign, other.target_foreign)
124 return cmp(self.ctype, other.ctype)
126 def is_equiv(self, typeval):
127 """Return True if the specified types are compatible at
128 an introspection level, disregarding their C types.
129 A sequence may be given for typeval, in which case
130 this function returns True if the type is compatible with
132 if isinstance(typeval, (list, tuple)):
134 if self.is_equiv(val):
137 return self == typeval
140 return Type(target_fundamental=self.target_fundamental,
141 target_giname=self.target_giname,
142 target_foreign=self.target_foreign,
144 is_const=self.is_const)
147 if self.target_fundamental:
148 return self.target_fundamental
149 elif self.target_giname:
150 return self.target_giname
151 elif self.target_foreign:
152 return self.target_foreign
155 if self.target_fundamental:
156 data = 'target_fundamental=%s, ' % (self.target_fundamental, )
157 elif self.target_giname:
158 data = 'target_giname=%s, ' % (self.target_giname, )
159 elif self.target_foreign:
160 data = 'target_foreign=%s, ' % (self.target_foreign, )
163 return '%s(%sctype=%s)' % (self.__class__.__name__, data, self.ctype)
165 class TypeUnknown(Type):
167 Type.__init__(self, _target_unknown=True)
173 TYPE_NONE = Type(target_fundamental='none', ctype='void')
174 TYPE_ANY = Type(target_fundamental='gpointer', ctype='gpointer')
176 TYPE_BOOLEAN = Type(target_fundamental='gboolean', ctype='gboolean')
177 TYPE_INT8 = Type(target_fundamental='gint8', ctype='gint8')
178 TYPE_UINT8 = Type(target_fundamental='guint8', ctype='guint8')
179 TYPE_INT16 = Type(target_fundamental='gint16', ctype='gint16')
180 TYPE_UINT16 = Type(target_fundamental='guint16', ctype='guint16')
181 TYPE_INT32 = Type(target_fundamental='gint32', ctype='gint32')
182 TYPE_UINT32 = Type(target_fundamental='guint32', ctype='guint32')
183 TYPE_INT64 = Type(target_fundamental='gint64', ctype='gint64')
184 TYPE_UINT64 = Type(target_fundamental='guint64', ctype='guint64')
185 TYPE_CHAR = Type(target_fundamental='gchar', ctype='gchar')
186 TYPE_SHORT = Type(target_fundamental='gshort', ctype='gshort')
187 TYPE_USHORT = Type(target_fundamental='gushort', ctype='gushort')
188 TYPE_INT = Type(target_fundamental='gint', ctype='gint')
189 TYPE_UINT = Type(target_fundamental='guint', ctype='guint')
190 TYPE_LONG = Type(target_fundamental='glong', ctype='glong')
191 TYPE_ULONG = Type(target_fundamental='gulong', ctype='gulong')
192 TYPE_SIZE = Type(target_fundamental='gsize', ctype='gsize')
193 TYPE_SSIZE = Type(target_fundamental='gssize', ctype='gssize')
194 TYPE_INTPTR = Type(target_fundamental='gintptr', ctype='gintptr')
195 TYPE_UINTPTR = Type(target_fundamental='guintptr', ctype='guintptr')
197 TYPE_LONG_LONG = Type(target_fundamental='long long', ctype='long long')
198 TYPE_LONG_ULONG = Type(target_fundamental='unsigned long long',
199 ctype='unsigned long long')
200 TYPE_FLOAT = Type(target_fundamental='gfloat', ctype='gfloat')
201 TYPE_DOUBLE = Type(target_fundamental='gdouble', ctype='gdouble')
203 TYPE_LONG_DOUBLE = Type(target_fundamental='long double',
205 TYPE_UNICHAR = Type(target_fundamental='gunichar', ctype='gunichar')
207 # C types with semantics overlaid
208 TYPE_GTYPE = Type(target_fundamental='GType', ctype='GType')
209 TYPE_STRING = Type(target_fundamental='utf8', ctype='gchar*')
210 TYPE_FILENAME = Type(target_fundamental='filename', ctype='gchar*')
212 TYPE_VALIST = Type(target_fundamental='va_list', ctype='va_list')
214 BASIC_GIR_TYPES = [TYPE_BOOLEAN, TYPE_INT8, TYPE_UINT8, TYPE_INT16,
215 TYPE_UINT16, TYPE_INT32, TYPE_UINT32, TYPE_INT64,
216 TYPE_UINT64, TYPE_CHAR, TYPE_SHORT, TYPE_USHORT, TYPE_INT,
217 TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_SIZE, TYPE_SSIZE,
218 TYPE_LONG_LONG, TYPE_LONG_ULONG, TYPE_INTPTR, TYPE_UINTPTR,
219 TYPE_FLOAT, TYPE_DOUBLE,
220 TYPE_LONG_DOUBLE, TYPE_UNICHAR, TYPE_GTYPE]
221 GIR_TYPES = [TYPE_NONE, TYPE_ANY]
222 GIR_TYPES.extend(BASIC_GIR_TYPES)
223 GIR_TYPES.extend([TYPE_STRING, TYPE_FILENAME, TYPE_VALIST])
225 INTROSPECTABLE_BASIC = list(GIR_TYPES)
226 for v in [TYPE_NONE, TYPE_ANY,
227 TYPE_LONG_LONG, TYPE_LONG_ULONG,
228 TYPE_LONG_DOUBLE, TYPE_VALIST]:
229 INTROSPECTABLE_BASIC.remove(v)
232 for typeval in GIR_TYPES:
233 type_names[typeval.target_fundamental] = typeval
234 basic_type_names = {}
235 for typeval in BASIC_GIR_TYPES:
236 basic_type_names[typeval.target_fundamental] = typeval
239 type_names['char'] = TYPE_CHAR
240 type_names['signed char'] = TYPE_INT8
241 type_names['unsigned char'] = TYPE_UINT8
242 type_names['short'] = TYPE_SHORT
243 type_names['signed short'] = TYPE_SHORT
244 type_names['unsigned short'] = TYPE_USHORT
245 type_names['int'] = TYPE_INT
246 type_names['signed int'] = TYPE_INT
247 type_names['unsigned short int'] = TYPE_USHORT
248 type_names['signed'] = TYPE_INT
249 type_names['unsigned int'] = TYPE_UINT
250 type_names['unsigned'] = TYPE_UINT
251 type_names['long'] = TYPE_LONG
252 type_names['signed long'] = TYPE_LONG
253 type_names['unsigned long'] = TYPE_ULONG
254 type_names['unsigned long int'] = TYPE_ULONG
255 type_names['float'] = TYPE_FLOAT
256 type_names['double'] = TYPE_DOUBLE
257 type_names['char*'] = TYPE_STRING
258 type_names['void*'] = TYPE_ANY
259 type_names['void'] = TYPE_NONE
260 # Also alias the signed one here
261 type_names['signed long long'] = TYPE_LONG_LONG
263 # A few additional GLib type aliases
264 type_names['guchar'] = TYPE_UINT8
265 type_names['gchararray'] = TYPE_STRING
266 type_names['gchar*'] = TYPE_STRING
267 type_names['goffset'] = TYPE_INT64
268 type_names['gunichar2'] = TYPE_UINT16
269 type_names['gsize'] = TYPE_SIZE
270 type_names['gssize'] = TYPE_SSIZE
271 type_names['gintptr'] = TYPE_INTPTR
272 type_names['guintptr'] = TYPE_UINTPTR
273 type_names['gconstpointer'] = TYPE_ANY
275 # We used to support these; continue to do so
276 type_names['any'] = TYPE_ANY
277 type_names['boolean'] = TYPE_BOOLEAN
278 type_names['uint'] = TYPE_UINT
279 type_names['ulong'] = TYPE_ULONG
281 # C stdio, used in GLib public headers; squash this for now here
282 # until we move scanning into GLib and can (skip)
283 type_names['FILE*'] = TYPE_ANY
285 # One off C unix type definitions; note some of these may be GNU Libc
286 # specific. If someone is actually bitten by this, feel free to do
287 # the required configure goop to determine their size and replace
290 # We don't want to encourage people to use these in their APIs because
291 # they compromise the platform-independence that GLib gives you.
292 # These are here mostly to avoid blowing when random platform-specific
293 # methods are added under #ifdefs inside GLib itself. We could just (skip)
294 # the relevant methods, but on the other hand, since these types are just
295 # integers it's easy enough to expand them.
296 type_names['size_t'] = type_names['gsize']
297 type_names['time_t'] = TYPE_LONG
298 type_names['off_t'] = type_names['gsize']
299 type_names['pid_t'] = TYPE_INT
300 type_names['uid_t'] = TYPE_UINT
301 type_names['gid_t'] = TYPE_UINT
302 type_names['dev_t'] = TYPE_INT
303 type_names['socklen_t'] = TYPE_INT32
304 type_names['size_t'] = TYPE_ULONG
305 type_names['ssize_t'] = TYPE_LONG
308 type_names['id'] = TYPE_ANY
314 PARAM_DIRECTION_IN = 'in'
315 PARAM_DIRECTION_OUT = 'out'
316 PARAM_DIRECTION_INOUT = 'inout'
318 PARAM_SCOPE_CALL = 'call'
319 PARAM_SCOPE_ASYNC = 'async'
320 PARAM_SCOPE_NOTIFIED = 'notified'
322 PARAM_TRANSFER_NONE = 'none'
323 PARAM_TRANSFER_CONTAINER = 'container'
324 PARAM_TRANSFER_FULL = 'full'
326 class Namespace(object):
327 def __init__(self, name, version,
328 identifier_prefixes=None,
329 symbol_prefixes=None):
331 self.version = version
332 if identifier_prefixes is not None:
333 self.identifier_prefixes = identifier_prefixes
335 self.identifier_prefixes = [name]
336 if symbol_prefixes is not None:
337 self.symbol_prefixes = symbol_prefixes
339 ps = self.identifier_prefixes
340 self.symbol_prefixes = [to_underscores(p).lower() for p in ps]
341 # cache upper-cased versions
342 self._ucase_symbol_prefixes = [p.upper() for p in self.symbol_prefixes]
343 self._names = odict() # Maps from GIName -> node
344 self._aliases = {} # Maps from GIName -> GIName
345 self._type_names = {} # Maps from GTName -> node
346 self._ctypes = {} # Maps from CType -> node
347 self._symbols = {} # Maps from function symbols -> Function
358 def type_names(self):
359 return self._type_names
365 def type_from_name(self, name, ctype=None):
366 """Backwards compatibility method for older .gir files, which
367 only use the 'name' attribute. If name refers to a fundamental type,
368 create a Type object referncing it. If name is already a
369 fully-qualified GIName like 'Foo.Bar', returns a Type targeting it .
370 Otherwise a Type targeting name qualififed with the namespace name is
372 if name in type_names:
373 return Type(target_fundamental=name, ctype=ctype)
377 target = '%s.%s' % (self.name, name)
378 return Type(target_giname=target, ctype=ctype)
380 def append(self, node, replace=False):
381 previous = self._names.get(node.name)
382 if previous is not None:
384 raise ValueError("Namespace conflict: %r" % (node, ))
385 self.remove(previous)
386 # A layering violation...but oh well.
387 if isinstance(node, Alias):
388 self._aliases[node.name] = node
389 elif isinstance(node, Registered) and node.gtype_name is not None:
390 self._type_names[node.gtype_name] = node
391 elif isinstance(node, Function):
392 self._symbols[node.symbol] = node
393 assert isinstance(node, Node)
394 assert node.namespace is None
395 node.namespace = self
396 self._names[node.name] = node
397 if hasattr(node, 'ctype'):
398 self._ctypes[node.ctype] = node
399 if hasattr(node, 'symbol'):
400 self._ctypes[node.symbol] = node
402 def remove(self, node):
403 if isinstance(node, Alias):
404 del self._aliases[node.name]
405 elif isinstance(node, Registered) and node.gtype_name is not None:
406 del self._type_names[node.gtype_name]
407 del self._names[node.name]
408 node.namespace = None
409 if hasattr(node, 'ctype'):
410 del self._ctypes[node.ctype]
411 if isinstance(node, Function):
412 del self._symbols[node.symbol]
414 def float(self, node):
415 """Like remove(), but doesn't unset the node's namespace
416 back-reference, and it's still possible to look up
417 functions via get_by_symbol()."""
418 if isinstance(node, Function):
421 self._symbols[symbol] = node
422 node.namespace = self
425 return iter(self._names)
428 return self._names.iteritems()
430 def itervalues(self):
431 return self._names.itervalues()
434 return self._names.get(name)
436 def get_by_ctype(self, ctype):
437 return self._ctypes.get(ctype)
439 def get_by_symbol(self, symbol):
440 return self._symbols.get(symbol)
442 def walk(self, callback):
443 for node in self.itervalues():
444 node.walk(callback, [])
446 class Include(object):
448 def __init__(self, name, version):
450 self.version = version
453 def from_string(cls, string):
454 return cls(*string.split('-', 1))
456 def __cmp__(self, other):
457 namecmp = cmp(self.name, other.name)
460 return cmp(self.version, other.version)
463 return hash(str(self))
466 return '%s-%s' % (self.name, self.version)
468 class Annotated(object):
469 """An object which has a few generic metadata
474 self.introspectable = True
475 self.attributes = [] # (key, value)*
476 self.deprecated = None
477 self.deprecated_version = None
480 class Node(Annotated):
481 """A node is a type of object which is uniquely identified by its
482 (namespace, name) pair. When combined with a ., this is called a
483 GIName. It's possible for nodes to contain or point to other nodes."""
485 c_name = property(lambda self: self.namespace.name + self.name)
486 gi_name = property(lambda self: '%s.%s' % (self.namespace.name, self.name))
488 def __init__(self, name=None):
489 Annotated.__init__(self)
490 self.namespace = None # Should be set later by Namespace.append()
493 self.file_positions = set()
495 def create_type(self):
496 """Create a Type object referencing this node."""
497 assert self.namespace is not None
498 return Type(target_giname=('%s.%s' % (self.namespace.name, self.name)))
500 def __cmp__(self, other):
501 nscmp = cmp(self.namespace, other.namespace)
504 return cmp(self.name, other.name)
507 return '%s(%r)' % (self.__class__.__name__, self.name)
509 def inherit_file_positions(self, node):
510 self.file_positions.update(node.file_positions)
512 def add_file_position(self, position):
513 self.file_positions.add(position)
515 def add_symbol_reference(self, symbol):
516 if symbol.source_filename:
517 self.add_file_position(Position(symbol.source_filename, symbol.line))
519 def walk(self, callback, chain):
520 res = callback(self, chain)
521 assert res in (True, False), "Walk function must return boolean, not %r" % (res, )
525 self._walk(callback, chain)
528 def _walk(self, callback, chain):
533 """A node that (possibly) has gtype_name and get_type."""
534 def __init__(self, gtype_name, get_type):
535 assert (gtype_name is None and get_type is None) or \
536 (gtype_name is not None and get_type is not None)
537 self.gtype_name = gtype_name
538 self.get_type = get_type
541 class Callable(Node):
543 def __init__(self, name, retval, parameters, throws):
544 Node.__init__(self, name)
546 self.parameters = parameters
547 self.throws = not not throws
548 self.instance_parameter = None # Parameter
550 def get_parameter_index(self, name):
551 for i, parameter in enumerate(self.parameters):
552 if parameter.argname == name:
554 raise ValueError("Unknown argument %s" % (name, ))
556 def get_parameter(self, name):
557 for parameter in self.parameters:
558 if parameter.argname == name:
560 raise ValueError("Unknown argument %s" % (name, ))
563 class Function(Callable):
565 def __init__(self, name, retval, parameters, throws, symbol):
566 Callable.__init__(self, name, retval, parameters, throws)
568 self.is_method = False
569 self.is_constructor = False
570 self.shadowed_by = None # C symbol string
571 self.shadows = None # C symbol string
574 clone = copy.copy(self)
575 # copy the parameters array so a change to self.parameters does not
576 # influence clone.parameters.
577 clone.parameters = self.parameters[:]
581 class ErrorQuarkFunction(Function):
583 def __init__(self, name, retval, parameters, throws, symbol, error_domain):
584 Function.__init__(self, name, retval, parameters, throws, symbol)
585 self.error_domain = error_domain
588 class VFunction(Callable):
590 def __init__(self, name, retval, parameters, throws):
591 Callable.__init__(self, name, retval, parameters, throws)
595 def from_callback(cls, cb):
596 obj = cls(cb.name, cb.retval, cb.parameters[1:],
605 Type.__init__(self, '<varargs>', target_fundamental='<varargs>')
610 GLIB_ARRAY = 'GLib.Array'
611 GLIB_BYTEARRAY = 'GLib.ByteArray'
612 GLIB_PTRARRAY = 'GLib.PtrArray'
614 def __init__(self, array_type, element_type, **kwargs):
615 Type.__init__(self, target_fundamental='<array>',
617 if (array_type is None or array_type == self.C):
618 self.array_type = self.C
620 assert array_type in (self.GLIB_ARRAY,
622 self.GLIB_PTRARRAY), array_type
623 self.array_type = array_type
624 assert isinstance(element_type, Type)
625 self.element_type = element_type
626 self.zeroterminated = True
627 self.length_param_name = None
631 arr = Array(self.array_type, self.element_type)
632 arr.zeroterminated = self.zeroterminated
633 arr.length_param_name = self.length_param_name
639 def __init__(self, name, element_type, **kwargs):
640 Type.__init__(self, target_fundamental='<list>',
643 assert isinstance(element_type, Type)
644 self.element_type = element_type
647 l = List(self.name, self.element_type)
648 l.zeroterminated = self.zeroterminated
649 l.length_param_name = self.length_param_name
655 def __init__(self, key_type, value_type, **kwargs):
656 Type.__init__(self, target_fundamental='<map>', **kwargs)
657 assert isinstance(key_type, Type)
658 self.key_type = key_type
659 assert isinstance(value_type, Type)
660 self.value_type = value_type
663 return Map(self.key_type, self.value_type)
667 def __init__(self, name, target, ctype=None):
668 Node.__init__(self, name)
673 class TypeContainer(Annotated):
674 """A fundamental base class for Return and Parameter."""
676 def __init__(self, typenode, transfer):
677 Annotated.__init__(self)
679 if transfer is not None:
680 self.transfer = transfer
681 elif typenode.is_const:
682 self.transfer = PARAM_TRANSFER_NONE
687 class Parameter(TypeContainer):
688 """An argument to a function."""
690 def __init__(self, argname, typenode, direction=None,
691 transfer=None, allow_none=False, scope=None,
692 caller_allocates=False):
693 TypeContainer.__init__(self, typenode, transfer)
694 self.argname = argname
695 self.direction = direction
696 self.allow_none = allow_none
698 self.caller_allocates = caller_allocates
699 self.closure_name = None
700 self.destroy_name = None
703 class Return(TypeContainer):
704 """A return value from a function."""
706 def __init__(self, rtype, transfer=None):
707 TypeContainer.__init__(self, rtype, transfer)
708 self.direction = PARAM_DIRECTION_OUT
711 class Enum(Node, Registered):
713 def __init__(self, name, ctype,
716 c_symbol_prefix=None,
718 Node.__init__(self, name)
719 Registered.__init__(self, gtype_name, get_type)
720 self.c_symbol_prefix = c_symbol_prefix
722 self.members = members
723 # Associated error domain name
724 self.error_domain = None
727 class Bitfield(Node, Registered):
729 def __init__(self, name, ctype,
731 c_symbol_prefix=None,
734 Node.__init__(self, name)
735 Registered.__init__(self, gtype_name, get_type)
737 self.c_symbol_prefix = c_symbol_prefix
738 self.members = members
741 class Member(Annotated):
743 def __init__(self, name, value, symbol, nick):
744 Annotated.__init__(self)
750 def __cmp__(self, other):
751 return cmp(self.name, other.name)
755 class Compound(Node, Registered):
756 def __init__(self, name,
760 c_symbol_prefix=None,
762 Node.__init__(self, name)
763 Registered.__init__(self, gtype_name, get_type)
766 self.static_methods = []
768 self.constructors = []
769 self.disguised = disguised
770 self.gtype_name = gtype_name
771 self.get_type = get_type
772 self.c_symbol_prefix = c_symbol_prefix
774 def add_gtype(self, gtype_name, get_type):
775 self.gtype_name = gtype_name
776 self.get_type = get_type
778 def _walk(self, callback, chain):
779 for ctor in self.constructors:
780 ctor.walk(callback, chain)
781 for func in self.methods:
782 func.walk(callback, chain)
783 for func in self.static_methods:
784 func.walk(callback, chain)
785 for field in self.fields:
786 if field.anonymous_node is not None:
787 field.anonymous_node.walk(callback, chain)
789 class Field(Annotated):
791 def __init__(self, name, typenode, readable, writable, bits=None,
792 anonymous_node=None):
793 Annotated.__init__(self)
794 assert (typenode or anonymous_node)
797 self.readable = readable
798 self.writable = writable
800 self.anonymous_node = anonymous_node
803 def __cmp__(self, other):
804 return cmp(self.name, other.name)
807 class Record(Compound):
809 def __init__(self, name,
813 c_symbol_prefix=None,
815 Compound.__init__(self, name,
817 gtype_name=gtype_name,
819 c_symbol_prefix=c_symbol_prefix,
821 # If non-None, this record defines the FooClass C structure
822 # for some Foo GObject (or similar for GInterface)
823 self.is_gtype_struct_for = None
826 class Union(Compound):
828 def __init__(self, name,
832 c_symbol_prefix=None,
834 Compound.__init__(self, name,
836 gtype_name=gtype_name,
838 c_symbol_prefix=c_symbol_prefix,
842 class Boxed(Node, Registered):
843 """A boxed type with no known associated structure/union."""
844 def __init__(self, name,
847 c_symbol_prefix=None):
848 assert gtype_name is not None
849 assert get_type is not None
850 Node.__init__(self, name)
851 Registered.__init__(self, gtype_name, get_type)
852 if get_type is not None:
853 assert c_symbol_prefix is not None
854 self.c_symbol_prefix = c_symbol_prefix
855 self.constructors = []
857 self.static_methods = []
859 def _walk(self, callback, chain):
860 for ctor in self.constructors:
861 ctor.walk(callback, chain)
862 for meth in self.methods:
863 meth.walk(callback, chain)
864 for meth in self.static_methods:
865 meth.walk(callback, chain)
868 class Signal(Callable):
870 def __init__(self, name, retval, parameters):
871 Callable.__init__(self, name, retval, parameters, False)
874 class Class(Node, Registered):
876 def __init__(self, name, parent,
880 c_symbol_prefix=None,
882 Node.__init__(self, name)
883 Registered.__init__(self, gtype_name, get_type)
885 self.c_symbol_prefix = c_symbol_prefix
887 self.fundamental = False
888 self.unref_func = None
890 self.set_value_func = None
891 self.get_value_func = None
892 # When we're in the scanner, we keep around a list
893 # of parents so that we can transparently fall back
894 # if there are 'hidden' parents
895 self.parent_chain = []
896 self.glib_type_struct = None
897 self.is_abstract = is_abstract
899 self.virtual_methods = []
900 self.static_methods = []
902 self.constructors = []
907 def _walk(self, callback, chain):
908 for meth in self.methods:
909 meth.walk(callback, chain)
910 for meth in self.virtual_methods:
911 meth.walk(callback, chain)
912 for meth in self.static_methods:
913 meth.walk(callback, chain)
914 for ctor in self.constructors:
915 ctor.walk(callback, chain)
916 for field in self.fields:
917 if field.anonymous_node:
918 field.anonymous_node.walk(callback, chain)
919 for sig in self.signals:
920 sig.walk(callback, chain)
923 class Interface(Node, Registered):
925 def __init__(self, name, parent,
929 c_symbol_prefix=None):
930 Node.__init__(self, name)
931 Registered.__init__(self, gtype_name, get_type)
933 self.c_symbol_prefix = c_symbol_prefix
935 self.parent_chain = []
938 self.static_methods = []
939 self.virtual_methods = []
940 self.glib_type_struct = None
943 self.prerequisites = []
945 def _walk(self, callback, chain):
946 for meth in self.methods:
947 meth.walk(callback, chain)
948 for meth in self.static_methods:
949 meth.walk(callback, chain)
950 for meth in self.virtual_methods:
951 meth.walk(callback, chain)
952 for field in self.fields:
953 if field.anonymous_node:
954 field.anonymous_node.walk(callback, chain)
955 for sig in self.signals:
956 sig.walk(callback, chain)
959 class Constant(Node):
961 def __init__(self, name, value_type, value):
962 Node.__init__(self, name)
963 self.value_type = value_type
967 class Property(Node):
969 def __init__(self, name, typeobj, readable, writable,
970 construct, construct_only, transfer=None):
971 Node.__init__(self, name)
973 self.readable = readable
974 self.writable = writable
975 self.construct = construct
976 self.construct_only = construct_only
978 self.transfer = PARAM_TRANSFER_NONE
980 self.transfer = transfer
983 class Callback(Callable):
985 def __init__(self, name, retval, parameters, throws, ctype=None):
986 Callable.__init__(self, name, retval, parameters, throws)