From 24db547584425d6f986de548a23ee4305eaff347 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Wed, 18 Jul 2001 11:52:25 +0000 Subject: [PATCH] improved add routinesC [r241] --- ir/tr/type.c | 10 ++++++++++ ir/tr/type.h | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ir/tr/type.c b/ir/tr/type.c index 66ff9b2b4..ad016d420 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -234,8 +234,13 @@ void remove_class_member(type *clss, entity *member) { } void add_class_subtype (type *clss, type *subtype) { + int i; assert(clss && (clss->type_op == type_class)); ARR_APP1 (type *, clss->attr.ca.subtypes, subtype); + for (i = 0; i < get_class_n_subtype(subtype); i++) + if (get_class_subtype(subtype, i) == clss) + /* Class already registered */ + return; ARR_APP1 (type *, subtype->attr.ca.supertypes, clss); } int get_class_n_subtype (type *clss) { @@ -263,9 +268,14 @@ void remove_class_subtype(type *clss, type *subtype) { } void add_class_supertype (type *clss, type *supertype) { + int i; assert(clss && (clss->type_op == type_class)); assert(supertype && (supertype -> type_op == type_class)); ARR_APP1 (type *, clss->attr.ca.supertypes, supertype); + for (i = 0; i < get_class_n_supertype(supertype); i++) + if (get_class_supertype(supertype, i) == clss) + /* Class already registered */ + return; ARR_APP1 (type *, supertype->attr.ca.subtypes, clss); } int get_class_n_supertype (type *clss) { diff --git a/ir/tr/type.h b/ir/tr/type.h index 36f0afbf7..66c41ec22 100644 --- a/ir/tr/type.h +++ b/ir/tr/type.h @@ -206,8 +206,9 @@ void set_class_member (type *clss, entity *member, int pos); void remove_class_member(type *clss, entity *member); -/* Adds subtype as subtype to clss and also - clss as supertype to subtype */ +/* Adds subtype as subtype to clss. + Checks whether clss is a supertype of subtype. If not + adds also clss as supertype to subtype. */ void add_class_subtype (type *clss, type *subtype); /* Returns the number of subtypes */ int get_class_n_subtype (type *clss); @@ -221,8 +222,9 @@ void set_class_subtype (type *clss, type *subtype, int pos); void remove_class_subtype(type *clss, type *subtype); -/* Adds supertype as supertype to class and also - class as subtype to supertype. */ +/* Adds supertype as supertype to class. + Checks whether clss is a subtype of supertype. If not + adds also clss as subtype to supertype. */ void add_class_supertype (type *clss, type *supertype); /* Returns the number of supertypes */ int get_class_n_supertype (type *clss); -- 2.20.1