~ubuntu-branches/ubuntu/oneiric/gobject-introspection/oneiric

« back to all changes in this revision

Viewing changes to giscanner/gdumpparser.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-07-07 11:49:03 UTC
  • mfrom: (1.7.3 upstream) (3.3.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110707114903-dmigibkeg25eva3u
Tags: 1.29.0-0ubuntu1
* New upstream release.
* debian/control.in: Bump glib build dependency according to new upstream
  configure.ac.
* debian/libgirepository-1.0-1.symbols: Add new symbols from this release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
            if isinstance(node, ast.Function):
87
87
                self._initparse_function(node)
88
88
 
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)
135
135
 
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
143
 
 
144
136
    # Helper functions
145
137
 
146
138
    def _execute_binary_get_tree(self):
172
164
                shutil.rmtree(self._binary.tmpdir)
173
165
 
174
166
    def _create_gobject(self, node):
175
 
        type_name = 'G' + node.name
176
 
        if type_name == 'GObject':
177
 
            parent_gitype = None
178
 
            symbol = 'intern'
179
 
        elif type_name == 'GInitiallyUnowned':
 
167
        symbol = 'intern'
 
168
        parent_gitype = None
 
169
        if node.name == 'ParamSpec':
 
170
            type_name = 'GParam'
 
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'
182
183
        else:
183
184
            assert False
 
185
 
184
186
        gnode = ast.Class(node.name, parent_gitype,
185
187
                          gtype_name=type_name,
186
188
                          get_type=symbol,
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
 
        else:
 
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
 
200
        else:
 
201
            gnode.fields.extend(node.fields)
200
202
        self._namespace.append(gnode, replace=True)
201
203
 
202
204
    # Parser
205
207
        symbol = func.symbol
206
208
        if symbol.startswith('_'):
207
209
            return
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)
210
212
 
211
213
    def _initparse_get_type_function(self, func):
212
 
        if self._namespace.name == 'GLib':
213
 
            # No GObjects in GLib
214
 
            return False
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
218
218
            return True
219
219
        if func.parameters:
220
220
            return False
230
230
        return True
231
231
 
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',
 
239
                                                      get_type='intern',
 
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:
312
317
  %r
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'
 
322
        else:
 
323
            type_suffix = '_get_gtype'
 
324
        return (get_type, name[:-len(type_suffix)])
317
325
 
318
326
    def _introspect_object(self, xmlnode):
319
327
        type_name = xmlnode.attrib['name']
452
460
        node.parent_chain = parent_types
453
461
 
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
458
 
        # are ignored
459
 
        if not xmlnode.attrib.get('instantiatable', False):
460
 
            return
 
463
        type_name = xmlnode.attrib['name']
461
464
 
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)
465
467
        try: