gobject-introspection r99 - in trunk: . src



Author: johan
Date: Fri Jan 11 23:59:49 2008
New Revision: 99
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=99&view=rev

Log:
2008-01-11  Johan Dahlin  <johan gnome org>

	* src/scanner.c (g_igenerator_process_function_symbol): 
	Refactor out g_idle_node_add_member.
	(create_node_from_gtype, create_node_from_ctype): 
	Use case instead of if...else
	(get_type_from_type_id):
	Rename to create_node_from_gtype
	(get_type_from_ctype):
	Rename to create_node_from_ctype

	Rename ginode -> node, gitype -> type, gifunc -> func.
	
	* src/gidlnode.c (g_idl_node_add_member, g_idl_node_cmp): 
	Two new functions, refactor out of scanner.c



Modified:
   trunk/ChangeLog
   trunk/src/gidlnode.c
   trunk/src/gidlnode.h
   trunk/src/scanner.c

Modified: trunk/src/gidlnode.c
==============================================================================
--- trunk/src/gidlnode.c	(original)
+++ trunk/src/gidlnode.c	Fri Jan 11 23:59:49 2008
@@ -764,6 +764,67 @@
   return size;
 }
 
+int
+g_idl_node_cmp (GIdlNode *node,
+		GIdlNode *other)
+{
+  if (node->type < other->type)
+    return -1;
+  else if (node->type > other->type)
+    return 1;
+  else
+    return strcmp (node->name, other->name);
+}
+
+void
+g_idl_node_add_member (GIdlNode         *node,
+		       GIdlNodeFunction *member)
+{
+  g_return_if_fail (node != NULL);
+  g_return_if_fail (member != NULL);
+		    
+  switch (node->type)
+    {
+    case G_IDL_NODE_OBJECT:
+    case G_IDL_NODE_INTERFACE:
+      {
+	GIdlNodeInterface *iface = (GIdlNodeInterface *)node;
+	iface->members =
+	  g_list_insert_sorted (iface->members, member,
+				(GCompareFunc) g_idl_node_cmp);
+	break;
+      }
+    case G_IDL_NODE_BOXED:
+      {
+	GIdlNodeBoxed *boxed = (GIdlNodeBoxed *)node;
+	boxed->members =
+	  g_list_insert_sorted (boxed->members, member,
+				(GCompareFunc) g_idl_node_cmp);
+	break;
+      }
+    case G_IDL_NODE_STRUCT:
+      {
+	GIdlNodeStruct *struct_ = (GIdlNodeStruct *)node;
+	struct_->members =
+	  g_list_insert_sorted (struct_->members, member,
+				(GCompareFunc) g_idl_node_cmp);
+	break;
+      }
+    case G_IDL_NODE_UNION:
+      {
+	GIdlNodeUnion *union_ = (GIdlNodeUnion *)node;
+	union_->members =
+	  g_list_insert_sorted (union_->members, member,
+				(GCompareFunc) g_idl_node_cmp);
+	break;
+      }
+    default:
+      g_error ("Cannot add a member to unknown type tag type %d\n",
+	       node->type);
+      break;
+    }
+}
+
 static gint64
 parse_int_value (const gchar *str)
 {

Modified: trunk/src/gidlnode.h
==============================================================================
--- trunk/src/gidlnode.h	(original)
+++ trunk/src/gidlnode.h	Fri Jan 11 23:59:49 2008
@@ -317,7 +317,10 @@
 				      guchar      *data,
 				      guint32     *offset,
                                       guint32     *offset2);
-
+int       g_idl_node_cmp             (GIdlNode    *node,
+				      GIdlNode    *other);
+void      g_idl_node_add_member      (GIdlNode         *node,
+				      GIdlNodeFunction *member);
 guint32   write_string               (const gchar *str,
 				      GHashTable  *strings, 
 				      guchar      *data,

Modified: trunk/src/scanner.c
==============================================================================
--- trunk/src/scanner.c	(original)
+++ trunk/src/scanner.c	Fri Jan 11 23:59:49 2008
@@ -40,23 +40,6 @@
 
 static void g_igenerator_parse_macros (GIGenerator * igenerator);
 
-static int
-g_idl_node_cmp (GIdlNode * a, GIdlNode * b)
-{
-  if (a->type < b->type)
-    {
-      return -1;
-    }
-  else if (a->type > b->type)
-    {
-      return 1;
-    }
-  else
-    {
-      return strcmp (a->name, b->name);
-    }
-}
-
 static GIGenerator *
 g_igenerator_new (const gchar *namespace,
 		  const gchar *shared_library)
@@ -104,36 +87,99 @@
 }
 
 static GIdlNodeType *
-get_type_from_type_id (GType type_id)
+create_node_from_gtype (GType type_id)
 {
-  GIdlNodeType *gitype = (GIdlNodeType *) g_idl_node_new (G_IDL_NODE_TYPE);
+  GIdlNodeType *node;
+  GType fundamental;
 
-  GType type_fundamental = g_type_fundamental (type_id);
+  node = (GIdlNodeType *) g_idl_node_new (G_IDL_NODE_TYPE);
 
-  if (type_fundamental == G_TYPE_STRING)
+  fundamental = g_type_fundamental (type_id);
+  switch (fundamental)
     {
-      gitype->unparsed = g_strdup ("char*");
-    }
-  else if (type_id == G_TYPE_STRV)
-    {
-      gitype->unparsed = g_strdup ("char*[]");
-    }
-  else if (type_fundamental == G_TYPE_INTERFACE
-	   || type_fundamental == G_TYPE_BOXED
-	   || type_fundamental == G_TYPE_OBJECT)
-    {
-      gitype->unparsed = g_strdup_printf ("%s*", g_type_name (type_id));
-    }
-  else if (type_fundamental == G_TYPE_PARAM)
-    {
-      gitype->unparsed = g_strdup ("GParamSpec*");
+    case G_TYPE_STRING:
+      node->unparsed = g_strdup ("char*");
+      break;
+    case G_TYPE_INTERFACE:
+    case G_TYPE_BOXED:
+    case G_TYPE_OBJECT:
+      node->unparsed = g_strdup_printf ("%s*", g_type_name (type_id));
+      break;
+    case G_TYPE_PARAM:
+      node->unparsed = g_strdup ("GParamSpec*");
+      break;
+    default:
+      if (fundamental == G_TYPE_STRV)
+	node->unparsed = g_strdup ("char*[]");
+      else
+	node->unparsed = g_strdup (g_type_name (type_id));
+      break;
     }
-  else
+
+  return node;
+}
+
+static GIdlNodeType *
+create_node_from_ctype (CType * ctype)
+{
+  GIdlNodeType *node;
+
+  node = (GIdlNodeType *) g_idl_node_new (G_IDL_NODE_TYPE);
+
+  switch (ctype->type)
     {
-      gitype->unparsed = g_strdup (g_type_name (type_id));
+    case CTYPE_VOID:
+      node->unparsed = g_strdup ("void");
+      break;
+    case CTYPE_BASIC_TYPE:
+      node->unparsed = g_strdup (ctype->name);
+      break;
+    case CTYPE_TYPEDEF:
+      node->unparsed = g_strdup (ctype->name);
+      break;
+    case CTYPE_STRUCT:
+      if (ctype->name == NULL)
+	/* anonymous struct */
+	node->unparsed = g_strdup ("gpointer");
+      else
+	node->unparsed = g_strdup_printf ("struct %s", ctype->name);
+      break;
+    case CTYPE_UNION:
+      if (ctype->name == NULL)
+	/* anonymous union */
+	node->unparsed = g_strdup ("gpointer");
+      else
+	node->unparsed = g_strdup_printf ("union %s", ctype->name);
+      break;
+    case CTYPE_ENUM:
+      if (ctype->name == NULL)
+	/* anonymous enum */
+	node->unparsed = g_strdup ("gint");
+      else
+	node->unparsed = g_strdup_printf ("enum %s", ctype->name);
+      break;
+    case CTYPE_POINTER:
+      if (ctype->base_type->type == CTYPE_FUNCTION)
+	/* anonymous function pointer */
+	node->unparsed = g_strdup ("GCallback");
+      else
+	{
+	  GIdlNodeType *gibasetype = create_node_from_ctype (ctype->base_type);
+	  node->unparsed = g_strdup_printf ("%s*", gibasetype->unparsed);
+	}
+      break;
+    case CTYPE_ARRAY:
+      {
+	GIdlNodeType *gibasetype = create_node_from_ctype (ctype->base_type);
+	node->unparsed = g_strdup_printf ("%s[]", gibasetype->unparsed);
+	break;
+      }
+    default:
+      node->unparsed = g_strdup ("unknown");
+      break;
     }
 
-  return gitype;
+  return node;
 }
 
 static char *
@@ -147,18 +193,18 @@
 
 static void
 g_igenerator_process_properties (GIGenerator * igenerator,
-				 GIdlNodeInterface * ginode, GType type_id)
+				 GIdlNodeInterface * node, GType type_id)
 {
   int i;
   guint n_properties;
   GParamSpec **properties;
 
-  if (ginode->node.type == G_IDL_NODE_OBJECT)
+  if (node->node.type == G_IDL_NODE_OBJECT)
     {
       GObjectClass *type_class = g_type_class_ref (type_id);
       properties = g_object_class_list_properties (type_class, &n_properties);
     }
-  else if (ginode->node.type == G_IDL_NODE_INTERFACE)
+  else if (node->node.type == G_IDL_NODE_INTERFACE)
     {
       GTypeInterface *iface = g_type_default_interface_ref (type_id);
       properties = g_object_interface_list_properties (iface, &n_properties);
@@ -179,10 +225,10 @@
 	}
       giprop = (GIdlNodeProperty *) g_idl_node_new (G_IDL_NODE_PROPERTY);
       giprop->node.name = properties[i]->name;
-      ginode->members =
-	g_list_insert_sorted (ginode->members, giprop,
+      node->members =
+	g_list_insert_sorted (node->members, giprop,
 			      (GCompareFunc) g_idl_node_cmp);
-      giprop->type = get_type_from_type_id (properties[i]->value_type);
+      giprop->type = create_node_from_gtype (properties[i]->value_type);
       giprop->readable = (properties[i]->flags & G_PARAM_READABLE) != 0;
       giprop->writable = (properties[i]->flags & G_PARAM_WRITABLE) != 0;
       giprop->construct = (properties[i]->flags & G_PARAM_CONSTRUCT) != 0;
@@ -193,7 +239,7 @@
 
 static void
 g_igenerator_process_signals (GIGenerator * igenerator,
-			      GIdlNodeInterface * ginode, GType type_id)
+			      GIdlNodeInterface * node, GType type_id)
 {
   int i, j;
   guint n_signal_ids;
@@ -208,8 +254,8 @@
       g_signal_query (signal_ids[i], &signal_query);
       gisig = (GIdlNodeSignal *) g_idl_node_new (G_IDL_NODE_SIGNAL);
       gisig->node.name = g_strdup (signal_query.signal_name);
-      ginode->members =
-	g_list_insert_sorted (ginode->members, gisig,
+      node->members =
+	g_list_insert_sorted (node->members, gisig,
 			      (GCompareFunc) g_idl_node_cmp);
 
       gisig->run_first =
@@ -222,17 +268,17 @@
       giparam = (GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
       gisig->parameters = g_list_append (gisig->parameters, giparam);
       giparam->node.name = g_strdup ("object");
-      giparam->type = get_type_from_type_id (type_id);
+      giparam->type = create_node_from_gtype (type_id);
 
       for (j = 0; j < signal_query.n_params; j++)
 	{
 	  giparam = (GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
 	  gisig->parameters = g_list_append (gisig->parameters, giparam);
 	  giparam->node.name = g_strdup_printf ("p%d", j);
-	  giparam->type = get_type_from_type_id (signal_query.param_types[j]);
+	  giparam->type = create_node_from_gtype (signal_query.param_types[j]);
 	}
       gisig->result = (GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
-      gisig->result->type = get_type_from_type_id (signal_query.return_type);
+      gisig->result->type = create_node_from_gtype (signal_query.return_type);
     }
 }
 
@@ -259,21 +305,21 @@
 
 {
   char *alt_lower_case_prefix;
-  GIdlNodeInterface *ginode;
+  GIdlNodeInterface *node;
   guint n_type_interfaces;
   GType *type_interfaces;
   int i;
 
-  ginode = (GIdlNodeInterface *) g_idl_node_new (G_IDL_NODE_OBJECT);
-  ginode->node.name = g_strdup (g_type_name (type_id));
+  node = (GIdlNodeInterface *) g_idl_node_new (G_IDL_NODE_OBJECT);
+  node->node.name = g_strdup (g_type_name (type_id));
   igenerator->module->entries =
-    g_list_insert_sorted (igenerator->module->entries, ginode,
+    g_list_insert_sorted (igenerator->module->entries, node,
 			  (GCompareFunc) g_idl_node_cmp);
-  g_hash_table_insert (igenerator->type_map, ginode->node.name,
-		       ginode);
+  g_hash_table_insert (igenerator->type_map, node->node.name,
+		       node);
   g_hash_table_insert (igenerator->type_by_lower_case_prefix,
-		       lower_case_prefix, ginode);
-  alt_lower_case_prefix = g_ascii_strdown (ginode->node.name, -1);
+		       lower_case_prefix, node);
+  alt_lower_case_prefix = g_ascii_strdown (node->node.name, -1);
   
   if (strcmp (alt_lower_case_prefix, lower_case_prefix) != 0)
     {
@@ -281,16 +327,16 @@
        * for GdkWindow
        */
       g_hash_table_insert (igenerator->type_by_lower_case_prefix,
-			   alt_lower_case_prefix, ginode);
+			   alt_lower_case_prefix, node);
     }
   else
     {
       g_free (alt_lower_case_prefix);
     }
 
-  ginode->gtype_name = ginode->node.name;
-  ginode->gtype_init = g_strdup (symbol_name);
-  ginode->parent = g_strdup (lookup_symbol (igenerator,
+  node->gtype_name = node->node.name;
+  node->gtype_init = g_strdup (symbol_name);
+  node->parent = g_strdup (lookup_symbol (igenerator,
 					    g_type_name (g_type_parent (type_id))));
   
   type_interfaces = g_type_interfaces (type_id, &n_type_interfaces);
@@ -304,17 +350,17 @@
 	  iface_name[strlen (iface_name) - strlen ("Iface")] =
 	    '\0';
 	}
-      ginode->interfaces =
-	g_list_append (ginode->interfaces, iface_name);
+      node->interfaces =
+	g_list_append (node->interfaces, iface_name);
     }
   
   g_hash_table_insert (igenerator->symbols,
-		       g_strdup (ginode->gtype_name),
+		       g_strdup (node->gtype_name),
 		       /* FIXME: Strip igenerator->namespace */
-		       g_strdup (ginode->node.name));
+		       g_strdup (node->node.name));
   
-  g_igenerator_process_properties (igenerator, ginode, type_id);
-  g_igenerator_process_signals (igenerator, ginode, type_id);
+  g_igenerator_process_properties (igenerator, node, type_id);
+  g_igenerator_process_signals (igenerator, node, type_id);
 }
 
 static void
@@ -324,30 +370,30 @@
 			       char *lower_case_prefix)
 
 {
-  GIdlNodeInterface *ginode;
+  GIdlNodeInterface *node;
   gboolean is_gobject = FALSE;
   guint n_iface_prereqs;
   GType *iface_prereqs;
   int i;
 
-  ginode = (GIdlNodeInterface *) g_idl_node_new (G_IDL_NODE_INTERFACE);
-  ginode->node.name = g_strdup (g_type_name (type_id));
+  node = (GIdlNodeInterface *) g_idl_node_new (G_IDL_NODE_INTERFACE);
+  node->node.name = g_strdup (g_type_name (type_id));
   
   /* workaround for AtkImplementorIface */
-  if (g_str_has_suffix (ginode->node.name, "Iface"))
+  if (g_str_has_suffix (node->node.name, "Iface"))
     {
-      ginode->node.name[strlen (ginode->node.name) -
+      node->node.name[strlen (node->node.name) -
 			strlen ("Iface")] = '\0';
     }
   igenerator->module->entries =
-    g_list_insert_sorted (igenerator->module->entries, ginode,
+    g_list_insert_sorted (igenerator->module->entries, node,
 			  (GCompareFunc) g_idl_node_cmp);
-  g_hash_table_insert (igenerator->type_map, ginode->node.name,
-		       ginode);
+  g_hash_table_insert (igenerator->type_map, node->node.name,
+		       node);
   g_hash_table_insert (igenerator->type_by_lower_case_prefix,
-		       lower_case_prefix, ginode);
-  ginode->gtype_name = ginode->node.name;
-  ginode->gtype_init = g_strdup (symbol_name);
+		       lower_case_prefix, node);
+  node->gtype_name = node->node.name;
+  node->gtype_init = g_strdup (symbol_name);
   
   iface_prereqs =
     g_type_interface_prerequisites (type_id, &n_iface_prereqs);
@@ -358,17 +404,17 @@
 	{
 	  is_gobject = TRUE;
 	}
-      ginode->prerequisites =
-	g_list_append (ginode->prerequisites,
+      node->prerequisites =
+	g_list_append (node->prerequisites,
 		       g_strdup (g_type_name (iface_prereqs[i])));
     }
   
   if (is_gobject)
-    g_igenerator_process_properties (igenerator, ginode, type_id);
+    g_igenerator_process_properties (igenerator, node, type_id);
   else
     g_type_default_interface_ref (type_id);
 
-  g_igenerator_process_signals (igenerator, ginode, type_id);
+  g_igenerator_process_signals (igenerator, node, type_id);
 }
 
 static void
@@ -377,18 +423,18 @@
 			   GType type_id,
 			   char *lower_case_prefix)
 {
-  GIdlNodeBoxed *ginode =
+  GIdlNodeBoxed *node =
     (GIdlNodeBoxed *) g_idl_node_new (G_IDL_NODE_BOXED);
-  ginode->node.name = g_strdup (g_type_name (type_id));
+  node->node.name = g_strdup (g_type_name (type_id));
   igenerator->module->entries =
-    g_list_insert_sorted (igenerator->module->entries, ginode,
+    g_list_insert_sorted (igenerator->module->entries, node,
 			  (GCompareFunc) g_idl_node_cmp);
-  g_hash_table_insert (igenerator->type_map, ginode->node.name,
-		       ginode);
+  g_hash_table_insert (igenerator->type_map, node->node.name,
+		       node);
   g_hash_table_insert (igenerator->type_by_lower_case_prefix,
-		       lower_case_prefix, ginode);
-  ginode->gtype_name = ginode->node.name;
-  ginode->gtype_init = g_strdup (symbol_name);
+		       lower_case_prefix, node);
+  node->gtype_name = node->node.name;
+  node->gtype_init = g_strdup (symbol_name);
 }
 
 static void
@@ -397,21 +443,21 @@
 			  GType type_id,
 			  char *lower_case_prefix)
 {
-  GIdlNodeEnum *ginode;
+  GIdlNodeEnum *node;
   int i;
   GEnumClass *type_class;
   
-  ginode = (GIdlNodeEnum *) g_idl_node_new (G_IDL_NODE_ENUM);
-  ginode->node.name = g_strdup (g_type_name (type_id));
+  node = (GIdlNodeEnum *) g_idl_node_new (G_IDL_NODE_ENUM);
+  node->node.name = g_strdup (g_type_name (type_id));
   igenerator->module->entries =
-    g_list_insert_sorted (igenerator->module->entries, ginode,
+    g_list_insert_sorted (igenerator->module->entries, node,
 			  (GCompareFunc) g_idl_node_cmp);
-  g_hash_table_insert (igenerator->type_map, ginode->node.name,
-		       ginode);
+  g_hash_table_insert (igenerator->type_map, node->node.name,
+		       node);
   g_hash_table_insert (igenerator->type_by_lower_case_prefix,
-		       lower_case_prefix, ginode);
-  ginode->gtype_name = ginode->node.name;
-  ginode->gtype_init = g_strdup (symbol_name);
+		       lower_case_prefix, node);
+  node->gtype_name = node->node.name;
+  node->gtype_init = g_strdup (symbol_name);
   
   type_class = g_type_class_ref (type_id);
 
@@ -419,7 +465,7 @@
     {
       GIdlNodeValue *gival =
 	(GIdlNodeValue *) g_idl_node_new (G_IDL_NODE_VALUE);
-      ginode->values = g_list_append (ginode->values, gival);
+      node->values = g_list_append (node->values, gival);
       gival->node.name =
 	g_strdup (type_class->values[i].value_name);
       gival->value = type_class->values[i].value;
@@ -432,21 +478,21 @@
 			   GType type_id,
 			   char *lower_case_prefix)
 {
-  GIdlNodeEnum *ginode;
+  GIdlNodeEnum *node;
   GFlagsClass *type_class;
   int i;
   
-  ginode = (GIdlNodeEnum *) g_idl_node_new (G_IDL_NODE_FLAGS);
-  ginode->node.name = g_strdup (g_type_name (type_id));
+  node = (GIdlNodeEnum *) g_idl_node_new (G_IDL_NODE_FLAGS);
+  node->node.name = g_strdup (g_type_name (type_id));
   igenerator->module->entries =
-    g_list_insert_sorted (igenerator->module->entries, ginode,
+    g_list_insert_sorted (igenerator->module->entries, node,
 			  (GCompareFunc) g_idl_node_cmp);
-  g_hash_table_insert (igenerator->type_map, ginode->node.name,
-		       ginode);
+  g_hash_table_insert (igenerator->type_map, node->node.name,
+		       node);
   g_hash_table_insert (igenerator->type_by_lower_case_prefix,
-		       lower_case_prefix, ginode);
-  ginode->gtype_name = ginode->node.name;
-  ginode->gtype_init = g_strdup (symbol_name);
+		       lower_case_prefix, node);
+  node->gtype_name = node->node.name;
+  node->gtype_init = g_strdup (symbol_name);
   
   type_class = g_type_class_ref (type_id);
   
@@ -454,7 +500,7 @@
     {
       GIdlNodeValue *gival =
 	(GIdlNodeValue *) g_idl_node_new (G_IDL_NODE_VALUE);
-      ginode->values = g_list_append (ginode->values, gival);
+      node->values = g_list_append (node->values, gival);
       gival->node.name =
 	g_strdup (type_class->values[i].value_name);
       gival->value = type_class->values[i].value;
@@ -541,160 +587,53 @@
     }
 }
 
-static GIdlNodeType *
-get_type_from_ctype (CType * ctype)
-{
-  GIdlNodeType *gitype = (GIdlNodeType *) g_idl_node_new (G_IDL_NODE_TYPE);
-  if (ctype->type == CTYPE_VOID)
-    {
-      gitype->unparsed = g_strdup ("void");
-    }
-  else if (ctype->type == CTYPE_BASIC_TYPE)
-    {
-      gitype->unparsed = g_strdup (ctype->name);
-    }
-  else if (ctype->type == CTYPE_TYPEDEF)
-    {
-      gitype->unparsed = g_strdup (ctype->name);
-    }
-  else if (ctype->type == CTYPE_STRUCT)
-    {
-      if (ctype->name == NULL)
-	{
-	  /* anonymous struct */
-	  gitype->unparsed = g_strdup ("gpointer");
-	}
-      else
-	{
-	  gitype->unparsed = g_strdup_printf ("struct %s", ctype->name);
-	}
-    }
-  else if (ctype->type == CTYPE_UNION)
-    {
-      if (ctype->name == NULL)
-	{
-	  /* anonymous union */
-	  gitype->unparsed = g_strdup ("gpointer");
-	}
-      else
-	{
-	  gitype->unparsed = g_strdup_printf ("union %s", ctype->name);
-	}
-    }
-  else if (ctype->type == CTYPE_ENUM)
-    {
-      if (ctype->name == NULL)
-	{
-	  /* anonymous enum */
-	  gitype->unparsed = g_strdup ("gint");
-	}
-      else
-	{
-	  gitype->unparsed = g_strdup_printf ("enum %s", ctype->name);
-	}
-    }
-  else if (ctype->type == CTYPE_POINTER)
-    {
-      if (ctype->base_type->type == CTYPE_FUNCTION)
-	{
-	  /* anonymous function pointer */
-	  gitype->unparsed = g_strdup ("GCallback");
-	}
-      else
-	{
-	  GIdlNodeType *gibasetype = get_type_from_ctype (ctype->base_type);
-	  gitype->unparsed = g_strdup_printf ("%s*", gibasetype->unparsed);
-	}
-    }
-  else if (ctype->type == CTYPE_ARRAY)
-    {
-      GIdlNodeType *gibasetype = get_type_from_ctype (ctype->base_type);
-      gitype->unparsed = g_strdup_printf ("%s[]", gibasetype->unparsed);
-    }
-  else
-    {
-      gitype->unparsed = g_strdup ("unknown");
-    }
-  return gitype;
-}
-
 static void
 g_igenerator_process_function_symbol (GIGenerator * igenerator, CSymbol * sym)
 {
-  GIdlNodeFunction *gifunc =
-    (GIdlNodeFunction *) g_idl_node_new (G_IDL_NODE_FUNCTION);
-  /* check whether this is a type method */
-  char *last_underscore = strrchr (sym->ident, '_');
+  GIdlNodeFunction *func;
+  char *last_underscore;
   GList *param_l;
   int i;
   GSList *l;
 
+  func = (GIdlNodeFunction *) g_idl_node_new (G_IDL_NODE_FUNCTION);
+  
+  /* check whether this is a type method */
+  last_underscore = strrchr (sym->ident, '_');
+
   while (last_underscore != NULL)
     {
-      char *prefix =
-	str_replace (g_strndup (sym->ident, last_underscore - sym->ident),
-		     "_", "");
-      GIdlNode *ginode =
-	g_hash_table_lookup (igenerator->type_by_lower_case_prefix, prefix);
-      if (ginode != NULL)
-	{
-	  gifunc->node.name = g_strdup (last_underscore + 1);
-	  if (strcmp (gifunc->node.name, "get_type") == 0)
-	    {
-	      /* ignore get_type functions in registered types */
-	      return;
-	    }
-	  if ((ginode->type == G_IDL_NODE_OBJECT
-	       || ginode->type == G_IDL_NODE_BOXED)
-	      && g_str_has_prefix (gifunc->node.name, "new"))
-	    {
-	      gifunc->is_constructor = TRUE;
-	    }
+      char *prefix;
+      GIdlNode *node;
+
+      prefix = g_strndup (sym->ident, last_underscore - sym->ident);
+      prefix = str_replace (prefix, "_", "");
+
+      node = g_hash_table_lookup (igenerator->type_by_lower_case_prefix,
+				  prefix);
+      if (node != NULL)
+	{
+	  func->node.name = g_strdup (last_underscore + 1);
+
+	  /* ignore get_type functions in registered types */
+	  if (strcmp (func->node.name, "get_type") == 0)
+	    return;
+
+	  if ((node->type == G_IDL_NODE_OBJECT ||
+	       node->type == G_IDL_NODE_BOXED) &&
+	      g_str_has_prefix (func->node.name, "new"))
+	    func->is_constructor = TRUE;
 	  else
-	    {
-	      gifunc->is_method = TRUE;
-	    }
-	  if (ginode->type == G_IDL_NODE_OBJECT
-	      || ginode->type == G_IDL_NODE_INTERFACE)
-	    {
-	      GIdlNodeInterface *giiface = (GIdlNodeInterface *) ginode;
-	      giiface->members =
-		g_list_insert_sorted (giiface->members, gifunc,
-				      (GCompareFunc) g_idl_node_cmp);
-	      break;
-	    }
-	  else if (ginode->type == G_IDL_NODE_BOXED)
-	    {
-	      GIdlNodeBoxed *giboxed = (GIdlNodeBoxed *) ginode;
-	      giboxed->members =
-		g_list_insert_sorted (giboxed->members, gifunc,
-				      (GCompareFunc) g_idl_node_cmp);
-	      break;
-	    }
-	  else if (ginode->type == G_IDL_NODE_STRUCT)
-	    {
-	      GIdlNodeStruct *gistruct = (GIdlNodeStruct *) ginode;
-	      gistruct->members =
-		g_list_insert_sorted (gistruct->members, gifunc,
-				      (GCompareFunc) g_idl_node_cmp);
-	      break;
-	    }
-	  else if (ginode->type == G_IDL_NODE_UNION)
-	    {
-	      GIdlNodeUnion *giunion = (GIdlNodeUnion *) ginode;
-	      giunion->members =
-		g_list_insert_sorted (giunion->members, gifunc,
-				      (GCompareFunc) g_idl_node_cmp);
-	      break;
-	    }
+	    func->is_method = TRUE;
+
+	  g_idl_node_add_member (node, func);
+	  break;
 	}
       else if (strcmp (igenerator->lower_case_namespace, prefix) == 0)
 	{
-	  gifunc->node.name = g_strdup (last_underscore + 1);
-	  gifunc->is_constructor = FALSE;
-	  gifunc->is_method = FALSE;
+	  func->node.name = g_strdup (last_underscore + 1);
 	  igenerator->module->entries =
-	    g_list_insert_sorted (igenerator->module->entries, gifunc,
+	    g_list_insert_sorted (igenerator->module->entries, func,
 				  (GCompareFunc) g_idl_node_cmp);
 	  break;
 	}
@@ -703,36 +642,35 @@
     }
 
   /* create a namespace function if no prefix matches */
-  if (gifunc->node.name == NULL)
+  if (func->node.name == NULL)
     {
-      gifunc->node.name = sym->ident;
-      gifunc->is_constructor = FALSE;
-      gifunc->is_method = FALSE;
+      func->node.name = sym->ident;
+      func->is_constructor = FALSE;
+      func->is_method = FALSE;
       igenerator->module->entries =
-	g_list_insert_sorted (igenerator->module->entries, gifunc,
+	g_list_insert_sorted (igenerator->module->entries, func,
 			      (GCompareFunc) g_idl_node_cmp);
     }
 
-  gifunc->symbol = sym->ident;
-  gifunc->result = (GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
-  gifunc->result->type = get_type_from_ctype (sym->base_type->base_type);
+  func->symbol = sym->ident;
+  func->result = (GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
+  func->result->type = create_node_from_ctype (sym->base_type->base_type);
 
   for (param_l = sym->base_type->child_list, i = 1; param_l != NULL;
        param_l = param_l->next, i++)
     {
       CSymbol *param_sym = param_l->data;
-      GIdlNodeParam *param =
-	(GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
+      GIdlNodeParam *param;
+
+      param = (GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
+      param->type = create_node_from_ctype (param_sym->base_type);
+
       if (param_sym->ident == NULL)
-	{
-	  param->node.name = g_strdup_printf ("p%d", i);
-	}
+	param->node.name = g_strdup_printf ("p%d", i);
       else
-	{
-	  param->node.name = param_sym->ident;
-	}
-      param->type = get_type_from_ctype (param_sym->base_type);
-      gifunc->parameters = g_list_append (gifunc->parameters, param);
+	param->node.name = param_sym->ident;
+
+      func->parameters = g_list_append (func->parameters, param);
     }
 
   for (l = sym->directives; l; l = l->next)
@@ -740,7 +678,7 @@
       CDirective *directive = (CDirective*)l->data;
 
       if (!strcmp (directive->name, "deprecated"))
-	gifunc->deprecated = TRUE;
+	func->deprecated = TRUE;
       else
 	g_printerr ("Unknown function directive: %s\n",
 		    directive->name);
@@ -752,19 +690,19 @@
 						  CSymbol * sym,
 						  CType * struct_type)
 {
-  GIdlNodeStruct *ginode =
+  GIdlNodeStruct *node =
     (GIdlNodeStruct *) g_idl_node_new (G_IDL_NODE_STRUCT);
   GList *member_l;
   char *lower_case_prefix;
 
-  ginode->node.name = sym->ident;
+  node->node.name = sym->ident;
   igenerator->module->entries =
-    g_list_insert_sorted (igenerator->module->entries, ginode,
+    g_list_insert_sorted (igenerator->module->entries, node,
 			  (GCompareFunc) g_idl_node_cmp);
   lower_case_prefix = g_ascii_strdown (sym->ident, -1);
-  g_hash_table_insert (igenerator->type_map, sym->ident, ginode);
+  g_hash_table_insert (igenerator->type_map, sym->ident, node);
   g_hash_table_insert (igenerator->type_by_lower_case_prefix,
-		       lower_case_prefix, ginode);
+		       lower_case_prefix, node);
 
   for (member_l = struct_type->child_list; member_l != NULL;
        member_l = member_l->next)
@@ -773,9 +711,9 @@
       GIdlNodeField *gifield =
 	(GIdlNodeField *) g_idl_node_new (G_IDL_NODE_FIELD);
 
-      ginode->members = g_list_append (ginode->members, gifield);
+      node->members = g_list_append (node->members, gifield);
       gifield->node.name = member->ident;
-      gifield->type = get_type_from_ctype (member->base_type);
+      gifield->type = create_node_from_ctype (member->base_type);
     }
 }
 
@@ -784,7 +722,7 @@
 {
   CType *struct_type = sym->base_type;
   gboolean opaque_type = FALSE;
-  GIdlNode *gitype;
+  GIdlNode *type;
   
   if (struct_type->child_list == NULL)
     {
@@ -804,15 +742,15 @@
       opaque_type = TRUE;
     }
   
-  gitype = g_hash_table_lookup (igenerator->type_map, sym->ident);
-  if (gitype != NULL)
+  type = g_hash_table_lookup (igenerator->type_map, sym->ident);
+  if (type != NULL)
     {
       /* struct of a GTypeInstance */
       if (!opaque_type
-	  && (gitype->type == G_IDL_NODE_OBJECT
-	      || gitype->type == G_IDL_NODE_INTERFACE))
+	  && (type->type == G_IDL_NODE_OBJECT
+	      || type->type == G_IDL_NODE_INTERFACE))
 	{
-	  GIdlNodeInterface *ginode = (GIdlNodeInterface *) gitype;
+	  GIdlNodeInterface *node = (GIdlNodeInterface *) type;
 	  GList *member_l;
 	  /* ignore first field => parent */
 	  for (member_l = struct_type->child_list->next; member_l != NULL;
@@ -827,14 +765,14 @@
 		}
 	      GIdlNodeField *gifield =
 		(GIdlNodeField *) g_idl_node_new (G_IDL_NODE_FIELD);
-	      ginode->members = g_list_append (ginode->members, gifield);
+	      node->members = g_list_append (node->members, gifield);
 	      gifield->node.name = member->ident;
-	      gifield->type = get_type_from_ctype (member->base_type);
+	      gifield->type = create_node_from_ctype (member->base_type);
 	    }
 	}
-      else if (gitype->type == G_IDL_NODE_BOXED)
+      else if (type->type == G_IDL_NODE_BOXED)
 	{
-	  GIdlNodeBoxed *ginode = (GIdlNodeBoxed *) gitype;
+	  GIdlNodeBoxed *node = (GIdlNodeBoxed *) type;
 	  GList *member_l;
 	  for (member_l = struct_type->child_list; member_l != NULL;
 	       member_l = member_l->next)
@@ -842,9 +780,9 @@
 	      CSymbol *member = member_l->data;
 	      GIdlNodeField *gifield =
 		(GIdlNodeField *) g_idl_node_new (G_IDL_NODE_FIELD);
-	      ginode->members = g_list_append (ginode->members, gifield);
+	      node->members = g_list_append (node->members, gifield);
 	      gifield->node.name = member->ident;
-	      gifield->type = get_type_from_ctype (member->base_type);
+	      gifield->type = create_node_from_ctype (member->base_type);
 	    }
 	}
     }
@@ -855,7 +793,7 @@
     {
       char *base_name;
       GList *member_l;
-      GIdlNodeInterface *ginode;
+      GIdlNodeInterface *node;
 
       if (g_str_has_suffix (sym->ident, "Interface"))
 	{
@@ -868,16 +806,16 @@
 	  base_name =
 	    g_strndup (sym->ident, strlen (sym->ident) - strlen ("Class"));
 	}
-      gitype = g_hash_table_lookup (igenerator->type_map, base_name);
-      if (gitype == NULL
-	  || (gitype->type != G_IDL_NODE_OBJECT
-	      && gitype->type != G_IDL_NODE_INTERFACE))
+      type = g_hash_table_lookup (igenerator->type_map, base_name);
+      if (type == NULL
+	  || (type->type != G_IDL_NODE_OBJECT
+	      && type->type != G_IDL_NODE_INTERFACE))
 	{
 	  g_igenerator_process_unregistered_struct_typedef (igenerator, sym,
 							    struct_type);
 	  return;
 	}
-      ginode = (GIdlNodeInterface *) gitype;
+      node = (GIdlNodeInterface *) type;
 
       /* ignore first field => parent */
       for (member_l = struct_type->child_list->next; member_l != NULL;
@@ -899,7 +837,7 @@
 	      int i;
 	      GIdlNodeVFunc *givfunc;
 	      
-	      for (type_member_l = ginode->members; type_member_l != NULL;
+	      for (type_member_l = node->members; type_member_l != NULL;
 		   type_member_l = type_member_l->next)
 		{
 		  GIdlNode *type_member = type_member_l->data;
@@ -939,13 +877,13 @@
 
 	      givfunc = (GIdlNodeVFunc *) g_idl_node_new (G_IDL_NODE_VFUNC);
 	      givfunc->node.name = member->ident;
-	      ginode->members =
-		g_list_insert_sorted (ginode->members, givfunc,
+	      node->members =
+		g_list_insert_sorted (node->members, givfunc,
 				      (GCompareFunc) g_idl_node_cmp);
 	      givfunc->result =
 		(GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
 	      givfunc->result->type =
-		get_type_from_ctype (member->base_type->base_type->base_type);
+		create_node_from_ctype (member->base_type->base_type->base_type);
 	      for (param_l = member->base_type->base_type->child_list, i = 1;
 		   param_l != NULL; param_l = param_l->next, i++)
 		{
@@ -960,7 +898,7 @@
 		    {
 		      param->node.name = param_sym->ident;
 		    }
-		  param->type = get_type_from_ctype (param_sym->base_type);
+		  param->type = create_node_from_ctype (param_sym->base_type);
 		  givfunc->parameters =
 		    g_list_append (givfunc->parameters, param);
 		}
@@ -983,7 +921,7 @@
 {
   CType *union_type = sym->base_type;
   gboolean opaque_type = FALSE;
-  GIdlNode *gitype;
+  GIdlNode *type;
   
   if (union_type->child_list == NULL)
     {
@@ -1001,11 +939,11 @@
       opaque_type = TRUE;
     }
 
-  gitype = g_hash_table_lookup (igenerator->type_map, sym->ident);
-  if (gitype != NULL)
+  type = g_hash_table_lookup (igenerator->type_map, sym->ident);
+  if (type != NULL)
     {
-      g_assert (gitype->type == G_IDL_NODE_BOXED);
-      GIdlNodeBoxed *ginode = (GIdlNodeBoxed *) gitype;
+      g_assert (type->type == G_IDL_NODE_BOXED);
+      GIdlNodeBoxed *node = (GIdlNodeBoxed *) type;
       GList *member_l;
       for (member_l = union_type->child_list; member_l != NULL;
 	   member_l = member_l->next)
@@ -1013,37 +951,37 @@
 	  CSymbol *member = member_l->data;
 	  GIdlNodeField *gifield =
 	    (GIdlNodeField *) g_idl_node_new (G_IDL_NODE_FIELD);
-	  ginode->members = g_list_append (ginode->members, gifield);
+	  node->members = g_list_append (node->members, gifield);
 	  gifield->node.name = member->ident;
-	  gifield->type = get_type_from_ctype (member->base_type);
+	  gifield->type = create_node_from_ctype (member->base_type);
 	}
     }
   else
     {
-      GIdlNodeUnion *ginode =
+      GIdlNodeUnion *node =
 	(GIdlNodeUnion *) g_idl_node_new (G_IDL_NODE_UNION);
       char *lower_case_prefix;
       GList *member_l;
       
-      ginode->node.name = sym->ident;
+      node->node.name = sym->ident;
       igenerator->module->entries =
-	g_list_insert_sorted (igenerator->module->entries, ginode,
+	g_list_insert_sorted (igenerator->module->entries, node,
 			      (GCompareFunc) g_idl_node_cmp);
       lower_case_prefix = g_ascii_strdown (sym->ident, -1);
-      g_hash_table_insert (igenerator->type_map, sym->ident, ginode);
+      g_hash_table_insert (igenerator->type_map, sym->ident, node);
       g_hash_table_insert (igenerator->type_by_lower_case_prefix,
-			   lower_case_prefix, ginode);
+			   lower_case_prefix, node);
 
-      ginode->node.name = sym->ident;
+      node->node.name = sym->ident;
       for (member_l = union_type->child_list; member_l != NULL;
 	   member_l = member_l->next)
 	{
 	  CSymbol *member = member_l->data;
 	  GIdlNodeField *gifield =
 	    (GIdlNodeField *) g_idl_node_new (G_IDL_NODE_FIELD);
-	  ginode->members = g_list_append (ginode->members, gifield);
+	  node->members = g_list_append (node->members, gifield);
 	  gifield->node.name = member->ident;
-	  gifield->type = get_type_from_ctype (member->base_type);
+	  gifield->type = create_node_from_ctype (member->base_type);
 	}
     }
 }
@@ -1053,7 +991,7 @@
 {
   CType *enum_type;
   GList *member_l;
-  GIdlNodeEnum *ginode;
+  GIdlNodeEnum *node;
   CSymbol *enum_symbol;
 
   enum_type = sym->base_type;
@@ -1074,16 +1012,16 @@
       return;
     }
   
-  ginode = g_hash_table_lookup (igenerator->type_map, sym->ident);
-  if (ginode != NULL)
+  node = g_hash_table_lookup (igenerator->type_map, sym->ident);
+  if (node != NULL)
     {
       return;
     }
 
-  ginode = (GIdlNodeEnum *) g_idl_node_new (G_IDL_NODE_ENUM);
-  ginode->node.name = sym->ident;
+  node = (GIdlNodeEnum *) g_idl_node_new (G_IDL_NODE_ENUM);
+  node->node.name = sym->ident;
   igenerator->module->entries =
-    g_list_insert_sorted (igenerator->module->entries, ginode,
+    g_list_insert_sorted (igenerator->module->entries, node,
 			  (GCompareFunc) g_idl_node_cmp);
 
   for (member_l = enum_type->child_list; member_l != NULL;
@@ -1092,7 +1030,7 @@
       CSymbol *member = member_l->data;
       GIdlNodeValue *gival =
 	(GIdlNodeValue *) g_idl_node_new (G_IDL_NODE_VALUE);
-      ginode->values = g_list_append (ginode->values, gival);
+      node->values = g_list_append (node->values, gival);
       gival->node.name = member->ident;
       gival->value = member->const_int;
     }
@@ -1117,7 +1055,7 @@
   gifunc->symbol = sym->ident;
   gifunc->result = (GIdlNodeParam *) g_idl_node_new (G_IDL_NODE_PARAM);
   gifunc->result->type =
-    get_type_from_ctype (sym->base_type->base_type->base_type);
+    create_node_from_ctype (sym->base_type->base_type->base_type);
 
   for (param_l = sym->base_type->base_type->child_list, i = 1;
        param_l != NULL; param_l = param_l->next, i++)
@@ -1133,7 +1071,7 @@
 	{
 	  param->node.name = param_sym->ident;
 	}
-      param->type = get_type_from_ctype (param_sym->base_type);
+      param->type = create_node_from_ctype (param_sym->base_type);
       gifunc->parameters = g_list_append (gifunc->parameters, param);
     }
 }
@@ -1196,18 +1134,18 @@
 	    }
 	  else
 	    {
-	      GIdlNodeStruct *ginode =
+	      GIdlNodeStruct *node =
 		(GIdlNodeStruct *) g_idl_node_new (G_IDL_NODE_STRUCT);
 	      char *lower_case_prefix;
 	      
-	      ginode->node.name = sym->ident;
+	      node->node.name = sym->ident;
 	      igenerator->module->entries =
-		g_list_insert_sorted (igenerator->module->entries, ginode,
+		g_list_insert_sorted (igenerator->module->entries, node,
 				      (GCompareFunc) g_idl_node_cmp);
 	      lower_case_prefix = g_ascii_strdown (sym->ident, -1);
-	      g_hash_table_insert (igenerator->type_map, sym->ident, ginode);
+	      g_hash_table_insert (igenerator->type_map, sym->ident, node);
 	      g_hash_table_insert (igenerator->type_by_lower_case_prefix,
-				   lower_case_prefix, ginode);
+				   lower_case_prefix, node);
 	    }
 	}
     }



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