added missing include <assert.h> (not anymore included in libFirm)
[libfirm] / ir / ana2 / pto_name.c
index e77f64e..ce69bd6 100644 (file)
 # include "pto_name.h"
 # include "pto_util.h"
 
+#include <assert.h>
+
+#ifdef HAVE_STRING_H
 # include <string.h>            /* for memcpy */
+#endif
 # include <obstack.h>
 # include <errno.h>
 
@@ -33,6 +37,7 @@
 # include "xmalloc.h"
 
 # include "pto_debug.h"
+# include "gnu_ext.h"
 
 /* Local Defines: */
 # define obstack_chunk_alloc xmalloc
@@ -199,7 +204,7 @@ static int is_field (entity *ent)
 {
   type *tp = get_entity_type (ent);
 
-  if (is_primitive_type (tp) || is_pointer_type (tp)) {
+  if (is_Primitive_type (tp) || is_Pointer_type (tp)) {
     /* actually, we don't get by by restricting ourselves to pointer types */
     return (TRUE);
   } else {
@@ -242,12 +247,14 @@ static entity **collect_fields (type *clazz)
   void *tmp;
 
   if (NULL != get_type_link (clazz)) {
-    DBGPRINT (3, (stdout, "collect_fields(): reusing field list for \"%s\"\n",
+    DBGPRINT (3, (stdout, "%s: reusing field list for \"%s\"\n",
+                  __FUNCTION__,
                   get_type_name (clazz)));
 
     return ((entity **) get_type_link (clazz));
   } else {
-    DBGPRINT (2, (stdout, "collect_fields(): new field list for \"%s\"\n",
+    DBGPRINT (2, (stdout, "%s: new field list for \"%s\"\n",
+                  __FUNCTION__,
                   get_type_name (clazz)));
   }
 
@@ -260,10 +267,10 @@ static entity **collect_fields (type *clazz)
 
   n_fields = obstack_object_size (&obst) / sizeof (void*);
 
-  fields = NALLOC(n_fields * sizeof(*fields));
+  fields = NALLOC (n_fields * sizeof (entity*));
   tmp = obstack_finish(&obst);
 
-  memcpy (fields, tmp, n_fields * sizeof(*fields));
+  memcpy (fields, tmp, n_fields * sizeof (entity*));
 
   obstack_free (&obst, NULL);
 
@@ -338,7 +345,7 @@ static void pto_name_dump_desc (desc_t *desc, FILE *stream)
     for (i = 0; i < obj_desc->n_fields; i ++) {
       entity *field = obj_desc->fields [i];
 
-      if (is_pointer_type (get_entity_type (field))) {
+      if (is_Pointer_type (get_entity_type (field))) {
         const char *ent_name = get_entity_name (field);
 
         fprintf (stream, "|<%i>%s", i, ent_name);
@@ -460,8 +467,8 @@ qset_t *get_entry (desc_t *desc, entity *ent)
     return (arr_desc->value);
   } else {
     assert (0 && "invalid descriptor");
-    return NULL;
   }
+  return NULL;
 }
 
 
@@ -470,14 +477,15 @@ desc_t *new_name (type *tp, ir_node *node, int ctx)
 {
   desc_t *desc = NULL;
 
-  assert ((is_class_type (tp) || is_array_type (tp)) && "unsuitable type");
+  assert ((is_Class_type (tp) || is_Array_type (tp)) && "unsuitable type");
 
-  DBGPRINT (2, (stdout, "new_name(): new name for type \"%s\"\n",
+  DBGPRINT (2, (stdout, "%s: new name for type \"%s\"\n",
+                __FUNCTION__,
                 get_type_name (tp)));
   fflush (stdout);
 
-  if (is_class_type (tp)) {
-    obj_desc_t *obj_desc = NALLOC(sizeof(*obj_desc));
+  if (is_Class_type (tp)) {
+    obj_desc_t *obj_desc = NALLOC (sizeof (obj_desc_t));
     int i;
     int n_fields;
 
@@ -489,14 +497,14 @@ desc_t *new_name (type *tp, ir_node *node, int ctx)
     }
 
     obj_desc->n_fields = n_fields;
-    obj_desc->values = (qset_t**) NALLOC (n_fields * sizeof (qset_t));
+    obj_desc->values = (qset_t**) NALLOC (n_fields * sizeof (qset_t*));
 
     for (i = 0; i < n_fields; i ++) {
       obj_desc->values [i] = qset_new (N_INITIAL_OJBS, qset_obst);
     }
 
     desc = (desc_t*) obj_desc;
-  } else if (is_array_type (tp)) {
+  } else if (is_Array_type (tp)) {
     arr_desc_t *arr_desc = (arr_desc_t*) NALLOC (sizeof (arr_desc_t));
 
     arr_desc->kind = array;
@@ -529,11 +537,12 @@ desc_t *new_ent_name (entity *ent)
   int missing = TRUE;
   type *tp = get_entity_type (ent);
 
-  assert (is_pointer_type (tp));
+  assert (is_Pointer_type (tp));
   tp = get_pointer_points_to_type (tp);
-  assert (is_class_type (tp));
+  assert (is_Class_type (tp));
 
-  DBGPRINT (2, (stdout, "new_ent_name(): new name for entity \"%s\"\n",
+  DBGPRINT (2, (stdout, "%s: new name for entity \"%s\"\n",
+                __FUNCTION__,
                 get_entity_name (ent)));
   DBGEXE (2, (fflush (stdout)));
 
@@ -598,8 +607,8 @@ void pto_dump_names (const char *name)
 
   errno = 0;
   if  (NULL == stream) {
-    fprintf (stderr, "pto_dump_names(): unable to open %s (%s)\n",
-             name, strerror (errno));
+    fprintf (stderr, "%s: unable to open %s (%s)\n",
+             __FUNCTION__, name, strerror (errno));
     return;
   }
 
@@ -618,12 +627,12 @@ void pto_dump_names (const char *name)
 /* Initialise the name module */
 void pto_name_init (void)
 {
-  DBGPRINT (3, (stdout, "(%s:%i) pto_name_init()\n", __FILE__, __LINE__));
+  DBGPRINT (3, (stdout, "%s\n", __FUNCTION__));
   assert (NULL == name_obst);
   assert (NULL == qset_obst);
 
-  name_obst = xmalloc (sizeof(*name_obst));
-  qset_obst = xmalloc (sizeof(*qset_obst));
+  name_obst = xmalloc (sizeof (struct obstack));
+  qset_obst = xmalloc (sizeof (struct obstack));
 
   obstack_init (name_obst);
   obstack_init (qset_obst);
@@ -632,7 +641,7 @@ void pto_name_init (void)
 /* Cleanup the name module */
 void pto_name_cleanup (void)
 {
-  DBGPRINT (3, (stdout, "(%s:%i) pto_name_cleanup()\n", __FILE__, __LINE__));
+  DBGPRINT (3, (stdout, "%s\n", __FUNCTION__));
   obstack_free (name_obst, NULL);
   obstack_free (qset_obst, NULL);
 
@@ -649,6 +658,24 @@ void pto_name_cleanup (void)
 \f
 /*
   $Log$
+  Revision 1.16  2005/12/05 12:19:54  beck
+  added missing include <assert.h> (not anymore included in libFirm)
+
+  Revision 1.15  2005/03/02 10:14:38  beck
+  placed a return on all execution pathes
+
+  Revision 1.14  2005/02/17 08:45:38  liekweg
+  Don't return a value for an invalid descriptor
+
+  Revision 1.13  2005/02/11 10:21:28  beck
+  get_entry now always returns a value
+
+  Revision 1.12  2005/01/14 14:13:56  liekweg
+  fix gnu extension, fix fprintf's, fix allocs
+
+  Revision 1.11  2005/01/05 14:25:54  beck
+  renames all is_x*_type() functions to is_X*_type() to prevent name clash with EDG fronten
+
   Revision 1.10  2004/12/22 14:43:14  beck
   made allocations C-like