this file is replaced by Makefile.in. this much more conform
[libfirm] / ir / tr / typewalk.c
index f1c2105..5f136b6 100644 (file)
@@ -9,9 +9,16 @@
 ** - execute the post function after recursion
 */
 
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
 #include "irgwalk.h"
 #include "irgraph.h"
 #include "irnode.h"
+#include "irprog.h"
 #include "type_or_entity.h"
 
 /* Make types visible to allow most efficient access */
@@ -25,8 +32,9 @@ typedef struct type_walk_env {
 
 
 void type_walk_2(type_or_ent *tore,
-             void (pre)(type_or_ent*, void*), void (post)(type_or_ent*, void*),
-           void *env)
+              void (pre)(type_or_ent*, void*),
+              void (post)(type_or_ent*, void*),
+              void *env)
 {
   int i, visited = 0;
 
@@ -71,12 +79,39 @@ void type_walk_2(type_or_ent *tore,
       }
       break;
     case k_type_class:
-      ((type_class *)tore)->visit = type_visited;
-      /* !!!!! */
+      {
+       int i;
+       ((type_class *)tore)->visit = type_visited;
+       /* CS */
+       for (i=0; i<get_class_n_member((type_class *)tore); i++)
+         {
+           type_walk_2((type_or_ent *)get_class_member((type_class *)tore, i),
+                       pre, post, env);
+         }
+       for (i=0; i<get_class_n_subtype((type_class *)tore); i++)
+         {
+           type_walk_2((type_or_ent *)get_class_subtype((type_class *)tore, i),
+                       pre, post, env);
+         }
+       for (i=0; i<get_class_n_supertype((type_class *)tore); i++)
+         {
+           type_walk_2((type_or_ent *)get_class_supertype((type_class *)tore, i),
+                       pre, post, env);
+         }
+      }
       break;
     case k_type_strct:
-      ((type_strct *)tore)->visit = type_visited;
-      /* !!!!! */
+      {
+       int i;
+
+       ((type_strct *)tore)->visit = type_visited;
+       /* CS */
+       for (i=0; i<get_strct_n_member((type_strct *)tore); i++)
+         {
+           type_walk_2((type_or_ent *)get_strct_member((type_strct *)tore, i),
+                       pre, post, env);
+         }
+      }
       break;
     case k_type_method:
       {
@@ -90,6 +125,7 @@ void type_walk_2(type_or_ent *tore,
       break;
     case k_type_union:
       ((type_union *)tore)->visit = type_visited;
+      /* !!!!! */
       break;
     case k_type_array:
       ((type_array *)tore)->visit = type_visited;
@@ -153,9 +189,21 @@ void start_type_walk(ir_node *node, void *env) {
     }
 }
 
-void type_walk(ir_graph *irg,
-             void (pre)(type_or_ent*, void*), void (post)(type_or_ent*, void*),
-             void *env)
+void type_walk(void (pre)(type_or_ent*, void*),
+              void (post)(type_or_ent*, void*),
+              void *env) {
+  int i;
+  ++type_visited;
+  type_walk_2((type_or_ent *)get_glob_type(), pre, post, env);
+  for (i = 0; i < get_irp_n_types(); i++) {
+    type_walk_2((type_or_ent *)get_irp_type(i), pre, post, env);
+  }
+}
+
+void type_walk_irg (ir_graph *irg,
+                   void (pre)(type_or_ent*, void*),
+                   void (post)(type_or_ent*, void*),
+                   void *env)
 {
   /* this is needed to pass the parameters to the walker that actually
      walks the type information */
@@ -166,7 +214,10 @@ void type_walk(ir_graph *irg,
   type_env->env = env;
 
   ++type_visited;
-  irg_walk(irg->end, start_type_walk, NULL, type_env);
+  irg_walk(get_irg_end(irg), start_type_walk, NULL, type_env);
+
+  type_walk_2((type_or_ent *)get_irg_ent(irg), pre, post, env);
 
+  /* @@@ free type_walk_env!! */
   return;
 }