changed definition of subdir only (added prefix ir/)
[libfirm] / ir / tr / typewalk.c
index 362ff9e..5f136b6 100644 (file)
@@ -9,11 +9,16 @@
 ** - execute the post function after recursion
 */
 
-#include <stdio.h>
+#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 */
@@ -27,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;
 
@@ -73,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:
       {
@@ -92,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;
@@ -155,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 */