From 6bd4b45f442292cce4c650c2bb10cae9e52323a0 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Fri, 27 Jan 2006 17:02:04 +0000 Subject: [PATCH] get_union_member_index() and get_compound_member_index() added [r7279] --- ir/tr/type.c | 34 ++++++++++++++++++++++++++++------ ir/tr/type.h | 10 ++++++++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/ir/tr/type.c b/ir/tr/type.c index 067945fed..4b14ba6fd 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -799,10 +799,10 @@ int (get_class_n_members) (const ir_type *clss) { return _get_class_n_members(clss); } -int get_class_member_index(ir_type *clss, entity *mem) { - int i; +int get_class_member_index(const ir_type *clss, entity *mem) { + int i, n; assert(clss && (clss->type_op == type_class)); - for (i = 0; i < get_class_n_members(clss); i++) + for (i = 0, n = get_class_n_members(clss); i < n; ++i) if (get_class_member(clss, i) == mem) return i; return -1; @@ -1038,10 +1038,10 @@ entity *get_struct_member (const ir_type *strct, int pos) { return strct->attr.sa.members[pos]; } -int get_struct_member_index(ir_type *strct, entity *mem) { - int i; +int get_struct_member_index(const ir_type *strct, entity *mem) { + int i, n; assert(strct && (strct->type_op == type_struct)); - for (i = 0; i < get_struct_n_members(strct); i++) + for (i = 0, n = get_struct_n_members(strct); i < n; ++i) if (get_struct_member(strct, i) == mem) return i; return -1; @@ -1410,6 +1410,14 @@ entity *get_union_member (const ir_type *uni, int pos) { assert(pos >= 0 && pos < get_union_n_members(uni)); return uni->attr.ua.members[pos]; } +int get_union_member_index(const ir_type *uni, entity *mem) { + int i, n; + assert(uni && (uni->type_op == type_union)); + for (i = 0, n = get_union_n_members(uni); i < n; ++i) + if (get_union_member(uni, i) == mem) + return i; + return -1; +} void set_union_member (ir_type *uni, int pos, entity *member) { assert(uni && (uni->type_op == type_union)); assert(pos >= 0 && pos < get_union_n_members(uni)); @@ -1844,6 +1852,20 @@ entity *get_compound_member(const ir_type *tp, int pos) return res; } +/* Returns index of member in tp, -1 if not contained. */ +int get_compound_member_index(const ir_type *tp, entity *member) +{ + const tp_op *op = get_type_tpop(tp); + int index = -1; + + if (op->ops.get_member_index) + index = op->ops.get_member(tp, member); + else + assert(0 && "no members in this type"); + + return index; +} + int is_compound_type(const ir_type *tp) { assert(tp && tp->kind == k_type); return tp->type_op->flags & TP_OP_FLAG_COMPOUND; diff --git a/ir/tr/type.h b/ir/tr/type.h index 59a2f6596..7abf38cf5 100644 --- a/ir/tr/type.h +++ b/ir/tr/type.h @@ -452,7 +452,7 @@ int get_class_n_members (const ir_type *clss); entity *get_class_member (const ir_type *clss, int pos); /** Returns index of mem in clss, -1 if not contained. */ -int get_class_member_index(ir_type *clss, entity *mem); +int get_class_member_index(const ir_type *clss, entity *mem); /** Finds the member with name 'name'. If several members with the same * name returns one of them. Returns NULL if no member found. */ @@ -617,7 +617,7 @@ int get_struct_n_members (const ir_type *strct); entity *get_struct_member (const ir_type *strct, int pos); /** Returns index of member in strct, -1 if not contained. */ -int get_struct_member_index(ir_type *strct, entity *member); +int get_struct_member_index(const ir_type *strct, entity *member); /** Overwrites the member at position pos, 0 <= pos < n_member with the passed entity. */ @@ -902,6 +902,9 @@ void add_union_member (ir_type *uni, entity *member); /** Returns the entity at position pos of a union */ entity *get_union_member (const ir_type *uni, int pos); +/** Returns index of member in uni, -1 if not contained. */ +int get_union_member_index(const ir_type *uni, entity *member); + /** Overwrites a entity at position pos in a union type. */ void set_union_member (ir_type *uni, int pos, entity *member); @@ -1187,6 +1190,9 @@ int get_compound_n_members(const ir_type *tp); */ entity *get_compound_member(const ir_type *tp, int pos); +/** Returns index of member in tp, -1 if not contained. */ +int get_compound_member_index(const ir_type *tp, entity *member); + /** * Checks whether a type is compound. * -- 2.20.1