[gobject-introspection] giscanner: Apply standard annotations to constant values



commit 0f5f94ed8a86355003533452a2d6cc8077d27535
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Jan 31 21:42:32 2013 -0500

    giscanner: Apply standard annotations to constant values
    
    While there's no particular reason I need to do this, there
    really isn't any reason to not do this, and it helps with doctool
    or whatever in the future if we want to document when a constant
    showed up. g-ir-compiler also keeps track of constant deprecations,
    so this fixes constants not ever being deprecated.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693040

 giscanner/girwriter.py                    |    3 +++
 giscanner/maintransformer.py              |    9 ++++++---
 giscanner/transformer.py                  |    5 +----
 tests/scanner/Annotation-1.0-expected.gir |    5 ++++-
 tests/scanner/annotation.h                |    2 ++
 5 files changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 7344488..e9910d4 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -370,7 +370,10 @@ and/or use gtk-doc annotations. ''')
         attrs = [('name', constant.name),
                  ('value', constant.value),
                  ('c:type', constant.ctype)]
+        self._append_version(constant, attrs)
+        self._append_node_generic(constant, attrs)
         with self.tagcontext('constant', attrs):
+            self._write_generic(constant)
             self._write_type(constant.value_type)
 
     def _write_class(self, node):
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 67168d6..d149f30 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -192,7 +192,7 @@ usage is void (*_gtk_reserved1)(void);"""
     def _get_annotation_name(self, node):
         if isinstance(node, (ast.Class, ast.Interface, ast.Record,
                              ast.Union, ast.Enum, ast.Bitfield,
-                             ast.Callback, ast.Alias)):
+                             ast.Callback, ast.Alias, ast.Constant)):
             if node.ctype is not None:
                 return node.ctype
             elif isinstance(node, ast.Registered) and node.gtype_name is not None:
@@ -815,9 +815,12 @@ usage is void (*_gtk_reserved1)(void);"""
         self._apply_annotations_return(signal, signal.retval, block)
 
     def _apply_annotations_constant(self, node):
-        block = self._blocks.get(node.ctype)
-        if not block:
+        block = self._get_block(node)
+        if block is None:
             return
+
+        self._apply_annotations_annotated(node, block)
+
         tag = block.get_tag(TAG_VALUE)
         if tag:
             node.value = tag.value
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 6736799..ba7afb9 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -338,10 +338,7 @@ raise ValueError."""
         elif stype == CSYMBOL_TYPE_UNION:
             return self._create_union(symbol)
         elif stype == CSYMBOL_TYPE_CONST:
-            # Don't parse constants which are marked (skip)
-            docblock = self._annotations.get(symbol.ident)
-            if not docblock or not 'skip' in docblock.options:
-                return self._create_const(symbol)
+            return self._create_const(symbol)
         # Ignore variable declarations in the header
         elif stype == CSYMBOL_TYPE_OBJECT:
             pass
diff --git a/tests/scanner/Annotation-1.0-expected.gir b/tests/scanner/Annotation-1.0-expected.gir
index 73d982d..0be91d6 100644
--- a/tests/scanner/Annotation-1.0-expected.gir
+++ b/tests/scanner/Annotation-1.0-expected.gir
@@ -29,12 +29,15 @@ and/or use gtk-doc annotations.  -->
     </constant>
     <constant name="CALCULATED_LARGE"
               value="10000000000UL"
-              c:type="ANNOTATION_CALCULATED_LARGE">
+              c:type="ANNOTATION_CALCULATED_LARGE"
+              version="1.4">
+      <doc xml:whitespace="preserve">Constant to define a calculated large value</doc>
       <type name="gint" c:type="gint"/>
     </constant>
     <constant name="CALCULATED_LARGE_DIV"
               value="1000000UL"
               c:type="ANNOTATION_CALCULATED_LARGE_DIV">
+      <doc xml:whitespace="preserve">Constant to define a calculated large value</doc>
       <type name="gint" c:type="gint"/>
     </constant>
     <callback name="Callback" c:type="AnnotationCallback">
diff --git a/tests/scanner/annotation.h b/tests/scanner/annotation.h
index b3b4bd4..09d4f4f 100644
--- a/tests/scanner/annotation.h
+++ b/tests/scanner/annotation.h
@@ -180,6 +180,8 @@ GObject * annotation_transfer_floating(void);
  * Constant to define a calculated large value
  *
  * Value: 10000000000UL
+ *
+ * Since: 1.4
  */
 #define ANNOTATION_CALCULATED_LARGE (1000 * G_GINT64_CONSTANT (10000000))
 



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