core: type__name() doesn't need a cu arg

Now that namespace->name is a real char string.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-06-24 20:41:37 -03:00
parent b99c4008ac
commit 00e8c5fe21
7 changed files with 60 additions and 80 deletions

View File

@ -748,7 +748,7 @@ static int32_t btf_encoder__add_struct_type(struct btf_encoder *encoder, struct
{
struct type *type = tag__type(tag);
struct class_member *pos;
const char *name = type__name(type, cu);
const char *name = type__name(type);
int32_t type_id;
uint8_t kind;
@ -789,7 +789,7 @@ static int32_t btf_encoder__add_enum_type(struct btf_encoder *encoder, struct cu
{
struct type *etype = tag__type(tag);
struct enumerator *pos;
const char *name = type__name(etype, cu);
const char *name = type__name(etype);
int32_t type_id;
type_id = btf_encoder__add_enum(encoder, name, etype->size);

View File

@ -757,7 +757,7 @@ struct tag *cu__find_enumeration_by_name_and_size(const struct cu *cu, const cha
const struct type *t = tag__type(pos);
if (t->size == bit_size &&
strcmp(type__name(t, cu), name) == 0) {
strcmp(type__name(t), name) == 0) {
if (idp != NULL)
*idp = id;
return pos;
@ -779,7 +779,7 @@ struct tag *cu__find_enumeration_by_name(const struct cu *cu, const char *name,
cu__for_each_type(cu, id, pos) {
if (pos->tag == DW_TAG_enumeration_type) {
const struct type *type = tag__type(pos);
const char *tname = type__name(type, cu);
const char *tname = type__name(type);
if (tname && strcmp(tname, name) == 0) {
if (idp != NULL)
@ -806,7 +806,7 @@ struct tag *cu__find_type_by_name(const struct cu *cu, const char *name, const i
continue;
type = tag__type(pos);
const char *tname = type__name(type, cu);
const char *tname = type__name(type);
if (tname && strcmp(tname, name) == 0) {
if (!type->declaration)
goto found;
@ -860,7 +860,7 @@ static struct tag *__cu__find_struct_by_name(const struct cu *cu, const char *na
continue;
type = tag__type(pos);
const char *tname = type__name(type, cu);
const char *tname = type__name(type);
if (tname && strcmp(tname, name) == 0) {
if (!type->declaration)
goto found;

View File

@ -1141,8 +1141,7 @@ static __pure inline const char *namespace__name(const struct namespace *nspace)
return nspace->name;
}
static __pure inline const char *type__name(const struct type *type,
const struct cu *cu)
static __pure inline const char *type__name(const struct type *type)
{
return namespace__name(&type->namespace);
}
@ -1150,7 +1149,7 @@ static __pure inline const char *type__name(const struct type *type,
static __pure inline const char *class__name(struct class *cls,
const struct cu *cu)
{
return type__name(&cls->type, cu);
return type__name(&cls->type);
}
static inline int class__is_struct(const struct class *cls)

View File

@ -46,8 +46,8 @@ struct type *type_emissions__find_definition(const struct type_emissions *emissi
return NULL;
list_for_each_entry(pos, &emissions->definitions, node)
if (type__name(pos, cu) != NULL &&
strcmp(type__name(pos, cu), name) == 0)
if (type__name(pos) != NULL &&
strcmp(type__name(pos), name) == 0)
return pos;
return NULL;
@ -63,7 +63,7 @@ static struct type *type_emissions__find_fwd_decl(const struct type_emissions *e
return NULL;
list_for_each_entry(pos, &emissions->fwd_decls, node) {
const char *curr_name = type__name(pos, cu);
const char *curr_name = type__name(pos);
if (curr_name && strcmp(curr_name, name) == 0)
return pos;
@ -84,8 +84,7 @@ static int enumeration__emit_definitions(struct tag *tag, struct cu *cu,
return 0;
/* Ok, lets look at the previous CUs: */
if (type_emissions__find_definition(emissions, cu,
type__name(etype, cu)) != NULL) {
if (type_emissions__find_definition(emissions, cu, type__name(etype)) != NULL) {
/*
* Yes, so lets mark it visited on this CU too,
* to speed up the lookup.
@ -114,8 +113,7 @@ static int typedef__emit_definitions(struct tag *tdef, struct cu *cu,
return 0;
/* Ok, lets look at the previous CUs: */
if (type_emissions__find_definition(emissions, cu,
type__name(def, cu)) != NULL) {
if (type_emissions__find_definition(emissions, cu, type__name(def)) != NULL) {
/*
* Yes, so lets mark it visited on this CU too,
* to speed up the lookup.
@ -155,9 +153,9 @@ static int typedef__emit_definitions(struct tag *tdef, struct cu *cu,
.suffix = NULL,
};
if (type__name(ctype, cu) == NULL) {
if (type__name(ctype) == NULL) {
fputs("typedef ", fp);
conf.suffix = type__name(def, cu);
conf.suffix = type__name(def);
enumeration__emit_definitions(type, cu, emissions,
&conf, fp);
goto out;
@ -170,10 +168,10 @@ static int typedef__emit_definitions(struct tag *tdef, struct cu *cu,
case DW_TAG_union_type: {
struct type *ctype = tag__type(type);
if (type__name(ctype, cu) == NULL) {
if (type__name(ctype) == NULL) {
if (type__emit_definitions(type, cu, emissions, fp))
type__emit(type, cu, "typedef",
type__name(def, cu), fp);
type__name(def), fp);
goto out;
} else if (type__emit_definitions(type, cu, emissions, fp))
type__emit(type, cu, NULL, NULL, fp);
@ -204,7 +202,7 @@ int type__emit_fwd_decl(struct type *ctype, const struct cu *cu,
if (ctype->fwd_decl_emitted)
return 0;
const char *name = type__name(ctype, cu);
const char *name = type__name(ctype);
if (name == NULL)
return 0;
@ -220,7 +218,7 @@ int type__emit_fwd_decl(struct type *ctype, const struct cu *cu,
fprintf(fp, "%s %s;\n",
tag__is_union(&ctype->namespace.tag) ? "union" : "struct",
type__name(ctype, cu));
type__name(ctype));
type_emissions__add_fwd_decl(emissions, ctype);
return 1;
}
@ -249,7 +247,7 @@ next_indirection:
case DW_TAG_typedef:
return typedef__emit_definitions(type, cu, emissions, fp);
case DW_TAG_enumeration_type:
if (type__name(tag__type(type), cu) != NULL) {
if (type__name(tag__type(type)) != NULL) {
struct conf_fprintf conf = {
.suffix = NULL,
};
@ -264,7 +262,7 @@ next_indirection:
* Struct defined inline, no name, need to have its
* members types emitted.
*/
if (type__name(tag__type(type), cu) == NULL)
if (type__name(tag__type(type)) == NULL)
type__emit_definitions(type, cu, emissions, fp);
return type__emit_fwd_decl(tag__type(type), cu,
@ -308,8 +306,7 @@ int type__emit_definitions(struct tag *tag, struct cu *cu,
return 0;
/* Ok, lets look at the previous CUs: */
if (type_emissions__find_definition(emissions, cu,
type__name(ctype, cu)) != NULL) {
if (type_emissions__find_definition(emissions, cu, type__name(ctype)) != NULL) {
ctype->definition_emitted = 1;
return 0;
}
@ -333,7 +330,7 @@ void type__emit(struct tag *tag, struct cu *cu,
{
struct type *ctype = tag__type(tag);
if (type__name(ctype, cu) != NULL ||
if (type__name(ctype) != NULL ||
suffix != NULL || prefix != NULL) {
struct conf_fprintf conf = {
.prefix = prefix,

View File

@ -274,21 +274,19 @@ size_t typedef__fprintf(const struct tag *tag, const struct cu *cu,
* to avoid all these checks?
*/
if (tag->type == 0)
return fprintf(fp, "typedef void %s", type__name(type, cu));
return fprintf(fp, "typedef void %s", type__name(type));
tag_type = cu__type(cu, tag->type);
if (tag_type == NULL) {
printed = fprintf(fp, "typedef ");
printed += tag__id_not_found_fprintf(fp, tag->type);
return printed + fprintf(fp, " %s", type__name(type, cu));
return printed + fprintf(fp, " %s", type__name(type));
}
switch (tag_type->tag) {
case DW_TAG_array_type:
printed = fprintf(fp, "typedef ");
return printed + array_type__fprintf(tag_type, cu,
type__name(type, cu),
pconf, fp);
return printed + array_type__fprintf(tag_type, cu, type__name(type), pconf, fp);
case DW_TAG_pointer_type:
if (tag_type->type == 0) /* void pointer */
break;
@ -296,8 +294,7 @@ size_t typedef__fprintf(const struct tag *tag, const struct cu *cu,
if (ptr_type == NULL) {
printed = fprintf(fp, "typedef ");
printed += tag__id_not_found_fprintf(fp, tag_type->type);
return printed + fprintf(fp, " *%s",
type__name(type, cu));
return printed + fprintf(fp, " *%s", type__name(type));
}
if (ptr_type->tag != DW_TAG_subroutine_type)
break;
@ -306,40 +303,35 @@ size_t typedef__fprintf(const struct tag *tag, const struct cu *cu,
/* Fall thru */
case DW_TAG_subroutine_type:
printed = fprintf(fp, "typedef ");
return printed + ftype__fprintf(tag__ftype(tag_type), cu,
type__name(type, cu),
0, is_pointer, 0,
true, pconf, fp);
return printed + ftype__fprintf(tag__ftype(tag_type), cu, type__name(type),
0, is_pointer, 0, true, pconf, fp);
case DW_TAG_class_type:
case DW_TAG_structure_type: {
struct type *ctype = tag__type(tag_type);
if (type__name(ctype, cu) != NULL)
return fprintf(fp, "typedef struct %s %s",
type__name(ctype, cu),
type__name(type, cu));
if (type__name(ctype) != NULL)
return fprintf(fp, "typedef struct %s %s", type__name(ctype), type__name(type));
struct conf_fprintf tconf = *pconf;
tconf.suffix = type__name(type, cu);
tconf.suffix = type__name(type);
return fprintf(fp, "typedef ") + __class__fprintf(tag__class(tag_type), cu, &tconf, fp);
}
case DW_TAG_enumeration_type: {
struct type *ctype = tag__type(tag_type);
if (type__name(ctype, cu) != NULL)
return fprintf(fp, "typedef enum %s %s", type__name(ctype, cu), type__name(type, cu));
if (type__name(ctype) != NULL)
return fprintf(fp, "typedef enum %s %s", type__name(ctype), type__name(type));
struct conf_fprintf tconf = *pconf;
tconf.suffix = type__name(type, cu);
tconf.suffix = type__name(type);
return fprintf(fp, "typedef ") + enumeration__fprintf(tag_type, cu, &tconf, fp);
}
}
return fprintf(fp, "typedef %s %s",
tag__name(tag_type, cu, bf, sizeof(bf), pconf),
type__name(type, cu));
tag__name(tag_type, cu, bf, sizeof(bf), pconf), type__name(type));
}
static size_t imported_declaration__fprintf(const struct tag *tag,
@ -393,9 +385,7 @@ size_t enumeration__fprintf(const struct tag *tag, const struct cu *cu,
struct type *type = tag__type(tag);
struct enumerator *pos;
int max_entry_name_len = enumeration__max_entry_name_len(type, cu);
size_t printed = fprintf(fp, "enum%s%s {\n",
type__name(type, cu) ? " " : "",
type__name(type, cu) ?: "");
size_t printed = fprintf(fp, "enum%s%s {\n", type__name(type) ? " " : "", type__name(type) ?: "");
int indent = conf->indent;
if (indent >= (int)sizeof(tabs))
@ -574,7 +564,7 @@ static const char *__tag__name(const struct tag *tag, const struct cu *cu,
break;
default:
snprintf(bf, len, "%s%s", tag__prefix(cu, tag->tag, pconf),
type__name(tag__type(tag), cu) ?: "");
type__name(tag__type(tag)) ?: "");
break;
}
@ -700,11 +690,9 @@ static size_t type__fprintf(struct tag *type, const struct cu *cu,
ctype = tag__type(type);
if (typedef_expanded)
printed += fprintf(fp, " -> %s",
type__name(ctype, cu));
printed += fprintf(fp, " -> %s", type__name(ctype));
else {
printed += fprintf(fp, "/* typedef %s",
type__name(ctype, cu));
printed += fprintf(fp, "/* typedef %s", type__name(ctype));
typedef_expanded = 1;
}
type_type = cu__type(cu, type->type);
@ -749,7 +737,7 @@ next_type:
break;
}
if ((tag__is_struct(ptype) || tag__is_union(ptype) ||
tag__is_enumeration(ptype)) && type__name(tag__type(ptype), cu) == NULL) {
tag__is_enumeration(ptype)) && type__name(tag__type(ptype)) == NULL) {
if (name == namebfptr)
goto out_type_not_found;
snprintf(namebfptr, sizeof(namebfptr), "* %.*s", (int)sizeof(namebfptr) - 3, name);
@ -794,12 +782,12 @@ print_default:
case DW_TAG_structure_type:
ctype = tag__type(type);
if (type__name(ctype, cu) != NULL && !expand_types) {
if (type__name(ctype) != NULL && !expand_types) {
printed += fprintf(fp, "%s %-*s %s",
(type->tag == DW_TAG_class_type &&
!tconf.classes_as_structs) ? "class" : "struct",
tconf.type_spacing - 7,
type__name(ctype, cu), name);
type__name(ctype), name);
} else {
struct class *cclass = tag__class(type);
@ -813,10 +801,8 @@ print_default:
case DW_TAG_union_type:
ctype = tag__type(type);
if (type__name(ctype, cu) != NULL && !expand_types) {
printed += fprintf(fp, "union %-*s %s",
tconf.type_spacing - 6,
type__name(ctype, cu), name);
if (type__name(ctype) != NULL && !expand_types) {
printed += fprintf(fp, "union %-*s %s", tconf.type_spacing - 6, type__name(ctype), name);
} else {
tconf.type_spacing -= 8;
printed += union__fprintf(ctype, cu, &tconf, fp);
@ -825,10 +811,8 @@ print_default:
case DW_TAG_enumeration_type:
ctype = tag__type(type);
if (type__name(ctype, cu) != NULL)
printed += fprintf(fp, "enum %-*s %s",
tconf.type_spacing - 5,
type__name(ctype, cu), name);
if (type__name(ctype) != NULL)
printed += fprintf(fp, "enum %-*s %s", tconf.type_spacing - 5, type__name(ctype), name);
else
printed += enumeration__fprintf(type, cu, &tconf, fp);
break;
@ -897,7 +881,7 @@ static size_t class_member__fprintf(struct class_member *member, bool union_memb
if ((tag__is_union(type) || tag__is_struct(type) ||
tag__is_enumeration(type)) &&
/* Look if is a type defined inline */
type__name(tag__type(type), cu) == NULL) {
type__name(tag__type(type)) == NULL) {
if (!sconf.suppress_offset_comment) {
/* Check if this is a anonymous union */
int slen = cm_name ? (int)strlen(cm_name) : -1;
@ -998,8 +982,8 @@ static size_t union__fprintf(struct type *type, const struct cu *cu,
if (conf->prefix != NULL)
printed += fprintf(fp, "%s ", conf->prefix);
printed += fprintf(fp, "union%s%s {\n", type__name(type, cu) ? " " : "",
type__name(type, cu) ?: "");
printed += fprintf(fp, "union%s%s {\n", type__name(type) ? " " : "",
type__name(type) ?: "");
uconf = *conf;
uconf.indent = indent + 1;
@ -1384,8 +1368,8 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu,
t == DW_TAG_structure_type) ? "struct" :
t == DW_TAG_class_type ? "class" :
"interface"),
type__name(type, cu) ? " " : "",
type__name(type, cu) ?: "");
type__name(type) ? " " : "",
type__name(type) ?: "");
int indent = cconf.indent;
if (indent >= (int)sizeof(tabs))
@ -1424,7 +1408,7 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu,
struct tag *pos_type = cu__type(cu, tag_pos->type);
if (pos_type != NULL)
printed += fprintf(fp, " %s",
type__name(tag__type(pos_type), cu));
type__name(tag__type(pos_type)));
else
printed += tag__id_not_found_fprintf(fp, tag_pos->type);
}

View File

@ -234,7 +234,7 @@ static void class_formatter(struct class *class, struct cu *cu, uint32_t id)
struct type *tdef = tag__type(typedef_alias);
conf.prefix = "typedef";
conf.suffix = type__name(tdef, cu);
conf.suffix = type__name(tdef);
} else
conf.prefix = conf.suffix = NULL;
@ -795,7 +795,7 @@ static int type__print_containers(struct type *type, struct cu *cu, uint32_t con
return 0;
}
printf("%.*s%s", ident * 2, tab, type__name(type, cu));
printf("%.*s%s", ident * 2, tab, type__name(type));
if (global_verbose)
printf(": %u", n);
putchar('\n');
@ -2150,7 +2150,7 @@ do_read:
real_type = type;
if (global_verbose) {
printed += fprintf(fp, "// type=%s, offset=%#" PRIx64 ", sizeof=%d", type__name(tag__type(type), cu), record_offset, _sizeof);
printed += fprintf(fp, "// type=%s, offset=%#" PRIx64 ", sizeof=%d", type__name(tag__type(type)), record_offset, _sizeof);
if (real_sizeof != _sizeof)
printed += fprintf(fp, ", real_sizeof=%d\n", real_sizeof);
else
@ -2200,7 +2200,7 @@ static int class_member_filter__parse(struct class_member_filter *filter, struct
if (!filter->left) {
if (global_verbose)
fprintf(stderr, "The '%s' member wasn't found in '%s'\n", member_name, type__name(type, cu));
fprintf(stderr, "The '%s' member wasn't found in '%s'\n", member_name, type__name(type));
s[1] = before;
return -1;
}
@ -2210,7 +2210,7 @@ static int class_member_filter__parse(struct class_member_filter *filter, struct
while (isspace(*value))
if (*++value == '\0') {
if (global_verbose)
fprintf(stderr, "The '%s' member was asked without a value to filter '%s'\n", member_name, type__name(type, cu));
fprintf(stderr, "The '%s' member was asked without a value to filter '%s'\n", member_name, type__name(type));
return -1; // no value
}

View File

@ -387,9 +387,9 @@ static void function__show(struct function *func, struct cu *cu)
else if (tag__is_struct(type))
fprintf(stdout, "\n\treturn *(struct %s *)1;", class__name(tag__class(type), cu));
else if (tag__is_union(type))
fprintf(stdout, "\n\treturn *(union %s *)1;", type__name(tag__type(type), cu));
fprintf(stdout, "\n\treturn *(union %s *)1;", type__name(tag__type(type)));
else if (tag__is_typedef(type))
fprintf(stdout, "\n\treturn *(%s *)1;", type__name(tag__type(type), cu));
fprintf(stdout, "\n\treturn *(%s *)1;", type__name(tag__type(type)));
else
fprintf(stdout, "\n\treturn 0;");
}