[LIB]: Introduce type__for_each_data_member

So that we traverse just the data members, mostly in the reorganize code, where
we can't care less where is that the compiler put the base classes in the
layout since we can't influence how the compiler does this, it has only to
respect the layout we specify for the data members.

Well, it may well be the case that the order of the ancestor classes in the
class declaration can influence this, but I haven't checked.

Yes, another C++ism :-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
This commit is contained in:
Arnaldo Carvalho de Melo 2007-05-29 14:06:33 -03:00
parent 4c5dfb4ba7
commit 911375f5c5
4 changed files with 40 additions and 15 deletions

View File

@ -179,7 +179,7 @@ static size_t class__find_biggest_member_name(const struct class *self)
struct class_member *pos;
size_t biggest_name_len = 0;
type__for_each_member(&self->type, pos) {
type__for_each_data_member(&self->type, pos) {
const size_t len = strlen(pos->name);
if (len > biggest_name_len)
@ -202,7 +202,7 @@ static void class__emit_class_state_collector(struct class *self,
"\tconst struct %s *obj = from;\n"
"\tstruct %s *mini_obj = to;\n\n",
class__name(self, cu), class__name(clone, cu));
type__for_each_member(&clone->type, pos)
type__for_each_data_member(&clone->type, pos)
fprintf(fp_methods, "\tmini_obj->%-*s = obj->%s;\n",
len, pos->name, pos->name);
fputs("}\n\n", fp_methods);
@ -221,7 +221,7 @@ static struct class *class__clone_base_types(const struct tag *tag_self,
class__find_holes(clone, cu);
type__for_each_member_safe(&clone->type, pos, next) {
type__for_each_data_member_safe(&clone->type, pos, next) {
struct tag *member_type = cu__find_tag_by_id(cu, pos->tag.type);
if (member_type->tag != DW_TAG_base_type)
@ -318,7 +318,7 @@ static int class__emit_ostra_converter(struct tag *tag_self,
"\t\t\t\":",
fp_converter);
type__for_each_member(type, pos) {
type__for_each_data_member(type, pos) {
if (first)
first = 0;
else {

View File

@ -1705,7 +1705,7 @@ const struct class_member *class__find_bit_hole(const struct class *self,
struct class_member *pos;
const size_t byte_hole_size = bit_hole_size / 8;
type__for_each_member(&self->type, pos)
type__for_each_data_member(&self->type, pos)
if (pos == trailer)
break;
else if (pos->hole >= byte_hole_size ||
@ -1725,7 +1725,7 @@ void class__find_holes(struct class *self, const struct cu *cu)
self->nr_holes = 0;
self->nr_bit_holes = 0;
type__for_each_member(ctype, pos) {
type__for_each_data_member(ctype, pos) {
/* XXX for now just skip these */
if (pos->tag.tag == DW_TAG_inheritance &&
pos->virtuality == DW_VIRTUALITY_virtual)
@ -1802,7 +1802,7 @@ int class__has_hole_ge(const struct class *self, const uint16_t size)
if (self->nr_holes == 0)
return 0;
type__for_each_member(&self->type, pos)
type__for_each_data_member(&self->type, pos)
if (pos->hole >= size)
return 1;
@ -1814,7 +1814,7 @@ struct class_member *type__find_member_by_name(const struct type *self,
{
if (name != NULL) {
struct class_member *pos;
type__for_each_member(self, pos)
type__for_each_data_member(self, pos)
if (pos->name != NULL && strcmp(pos->name, name) == 0)
return pos;
}

View File

@ -111,7 +111,8 @@ struct type {
list_for_each_entry(pos, &(self)->namespace.tags, tag.node)
/**
* type__for_each_member - iterate thru the DW_TAG_member entries
* type__for_each_member - iterate thru the entries that use space
* (data members and inheritance entries)
* @self: struct type instance to iterate
* @pos: struct class_member iterator
*/
@ -123,7 +124,19 @@ struct type {
else
/**
* type__for_each_member_safe - safely iterate thru the DW_TAG_member entries
* type__for_each_data_member - iterate thru the data member entries
* @self: struct type instance to iterate
* @pos: struct class_member iterator
*/
#define type__for_each_data_member(self, pos) \
list_for_each_entry(pos, &(self)->namespace.tags, tag.node) \
if (pos->tag.tag != DW_TAG_member) \
continue; \
else
/**
* type__for_each_member_safe - safely iterate thru the entries that use space
* (data members and inheritance entries)
* @self: struct type instance to iterate
* @pos: struct class_member iterator
* @n: struct class_member temp iterator
@ -134,6 +147,18 @@ struct type {
continue; \
else
/**
* type__for_each_data_member_safe - safely iterate thru the data member entries
* @self: struct type instance to iterate
* @pos: struct class_member iterator
* @n: struct class_member temp iterator
*/
#define type__for_each_data_member_safe(self, pos, n) \
list_for_each_entry_safe(pos, n, &(self)->namespace.tags, tag.node) \
if (pos->tag.tag != DW_TAG_member) \
continue; \
else
static inline struct type *tag__type(const struct tag *self)
{
return (struct type *)self;

View File

@ -404,7 +404,7 @@ static int class__demote_bitfields(struct class *class, const struct cu *cu,
size_t current_bitfield_size = 0, size, bytes_needed, new_size;
int some_was_demoted = 0;
type__for_each_member(&class->type, member) {
type__for_each_data_member(&class->type, member) {
/*
* Check if we are moving away from a bitfield
*/
@ -538,7 +538,7 @@ static void class__reorganize_bitfields(struct class *class,
{
struct class_member *member, *brother;
restart:
type__for_each_member(&class->type, member) {
type__for_each_data_member(&class->type, member) {
/* See if we have a hole after this member */
if (member->bit_hole != 0) {
/*
@ -605,7 +605,7 @@ static void class__fixup_member_types(struct class *self, const struct cu *cu,
struct class_member *pos, *bitfield_head = NULL;
uint8_t fixup_was_done = 0;
type__for_each_member(&self->type, pos) {
type__for_each_data_member(&self->type, pos) {
/*
* Is this bitfield member?
*/
@ -678,7 +678,7 @@ restart:
last_member_size = class_member__size(last_member, cu);
type__for_each_member(&self->type, member) {
type__for_each_data_member(&self->type, member) {
/* See if we have a hole after this member */
if (member->hole != 0) {
/*
@ -728,7 +728,7 @@ restart:
if (self->nr_holes == 0)
return;
type__for_each_member(&self->type, member) {
type__for_each_data_member(&self->type, member) {
/* See if we have a hole after this member */
if (member->hole != 0) {
brother = class__find_last_member_of_size(self, member,