Commit 6bd4b45f authored by Michael Beck's avatar Michael Beck
Browse files

get_union_member_index() and get_compound_member_index() added

[r7279]
parent 8de98d42
......@@ -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;
......
......@@ -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.
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment