/* Support for printing C and C++ types for GDB, the GNU debugger.
- Copyright (C) 1986-2020 Free Software Foundation, Inc.
+ Copyright (C) 1986-2022 Free Software Foundation, Inc.
This file is part of GDB.
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
#include "bfd.h" /* Binary File Description. */
#include "symtab.h"
#include "gdbtypes.h"
code = type->code ();
if (local_name != NULL)
{
+ c_type_print_modifier (type, stream, 0, 1, language);
fputs_filtered (local_name, stream);
if (varstring != NULL && *varstring != '\0')
fputs_filtered (" ", stream);
int show, int level,
const struct type_print_options *flags)
{
- struct print_offset_data podata;
+ struct print_offset_data podata (flags);
c_print_type_1 (type, varstring, stream, show, level,
current_language->la_language, flags, &podata);
enum language language,
const struct type_print_options *flags)
{
- struct print_offset_data podata;
+ struct print_offset_data podata (flags);
c_print_type_1 (type, varstring, stream, show, level, language, flags,
&podata);
case TYPE_CODE_ARRAY:
c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
- stream, show, 0, 0, language, flags,
- podata);
+ stream, show, 0, need_post_space,
+ language, flags, podata);
if (passed_a_ptr)
fprintf_filtered (stream, "(");
break;
}
address_space_id
- = address_space_type_instance_flags_to_name (get_type_arch (type),
+ = address_space_type_instance_flags_to_name (type->arch (),
type->instance_flags ());
if (address_space_id)
{
form. Even the author of this function feels that writing little
parsers like this everywhere is stupid. */
-static char *
-remove_qualifiers (char *qid)
+static const char *
+remove_qualifiers (const char *qid)
{
int quoted = 0; /* Zero if we're not in quotes;
'"' if we're in a double-quoted string;
'\'' if we're in a single-quoted string. */
int depth = 0; /* Number of unclosed parens we've seen. */
char *parenstack = (char *) alloca (strlen (qid));
- char *scan;
- char *last = 0; /* The character after the rightmost
+ const char *scan;
+ const char *last = 0; /* The character after the rightmost
`::' token we've seen so far. */
for (scan = qid; *scan; scan++)
static bool
need_access_label_p (struct type *type)
{
- if (TYPE_DECLARED_CLASS (type))
+ if (type->is_declared_class ())
{
QUIT;
for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
c_type_print_modifier (type, stream, 0, 1, language);
if (type->code () == TYPE_CODE_UNION)
fprintf_filtered (stream, "union ");
- else if (TYPE_DECLARED_CLASS (type))
+ else if (type->is_declared_class ())
fprintf_filtered (stream, "class ");
else
fprintf_filtered (stream, "struct ");
if (type->num_fields () == 0 && TYPE_NFN_FIELDS (type) == 0
&& TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
{
+ print_spaces_filtered_with_print_options (level + 4, stream, flags);
if (type->is_stub ())
- fprintf_filtered (stream, _("%*s%p[<incomplete type>%p]\n"),
- level + 4, "",
+ fprintf_filtered (stream, _("%p[<incomplete type>%p]\n"),
metadata_style.style ().ptr (), nullptr);
else
- fprintf_filtered (stream, _("%*s%p[<no data fields>%p]\n"),
- level + 4, "",
+ fprintf_filtered (stream, _("%p[<no data fields>%p]\n"),
metadata_style.style ().ptr (), nullptr);
}
int len = type->num_fields ();
vptr_fieldno = get_vptr_fieldno (type, &basetype);
- struct print_offset_data local_podata;
+ struct print_offset_data local_podata (flags);
for (int i = TYPE_N_BASECLASSES (type); i < len; i++)
{
/* Make sure we carry our offset when we expand the
struct/union. */
local_podata.offset_bitpos
- = podata->offset_bitpos + TYPE_FIELD_BITPOS (type, i);
+ = podata->offset_bitpos + type->field (i).loc_bitpos ();
/* We're entering a struct/union. Right now,
PODATA->END_BITPOS points right *after* the
struct/union. However, when printing the first field
}
c_print_type_1 (type->field (i).type (),
- TYPE_FIELD_NAME (type, i),
+ type->field (i).name (),
stream, newshow, level + 4,
language, &local_flags, &local_podata);
{
const char *mangled_name;
gdb::unique_xmalloc_ptr<char> mangled_name_holder;
- char *demangled_name;
const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
int is_full_physname_constructor =
TYPE_FN_FIELD_CONSTRUCTOR (f, j)
else
mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
- demangled_name =
- gdb_demangle (mangled_name,
- DMGL_ANSI | DMGL_PARAMS);
+ gdb::unique_xmalloc_ptr<char> demangled_name
+ = gdb_demangle (mangled_name,
+ DMGL_ANSI | DMGL_PARAMS);
if (demangled_name == NULL)
{
/* In some cases (for instance with the HP
}
else
{
- char *p;
- char *demangled_no_class
- = remove_qualifiers (demangled_name);
+ const char *p;
+ const char *demangled_no_class
+ = remove_qualifiers (demangled_name.get ());
/* Get rid of the `static' appended by the
demangler. */
if (p != NULL)
{
int length = p - demangled_no_class;
- char *demangled_no_static;
-
- demangled_no_static
- = (char *) xmalloc (length + 1);
- strncpy (demangled_no_static,
- demangled_no_class, length);
- *(demangled_no_static + length) = '\0';
- fputs_filtered (demangled_no_static, stream);
- xfree (demangled_no_static);
+ std::string demangled_no_static (demangled_no_class,
+ length);
+ fputs_filtered (demangled_no_static.c_str (), stream);
}
else
fputs_filtered (demangled_no_class, stream);
- xfree (demangled_name);
}
fprintf_filtered (stream, ";\n");
fprintf_filtered (stream, "union ");
else if (type->code () == TYPE_CODE_STRUCT)
{
- if (TYPE_DECLARED_CLASS (type))
+ if (type->is_declared_class ())
fprintf_filtered (stream, "class ");
else
fprintf_filtered (stream, "struct ");
case TYPE_CODE_ENUM:
c_type_print_modifier (type, stream, 0, 1, language);
fprintf_filtered (stream, "enum ");
- if (TYPE_DECLARED_CLASS (type))
+ if (type->is_declared_class ())
fprintf_filtered (stream, "class ");
/* Print the tag name if it exists.
The aCC compiler emits a spurious
if (i)
fprintf_filtered (stream, ", ");
wrap_here (" ");
- fputs_styled (TYPE_FIELD_NAME (type, i),
+ fputs_styled (type->field (i).name (),
variable_name_style.style (), stream);
- if (lastval != TYPE_FIELD_ENUMVAL (type, i))
+ if (lastval != type->field (i).loc_enumval ())
{
fprintf_filtered (stream, " = %s",
- plongest (TYPE_FIELD_ENUMVAL (type, i)));
- lastval = TYPE_FIELD_ENUMVAL (type, i);
+ plongest (type->field (i).loc_enumval ()));
+ lastval = type->field (i).loc_enumval ();
}
lastval++;
}
/* We pass "show" here and not "show - 1" to get enum types
printed. There's no other way to see them. */
c_print_type_1 (type->field (i).type (),
- TYPE_FIELD_NAME (type, i),
+ type->field (i).name (),
stream, show, level + 4,
language, &local_flags, podata);
fprintf_filtered (stream, " @%s",
- plongest (TYPE_FIELD_BITPOS (type, i)));
+ plongest (type->field (i).loc_bitpos ()));
if (TYPE_FIELD_BITSIZE (type, i) > 1)
{
fprintf_filtered (stream, "-%s",
- plongest (TYPE_FIELD_BITPOS (type, i)
+ plongest (type->field (i).loc_bitpos ()
+ TYPE_FIELD_BITSIZE (type, i)
- 1));
}
int show, int level,
const struct type_print_options *flags)
{
- struct print_offset_data podata;
+ struct print_offset_data podata (flags);
c_type_print_base_1 (type, stream, show, level,
current_language->la_language, flags, &podata);