added doxygen comments
[libfirm] / ir / ana2 / typalise.c
index 30cc873..42e3e52 100644 (file)
@@ -14,7 +14,7 @@
 
 
 # ifdef HAVE_CONFIG_H
-#  include <config.h>
+#  include "config.h"
 # endif
 
 # include "typalise.h"
 
 # include <assert.h>
 
-# include "irnode.h"
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+# include "irnode_t.h"
 # include "irgwalk.h"
 # include "xmalloc.h"
+# include "gnu_ext.h"
 
 
 /*
@@ -48,19 +53,19 @@ static typalise_t *typalise_proj (ir_node*);
 */
 static typalise_t *ta_exact (type *tp)
 {
-  typalise_t *ta = (typalise_t*) xmalloc (sizeof (typalise_t));
+  typalise_t *ta = xmalloc (sizeof (typalise_t));
   ta->kind = type_exact;
   ta->res.type = tp;
   ta->id = ta_id ++;
 
-  assert (is_class_type (tp));
+  assert (is_Class_type (tp));
 
   return (ta);
 }
 
 static typalise_t *ta_types (lset_t *set)
 {
-  typalise_t *ta = (typalise_t*) xmalloc (sizeof (typalise_t));
+  typalise_t *ta = xmalloc (sizeof (typalise_t));
   ta->kind = type_types;
   ta->res.types = set;
   ta->id = ta_id ++;
@@ -70,12 +75,12 @@ static typalise_t *ta_types (lset_t *set)
 
 static typalise_t *ta_type (type *tp)
 {
-  typalise_t *ta = (typalise_t*) xmalloc (sizeof (typalise_t));
+  typalise_t *ta = xmalloc (sizeof (typalise_t));
   ta->kind = type_type;
   ta->res.type = tp;
   ta->id = ta_id ++;
 
-  assert (is_class_type (tp));
+  assert (is_Class_type (tp));
 
   return (ta);
 }
@@ -128,11 +133,11 @@ static int is_subtype (type *otype, type *stype)
 */
 static void _collect_subtypes (type *otype, lset_t *set)
 {
-  lset_insert (set, otype);
+  int i, n_sub;
 
-  int n_sub = get_class_n_subtypes (otype);
-  int i;
+  lset_insert (set, otype);
 
+  n_sub = get_class_n_subtypes (otype);
   for (i = 0; i < n_sub; i ++) {
     type *sub = get_class_subtype (otype, i);
 
@@ -154,6 +159,8 @@ static lset_t *subtype_closure (type *otype)
 */
 static void _collect_owner_types (entity *method, ir_graph *graph, lset_t *tps)
 {
+  int i, n_over;
+
   /* search DOWNwards in clazz hierarchy */
 
   if ((peculiarity_description == get_entity_peculiarity (method)) ||
@@ -171,9 +178,7 @@ static void _collect_owner_types (entity *method, ir_graph *graph, lset_t *tps)
     }
   }
 
-  int n_over = get_entity_n_overwrittenby (method);
-  int i;
-
+  n_over = get_entity_n_overwrittenby (method);
   for (i = 0; i < n_over; i ++) {
     entity *ometh = get_entity_overwrittenby (method, i);
 
@@ -331,7 +336,7 @@ static typalise_t *ta_join (typalise_t *one, typalise_t *two)
 # ifdef SHUT_UP_GCC
 static const char *ta_name (typalise_t *ta)
 {
-  /* # define BUF_SIZE 1024 */
+# define BUF_SIZE 1024
   static char buf [BUF_SIZE];
 
   int len = sprintf (buf, "[%d] ", ta->id);
@@ -374,6 +379,7 @@ static const char *ta_name (typalise_t *ta)
 static int uses_graph (type *clazz, entity *meth, ir_graph *graph)
 {
   type *g_clazz = get_entity_owner (meth);
+  int i, n_over, use = FALSE;
 
   if (g_clazz == clazz) {
     return (TRUE);
@@ -388,10 +394,7 @@ static int uses_graph (type *clazz, entity *meth, ir_graph *graph)
   }
 
   /* else inherited or description */
-  int use = FALSE;
-  int i;
-  int n_over = get_entity_n_overwrittenby (meth); /* DOWN-wards */
-
+  n_over = get_entity_n_overwrittenby (meth); /* DOWN-wards */
   for (i = 0; (i < n_over) && (!use); i ++) {
     entity *over = get_entity_overwrittenby (meth, i);
 
@@ -441,6 +444,7 @@ static int ta_supports (typalise_t *ta, ir_graph *graph)
   }
 
   assert (0 && "invalid ta");
+  return FALSE;
 }
 
 
@@ -462,23 +466,29 @@ static typalise_t *typalise_proj (ir_node *proj)
 
     proj_in = get_Proj_pred (proj_in);
     if (iro_Start == get_irn_opcode (proj_in)) {
+      ir_graph *graph = get_irn_irg (proj);
+      entity   *meth  = get_irg_entity (graph);
+
       long n = get_Proj_proj (proj);
+
       if (1 == n) {
         /* yay proj this */
-        ir_graph *graph = get_irn_irg (proj);
-        entity   *meth  = get_irg_entity (graph);
         type     *tp    = get_entity_owner (meth);
 
         /* res = ta_exact (tp); */
         res = ta_type (tp);     /* TODO */
       } else {
         /* ugh proj arg */
-        /* hey, even 'filtering' this NULL by the select of the actual
-           call is probably as "precise" as anything: */
-        return (NULL);
+        type *tp = get_method_param_type (get_entity_type (meth), n);
+        if (is_Pointer_type (tp)) {
+          tp = get_pointer_points_to_type (tp);
+        }
+
+        res = ta_type (tp);
       }
     } else if (iro_Call == get_irn_opcode (proj_in)) {
       /* call result ... 'whatever' */
+      /* hey, this is redundant (or the check for iro_Call further down) */
       ir_node *call_ptr = get_Call_ptr (proj_in);
 
       res = typalise (call_ptr);
@@ -544,10 +554,10 @@ typalise_t *typalise (ir_node *node)
     typalise_t *ta = NULL;
     type *tp = get_Cast_type (node);
 
-    if (is_pointer_type (tp)) {
+    if (is_Pointer_type (tp)) {
       tp = get_pointer_points_to_type (tp);
     }
-    assert (is_class_type (tp));
+    assert (is_Class_type (tp));
 
     ta = typalise (get_Cast_op (node));
 
@@ -575,7 +585,6 @@ typalise_t *typalise (ir_node *node)
   } break;
 
   case (iro_Load): {
-    /* presumably it's call (load (ptr)) we're analyzing. */
     ir_node *load_ptr = get_Load_ptr (node);
 
     res = typalise (load_ptr);
@@ -587,24 +596,24 @@ typalise_t *typalise (ir_node *node)
     entity *ent = get_Sel_entity (node);
     type *tp = get_entity_type (ent);
 
-    if (is_method_type (tp)) {
+    if (is_Method_type (tp)) {
       tp = get_entity_type (ent);
       tp = get_method_res_type (tp, 0);
 
-      if (is_pointer_type (tp)) {
+      if (is_Pointer_type (tp)) {
         tp = get_pointer_points_to_type (tp);
       }
 
       res = ta_type (tp);
-    } else if (is_class_type (tp)) {
+    } else if (is_Class_type (tp)) {
       tp = get_entity_type (ent);
 
-      if (is_pointer_type (tp)) {
+      if (is_Pointer_type (tp)) {
         tp = get_pointer_points_to_type (tp);
       }
 
       res = ta_type (tp);
-    } else if (is_pointer_type (tp)) {
+    } else if (is_Pointer_type (tp)) {
       tp = get_pointer_points_to_type (tp);
       res = ta_type (tp);
     } else {
@@ -668,11 +677,12 @@ typalise_t *typalise (ir_node *node)
       entity *ent = get_SymConst_entity (node);
       type *tp = get_entity_type (ent);
       tp = get_pointer_points_to_type (tp);
-      assert (is_class_type (tp));
+      assert (is_Class_type (tp));
 
       res = ta_type (tp);       /* can't use ta_exact */
     } else {
-      fprintf (stdout, "can't handle SymConst %s?\n",
+      fprintf (stdout, "%s (%s:%i): can't handle SymConst %s?\n",
+               __FUNCTION__, __FILE__, __LINE__,
                get_op_name (get_irn_op (node)));
       res = NULL;
     }
@@ -698,6 +708,27 @@ typalise_t *typalise (ir_node *node)
 \f
 /*
   $Log$
+  Revision 1.8  2005/01/14 14:13:24  liekweg
+  fix gnu extension
+
+  Revision 1.7  2005/01/10 17:26:34  liekweg
+  fixup printfs, don't put environments on the stack
+
+  Revision 1.6  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.5  2004/12/22 14:43:14  beck
+  made allocations C-like
+
+  Revision 1.4  2004/12/21 15:50:18  beck
+  removed C99 constructs
+
+  Revision 1.3  2004/12/02 16:17:51  beck
+  fixed config.h include
+
+  Revision 1.2  2004/10/22 09:53:10  liekweg
+  Correctly handle proj_args
+
   Revision 1.1  2004/10/21 11:09:37  liekweg
   Moved memwalk stuf into irmemwalk
   Moved lset stuff into lset