3 #include "irgraph_t.h" /* for checking whether constant code is allocated
6 static int check_class(type *tp) {
10 //printf("\n"); DDMT(tp);
12 for (i = 0; i < get_class_n_members(tp); i++) {
14 entity *mem = get_class_member(tp, i);
15 assert(mem && "NULL members not allowed");
16 //printf(" %d, %d", get_entity_n_overwrites(mem), get_class_n_supertypes(tp)); DDME(mem);
17 if (!mem) return error_null_mem;
18 assert(get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp));
19 for (j = 0; j < get_entity_n_overwrites(mem); j++) {
20 entity *ovw = get_entity_overwrites(mem, j);
21 //printf(" overwrites: "); DDME(ovw);
22 /* Check whether ovw is member of one of tp's supertypes. If so,
23 the representation is correct. */
25 for (k = 0; k < get_class_n_supertypes(tp); k++) {
26 if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) {
33 assert(found && "overwrites an entity not contained in direct supertype");
34 return error_ent_not_cont;
42 static int check_type(type *tp) {
43 switch (get_type_tpop_code(tp)) {
45 return check_class(tp);
56 static void on_obstack(ir_node *n, void *env) {
57 struct obstack *obst = ((struct myenv *)env)->obst;
59 /* n must be on the obstack obst. */
61 ((struct myenv *)env)->res = 0;
64 static int constant_on_wrong_obstack(ir_node *n) {
66 env.res = 0; /* false, not on wrong obstack */
67 env.obst = get_irg_obstack(get_const_code_irg());
68 irg_walk(n, on_obstack, NULL, (void *)&env);
72 static int constants_on_wrong_obstack(entity *ent) {
73 if (get_entity_variability(ent) == uninitialized) return 0;
75 if (is_compound_entity(ent)) {
77 for (i = 0; i < get_compound_ent_n_values(ent); i++) {
78 if (constant_on_wrong_obstack(get_compound_ent_value(ent, i)));
82 return constant_on_wrong_obstack(get_atomic_ent_value(ent));
87 static int check_entity(entity *ent) {
88 if (constants_on_wrong_obstack(ent))
89 return error_const_on_wrong_obstack;
93 static void check_tore(type_or_ent *tore, void *env) {
96 *res = check_type((type *)tore);
98 assert(is_entity(tore));
99 *res = check_entity((entity *)tore);
107 type_walk(check_tore, NULL, &res);