gobject-introspection r641 - in trunk: docs girepository giscanner tests/scanner tools



Author: walters
Date: Thu Oct  2 13:25:46 2008
New Revision: 641
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=641&view=rev

Log:
Bug 554632: Create type tag for GType


Modified:
   trunk/docs/typelib-format.txt
   trunk/girepository/girepository.c
   trunk/girepository/girepository.h
   trunk/girepository/girparser.c
   trunk/giscanner/ast.py
   trunk/giscanner/glibtransformer.py
   trunk/tests/scanner/foo-expected.gir
   trunk/tools/generate.c

Modified: trunk/docs/typelib-format.txt
==============================================================================
--- trunk/docs/typelib-format.txt	(original)
+++ trunk/docs/typelib-format.txt	Thu Oct  2 13:25:46 2008
@@ -473,9 +473,11 @@
          15  size_t
          16  float
          17  double
-         18  utf8     (these are zero-terminated char[] and assumed to be 
+	 18  time_t
+	 19  GType
+         20  utf8     (these are zero-terminated char[] and assumed to be 
                        in UTF-8)
-         19  filename (these are zero-terminated char[] and assumed to be
+         21  filename (these are zero-terminated char[] and assumed to be
                        in the GLib filename encoding)
 
          For utf8 and filename is_pointer will always be set.

Modified: trunk/girepository/girepository.c
==============================================================================
--- trunk/girepository/girepository.c	(original)
+++ trunk/girepository/girepository.c	Thu Oct  2 13:25:46 2008
@@ -750,6 +750,8 @@
       return "double";
     case GI_TYPE_TAG_TIME_T:
       return "time_t";
+    case GI_TYPE_TAG_GTYPE:
+      return "GType";
     case GI_TYPE_TAG_UTF8:
       return "utf8";
     case GI_TYPE_TAG_FILENAME:

Modified: trunk/girepository/girepository.h
==============================================================================
--- trunk/girepository/girepository.h	(original)
+++ trunk/girepository/girepository.h	Thu Oct  2 13:25:46 2008
@@ -267,6 +267,7 @@
 /* GITypeInfo */
 
 typedef enum {
+  /* Basic types */
   GI_TYPE_TAG_VOID      =  0,
   GI_TYPE_TAG_BOOLEAN   =  1,
   GI_TYPE_TAG_INT8      =  2,
@@ -286,16 +287,22 @@
   GI_TYPE_TAG_FLOAT     = 16,
   GI_TYPE_TAG_DOUBLE    = 17,
   GI_TYPE_TAG_TIME_T    = 18,
-  GI_TYPE_TAG_UTF8      = 19,
-  GI_TYPE_TAG_FILENAME  = 20,
-  GI_TYPE_TAG_ARRAY     = 21,
-  GI_TYPE_TAG_INTERFACE = 22,
-  GI_TYPE_TAG_GLIST     = 23,
-  GI_TYPE_TAG_GSLIST    = 24,
-  GI_TYPE_TAG_GHASH     = 25,
-  GI_TYPE_TAG_ERROR     = 26
+  GI_TYPE_TAG_GTYPE     = 19,
+  GI_TYPE_TAG_UTF8      = 20,
+  GI_TYPE_TAG_FILENAME  = 21,
+  /* Non-basic types */
+  GI_TYPE_TAG_ARRAY     = 22,
+  GI_TYPE_TAG_INTERFACE = 23,
+  GI_TYPE_TAG_GLIST     = 24,
+  GI_TYPE_TAG_GSLIST    = 25,
+  GI_TYPE_TAG_GHASH     = 26,
+  GI_TYPE_TAG_ERROR     = 27
+  /* Note - there is only room currently for 32 tags.
+   * See docs/typelib-format.txt SimpleTypeBlob definition */
 } GITypeTag;
 
+#define G_TYPE_TAG_IS_BASIC(tag) (tag < GI_TYPE_TAG_ARRAY)
+
 const gchar*           g_type_tag_to_string            (GITypeTag   type);
 
 gboolean               g_type_info_is_pointer          (GITypeInfo *info);

Modified: trunk/girepository/girparser.c
==============================================================================
--- trunk/girepository/girparser.c	(original)
+++ trunk/girepository/girparser.c	Thu Oct  2 13:25:46 2008
@@ -222,7 +222,8 @@
   ctx->state = newstate;
 }
 
-static GIrNodeType * parse_type_internal (const gchar *str, gchar **next, gboolean in_glib);
+static GIrNodeType * parse_type_internal (const gchar *str, gchar **next, gboolean in_glib,
+					  gboolean in_gobject);
 
 typedef struct {
   const gchar *str;
@@ -255,6 +256,7 @@
     { "float",    GI_TYPE_TAG_FLOAT,   0 },
     { "double",   GI_TYPE_TAG_DOUBLE,  0 },
     { "time_t",   GI_TYPE_TAG_TIME_T,  0 },
+    { "GType",    GI_TYPE_TAG_GTYPE,   0 },
     { "utf8",     GI_TYPE_TAG_UTF8,    1 },  
     { "filename", GI_TYPE_TAG_FILENAME,1 },
 };  
@@ -277,7 +279,8 @@
 }
 
 static GIrNodeType *
-parse_type_internal (const gchar *str, char **next, gboolean in_glib)
+parse_type_internal (const gchar *str, char **next, gboolean in_glib,
+		     gboolean in_gobject)
 {
   const BasicTypeInfo *basic;  
   GIrNodeType *type;
@@ -287,6 +290,13 @@
   
   type->unparsed = g_strdup (str);
 
+  /* See comment below on GLib.List handling */
+  if (in_gobject && strcmp (str, "Type") == 0) 
+    {
+      temporary_type = g_strdup ("GLib.Type");
+      str = temporary_type;
+    }
+  
   basic = parse_basic (str);
   if (basic != NULL)
     {
@@ -298,11 +308,10 @@
     }
   else if (in_glib)
     {
-      /* If we're inside GLib, handle "List" by prefixing it with
+      /* If we're inside GLib, handle "List" etc. by prefixing with
        * "GLib." so the parsing code below doesn't have to get more
        * special. 
        */
-      
       if (g_str_has_prefix (str, "List<") ||
 	  strcmp (str, "List") == 0)
 	{
@@ -437,17 +446,18 @@
   gchar *str;
   GIrNodeType *node;
   const BasicTypeInfo *basic;
-  gboolean in_glib;
+  gboolean in_glib, in_gobject;
   gboolean matched_special = FALSE;
 
   in_glib = strcmp (ctx->namespace, "GLib") == 0;
+  in_gobject = strcmp (ctx->namespace, "GObject") == 0;
 
   /* Do not search aliases for basic types */
   basic = parse_basic (type);
   if (basic == NULL)
     type = resolve_aliases (ctx, type);
 
-  node = parse_type_internal (type, NULL, in_glib);
+  node = parse_type_internal (type, NULL, in_glib, in_gobject);
   if (node)
     g_debug ("Parsed type: %s => %d", type, node->tag);
   else

Modified: trunk/giscanner/ast.py
==============================================================================
--- trunk/giscanner/ast.py	(original)
+++ trunk/giscanner/ast.py	Thu Oct  2 13:25:46 2008
@@ -48,6 +48,7 @@
 TYPE_SSIZET = 'ssize_t'
 TYPE_SIZET = 'size_t'
 TYPE_TIMET = 'time_t'
+TYPE_GTYPE = 'GType'
 TYPE_FLOAT = 'float'
 TYPE_DOUBLE = 'double'
 TYPE_STRING = 'utf8' # requires zero-terminated
@@ -57,7 +58,7 @@
                    TYPE_UINT16, TYPE_INT32, TYPE_UINT32, TYPE_INT64,
                    TYPE_UINT64, TYPE_INT, TYPE_UINT, TYPE_LONG,
                    TYPE_ULONG, TYPE_SSIZET, TYPE_SIZET, TYPE_FLOAT,
-                   TYPE_DOUBLE, TYPE_TIMET]
+                   TYPE_DOUBLE, TYPE_TIMET, TYPE_GTYPE]
 GIR_TYPES = [TYPE_NONE, TYPE_ANY]
 GIR_TYPES.extend(BASIC_GIR_TYPES)
 GIR_TYPES.extend([TYPE_STRING, TYPE_FILENAME])

Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py	(original)
+++ trunk/giscanner/glibtransformer.py	Thu Oct  2 13:25:46 2008
@@ -110,6 +110,11 @@
         for node in namespace.nodes:
             self._parse_node(node)
 
+        # We don't want an alias for this - it's handled specially in
+        # the typelib compiler.
+        if namespace.name == 'GObject':
+            del self._names.aliases['Type']
+
         # Introspection is done from within parsing
 
         # Second pass: pair boxed structures
@@ -253,13 +258,10 @@
             # No GObjects in GLib
             return False
         # GType *_get_type(void)
-        # This is a bit fishy, why do we need all these aliases?
         if func.retval.type.name not in ['Type',
                                          'GType',
-                                         'Object.Type',
                                          'GObject.Type',
-                                         'Gtk.Type',
-                                         'GObject.GType']:
+                                         'Gtk.Type']:
             print ("Warning: *_get_type function returns '%r'"
                    ", not GObject.Type") % (func.retval.type.name, )
             return False

Modified: trunk/tests/scanner/foo-expected.gir
==============================================================================
--- trunk/tests/scanner/foo-expected.gir	(original)
+++ trunk/tests/scanner/foo-expected.gir	Thu Oct  2 13:25:46 2008
@@ -73,7 +73,7 @@
             <type name="any" c:type="void*"/>
           </parameter>
           <parameter name="some_type">
-            <type name="GObject.Type" c:type="GType"/>
+            <type name="GType" c:type="GType"/>
           </parameter>
         </parameters>
       </method>

Modified: trunk/tools/generate.c
==============================================================================
--- trunk/tools/generate.c	(original)
+++ trunk/tools/generate.c	Thu Oct  2 13:25:46 2008
@@ -64,30 +64,6 @@
   GITypeInfo *type;
   gboolean is_pointer;
   
-  const gchar* basic[] = {
-    "none", 
-    "boolean", 
-    "int8", 
-    "uint8", 
-    "int16", 
-    "uint16", 
-    "int32", 
-    "uint32", 
-    "int64", 
-    "uint64", 
-    "int",
-    "uint",
-    "long",
-    "ulong",
-    "ssize",
-    "size",
-    "float", 
-    "double", 
-    "time_t", 
-    "utf8",
-    "filename"
-  };
-
   check_unresolved ((GIBaseInfo*)info);
 
   tag = g_type_info_get_tag (info);
@@ -100,8 +76,8 @@
       else
 	g_fprintf (file, "%s", "none");
     } 
-  else if (tag < GI_TYPE_TAG_ARRAY)
-    g_fprintf (file, "%s", basic[tag]);
+  else if (G_TYPE_TAG_IS_BASIC (tag))
+    g_fprintf (file, "%s", g_type_tag_to_string (tag));
   else if (tag == GI_TYPE_TAG_ARRAY)
     {
       gint length;



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