diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-08-06 11:14:37 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-10-23 10:57:13 +0100 |
commit | b01175fc46bbb9103bde88ec93236bcb6719c696 (patch) | |
tree | 99cd85540b79968319d8579877bb98c200c57133 /gdb/language.c | |
parent | a948551942824947baaf6a077745fb5480d264a7 (diff) | |
download | gdb-b01175fc46bbb9103bde88ec93236bcb6719c696.zip gdb-b01175fc46bbb9103bde88ec93236bcb6719c696.tar.gz gdb-b01175fc46bbb9103bde88ec93236bcb6719c696.tar.bz2 |
gdb: Merge auto and unknown language implementations
The auto_language and unknown_language classes are basically the same
except for the language names and store_sym_names_in_linkage_form_p
which the unknown_language overrides to return true, while
auto_language returns the default false.
This commit creates a new parent class from which both of these
languages can inherit. The two base classes are now greatly reduced.
Some of the static helper functions which previously were called from
both of these languages are now only called from one place, and so
I've inlined them into the new class.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* language.c (default_is_string_type_p): Delete, implementation
moved into auto_or_unknown_language::is_string_type_p.
(unk_op_print_tab): Moved into
auto_or_unknown_language::opcode_print_table.
(unknown_language_arch_info): Delete, implementation moved into
auto_or_unknown_language::language_arch_info.
(class auto_or_unknown_language): New class, member functions
copied from unknown_language class, with some updates.
(class unknown_language): Most member functions moved into
auto_or_unknown_language class. Inherit from
auto_or_unknown_language class.
(class auto_language): Inherit from auto_or_unknown_language.
Delete most member functions.
Diffstat (limited to 'gdb/language.c')
-rw-r--r-- | gdb/language.c | 215 |
1 files changed, 60 insertions, 155 deletions
diff --git a/gdb/language.c b/gdb/language.c index 761f496..ffc1e85 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -782,60 +782,25 @@ language_defn::expression_ops () const return &exp_descriptor_standard; } -/* Return true if TYPE is a string type, otherwise return false. This - default implementation only detects TYPE_CODE_STRING. */ +/* Parent class for both the "auto" and "unknown" languages. These two + pseudo-languages are very similar so merging their implementations like + this makes sense. */ -static bool -default_is_string_type_p (struct type *type) -{ - type = check_typedef (type); - while (type->code () == TYPE_CODE_REF) - { - type = TYPE_TARGET_TYPE (type); - type = check_typedef (type); - } - return (type->code () == TYPE_CODE_STRING); -} - -static const struct op_print unk_op_print_tab[] = -{ - {NULL, OP_NULL, PREC_NULL, 0} -}; - -static void -unknown_language_arch_info (struct gdbarch *gdbarch, - struct language_arch_info *lai) -{ - lai->string_char_type = builtin_type (gdbarch)->builtin_char; - lai->bool_type_default = builtin_type (gdbarch)->builtin_int; - lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, - struct type *); -} - -/* Class representing the unknown language. */ - -class unknown_language : public language_defn +class auto_or_unknown_language : public language_defn { public: - unknown_language () - : language_defn (language_unknown) + auto_or_unknown_language (enum language lang) + : language_defn (lang) { /* Nothing. */ } /* See language.h. */ - - const char *name () const override - { return "unknown"; } - - /* See language.h. */ - - const char *natural_name () const override - { return "Unknown"; } - - /* See language.h. */ void language_arch_info (struct gdbarch *gdbarch, struct language_arch_info *lai) const override { - unknown_language_arch_info (gdbarch, lai); + lai->string_char_type = builtin_type (gdbarch)->builtin_char; + lai->bool_type_default = builtin_type (gdbarch)->builtin_int; + lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, + struct type *); } /* See language.h. */ @@ -844,14 +809,15 @@ public: struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override { - error (_("unimplemented unknown_language::print_type called")); + error (_("type printing not implemented for language \"%s\""), + natural_name ()); } /* See language.h. */ char *demangle (const char *mangled, int options) const override { - /* The unknown language just uses the C++ demangler. */ + /* The auto language just uses the C++ demangler. */ return gdb_demangle (mangled, options); } @@ -860,7 +826,8 @@ public: void value_print (struct value *val, struct ui_file *stream, const struct value_print_options *options) const override { - error (_("unimplemented unknown_language::value_print called")); + error (_("value printing not implemented for language \"%s\""), + natural_name ()); } /* See language.h. */ @@ -869,7 +836,8 @@ public: (struct value *val, struct ui_file *stream, int recurse, const struct value_print_options *options) const override { - error (_("unimplemented unknown_language::value_print_inner called")); + error (_("inner value printing not implemented for language \"%s\""), + natural_name ()); } /* See language.h. */ @@ -885,7 +853,8 @@ public: void emitchar (int ch, struct type *chtype, struct ui_file *stream, int quoter) const override { - error (_("unimplemented unknown_language::emitchar called")); + error (_("emit character not implemented for language \"%s\""), + natural_name ()); } /* See language.h. */ @@ -893,7 +862,8 @@ public: void printchar (int ch, struct type *chtype, struct ui_file *stream) const override { - error (_("unimplemented unknown_language::printchar called")); + error (_("print character not implemented for language \"%s\""), + natural_name ()); } /* See language.h. */ @@ -903,7 +873,8 @@ public: const char *encoding, int force_ellipses, const struct value_print_options *options) const override { - error (_("unimplemented unknown_language::printstr called")); + error (_("print string not implemented for language \"%s\""), + natural_name ()); } /* See language.h. */ @@ -911,14 +882,21 @@ public: void print_typedef (struct type *type, struct symbol *new_symbol, struct ui_file *stream) const override { - error (_("unimplemented unknown_language::print_typedef called")); + error (_("print typedef not implemented for language \"%s\""), + natural_name ()); } /* See language.h. */ bool is_string_type_p (struct type *type) const override { - return default_is_string_type_p (type); + type = check_typedef (type); + while (type->code () == TYPE_CODE_REF) + { + type = TYPE_TARGET_TYPE (type); + type = check_typedef (type); + } + return (type->code () == TYPE_CODE_STRING); } /* See language.h. */ @@ -928,26 +906,24 @@ public: /* See language.h. */ - bool store_sym_names_in_linkage_form_p () const override - { return true; } - - /* See language.h. */ - const struct op_print *opcode_print_table () const override - { return unk_op_print_tab; } -}; - -/* Single instance of the unknown language class. */ + { + static const struct op_print unk_op_print_tab[] = + { + {NULL, OP_NULL, PREC_NULL, 0} + }; -static unknown_language unknown_language_defn; + return unk_op_print_tab; + } +}; /* Class representing the fake "auto" language. */ -class auto_language : public language_defn +class auto_language : public auto_or_unknown_language { public: auto_language () - : language_defn (language_auto) + : auto_or_unknown_language (language_auto) { /* Nothing. */ } /* See language.h. */ @@ -959,111 +935,40 @@ public: const char *natural_name () const override { return "Auto"; } +}; - /* See language.h. */ - void language_arch_info (struct gdbarch *gdbarch, - struct language_arch_info *lai) const override - { - unknown_language_arch_info (gdbarch, lai); - } - - /* 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 - { - error (_("unimplemented auto_language::print_type called")); - } - - /* See language.h. */ - - char *demangle (const char *mangled, int options) const override - { - /* The auto language just uses the C++ demangler. */ - return gdb_demangle (mangled, options); - } - - /* See language.h. */ - - void value_print (struct value *val, struct ui_file *stream, - const struct value_print_options *options) const override - { - error (_("unimplemented auto_language::value_print called")); - } - - /* See language.h. */ - - void value_print_inner - (struct value *val, struct ui_file *stream, int recurse, - const struct value_print_options *options) const override - { - error (_("unimplemented auto_language::value_print_inner called")); - } - - /* See language.h. */ - - int parser (struct parser_state *ps) const override - { - /* No parsing is done, just claim success. */ - return 1; - } - - /* See language.h. */ - - void emitchar (int ch, struct type *chtype, - struct ui_file *stream, int quoter) const override - { - error (_("unimplemented auto_language::emitchar called")); - } - - /* See language.h. */ - - void printchar (int ch, struct type *chtype, - struct ui_file *stream) const override - { - error (_("unimplemented auto_language::printchar called")); - } - - /* See language.h. */ +/* Single instance of the fake "auto" language. */ - void printstr (struct ui_file *stream, struct type *elttype, - const gdb_byte *string, unsigned int length, - const char *encoding, int force_ellipses, - const struct value_print_options *options) const override - { - error (_("unimplemented auto_language::printstr called")); - } +static auto_language auto_language_defn; - /* See language.h. */ +/* Class representing the unknown language. */ - void print_typedef (struct type *type, struct symbol *new_symbol, - struct ui_file *stream) const override - { - error (_("unimplemented auto_language::print_typedef called")); - } +class unknown_language : public auto_or_unknown_language +{ +public: + unknown_language () + : auto_or_unknown_language (language_unknown) + { /* Nothing. */ } /* See language.h. */ - bool is_string_type_p (struct type *type) const override - { - return default_is_string_type_p (type); - } + const char *name () const override + { return "unknown"; } /* See language.h. */ - const char *name_of_this () const override - { return "this"; } + const char *natural_name () const override + { return "Unknown"; } /* See language.h. */ - const struct op_print *opcode_print_table () const override - { return unk_op_print_tab; } + bool store_sym_names_in_linkage_form_p () const override + { return true; } }; -/* Single instance of the fake "auto" language. */ +/* Single instance of the unknown language class. */ -static auto_language auto_language_defn; +static unknown_language unknown_language_defn; /* Per-architecture language information. */ |