86
86
if isinstance(node, ast.Function):
87
87
self._initparse_function(node)
89
if self._namespace.name == 'GObject':
89
if self._namespace.name == 'GObject' or self._namespace.name == 'GLib':
90
90
for node in self._namespace.itervalues():
91
91
if isinstance(node, ast.Record):
92
92
self._initparse_gobject_record(node)
133
133
for node in to_remove:
134
134
self._namespace.remove(node)
136
if self._namespace.name == 'GLib':
137
variant = self._namespace.get('Variant')
138
assert variant is not None
139
variant.add_gtype('GVariant', 'g_variant_get_gtype')
140
variant.c_symbol_prefix = 'variant'
141
# Work around scanner bug
142
variant.disguised = False
144
136
# Helper functions
146
138
def _execute_binary_get_tree(self):
172
164
shutil.rmtree(self._binary.tmpdir)
174
166
def _create_gobject(self, node):
175
type_name = 'G' + node.name
176
if type_name == 'GObject':
179
elif type_name == 'GInitiallyUnowned':
169
if node.name == 'ParamSpec':
171
# Some function use g_param_value instead
172
c_symbol_prefix = 'param_spec'
173
elif node.name == 'Object':
174
type_name = 'GObject'
175
c_symbol_prefix = 'object'
176
elif node.name == 'InitiallyUnowned':
177
type_name = 'GInitiallyUnowned'
178
symbol = 'g_initially_unowned_get_type'
180
179
parent_gitype = ast.Type(target_giname='GObject.Object')
181
symbol = 'g_initially_unowned_get_type'
180
# Not really used, but otherwise InitallyUnowned
181
# gets the static methods that should be in Object
182
c_symbol_prefix = 'initially_unowned'
184
186
gnode = ast.Class(node.name, parent_gitype,
185
187
gtype_name=type_name,
187
c_symbol_prefix='object',
189
c_symbol_prefix=c_symbol_prefix,
188
190
is_abstract=True)
189
if type_name == 'GObject':
190
gnode.fields.extend(node.fields)
191
if node.name == 'InitiallyUnowned':
192
192
# http://bugzilla.gnome.org/show_bug.cgi?id=569408
193
193
# GInitiallyUnowned is actually a typedef for GObject, but
194
194
# that's not reflected in the GIR, where it appears as a
197
197
# GInitiallyUnowned so that struct offset computation
198
198
# works correctly.
199
199
gnode.fields = self._namespace.get('Object').fields
201
gnode.fields.extend(node.fields)
200
202
self._namespace.append(gnode, replace=True)
205
207
symbol = func.symbol
206
208
if symbol.startswith('_'):
208
elif symbol.endswith('_get_type'):
210
elif (symbol.endswith('_get_type') or symbol.endswith('_get_gtype')):
209
211
self._initparse_get_type_function(func)
211
213
def _initparse_get_type_function(self, func):
212
if self._namespace.name == 'GLib':
213
# No GObjects in GLib
215
if (self._namespace.name == 'GObject' and
216
func.symbol in ('g_object_get_type', 'g_initially_unowned_get_type')):
217
# We handle these internally, see _create_gobject
214
if func.symbol in ('g_object_get_type',
215
'g_initially_unowned_get_type',
216
'g_variant_get_gtype'):
217
# We handle these internally, see _initparse_gobject_record
219
219
if func.parameters:
232
232
def _initparse_gobject_record(self, record):
233
# Special handling for when we're parsing GObject
234
if record.name in ("Object", 'InitiallyUnowned'):
233
# Special handling for when we're parsing GObject / GLib
234
if record.name in ('Object', 'InitiallyUnowned', 'ParamSpec'):
235
235
self._create_gobject(record)
236
elif record.name == 'Variant':
237
self._boxed_types['GVariant'] = ast.Boxed('Variant',
238
gtype_name='GVariant',
240
c_symbol_prefix='variant')
236
241
elif record.name == 'InitiallyUnownedClass':
237
242
record.fields = self._namespace.get('ObjectClass').fields
238
243
record.disguised = False
306
311
get_type = xmlnode.attrib['get-type']
307
312
(ns, name) = self._transformer.split_csymbol(get_type)
308
313
assert ns is self._namespace
309
if name == 'get_type':
314
if name in ('get_type', '_get_gtype'):
310
315
message.fatal("""The GObject name %r isn't compatibile
311
316
with the configured identifier prefixes:
313
318
The class would have no name. Most likely you want to specify a
314
319
different --identifier-prefix.""" % (xmlnode.attrib['name'], self._namespace.identifier_prefixes))
315
assert name.endswith('_get_type')
316
return (get_type, name[:-len('_get_type')])
320
if name.endswith('_get_type'):
321
type_suffix = '_get_type'
323
type_suffix = '_get_gtype'
324
return (get_type, name[:-len(type_suffix)])
318
326
def _introspect_object(self, xmlnode):
319
327
type_name = xmlnode.attrib['name']
452
460
node.parent_chain = parent_types
454
462
def _introspect_fundamental(self, xmlnode):
455
# We only care about types that can be instantiatable, other
456
# fundamental types such as the Clutter.Fixed/CoglFixed registers
457
# are not yet interesting from an introspection perspective and
459
if not xmlnode.attrib.get('instantiatable', False):
463
type_name = xmlnode.attrib['name']
462
type_name = xmlnode.attrib['name']
463
465
is_abstract = bool(xmlnode.attrib.get('abstract', False))
464
466
(get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)