-#include "trvrfy.h"
-
-static int check_class(type *tp) {
- int i, j, k;
- int found;
-
- //printf("\n"); DDMT(tp);
-
- for (i = 0; i < get_class_n_members(tp); i++) {
-
- entity *mem = get_class_member(tp, i);
- assert(mem && "NULL members not allowed");
- //printf(" %d, %d", get_entity_n_overwrites(mem), get_class_n_supertypes(tp)); DDME(mem);
- if (!mem) return error_null_mem;
- assert(get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp));
- for (j = 0; j < get_entity_n_overwrites(mem); j++) {
- entity *ovw = get_entity_overwrites(mem, j);
- //printf(" overwrites: "); DDME(ovw);
- /* Check whether ovw is member of one of tp's supertypes. If so,
- the representation is correct. */
- found = false;
- for (k = 0; k < get_class_n_supertypes(tp); k++) {
- if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) {
- found = true;
- break;
+/**
+ * @file tr_inheritance.c
+ * @brief Check types and entities for correctness.
+ * @date 29.1.2003
+ * @author Michael Beck, Goetz Lindenmaier
+ * @version $Id$
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "irgraph_t.h" /* for checking whether constant code is allocated
+ on proper obstack */
+#include "irflag_t.h"
+#include "irprintf.h"
+#include "irgwalk.h"
+
+
+#ifdef NDEBUG
+/*
+ * in RELEASE mode, returns ret if the expression expr evaluates to zero
+ * in ASSERT mode, asserts the expression expr (and the string string).
+ */
+#define ASSERT_AND_RET(expr, string, ret) if (!(expr)) return (ret)
+
+/*
+ * in RELEASE mode, returns ret if the expression expr evaluates to zero
+ * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts expr
+ */
+#define ASSERT_AND_RET_DBG(expr, string, ret, blk) if (!(expr)) return (ret)
+#else
+#define ASSERT_AND_RET(expr, string, ret) \
+do { \
+ if (opt_do_node_verification == FIRM_VERIFICATION_ON) {\
+ assert((expr) && string); } \
+ if (!(expr)) { \
+ if (opt_do_node_verification == FIRM_VERIFICATION_REPORT) \
+ fprintf(stderr, #expr " : " string "\n"); \
+ firm_vrfy_failure_msg = #expr " && " string; \
+ return (ret); \
+ } \
+} while(0)
+
+#define ASSERT_AND_RET_DBG(expr, string, ret, blk) \
+do { \
+ if (!(expr)) { \
+ firm_vrfy_failure_msg = #expr " && " string; \
+ if (opt_do_node_verification != FIRM_VERIFICATION_ERROR_ONLY) { blk; } \
+ if (opt_do_node_verification == FIRM_VERIFICATION_REPORT) \
+ fprintf(stderr, #expr " : " string "\n"); \
+ else if (opt_do_node_verification == FIRM_VERIFICATION_ON) { \
+ assert((expr) && string); \
+ } \
+ return (ret); \
+ } \
+} while(0)
+
+#endif /* NDEBUG */
+
+#ifndef NDEBUG
+
+static const char *firm_vrfy_failure_msg;
+
+/**
+ * Show diagnostic if an entity overwrites another one not
+ * in direct superclasses.
+ */
+static void show_ent_not_supertp(ir_entity *ent, ir_entity *ovw) {
+ ir_type *owner = get_entity_owner(ent);
+ ir_type *ov_own = get_entity_owner(ovw);
+ int i;
+
+ fprintf(stderr, "Type verification error:\n");
+ ir_fprintf(stderr, "Entity %+F::%+e owerwrites ", owner, ent);
+ ir_fprintf(stderr, "Entity %+F::%+e\n", ov_own, ovw);
+
+ ir_fprintf(stderr, "Supertypes of %+F:\n", owner);
+ for (i = 0; i < get_class_n_supertypes(owner); ++i) {
+ ir_type *super = get_class_supertype(owner, i);
+ ir_fprintf(stderr, " %+F:\n", super);
+ }
+}
+
+/**
+ * Show diagnostic if an entity overwrites a wrong number of things.
+ */
+static void show_ent_overwrite_cnt(ir_entity *ent) {
+ ir_type *owner = get_entity_owner(ent);
+ int i, j, k, found, show_stp = 0;
+
+ fprintf(stderr, "Type verification error:\n");
+ ir_fprintf(stderr, "Entity %t::%e owerwrites\n", owner, ent);
+ for (i = 0; i < get_entity_n_overwrites(ent); ++i) {
+ ir_entity *ovw = get_entity_overwrites(ent, i);
+ ir_type *ov_own = get_entity_owner(ovw);
+
+ ir_fprintf(stderr, " %t::%e\n", ov_own, ovw);
+ for (k = 0; k < i; ++k)
+ if (ovw == get_entity_overwrites(ent, k)) {
+ ir_fprintf(stderr, " ->%t::%e entered more than once\n", ov_own, ovw);
+ break;
+ }
+
+ found = 0;
+ for (j = get_class_n_supertypes(owner) - 1; j >= 0; --j) {
+ if (ov_own == get_class_supertype(owner, j)) {
+ show_stp = found = 1;
+ break;
+ }
+ }
+ if (! found)
+ ir_fprintf(stderr, " ->%t not in super types of %t\n", ov_own, owner);
+ }
+
+ if (show_stp) {
+ ir_fprintf(stderr, "Supertypes of %t:\n", owner);
+ for (i = 0; i < get_class_n_supertypes(owner); ++i) {
+ ir_type *super = get_class_supertype(owner, i);
+ ir_fprintf(stderr, " %t:\n", super);
+ }