3 #include "irgraph_t.h" /* for checking whether constant code is allocated
9 static int check_class(type *tp) {
13 /*printf("\n"); DDMT(tp);*/
15 for (i = 0; i < get_class_n_members(tp); i++) {
17 entity *mem = get_class_member(tp, i);
18 assert(mem && "NULL members not allowed");
19 /*printf(" %d, %d", get_entity_n_overwrites(mem), get_class_n_supertypes(tp)); DDME(mem);*/
20 if (!mem) return error_null_mem;
22 if (get_entity_n_overwrites(mem) > get_class_n_supertypes(tp)) {
24 assert(get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp));
26 for (j = 0; j < get_entity_n_overwrites(mem); j++) {
27 entity *ovw = get_entity_overwrites(mem, j);
28 /*printf(" overwrites: "); DDME(ovw);*/
29 /* Check whether ovw is member of one of tp's supertypes. If so,
30 the representation is correct. */
32 for (k = 0; k < get_class_n_supertypes(tp); k++) {
33 if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) {
40 assert(found && "overwrites an entity not contained in direct supertype");
41 return error_ent_not_cont;
52 * Currently checks class types only.
54 static int check_type(type *tp) {
55 switch (get_type_tpop_code(tp)) {
57 return check_class(tp);
64 * helper environment struct for constant_on_wrong_obstack()
72 * called by the walker
74 static void on_irg_storage(ir_node *n, void *env) {
75 struct myenv * myenv = env;
77 myenv->res = node_is_in_irgs_storage(myenv->irg, n);
81 * checks wheater a given constant IR node is NOT on the
84 static int constant_on_wrong_irg(ir_node *n) {
87 env.res = 1; /* on right obstack */
88 env.irg = get_const_code_irg();
90 irg_walk(n, on_irg_storage, NULL, (void *)&env);
95 * Check if constants node are NOT on the constant IR graph.
97 static int constants_on_wrong_irg(entity *ent) {
98 if (get_entity_variability(ent) == uninitialized) return 0;
100 if (is_compound_entity(ent)) {
102 for (i = 0; i < get_compound_ent_n_values(ent); i++) {
103 if (constant_on_wrong_irg(get_compound_ent_value(ent, i)))
107 /* Might not be set if entity belongs to a description. */
108 if (get_atomic_ent_value(ent))
109 return constant_on_wrong_irg(get_atomic_ent_value(ent));
111 assert((is_class_type(get_entity_owner(ent)) &&
112 get_class_peculiarity(get_entity_owner(ent)) == description) &&
113 "Value in constant atomic entity not set.");
119 * Check an entity. Currently, we check only if initialized constants
120 * are build on the const irg graph.
123 * 0 if no error encountered
126 static int check_entity(entity *ent) {
127 if (constants_on_wrong_irg(ent)) {
128 assert(0 && "Contants placed on wrong IRG");
129 return error_const_on_wrong_irg;
135 * check types and entities
137 static void check_tore(type_or_ent *tore, void *env) {
141 *res = check_type((type *)tore);
143 assert(is_entity(tore));
144 *res = check_entity((entity *)tore);
149 * Verify types and entities.
154 type_walk(check_tore, NULL, &res);