From e3e84400529899854fe06f7d110685f50be26a18 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 4 Feb 2009 00:48:24 +0000 Subject: Bug 555960 - Nested structs and unions (generation portion) Patch from Andreas Rottmann . * tests/scanner/utility.h (UtilityTaggedValue): Make the union member anonymous. (UtilityByte): New union typedef with an unnamed struct in it. * giscanner/transformer.py (Transformer._create_struct): Create unnamed structs for symbols with a None ident. (Transformer._create_union): Likewise. * giscanner/girwriter.py (GIRWriter._write_record): Allow name being None. (GIRWriter._write_union): Likewise. * girepository/girparser.c (start_struct): Allow a NULL name for non-toplevel structs. (start_union): Likewise. * tests/scanner/utility.h (UtilityTaggedValue): New struct typedef, which has a nested union member. * tests/scanner/utility-expected.gir: Adapted. * giscanner/transformer.py (Transformer._create_member): Create struct/union members if appropriate. (Transformer._create_struct, Transformer._create_union): Allow for structs/unions without a C type. * giscanner/glibtransformer.py (GLibTransformer._resolve_field): We don't need to resolve non-typef'd (GLibTransformer._resolve_field): Add cases for non-typedef'd struct/union "fields". * giscanner/girwriter.py (GIRWriter._write_record): Allow for records without a C type. (GIRWriter._write_field): structs and unions may appear in places where fields do. svn path=/trunk/; revision=1082 --- giscanner/girwriter.py | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'giscanner/girwriter.py') diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py index 51a208d7..cd19e989 100644 --- a/giscanner/girwriter.py +++ b/giscanner/girwriter.py @@ -366,8 +366,11 @@ and/or use gtk-doc annotations. ''') ('glib:get-type', boxed.get_type)] def _write_record(self, record): - attrs = [('name', record.name), - ('c:type', record.symbol)] + attrs = [] + if record.name is not None: + attrs.append(('name', record.name)) + if record.symbol is not None: # the record might be anonymous + attrs.append(('c:type', record.symbol)) if record.disguised: attrs.append(('disguised', '1')) if record.doc: @@ -386,8 +389,11 @@ and/or use gtk-doc annotations. ''') self._write_method(method) def _write_union(self, union): - attrs = [('name', union.name), - ('c:type', union.symbol)] + attrs = [] + if union.name is not None: + attrs.append(('name', union.name)) + if union.symbol is not None: # the union might be anonymous + attrs.append(('c:type', union.symbol)) if union.doc: attrs.append(('doc', union.doc)) self._append_version(union, attrs) @@ -410,19 +416,22 @@ and/or use gtk-doc annotations. ''') if isinstance(field, Callback): self._write_callback(field) - return - - attrs = [('name', field.name)] - # Fields are assumed to be read-only - # (see also girparser.c and generate.c) - if not field.readable: - attrs.append(('readable', '0')) - if field.writable: - attrs.append(('writable', '1')) - if field.bits: - attrs.append(('bits', str(field.bits))) - with self.tagcontext('field', attrs): - self._write_type(field.type) + elif isinstance(field, Struct): + self._write_record(field) + elif isinstance(field, Union): + self._write_union(field) + else: + attrs = [('name', field.name)] + # Fields are assumed to be read-only + # (see also girparser.c and generate.c) + if not field.readable: + attrs.append(('readable', '0')) + if field.writable: + attrs.append(('writable', '1')) + if field.bits: + attrs.append(('bits', str(field.bits))) + with self.tagcontext('field', attrs): + self._write_type(field.type) def _write_signal(self, signal): attrs = [('name', signal.name)] -- cgit v1.2.1