[DWARVES]: Add some destructors: tag, cu, namespace

To be used later.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2008-01-14 20:04:57 -02:00
parent 0a7fabf304
commit a2eb3ea774
2 changed files with 55 additions and 1 deletions

View File

@ -313,6 +313,12 @@ static struct tag *tag__new(Dwarf_Die *die)
return self;
}
static void tag__delete(struct tag *self)
{
assert(list_empty(&self->node));
free(self);
}
static const char *tag__accessibility(const struct tag *self)
{
int a;
@ -423,6 +429,25 @@ static struct namespace *namespace__new(Dwarf_Die *die)
return self;
}
static void namespace__delete(struct namespace *self)
{
struct tag *pos, *n;
namespace__for_each_tag_safe(self, pos, n) {
list_del_init(&pos->node);
/* Look for nested namespaces */
if (tag__is_struct(pos) ||
tag__is_union(pos) ||
tag__is_namespace(pos) ||
tag__is_enumeration(pos))
namespace__delete(tag__namespace(pos));
tag__delete(pos);
}
tag__delete(&self->tag);
}
static void type__init(struct type *self, Dwarf_Die *die)
{
namespace__init(&self->namespace, die);
@ -713,6 +738,24 @@ static struct cu *cu__new(const char *name, uint8_t addr_size,
return self;
}
void cu__delete(struct cu *self)
{
struct tag *pos, *n;
list_for_each_entry_safe(pos, n, &self->tags, node) {
list_del_init(&pos->node);
/* Look for nested namespaces */
if (tag__is_struct(pos) ||
tag__is_union(pos) ||
tag__is_namespace(pos) ||
tag__is_enumeration(pos)) {
namespace__delete(tag__namespace(pos));
}
}
free(self);
}
static void cu__add_tag(struct cu *self, struct tag *tag)
{
list_add_tail(&tag->node, &self->tags);

View File

@ -88,7 +88,7 @@ static inline struct namespace *tag__namespace(const struct tag *self)
return (struct namespace *)self;
}
/**
/**
* namespace__for_each_tag - iterate thru all the tags
* @self: struct namespace instance to iterate
* @pos: struct tag iterator
@ -96,6 +96,15 @@ static inline struct namespace *tag__namespace(const struct tag *self)
#define namespace__for_each_tag(self, pos) \
list_for_each_entry(pos, &(self)->tags, node)
/**
* namespace__for_each_tag_safe - safely iterate thru all the tags
* @self: struct namespace instance to iterate
* @pos: struct tag iterator
* @n: struct class_member temp iterator
*/
#define namespace__for_each_tag_safe(self, pos, n) \
list_for_each_entry_safe(pos, n, &(self)->tags, node)
/**
* struct type - base type for enumerations, structs and unions
*
@ -480,6 +489,8 @@ extern struct tag *cus__find_function_by_name(const struct cus *self,
extern struct tag *cus__find_tag_by_id(const struct cus *self,
struct cu **cu, const Dwarf_Off id);
extern void cu__delete(struct cu *self);
extern struct tag *cu__find_tag_by_id(const struct cu *self,
const Dwarf_Off id);
extern struct tag *cu__find_first_typedef_of_type(const struct cu *self,