X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Ftypewalk.c;h=ba916896aafb558f9cd3186aa8a2ca75da0965b8;hb=2e3dc475cf5d9edd3ecd6143f44fb1a45f7630d5;hp=1e349953ed653fb1a1f8f68d7000c10bf4bad11e;hpb=a264fae9c118b272a26d1f636289873d6df14e39;p=libfirm diff --git a/ir/tr/typewalk.c b/ir/tr/typewalk.c index 1e349953e..ba916896a 100644 --- a/ir/tr/typewalk.c +++ b/ir/tr/typewalk.c @@ -9,6 +9,8 @@ ** - execute the post function after recursion */ +/* $Id$ */ + #ifdef HAVE_CONFIG_H # include #endif @@ -16,13 +18,14 @@ #include #include #include "irgwalk.h" -#include "irgraph.h" +#include "irgraph_t.h" #include "irnode.h" #include "irprog.h" #include "type_or_entity.h" +#include "typegmod.h" /* Make types visible to allow most efficient access */ -# include "entity_t.h" +#include "entity_t.h" #include "type_t.h" typedef struct type_walk_env { @@ -42,9 +45,15 @@ void type_walk_2(type_or_ent *tore, /* marked? */ switch (get_kind(tore)) { case k_entity: - if (((entity *)tore)->visit >= type_visited) return; break; + if (((entity *)tore)->visit >= type_visited) return; + break; case k_type: - if (((type *)tore)->visit >= type_visited) return; break; + if(type_id == get_type_tpop((type*)tore)) { + type_walk_2((type_or_ent *)skip_tid((type *)tore), pre, post, env); + return; + } + if (((type *)tore)->visit >= type_visited) return; + break; default: break; } @@ -68,55 +77,58 @@ void type_walk_2(type_or_ent *tore, { type *tp = (type *)tore; mark_type_visited(tp); - switch (get_type_tpop_code(tp)) - case tpo_class: - { - for (i=0; ivisit >= type_visited) return; + break; + case k_type: + if(type_id == get_type_tpop((type*)tore)) { + type_walk_s2s_2((type_or_ent *)skip_tid((type *)tore), pre, post, env); + return; + } + if (((type *)tore)->visit >= type_visited) return; + break; + default: + break; + } + + /* iterate */ + switch (get_kind(tore)) { + case k_type: + { + type *tp = (type *)tore; + mark_type_visited(tp); + switch (get_type_tpop_code(tp)) { + case tpo_class: + { + for (i = 0; i < get_class_n_supertypes(tp); i++) { + type_walk_s2s_2((type_or_ent *)get_class_supertype(tp, i), pre, + post, env); + } + /* execute pre method */ + if(pre) + pre(tore, env); + tp = skip_tid((type*)tore); + + for (i = 0; i < get_class_n_subtypes(tp); i++) { + type_walk_s2s_2((type_or_ent *)get_class_subtype(tp, i), pre, + post, env); + } + + /* execute post method */ + if(post) + post(tore, env); + } + break; + case tpo_struct: + case tpo_method: + case tpo_union: + case tpo_array: + case tpo_enumeration: + case tpo_pointer: + case tpo_primitive: + case tpo_id: + /* dont care */ + break; + default: + printf(" *** Faulty type! \n"); + break; + } + } break; /* end case k_type */ + case k_entity: + /* dont care */ + break; + default: + printf(" *** Faulty type or entity! \n"); + break; + } + return; +} + +void type_walk_super2sub(void (pre)(type_or_ent*, void*), + void (post)(type_or_ent*, void*), + void *env) { + int i; + type *tp; + ++type_visited; + type_walk_s2s_2((type_or_ent *)get_glob_type(), pre, post, env); + for (i = 0; i < get_irp_n_types(); i++) { + tp = get_irp_type(i); + type_walk_s2s_2((type_or_ent *)tp, pre, post, env); + } +} + +/*****************************************************************************/ + +static +void type_walk_super_2(type_or_ent *tore, + void (pre)(type_or_ent*, void*), + void (post)(type_or_ent*, void*), + void *env) +{ + int i; + + /* marked? */ + switch (get_kind(tore)) { + case k_entity: + if (((entity *)tore)->visit >= type_visited) return; + break; + case k_type: + if(type_id == get_type_tpop((type*)tore)) { + type_walk_super_2((type_or_ent *)skip_tid((type *)tore), pre, post, env); + return; + } + if (((type *)tore)->visit >= type_visited) return; + break; + default: + break; + } + + /* iterate */ + switch (get_kind(tore)) { + case k_type: + { + type *tp = (type *)tore; + mark_type_visited(tp); + switch (get_type_tpop_code(tp)) { + case tpo_class: + { + /* execute pre method */ + if(pre) + pre(tore, env); + tp = skip_tid((type*)tore); + + for (i = 0; i < get_class_n_supertypes(tp); i++) { + type_walk_super_2((type_or_ent *)get_class_supertype(tp, i), pre, + post, env); + } + + /* execute post method */ + if(post) + post(tore, env); + } + break; + case tpo_struct: + case tpo_method: + case tpo_union: + case tpo_array: + case tpo_enumeration: + case tpo_pointer: + case tpo_primitive: + case tpo_id: + /* dont care */ + break; + default: + printf(" *** Faulty type! \n"); + break; + } + } break; /* end case k_type */ + case k_entity: + /* dont care */ + break; + default: + printf(" *** Faulty type or entity! \n"); + break; + } + return; +} + +void type_walk_super(void (pre)(type_or_ent*, void*), + void (post)(type_or_ent*, void*), + void *env) { + int i; + type *tp; + ++type_visited; + type_walk_super_2((type_or_ent *)get_glob_type(), pre, post, env); + for (i = 0; i < get_irp_n_types(); i++) { + tp = get_irp_type(i); + type_walk_super_2((type_or_ent *)tp, pre, post, env); + } +} + +/*****************************************************************************/ + + +void class_walk_s2s_2(type *tp, + void (pre)(type*, void*), + void (post)(type*, void*), + void *env) +{ + int i; + + /* marked? */ + if (tp->visit >= type_visited) return; + + assert(is_class_type(tp)); + /* Assure all supertypes are visited before */ + for (i=0; i < get_class_n_supertypes(tp); i++) { + if (get_type_visited(get_class_supertype(tp, i)) < type_visited) + return; + } + + mark_type_visited(tp); + + /* execute pre method */ + if(pre) + pre(tp, env); + + tp = skip_tid((type*)tp); + for (i=0; ivisit < type_visited) && + (!is_frame_type(tp)) && + (tp != get_glob_type())) { + class_walk_s2s_2(tp, pre, post, env); + } + } +} +#endif +void class_walk_super2sub(void (pre)(type*, void*), + void (post)(type*, void*), + void *env) { + int i; + type *tp; + + ++type_visited; + for (i = 0; i < get_irp_n_types(); i++) { + tp = get_irp_type(i); + if (is_class_type(tp) && + (get_class_n_supertypes(tp) == 0) && + (tp->visit < type_visited)) { + assert(!is_frame_type(tp)); + assert(tp != get_glob_type()); + class_walk_s2s_2(tp, pre, post, env); + } + } +} + + +/* Walks over all entities in the type */ +void walk_types_entities(type *tp, + void (doit)(entity*, void*), + void *env) { + int i; + switch(get_type_tpop_code(tp)) { + case tpo_class: { + for (i=0; i