int show;
int level;
{
- char *name;
register int i;
register int len;
register int lastval;
}
/* When SHOW is zero or less, and there is a valid type name, then always
- just print the type name directly from the type. */
+ just print the type name directly from the type. */
+ /* If we have "typedef struct foo {. . .} bar;" do we want to print it
+ as "struct foo" or as "bar"? Pick the latter, because C++ folk tend
+ to expect things like "class5 *foo" rather than "struct class5 *foo". */
- if ((show <= 0) && (TYPE_NAME (type) != NULL))
+ if (show <= 0
+ && TYPE_NAME (type) != NULL)
{
fputs_filtered (TYPE_NAME (type), stream);
return;
case TYPE_CODE_STRUCT:
if (HAVE_CPLUS_STRUCT (type))
{
- /* Always print it as "class foo" even if foo is a typedef'd
- name, not a tag. */
fprintf_filtered (stream, "class ");
- name = type_name_no_tag (type);
- if (name != NULL)
- {
- fputs_filtered (name, stream);
- fputs_filtered (" ", stream);
- wrap_here (" ");
- }
}
else
{
fprintf_filtered (stream, "struct ");
- name = TYPE_NAME (type);
- /* If the name does not start with "struct " it means that the
- type was defined without a tag, so don't print a tag. It is
- possible that we should have a better way of distinguising
- tag names from typedef'd names. (e.g. a new tagname field in
- the struct type). */
- if (name != NULL && strncmp (name, "struct ", 7) == 0)
- {
- fputs_filtered (name + 7, stream);
- fputs_filtered (" ", stream);
- }
}
goto struct_union;
case TYPE_CODE_UNION:
fprintf_filtered (stream, "union ");
- if (HAVE_CPLUS_STRUCT (type))
- {
- /* Always print it as "union foo" even if foo is a typedef'd
- name, not a tag. */
- name = type_name_no_tag (type);
- if (name != NULL)
- {
- fputs_filtered (name, stream);
- fputs_filtered (" ", stream);
- wrap_here (" ");
- }
- }
- else
+
+ struct_union:
+ if (TYPE_TAG_NAME (type) != NULL)
{
- name = TYPE_NAME (type);
- /* If the name does not start with "union " it means that the
- type was defined without a tag, so don't print a tag. It is
- possible that we should have a better way of distinguising
- tag names from typedef'd names. (e.g. a new tagname field in
- the struct type). */
- if (name != NULL && strncmp (name, "union ", 6) == 0)
- {
- fputs_filtered (name + 6, stream);
- fputs_filtered (" ", stream);
- }
+ fputs_filtered (TYPE_TAG_NAME (type), stream);
+ if (show > 0)
+ fputs_filtered (" ", stream);
}
- struct_union:
wrap_here (" ");
if (show < 0)
- fprintf_filtered (stream, "{...}");
- else
+ {
+ /* If we just printed a tag name, no need to print anything else. */
+ if (TYPE_TAG_NAME (type) == NULL)
+ fprintf_filtered (stream, "{...}");
+ }
+ else if (show > 0)
{
check_stub_type (type);
struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
+ char *name = type_name_no_tag (type);
int is_constructor = name && STREQ(method_name, name);
for (j = 0; j < len2; j++)
{
case TYPE_CODE_ENUM:
fprintf_filtered (stream, "enum ");
- name = TYPE_NAME (type);
-
- /* If the name does not start with "enum " it means that the
- type was defined without a tag, so don't print a tag. It is
- possible that we should have a better way of distinguising
- tag names from typedef'd names. (e.g. a new tagname field in
- the struct type). */
- if (name != NULL && strncmp (name, "enum ", 5) == 0)
+ if (TYPE_TAG_NAME (type) != NULL)
{
- fputs_filtered (name + 5, stream);
- fputs_filtered (" ", stream);
+ fputs_filtered (TYPE_TAG_NAME (type), stream);
+ if (show > 0)
+ fputs_filtered (" ", stream);
}
wrap_here (" ");
if (show < 0)
- fprintf_filtered (stream, "{...}");
- else
+ {
+ /* If we just printed a tag name, no need to print anything else. */
+ if (TYPE_TAG_NAME (type) == NULL)
+ fprintf_filtered (stream, "{...}");
+ }
+ else if (show > 0)
{
fprintf_filtered (stream, "{");
len = TYPE_NFIELDS (type);
struct nextfield *new;
int nfields = 0;
int n;
- char *tpart1;
struct dieinfo mbr;
char *nextdie;
#if !BITS_BIG_ENDIAN
{
case TAG_class_type:
TYPE_CODE (type) = TYPE_CODE_CLASS;
- tpart1 = "class";
break;
case TAG_structure_type:
TYPE_CODE (type) = TYPE_CODE_STRUCT;
- tpart1 = "struct";
break;
case TAG_union_type:
TYPE_CODE (type) = TYPE_CODE_UNION;
- tpart1 = "union";
break;
default:
/* Should never happen */
TYPE_CODE (type) = TYPE_CODE_UNDEF;
- tpart1 = "???";
complain (&missing_tag, DIE_ID, DIE_NAME);
break;
}
&& *dip -> at_name != '~'
&& *dip -> at_name != '.')
{
- TYPE_NAME (type) = obconcat (&objfile -> type_obstack,
- tpart1, " ", dip -> at_name);
+ TYPE_TAG_NAME (type) = obconcat (&objfile -> type_obstack,
+ "", "", dip -> at_name);
}
/* Use whatever size is known. Zero is a valid size. We might however
wish to check has_at_byte_size to make sure that some byte size was
&& *dip -> at_name != '~'
&& *dip -> at_name != '.')
{
- TYPE_NAME (type) = obconcat (&objfile -> type_obstack, "enum",
- " ", dip -> at_name);
+ TYPE_TAG_NAME (type) = obconcat (&objfile -> type_obstack,
+ "", "", dip -> at_name);
}
if (dip -> at_byte_size != 0)
{
TYPE_CODE (type) = TYPE_CODE_METHOD;
}
-/* Return a typename for a struct/union/enum type
- without the tag qualifier. If the type has a NULL name,
- NULL is returned. */
+/* Return a typename for a struct/union/enum type without "struct ",
+ "union ", or "enum ". If the type has a NULL name, return NULL. */
char *
type_name_no_tag (type)
register const struct type *type;
{
- register char *name;
+ if (TYPE_TAG_NAME (type) != NULL)
+ return TYPE_TAG_NAME (type);
- if ((name = TYPE_NAME (type)) != NULL)
- {
- switch (TYPE_CODE (type))
- {
- case TYPE_CODE_STRUCT:
- if(!strncmp (name, "struct ", 7))
- {
- name += 7;
- }
- break;
- case TYPE_CODE_UNION:
- if(!strncmp (name, "union ", 6))
- {
- name += 6;
- }
- break;
- case TYPE_CODE_ENUM:
- if(!strncmp (name, "enum ", 5))
- {
- name += 5;
- }
- break;
- default: /* To avoid -Wall warnings */
- break;
- }
- }
- return (name);
+ /* Is there code which expects this to return the name if there is no
+ tag name? My guess is that this is mainly used for C++ in cases where
+ the two will always be the same. */
+ return TYPE_NAME (type);
}
/* Lookup a primitive type named NAME.
char *name;
+ /* Tag name for this type, or NULL if none. This is a feature which is
+ specific to C/C++ for structs, unions, or enums.
+ This is used for printing only, except by poorly designed C++ code. */
+
+ char *tag_name;
+
/* Length, in units of TARGET_CHAR_BIT bits,
of storage for a value of this type */
(TYPE_CPLUS_SPECIFIC(type) != &cplus_struct_default)
#define TYPE_NAME(thistype) (thistype)->name
+#define TYPE_TAG_NAME(type) ((type)->tag_name)
#define TYPE_TARGET_TYPE(thistype) (thistype)->target_type
#define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
#define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
SYMBOL_CLASS (sym) = LOC_TYPEDEF;
SYMBOL_VALUE (sym) = valu;
SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
- if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
- TYPE_NAME (SYMBOL_TYPE (sym))
- = obconcat (&objfile -> type_obstack, "",
- (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
- ? "enum "
- : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
- ? "struct " : "union ")),
- SYMBOL_NAME (sym));
+ if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
+ TYPE_TAG_NAME (SYMBOL_TYPE (sym))
+ = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
add_symbol_to_list (sym, &file_symbols);
if (synonym)
SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
SYMBOL_VALUE (typedef_sym) = valu;
SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
+ if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
+ TYPE_NAME (SYMBOL_TYPE (sym))
+ = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
add_symbol_to_list (typedef_sym, &file_symbols);
}
break;
{
case 's':
code = TYPE_CODE_STRUCT;
- prefix = "struct ";
break;
case 'u':
code = TYPE_CODE_UNION;
- prefix = "union ";
break;
case 'e':
code = TYPE_CODE_ENUM;
- prefix = "enum ";
break;
default:
return error_type (pp);
to = type_name = (char *)
obstack_alloc (&objfile -> type_obstack,
- (strlen (prefix) +
- ((char *) strchr (*pp, ':') - (*pp)) + 1));
+ (((char *) strchr (*pp, ':') - (*pp)) + 1));
- /* Copy the prefix. */
- from = prefix;
- while ((*to++ = *from++) != '\0')
- ;
- to--;
-
- type_name_only = to;
-
/* Copy the name. */
from = *pp + 1;
while ((*to++ = *from++) != ':')
/* Set the pointer ahead of the name which we just read. */
*pp = from;
-
-#if 0
- /* The following hack is clearly wrong, because it doesn't
- check whether we are in a baseclass. I tried to reproduce
- the case that it is trying to fix, but I couldn't get
- g++ to put out a cross reference to a basetype. Perhaps
- it doesn't do it anymore. */
- /* Note: for C++, the cross reference may be to a base type which
- has not yet been seen. In this case, we skip to the comma,
- which will mark the end of the base class name. (The ':'
- at the end of the base class name will be skipped as well.)
- But sometimes (ie. when the cross ref is the last thing on
- the line) there will be no ','. */
- from = (char *) strchr (*pp, ',');
- if (from)
- *pp = from;
-#endif /* 0 */
}
/* Now check to see whether the type has already been declared. */
if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
&& SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
&& (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
- && STREQ (SYMBOL_NAME (sym), type_name_only))
+ && STREQ (SYMBOL_NAME (sym), type_name))
{
obstack_free (&objfile -> type_obstack, type_name);
type = SYMBOL_TYPE (sym);
type. */
type = dbx_alloc_type (typenums, objfile);
TYPE_CODE (type) = code;
- TYPE_NAME (type) = type_name;
+ TYPE_TAG_NAME (type) = type_name;
INIT_CPLUS_SPECIFIC(type);
TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
struct pending *ppt;
int i;
/* Name of the type, without "struct" or "union" */
- char *typename = type_name_no_tag (*type);
+ char *typename = TYPE_TAG_NAME (*type);
if (typename == NULL)
{