From b8e3172424ba956a0d18eae8deb305310b2cab74 Mon Sep 17 00:00:00 2001 From: Andreas Rottmann Date: Wed, 04 Mar 2009 14:59:28 +0000 Subject: Bug 573332 - Allow annotation of enums as bitfields Add support for a `(type bitfield)' annotation for enums. Signed-off-by: Andreas Rottmann --- diff --git a/gir/glib-2.0.c b/gir/glib-2.0.c index ec98c4d..0fb1c68 100644 --- a/gir/glib-2.0.c +++ b/gir/glib-2.0.c @@ -19,4 +19,6 @@ * @context: (allow-none): */ - +/** + * GIOCondition: (type bitfield) + **/ diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index b831f93..35300b0 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -59,6 +59,9 @@ OPT_SCOPE = 'scope' OPT_TRANSFER = 'transfer' OPT_TYPE = 'type' +# Specific option values +OPT_VAL_BITFIELD = 'bitfield' + # Array options - array specific annotations OPT_ARRAY_FIXED_SIZE = 'fixed-size' OPT_ARRAY_LENGTH = 'length' @@ -344,6 +347,10 @@ class AnnotationApplier(object): self._parse_node_common(enum, block) if block: enum.doc = block.comment + type_opt = block.options.get(OPT_TYPE) + if type_opt and type_opt.one() == OPT_VAL_BITFIELD: + # This is hack, but hey, it works :-) + enum.__class__ = Bitfield def _parse_bitfield(self, bitfield): block = self._blocks.get(bitfield.symbol) diff --git a/tests/scanner/utility-1.0-expected.gir b/tests/scanner/utility-1.0-expected.gir index 7ff6ca5..0ca72cb 100644 --- a/tests/scanner/utility-1.0-expected.gir +++ b/tests/scanner/utility-1.0-expected.gir @@ -42,11 +42,11 @@ and/or use gtk-doc annotations. --> - - - - - + + + + + - - - - - + + + + + diff --git a/tests/scanner/utility.c b/tests/scanner/utility.c index 756de17..a54afad 100644 --- a/tests/scanner/utility.c +++ b/tests/scanner/utility.c @@ -2,6 +2,10 @@ G_DEFINE_TYPE (UtilityObject, utility_object, G_TYPE_OBJECT); +/** + * UtilityFlagType: (type bitfield) + **/ + static void utility_object_class_init (UtilityObjectClass *klass) { diff --git a/tests/scanner/utility.h b/tests/scanner/utility.h index b493a67..cad93ff 100644 --- a/tests/scanner/utility.h +++ b/tests/scanner/utility.h @@ -62,9 +62,9 @@ typedef enum typedef enum { - UTILITY_FLAG_A, - UTILITY_FLAG_B, - UTILITY_FLAG_C + UTILITY_FLAG_A = 1, + UTILITY_FLAG_B = 2, + UTILITY_FLAG_C = 4 } UtilityFlagType; typedef struct -- cgit v0.9.1