[LIB]: Introduce type__name()

This is in preparation for the introduction of struct namespace, that will be
struct type ancestor.

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
This commit is contained in:
Arnaldo Carvalho de Melo 2007-05-24 11:56:12 -03:00
parent 2b480348e9
commit 230d9310aa
4 changed files with 45 additions and 40 deletions

View File

@ -399,7 +399,7 @@ size_t typedef__fprintf(const struct tag *tag_self, const struct cu *cu,
case DW_TAG_array_type:
printed = fprintf(fp, "typedef ");
return printed + array_type__fprintf(type, cu,
self->name, 0, fp);
type__name(self), 0, fp);
case DW_TAG_pointer_type:
if (type->type == 0) /* void pointer */
break;
@ -416,19 +416,19 @@ size_t typedef__fprintf(const struct tag *tag_self, const struct cu *cu,
case DW_TAG_subroutine_type:
printed = fprintf(fp, "typedef ");
return printed + ftype__fprintf(tag__ftype(type), cu,
self->name, 0, is_pointer, 0,
type__name(self), 0, is_pointer, 0,
fp);
case DW_TAG_structure_type: {
const struct type *ctype = tag__type(type);
if (ctype->name != NULL)
if (type__name(ctype) != NULL)
return fprintf(fp, "typedef struct %s %s",
ctype->name, self->name);
type__name(ctype), type__name(self));
}
}
return fprintf(fp, "typedef %s %s",
tag__name(type, cu, bf, sizeof(bf)), self->name);
tag__name(type, cu, bf, sizeof(bf)), type__name(self));
}
size_t enumeration__fprintf(const struct tag *tag_self,
@ -436,8 +436,8 @@ size_t enumeration__fprintf(const struct tag *tag_self,
{
const struct type *self = tag__type(tag_self);
struct enumerator *pos;
size_t printed = fprintf(fp, "enum%s%s {\n", self->name ? " " : "",
self->name ?: "");
size_t printed = fprintf(fp, "enum%s%s {\n", type__name(self) ? " " : "",
type__name(self) ?: "");
size_t indent = conf->indent;
if (indent >= sizeof(tabs))
@ -649,8 +649,8 @@ struct tag *cu__find_struct_by_name(const struct cu *self, const char *name)
type = tag__type(pos);
if (!type->declaration &&
type->name != NULL &&
strcmp(type->name, name) == 0)
type__name(type) != NULL &&
strcmp(type__name(type), name) == 0)
return pos;
}
@ -925,7 +925,7 @@ const char *tag__name(const struct tag *self, const struct cu *cu,
break;
default:
snprintf(bf, len, "%s%s", tag__prefix(cu, self->tag),
tag__type(self)->name ?: "");
type__name(tag__type(self)) ?: "");
break;
}
@ -1155,9 +1155,9 @@ static size_t type__fprintf(struct tag *type, const struct cu *cu,
while (type->tag == DW_TAG_typedef) {
ctype = tag__type(type);
if (typedef_expanded)
printed += fprintf(fp, " -> %s", ctype->name);
printed += fprintf(fp, " -> %s", type__name(ctype));
else {
printed += fprintf(fp, "/* typedef %s", ctype->name);
printed += fprintf(fp, "/* typedef %s", type__name(ctype));
typedef_expanded = 1;
}
type = cu__find_tag_by_id(cu, type->type);
@ -1200,26 +1200,26 @@ static size_t type__fprintf(struct tag *type, const struct cu *cu,
case DW_TAG_structure_type:
ctype = tag__type(type);
if (ctype->name != NULL && !conf->expand_types)
if (type__name(ctype) != NULL && !conf->expand_types)
return fprintf(fp, "struct %-*s %s",
conf->type_spacing - 7,
ctype->name, name);
type__name(ctype), name);
return printed + class__fprintf(tag__class(type), cu, &tconf, fp);
case DW_TAG_union_type:
ctype = tag__type(type);
if (ctype->name != NULL && !conf->expand_types)
if (type__name(ctype) != NULL && !conf->expand_types)
return fprintf(fp, "union %-*s %s",
conf->type_spacing - 6,
ctype->name, name);
type__name(ctype), name);
return printed + union__fprintf(ctype, cu, &tconf, fp);
case DW_TAG_enumeration_type:
ctype = tag__type(type);
if (ctype->name != NULL)
if (type__name(ctype) != NULL)
return printed + fprintf(fp, "enum %-*s %s",
conf->type_spacing - 5,
ctype->name, name);
type__name(ctype), name);
return printed + enumeration__fprintf(type, &tconf, fp);
}
@ -1257,7 +1257,7 @@ static size_t struct_member__fprintf(struct class_member *self,
type->tag == DW_TAG_enumeration_type ||
type->tag == DW_TAG_structure_type) &&
/* Look if is a type defined inline */
tag__type(type)->name == NULL) {
type__name(tag__type(type)) == NULL) {
/* Check if this is a anonymous union */
const int slen = self->name != NULL ?
(int)strlen(self->name) : -1;
@ -1284,7 +1284,7 @@ static size_t union_member__fprintf(struct class_member *self,
type->tag == DW_TAG_enumeration_type ||
type->tag == DW_TAG_structure_type) &&
/* Look if is a type defined inline */
tag__type(type)->name == NULL) {
type__name(tag__type(type)) == NULL) {
/* Check if this is a anonymous union */
const int slen = self->name != NULL ? (int)strlen(self->name) : -1;
/*
@ -1315,8 +1315,8 @@ static size_t union__fprintf(const struct type *self, const struct cu *cu,
if (conf->prefix != NULL)
printed += fprintf(fp, "%s ", conf->prefix);
printed += fprintf(fp, "union%s%s {\n", self->name ? " " : "",
self->name ?: "");
printed += fprintf(fp, "union%s%s {\n", type__name(self) ? " " : "",
type__name(self) ?: "");
uconf = *conf;
uconf.indent = indent + 1;
@ -1988,7 +1988,7 @@ size_t class__fprintf(const struct class *self, const struct cu *cu,
struct conf_fprintf cconf = conf ? *conf : conf_fprintf__defaults;
size_t printed = fprintf(fp, "%s%sstruct%s%s {\n",
cconf.prefix ?: "", cconf.prefix ? " " : "",
tself->name ? " " : "", tself->name ?: "");
type__name(tself) ? " " : "", type__name(tself) ?: "");
size_t indent = cconf.indent;
if (indent >= sizeof(tabs))

View File

@ -143,9 +143,14 @@ extern struct class *class__clone(const struct class *from,
const char *new_class_name);
extern void class__delete(struct class *self);
static inline const char *type__name(const struct type *self)
{
return self->name;
}
static inline const char *class__name(const struct class *self)
{
return self->type.name;
return type__name(&self->type);
}
static inline uint16_t class__tag_type(const struct class *self)

View File

@ -39,7 +39,7 @@ static struct type *cus__find_definition(const struct cus *self,
return NULL;
list_for_each_entry(pos, self->definitions, node)
if (pos->name != NULL && strcmp(pos->name, name) == 0)
if (type__name(pos) != NULL && strcmp(type__name(pos), name) == 0)
return pos;
return NULL;
@ -51,7 +51,7 @@ static struct type *cus__find_fwd_decl(const struct cus *self,
struct type *pos;
list_for_each_entry(pos, self->fwd_decls, node)
if (strcmp(pos->name, name) == 0)
if (strcmp(type__name(pos), name) == 0)
return pos;
return NULL;
@ -68,7 +68,7 @@ static int cus__emit_enumeration_definitions(struct cus *self, struct tag *tag,
return 0;
/* Ok, lets look at the previous CUs: */
if (cus__find_definition(self, etype->name) != NULL) {
if (cus__find_definition(self, type__name(etype)) != NULL) {
/*
* Yes, so lets mark it visited on this CU too,
* to speed up the lookup.
@ -98,7 +98,7 @@ static int cus__emit_typedef_definitions(struct cus *self, struct cu *cu,
return 0;
/* Ok, lets look at the previous CUs: */
if (cus__find_definition(self, def->name) != NULL) {
if (cus__find_definition(self, type__name(def)) != NULL) {
/*
* Yes, so lets mark it visited on this CU too,
* to speed up the lookup.
@ -133,9 +133,9 @@ static int cus__emit_typedef_definitions(struct cus *self, struct cu *cu,
};
tag__fprintf_decl_info(type, fp);
if (ctype->name == NULL) {
if (type__name(ctype) == NULL) {
fputs("typedef ", fp);
conf.suffix = def->name;
conf.suffix = type__name(def);
cus__emit_enumeration_definitions(self, type, &conf, fp);
goto out;
} else
@ -146,9 +146,9 @@ static int cus__emit_typedef_definitions(struct cus *self, struct cu *cu,
case DW_TAG_union_type: {
const struct type *ctype = tag__type(type);
if (ctype->name == NULL) {
if (type__name(ctype) == NULL) {
if (cus__emit_type_definitions(self, cu, type, fp))
type__emit(type, cu, "typedef", def->name, fp);
type__emit(type, cu, "typedef", type__name(def), fp);
goto out;
} else if (cus__emit_type_definitions(self, cu, type, fp))
type__emit(type, cu, NULL, NULL, fp);
@ -179,7 +179,7 @@ int cus__emit_fwd_decl(struct cus *self, struct type *ctype, FILE *fp)
return 0;
/* Ok, lets look at the previous CUs: */
if (cus__find_fwd_decl(self, ctype->name) != NULL) {
if (cus__find_fwd_decl(self, type__name(ctype)) != NULL) {
/*
* Yes, so lets mark it visited on this CU too,
* to speed up the lookup.
@ -190,7 +190,7 @@ int cus__emit_fwd_decl(struct cus *self, struct type *ctype, FILE *fp)
fprintf(fp, "%s %s;\n",
ctype->tag.tag == DW_TAG_union_type ? "union" : "struct",
ctype->name);
type__name(ctype));
cus__add_fwd_decl(self, ctype);
return 1;
}
@ -219,7 +219,7 @@ next_indirection:
case DW_TAG_typedef:
return cus__emit_typedef_definitions(self, cu, type, fp);
case DW_TAG_enumeration_type:
if (tag__type(type)->name != NULL) {
if (type__name(tag__type(type)) != NULL) {
tag__fprintf_decl_info(type, fp);
return cus__emit_enumeration_definitions(self, type,
NULL, fp);
@ -268,7 +268,7 @@ int cus__emit_type_definitions(struct cus *self, struct cu *cu,
return 0;
/* Ok, lets look at the previous CUs: */
if (cus__find_definition(self, ctype->name) != NULL) {
if (cus__find_definition(self, type__name(ctype)) != NULL) {
ctype->definition_emitted = 1;
return 0;
}
@ -292,7 +292,7 @@ void type__emit(struct tag *tag_self, struct cu *cu,
if (tag_self->tag == DW_TAG_structure_type)
class__find_holes(tag__class(tag_self), cu);
if (ctype->name != NULL || suffix != NULL || prefix != NULL) {
if (type__name(ctype) != NULL || suffix != NULL || prefix != NULL) {
struct conf_fprintf conf = {
.prefix = prefix,
.suffix = suffix,

View File

@ -181,7 +181,7 @@ static void class_formatter(const struct structure *self)
const struct type *tdef = tag__type(typedef_alias);
conf.prefix = "typedef";
conf.suffix = tdef->name;
conf.suffix = type__name(tdef);
}
tag__fprintf(tag, self->cu, &conf, stdout);
@ -414,10 +414,10 @@ static int nr_methods_iterator(struct tag *tag, struct cu *cu,
continue;
ctype = tag__type(type);
if (ctype->name == NULL)
if (type__name(ctype) == NULL)
continue;
str = structures__find(ctype->name);
str = structures__find(type__name(ctype));
if (str != NULL)
++str->nr_methods;
}