[gobject-introspection] giscanner: rename "options" to "annotations"



commit 680ec99d696db06a02aab24e07c4457a1d031250
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date:   Wed May 15 12:31:28 2013 +0200

    giscanner: rename "options" to "annotations"
    
    Makes it easier to understand the difference between
    an annotation and an option, which are written as
    "(annotation option1=value1 option2=value2 ...)" in
    GTK-Doc comment blocks.

 giscanner/annotationparser.py                 |  284 ++++++++++++-------------
 giscanner/maintransformer.py                  |  110 +++++-----
 tests/scanner/annotationparser/test_parser.py |   12 +-
 tests/warn/invalid-option.h                   |    2 +-
 4 files changed, 202 insertions(+), 206 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index e5d1ef3..5ce7da7 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -157,45 +157,45 @@ _ALL_TAGS = [TAG_VFUNC,
              TAG_TRANSFER,
              TAG_VALUE]
 
-# Options - annotations for parameters and return values
-OPT_ALLOW_NONE = 'allow-none'
-OPT_ARRAY = 'array'
-OPT_ATTRIBUTE = 'attribute'
-OPT_CLOSURE = 'closure'
-OPT_DESTROY = 'destroy'
-OPT_ELEMENT_TYPE = 'element-type'
-OPT_FOREIGN = 'foreign'
-OPT_IN = 'in'
-OPT_INOUT = 'inout'
-OPT_INOUT_ALT = 'in-out'
-OPT_OUT = 'out'
-OPT_SCOPE = 'scope'
-OPT_TRANSFER = 'transfer'
-OPT_TYPE = 'type'
-OPT_SKIP = 'skip'
-OPT_CONSTRUCTOR = 'constructor'
-OPT_METHOD = 'method'
-
-ALL_OPTIONS = [
-    OPT_ALLOW_NONE,
-    OPT_ARRAY,
-    OPT_ATTRIBUTE,
-    OPT_CLOSURE,
-    OPT_DESTROY,
-    OPT_ELEMENT_TYPE,
-    OPT_FOREIGN,
-    OPT_IN,
-    OPT_INOUT,
-    OPT_INOUT_ALT,
-    OPT_OUT,
-    OPT_SCOPE,
-    OPT_TRANSFER,
-    OPT_TYPE,
-    OPT_SKIP,
-    OPT_CONSTRUCTOR,
-    OPT_METHOD]
-
-# Array options - array specific annotations
+# Annotations - applied to parameters and return values
+ANN_ALLOW_NONE = 'allow-none'
+ANN_ARRAY = 'array'
+ANN_ATTRIBUTE = 'attribute'
+ANN_CLOSURE = 'closure'
+ANN_DESTROY = 'destroy'
+ANN_ELEMENT_TYPE = 'element-type'
+ANN_FOREIGN = 'foreign'
+ANN_IN = 'in'
+ANN_INOUT = 'inout'
+ANN_INOUT_ALT = 'in-out'
+ANN_OUT = 'out'
+ANN_SCOPE = 'scope'
+ANN_TRANSFER = 'transfer'
+ANN_TYPE = 'type'
+ANN_SKIP = 'skip'
+ANN_CONSTRUCTOR = 'constructor'
+ANN_METHOD = 'method'
+
+ALL_ANNOTATIONS = [
+    ANN_ALLOW_NONE,
+    ANN_ARRAY,
+    ANN_ATTRIBUTE,
+    ANN_CLOSURE,
+    ANN_DESTROY,
+    ANN_ELEMENT_TYPE,
+    ANN_FOREIGN,
+    ANN_IN,
+    ANN_INOUT,
+    ANN_INOUT_ALT,
+    ANN_OUT,
+    ANN_SCOPE,
+    ANN_TRANSFER,
+    ANN_TYPE,
+    ANN_SKIP,
+    ANN_CONSTRUCTOR,
+    ANN_METHOD]
+
+# Array options - array specific annotation options
 OPT_ARRAY_FIXED_SIZE = 'fixed-size'
 OPT_ARRAY_LENGTH = 'length'
 OPT_ARRAY_ZERO_TERMINATED = 'zero-terminated'
@@ -455,7 +455,7 @@ class DocBlock(object):
 
     def __init__(self, name):
         self.name = name
-        self.options = DocOptions()
+        self.annotations = DocAnnotations()
         self.value = None
         self.tags = OrderedDict()
         self.comment = None
@@ -469,17 +469,17 @@ class DocBlock(object):
         return cmp(self.name, other.name)
 
     def __repr__(self):
-        return '<DocBlock %r %r>' % (self.name, self.options)
+        return '<DocBlock %r %r>' % (self.name, self.annotations)
 
     def to_gtk_doc(self):
-        options = ''
-        if self.options:
-            options += ' '
-            options += ' '.join('(%s)' % o for o in self.options)
+        annotations = ''
+        if self.annotations:
+            annotations += ' '
+            annotations += ' '.join('(%s)' % o for o in self.annotations)
         lines = [self.name]
         if 'SECTION' not in self.name:
             lines[0] += ':'
-        lines[0] += options
+        lines[0] += annotations
         for param in self.params.values():
             lines.append(param.to_gtk_doc_param())
         if self.comment:
@@ -515,19 +515,18 @@ class DocTag(object):
     def __init__(self, block, name):
         self.block = block
         self.name = name
-        self.options = DocOptions()
+        self.annotations = DocAnnotations()
         self.comment = None
         self.value = ''
         self.position = None
 
     def __repr__(self):
-        return '<DocTag %r %r>' % (self.name, self.options)
+        return '<DocTag %r %r>' % (self.name, self.annotations)
 
-    def _validate_option(self, name, value, required=False,
-                         n_params=None, choices=None):
-        if required and value is None:
-            message.warn('%s annotation needs a value' % (
-                name, ), self.position)
+    def _validate_annotation(self, ann_name, options, required=False,
+                             n_params=None, choices=None):
+        if required and options is None:
+            message.warn('%s annotation needs a value' % (ann_name, ), self.position)
             return
 
         if n_params is not None:
@@ -537,74 +536,74 @@ class DocTag(object):
                 s = 'one value'
             else:
                 s = '%d values' % (n_params, )
-            if ((n_params > 0 and (value is None or value.length() != n_params))
-            or n_params == 0 and value is not None):
-                if value is None:
+            if ((n_params > 0 and (options is None or options.length() != n_params))
+            or n_params == 0 and options is not None):
+                if options is None:
                     length = 0
                 else:
-                    length = value.length()
-                message.warn('%s annotation needs %s, not %d' % (
-                    name, s, length), self.position)
+                    length = options.length()
+                message.warn('%s annotation needs %s, not %d' % (ann_name, s, length),
+                             self.position)
                 return
 
         if choices is not None:
-            valuestr = value.one()
-            if valuestr not in choices:
-                message.warn('invalid %s annotation value: %r' % (
-                    name, valuestr, ), self.position)
+            option = options.one()
+            if option not in choices:
+                message.warn('invalid %s annotation value: %r' % (ann_name, option, ),
+                             self.position)
                 return
 
-    def _validate_array(self, option, value):
-        if value is None:
+    def _validate_array(self, ann_name, options):
+        if options is None:
             return
 
-        for name, v in value.all().items():
-            if name in [OPT_ARRAY_ZERO_TERMINATED, OPT_ARRAY_FIXED_SIZE]:
+        for option, value in options.all().items():
+            if option in [OPT_ARRAY_ZERO_TERMINATED, OPT_ARRAY_FIXED_SIZE]:
                 try:
-                    int(v)
+                    int(value)
                 except (TypeError, ValueError):
-                    if v is None:
-                        message.warn('array option %s needs a value' % (name, ),
+                    if value is None:
+                        message.warn('array option %s needs a value' % (option, ),
                                      positions=self.position)
                     else:
                         message.warn('invalid array %s option value %r, '
-                                     'must be an integer' % (name, v, ),
+                                     'must be an integer' % (option, value, ),
                                      positions=self.position)
-            elif name == OPT_ARRAY_LENGTH:
-                if v is None:
+            elif option == OPT_ARRAY_LENGTH:
+                if value is None:
                     message.warn('array option length needs a value',
                                  positions=self.position)
             else:
-                message.warn('invalid array annotation value: %r' % (name, ),
+                message.warn('invalid array annotation value: %r' % (option, ),
                              self.position)
 
-    def _validate_closure(self, option, value):
-        if value is not None and value.length() > 1:
-            message.warn('closure takes at most 1 value, %d given' % (value.length(), ),
+    def _validate_closure(self, ann_name, options):
+        if options is not None and options.length() > 1:
+            message.warn('closure takes at most 1 value, %d given' % (options.length(), ),
                          self.position)
 
-    def _validate_element_type(self, option, value):
-        self._validate_option(option, value, required=True)
-        if value is None:
+    def _validate_element_type(self, ann_name, options):
+        self._validate_annotation(ann_name, options, required=True)
+        if options is None:
             message.warn('element-type takes at least one value, none given',
                          self.position)
             return
-        if value.length() > 2:
-            message.warn('element-type takes at most 2 values, %d given' % (value.length(), ),
+        if options.length() > 2:
+            message.warn('element-type takes at most 2 values, %d given' % (options.length(), ),
                          self.position)
             return
 
-    def _validate_out(self, option, value):
-        if value is None:
+    def _validate_out(self, ann_name, options):
+        if options is None:
             return
-        if value.length() > 1:
-            message.warn('out annotation takes at most 1 value, %d given' % (value.length(), ),
+        if options.length() > 1:
+            message.warn('out annotation takes at most 1 value, %d given' % (options.length(), ),
                          self.position)
             return
-        value_str = value.one()
-        if value_str not in [OPT_OUT_CALLEE_ALLOCATES,
-                             OPT_OUT_CALLER_ALLOCATES]:
-            message.warn("out annotation value is invalid: %r" % (value_str, ),
+        option = options.one()
+        if option not in [OPT_OUT_CALLEE_ALLOCATES,
+                          OPT_OUT_CALLER_ALLOCATES]:
+            message.warn("out annotation value is invalid: %r" % (option, ),
                          self.position)
             return
 
@@ -618,9 +617,8 @@ class DocTag(object):
             else:
                 return fmt2 % (option, )
         annotations = []
-        for option, value in self.options.items():
-            annotations.append(
-                serialize_one(option, value, '(%s %s)', '(%s)'))
+        for ann_name, options in self.annotations.items():
+            annotations.append(serialize_one(ann_name, options, '(%s %s)', '(%s)'))
         if annotations:
             return ' '.join(annotations) + ': '
         else:
@@ -640,63 +638,63 @@ class DocTag(object):
             # validation below is most certainly going to fail.
             return
 
-        for option, value in self.options.items():
-            if option == OPT_ALLOW_NONE:
-                self._validate_option(option, value, n_params=0)
-            elif option == OPT_ARRAY:
-                self._validate_array(option, value)
-            elif option == OPT_ATTRIBUTE:
-                self._validate_option(option, value, n_params=2)
-            elif option == OPT_CLOSURE:
-                self._validate_closure(option, value)
-            elif option == OPT_DESTROY:
-                self._validate_option(option, value, n_params=1)
-            elif option == OPT_ELEMENT_TYPE:
-                self._validate_element_type(option, value)
-            elif option == OPT_FOREIGN:
-                self._validate_option(option, value, n_params=0)
-            elif option == OPT_IN:
-                self._validate_option(option, value, n_params=0)
-            elif option in [OPT_INOUT, OPT_INOUT_ALT]:
-                self._validate_option(option, value, n_params=0)
-            elif option == OPT_OUT:
-                self._validate_out(option, value)
-            elif option == OPT_SCOPE:
-                self._validate_option(
-                    option, value, required=True,
+        for ann_name, value in self.annotations.items():
+            if ann_name == ANN_ALLOW_NONE:
+                self._validate_annotation(ann_name, value, n_params=0)
+            elif ann_name == ANN_ARRAY:
+                self._validate_array(ann_name, value)
+            elif ann_name == ANN_ATTRIBUTE:
+                self._validate_annotation(ann_name, value, n_params=2)
+            elif ann_name == ANN_CLOSURE:
+                self._validate_closure(ann_name, value)
+            elif ann_name == ANN_DESTROY:
+                self._validate_annotation(ann_name, value, n_params=1)
+            elif ann_name == ANN_ELEMENT_TYPE:
+                self._validate_element_type(ann_name, value)
+            elif ann_name == ANN_FOREIGN:
+                self._validate_annotation(ann_name, value, n_params=0)
+            elif ann_name == ANN_IN:
+                self._validate_annotation(ann_name, value, n_params=0)
+            elif ann_name in [ANN_INOUT, ANN_INOUT_ALT]:
+                self._validate_annotation(ann_name, value, n_params=0)
+            elif ann_name == ANN_OUT:
+                self._validate_out(ann_name, value)
+            elif ann_name == ANN_SCOPE:
+                self._validate_annotation(
+                    ann_name, value, required=True,
                     n_params=1,
                     choices=[OPT_SCOPE_ASYNC,
                              OPT_SCOPE_CALL,
                              OPT_SCOPE_NOTIFIED])
-            elif option == OPT_SKIP:
-                self._validate_option(option, value, n_params=0)
-            elif option == OPT_TRANSFER:
-                self._validate_option(
-                    option, value, required=True,
+            elif ann_name == ANN_SKIP:
+                self._validate_annotation(ann_name, value, n_params=0)
+            elif ann_name == ANN_TRANSFER:
+                self._validate_annotation(
+                    ann_name, value, required=True,
                     n_params=1,
                     choices=[OPT_TRANSFER_FULL,
                              OPT_TRANSFER_CONTAINER,
                              OPT_TRANSFER_NONE,
                              OPT_TRANSFER_FLOATING])
-            elif option == OPT_TYPE:
-                self._validate_option(option, value, required=True,
-                                      n_params=1)
-            elif option == OPT_CONSTRUCTOR:
-                self._validate_option(option, value, n_params=0)
-            elif option == OPT_METHOD:
-                self._validate_option(option, value, n_params=0)
+            elif ann_name == ANN_TYPE:
+                self._validate_annotation(ann_name, value, required=True,
+                                          n_params=1)
+            elif ann_name == ANN_CONSTRUCTOR:
+                self._validate_annotation(ann_name, value, n_params=0)
+            elif ann_name == ANN_METHOD:
+                self._validate_annotation(ann_name, value, n_params=0)
             else:
-                message.warn('invalid annotation option: %s' % (option, ),
+                message.warn('unknown annotation: %s' % (ann_name, ),
                              self.position)
 
 
-class DocOptions(object):
+class DocAnnotations(object):
     def __init__(self):
         self.values = []
         self.position = None
 
     def __repr__(self):
-        return '<DocOptions %r>' % (self.values, )
+        return '<DocAnnotations %r>' % (self.values, )
 
     def __getitem__(self, item):
         for key, value in self.values:
@@ -769,7 +767,7 @@ class AnnotationParser(object):
     GTK-Doc comment block parser.
 
     Parses GTK-Doc comment blocks into a parse tree built out of :class:`DockBlock`,
-    :class:`DocTag`, :class:`DocOptions` and :class:`DocOption` objects. This
+    :class:`DocTag`, :class:`DocAnnotations` and :class:`DocOption` objects. This
     parser tries to accept malformed input whenever possible and does not emit
     syntax errors. However, it does emit warnings at the slightest indication
     of malformed input when possible. It is usually a good idea to heed these
@@ -1014,8 +1012,8 @@ class AnnotationParser(object):
                                      position)
 
                     if 'annotations' in result.groupdict():
-                        comment_block.options = self.parse_options(comment_block,
-                                                                   result.group('annotations'))
+                        comment_block.annotations = self.parse_annotations(comment_block,
+                                                                       result.group('annotations'))
 
                     continue
                 else:
@@ -1078,7 +1076,7 @@ class AnnotationParser(object):
                 tag.position = position
                 tag.comment = param_description
                 if param_annotations:
-                    tag.options = self.parse_options(tag, param_annotations)
+                    tag.annotations = self.parse_annotations(tag, param_annotations)
                 if param_name == TAG_RETURNS:
                     comment_block.tags[param_name] = tag
                 else:
@@ -1149,7 +1147,7 @@ class AnnotationParser(object):
                     tag.position = position
                     tag.comment = tag_description
                     if tag_annotations:
-                        tag.options = self.parse_options(tag, tag_annotations)
+                        tag.annotations = self.parse_annotations(tag, tag_annotations)
                     comment_block.tags[TAG_RETURNS] = tag
                     current_tag = tag
                     continue
@@ -1166,7 +1164,7 @@ class AnnotationParser(object):
                     tag.value = tag_description
                     if tag_annotations:
                         if tag_name.lower() == TAG_ATTRIBUTES:
-                            tag.options = self.parse_options(tag, tag_annotations)
+                            tag.annotations = self.parse_annotations(tag, tag_annotations)
                         else:
                             message.warn("annotations not supported for tag '%s:'." %
                                          (tag_name, ),
@@ -1254,13 +1252,13 @@ class AnnotationParser(object):
                          position)
 
     @classmethod
-    def parse_options(cls, tag, value):
+    def parse_annotations(cls, tag, value):
         # (annotation)
         # (annotation opt1 opt2 ...)
         # (annotation opt1=value1 opt2=value2 ...)
         opened = -1
-        options = DocOptions()
-        options.position = tag.position
+        annotations = DocAnnotations()
+        annotations.position = tag.position
 
         for i, c in enumerate(value):
             if c == '(' and opened == -1:
@@ -1277,7 +1275,7 @@ class AnnotationParser(object):
                     raise AssertionError
                 if option is not None:
                     option = DocOption(tag, option)
-                options.add(name, option)
+                annotations.add(name, option)
                 opened = -1
 
-        return options
+        return annotations
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 4611fb9..a12c807 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -26,15 +26,15 @@ from .annotationparser import (TAG_VFUNC, TAG_SINCE, TAG_DEPRECATED, TAG_RETURNS
                                TAG_UNREF_FUNC, TAG_REF_FUNC, TAG_SET_VALUE_FUNC,
                                TAG_GET_VALUE_FUNC, TAG_VALUE, TAG_TRANSFER,
                                TAG_STABILITY)
-from .annotationparser import (OPT_ALLOW_NONE, OPT_ARRAY, OPT_ATTRIBUTE,
-                               OPT_ELEMENT_TYPE, OPT_IN, OPT_INOUT,
-                               OPT_INOUT_ALT, OPT_OUT, OPT_SCOPE,
+from .annotationparser import (ANN_ALLOW_NONE, ANN_ARRAY, ANN_ATTRIBUTE,
+                               ANN_ELEMENT_TYPE, ANN_IN, ANN_INOUT,
+                               ANN_INOUT_ALT, ANN_OUT, ANN_SCOPE,
+                               ANN_TYPE, ANN_CLOSURE, ANN_DESTROY, ANN_TRANSFER, ANN_SKIP,
+                               ANN_FOREIGN, ANN_CONSTRUCTOR, ANN_METHOD,
+                               OPT_ARRAY_FIXED_SIZE, OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED,
                                OPT_OUT_CALLER_ALLOCATES, OPT_OUT_CALLEE_ALLOCATES,
-                               OPT_TYPE, OPT_CLOSURE, OPT_DESTROY, OPT_TRANSFER, OPT_SKIP,
-                               OPT_FOREIGN, OPT_ARRAY_FIXED_SIZE,
-                               OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED,
-                               OPT_CONSTRUCTOR, OPT_METHOD,
                                OPT_TRANSFER_NONE, OPT_TRANSFER_FLOATING)
+
 from .utils import to_underscores_noprefix
 
 
@@ -239,14 +239,14 @@ class MainTransformer(object):
             self._apply_annotations_constant(node)
         return True
 
-    def _adjust_container_type(self, parent, node, options):
-        if OPT_ARRAY in options:
-            self._apply_annotations_array(parent, node, options)
-        elif OPT_ELEMENT_TYPE in options:
-            self._apply_annotations_element_type(parent, node, options)
+    def _adjust_container_type(self, parent, node, annotations):
+        if ANN_ARRAY in annotations:
+            self._apply_annotations_array(parent, node, annotations)
+        elif ANN_ELEMENT_TYPE in annotations:
+            self._apply_annotations_element_type(parent, node, annotations)
 
         if isinstance(node.type, ast.Array):
-            self._check_array_element_type(node.type, options)
+            self._check_array_element_type(node.type, annotations)
 
     def _resolve(self, type_str, type_node=None, node=None, parent=None):
         def grab_one(type_str, resolver, top_combiner, combiner):
@@ -326,7 +326,7 @@ class MainTransformer(object):
 
         return block.position
 
-    def _check_array_element_type(self, array, options):
+    def _check_array_element_type(self, array, annotations):
         array_type = array.array_type
         element_type = array.element_type
 
@@ -337,7 +337,7 @@ class MainTransformer(object):
             if ((element_type in ast.BASIC_GIR_TYPES and not element_type in ast.POINTER_TYPES)
             or isinstance(element_type, (ast.Enum, ast.Bitfield))):
                 message.warn("invalid (element-type) for a GPtrArray, "
-                             "must be a pointer", options.position)
+                             "must be a pointer", annotations.position)
 
         # GByteArrays have (element-type) guint8 by default
         if array_type == ast.Array.GLIB_BYTEARRAY:
@@ -346,16 +346,16 @@ class MainTransformer(object):
             elif not element_type in [ast.TYPE_UINT8, ast.TYPE_INT8, ast.TYPE_CHAR]:
                 message.warn("invalid (element-type) for a GByteArray, "
                              "must be one of guint8, gint8 or gchar",
-                             options.position)
+                             annotations.position)
 
-    def _apply_annotations_array(self, parent, node, options):
-        array_opt = options.get(OPT_ARRAY)
+    def _apply_annotations_array(self, parent, node, annotations):
+        array_opt = annotations.get(ANN_ARRAY)
         if array_opt:
             array_values = array_opt.all()
         else:
             array_values = {}
 
-        element_type = options.get(OPT_ELEMENT_TYPE)
+        element_type = annotations.get(ANN_ELEMENT_TYPE)
         if element_type is not None:
             element_type_node = self._resolve(element_type.one(),
                                               node.type, node, parent)
@@ -400,13 +400,13 @@ class MainTransformer(object):
                 return
         node.type = container_type
 
-    def _apply_annotations_element_type(self, parent, node, options):
-        element_type_opt = options.get(OPT_ELEMENT_TYPE)
+    def _apply_annotations_element_type(self, parent, node, annotations):
+        element_type_opt = annotations.get(ANN_ELEMENT_TYPE)
         if element_type_opt is None:
             message.warn(
                 'element-type annotation takes at least one option, '
                 'none given',
-                options.position)
+                annotations.position)
             return
 
         if isinstance(node.type, ast.List):
@@ -414,7 +414,7 @@ class MainTransformer(object):
                 message.warn(
                     'element-type annotation for a list must have exactly '
                     'one option, not %d options' % (element_type_opt.length(), ),
-                    options.position)
+                    annotations.position)
                 return
             node.type.element_type = self._resolve(element_type_opt.one(),
                                                    node.type, node, parent)
@@ -423,7 +423,7 @@ class MainTransformer(object):
                 message.warn(
                     'element-type annotation for a hash table must have exactly '
                     'two options, not %d option(s)' % (element_type_opt.length(), ),
-                    options.position)
+                    annotations.position)
                 return
             element_type = element_type_opt.flat()
             node.type.key_type = self._resolve(element_type[0],
@@ -435,7 +435,7 @@ class MainTransformer(object):
                 message.warn(
                     'element-type annotation for an array must have exactly '
                     'one option, not %d options' % (element_type_opt.length(), ),
-                    options.position)
+                    annotations.position)
                 return
             node.type.element_type = self._resolve(element_type_opt.one(),
                                                    node.type, node, parent)
@@ -525,19 +525,19 @@ class MainTransformer(object):
             raise AssertionError(node)
 
     def _apply_annotations_param_ret_common(self, parent, node, tag):
-        options = getattr(tag, 'options', {})
+        annotations = tag.annotations if tag else {}
 
-        param_type = options.get(OPT_TYPE)
+        param_type = annotations.get(ANN_TYPE)
         if param_type:
             node.type = self._resolve_toplevel(param_type.one(),
                                                node.type, node, parent)
 
         caller_allocates = False
         annotated_direction = None
-        if (OPT_INOUT in options or OPT_INOUT_ALT in options):
+        if (ANN_INOUT in annotations or ANN_INOUT_ALT in annotations):
             annotated_direction = ast.PARAM_DIRECTION_INOUT
-        elif OPT_OUT in options:
-            subtype = options[OPT_OUT]
+        elif ANN_OUT in annotations:
+            subtype = annotations[ANN_OUT]
             if subtype is not None:
                 subtype = subtype.one()
             annotated_direction = ast.PARAM_DIRECTION_OUT
@@ -554,7 +554,7 @@ class MainTransformer(object):
                 caller_allocates = True
             elif subtype == OPT_OUT_CALLEE_ALLOCATES:
                 caller_allocates = False
-        elif OPT_IN in options:
+        elif ANN_IN in annotations:
             annotated_direction = ast.PARAM_DIRECTION_IN
 
         if (annotated_direction is not None) and (annotated_direction != node.direction):
@@ -563,16 +563,16 @@ class MainTransformer(object):
             # Also reset the transfer default if we're toggling direction
             node.transfer = self._get_transfer_default(parent, node)
 
-        transfer_tag = options.get(OPT_TRANSFER)
+        transfer_tag = annotations.get(ANN_TRANSFER)
         if transfer_tag and transfer_tag.length() == 1:
             transfer = transfer_tag.one()
             if transfer == OPT_TRANSFER_FLOATING:
                 transfer = OPT_TRANSFER_NONE
             node.transfer = transfer
 
-        self._adjust_container_type(parent, node, options)
+        self._adjust_container_type(parent, node, annotations)
 
-        if (OPT_ALLOW_NONE in options
+        if (ANN_ALLOW_NONE in annotations
         or node.type.target_giname == 'Gio.AsyncReadyCallback'
         or node.type.target_giname == 'Gio.Cancellable'):
             node.allow_none = True
@@ -580,11 +580,11 @@ class MainTransformer(object):
         if tag is not None and tag.comment is not None:
             node.doc = tag.comment
 
-        if OPT_SKIP in options:
+        if ANN_SKIP in annotations:
             node.skip = True
 
-        if options:
-            for attribute in options.getall(OPT_ATTRIBUTE):
+        if annotations:
+            for attribute in annotations.getall(ANN_ATTRIBUTE):
                 node.attributes.append(attribute.flat())
 
     def _apply_annotations_annotated(self, node, block):
@@ -622,20 +622,20 @@ class MainTransformer(object):
 
         annos_tag = block.tags.get(TAG_ATTRIBUTES)
         if annos_tag is not None:
-            for key, value in annos_tag.options.items():
-                if value:
-                    node.attributes.append((key, value.one()))
+            for ann_name, options in annos_tag.annotations.items():
+                if options:
+                    node.attributes.append((ann_name, options.one()))
 
-        if OPT_SKIP in block.options:
+        if ANN_SKIP in block.annotations:
             node.skip = True
 
-        if OPT_FOREIGN in block.options:
+        if ANN_FOREIGN in block.annotations:
             node.foreign = True
 
-        if OPT_CONSTRUCTOR in block.options and isinstance(node, ast.Function):
+        if ANN_CONSTRUCTOR in block.annotations and isinstance(node, ast.Function):
             node.is_constructor = True
 
-        if OPT_METHOD in block.options:
+        if ANN_METHOD in block.annotations:
             node.is_method = True
 
     def _apply_annotations_alias(self, node, chain):
@@ -643,17 +643,15 @@ class MainTransformer(object):
         self._apply_annotations_annotated(node, block)
 
     def _apply_annotations_param(self, parent, param, tag):
-        if tag:
-            options = tag.options
-        else:
-            options = {}
+        annotations = tag.annotations if tag else {}
+
         if isinstance(parent, (ast.Function, ast.VFunction)):
-            scope = options.get(OPT_SCOPE)
+            scope = annotations.get(ANN_SCOPE)
             if scope and scope.length() == 1:
                 param.scope = scope.one()
                 param.transfer = ast.PARAM_TRANSFER_NONE
 
-            destroy = options.get(OPT_DESTROY)
+            destroy = annotations.get(ANN_DESTROY)
             if destroy:
                 param.destroy_name = self._get_validate_parameter_name(parent,
                                                                        destroy.one(),
@@ -665,13 +663,13 @@ class MainTransformer(object):
                     # itself.  But this helps avoid tripping a warning from finaltransformer,
                     # since we don't have a way right now to flag this callback a destroy.
                     destroy_param.scope = ast.PARAM_SCOPE_NOTIFIED
-            closure = options.get(OPT_CLOSURE)
+            closure = annotations.get(ANN_CLOSURE)
             if closure and closure.length() == 1:
                 param.closure_name = self._get_validate_parameter_name(parent,
                                                                        closure.one(),
                                                                        param)
         elif isinstance(parent, ast.Callback):
-            if OPT_CLOSURE in options:
+            if ANN_CLOSURE in annotations:
                 # For callbacks, (closure) appears without an
                 # argument, and tags a parameter that is a closure. We
                 # represent it (weirdly) in the gir and typelib by
@@ -734,12 +732,12 @@ class MainTransformer(object):
         tag = block.params.get(field.name)
         if not tag:
             return
-        t = tag.options.get(OPT_TYPE)
+        t = tag.annotations.get(ANN_TYPE)
         if t:
             field.type = self._transformer.create_type_from_user_string(t.one())
 
         try:
-            self._adjust_container_type(parent, field, tag.options)
+            self._adjust_container_type(parent, field, tag.annotations)
         except AttributeError:
             pass
 
@@ -787,8 +785,8 @@ class MainTransformer(object):
         for i, param in enumerate(signal.parameters):
             if names:
                 name, tag = names[i + 1]
-                options = getattr(tag, 'options', {})
-                param_type = options.get(OPT_TYPE)
+                annotations = getattr(tag, 'annotations', {})
+                param_type = annotations.get(ANN_TYPE)
                 if param_type:
                     param.type = self._resolve_toplevel(param_type.one(), param.type,
                                                         param, parent)
diff --git a/tests/scanner/annotationparser/test_parser.py b/tests/scanner/annotationparser/test_parser.py
index b1b8734..b20cf2c 100644
--- a/tests/scanner/annotationparser/test_parser.py
+++ b/tests/scanner/annotationparser/test_parser.py
@@ -130,9 +130,9 @@ class TestCommentBlock(unittest.TestCase):
 
             parsed += '  <identifier>\n'
             parsed += '    <name>%s</name>\n' % (docblock.name, )
-            if docblock.options.values:
+            if docblock.annotations.values:
                 parsed += '    <annotations>\n'
-                for key, value in docblock.options.values:
+                for key, value in docblock.annotations.values:
                     parsed += '      <annotation>\n'
                     parsed += '        <name>%s</name>\n' % (key, )
                     if value is not None:
@@ -155,9 +155,9 @@ class TestCommentBlock(unittest.TestCase):
                     param = docblock.params.get(param_name)
                     parsed += '    <parameter>\n'
                     parsed += '      <name>%s</name>\n' % (param_name, )
-                    if param.options.values:
+                    if param.annotations.values:
                         parsed += '      <annotations>\n'
-                        for key, value in param.options.values:
+                        for key, value in param.annotations.values:
                             parsed += '        <annotation>\n'
                             parsed += '          <name>%s</name>\n' % (key, )
                             if value is not None:
@@ -186,9 +186,9 @@ class TestCommentBlock(unittest.TestCase):
                     tag = docblock.tags.get(tag_name)
                     parsed += '    <tag>\n'
                     parsed += '      <name>%s</name>\n' % (tag_name, )
-                    if tag.options.values:
+                    if tag.annotations.values:
                         parsed += '      <annotations>\n'
-                        for key, value in tag.options.values:
+                        for key, value in tag.annotations.values:
                             parsed += '        <annotation>\n'
                             parsed += '          <name>%s</name>\n' % (key, )
                             if value is not None:
diff --git a/tests/warn/invalid-option.h b/tests/warn/invalid-option.h
index 41985a0..de336ee 100644
--- a/tests/warn/invalid-option.h
+++ b/tests/warn/invalid-option.h
@@ -5,7 +5,7 @@
  */
 void test_func(int param);
 
-// EXPECT:4: Warning: Test: invalid annotation option: invalid-annotation-option
+// EXPECT:4: Warning: Test: unknown annotation: invalid-annotation-option
 
 /**
  * func_weird_gtk_doc:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]