3 * File name: ir/tr/trvrfy.c
4 * Purpose: Check types and entities for correctness.
5 * Author: Michael Beck, Goetz Lindenmaier
9 * Copyright: (c) 2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
14 #include "irgraph_t.h" /* for checking whether constant code is allocated
20 static int check_class(type *tp) {
24 /*printf("\n"); DDMT(tp);*/
26 for (i = 0; i < get_class_n_members(tp); i++) {
28 entity *mem = get_class_member(tp, i);
29 assert(mem && "NULL members not allowed");
30 /*printf(" %d, %d", get_entity_n_overwrites(mem), get_class_n_supertypes(tp)); DDME(mem);*/
31 if (!mem) return error_null_mem;
33 if (get_entity_n_overwrites(mem) > get_class_n_supertypes(tp)) {
35 assert(get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp));
37 for (j = 0; j < get_entity_n_overwrites(mem); j++) {
38 entity *ovw = get_entity_overwrites(mem, j);
39 /*printf(" overwrites: "); DDME(ovw);*/
40 /* Check whether ovw is member of one of tp's supertypes. If so,
41 the representation is correct. */
43 for (k = 0; k < get_class_n_supertypes(tp); k++) {
44 if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) {
51 assert(found && "overwrites an entity not contained in direct supertype");
52 return error_ent_not_cont;
63 * Currently checks class types only.
65 static int check_type(type *tp) {
66 switch (get_type_tpop_code(tp)) {
68 return check_class(tp);
75 * helper environment struct for constant_on_wrong_obstack()
83 * called by the walker
85 static void on_irg_storage(ir_node *n, void *env) {
86 struct myenv * myenv = env;
88 myenv->res = node_is_in_irgs_storage(myenv->irg, n);
90 /* We also test whether the setting of the visited flag is legal. */
91 assert(get_irn_visited(n) <= get_irg_visited(myenv->irg) &&
92 "Visited flag of node is larger than that of corresponding irg.");
96 * checks wheater a given constant IR node is NOT on the
99 static int constant_on_wrong_irg(ir_node *n) {
102 env.res = 1; /* on right obstack */
103 env.irg = get_const_code_irg();
105 irg_walk(n, on_irg_storage, NULL, (void *)&env);
110 * Check if constants node are NOT on the constant IR graph.
112 static int constants_on_wrong_irg(entity *ent) {
113 if (get_entity_variability(ent) == uninitialized) return 0;
115 if (is_compound_entity(ent)) {
117 for (i = 0; i < get_compound_ent_n_values(ent); i++) {
118 if (constant_on_wrong_irg(get_compound_ent_value(ent, i)))
122 /* Might not be set if entity belongs to a description. */
123 if (get_atomic_ent_value(ent))
124 return constant_on_wrong_irg(get_atomic_ent_value(ent));
126 assert((is_class_type(get_entity_owner(ent)) &&
127 get_class_peculiarity(get_entity_owner(ent)) == description) &&
128 "Value in constant atomic entity not set.");
134 * Check an entity. Currently, we check only if initialized constants
135 * are build on the const irg graph.
138 * 0 if no error encountered
141 static int check_entity(entity *ent) {
142 current_ir_graph = get_const_code_irg();
143 if (constants_on_wrong_irg(ent)) {
144 assert(0 && "Contants placed on wrong IRG");
145 return error_const_on_wrong_irg;
151 * check types and entities
153 static void check_tore(type_or_ent *tore, void *env) {
157 *res = check_type((type *)tore);
159 assert(is_entity(tore));
160 *res = check_entity((entity *)tore);
165 * Verify types and entities.
170 type_walk(check_tore, NULL, &res);