/* D language support routines for GDB, the GNU debugger.
- Copyright (C) 2005-2021 Free Software Foundation, Inc.
+ Copyright (C) 2005-2023 Free Software Foundation, Inc.
This file is part of GDB.
/* Implements the la_demangle language_defn routine for language D. */
-char *
+gdb::unique_xmalloc_ptr<char>
d_demangle (const char *symbol, int options)
{
return gdb_demangle (symbol, options | DMGL_DLANG);
}
-/* Table mapping opcodes into strings for printing operators
- and precedences of the operators. */
-static const struct op_print d_op_print_tab[] =
-{
- {",", BINOP_COMMA, PREC_COMMA, 0},
- {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
- {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
- {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
- {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
- {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
- {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
- {"==", BINOP_EQUAL, PREC_ORDER, 0},
- {"!=", BINOP_NOTEQUAL, PREC_ORDER, 0},
- {"<=", BINOP_LEQ, PREC_ORDER, 0},
- {">=", BINOP_GEQ, PREC_ORDER, 0},
- {">", BINOP_GTR, PREC_ORDER, 0},
- {"<", BINOP_LESS, PREC_ORDER, 0},
- {">>", BINOP_RSH, PREC_SHIFT, 0},
- {"<<", BINOP_LSH, PREC_SHIFT, 0},
- {"+", BINOP_ADD, PREC_ADD, 0},
- {"-", BINOP_SUB, PREC_ADD, 0},
- {"~", BINOP_CONCAT, PREC_ADD, 0},
- {"*", BINOP_MUL, PREC_MUL, 0},
- {"/", BINOP_DIV, PREC_MUL, 0},
- {"%", BINOP_REM, PREC_MUL, 0},
- {"^^", BINOP_EXP, PREC_REPEAT, 0},
- {"@", BINOP_REPEAT, PREC_REPEAT, 0},
- {"-", UNOP_NEG, PREC_PREFIX, 0},
- {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
- {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
- {"*", UNOP_IND, PREC_PREFIX, 0},
- {"&", UNOP_ADDR, PREC_PREFIX, 0},
- {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
- {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
- {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
- {NULL, OP_NULL, PREC_PREFIX, 0}
-};
-
/* Class representing the D language. */
class d_language : public language_defn
}
/* See language.h. */
- bool sniff_from_mangled_name (const char *mangled,
- char **demangled) const override
+ bool sniff_from_mangled_name
+ (const char *mangled,
+ gdb::unique_xmalloc_ptr<char> *demangled) const override
{
*demangled = d_demangle (mangled, 0);
return *demangled != NULL;
/* See language.h. */
- char *demangle_symbol (const char *mangled, int options) const override
+ gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const override
{
return d_demangle (mangled, options);
}
/* See language.h. */
+ bool can_print_type_offsets () const override
+ {
+ return true;
+ }
+
+ /* See language.h. */
+
void print_type (struct type *type, const char *varstring,
struct ui_file *stream, int show, int level,
const struct type_print_options *flags) const override
{
- c_print_type (type, varstring, stream, show, level, flags);
+ c_print_type (type, varstring, stream, show, level, la_language, flags);
}
/* See language.h. */
const char *name_of_this () const override
{ return "this"; }
-
- /* See language.h. */
-
- const struct exp_descriptor *expression_ops () const override
- { return &exp_descriptor_c; }
-
- /* See language.h. */
-
- const struct op_print *opcode_print_table () const override
- { return d_op_print_tab; }
};
/* Single instance of the D language class. */
/* Build all D language types for the specified architecture. */
-static void *
+static struct builtin_d_type *
build_d_types (struct gdbarch *gdbarch)
{
- struct builtin_d_type *builtin_d_type
- = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_d_type);
+ struct builtin_d_type *builtin_d_type = new struct builtin_d_type;
/* Basic types. */
builtin_d_type->builtin_void
return builtin_d_type;
}
-static struct gdbarch_data *d_type_data;
+static const registry<gdbarch>::key<struct builtin_d_type> d_type_data;
/* Return the D type table for the specified architecture. */
const struct builtin_d_type *
builtin_d_type (struct gdbarch *gdbarch)
{
- return (const struct builtin_d_type *) gdbarch_data (gdbarch, d_type_data);
-}
+ struct builtin_d_type *result = d_type_data.get (gdbarch);
+ if (result == nullptr)
+ {
+ result = build_d_types (gdbarch);
+ d_type_data.set (gdbarch, result);
+ }
-void _initialize_d_language ();
-void
-_initialize_d_language ()
-{
- d_type_data = gdbarch_data_register_post_init (build_d_types);
+ return result;
}