gobject-introspection r603 - in trunk: girepository giscanner tests/scanner



Author: walters
Date: Mon Sep 15 14:46:19 2008
New Revision: 603
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=603&view=rev

Log:
Bug 552065: Add deprecation information to GIR

	* giscanner/ast.py: Add deprecation attributes.
	* giscanner/girwriter.py: Write out deprecation data.
	* girepository/girparser.c: Relax parsing; deprecated
	attribute now includes freeform string.
	* giscanner/scannerlexer.l: Parse Deprecated.
	* giscanner/transformer.py: Look for deprecated attribute
	on functions.
	* tests/scanner/*: Add a Deprecated test.


Modified:
   trunk/girepository/girparser.c
   trunk/giscanner/ast.py
   trunk/giscanner/girwriter.py
   trunk/giscanner/scannerlexer.l
   trunk/giscanner/transformer.py
   trunk/tests/scanner/annotation-expected.gir
   trunk/tests/scanner/annotation.c
   trunk/tests/scanner/annotation.h

Modified: trunk/girepository/girparser.c
==============================================================================
--- trunk/girepository/girparser.c	(original)
+++ trunk/girepository/girparser.c	Mon Sep 15 14:46:19 2008
@@ -634,7 +634,7 @@
   ((GIrNode *)boxed)->name = g_strdup (name);
   boxed->gtype_name = g_strdup (typename);
   boxed->gtype_init = g_strdup (typeinit);
-  if (deprecated && strcmp (deprecated, "1") == 0)
+  if (deprecated)
     boxed->deprecated = TRUE;
   else
     boxed->deprecated = FALSE;
@@ -706,7 +706,7 @@
   ((GIrNode *)function)->name = g_strdup (name);
   function->symbol = g_strdup (symbol);
   function->parameters = NULL;
-  if (deprecated && strcmp (deprecated, "1") == 0)
+  if (deprecated)
     function->deprecated = TRUE;
   else
     function->deprecated = FALSE;
@@ -1138,7 +1138,7 @@
 	  ((GIrNode *)enum_)->name = g_strdup (name);
 	  enum_->gtype_name = g_strdup (typename);
 	  enum_->gtype_init = g_strdup (typeinit);
-	  if (deprecated && strcmp (deprecated, "1") == 0)
+	  if (deprecated)
 	    enum_->deprecated = TRUE;
 	  else
 	    enum_->deprecated = FALSE;
@@ -1280,7 +1280,7 @@
 	  
 	  value_->value = parse_value (value);
 	  
-	  if (deprecated && strcmp (deprecated, "1") == 0)
+	  if (deprecated)
 	    value_->deprecated = TRUE;
 	  else
 	    value_->deprecated = FALSE;
@@ -1330,7 +1330,7 @@
 
 	  ctx->current_typed = (GIrNode*) constant;
 
-	  if (deprecated && strcmp (deprecated, "1") == 0)
+	  if (deprecated)
 	    constant->deprecated = TRUE;
 	  else
 	    constant->deprecated = FALSE;
@@ -1408,7 +1408,7 @@
 	  domain->getquark = g_strdup (getquark);
 	  domain->codes = g_strdup (codes);
 
-	  if (deprecated && strcmp (deprecated, "1") == 0)
+	  if (deprecated)
 	    domain->deprecated = TRUE;
 	  else
 	    domain->deprecated = FALSE;
@@ -1460,7 +1460,7 @@
 	  ((GIrNode *)iface)->name = g_strdup (name);
 	  iface->gtype_name = g_strdup (typename);
 	  iface->gtype_init = g_strdup (typeinit);
-	  if (deprecated && strcmp (deprecated, "1") == 0)
+	  if (deprecated)
 	    iface->deprecated = TRUE;
 	  else
 	    iface->deprecated = FALSE;
@@ -1516,7 +1516,7 @@
 	  iface->gtype_name = g_strdup (typename);
 	  iface->gtype_init = g_strdup (typeinit);
 	  iface->parent = g_strdup (parent);
-	  if (deprecated && strcmp (deprecated, "1") == 0)
+	  if (deprecated)
 	    iface->deprecated = TRUE;
 	  else
 	    iface->deprecated = FALSE;
@@ -1918,7 +1918,7 @@
       struct_ = (GIrNodeStruct *) g_ir_node_new (G_IR_NODE_STRUCT);
       
       ((GIrNode *)struct_)->name = g_strdup (name);
-      if (deprecated && strcmp (deprecated, "1") == 0)
+      if (deprecated)
 	struct_->deprecated = TRUE;
       else
 	struct_->deprecated = FALSE;
@@ -1969,7 +1969,7 @@
 	  ((GIrNode *)union_)->name = g_strdup (name);
 	  union_->gtype_name = g_strdup (typename);
 	  union_->gtype_init = g_strdup (typeinit);
-	  if (deprecated && strcmp (deprecated, "1") == 0)
+	  if (deprecated)
 	    union_->deprecated = TRUE;
 	  else
 	    union_->deprecated = FALSE;

Modified: trunk/giscanner/ast.py
==============================================================================
--- trunk/giscanner/ast.py	(original)
+++ trunk/giscanner/ast.py	Mon Sep 15 14:46:19 2008
@@ -117,6 +117,7 @@
 
     def __init__(self, name=None):
         self.name = name
+        self.deprecated = None
 
     def __repr__(self):
         return '%s(%r)' % (self.__class__.__name__, self.name)

Modified: trunk/giscanner/girwriter.py
==============================================================================
--- trunk/giscanner/girwriter.py	(original)
+++ trunk/giscanner/girwriter.py	Mon Sep 15 14:46:19 2008
@@ -81,6 +81,14 @@
         else:
             print 'WRITER: Unhandled node', node
 
+    def _append_deprecated(self, node, attrs):
+        if node.deprecated:
+            (deprecated_version, deprecated_str) = node.deprecated
+            attrs.append(('deprecated', deprecated_str.strip()))
+            if deprecated_version:
+                attrs.append(('deprecated-version',
+                              deprecated_version.strip()))
+
     def _write_alias(self, alias):
         attrs = [('name', alias.name), ('target', alias.target)]
         if alias.ctype is not None:
@@ -90,6 +98,7 @@
     def _write_function(self, func, tag_name='function'):
         attrs = [('name', func.name),
                  ('c:identifier', func.symbol)]
+        self._append_deprecated(func, attrs)
         with self.tagcontext(tag_name, attrs):
             self._write_return_type(func.retval)
             self._write_parameters(func.parameters)
@@ -159,6 +168,7 @@
     def _write_enum(self, enum):
         attrs = [('name', enum.name),
                  ('c:type', enum.symbol)]
+        self._append_deprecated(enum, attrs)
         tag_name = 'enumeration'
         if isinstance(enum, GLibEnum):
             attrs.extend([('glib:type-name', enum.type_name),
@@ -181,6 +191,7 @@
     def _write_class(self, node):
         attrs = [('name', node.name),
                  ('c:type', node.ctype)]
+        self._append_deprecated(node, attrs)
         if isinstance(node, Class):
             tag_name = 'class'
             if node.parent is not None:
@@ -229,6 +240,7 @@
     def _write_callback(self, callback):
         # FIXME: reuse _write_function
         attrs = [('name', callback.name), ('c:type', callback.ctype)]
+        self._append_deprecated(callback, attrs)
         with self.tagcontext('callback', attrs):
             self._write_return_type(callback.retval)
             self._write_parameters(callback.parameters)
@@ -246,6 +258,7 @@
     def _write_record(self, record):
         attrs = [('name', record.name),
                  ('c:type', record.symbol)]
+        self._append_deprecated(record, attrs)
         if isinstance(record, GLibBoxed):
             attrs.extend(self._boxed_attrs(record))
         with self.tagcontext('record', attrs):
@@ -258,6 +271,7 @@
     def _write_union(self, union):
         attrs = [('name', union.name),
                  ('c:type', union.symbol)]
+        self._append_deprecated(union, attrs)
         if isinstance(union, GLibBoxed):
             attrs.extend(self._boxed_attrs(union))
         with self.tagcontext('union', attrs):

Modified: trunk/giscanner/scannerlexer.l
==============================================================================
--- trunk/giscanner/scannerlexer.l	(original)
+++ trunk/giscanner/scannerlexer.l	Mon Sep 15 14:46:19 2008
@@ -207,6 +207,7 @@
   GSList *directives;
   GSList *options = NULL;
   char *rname;
+  int n_parts;
 
   i = 0;
   do 
@@ -229,12 +230,24 @@
   line[i] = '\0';
 
   parts = g_strsplit (line, ": ", 3);
+  n_parts = g_strv_length (parts);
 
-  if (g_strv_length (parts) >= 2)
+  if (g_ascii_strcasecmp (parts[0], "eprecated") == 0)
+    {
+      if (n_parts == 3)
+	options = g_slist_prepend (options, g_strdup (parts[2]));
+      else if (n_parts == 2)
+	options = g_slist_prepend (options, g_strdup (parts[1]));
+      else
+	options = g_slist_prepend (options, g_strdup (""));
+      name = parts[0];
+      value = NULL;
+    }
+  else if (n_parts >= 2)
     {
       name = parts[0];
 
-      if (g_strv_length (parts) == 3) 
+      if (n_parts == 3) 
         {
           char *ptr = parts[1];
           GString *current = NULL;
@@ -275,12 +288,13 @@
     }
 
   /*
-   * This is a special case for return values, name will only be
-   * 'eturn' or a valid name, check the call site.
-   * Context-sensitive parsing would probably be the right way to go
+   * Special cases for global annotations.
+   * Context-sensitive parsing would probably be the right way to go.
    */
   if (g_ascii_strncasecmp ("eturn", name, 5) == 0)
     rname = "return";
+  else if (g_ascii_strncasecmp ("eprecated", name, 9) == 0)
+    rname = "deprecated";
   else
     rname = name;
 
@@ -333,7 +347,7 @@
       if ((c1 != '*' && c1 != ' '))
           startofline = FALSE;
 
-      if (startofline && (c1 == ' ') && (c2 == '@' || (c2 == 'r') || (c2 == 'R')))
+      if (startofline && (c1 == ' ') && (c2 == '@' || (c2 == 'r') || (c2 == 'R') || (c2 == 'D')))
         {
            c1 = c2;
            c2 = input();

Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py	(original)
+++ trunk/giscanner/transformer.py	Mon Sep 15 14:46:19 2008
@@ -222,7 +222,16 @@
         return_ = self._create_return(symbol.base_type.base_type,
                                       directives.get('return', []))
         name = self._strip_namespace_func(symbol.ident)
-        return Function(name, return_, parameters, symbol.ident)
+        func = Function(name, return_, parameters, symbol.ident)
+        deprecated = directives.get('deprecated', False)
+        if deprecated:
+            try:
+                # Split out gtk-doc version
+                func.deprecated = deprecated[0].split(':', 1)
+            except ValueError, e:
+                # No version, just include str
+                func.deprecated = (None, deprecated[0])
+        return func
 
     def _create_source_type(self, source_type):
         if source_type is None:

Modified: trunk/tests/scanner/annotation-expected.gir
==============================================================================
--- trunk/tests/scanner/annotation-expected.gir	(original)
+++ trunk/tests/scanner/annotation-expected.gir	Mon Sep 15 14:46:19 2008
@@ -174,5 +174,18 @@
         </parameter>
       </parameters>
     </function>
+    <function name="object_do_not_use"
+              c:identifier="annotation_object_do_not_use"
+              deprecated="Use annotation_object_create_object() instead."
+              deprecated-version="0.12">
+      <return-value>
+        <type name="GObject.Object" c:type="GObject*"/>
+      </return-value>
+      <parameters>
+        <parameter name="object">
+          <type name="Object" c:type="AnnotationObject*"/>
+        </parameter>
+      </parameters>
+    </function>
   </namespace>
 </repository>

Modified: trunk/tests/scanner/annotation.c
==============================================================================
--- trunk/tests/scanner/annotation.c	(original)
+++ trunk/tests/scanner/annotation.c	Mon Sep 15 14:46:19 2008
@@ -208,3 +208,15 @@
 annotation_object_allow_none (AnnotationObject *object, gchar *allow_none)
 {
 }
+
+/**
+ * annotation_object_do_not_use: 
+ * @object: a #GObject
+ *
+ * Deprecated: 0.12: Use annotation_object_create_object() instead.
+ **/
+GObject*
+annotation_object_do_not_use (AnnotationObject *object)
+{
+  return NULL;
+}

Modified: trunk/tests/scanner/annotation.h
==============================================================================
--- trunk/tests/scanner/annotation.h	(original)
+++ trunk/tests/scanner/annotation.h	Mon Sep 15 14:46:19 2008
@@ -38,4 +38,7 @@
 GList*   annotation_object_get_strings  (AnnotationObject *object);
 GSList*  annotation_object_get_objects  (AnnotationObject *object);
 
+GObject* annotation_object_do_not_use   (AnnotationObject *object);
+
+
 #endif /* __ANNOTATION_OBJECT_H__ */



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