public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/9] Starting to convert languages to separate classes
@ 2020-05-11 22:35 Andrew Burgess
  2020-05-11 22:35 ` [PATCH 1/9] gdb: Represent all languages as sub-classes of language_defn Andrew Burgess
                   ` (12 more replies)
  0 siblings, 13 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This series starts the process of converting GDB's language structures
into separate classes, one for each supported language.

In the first commit I actually perform the conversion, but do so in a
way that basically doesn't change anything.  All the data is held in
the base class, and accessed just as it was before.

In the following commits I begin converting function pointer fields
within the language base class into real member functions.

I haven't converted all of the function pointers yet, I want to see
what feedback this series gets before I invest any more time.

Further into the future I think it's possible that we could tweak the
class hierarchy of languages, I do wonder if there will be some
obvious inheritance around the c_language maybe, but I figure I'll
convert all of the function pointers to methods first, then see what
everyone implements.

My hope is that be performing this conversion it will be easier for
people to add new methods into the language classes, to allow easier
language specific specialisation, hopefully we should be able to
remove some of the places where we check the language enum, and
instead replace this with a method on the language class.

Further into the future, I wonder if some things like expression
parsing, and maybe some of the value manipulation/printing code would
be better off as methods within the language classes.

Anyway, I'd be interested to hear peoples thoughts on the series so,
and of this as a piece of work in general, is this a good change or
not.

Thanks,
Andrew

---

Andrew Burgess (9):
  gdb: Represent all languages as sub-classes of language_defn
  gdb: Convert language la_print_array_index field to a method
  gdb: Convert language la_read_var_value field to a method
  gdb: Convert language la_pass_by_reference field to a method
  gdb: Convert language la_language_arch_info field to a method
  gdb: Convert language la_lookup_transparent_type field to a method
  gdb: Convert language la_iterate_over_symbols field to a method
  gdb: Convert language la_get_compile_instance field to a method
  gdb: Convert language la_search_name_hash field to a method

 gdb/ChangeLog         | 361 ++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c        | 264 +++++++++++++++---------------
 gdb/c-lang.c          | 283 +++++++++++++++++++++------------
 gdb/c-lang.h          |   4 +-
 gdb/compile/compile.c |   8 +-
 gdb/d-lang.c          | 157 +++++++++---------
 gdb/f-lang.c          | 108 +++++++------
 gdb/findvar.c         |   5 +-
 gdb/go-lang.c         | 130 ++++++++-------
 gdb/language.c        | 170 ++++++++++++--------
 gdb/language.h        | 223 ++++++++++++++------------
 gdb/linespec.c        |   2 +-
 gdb/m2-lang.c         |  78 +++++----
 gdb/objc-lang.c       |  34 ++--
 gdb/opencl-lang.c     |  59 ++++---
 gdb/p-lang.c          | 124 ++++++++-------
 gdb/rust-exp.y        |   4 +-
 gdb/rust-lang.c       | 112 ++++++-------
 gdb/symtab.c          |   4 +-
 19 files changed, 1351 insertions(+), 779 deletions(-)

-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 1/9] gdb: Represent all languages as sub-classes of language_defn
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
@ 2020-05-11 22:35 ` Andrew Burgess
  2020-05-11 22:35 ` [PATCH 2/9] gdb: Convert language la_print_array_index field to a method Andrew Burgess
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This commit converts all languages to sub-classes of a language_defn
base class.

The motivation for this change is to make it easier to add new methods
onto languages without having to update all of the individual language
structures.  In the future it might be possible to move more things,
like expression parsing, into the language class(es) for better
encapsulation, however I have no plans to tackle this in the short
term.

This commit sets up a strategy for transitioning from the current
language system, where each language is an instance of the
language_defn structure, to the class hierarchy system.

The plan is to rename the existing language_defn into language_data,
and make this a base class for the new language_defn class, something
like this:

  struct language_data
  {
    ... old language_defn fields here ...
  };

  struct language_defn : public language_data
  {
    language_defn (const language_data d)
      : language_data (d)
    { .... }
  };

Then each existing language, for example ada_language_defn can be
converted into an instance of language_data, and passed into the
constructor of a new language class, something like this:

  language_data ada_language_data =
  {
    ... old ada_language_defn values here ...
  };

  struct ada_language : public language_defn
  {
    ada_language (ada_language_data)
    { .... }
  };

What this means is that immediately after the conversion nothing much
changes.  Every language is now its own class, but all the old
language fields still exist and can be accessed in the same way.

In later commits I will convert function pointers from the old
language_defn structure into real class methods on language_defn, with
overrides on sub-classes where needed.

At this point I imagine that those fields of the old language_defn
structure that contained only data will probably remain as data fields
within the new language_data base structure, it is only the methods
that I plan to change initially.

I tweaked how we manage the list of languages a bit, each language is
now registered as it is created, and this resulted in a small number
of changes in language.c.

Most of the changes in the *-lang.c files are identical.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* gdb/ada-lang.c (ada_language_defn): Convert to...
	(ada_language_data): ...this.
	(class ada_language): New class.
	(ada_language_defn): New static global.
	* gdb/c-lang.c (c_language_defn): Convert to...
	(c_language_data): ...this.
	(class c_language): New class.
	(c_language_defn): New static global.
	(cplus_language_defn): Convert to...
	(cplus_language_data): ...this.
	(class cplus_language): New class.
	(cplus_language_defn): New static global.
	(asm_language_defn): Convert to...
	(asm_language_data): ...this.
	(class asm_language): New class.
	(asm_language_defn): New static global.
	(minimal_language_defn): Convert to...
	(minimal_language_data): ...this.
	(class minimal_language): New class.
	(minimal_language_defn): New static global.
	* gdb/d-lang.c (d_language_defn): Convert to...
	(d_language_data): ...this.
	(class d_language): New class.
	(d_language_defn): New static global.
	* gdb/f-lang.c (f_language_defn): Convert to...
	(f_language_data): ...this.
	(class f_language): New class.
	(f_language_defn): New static global.
	* gdb/go-lang.c (go_language_defn): Convert to...
	(go_language_data): ...this.
	(class go_language): New class.
	(go_language_defn): New static global.
	* gdb/language.c (unknown_language_defn): Remove declaration.
	(current_language): Initialize to nullptr, real initialization is
	moved to _initialize_language.
	(languages): Delete global.
	(language_defn::languages): Define.
	(set_language_command): Use language_defn::languages.
	(set_language): Likewise.
	(range_error): Likewise.
	(language_enum): Likewise.
	(language_def): Likewise.
	(add_set_language_command): Use language_def::languages for the
	language list, and language_def to lookup language pointers.
	(skip_language_trampoline): Use language_defn::languages.
	(unknown_language_defn): Convert to...
	(unknown_language_data): ...this.
	(class unknown_language): New class.
	(unknown_language_defn): New static global.
	(auto_language_defn): Convert to...
	(auto_language_data): ...this.
	(class auto_language): New class.
	(auto_language_defn): New static global.
	(language_gdbarch_post_init): Use language_defn::languages.
	(_initialize_language): Initialize current_language.
	* gdb/language.h (struct language_defn): Rename to...
	(struct language_data): ...this.
	(struct language_defn): New.
	(auto_language_defn): Delete.
	(unknown_language_defn): Delete.
	(minimal_language_defn): Delete.
	(ada_language_defn): Delete.
	(asm_language_defn): Delete.
	(c_language_defn): Delete.
	(cplus_language_defn): Delete.
	(d_language_defn): Delete.
	(f_language_defn): Delete.
	(go_language_defn): Delete.
	(m2_language_defn): Delete.
	(objc_language_defn): Delete.
	(opencl_language_defn): Delete.
	(pascal_language_defn): Delete.
	(rust_language_defn): Delete.
	* gdb/m2-lang.c (m2_language_defn): Convert to...
	(m2_language_data): ...this.
	(class m2_language): New class.
	(m2_language_defn): New static global.
	* gdb/objc-lang.c (objc_language_defn): Convert to...
	(objc_language_data): ...this.
	(class objc_language): New class.
	(objc_language_defn): New static global.
	* gdb/opencl-lang.c (opencl_language_defn): Convert to...
	(opencl_language_data): ...this.
	(class opencl_language): New class.
	(opencl_language_defn): New static global.
	* gdb/p-lang.c (pascal_language_defn): Convert to...
	(pascal_language_data): ...this.
	(class pascal_language): New class.
	(pascal_language_defn): New static global.
	* gdb/rust-exp.y (rust_lex_tests): Use language_def to find
	language pointer, update comment format.
	* gdb/rust-lang.c (rust_language_defn): Convert to...
	(rust_language_data): ...this.
	(class rust_language): New class.
	(rust_language_defn): New static global.
---
 gdb/ChangeLog     | 98 ++++++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 19 ++++++++-
 gdb/c-lang.c      | 68 ++++++++++++++++++++++++++++++--
 gdb/d-lang.c      | 18 ++++++++-
 gdb/f-lang.c      | 18 ++++++++-
 gdb/go-lang.c     | 18 ++++++++-
 gdb/language.c    | 99 +++++++++++++++++++++++++++--------------------
 gdb/language.h    | 51 ++++++++++++++----------
 gdb/m2-lang.c     | 18 ++++++++-
 gdb/objc-lang.c   | 19 ++++++++-
 gdb/opencl-lang.c | 17 +++++++-
 gdb/p-lang.c      | 18 ++++++++-
 gdb/rust-exp.y    |  4 +-
 gdb/rust-lang.c   | 18 ++++++++-
 14 files changed, 406 insertions(+), 77 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index be26231524d..4489c284776 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -14069,7 +14069,10 @@ static const char *ada_extensions[] =
   ".adb", ".ads", ".a", ".ada", ".dg", NULL
 };
 
-extern const struct language_defn ada_language_defn = {
+/* Constant data that describes the Ada language.  */
+
+extern const struct language_data ada_language_data =
+{
   "ada",                        /* Language name */
   "Ada",
   language_ada,
@@ -14118,6 +14121,20 @@ extern const struct language_defn ada_language_defn = {
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the Ada language.  */
+
+class ada_language : public language_defn
+{
+public:
+  ada_language ()
+    : language_defn (language_ada, ada_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Ada language class.  */
+
+static ada_language ada_language_defn;
+
 /* Command-list for the "set/show ada" prefix command.  */
 static struct cmd_list_element *set_ada_list;
 static struct cmd_list_element *show_ada_list;
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index c335044b06b..2774010a2ed 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -885,7 +885,9 @@ static const char *c_extensions[] =
   ".c", NULL
 };
 
-extern const struct language_defn c_language_defn =
+/* Constant data that describes the C language.  */
+
+extern const struct language_data c_language_data =
 {
   "c",				/* Language name */
   "C",
@@ -934,6 +936,20 @@ extern const struct language_defn c_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the C language.  */
+
+class c_language : public language_defn
+{
+public:
+  c_language ()
+    : language_defn (language_c, c_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the C language class.  */
+
+static c_language c_language_defn;
+
 enum cplus_primitive_types {
   cplus_primitive_type_int,
   cplus_primitive_type_long,
@@ -1030,7 +1046,9 @@ static const char *cplus_extensions[] =
   ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", NULL
 };
 
-extern const struct language_defn cplus_language_defn =
+/* Constant data that describes the C++ language.  */
+
+extern const struct language_data cplus_language_data =
 {
   "c++",			/* Language name */
   "C++",
@@ -1079,12 +1097,28 @@ extern const struct language_defn cplus_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* A class for the C++ language.  */
+
+class cplus_language : public language_defn
+{
+public:
+  cplus_language ()
+    : language_defn (language_cplus, cplus_language_data)
+  { /* Nothing.  */ }
+};
+
+/* The single instance of the C++ language class.  */
+
+static cplus_language cplus_language_defn;
+
 static const char *asm_extensions[] =
 {
   ".s", ".sx", ".S", NULL
 };
 
-extern const struct language_defn asm_language_defn =
+/* Constant data that describes the ASM language.  */
+
+extern const struct language_data asm_language_data =
 {
   "asm",			/* Language name */
   "assembly",
@@ -1133,12 +1167,25 @@ extern const struct language_defn asm_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* A class for the ASM language.  */
+
+class asm_language : public language_defn
+{
+public:
+  asm_language ()
+    : language_defn (language_asm, asm_language_data)
+  { /* Nothing.  */ }
+};
+
+/* The single instance of the ASM language class.  */
+static asm_language asm_language_defn;
+
 /* The following language_defn does not represent a real language.
    It just provides a minimal support a-la-C that should allow users
    to do some simple operations when debugging applications that use
    a language currently not supported by GDB.  */
 
-extern const struct language_defn minimal_language_defn =
+extern const struct language_data minimal_language_data =
 {
   "minimal",			/* Language name */
   "Minimal",
@@ -1186,3 +1233,16 @@ extern const struct language_defn minimal_language_defn =
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
+
+/* A class for the minimal language.  */
+
+class minimal_language : public language_defn
+{
+public:
+  minimal_language ()
+    : language_defn (language_minimal, minimal_language_data)
+  { /* Nothing.  */ }
+};
+
+/* The single instance of the minimal language class.  */
+static minimal_language minimal_language_defn;
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 951e664ceda..c572ad7890e 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -205,7 +205,9 @@ static const char *d_extensions[] =
   ".d", NULL
 };
 
-extern const struct language_defn d_language_defn =
+/* Constant data that describes the D language.  */
+
+extern const struct language_data d_language_data =
 {
   "d",
   "D",
@@ -255,6 +257,20 @@ extern const struct language_defn d_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the D language.  */
+
+class d_language : public language_defn
+{
+public:
+  d_language ()
+    : language_defn (language_d, d_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the D language class.  */
+
+static d_language d_language_defn;
+
 /* Build all D language types for the specified architecture.  */
 
 static void *
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 6b7a5fb7dba..888d78b720a 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -628,7 +628,9 @@ static const struct exp_descriptor exp_descriptor_f =
   evaluate_subexp_f
 };
 
-extern const struct language_defn f_language_defn =
+/* Constant data that describes the Fortran language.  */
+
+extern const struct language_data f_language_data =
 {
   "fortran",
   "Fortran",
@@ -683,6 +685,20 @@ extern const struct language_defn f_language_defn =
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the Fortran language.  */
+
+class f_language : public language_defn
+{
+public:
+  f_language ()
+    : language_defn (language_fortran, f_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Fortran language class.  */
+
+static f_language f_language_defn;
+
 static void *
 build_fortran_types (struct gdbarch *gdbarch)
 {
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 03dc986ab6a..61e2a1d549f 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -576,7 +576,9 @@ go_language_arch_info (struct gdbarch *gdbarch,
   lai->bool_type_default = builtin->builtin_bool;
 }
 
-extern const struct language_defn go_language_defn =
+/* Constant data that describes the Go language.  */
+
+extern const struct language_data go_language_data =
 {
   "go",
   "Go",
@@ -626,6 +628,20 @@ extern const struct language_defn go_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the Go language.  */
+
+class go_language : public language_defn
+{
+public:
+  go_language ()
+    : language_defn (language_go, go_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Go language class.  */
+
+static go_language go_language_defn;
+
 static void *
 build_go_types (struct gdbarch *gdbarch)
 {
diff --git a/gdb/language.c b/gdb/language.c
index 769b3299793..7622ddca0a3 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -62,9 +62,6 @@ static void unk_lang_value_print (struct value *, struct ui_file *,
 
 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
 
-/* Forward declaration */
-extern const struct language_defn unknown_language_defn;
-
 /* The current (default at startup) state of type and range checking.
    (If the modes are set to "auto", though, these are changed based
    on the default language at startup, and then again based on the
@@ -77,7 +74,7 @@ enum case_sensitivity case_sensitivity = case_sensitive_on;
 
 /* The current language and language_mode (see language.h).  */
 
-const struct language_defn *current_language = &unknown_language_defn;
+const struct language_defn *current_language = nullptr;
 enum language_mode language_mode = language_mode_auto;
 
 /* The language that the user expects to be typing in (the language
@@ -85,26 +82,9 @@ enum language_mode language_mode = language_mode_auto;
 
 const struct language_defn *expected_language;
 
-/* The list of supported languages.  Keep this in the same order as
-   the 'enum language' values.  */
-
-static const struct language_defn *languages[] = {
-  &unknown_language_defn,
-  &auto_language_defn,
-  &c_language_defn,
-  &objc_language_defn,
-  &cplus_language_defn,
-  &d_language_defn,
-  &go_language_defn,
-  &f_language_defn,
-  &m2_language_defn,
-  &asm_language_defn,
-  &pascal_language_defn,
-  &opencl_language_defn,
-  &rust_language_defn,
-  &minimal_language_defn,
-  &ada_language_defn,
-};
+/* Define the array containing all languages.  */
+
+const struct language_defn *language_defn::languages[nr_languages];
 
 /* The current values of the "set language/range/case-sensitive" enum
    commands.  */
@@ -162,7 +142,7 @@ set_language_command (const char *ignore,
     language = "auto";
 
   /* Search the list of languages for a match.  */
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     {
       if (strcmp (lang->la_name, language) == 0)
 	{
@@ -377,7 +357,7 @@ set_language (enum language lang)
   enum language prev_language;
 
   prev_language = current_language->la_language;
-  current_language = languages[lang];
+  current_language = language_def (lang);
   set_range_case ();
   return prev_language;
 }
@@ -474,7 +454,7 @@ range_error (const char *string,...)
 enum language
 language_enum (const char *str)
 {
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     if (strcmp (lang->la_name, str) == 0)
       return lang->la_language;
 
@@ -489,7 +469,9 @@ language_enum (const char *str)
 const struct language_defn *
 language_def (enum language lang)
 {
-  return languages[lang];
+  const struct language_defn *l = language_defn::languages[lang];
+  gdb_assert (l != nullptr);
+  return l;
 }
 
 /* Return the language as a string.  */
@@ -497,7 +479,7 @@ language_def (enum language lang)
 const char *
 language_str (enum language lang)
 {
-  return languages[lang]->la_name;
+  return language_def (lang)->la_name;
 }
 
 \f
@@ -512,16 +494,16 @@ add_set_language_command ()
   /* Build the language names array, to be used as enumeration in the
      "set language" enum command.  +1 for "local" and +1 for NULL
      termination.  */
-  language_names = new const char *[ARRAY_SIZE (languages) + 2];
+  language_names = new const char *[ARRAY_SIZE (language_defn::languages) + 2];
 
   /* Display "auto", "local" and "unknown" first, and then the rest,
      alpha sorted.  */
   const char **language_names_p = language_names;
-  *language_names_p++ = auto_language_defn.la_name;
+  *language_names_p++ = language_def (language_auto)->la_name;
   *language_names_p++ = "local";
-  *language_names_p++ = unknown_language_defn.la_name;
+  *language_names_p++ = language_def (language_unknown)->la_name;
   const char **sort_begin = language_names_p;
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     {
       /* Already handled above.  */
       if (lang->la_language == language_auto
@@ -533,7 +515,7 @@ add_set_language_command ()
   std::sort (sort_begin, language_names_p, compare_cstrings);
 
   /* Add the filename extensions.  */
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     if (lang->la_filename_extensions != NULL)
       {
 	for (size_t i = 0; lang->la_filename_extensions[i] != NULL; ++i)
@@ -548,7 +530,7 @@ add_set_language_command ()
 		"The currently understood settings are:\n\nlocal or "
 		"auto    Automatic setting based on source file"));
 
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     {
       /* Already dealt with these above.  */
       if (lang->la_language == language_unknown
@@ -583,7 +565,7 @@ add_set_language_command ()
 CORE_ADDR 
 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
 {
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     {
       if (lang->skip_trampoline != NULL)
 	{
@@ -826,7 +808,9 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 						       struct type *);
 }
 
-const struct language_defn unknown_language_defn =
+/* Constant data that describes the unknown language.  */
+
+extern const struct language_data unknown_language_data =
 {
   "unknown",
   "Unknown",
@@ -875,9 +859,23 @@ const struct language_defn unknown_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
-/* These two structs define fake entries for the "local" and "auto"
-   options.  */
-const struct language_defn auto_language_defn =
+/* Class representing the unknown language.  */
+
+class unknown_language : public language_defn
+{
+public:
+  unknown_language ()
+    : language_defn (language_unknown, unknown_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the unknown language class.  */
+
+static unknown_language unknown_language_defn;
+
+/* Constant data for the fake "auto" language.  */
+
+extern const struct language_data auto_language_data =
 {
   "auto",
   "Auto",
@@ -926,6 +924,20 @@ const struct language_defn auto_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the fake "auto" language.  */
+
+class auto_language : public language_defn
+{
+public:
+  auto_language ()
+    : language_defn (language_auto, auto_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the fake "auto" language.  */
+
+static auto_language auto_language_defn;
+
 \f
 /* Per-architecture language information.  */
 
@@ -944,7 +956,7 @@ language_gdbarch_post_init (struct gdbarch *gdbarch)
   struct language_gdbarch *l;
 
   l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     if (lang != NULL && lang->la_language_arch_info != NULL)
       {
 	lang->la_language_arch_info (gdbarch,
@@ -1165,6 +1177,11 @@ For Fortran the default is off; for other languages the default is on."),
 			show_case_command,
 			&setlist, &showlist);
 
+  /* In order to call SET_LANGUAGE (below) we need to make sure that
+     CURRENT_LANGUAGE is not NULL.  So first set the language to unknown,
+     then we can change the language to 'auto'.  */
+  current_language = language_def (language_unknown);
+
   add_set_language_command ();
 
   language = "auto";
diff --git a/gdb/language.h b/gdb/language.h
index ea8aae511b0..a07ed0637a6 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -169,9 +169,21 @@ struct language_pass_by_ref_info
   bool destructible = true;
 };
 
-/* Structure tying together assorted information about a language.  */
+/* Structure tying together assorted information about a language.
 
-struct language_defn
+   As we move over from the old structure based languages to a class
+   hierarchy of languages this structure will continue to contain a
+   mixture of both data and function pointers.
+
+   Once the class hierarchy of languages in place the first task is to
+   remove the function pointers from this structure and convert them into
+   member functions on the different language classes.
+
+   The current plan it to keep the constant data that describes a language
+   in this structure, and have each language pass in an instance of this
+   structure at construction time.  */
+
+struct language_data
   {
     /* Name of the language.  */
 
@@ -470,6 +482,22 @@ struct language_defn
 
   };
 
+/* Base class from which all other language classes derive.  */
+
+struct language_defn : language_data
+{
+  language_defn (enum language lang, const language_data &init_data)
+    : language_data (init_data)
+  {
+    /* We should only ever create one instance of each language.  */
+    gdb_assert (languages[lang] == nullptr);
+    languages[lang] = this;
+  }
+
+  /* List of all known languages.  */
+  static const struct language_defn *languages[nr_languages];
+};
+
 /* Pointer to the language_defn for our current language.  This pointer
    always points to *some* valid struct; it can be used without checking
    it for validity.
@@ -679,25 +707,6 @@ extern bool default_symbol_name_matcher
 symbol_name_matcher_ftype *get_symbol_name_matcher
   (const language_defn *lang, const lookup_name_info &lookup_name);
 
-/* The languages supported by GDB.  */
-
-extern const struct language_defn auto_language_defn;
-extern const struct language_defn unknown_language_defn;
-extern const struct language_defn minimal_language_defn;
-
-extern const struct language_defn ada_language_defn;
-extern const struct language_defn asm_language_defn;
-extern const struct language_defn c_language_defn;
-extern const struct language_defn cplus_language_defn;
-extern const struct language_defn d_language_defn;
-extern const struct language_defn f_language_defn;
-extern const struct language_defn go_language_defn;
-extern const struct language_defn m2_language_defn;
-extern const struct language_defn objc_language_defn;
-extern const struct language_defn opencl_language_defn;
-extern const struct language_defn pascal_language_defn;
-extern const struct language_defn rust_language_defn;
-
 /* Save the current language and restore it upon destruction.  */
 
 class scoped_restore_current_language
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index af3cf3ad85f..161be09001f 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -375,7 +375,9 @@ const struct exp_descriptor exp_descriptor_modula2 =
   evaluate_subexp_modula2
 };
 
-extern const struct language_defn m2_language_defn =
+/* Constant data describing the M2 language.  */
+
+extern const struct language_data m2_language_data =
 {
   "modula-2",
   "Modula-2",
@@ -424,6 +426,20 @@ extern const struct language_defn m2_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the M2 language.  */
+
+class m2_language : public language_defn
+{
+public:
+  m2_language ()
+    : language_defn (language_m2, m2_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the M2 language.  */
+
+static m2_language m2_language_defn;
+
 static void *
 build_m2_types (struct gdbarch *gdbarch)
 {
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 1c7ec560197..7fe495f6892 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -364,7 +364,10 @@ static const char *objc_extensions[] =
   ".m", NULL
 };
 
-extern const struct language_defn objc_language_defn = {
+/* Constant data representing the Objective-C language.  */
+
+extern const struct language_data objc_language_data =
+{
   "objective-c",		/* Language name */
   "Objective-C",
   language_objc,
@@ -412,6 +415,20 @@ extern const struct language_defn objc_language_defn = {
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the Objective-C language.  */
+
+class objc_language : public language_defn
+{
+public:
+  objc_language ()
+    : language_defn (language_objc, objc_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the class representing the Objective-C language.  */
+
+static objc_language objc_language_defn;
+
 /*
  * ObjC:
  * Following functions help construct Objective-C message calls.
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index a4fdc5a1176..b7ea773e75f 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1042,7 +1042,8 @@ const struct exp_descriptor exp_descriptor_opencl =
   evaluate_subexp_opencl
 };
 
-extern const struct language_defn opencl_language_defn =
+/* Constant data representing the OpenCL language.  */
+extern const struct language_data opencl_language_data =
 {
   "opencl",			/* Language name */
   "OpenCL C",
@@ -1091,6 +1092,20 @@ extern const struct language_defn opencl_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the OpenCL language.  */
+
+class opencl_language : public language_defn
+{
+public:
+  opencl_language ()
+    : language_defn (language_opencl, opencl_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the OpenCL language class.  */
+
+static opencl_language opencl_language_defn;
+
 static void *
 build_opencl_types (struct gdbarch *gdbarch)
 {
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 944a077506c..d5c83d70eff 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -429,7 +429,9 @@ static const char *p_extensions[] =
   ".pas", ".p", ".pp", NULL
 };
 
-extern const struct language_defn pascal_language_defn =
+/* Constant data representing the Pascal language.  */
+
+extern const struct language_data pascal_language_data =
 {
   "pascal",			/* Language name */
   "Pascal",
@@ -476,3 +478,17 @@ extern const struct language_defn pascal_language_defn =
   pascal_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
+
+/* Class representing the Pascal language.  */
+
+class pascal_language : public language_defn
+{
+public:
+  pascal_language ()
+    : language_defn (language_pascal, pascal_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Pascal language class.  */
+
+static pascal_language pascal_language_defn;
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index de4a8161635..6bfce5dd88c 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2725,8 +2725,8 @@ rust_lex_tests (void)
 {
   int i;
 
-  // Set up dummy "parser", so that rust_type works.
-  struct parser_state ps (&rust_language_defn, target_gdbarch (),
+  /* Set up dummy "parser", so that rust_type works.  */
+  struct parser_state ps (language_def (language_rust), target_gdbarch (),
 			  nullptr, 0, 0, nullptr, 0, nullptr);
   rust_parser parser (&ps);
 
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f2fb0119b00..d7caf3531e5 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2101,7 +2101,9 @@ static const char *rust_extensions[] =
   ".rs", NULL
 };
 
-extern const struct language_defn rust_language_defn =
+/* Constant data representing the Rust language.  */
+
+extern const struct language_data rust_language_data =
 {
   "rust",
   "Rust",
@@ -2149,3 +2151,17 @@ extern const struct language_defn rust_language_defn =
   rust_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
+
+/* Class representing the Rust language.  */
+
+class rust_language : public language_defn
+{
+public:
+  rust_language ()
+    : language_defn (language_rust, rust_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Rust language class.  */
+
+static rust_language rust_language_defn;
-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 2/9] gdb: Convert language la_print_array_index field to a method
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
  2020-05-11 22:35 ` [PATCH 1/9] gdb: Represent all languages as sub-classes of language_defn Andrew Burgess
@ 2020-05-11 22:35 ` Andrew Burgess
  2020-05-11 22:35 ` [PATCH 3/9] gdb: Convert language la_read_var_value " Andrew Burgess
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_print_array_index function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_print_array_index): Delete function, move
	implementation to...
	(ada_language::print_array_index): ...here.
	(ada_language_data): Delete la_print_array_index initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (default_print_array_index): Delete function, move
	implementation to...
	(language_defn::print_array_index): ...here.
	(unknown_language_data): Delete la_print_array_index initializer.
	(auto_language_data): Likewise.
	* language.h (struct language_data): Delete la_print_array_index
	field.
	(language_defn::print_array_index): New member function.
	(LA_PRINT_ARRAY_INDEX): Update.
	(default_print_array_index): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_print_array_index
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog     | 29 +++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 21 ++++++++++-----------
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  9 ++++-----
 gdb/language.h    | 19 ++++++++-----------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 13 files changed, 51 insertions(+), 39 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 4489c284776..47007e52119 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -498,16 +498,6 @@ ada_get_gdb_completer_word_break_characters (void)
   return ada_completer_word_break_characters;
 }
 
-/* Print an array element index using the Ada syntax.  */
-
-static void
-ada_print_array_index (struct value *index_value, struct ui_file *stream,
-                       const struct value_print_options *options)
-{
-  LA_VALUE_PRINT (index_value, stream, options);
-  fprintf_filtered (stream, " => ");
-}
-
 /* la_watch_location_expression for Ada.  */
 
 static gdb::unique_xmalloc_ptr<char>
@@ -14108,7 +14098,6 @@ extern const struct language_data ada_language_data =
   ada_get_gdb_completer_word_break_characters,
   ada_collect_symbol_completion_matches,
   ada_language_arch_info,
-  ada_print_array_index,
   default_pass_by_reference,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
@@ -14129,6 +14118,16 @@ class ada_language : public language_defn
   ada_language ()
     : language_defn (language_ada, ada_language_data)
   { /* Nothing.  */ }
+
+  /* Print an array element index using the Ada syntax.  */
+
+  void print_array_index (struct value *index_value,
+			  struct ui_file *stream,
+			  const value_print_options *options) const override
+  {
+    LA_VALUE_PRINT (index_value, stream, options);
+    fprintf_filtered (stream, " => ");
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 2774010a2ed..af4b4d3cf02 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -923,7 +923,6 @@ extern const struct language_data c_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
@@ -1084,7 +1083,6 @@ extern const struct language_data cplus_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   cplus_language_arch_info,
-  default_print_array_index,
   cp_pass_by_reference,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
@@ -1154,7 +1152,6 @@ extern const struct language_data asm_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,		/* FIXME: la_language_arch_info.  */
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
@@ -1221,7 +1218,6 @@ extern const struct language_data minimal_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index c572ad7890e..af8143b9b13 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -244,7 +244,6 @@ extern const struct language_data d_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   d_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 888d78b720a..1b79485f61d 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -672,7 +672,6 @@ extern const struct language_data f_language_data =
   f_word_break_characters,
   f_collect_symbol_completion_matches,
   f_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 61e2a1d549f..a69091bb631 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -615,7 +615,6 @@ extern const struct language_data go_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   go_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/language.c b/gdb/language.c
index 7622ddca0a3..4b2a405c725 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -650,11 +650,12 @@ default_word_break_characters (void)
   return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
 }
 
-/* Print the index of array elements using the C99 syntax.  */
+/* See language.h.  */
 
 void
-default_print_array_index (struct value *index_value, struct ui_file *stream,
-			   const struct value_print_options *options)
+language_defn::print_array_index (struct value *index_value,
+				  struct ui_file *stream,
+				  const value_print_options *options) const
 {
   fprintf_filtered (stream, "[");
   LA_VALUE_PRINT (index_value, stream, options);
@@ -846,7 +847,6 @@ extern const struct language_data unknown_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   unknown_language_arch_info,	/* la_language_arch_info.  */
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
@@ -911,7 +911,6 @@ extern const struct language_data auto_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   unknown_language_arch_info,	/* la_language_arch_info.  */
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/language.h b/gdb/language.h
index a07ed0637a6..307a08c13cd 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -387,11 +387,6 @@ struct language_data
     void (*la_language_arch_info) (struct gdbarch *,
 				   struct language_arch_info *);
 
-    /* Print the index of an element of an array.  */
-    void (*la_print_array_index) (struct value *index_value,
-                                  struct ui_file *stream,
-                                  const struct value_print_options *options);
-
     /* Return information about whether TYPE should be passed
        (and returned) by reference at the language level.  */
     struct language_pass_by_ref_info (*la_pass_by_reference)
@@ -494,6 +489,13 @@ struct language_defn : language_data
     languages[lang] = this;
   }
 
+  /* Print the index of an element of an array.  This default
+     implementation prints using C99 syntax.  */
+
+  virtual void print_array_index (struct value *index_value,
+				  struct ui_file *stream,
+				  const value_print_options *options) const;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
@@ -599,7 +601,7 @@ extern enum language set_language (enum language);
   (current_language->la_emitchar(ch, type, stream, quoter))
 
 #define LA_PRINT_ARRAY_INDEX(index_value, stream, options) \
-  (current_language->la_print_array_index(index_value, stream, options))
+  (current_language->print_array_index(index_value, stream, options))
 
 #define LA_ITERATE_OVER_SYMBOLS(BLOCK, NAME, DOMAIN, CALLBACK) \
   (current_language->la_iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK))
@@ -661,11 +663,6 @@ extern char *language_class_name_from_physname (const struct language_defn *,
 /* Splitting strings into words.  */
 extern const char *default_word_break_characters (void);
 
-/* Print the index of an array element using the C99 syntax.  */
-extern void default_print_array_index (struct value *index_value,
-                                       struct ui_file *stream,
-				       const struct value_print_options *options);
-
 /* Return information about whether TYPE should be passed
    (and returned) by reference at the language level.  */
 struct language_pass_by_ref_info language_pass_by_reference (struct type *type);
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 161be09001f..4d4f5493938 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -413,7 +413,6 @@ extern const struct language_data m2_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   m2_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 7fe495f6892..47d75620dcb 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -402,7 +402,6 @@ extern const struct language_data objc_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index b7ea773e75f..ebd13d68381 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1079,7 +1079,6 @@ extern const struct language_data opencl_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   opencl_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index d5c83d70eff..34063232da6 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -466,7 +466,6 @@ extern const struct language_data pascal_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   pascal_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index d7caf3531e5..41bb47189eb 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2139,7 +2139,6 @@ extern const struct language_data rust_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   rust_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 3/9] gdb: Convert language la_read_var_value field to a method
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
  2020-05-11 22:35 ` [PATCH 1/9] gdb: Represent all languages as sub-classes of language_defn Andrew Burgess
  2020-05-11 22:35 ` [PATCH 2/9] gdb: Convert language la_print_array_index field to a method Andrew Burgess
@ 2020-05-11 22:35 ` Andrew Burgess
  2020-05-14 19:43   ` Tom Tromey
  2020-05-11 22:35 ` [PATCH 4/9] gdb: Convert language la_pass_by_reference " Andrew Burgess
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_read_var_value function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_read_var_value): Delete function, move
	implementation to...
	(ada_language::read_var_value): ...here.
	(ada_language_data): Delete la_read_var_value initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* findvar.c (read_var_value): Update header comment, and change to
	call member function instead of function pointer.
	* go-lang.c (go_language_data): Likewise.
	* language.c (language_defn::read_var_value): New member function.
	(unknown_language_data): Delete la_read_var_value initializer.
	(auto_language_data): Likewise.
	* language.h (struct language_data): Delete la_read_var_value
	field.
	(language_defn::read_var_value): New member function.
	(default_read_var_value): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_read_var_value
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog     | 28 ++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 41 ++++++++++++++++++++---------------------
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/findvar.c     |  5 ++---
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 12 ++++++++++--
 gdb/language.h    | 30 +++++++++++++++---------------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 14 files changed, 75 insertions(+), 53 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 47007e52119..f39b4e0747c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -14034,26 +14034,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
     }
 }
 
-/* Implement the "la_read_var_value" language_defn method for Ada.  */
-
-static struct value *
-ada_read_var_value (struct symbol *var, const struct block *var_block,
-		    struct frame_info *frame)
-{
-  /* The only case where default_read_var_value is not sufficient
-     is when VAR is a renaming...  */
-  if (frame != nullptr)
-    {
-      const struct block *frame_block = get_frame_block (frame, NULL);
-      if (frame_block != nullptr && ada_is_renaming_symbol (var))
-	return ada_read_renaming_var_value (var, frame_block);
-    }
-
-  /* This is a typical case where we expect the default_read_var_value
-     function to work.  */
-  return default_read_var_value (var, var_block, frame);
-}
-
 static const char *ada_extensions[] =
 {
   ".adb", ".ads", ".a", ".ada", ".dg", NULL
@@ -14082,7 +14062,6 @@ extern const struct language_data ada_language_data =
   ada_print_typedef,            /* Print a typedef using appropriate syntax */
   ada_value_print_inner,	/* la_value_print_inner */
   ada_value_print,              /* Print a top-level value */
-  ada_read_var_value,		/* la_read_var_value */
   NULL,                         /* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
@@ -14128,6 +14107,26 @@ class ada_language : public language_defn
     LA_VALUE_PRINT (index_value, stream, options);
     fprintf_filtered (stream, " => ");
   }
+
+  /* Implement the "read_var_value" language_defn method for Ada.  */
+
+  struct value *read_var_value (struct symbol *var,
+				const struct block *var_block,
+				struct frame_info *frame) const override
+  {
+    /* The only case where default_read_var_value is not sufficient
+       is when VAR is a renaming...  */
+    if (frame != nullptr)
+      {
+	const struct block *frame_block = get_frame_block (frame, NULL);
+	if (frame_block != nullptr && ada_is_renaming_symbol (var))
+	  return ada_read_renaming_var_value (var, frame_block);
+      }
+
+    /* This is a typical case where we expect the default_read_var_value
+       function to work.  */
+    return default_read_var_value (var, var_block, frame);
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index af4b4d3cf02..8fbbf4b44d4 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -907,7 +907,6 @@ extern const struct language_data c_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
@@ -1067,7 +1066,6 @@ extern const struct language_data cplus_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   cplus_skip_trampoline,	/* Language specific skip_trampoline */
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -1136,7 +1134,6 @@ extern const struct language_data asm_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
@@ -1202,7 +1199,6 @@ extern const struct language_data minimal_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index af8143b9b13..e55d82e08be 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -228,7 +228,6 @@ extern const struct language_data d_language_data =
 				   syntax.  */
   d_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value.  */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline.  */
   "this",
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 1b79485f61d..310eb999f45 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -650,7 +650,6 @@ extern const struct language_data f_language_data =
   f_print_typedef,		/* Print a typedef using appropriate syntax */
   f_value_print_innner,		/* la_value_print_inner */
   c_value_print,		/* FIXME */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/findvar.c b/gdb/findvar.c
index ac4f5c3997d..3bed2706502 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -801,7 +801,7 @@ default_read_var_value (struct symbol *var, const struct block *var_block,
   return v;
 }
 
-/* Calls VAR's language la_read_var_value hook with the given arguments.  */
+/* Calls VAR's language read_var_value hook with the given arguments.  */
 
 struct value *
 read_var_value (struct symbol *var, const struct block *var_block,
@@ -810,9 +810,8 @@ read_var_value (struct symbol *var, const struct block *var_block,
   const struct language_defn *lang = language_def (var->language ());
 
   gdb_assert (lang != NULL);
-  gdb_assert (lang->la_read_var_value != NULL);
 
-  return lang->la_read_var_value (var, var_block, frame);
+  return lang->read_var_value (var, var_block, frame);
 }
 
 /* Install default attributes for register values.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index a69091bb631..cd960961400 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -599,7 +599,6 @@ extern const struct language_data go_language_data =
 				   syntax.  */
   go_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value.  */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline.  */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/language.c b/gdb/language.c
index 4b2a405c725..8917099d8fe 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -664,6 +664,16 @@ language_defn::print_array_index (struct value *index_value,
 
 /* See language.h.  */
 
+struct value *
+language_defn::read_var_value (struct symbol *var,
+					const struct block *var_block,
+					struct frame_info *frame) const
+{
+  return default_read_var_value (var, var_block, frame);
+}
+
+/* See language.h.  */
+
 bool
 default_symbol_name_matcher (const char *symbol_search_name,
 			     const lookup_name_info &lookup_name,
@@ -831,7 +841,6 @@ extern const struct language_data unknown_language_data =
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_value_print_inner,	/* la_value_print_inner */
   unk_lang_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
@@ -895,7 +904,6 @@ extern const struct language_data auto_language_data =
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_value_print_inner,	/* la_value_print_inner */
   unk_lang_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
diff --git a/gdb/language.h b/gdb/language.h
index 307a08c13cd..2219bcf3869 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -272,21 +272,6 @@ struct language_data
     void (*la_value_print) (struct value *, struct ui_file *,
 			    const struct value_print_options *);
 
-    /* Given a symbol VAR, the corresponding block VAR_BLOCK (if any) and a
-       stack frame id FRAME, read the value of the variable and return (pointer
-       to a) struct value containing the value.
-
-       VAR_BLOCK is needed if there's a possibility for VAR to be outside
-       FRAME.  This is what happens if FRAME correspond to a nested function
-       and VAR is defined in the outer function.  If callers know that VAR is
-       located in FRAME or is global/static, NULL can be passed as VAR_BLOCK.
-
-       Throw an error if the variable cannot be found.  */
-
-    struct value *(*la_read_var_value) (struct symbol *var,
-					const struct block *var_block,
-					struct frame_info *frame);
-
     /* PC is possibly an unknown languages trampoline.
        If that PC falls in a trampoline belonging to this language,
        return the address of the first pc in the real function, or 0
@@ -496,6 +481,21 @@ struct language_defn : language_data
 				  struct ui_file *stream,
 				  const value_print_options *options) const;
 
+  /* Given a symbol VAR, the corresponding block VAR_BLOCK (if any) and a
+     stack frame id FRAME, read the value of the variable and return (pointer
+     to a) struct value containing the value.
+
+     VAR_BLOCK is needed if there's a possibility for VAR to be outside
+     FRAME.  This is what happens if FRAME correspond to a nested function
+     and VAR is defined in the outer function.  If callers know that VAR is
+     located in FRAME or is global/static, NULL can be passed as VAR_BLOCK.
+
+     Throw an error if the variable cannot be found.  */
+
+  virtual struct value *read_var_value (struct symbol *var,
+					const struct block *var_block,
+					struct frame_info *frame) const;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 4d4f5493938..a6be7c3a889 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -397,7 +397,6 @@ extern const struct language_data m2_language_data =
   m2_print_typedef,		/* Print a typedef using appropriate syntax */
   m2_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 47d75620dcb..2ac484c7bcd 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -386,7 +386,6 @@ extern const struct language_data objc_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   objc_skip_trampoline, 	/* Language specific skip_trampoline */
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index ebd13d68381..c1dc325e29c 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1063,7 +1063,6 @@ extern const struct language_data opencl_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 34063232da6..8d64c30376a 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -451,7 +451,6 @@ extern const struct language_data pascal_language_data =
   pascal_print_typedef,		/* Print a typedef using appropriate syntax */
   pascal_value_print_inner,	/* la_value_print_inner */
   pascal_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 41bb47189eb..7f3ed2bb3ec 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2123,7 +2123,6 @@ extern const struct language_data rust_language_data =
   rust_print_typedef,		/* Print a typedef using appropriate syntax */
   rust_value_print_inner,	/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 4/9] gdb: Convert language la_pass_by_reference field to a method
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (2 preceding siblings ...)
  2020-05-11 22:35 ` [PATCH 3/9] gdb: Convert language la_read_var_value " Andrew Burgess
@ 2020-05-11 22:35 ` Andrew Burgess
  2020-05-14 11:00   ` Aktemur, Tankut Baris
  2020-05-14 19:48   ` Tom Tromey
  2020-05-11 22:35 ` [PATCH 5/9] gdb: Convert language la_language_arch_info " Andrew Burgess
                   ` (8 subsequent siblings)
  12 siblings, 2 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_pass_by_reference function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_pass_by_reference
	initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(cplus_language::pass_by_reference_info): New method.
	(asm_language_data): Delete la_pass_by_reference initializer.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (language_pass_by_reference): Update.
	(language_defn::pass_by_reference_info): New function.
	(unknown_language_data): Delete la_pass_by_reference
	initializer.
	(auto_language_data): Likewise.
	* language.h (struct language_data): Delete la_pass_by_reference
	field.
	(language_defn::pass_by_reference_info): New member function.
	* m2-lang.c (m2_language_data): Delete la_pass_by_reference
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog     | 27 +++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      | 12 ++++++++----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 16 ++++++++++------
 gdb/language.h    | 13 ++++++++-----
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 13 files changed, 53 insertions(+), 24 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index f39b4e0747c..641f78199c6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -14077,7 +14077,6 @@ extern const struct language_data ada_language_data =
   ada_get_gdb_completer_word_break_characters,
   ada_collect_symbol_completion_matches,
   ada_language_arch_info,
-  default_pass_by_reference,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
   ada_iterate_over_symbols,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 8fbbf4b44d4..1cc5b5c264d 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -922,7 +922,6 @@ extern const struct language_data c_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1081,7 +1080,6 @@ extern const struct language_data cplus_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   cplus_language_arch_info,
-  cp_pass_by_reference,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
   iterate_over_symbols,
@@ -1101,6 +1099,14 @@ class cplus_language : public language_defn
   cplus_language ()
     : language_defn (language_cplus, cplus_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+
+  struct language_pass_by_ref_info pass_by_reference_info
+	(struct type *type) const override
+  {
+    return cp_pass_by_reference (type);
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1149,7 +1155,6 @@ extern const struct language_data asm_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,		/* FIXME: la_language_arch_info.  */
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1214,7 +1219,6 @@ extern const struct language_data minimal_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index e55d82e08be..28864420bad 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -243,7 +243,6 @@ extern const struct language_data d_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   d_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 310eb999f45..efa1b4f84de 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -671,7 +671,6 @@ extern const struct language_data f_language_data =
   f_word_break_characters,
   f_collect_symbol_completion_matches,
   f_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index cd960961400..08b547463bc 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -614,7 +614,6 @@ extern const struct language_data go_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   go_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/language.c b/gdb/language.c
index 8917099d8fe..fec1fc383f5 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -627,12 +627,10 @@ language_class_name_from_physname (const struct language_defn *lang,
 struct language_pass_by_ref_info
 language_pass_by_reference (struct type *type)
 {
-  return current_language->la_pass_by_reference (type);
+  return current_language->pass_by_reference_info (type);
 }
 
-/* Return a default struct that provides pass-by-reference information
-   about the given TYPE.  Languages should update the default values
-   as appropriate.  */
+/* See language.h.  */
 
 struct language_pass_by_ref_info
 default_pass_by_reference (struct type *type)
@@ -674,6 +672,14 @@ language_defn::read_var_value (struct symbol *var,
 
 /* See language.h.  */
 
+struct language_pass_by_ref_info
+language_defn::pass_by_reference_info (struct type *type) const
+{
+  return default_pass_by_reference (type);
+}
+
+/* See language.h.  */
+
 bool
 default_symbol_name_matcher (const char *symbol_search_name,
 			     const lookup_name_info &lookup_name,
@@ -856,7 +862,6 @@ extern const struct language_data unknown_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   unknown_language_arch_info,	/* la_language_arch_info.  */
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -919,7 +924,6 @@ extern const struct language_data auto_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   unknown_language_arch_info,	/* la_language_arch_info.  */
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/language.h b/gdb/language.h
index 2219bcf3869..1435af7ad56 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -372,11 +372,6 @@ struct language_data
     void (*la_language_arch_info) (struct gdbarch *,
 				   struct language_arch_info *);
 
-    /* Return information about whether TYPE should be passed
-       (and returned) by reference at the language level.  */
-    struct language_pass_by_ref_info (*la_pass_by_reference)
-      (struct type *type);
-
     /* Return an expression that can be used for a location
        watchpoint.  TYPE is a pointer type that points to the memory
        to watch, and ADDR is the address of the watched memory.  */
@@ -496,6 +491,14 @@ struct language_defn : language_data
 					const struct block *var_block,
 					struct frame_info *frame) const;
 
+  /* Return information about whether TYPE should be passed
+     (and returned) by reference at the language level.  The default
+     implementation returns a LANGUAGE_PASS_BY_REF_INFO initialised in its
+     default state.  */
+
+  virtual struct language_pass_by_ref_info pass_by_reference_info
+	(struct type *type) const;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index a6be7c3a889..26048684bf0 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -412,7 +412,6 @@ extern const struct language_data m2_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   m2_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 2ac484c7bcd..a2f22031721 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -401,7 +401,6 @@ extern const struct language_data objc_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index c1dc325e29c..3562914c7d5 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1078,7 +1078,6 @@ extern const struct language_data opencl_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   opencl_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 8d64c30376a..cc0efaa0bdc 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -465,7 +465,6 @@ extern const struct language_data pascal_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   pascal_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
   iterate_over_symbols,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 7f3ed2bb3ec..33208c7ac1b 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2138,7 +2138,6 @@ extern const struct language_data rust_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   rust_language_arch_info,
-  default_pass_by_reference,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 5/9] gdb: Convert language la_language_arch_info field to a method
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (3 preceding siblings ...)
  2020-05-11 22:35 ` [PATCH 4/9] gdb: Convert language la_pass_by_reference " Andrew Burgess
@ 2020-05-11 22:35 ` Andrew Burgess
  2020-05-11 22:35 ` [PATCH 6/9] gdb: Convert language la_lookup_transparent_type " Andrew Burgess
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_language_arch_info function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_arch_info): Delete function, move
	implementation to...
	(ada_language::language_arch_info): ...here, a new member
	function.
	(ada_language_data): Delete la_language_arch_info.
	* c-lang.c (c_language_data): Likewise.
	(c_language::language_arch_info): New member function.
	(cplus_language_arch_info): Delete function, move
	implementation to...
	(cplus_language::language_arch_info): ...here, a new member
	function.
	(cplus_language_data): Delete la_language_arch_info.
	(asm_language_data): Likewise.
	(asm_language::language_arch_info): New member function.
	(minimal_language_data): Delete la_language_arch_info.
	(minimal_language::language_arch_info): New member function.
	* d-lang.c (d_language_arch_info): Delete function, move
	implementation to...
	(d_language::language_arch_info): ...here, a new member
	function.
	(d_language_data): Delete la_language_arch_info.
	* f-lang.c (f_language_arch_info): Delete function, move
	implementation to...
	(f_language::language_arch_info): ...here, a new member
	function.
	(f_language_data): Delete la_language_arch_info.
	* go-lang.c (go_language_arch_info): Delete function, move
	implementation to...
	(go_language::language_arch_info): ...here, a new member
	function.
	(go_language_data): Delete la_language_arch_info.
	* language.c (unknown_language_data): Likewise.
	(unknown_language::language_arch_info): New member function.
	(auto_language_data): Delete la_language_arch_info.
	(auto_language::language_arch_info): New member function.
	(language_gdbarch_post_init): Update call to
	la_language_arch_info.
	* language.h (language_data): Delete la_language_arch_info
	function pointer.
	(language_defn::language_arch_info): New function.
	* m2-lang.c (m2_language_arch_info): Delete function, move
	implementation to...
	(m2_language::language_arch_info): ...here, a new member
	function.
	(m2_language_data): Delete la_language_arch_info.
	* objc-lang.c (objc_language_arch_info): Delete function, move
	implementation to...
	(objc_language::language_arch_info): ...here, a new member
	function.
	(objc_language_data): Delete la_language_arch_info.
	* opencl-lang.c (opencl_language_arch_info): Delete function, move
	implementation to...
	(opencl_language::language_arch_info): ...here, a new member
	function.
	(opencl_language_data): Delete la_language_arch_info.
	* p-lang.c (pascal_language_arch_info): Delete function, move
	implementation to...
	(pascal_language::language_arch_info): ...here, a new member
	function.
	(pascal_language_data): Delete la_language_arch_info.
	* rust-lang.c (rust_language_arch_info): Delete function, move
	implementation to...
	(rust_language::language_arch_info): ...here, a new member
	function.
	(rust_language_data): Delete la_language_arch_info.
---
 gdb/ChangeLog     |  70 ++++++++++++++++++++-
 gdb/ada-lang.c    | 133 ++++++++++++++++++++--------------------
 gdb/c-lang.c      | 153 ++++++++++++++++++++++++++--------------------
 gdb/d-lang.c      | 132 +++++++++++++++++++--------------------
 gdb/f-lang.c      |  77 ++++++++++++-----------
 gdb/go-lang.c     | 107 ++++++++++++++++----------------
 gdb/language.c    |  26 +++++---
 gdb/language.h    |   9 +--
 gdb/m2-lang.c     |  53 ++++++++--------
 gdb/objc-lang.c   |   8 ++-
 gdb/opencl-lang.c |  35 ++++++-----
 gdb/p-lang.c      |  99 +++++++++++++++---------------
 gdb/rust-lang.c   |  87 +++++++++++++-------------
 13 files changed, 539 insertions(+), 450 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 641f78199c6..3281f973cd0 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -216,9 +216,6 @@ static int ada_resolve_function (struct block_symbol *, int,
 
 static int ada_is_direct_array_type (struct type *);
 
-static void ada_language_arch_info (struct gdbarch *,
-				    struct language_arch_info *);
-
 static struct value *ada_index_struct_field (int, struct value *, int,
 					     struct type *);
 
@@ -13794,70 +13791,6 @@ enum ada_primitive_types {
   nr_ada_primitive_types
 };
 
-static void
-ada_language_arch_info (struct gdbarch *gdbarch,
-			struct language_arch_info *lai)
-{
-  const struct builtin_type *builtin = builtin_type (gdbarch);
-
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
-			      struct type *);
-
-  lai->primitive_type_vector [ada_primitive_type_int]
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-			 0, "integer");
-  lai->primitive_type_vector [ada_primitive_type_long]
-    = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
-			 0, "long_integer");
-  lai->primitive_type_vector [ada_primitive_type_short]
-    = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
-			 0, "short_integer");
-  lai->string_char_type
-    = lai->primitive_type_vector [ada_primitive_type_char]
-    = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
-  lai->primitive_type_vector [ada_primitive_type_float]
-    = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
-		       "float", gdbarch_float_format (gdbarch));
-  lai->primitive_type_vector [ada_primitive_type_double]
-    = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
-		       "long_float", gdbarch_double_format (gdbarch));
-  lai->primitive_type_vector [ada_primitive_type_long_long]
-    = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
-			 0, "long_long_integer");
-  lai->primitive_type_vector [ada_primitive_type_long_double]
-    = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
-		       "long_long_float", gdbarch_long_double_format (gdbarch));
-  lai->primitive_type_vector [ada_primitive_type_natural]
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-			 0, "natural");
-  lai->primitive_type_vector [ada_primitive_type_positive]
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-			 0, "positive");
-  lai->primitive_type_vector [ada_primitive_type_void]
-    = builtin->builtin_void;
-
-  lai->primitive_type_vector [ada_primitive_type_system_address]
-    = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
-				      "void"));
-  TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
-    = "system__address";
-
-  /* Create the equivalent of the System.Storage_Elements.Storage_Offset
-     type.  This is a signed integral type whose size is the same as
-     the size of addresses.  */
-  {
-    unsigned int addr_length = TYPE_LENGTH
-      (lai->primitive_type_vector [ada_primitive_type_system_address]);
-
-    lai->primitive_type_vector [ada_primitive_type_storage_offset]
-      = arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0,
-			   "storage_offset");
-  }
-
-  lai->bool_type_symbol = NULL;
-  lai->bool_type_default = builtin->builtin_bool;
-}
 \f
 				/* Language vector */
 
@@ -14076,7 +14009,6 @@ extern const struct language_data ada_language_data =
   1,                            /* String lower bound */
   ada_get_gdb_completer_word_break_characters,
   ada_collect_symbol_completion_matches,
-  ada_language_arch_info,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
   ada_iterate_over_symbols,
@@ -14126,6 +14058,71 @@ class ada_language : public language_defn
        function to work.  */
     return default_read_var_value (var, var_block, frame);
   }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_type *builtin = builtin_type (gdbarch);
+
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [ada_primitive_type_int]
+      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+			   0, "integer");
+    lai->primitive_type_vector [ada_primitive_type_long]
+      = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
+			   0, "long_integer");
+    lai->primitive_type_vector [ada_primitive_type_short]
+      = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
+			   0, "short_integer");
+    lai->string_char_type
+      = lai->primitive_type_vector [ada_primitive_type_char]
+      = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
+    lai->primitive_type_vector [ada_primitive_type_float]
+      = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
+			 "float", gdbarch_float_format (gdbarch));
+    lai->primitive_type_vector [ada_primitive_type_double]
+      = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
+			 "long_float", gdbarch_double_format (gdbarch));
+    lai->primitive_type_vector [ada_primitive_type_long_long]
+      = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
+			   0, "long_long_integer");
+    lai->primitive_type_vector [ada_primitive_type_long_double]
+      = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
+			 "long_long_float", gdbarch_long_double_format (gdbarch));
+    lai->primitive_type_vector [ada_primitive_type_natural]
+      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+			   0, "natural");
+    lai->primitive_type_vector [ada_primitive_type_positive]
+      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+			   0, "positive");
+    lai->primitive_type_vector [ada_primitive_type_void]
+      = builtin->builtin_void;
+
+    lai->primitive_type_vector [ada_primitive_type_system_address]
+      = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
+					"void"));
+    TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
+      = "system__address";
+
+    /* Create the equivalent of the System.Storage_Elements.Storage_Offset
+       type.  This is a signed integral type whose size is the same as
+       the size of addresses.  */
+    {
+      unsigned int addr_length = TYPE_LENGTH
+	(lai->primitive_type_vector [ada_primitive_type_system_address]);
+
+      lai->primitive_type_vector [ada_primitive_type_storage_offset]
+	= arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0,
+			     "storage_offset");
+    }
+
+    lai->bool_type_symbol = NULL;
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 1cc5b5c264d..1a9837b8361 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -921,7 +921,6 @@ extern const struct language_data c_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  c_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -941,6 +940,13 @@ class c_language : public language_defn
   c_language ()
     : language_defn (language_c, c_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    c_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* Single instance of the C language class.  */
@@ -975,69 +981,6 @@ enum cplus_primitive_types {
   nr_cplus_primitive_types
 };
 
-static void
-cplus_language_arch_info (struct gdbarch *gdbarch,
-			  struct language_arch_info *lai)
-{
-  const struct builtin_type *builtin = builtin_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
-			      struct type *);
-  lai->primitive_type_vector [cplus_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [cplus_primitive_type_long]
-    = builtin->builtin_long;
-  lai->primitive_type_vector [cplus_primitive_type_short]
-    = builtin->builtin_short;
-  lai->primitive_type_vector [cplus_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [cplus_primitive_type_float]
-    = builtin->builtin_float;
-  lai->primitive_type_vector [cplus_primitive_type_double]
-    = builtin->builtin_double;
-  lai->primitive_type_vector [cplus_primitive_type_void]
-    = builtin->builtin_void;
-  lai->primitive_type_vector [cplus_primitive_type_long_long]
-    = builtin->builtin_long_long;
-  lai->primitive_type_vector [cplus_primitive_type_signed_char]
-    = builtin->builtin_signed_char;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
-    = builtin->builtin_unsigned_char;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
-    = builtin->builtin_unsigned_short;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
-    = builtin->builtin_unsigned_int;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
-    = builtin->builtin_unsigned_long;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
-    = builtin->builtin_unsigned_long_long;
-  lai->primitive_type_vector [cplus_primitive_type_long_double]
-    = builtin->builtin_long_double;
-  lai->primitive_type_vector [cplus_primitive_type_complex]
-    = builtin->builtin_complex;
-  lai->primitive_type_vector [cplus_primitive_type_double_complex]
-    = builtin->builtin_double_complex;
-  lai->primitive_type_vector [cplus_primitive_type_bool]
-    = builtin->builtin_bool;
-  lai->primitive_type_vector [cplus_primitive_type_decfloat]
-    = builtin->builtin_decfloat;
-  lai->primitive_type_vector [cplus_primitive_type_decdouble]
-    = builtin->builtin_decdouble;
-  lai->primitive_type_vector [cplus_primitive_type_declong]
-    = builtin->builtin_declong;
-  lai->primitive_type_vector [cplus_primitive_type_char16_t]
-    = builtin->builtin_char16;
-  lai->primitive_type_vector [cplus_primitive_type_char32_t]
-    = builtin->builtin_char32;
-  lai->primitive_type_vector [cplus_primitive_type_wchar_t]
-    = builtin->builtin_wchar;
-
-  lai->bool_type_symbol = "bool";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 static const char *cplus_extensions[] =
 {
   ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", NULL
@@ -1079,7 +1022,6 @@ extern const struct language_data cplus_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  cplus_language_arch_info,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
   iterate_over_symbols,
@@ -1107,6 +1049,69 @@ class cplus_language : public language_defn
   {
     return cp_pass_by_reference (type);
   }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_type *builtin = builtin_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
+				struct type *);
+    lai->primitive_type_vector [cplus_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [cplus_primitive_type_long]
+      = builtin->builtin_long;
+    lai->primitive_type_vector [cplus_primitive_type_short]
+      = builtin->builtin_short;
+    lai->primitive_type_vector [cplus_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [cplus_primitive_type_float]
+      = builtin->builtin_float;
+    lai->primitive_type_vector [cplus_primitive_type_double]
+      = builtin->builtin_double;
+    lai->primitive_type_vector [cplus_primitive_type_void]
+      = builtin->builtin_void;
+    lai->primitive_type_vector [cplus_primitive_type_long_long]
+      = builtin->builtin_long_long;
+    lai->primitive_type_vector [cplus_primitive_type_signed_char]
+      = builtin->builtin_signed_char;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
+      = builtin->builtin_unsigned_char;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
+      = builtin->builtin_unsigned_short;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
+      = builtin->builtin_unsigned_int;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
+      = builtin->builtin_unsigned_long;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
+      = builtin->builtin_unsigned_long_long;
+    lai->primitive_type_vector [cplus_primitive_type_long_double]
+      = builtin->builtin_long_double;
+    lai->primitive_type_vector [cplus_primitive_type_complex]
+      = builtin->builtin_complex;
+    lai->primitive_type_vector [cplus_primitive_type_double_complex]
+      = builtin->builtin_double_complex;
+    lai->primitive_type_vector [cplus_primitive_type_bool]
+      = builtin->builtin_bool;
+    lai->primitive_type_vector [cplus_primitive_type_decfloat]
+      = builtin->builtin_decfloat;
+    lai->primitive_type_vector [cplus_primitive_type_decdouble]
+      = builtin->builtin_decdouble;
+    lai->primitive_type_vector [cplus_primitive_type_declong]
+      = builtin->builtin_declong;
+    lai->primitive_type_vector [cplus_primitive_type_char16_t]
+      = builtin->builtin_char16;
+    lai->primitive_type_vector [cplus_primitive_type_char32_t]
+      = builtin->builtin_char32;
+    lai->primitive_type_vector [cplus_primitive_type_wchar_t]
+      = builtin->builtin_wchar;
+
+    lai->bool_type_symbol = "bool";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1154,7 +1159,6 @@ extern const struct language_data asm_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  c_language_arch_info,		/* FIXME: la_language_arch_info.  */
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1174,6 +1178,15 @@ class asm_language : public language_defn
   asm_language ()
     : language_defn (language_asm, asm_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.
+
+     FIXME: Should this have its own arch info method?  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    c_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* The single instance of the ASM language class.  */
@@ -1218,7 +1231,6 @@ extern const struct language_data minimal_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  c_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1238,6 +1250,13 @@ class minimal_language : public language_defn
   minimal_language ()
     : language_defn (language_minimal, minimal_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    c_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* The single instance of the minimal language class.  */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 28864420bad..778d77313c9 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -133,73 +133,6 @@ enum d_primitive_types {
   nr_d_primitive_types
 };
 
-/* Implements the la_language_arch_info language_defn routine
-   for language D.  */
-
-static void
-d_language_arch_info (struct gdbarch *gdbarch,
-		      struct language_arch_info *lai)
-{
-  const struct builtin_d_type *builtin = builtin_d_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_d_primitive_types + 1,
-			      struct type *);
-
-  lai->primitive_type_vector [d_primitive_type_void]
-    = builtin->builtin_void;
-  lai->primitive_type_vector [d_primitive_type_bool]
-    = builtin->builtin_bool;
-  lai->primitive_type_vector [d_primitive_type_byte]
-    = builtin->builtin_byte;
-  lai->primitive_type_vector [d_primitive_type_ubyte]
-    = builtin->builtin_ubyte;
-  lai->primitive_type_vector [d_primitive_type_short]
-    = builtin->builtin_short;
-  lai->primitive_type_vector [d_primitive_type_ushort]
-    = builtin->builtin_ushort;
-  lai->primitive_type_vector [d_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [d_primitive_type_uint]
-    = builtin->builtin_uint;
-  lai->primitive_type_vector [d_primitive_type_long]
-    = builtin->builtin_long;
-  lai->primitive_type_vector [d_primitive_type_ulong]
-    = builtin->builtin_ulong;
-  lai->primitive_type_vector [d_primitive_type_cent]
-    = builtin->builtin_cent;
-  lai->primitive_type_vector [d_primitive_type_ucent]
-    = builtin->builtin_ucent;
-  lai->primitive_type_vector [d_primitive_type_float]
-    = builtin->builtin_float;
-  lai->primitive_type_vector [d_primitive_type_double]
-    = builtin->builtin_double;
-  lai->primitive_type_vector [d_primitive_type_real]
-    = builtin->builtin_real;
-  lai->primitive_type_vector [d_primitive_type_ifloat]
-    = builtin->builtin_ifloat;
-  lai->primitive_type_vector [d_primitive_type_idouble]
-    = builtin->builtin_idouble;
-  lai->primitive_type_vector [d_primitive_type_ireal]
-    = builtin->builtin_ireal;
-  lai->primitive_type_vector [d_primitive_type_cfloat]
-    = builtin->builtin_cfloat;
-  lai->primitive_type_vector [d_primitive_type_cdouble]
-    = builtin->builtin_cdouble;
-  lai->primitive_type_vector [d_primitive_type_creal]
-    = builtin->builtin_creal;
-  lai->primitive_type_vector [d_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [d_primitive_type_wchar]
-    = builtin->builtin_wchar;
-  lai->primitive_type_vector [d_primitive_type_dchar]
-    = builtin->builtin_dchar;
-
-  lai->bool_type_symbol = "bool";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 static const char *d_extensions[] =
 {
   ".d", NULL
@@ -242,7 +175,6 @@ extern const struct language_data d_language_data =
   0,				/* String lower bound.  */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  d_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -262,6 +194,70 @@ class d_language : public language_defn
   d_language ()
     : language_defn (language_d, d_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_d_type *builtin = builtin_d_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_d_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [d_primitive_type_void]
+      = builtin->builtin_void;
+    lai->primitive_type_vector [d_primitive_type_bool]
+      = builtin->builtin_bool;
+    lai->primitive_type_vector [d_primitive_type_byte]
+      = builtin->builtin_byte;
+    lai->primitive_type_vector [d_primitive_type_ubyte]
+      = builtin->builtin_ubyte;
+    lai->primitive_type_vector [d_primitive_type_short]
+      = builtin->builtin_short;
+    lai->primitive_type_vector [d_primitive_type_ushort]
+      = builtin->builtin_ushort;
+    lai->primitive_type_vector [d_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [d_primitive_type_uint]
+      = builtin->builtin_uint;
+    lai->primitive_type_vector [d_primitive_type_long]
+      = builtin->builtin_long;
+    lai->primitive_type_vector [d_primitive_type_ulong]
+      = builtin->builtin_ulong;
+    lai->primitive_type_vector [d_primitive_type_cent]
+      = builtin->builtin_cent;
+    lai->primitive_type_vector [d_primitive_type_ucent]
+      = builtin->builtin_ucent;
+    lai->primitive_type_vector [d_primitive_type_float]
+      = builtin->builtin_float;
+    lai->primitive_type_vector [d_primitive_type_double]
+      = builtin->builtin_double;
+    lai->primitive_type_vector [d_primitive_type_real]
+      = builtin->builtin_real;
+    lai->primitive_type_vector [d_primitive_type_ifloat]
+      = builtin->builtin_ifloat;
+    lai->primitive_type_vector [d_primitive_type_idouble]
+      = builtin->builtin_idouble;
+    lai->primitive_type_vector [d_primitive_type_ireal]
+      = builtin->builtin_ireal;
+    lai->primitive_type_vector [d_primitive_type_cfloat]
+      = builtin->builtin_cfloat;
+    lai->primitive_type_vector [d_primitive_type_cdouble]
+      = builtin->builtin_cdouble;
+    lai->primitive_type_vector [d_primitive_type_creal]
+      = builtin->builtin_creal;
+    lai->primitive_type_vector [d_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [d_primitive_type_wchar]
+      = builtin->builtin_wchar;
+    lai->primitive_type_vector [d_primitive_type_dchar]
+      = builtin->builtin_dchar;
+
+    lai->bool_type_symbol = "bool";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the D language class.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index efa1b4f84de..0528e396c14 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -165,44 +165,6 @@ enum f_primitive_types {
   nr_f_primitive_types
 };
 
-static void
-f_language_arch_info (struct gdbarch *gdbarch,
-		      struct language_arch_info *lai)
-{
-  const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_character;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1,
-                              struct type *);
-
-  lai->primitive_type_vector [f_primitive_type_character]
-    = builtin->builtin_character;
-  lai->primitive_type_vector [f_primitive_type_logical]
-    = builtin->builtin_logical;
-  lai->primitive_type_vector [f_primitive_type_logical_s1]
-    = builtin->builtin_logical_s1;
-  lai->primitive_type_vector [f_primitive_type_logical_s2]
-    = builtin->builtin_logical_s2;
-  lai->primitive_type_vector [f_primitive_type_logical_s8]
-    = builtin->builtin_logical_s8;
-  lai->primitive_type_vector [f_primitive_type_real]
-    = builtin->builtin_real;
-  lai->primitive_type_vector [f_primitive_type_real_s8]
-    = builtin->builtin_real_s8;
-  lai->primitive_type_vector [f_primitive_type_real_s16]
-    = builtin->builtin_real_s16;
-  lai->primitive_type_vector [f_primitive_type_complex_s8]
-    = builtin->builtin_complex_s8;
-  lai->primitive_type_vector [f_primitive_type_complex_s16]
-    = builtin->builtin_complex_s16;
-  lai->primitive_type_vector [f_primitive_type_void]
-    = builtin->builtin_void;
-
-  lai->bool_type_symbol = "logical";
-  lai->bool_type_default = builtin->builtin_logical_s2;
-}
-
 /* Remove the modules separator :: from the default break list.  */
 
 static const char *
@@ -670,7 +632,6 @@ extern const struct language_data f_language_data =
   1,				/* String lower bound */
   f_word_break_characters,
   f_collect_symbol_completion_matches,
-  f_language_arch_info,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -690,6 +651,44 @@ class f_language : public language_defn
   f_language ()
     : language_defn (language_fortran, f_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_character;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [f_primitive_type_character]
+      = builtin->builtin_character;
+    lai->primitive_type_vector [f_primitive_type_logical]
+      = builtin->builtin_logical;
+    lai->primitive_type_vector [f_primitive_type_logical_s1]
+      = builtin->builtin_logical_s1;
+    lai->primitive_type_vector [f_primitive_type_logical_s2]
+      = builtin->builtin_logical_s2;
+    lai->primitive_type_vector [f_primitive_type_logical_s8]
+      = builtin->builtin_logical_s8;
+    lai->primitive_type_vector [f_primitive_type_real]
+      = builtin->builtin_real;
+    lai->primitive_type_vector [f_primitive_type_real_s8]
+      = builtin->builtin_real_s8;
+    lai->primitive_type_vector [f_primitive_type_real_s16]
+      = builtin->builtin_real_s16;
+    lai->primitive_type_vector [f_primitive_type_complex_s8]
+      = builtin->builtin_complex_s8;
+    lai->primitive_type_vector [f_primitive_type_complex_s16]
+      = builtin->builtin_complex_s16;
+    lai->primitive_type_vector [f_primitive_type_void]
+      = builtin->builtin_void;
+
+    lai->bool_type_symbol = "logical";
+    lai->bool_type_default = builtin->builtin_logical_s2;
+  }
 };
 
 /* Single instance of the Fortran language class.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 08b547463bc..8e590974ee4 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -523,59 +523,6 @@ enum go_primitive_types {
   nr_go_primitive_types
 };
 
-static void
-go_language_arch_info (struct gdbarch *gdbarch,
-		       struct language_arch_info *lai)
-{
-  const struct builtin_go_type *builtin = builtin_go_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_go_primitive_types + 1,
-			      struct type *);
-
-  lai->primitive_type_vector [go_primitive_type_void]
-    = builtin->builtin_void;
-  lai->primitive_type_vector [go_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [go_primitive_type_bool]
-    = builtin->builtin_bool;
-  lai->primitive_type_vector [go_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [go_primitive_type_uint]
-    = builtin->builtin_uint;
-  lai->primitive_type_vector [go_primitive_type_uintptr]
-    = builtin->builtin_uintptr;
-  lai->primitive_type_vector [go_primitive_type_int8]
-    = builtin->builtin_int8;
-  lai->primitive_type_vector [go_primitive_type_int16]
-    = builtin->builtin_int16;
-  lai->primitive_type_vector [go_primitive_type_int32]
-    = builtin->builtin_int32;
-  lai->primitive_type_vector [go_primitive_type_int64]
-    = builtin->builtin_int64;
-  lai->primitive_type_vector [go_primitive_type_uint8]
-    = builtin->builtin_uint8;
-  lai->primitive_type_vector [go_primitive_type_uint16]
-    = builtin->builtin_uint16;
-  lai->primitive_type_vector [go_primitive_type_uint32]
-    = builtin->builtin_uint32;
-  lai->primitive_type_vector [go_primitive_type_uint64]
-    = builtin->builtin_uint64;
-  lai->primitive_type_vector [go_primitive_type_float32]
-    = builtin->builtin_float32;
-  lai->primitive_type_vector [go_primitive_type_float64]
-    = builtin->builtin_float64;
-  lai->primitive_type_vector [go_primitive_type_complex64]
-    = builtin->builtin_complex64;
-  lai->primitive_type_vector [go_primitive_type_complex128]
-    = builtin->builtin_complex128;
-
-  lai->bool_type_symbol = "bool";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 /* Constant data that describes the Go language.  */
 
 extern const struct language_data go_language_data =
@@ -613,7 +560,6 @@ extern const struct language_data go_language_data =
   0,				/* String lower bound.  */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  go_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -633,6 +579,59 @@ class go_language : public language_defn
   go_language ()
     : language_defn (language_go, go_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_go_type *builtin = builtin_go_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_go_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [go_primitive_type_void]
+      = builtin->builtin_void;
+    lai->primitive_type_vector [go_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [go_primitive_type_bool]
+      = builtin->builtin_bool;
+    lai->primitive_type_vector [go_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [go_primitive_type_uint]
+      = builtin->builtin_uint;
+    lai->primitive_type_vector [go_primitive_type_uintptr]
+      = builtin->builtin_uintptr;
+    lai->primitive_type_vector [go_primitive_type_int8]
+      = builtin->builtin_int8;
+    lai->primitive_type_vector [go_primitive_type_int16]
+      = builtin->builtin_int16;
+    lai->primitive_type_vector [go_primitive_type_int32]
+      = builtin->builtin_int32;
+    lai->primitive_type_vector [go_primitive_type_int64]
+      = builtin->builtin_int64;
+    lai->primitive_type_vector [go_primitive_type_uint8]
+      = builtin->builtin_uint8;
+    lai->primitive_type_vector [go_primitive_type_uint16]
+      = builtin->builtin_uint16;
+    lai->primitive_type_vector [go_primitive_type_uint32]
+      = builtin->builtin_uint32;
+    lai->primitive_type_vector [go_primitive_type_uint64]
+      = builtin->builtin_uint64;
+    lai->primitive_type_vector [go_primitive_type_float32]
+      = builtin->builtin_float32;
+    lai->primitive_type_vector [go_primitive_type_float64]
+      = builtin->builtin_float64;
+    lai->primitive_type_vector [go_primitive_type_complex64]
+      = builtin->builtin_complex64;
+    lai->primitive_type_vector [go_primitive_type_complex128]
+      = builtin->builtin_complex128;
+
+    lai->bool_type_symbol = "bool";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the Go language class.  */
diff --git a/gdb/language.c b/gdb/language.c
index fec1fc383f5..4ded4deb194 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -861,7 +861,6 @@ extern const struct language_data unknown_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  unknown_language_arch_info,	/* la_language_arch_info.  */
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -881,6 +880,13 @@ class unknown_language : public language_defn
   unknown_language ()
     : language_defn (language_unknown, unknown_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    unknown_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -923,7 +929,6 @@ extern const struct language_data auto_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  unknown_language_arch_info,	/* la_language_arch_info.  */
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -943,6 +948,13 @@ class auto_language : public language_defn
   auto_language ()
     : language_defn (language_auto, auto_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    unknown_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
@@ -968,11 +980,11 @@ language_gdbarch_post_init (struct gdbarch *gdbarch)
 
   l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
   for (const auto &lang : language_defn::languages)
-    if (lang != NULL && lang->la_language_arch_info != NULL)
-      {
-	lang->la_language_arch_info (gdbarch,
-				     l->arch_info + lang->la_language);
-      }
+    {
+      gdb_assert (lang != nullptr);
+      lang->language_arch_info (gdbarch,
+				l->arch_info + lang->la_language);
+    }
 
   return l;
 }
diff --git a/gdb/language.h b/gdb/language.h
index 1435af7ad56..d6058dd6be9 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -368,10 +368,6 @@ struct language_data
        const char *word,
        enum type_code code);
 
-    /* The per-architecture (OS/ABI) language information.  */
-    void (*la_language_arch_info) (struct gdbarch *,
-				   struct language_arch_info *);
-
     /* Return an expression that can be used for a location
        watchpoint.  TYPE is a pointer type that points to the memory
        to watch, and ADDR is the address of the watched memory.  */
@@ -499,6 +495,11 @@ struct language_defn : language_data
   virtual struct language_pass_by_ref_info pass_by_reference_info
 	(struct type *type) const;
 
+  /* The per-architecture (OS/ABI) language information.  */
+
+  virtual void language_arch_info (struct gdbarch *,
+				   struct language_arch_info *) const = 0;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 26048684bf0..03c6cf610ae 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -339,32 +339,6 @@ enum m2_primitive_types {
   nr_m2_primitive_types
 };
 
-static void
-m2_language_arch_info (struct gdbarch *gdbarch,
-		       struct language_arch_info *lai)
-{
-  const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
-                              struct type *);
-
-  lai->primitive_type_vector [m2_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [m2_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [m2_primitive_type_card]
-    = builtin->builtin_card;
-  lai->primitive_type_vector [m2_primitive_type_real]
-    = builtin->builtin_real;
-  lai->primitive_type_vector [m2_primitive_type_bool]
-    = builtin->builtin_bool;
-
-  lai->bool_type_symbol = "BOOLEAN";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 const struct exp_descriptor exp_descriptor_modula2 = 
 {
   print_subexp_standard,
@@ -411,7 +385,6 @@ extern const struct language_data m2_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  m2_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -431,6 +404,32 @@ class m2_language : public language_defn
   m2_language ()
     : language_defn (language_m2, m2_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [m2_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [m2_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [m2_primitive_type_card]
+      = builtin->builtin_card;
+    lai->primitive_type_vector [m2_primitive_type_real]
+      = builtin->builtin_real;
+    lai->primitive_type_vector [m2_primitive_type_bool]
+      = builtin->builtin_bool;
+
+    lai->bool_type_symbol = "BOOLEAN";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index a2f22031721..10c1e3c50c8 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -400,7 +400,6 @@ extern const struct language_data objc_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  c_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -420,6 +419,13 @@ class objc_language : public language_defn
   objc_language ()
     : language_defn (language_objc, objc_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    c_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* Single instance of the class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 3562914c7d5..fa3db4115bf 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1015,23 +1015,6 @@ opencl_print_type (struct type *type, const char *varstring,
   c_print_type (type, varstring, stream, show, level, flags); 
 }
 
-static void
-opencl_language_arch_info (struct gdbarch *gdbarch,
-			   struct language_arch_info *lai)
-{
-  struct type **types = builtin_opencl_type (gdbarch);
-
-  /* Copy primitive types vector from gdbarch.  */
-  lai->primitive_type_vector = types;
-
-  /* Type of elements of strings.  */
-  lai->string_char_type = types [opencl_primitive_type_char];
-
-  /* Specifies the return type of logical and relational operations.  */
-  lai->bool_type_symbol = "int";
-  lai->bool_type_default = types [opencl_primitive_type_int];
-}
-
 const struct exp_descriptor exp_descriptor_opencl =
 {
   print_subexp_standard,
@@ -1077,7 +1060,6 @@ extern const struct language_data opencl_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  opencl_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1097,6 +1079,23 @@ class opencl_language : public language_defn
   opencl_language ()
     : language_defn (language_opencl, opencl_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    struct type **types = builtin_opencl_type (gdbarch);
+
+    /* Copy primitive types vector from gdbarch.  */
+    lai->primitive_type_vector = types;
+
+    /* Type of elements of strings.  */
+    lai->string_char_type = types [opencl_primitive_type_char];
+
+    /* Specifies the return type of logical and relational operations.  */
+    lai->bool_type_symbol = "int";
+    lai->bool_type_default = types [opencl_primitive_type_int];
+  }
 };
 
 /* Single instance of the OpenCL language class.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index cc0efaa0bdc..0ab43049a1c 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -375,55 +375,6 @@ enum pascal_primitive_types {
   nr_pascal_primitive_types
 };
 
-static void
-pascal_language_arch_info (struct gdbarch *gdbarch,
-			   struct language_arch_info *lai)
-{
-  const struct builtin_type *builtin = builtin_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_pascal_primitive_types + 1,
-                              struct type *);
-  lai->primitive_type_vector [pascal_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [pascal_primitive_type_long]
-    = builtin->builtin_long;
-  lai->primitive_type_vector [pascal_primitive_type_short]
-    = builtin->builtin_short;
-  lai->primitive_type_vector [pascal_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [pascal_primitive_type_float]
-    = builtin->builtin_float;
-  lai->primitive_type_vector [pascal_primitive_type_double]
-    = builtin->builtin_double;
-  lai->primitive_type_vector [pascal_primitive_type_void]
-    = builtin->builtin_void;
-  lai->primitive_type_vector [pascal_primitive_type_long_long]
-    = builtin->builtin_long_long;
-  lai->primitive_type_vector [pascal_primitive_type_signed_char]
-    = builtin->builtin_signed_char;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_char]
-    = builtin->builtin_unsigned_char;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_short]
-    = builtin->builtin_unsigned_short;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_int]
-    = builtin->builtin_unsigned_int;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_long]
-    = builtin->builtin_unsigned_long;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_long_long]
-    = builtin->builtin_unsigned_long_long;
-  lai->primitive_type_vector [pascal_primitive_type_long_double]
-    = builtin->builtin_long_double;
-  lai->primitive_type_vector [pascal_primitive_type_complex]
-    = builtin->builtin_complex;
-  lai->primitive_type_vector [pascal_primitive_type_double_complex]
-    = builtin->builtin_double_complex;
-
-  lai->bool_type_symbol = "boolean";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 static const char *p_extensions[] =
 {
   ".pas", ".p", ".pp", NULL
@@ -464,7 +415,6 @@ extern const struct language_data pascal_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  pascal_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
   iterate_over_symbols,
@@ -484,6 +434,55 @@ class pascal_language : public language_defn
   pascal_language ()
     : language_defn (language_pascal, pascal_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_type *builtin = builtin_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_pascal_primitive_types + 1,
+                              struct type *);
+    lai->primitive_type_vector [pascal_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [pascal_primitive_type_long]
+      = builtin->builtin_long;
+    lai->primitive_type_vector [pascal_primitive_type_short]
+      = builtin->builtin_short;
+    lai->primitive_type_vector [pascal_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [pascal_primitive_type_float]
+      = builtin->builtin_float;
+    lai->primitive_type_vector [pascal_primitive_type_double]
+      = builtin->builtin_double;
+    lai->primitive_type_vector [pascal_primitive_type_void]
+      = builtin->builtin_void;
+    lai->primitive_type_vector [pascal_primitive_type_long_long]
+      = builtin->builtin_long_long;
+    lai->primitive_type_vector [pascal_primitive_type_signed_char]
+      = builtin->builtin_signed_char;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_char]
+      = builtin->builtin_unsigned_char;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_short]
+      = builtin->builtin_unsigned_short;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_int]
+      = builtin->builtin_unsigned_int;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_long]
+      = builtin->builtin_unsigned_long;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_long_long]
+      = builtin->builtin_unsigned_long_long;
+    lai->primitive_type_vector [pascal_primitive_type_long_double]
+      = builtin->builtin_long_double;
+    lai->primitive_type_vector [pascal_primitive_type_complex]
+      = builtin->builtin_complex;
+    lai->primitive_type_vector [pascal_primitive_type_double_complex]
+      = builtin->builtin_double_complex;
+
+    lai->bool_type_symbol = "boolean";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 33208c7ac1b..fe997e5b70c 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1066,51 +1066,6 @@ enum rust_primitive_types
   nr_rust_primitive_types
 };
 
-/* la_language_arch_info implementation for Rust.  */
-
-static void
-rust_language_arch_info (struct gdbarch *gdbarch,
-			 struct language_arch_info *lai)
-{
-  const struct builtin_type *builtin = builtin_type (gdbarch);
-  struct type *tem;
-  struct type **types;
-  unsigned int length;
-
-  types = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_rust_primitive_types + 1,
-				  struct type *);
-
-  types[rust_primitive_bool] = arch_boolean_type (gdbarch, 8, 1, "bool");
-  types[rust_primitive_char] = arch_character_type (gdbarch, 32, 1, "char");
-  types[rust_primitive_i8] = arch_integer_type (gdbarch, 8, 0, "i8");
-  types[rust_primitive_u8] = arch_integer_type (gdbarch, 8, 1, "u8");
-  types[rust_primitive_i16] = arch_integer_type (gdbarch, 16, 0, "i16");
-  types[rust_primitive_u16] = arch_integer_type (gdbarch, 16, 1, "u16");
-  types[rust_primitive_i32] = arch_integer_type (gdbarch, 32, 0, "i32");
-  types[rust_primitive_u32] = arch_integer_type (gdbarch, 32, 1, "u32");
-  types[rust_primitive_i64] = arch_integer_type (gdbarch, 64, 0, "i64");
-  types[rust_primitive_u64] = arch_integer_type (gdbarch, 64, 1, "u64");
-
-  length = 8 * TYPE_LENGTH (builtin->builtin_data_ptr);
-  types[rust_primitive_isize] = arch_integer_type (gdbarch, length, 0, "isize");
-  types[rust_primitive_usize] = arch_integer_type (gdbarch, length, 1, "usize");
-
-  types[rust_primitive_f32] = arch_float_type (gdbarch, 32, "f32",
-					       floatformats_ieee_single);
-  types[rust_primitive_f64] = arch_float_type (gdbarch, 64, "f64",
-					       floatformats_ieee_double);
-
-  types[rust_primitive_unit] = arch_integer_type (gdbarch, 0, 1, "()");
-
-  tem = make_cv_type (1, 0, types[rust_primitive_u8], NULL);
-  types[rust_primitive_str] = rust_slice_type ("&str", tem,
-					       types[rust_primitive_usize]);
-
-  lai->primitive_type_vector = types;
-  lai->bool_type_default = types[rust_primitive_bool];
-  lai->string_char_type = types[rust_primitive_u8];
-}
-
 \f
 
 /* A helper for rust_evaluate_subexp that handles OP_FUNCALL.  */
@@ -2137,7 +2092,6 @@ extern const struct language_data rust_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  rust_language_arch_info,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -2157,6 +2111,47 @@ class rust_language : public language_defn
   rust_language ()
     : language_defn (language_rust, rust_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_type *builtin = builtin_type (gdbarch);
+
+    struct type **types
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_rust_primitive_types + 1,
+				struct type *);
+
+    types[rust_primitive_bool] = arch_boolean_type (gdbarch, 8, 1, "bool");
+    types[rust_primitive_char] = arch_character_type (gdbarch, 32, 1, "char");
+    types[rust_primitive_i8] = arch_integer_type (gdbarch, 8, 0, "i8");
+    types[rust_primitive_u8] = arch_integer_type (gdbarch, 8, 1, "u8");
+    types[rust_primitive_i16] = arch_integer_type (gdbarch, 16, 0, "i16");
+    types[rust_primitive_u16] = arch_integer_type (gdbarch, 16, 1, "u16");
+    types[rust_primitive_i32] = arch_integer_type (gdbarch, 32, 0, "i32");
+    types[rust_primitive_u32] = arch_integer_type (gdbarch, 32, 1, "u32");
+    types[rust_primitive_i64] = arch_integer_type (gdbarch, 64, 0, "i64");
+    types[rust_primitive_u64] = arch_integer_type (gdbarch, 64, 1, "u64");
+
+    unsigned int length = 8 * TYPE_LENGTH (builtin->builtin_data_ptr);
+    types[rust_primitive_isize] = arch_integer_type (gdbarch, length, 0, "isize");
+    types[rust_primitive_usize] = arch_integer_type (gdbarch, length, 1, "usize");
+
+    types[rust_primitive_f32] = arch_float_type (gdbarch, 32, "f32",
+						 floatformats_ieee_single);
+    types[rust_primitive_f64] = arch_float_type (gdbarch, 64, "f64",
+						 floatformats_ieee_double);
+
+    types[rust_primitive_unit] = arch_integer_type (gdbarch, 0, 1, "()");
+
+    struct type *tem = make_cv_type (1, 0, types[rust_primitive_u8], NULL);
+    types[rust_primitive_str] = rust_slice_type ("&str", tem,
+						 types[rust_primitive_usize]);
+
+    lai->primitive_type_vector = types;
+    lai->bool_type_default = types[rust_primitive_bool];
+    lai->string_char_type = types[rust_primitive_u8];
+  }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 6/9] gdb: Convert language la_lookup_transparent_type field to a method
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (4 preceding siblings ...)
  2020-05-11 22:35 ` [PATCH 5/9] gdb: Convert language la_language_arch_info " Andrew Burgess
@ 2020-05-11 22:35 ` Andrew Burgess
  2020-05-11 22:35 ` [PATCH 7/9] gdb: Convert language la_iterate_over_symbols " Andrew Burgess
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_lookup_transparent_type
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete
	la_lookup_transparent_type initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(cplus_language::lookup_transparent_type): New member function.
	(asm_language_data): Delete la_lookup_transparent_type
	initializer.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (struct language_data): Delete
	la_lookup_transparent_type field.
	(language_defn::lookup_transparent_type): New member function.
	* m2-lang.c (m2_language_data): Delete la_lookup_transparent_type
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	* symtab.c (symbol_matches_domain): Update call.
---
 gdb/ChangeLog     | 26 ++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      | 10 ++++++----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 gdb/language.h    | 10 +++++++---
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 gdb/symtab.c      |  2 +-
 14 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3281f973cd0..df9c6ab72cc 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13999,7 +13999,6 @@ extern const struct language_data ada_language_data =
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
-  basic_lookup_transparent_type,        /* lookup_transparent_type */
   ada_la_decode,                /* Language specific symbol demangler */
   ada_sniff_from_mangled_name,
   NULL,                         /* Language specific
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 1a9837b8361..9de546847c3 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -911,7 +911,6 @@ extern const struct language_data c_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
@@ -1012,7 +1011,6 @@ extern const struct language_data cplus_language_data =
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  cp_lookup_transparent_type,   /* lookup_transparent_type */
   gdb_demangle,			/* Language specific symbol demangler */
   gdb_sniff_from_mangled_name,
   cp_class_name_from_physname,  /* Language specific
@@ -1112,6 +1110,12 @@ class cplus_language : public language_defn
     lai->bool_type_symbol = "bool";
     lai->bool_type_default = builtin->builtin_bool;
   }
+
+  /* See language.h.  */
+  struct type *lookup_transparent_type (const char *name) const override
+  {
+    return cp_lookup_transparent_type (name);
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1149,7 +1153,6 @@ extern const struct language_data asm_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
@@ -1221,7 +1224,6 @@ extern const struct language_data minimal_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 778d77313c9..8c4ee44ac97 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -165,7 +165,6 @@ extern const struct language_data d_language_data =
   "this",
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_lookup_symbol_nonlocal,
-  basic_lookup_transparent_type,
   d_demangle,			/* Language specific symbol demangler.  */
   d_sniff_from_mangled_name,
   NULL,				/* Language specific
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 0528e396c14..70903d4a56d 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -616,7 +616,6 @@ extern const struct language_data f_language_data =
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
 
   /* We could support demangling here to provide module namespaces
      also for inferiors with only minimal symbol table (ELF symbols).
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 8e590974ee4..8036338415d 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -550,7 +550,6 @@ extern const struct language_data go_language_data =
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, 
-  basic_lookup_transparent_type,
   go_demangle,			/* Language specific symbol demangler.  */
   go_sniff_from_mangled_name,
   NULL,				/* Language specific
diff --git a/gdb/language.c b/gdb/language.c
index 4ded4deb194..4e1cb4d657e 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -851,7 +851,6 @@ extern const struct language_data unknown_language_data =
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
   NULL,
   unk_lang_class_name,		/* Language specific
@@ -919,7 +918,6 @@ extern const struct language_data auto_language_data =
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
   NULL,
   unk_lang_class_name,		/* Language specific
diff --git a/gdb/language.h b/gdb/language.h
index d6058dd6be9..dfd63fcac25 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -315,9 +315,6 @@ struct language_data
        const struct block *,
        const domain_enum);
 
-    /* Find the definition of the type with the given name.  */
-    struct type *(*la_lookup_transparent_type) (const char *);
-
     /* Return demangled language symbol, or NULL.  */
     char *(*la_demangle) (const char *mangled, int options);
 
@@ -500,6 +497,13 @@ struct language_defn : language_data
   virtual void language_arch_info (struct gdbarch *,
 				   struct language_arch_info *) const = 0;
 
+  /* Find the definition of the type with the given name.  */
+
+  virtual struct type *lookup_transparent_type (const char *name) const
+  {
+    return basic_lookup_transparent_type (name);
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 03c6cf610ae..8b994a79557 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -375,7 +375,6 @@ extern const struct language_data m2_language_data =
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 10c1e3c50c8..05a18311a58 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -390,7 +390,6 @@ extern const struct language_data objc_language_data =
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   objc_demangle,		/* Language specific symbol demangler */
   objc_sniff_from_mangled_name,
   NULL,				/* Language specific
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index fa3db4115bf..6b98f1159c6 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1050,7 +1050,6 @@ extern const struct language_data opencl_language_data =
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 0ab43049a1c..08b7f0464a0 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -406,7 +406,6 @@ extern const struct language_data pascal_language_data =
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific class_name_from_physname */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index fe997e5b70c..8baa7b2d357 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2082,7 +2082,6 @@ extern const struct language_data rust_language_data =
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   rust_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   gdb_demangle,			/* Language specific symbol demangler */
   rust_sniff_from_mangled_name,
   NULL,				/* Language specific
diff --git a/gdb/symtab.c b/gdb/symtab.c
index b765a583c42..932b744fa8c 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2738,7 +2738,7 @@ symbol_matches_domain (enum language symbol_language,
 struct type *
 lookup_transparent_type (const char *name)
 {
-  return current_language->la_lookup_transparent_type (name);
+  return current_language->lookup_transparent_type (name);
 }
 
 /* A helper for basic_lookup_transparent_type that interfaces with the
-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 7/9] gdb: Convert language la_iterate_over_symbols field to a method
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (5 preceding siblings ...)
  2020-05-11 22:35 ` [PATCH 6/9] gdb: Convert language la_lookup_transparent_type " Andrew Burgess
@ 2020-05-11 22:35 ` Andrew Burgess
  2020-05-12 23:21   ` Christian Biesinger
  2020-05-11 22:35 ` [PATCH 8/9] gdb: Convert language la_get_compile_instance " Andrew Burgess
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_iterate_over_symbols
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_add_all_symbols): Update comment.
	(ada_iterate_over_symbols): Delete, move implementation to...
	(ada_language::iterate_over_symbols): ...here, a new member
	function.
	(ada_language_data): Delete la_iterate_over_symbols initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_iterate_over_symbols field.
	(language_defn::iterate_over_symbols): New member function.
	(LA_ITERATE_OVER_SYMBOLS): Update.
	* linespec.c (iterate_over_all_matching_symtabs): Update.
	* m2-lang.c (m2_language_data): Delete la_iterate_over_symbols
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog     | 27 +++++++++++++++++++++++++++
 gdb/ada-lang.c    | 46 ++++++++++++++++++++++------------------------
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 gdb/language.h    | 41 ++++++++++++++++++++++-------------------
 gdb/linespec.c    |  2 +-
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 14 files changed, 72 insertions(+), 58 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index df9c6ab72cc..21be804603e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5689,7 +5689,7 @@ ada_add_all_symbols (struct obstack *obstackp,
       else
 	{
 	  /* In the !full_search case we're are being called by
-	     ada_iterate_over_symbols, and we don't want to search
+	     iterate_over_symbols, and we don't want to search
 	     superblocks.  */
 	  ada_add_block_symbols (obstackp, block, lookup_name, domain, NULL);
 	}
@@ -5790,28 +5790,6 @@ ada_lookup_symbol_list (const char *name, const struct block *block,
   return ada_lookup_symbol_list_worker (lookup_name, block, domain, results, 1);
 }
 
-/* Implementation of the la_iterate_over_symbols method.  */
-
-static bool
-ada_iterate_over_symbols
-  (const struct block *block, const lookup_name_info &name,
-   domain_enum domain,
-   gdb::function_view<symbol_found_callback_ftype> callback)
-{
-  int ndefs, i;
-  std::vector<struct block_symbol> results;
-
-  ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
-
-  for (i = 0; i < ndefs; ++i)
-    {
-      if (!callback (&results[i]))
-	return false;
-    }
-
-  return true;
-}
-
 /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
    to 1, but choosing the first symbol found if there are multiple
    choices.
@@ -14010,7 +13988,6 @@ extern const struct language_data ada_language_data =
   ada_collect_symbol_completion_matches,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
-  ada_iterate_over_symbols,
   default_search_name_hash,
   &ada_varobj_ops,
   NULL,
@@ -14122,6 +14099,27 @@ class ada_language : public language_defn
     lai->bool_type_symbol = NULL;
     lai->bool_type_default = builtin->builtin_bool;
   }
+
+  /* See language.h.  */
+
+  bool iterate_over_symbols
+	(const struct block *block, const lookup_name_info &name,
+	 domain_enum domain,
+	 gdb::function_view<symbol_found_callback_ftype> callback) const override
+  {
+    int ndefs, i;
+    std::vector<struct block_symbol> results;
+
+    ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
+
+    for (i = 0; i < ndefs; ++i)
+      {
+	if (!callback (&results[i]))
+	  return false;
+      }
+
+    return true;
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 9de546847c3..a3f8d363356 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -922,7 +922,6 @@ extern const struct language_data c_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &c_varobj_ops,
   c_get_compile_context,
@@ -1022,7 +1021,6 @@ extern const struct language_data cplus_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
-  iterate_over_symbols,
   cp_search_name_hash,
   &cplus_varobj_ops,
   cplus_get_compile_context,
@@ -1164,7 +1162,6 @@ extern const struct language_data asm_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
@@ -1235,7 +1232,6 @@ extern const struct language_data minimal_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 8c4ee44ac97..57327780214 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -176,7 +176,6 @@ extern const struct language_data d_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 70903d4a56d..67fd56a5d6f 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -633,7 +633,6 @@ extern const struct language_data f_language_data =
   f_collect_symbol_completion_matches,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   cp_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 8036338415d..8ade4312592 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -561,7 +561,6 @@ extern const struct language_data go_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/language.c b/gdb/language.c
index 4e1cb4d657e..8493e611d96 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -862,7 +862,6 @@ extern const struct language_data unknown_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
@@ -929,7 +928,6 @@ extern const struct language_data auto_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/language.h b/gdb/language.h
index dfd63fcac25..80515a99924 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -384,24 +384,6 @@ struct language_data
     symbol_name_matcher_ftype *(*la_get_symbol_name_matcher)
       (const lookup_name_info &);
 
-    /* Find all symbols in the current program space matching NAME in
-       DOMAIN, according to this language's rules.
-
-       The search is done in BLOCK only.
-       The caller is responsible for iterating up through superblocks
-       if desired.
-
-       For each one, call CALLBACK with the symbol.  If CALLBACK
-       returns false, the iteration ends at that point.
-
-       This field may not be NULL.  If the language does not need any
-       special processing here, 'iterate_over_symbols' should be
-       used as the definition.  */
-    bool (*la_iterate_over_symbols)
-      (const struct block *block, const lookup_name_info &name,
-       domain_enum domain,
-       gdb::function_view<symbol_found_callback_ftype> callback);
-
     /* Hash the given symbol search name.  Use
        default_search_name_hash if no special treatment is
        required.  */
@@ -504,6 +486,27 @@ struct language_defn : language_data
     return basic_lookup_transparent_type (name);
   }
 
+  /* Find all symbols in the current program space matching NAME in
+     DOMAIN, according to this language's rules.
+
+     The search is done in BLOCK only.
+     The caller is responsible for iterating up through superblocks
+     if desired.
+
+     For each one, call CALLBACK with the symbol.  If CALLBACK
+     returns false, the iteration ends at that point.
+
+     This field may not be NULL.  If the language does not need any
+     special processing here, 'iterate_over_symbols' should be
+     used as the definition.  */
+  virtual bool iterate_over_symbols
+	(const struct block *block, const lookup_name_info &name,
+	 domain_enum domain,
+	 gdb::function_view<symbol_found_callback_ftype> callback) const
+  {
+    return ::iterate_over_symbols (block, name, domain, callback);
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
@@ -612,7 +615,7 @@ extern enum language set_language (enum language);
   (current_language->print_array_index(index_value, stream, options))
 
 #define LA_ITERATE_OVER_SYMBOLS(BLOCK, NAME, DOMAIN, CALLBACK) \
-  (current_language->la_iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK))
+  (current_language->iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK))
 
 /* Test a character to decide whether it can be printed in literal form
    or needs to be printed in another representation.  For example,
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 1f289873f5e..aac4a88ef5e 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1168,7 +1168,7 @@ iterate_over_all_matching_symtabs
 		       i++)
 		    {
 		      block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), i);
-		      state->language->la_iterate_over_symbols
+		      state->language->iterate_over_symbols
 			(block, lookup_name, name_domain,
 			 [&] (block_symbol *bsym)
 			 {
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 8b994a79557..d3596420622 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -386,7 +386,6 @@ extern const struct language_data m2_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 05a18311a58..c72ced5e7e5 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -401,7 +401,6 @@ extern const struct language_data objc_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 6b98f1159c6..dbfacd70716 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1061,7 +1061,6 @@ extern const struct language_data opencl_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 08b7f0464a0..8488b5d4520 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -416,7 +416,6 @@ extern const struct language_data pascal_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 8baa7b2d357..148a5cf187e 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2093,7 +2093,6 @@ extern const struct language_data rust_language_data =
   default_collect_symbol_completion_matches,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 8/9] gdb: Convert language la_get_compile_instance field to a method
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (6 preceding siblings ...)
  2020-05-11 22:35 ` [PATCH 7/9] gdb: Convert language la_iterate_over_symbols " Andrew Burgess
@ 2020-05-11 22:35 ` Andrew Burgess
  2020-05-12 21:11   ` Christian Biesinger
  2020-05-11 22:35 ` [PATCH 9/9] gdb: Convert language la_search_name_hash " Andrew Burgess
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_get_compile_instance
function pointer member variable into a member function of
language_defn.  Unlike previous commits converting fields of
language_data to member function in language_defn, this field is NULL
for some languages.  As a result I had to change the API slightly so
that the base language_defn class provides an implementation.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_get_compile_instance
	initializer.
	* c-lang.c (class compile_instance): Declare.
	(c_language_data): Delete la_get_compile_instance initializer.
	(c_language::get_compile_instance): New member function.
	(cplus_language_data): Delete la_get_compile_instance initializer.
	(cplus_language::get_compile_instance): New member function.
	(asm_language_data): Delete la_get_compile_instance initializer.
	(minimal_language_data): Likewise.
	* c-lang.h (c_get_compile_context): Update comment.
	(cplus_get_compile_context): Update comment.
	* compile/compile.c (compile_to_object): Update calls, don't rely
	on function pointer being NULL.
	* d-lang.c (d_language_data): Delete la_get_compile_instance
	initializer.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_get_compile_instance field.
	(language_defn::get_compile_instance): New member function.
	* m2-lang.c (m2_language_data): Delete la_get_compile_instance
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog         | 30 ++++++++++++++++++++++++++++++
 gdb/ada-lang.c        |  1 -
 gdb/c-lang.c          | 18 ++++++++++++++----
 gdb/c-lang.h          |  4 ++--
 gdb/compile/compile.c |  8 +++-----
 gdb/d-lang.c          |  1 -
 gdb/f-lang.c          |  1 -
 gdb/go-lang.c         |  1 -
 gdb/language.c        |  2 --
 gdb/language.h        | 23 +++++++++++++----------
 gdb/m2-lang.c         |  1 -
 gdb/objc-lang.c       |  1 -
 gdb/opencl-lang.c     |  1 -
 gdb/p-lang.c          |  1 -
 gdb/rust-lang.c       |  1 -
 15 files changed, 62 insertions(+), 32 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 21be804603e..73f3f52b2e4 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13991,7 +13991,6 @@ extern const struct language_data ada_language_data =
   default_search_name_hash,
   &ada_varobj_ops,
   NULL,
-  NULL,
   ada_is_string_type,
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index a3f8d363356..30adb86581e 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -37,6 +37,8 @@
 #include "gdbcore.h"
 #include "gdbarch.h"
 
+class compile_instance;
+
 /* Given a C string type, STR_TYPE, return the corresponding target
    character set name.  */
 
@@ -924,7 +926,6 @@ extern const struct language_data c_language_data =
   NULL,				/* la_get_symbol_name_matcher */
   default_search_name_hash,
   &c_varobj_ops,
-  c_get_compile_context,
   c_compute_program,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
@@ -945,6 +946,12 @@ class c_language : public language_defn
   {
     c_language_arch_info (gdbarch, lai);
   }
+
+  /* See language.h.  */
+  compile_instance *get_compile_instance (void) const override
+  {
+    return c_get_compile_context ();
+  }
 };
 
 /* Single instance of the C language class.  */
@@ -1023,7 +1030,6 @@ extern const struct language_data cplus_language_data =
   cp_get_symbol_name_matcher,
   cp_search_name_hash,
   &cplus_varobj_ops,
-  cplus_get_compile_context,
   cplus_compute_program,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
@@ -1114,6 +1120,12 @@ class cplus_language : public language_defn
   {
     return cp_lookup_transparent_type (name);
   }
+
+  /* See language.h.  */
+  compile_instance *get_compile_instance (void) const override
+  {
+    return cplus_get_compile_context ();
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1165,7 +1177,6 @@ extern const struct language_data asm_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
@@ -1235,7 +1246,6 @@ extern const struct language_data minimal_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/c-lang.h b/gdb/c-lang.h
index 642157125a8..3e07dc9c88d 100644
--- a/gdb/c-lang.h
+++ b/gdb/c-lang.h
@@ -157,7 +157,7 @@ extern int c_textual_element_type (struct type *, char);
    compiler is owned by the caller and must be freed using the destroy
    method.  This function never returns NULL, but rather throws an
    exception on failure.  This is suitable for use as the
-   la_get_compile_instance language method.  */
+   language_defn::get_compile_instance method.  */
 
 extern compile_instance *c_get_compile_context (void);
 
@@ -165,7 +165,7 @@ extern compile_instance *c_get_compile_context (void);
    compiler is owned by the caller and must be freed using the destroy
    method.  This function never returns NULL, but rather throws an
    exception on failure.  This is suitable for use as the
-   la_get_compile_instance language method.  */
+   language_defn::get_compile_instance method.  */
 
 extern compile_instance *cplus_get_compile_context ();
 
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 8d134d9cf18..3a3afa85736 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -691,13 +691,11 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
   expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
 
   /* Set up instance and context for the compiler.  */
-  if (current_language->la_get_compile_instance == NULL)
+  std::unique_ptr <compile_instance> compiler
+			(current_language->get_compile_instance ());
+  if (compiler == nullptr)
     error (_("No compiler support for language %s."),
 	   current_language->la_name);
-
-  compile_instance *compiler_instance
-    = current_language->la_get_compile_instance ();
-  std::unique_ptr<compile_instance> compiler (compiler_instance);
   compiler->set_print_callback (print_callback, NULL);
   compiler->set_scope (scope);
   compiler->set_block (expr_block);
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 57327780214..08b884de733 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -179,7 +179,6 @@ extern const struct language_data d_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 67fd56a5d6f..b80adec8eb0 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -636,7 +636,6 @@ extern const struct language_data f_language_data =
   cp_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   f_is_string_type_p,
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 8ade4312592..6c0633ccebc 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -564,7 +564,6 @@ extern const struct language_data go_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   go_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/language.c b/gdb/language.c
index 8493e611d96..2a0ef94be30 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -865,7 +865,6 @@ extern const struct language_data unknown_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   default_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
@@ -931,7 +930,6 @@ extern const struct language_data auto_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   default_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/language.h b/gdb/language.h
index 80515a99924..44cb1683e6c 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -392,16 +392,6 @@ struct language_data
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
 
-    /* If this language allows compilation from the gdb command line,
-       this method should be non-NULL.  When called it should return
-       an instance of struct gcc_context appropriate to the language.
-       When defined this method must never return NULL; instead it
-       should throw an exception on failure.  The returned compiler
-       instance is owned by its caller and must be deallocated by
-       calling its 'destroy' method.  */
-
-    compile_instance *(*la_get_compile_instance) (void);
-
     /* This method must be defined if 'la_get_gcc_context' is defined.
        If 'la_get_gcc_context' is not defined, then this method is
        ignored.
@@ -507,6 +497,19 @@ struct language_defn : language_data
     return ::iterate_over_symbols (block, name, domain, callback);
   }
 
+  /* If this language allows compilation from the gdb command line, then
+     this method will return an instance of struct gcc_context appropriate
+     to the language.  If compilation for this language is generally
+     supported, but something goes wrong then an exception is thrown.  The
+     returned compiler instance is owned by its caller and must be
+     deallocated by the caller.  If compilation is not supported for this
+     language then this method returns NULL.  */
+
+  virtual compile_instance *get_compile_instance (void) const
+  {
+    return nullptr;
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index d3596420622..5f198c659e9 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -389,7 +389,6 @@ extern const struct language_data m2_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   m2_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index c72ced5e7e5..abd905127e2 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -404,7 +404,6 @@ extern const struct language_data objc_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index dbfacd70716..6af521778dd 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1064,7 +1064,6 @@ extern const struct language_data opencl_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 8488b5d4520..0b46bc9f980 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -419,7 +419,6 @@ extern const struct language_data pascal_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   pascal_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 148a5cf187e..856fa210a25 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2096,7 +2096,6 @@ extern const struct language_data rust_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   rust_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 9/9] gdb: Convert language la_search_name_hash field to a method
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (7 preceding siblings ...)
  2020-05-11 22:35 ` [PATCH 8/9] gdb: Convert language la_get_compile_instance " Andrew Burgess
@ 2020-05-11 22:35 ` Andrew Burgess
  2020-05-12 21:10   ` Christian Biesinger
  2020-05-12 23:17 ` [PATCH 0/9] Starting to convert languages to separate classes Christian Biesinger
                   ` (3 subsequent siblings)
  12 siblings, 1 reply; 37+ messages in thread
From: Andrew Burgess @ 2020-05-11 22:35 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_search_name_hash
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_search_name_hash
	initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(cplus_language::search_name_hash): New member function.
	(asm_language_data): Delete la_search_name_hash initializer.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	(f_language::search_name_hash): New member function.
	* go-lang.c (go_language_data): Delete la_search_name_hash
	initializer.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (default_search_name_hash): Move declaration of
	function to here from later in the file.
	(struct language_data): Delete la_search_name_hash field.
	(language_defn::search_name_hash): New member function.
	* m2-lang.c (m2_language_data): Delete la_search_name_hash
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	* symtab.c (search_name_hash): Update call.
---
 gdb/ChangeLog     | 28 ++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      | 10 ++++++----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  7 ++++++-
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 gdb/language.h    | 27 ++++++++++++++-------------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 gdb/symtab.c      |  2 +-
 14 files changed, 55 insertions(+), 29 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 73f3f52b2e4..e9d9a402a95 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13988,7 +13988,6 @@ extern const struct language_data ada_language_data =
   ada_collect_symbol_completion_matches,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &ada_varobj_ops,
   NULL,
   ada_is_string_type,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 30adb86581e..757b68d4cce 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -924,7 +924,6 @@ extern const struct language_data c_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &c_varobj_ops,
   c_compute_program,
   c_is_string_type_p,
@@ -1028,7 +1027,6 @@ extern const struct language_data cplus_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
-  cp_search_name_hash,
   &cplus_varobj_ops,
   cplus_compute_program,
   c_is_string_type_p,
@@ -1126,6 +1124,12 @@ class cplus_language : public language_defn
   {
     return cplus_get_compile_context ();
   }
+
+  /* See language.h.  */
+  unsigned int search_name_hash (const char *name) const override
+  {
+    return cp_search_name_hash (name);
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1174,7 +1178,6 @@ extern const struct language_data asm_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
@@ -1243,7 +1246,6 @@ extern const struct language_data minimal_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 08b884de733..c6ee6a231e6 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -176,7 +176,6 @@ extern const struct language_data d_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index b80adec8eb0..a28bb8c0c96 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -633,7 +633,6 @@ extern const struct language_data f_language_data =
   f_collect_symbol_completion_matches,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
-  cp_search_name_hash,
   &default_varobj_ops,
   NULL,
   f_is_string_type_p,
@@ -686,6 +685,12 @@ class f_language : public language_defn
     lai->bool_type_symbol = "logical";
     lai->bool_type_default = builtin->builtin_logical_s2;
   }
+
+  /* See language.h.  */
+  unsigned int search_name_hash (const char *name) const override
+  {
+    return cp_search_name_hash (name);
+  }
 };
 
 /* Single instance of the Fortran language class.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 6c0633ccebc..5b6e2f04425 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -561,7 +561,6 @@ extern const struct language_data go_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   go_is_string_type_p,
diff --git a/gdb/language.c b/gdb/language.c
index 2a0ef94be30..99f211e36c1 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -862,7 +862,6 @@ extern const struct language_data unknown_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   default_is_string_type_p,
@@ -927,7 +926,6 @@ extern const struct language_data auto_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   default_is_string_type_p,
diff --git a/gdb/language.h b/gdb/language.h
index 44cb1683e6c..053b5c944ac 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -169,6 +169,14 @@ struct language_pass_by_ref_info
   bool destructible = true;
 };
 
+/* Default name hashing function.
+
+   Produce an unsigned hash value from SEARCH_NAME that is consistent
+   with strcmp_iw, strcmp, and, at least on Ada symbols, wild_match.
+   That is, two identifiers equivalent according to any of those three
+   comparison operators hash to the same value.  */
+extern unsigned int default_search_name_hash (const char *search_name);
+
 /* Structure tying together assorted information about a language.
 
    As we move over from the old structure based languages to a class
@@ -384,11 +392,6 @@ struct language_data
     symbol_name_matcher_ftype *(*la_get_symbol_name_matcher)
       (const lookup_name_info &);
 
-    /* Hash the given symbol search name.  Use
-       default_search_name_hash if no special treatment is
-       required.  */
-    unsigned int (*la_search_name_hash) (const char *name);
-
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
 
@@ -510,6 +513,12 @@ struct language_defn : language_data
     return nullptr;
   }
 
+  /* Hash the given symbol search name.  */
+  virtual unsigned int search_name_hash (const char *name) const
+  {
+    return default_search_name_hash (name);
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
@@ -690,14 +699,6 @@ struct language_pass_by_ref_info default_pass_by_reference (struct type *type);
 void default_print_typedef (struct type *type, struct symbol *new_symbol,
 			    struct ui_file *stream);
 
-/* Default name hashing function.  */
-
-/* Produce an unsigned hash value from SEARCH_NAME that is consistent
-   with strcmp_iw, strcmp, and, at least on Ada symbols, wild_match.
-   That is, two identifiers equivalent according to any of those three
-   comparison operators hash to the same value.  */
-extern unsigned int default_search_name_hash (const char *search_name);
-
 void c_get_string (struct value *value,
 		   gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
 		   int *length, struct type **char_type,
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 5f198c659e9..b5b11c715f3 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -386,7 +386,6 @@ extern const struct language_data m2_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   m2_is_string_type_p,
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index abd905127e2..4fc670e1291 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -401,7 +401,6 @@ extern const struct language_data objc_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 6af521778dd..fca685e1ead 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1061,7 +1061,6 @@ extern const struct language_data opencl_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 0b46bc9f980..c022390bb26 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -416,7 +416,6 @@ extern const struct language_data pascal_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   pascal_is_string_type_p,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 856fa210a25..5c13fe4487f 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2093,7 +2093,6 @@ extern const struct language_data rust_language_data =
   default_collect_symbol_completion_matches,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   rust_is_string_type_p,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 932b744fa8c..6a8f7d3e3dd 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1855,7 +1855,7 @@ demangle_for_lookup (const char *name, enum language lang,
 unsigned int
 search_name_hash (enum language language, const char *search_name)
 {
-  return language_def (language)->la_search_name_hash (search_name);
+  return language_def (language)->search_name_hash (search_name);
 }
 
 /* See symtab.h.
-- 
2.25.3


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 9/9] gdb: Convert language la_search_name_hash field to a method
  2020-05-11 22:35 ` [PATCH 9/9] gdb: Convert language la_search_name_hash " Andrew Burgess
@ 2020-05-12 21:10   ` Christian Biesinger
  0 siblings, 0 replies; 37+ messages in thread
From: Christian Biesinger @ 2020-05-12 21:10 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On Mon, May 11, 2020 at 5:36 PM Andrew Burgess
<andrew.burgess@embecosm.com> wrote:
>
> This commit changes the language_data::la_search_name_hash
> function pointer member variable into a member function of
> language_defn.
>
> There should be no user visible changes after this commit.
>
> gdb/ChangeLog:
>
>         * ada-lang.c (ada_language_data): Delete la_search_name_hash
>         initializer.
>         * c-lang.c (c_language_data): Likewise.
>         (cplus_language_data): Likewise.
>         (cplus_language::search_name_hash): New member function.
>         (asm_language_data): Delete la_search_name_hash initializer.
>         (minimal_language_data): Likewise.
>         * d-lang.c (d_language_data): Likewise.
>         * f-lang.c (f_language_data): Likewise.
>         (f_language::search_name_hash): New member function.
>         * go-lang.c (go_language_data): Delete la_search_name_hash
>         initializer.
>         * language.c (unknown_language_data): Likewise.
>         (auto_language_data): Likewise.
>         * language.h (default_search_name_hash): Move declaration of
>         function to here from later in the file.
>         (struct language_data): Delete la_search_name_hash field.
>         (language_defn::search_name_hash): New member function.
>         * m2-lang.c (m2_language_data): Delete la_search_name_hash
>         initializer.
>         * objc-lang.c (objc_language_data): Likewise.
>         * opencl-lang.c (opencl_language_data): Likewise.
>         * p-lang.c (pascal_language_data): Likewise.
>         * rust-lang.c (rust_language_data): Likewise.
>         * symtab.c (search_name_hash): Update call.
> ---
>  gdb/ChangeLog     | 28 ++++++++++++++++++++++++++++
>  gdb/ada-lang.c    |  1 -
>  gdb/c-lang.c      | 10 ++++++----
>  gdb/d-lang.c      |  1 -
>  gdb/f-lang.c      |  7 ++++++-
>  gdb/go-lang.c     |  1 -
>  gdb/language.c    |  2 --
>  gdb/language.h    | 27 ++++++++++++++-------------
>  gdb/m2-lang.c     |  1 -
>  gdb/objc-lang.c   |  1 -
>  gdb/opencl-lang.c |  1 -
>  gdb/p-lang.c      |  1 -
>  gdb/rust-lang.c   |  1 -
>  gdb/symtab.c      |  2 +-
>  14 files changed, 55 insertions(+), 29 deletions(-)
>
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index 73f3f52b2e4..e9d9a402a95 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -13988,7 +13988,6 @@ extern const struct language_data ada_language_data =
>    ada_collect_symbol_completion_matches,
>    ada_watch_location_expression,
>    ada_get_symbol_name_matcher, /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &ada_varobj_ops,
>    NULL,
>    ada_is_string_type,
> diff --git a/gdb/c-lang.c b/gdb/c-lang.c
> index 30adb86581e..757b68d4cce 100644
> --- a/gdb/c-lang.c
> +++ b/gdb/c-lang.c
> @@ -924,7 +924,6 @@ extern const struct language_data c_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &c_varobj_ops,
>    c_compute_program,
>    c_is_string_type_p,
> @@ -1028,7 +1027,6 @@ extern const struct language_data cplus_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    cp_get_symbol_name_matcher,
> -  cp_search_name_hash,
>    &cplus_varobj_ops,
>    cplus_compute_program,
>    c_is_string_type_p,
> @@ -1126,6 +1124,12 @@ class cplus_language : public language_defn
>    {
>      return cplus_get_compile_context ();
>    }
> +
> +  /* See language.h.  */
> +  unsigned int search_name_hash (const char *name) const override
> +  {
> +    return cp_search_name_hash (name);
> +  }
>  };
>
>  /* The single instance of the C++ language class.  */
> @@ -1174,7 +1178,6 @@ extern const struct language_data asm_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> @@ -1243,7 +1246,6 @@ extern const struct language_data minimal_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> diff --git a/gdb/d-lang.c b/gdb/d-lang.c
> index 08b884de733..c6ee6a231e6 100644
> --- a/gdb/d-lang.c
> +++ b/gdb/d-lang.c
> @@ -176,7 +176,6 @@ extern const struct language_data d_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> diff --git a/gdb/f-lang.c b/gdb/f-lang.c
> index b80adec8eb0..a28bb8c0c96 100644
> --- a/gdb/f-lang.c
> +++ b/gdb/f-lang.c
> @@ -633,7 +633,6 @@ extern const struct language_data f_language_data =
>    f_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    cp_get_symbol_name_matcher,  /* la_get_symbol_name_matcher */
> -  cp_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    f_is_string_type_p,
> @@ -686,6 +685,12 @@ class f_language : public language_defn
>      lai->bool_type_symbol = "logical";
>      lai->bool_type_default = builtin->builtin_logical_s2;
>    }
> +
> +  /* See language.h.  */
> +  unsigned int search_name_hash (const char *name) const override
> +  {
> +    return cp_search_name_hash (name);
> +  }
>  };
>
>  /* Single instance of the Fortran language class.  */
> diff --git a/gdb/go-lang.c b/gdb/go-lang.c
> index 6c0633ccebc..5b6e2f04425 100644
> --- a/gdb/go-lang.c
> +++ b/gdb/go-lang.c
> @@ -561,7 +561,6 @@ extern const struct language_data go_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    go_is_string_type_p,
> diff --git a/gdb/language.c b/gdb/language.c
> index 2a0ef94be30..99f211e36c1 100644
> --- a/gdb/language.c
> +++ b/gdb/language.c
> @@ -862,7 +862,6 @@ extern const struct language_data unknown_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    default_is_string_type_p,
> @@ -927,7 +926,6 @@ extern const struct language_data auto_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    default_is_string_type_p,
> diff --git a/gdb/language.h b/gdb/language.h
> index 44cb1683e6c..053b5c944ac 100644
> --- a/gdb/language.h
> +++ b/gdb/language.h
> @@ -169,6 +169,14 @@ struct language_pass_by_ref_info
>    bool destructible = true;
>  };
>
> +/* Default name hashing function.
> +
> +   Produce an unsigned hash value from SEARCH_NAME that is consistent
> +   with strcmp_iw, strcmp, and, at least on Ada symbols, wild_match.
> +   That is, two identifiers equivalent according to any of those three
> +   comparison operators hash to the same value.  */
> +extern unsigned int default_search_name_hash (const char *search_name);

I like this change in general! Question about this line... is this
function still needed elsewhere or could it just become part of the
default search_name_hash impl?

> +
>  /* Structure tying together assorted information about a language.
>
>     As we move over from the old structure based languages to a class
> @@ -384,11 +392,6 @@ struct language_data
>      symbol_name_matcher_ftype *(*la_get_symbol_name_matcher)
>        (const lookup_name_info &);
>
> -    /* Hash the given symbol search name.  Use
> -       default_search_name_hash if no special treatment is
> -       required.  */
> -    unsigned int (*la_search_name_hash) (const char *name);
> -
>      /* Various operations on varobj.  */
>      const struct lang_varobj_ops *la_varobj_ops;
>
> @@ -510,6 +513,12 @@ struct language_defn : language_data
>      return nullptr;
>    }
>
> +  /* Hash the given symbol search name.  */
> +  virtual unsigned int search_name_hash (const char *name) const
> +  {
> +    return default_search_name_hash (name);
> +  }
> +
>    /* List of all known languages.  */
>    static const struct language_defn *languages[nr_languages];
>  };
> @@ -690,14 +699,6 @@ struct language_pass_by_ref_info default_pass_by_reference (struct type *type);
>  void default_print_typedef (struct type *type, struct symbol *new_symbol,
>                             struct ui_file *stream);
>
> -/* Default name hashing function.  */
> -
> -/* Produce an unsigned hash value from SEARCH_NAME that is consistent
> -   with strcmp_iw, strcmp, and, at least on Ada symbols, wild_match.
> -   That is, two identifiers equivalent according to any of those three
> -   comparison operators hash to the same value.  */
> -extern unsigned int default_search_name_hash (const char *search_name);
> -
>  void c_get_string (struct value *value,
>                    gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
>                    int *length, struct type **char_type,
> diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
> index 5f198c659e9..b5b11c715f3 100644
> --- a/gdb/m2-lang.c
> +++ b/gdb/m2-lang.c
> @@ -386,7 +386,6 @@ extern const struct language_data m2_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    m2_is_string_type_p,
> diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
> index abd905127e2..4fc670e1291 100644
> --- a/gdb/objc-lang.c
> +++ b/gdb/objc-lang.c
> @@ -401,7 +401,6 @@ extern const struct language_data objc_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
> index 6af521778dd..fca685e1ead 100644
> --- a/gdb/opencl-lang.c
> +++ b/gdb/opencl-lang.c
> @@ -1061,7 +1061,6 @@ extern const struct language_data opencl_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> diff --git a/gdb/p-lang.c b/gdb/p-lang.c
> index 0b46bc9f980..c022390bb26 100644
> --- a/gdb/p-lang.c
> +++ b/gdb/p-lang.c
> @@ -416,7 +416,6 @@ extern const struct language_data pascal_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_compare_symbol_for_completion */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    pascal_is_string_type_p,
> diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
> index 856fa210a25..5c13fe4487f 100644
> --- a/gdb/rust-lang.c
> +++ b/gdb/rust-lang.c
> @@ -2093,7 +2093,6 @@ extern const struct language_data rust_language_data =
>    default_collect_symbol_completion_matches,
>    rust_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    rust_is_string_type_p,
> diff --git a/gdb/symtab.c b/gdb/symtab.c
> index 932b744fa8c..6a8f7d3e3dd 100644
> --- a/gdb/symtab.c
> +++ b/gdb/symtab.c
> @@ -1855,7 +1855,7 @@ demangle_for_lookup (const char *name, enum language lang,
>  unsigned int
>  search_name_hash (enum language language, const char *search_name)
>  {
> -  return language_def (language)->la_search_name_hash (search_name);
> +  return language_def (language)->search_name_hash (search_name);
>  }
>
>  /* See symtab.h.
> --
> 2.25.3
>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 8/9] gdb: Convert language la_get_compile_instance field to a method
  2020-05-11 22:35 ` [PATCH 8/9] gdb: Convert language la_get_compile_instance " Andrew Burgess
@ 2020-05-12 21:11   ` Christian Biesinger
  0 siblings, 0 replies; 37+ messages in thread
From: Christian Biesinger @ 2020-05-12 21:11 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On Mon, May 11, 2020 at 5:36 PM Andrew Burgess
<andrew.burgess@embecosm.com> wrote:
>
> This commit changes the language_data::la_get_compile_instance
> function pointer member variable into a member function of
> language_defn.  Unlike previous commits converting fields of
> language_data to member function in language_defn, this field is NULL
> for some languages.  As a result I had to change the API slightly so
> that the base language_defn class provides an implementation.
>
> There should be no user visible changes after this commit.
>
> gdb/ChangeLog:
>
>         * ada-lang.c (ada_language_data): Delete la_get_compile_instance
>         initializer.
>         * c-lang.c (class compile_instance): Declare.
>         (c_language_data): Delete la_get_compile_instance initializer.
>         (c_language::get_compile_instance): New member function.
>         (cplus_language_data): Delete la_get_compile_instance initializer.
>         (cplus_language::get_compile_instance): New member function.
>         (asm_language_data): Delete la_get_compile_instance initializer.
>         (minimal_language_data): Likewise.
>         * c-lang.h (c_get_compile_context): Update comment.
>         (cplus_get_compile_context): Update comment.
>         * compile/compile.c (compile_to_object): Update calls, don't rely
>         on function pointer being NULL.
>         * d-lang.c (d_language_data): Delete la_get_compile_instance
>         initializer.
>         * f-lang.c (f_language_data): Likewise.
>         * go-lang.c (go_language_data): Likewise.
>         * language.c (unknown_language_data): Likewise.
>         (auto_language_data): Likewise.
>         * language.h (language_data): Delete la_get_compile_instance field.
>         (language_defn::get_compile_instance): New member function.
>         * m2-lang.c (m2_language_data): Delete la_get_compile_instance
>         initializer.
>         * objc-lang.c (objc_language_data): Likewise.
>         * opencl-lang.c (opencl_language_data): Likewise.
>         * p-lang.c (pascal_language_data): Likewise.
>         * rust-lang.c (rust_language_data): Likewise.
> ---
>  gdb/ChangeLog         | 30 ++++++++++++++++++++++++++++++
>  gdb/ada-lang.c        |  1 -
>  gdb/c-lang.c          | 18 ++++++++++++++----
>  gdb/c-lang.h          |  4 ++--
>  gdb/compile/compile.c |  8 +++-----
>  gdb/d-lang.c          |  1 -
>  gdb/f-lang.c          |  1 -
>  gdb/go-lang.c         |  1 -
>  gdb/language.c        |  2 --
>  gdb/language.h        | 23 +++++++++++++----------
>  gdb/m2-lang.c         |  1 -
>  gdb/objc-lang.c       |  1 -
>  gdb/opencl-lang.c     |  1 -
>  gdb/p-lang.c          |  1 -
>  gdb/rust-lang.c       |  1 -
>  15 files changed, 62 insertions(+), 32 deletions(-)
>
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index 21be804603e..73f3f52b2e4 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -13991,7 +13991,6 @@ extern const struct language_data ada_language_data =
>    default_search_name_hash,
>    &ada_varobj_ops,
>    NULL,
> -  NULL,
>    ada_is_string_type,
>    "(...)"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/c-lang.c b/gdb/c-lang.c
> index a3f8d363356..30adb86581e 100644
> --- a/gdb/c-lang.c
> +++ b/gdb/c-lang.c
> @@ -37,6 +37,8 @@
>  #include "gdbcore.h"
>  #include "gdbarch.h"
>
> +class compile_instance;
> +
>  /* Given a C string type, STR_TYPE, return the corresponding target
>     character set name.  */
>
> @@ -924,7 +926,6 @@ extern const struct language_data c_language_data =
>    NULL,                                /* la_get_symbol_name_matcher */
>    default_search_name_hash,
>    &c_varobj_ops,
> -  c_get_compile_context,
>    c_compute_program,
>    c_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
> @@ -945,6 +946,12 @@ class c_language : public language_defn
>    {
>      c_language_arch_info (gdbarch, lai);
>    }
> +
> +  /* See language.h.  */
> +  compile_instance *get_compile_instance (void) const override

(void) isn't needed here and in the other implementations of this function.

> +  {
> +    return c_get_compile_context ();
> +  }
>  };
>
>  /* Single instance of the C language class.  */
> @@ -1023,7 +1030,6 @@ extern const struct language_data cplus_language_data =
>    cp_get_symbol_name_matcher,
>    cp_search_name_hash,
>    &cplus_varobj_ops,
> -  cplus_get_compile_context,
>    cplus_compute_program,
>    c_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
> @@ -1114,6 +1120,12 @@ class cplus_language : public language_defn
>    {
>      return cp_lookup_transparent_type (name);
>    }
> +
> +  /* See language.h.  */
> +  compile_instance *get_compile_instance (void) const override
> +  {
> +    return cplus_get_compile_context ();
> +  }
>  };
>
>  /* The single instance of the C++ language class.  */
> @@ -1165,7 +1177,6 @@ extern const struct language_data asm_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    c_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> @@ -1235,7 +1246,6 @@ extern const struct language_data minimal_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    c_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/c-lang.h b/gdb/c-lang.h
> index 642157125a8..3e07dc9c88d 100644
> --- a/gdb/c-lang.h
> +++ b/gdb/c-lang.h
> @@ -157,7 +157,7 @@ extern int c_textual_element_type (struct type *, char);
>     compiler is owned by the caller and must be freed using the destroy
>     method.  This function never returns NULL, but rather throws an
>     exception on failure.  This is suitable for use as the
> -   la_get_compile_instance language method.  */
> +   language_defn::get_compile_instance method.  */
>
>  extern compile_instance *c_get_compile_context (void);
>
> @@ -165,7 +165,7 @@ extern compile_instance *c_get_compile_context (void);
>     compiler is owned by the caller and must be freed using the destroy
>     method.  This function never returns NULL, but rather throws an
>     exception on failure.  This is suitable for use as the
> -   la_get_compile_instance language method.  */
> +   language_defn::get_compile_instance method.  */
>
>  extern compile_instance *cplus_get_compile_context ();
>
> diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
> index 8d134d9cf18..3a3afa85736 100644
> --- a/gdb/compile/compile.c
> +++ b/gdb/compile/compile.c
> @@ -691,13 +691,11 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
>    expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
>
>    /* Set up instance and context for the compiler.  */
> -  if (current_language->la_get_compile_instance == NULL)
> +  std::unique_ptr <compile_instance> compiler
> +                       (current_language->get_compile_instance ());
> +  if (compiler == nullptr)
>      error (_("No compiler support for language %s."),
>            current_language->la_name);
> -
> -  compile_instance *compiler_instance
> -    = current_language->la_get_compile_instance ();
> -  std::unique_ptr<compile_instance> compiler (compiler_instance);
>    compiler->set_print_callback (print_callback, NULL);
>    compiler->set_scope (scope);
>    compiler->set_block (expr_block);
> diff --git a/gdb/d-lang.c b/gdb/d-lang.c
> index 57327780214..08b884de733 100644
> --- a/gdb/d-lang.c
> +++ b/gdb/d-lang.c
> @@ -179,7 +179,6 @@ extern const struct language_data d_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    c_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/f-lang.c b/gdb/f-lang.c
> index 67fd56a5d6f..b80adec8eb0 100644
> --- a/gdb/f-lang.c
> +++ b/gdb/f-lang.c
> @@ -636,7 +636,6 @@ extern const struct language_data f_language_data =
>    cp_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    f_is_string_type_p,
>    "(...)"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/go-lang.c b/gdb/go-lang.c
> index 8ade4312592..6c0633ccebc 100644
> --- a/gdb/go-lang.c
> +++ b/gdb/go-lang.c
> @@ -564,7 +564,6 @@ extern const struct language_data go_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    go_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/language.c b/gdb/language.c
> index 8493e611d96..2a0ef94be30 100644
> --- a/gdb/language.c
> +++ b/gdb/language.c
> @@ -865,7 +865,6 @@ extern const struct language_data unknown_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    default_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> @@ -931,7 +930,6 @@ extern const struct language_data auto_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    default_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/language.h b/gdb/language.h
> index 80515a99924..44cb1683e6c 100644
> --- a/gdb/language.h
> +++ b/gdb/language.h
> @@ -392,16 +392,6 @@ struct language_data
>      /* Various operations on varobj.  */
>      const struct lang_varobj_ops *la_varobj_ops;
>
> -    /* If this language allows compilation from the gdb command line,
> -       this method should be non-NULL.  When called it should return
> -       an instance of struct gcc_context appropriate to the language.
> -       When defined this method must never return NULL; instead it
> -       should throw an exception on failure.  The returned compiler
> -       instance is owned by its caller and must be deallocated by
> -       calling its 'destroy' method.  */
> -
> -    compile_instance *(*la_get_compile_instance) (void);
> -
>      /* This method must be defined if 'la_get_gcc_context' is defined.
>         If 'la_get_gcc_context' is not defined, then this method is
>         ignored.
> @@ -507,6 +497,19 @@ struct language_defn : language_data
>      return ::iterate_over_symbols (block, name, domain, callback);
>    }
>
> +  /* If this language allows compilation from the gdb command line, then
> +     this method will return an instance of struct gcc_context appropriate
> +     to the language.  If compilation for this language is generally
> +     supported, but something goes wrong then an exception is thrown.  The
> +     returned compiler instance is owned by its caller and must be
> +     deallocated by the caller.  If compilation is not supported for this
> +     language then this method returns NULL.  */
> +
> +  virtual compile_instance *get_compile_instance (void) const
> +  {
> +    return nullptr;
> +  }
> +
>    /* List of all known languages.  */
>    static const struct language_defn *languages[nr_languages];
>  };
> diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
> index d3596420622..5f198c659e9 100644
> --- a/gdb/m2-lang.c
> +++ b/gdb/m2-lang.c
> @@ -389,7 +389,6 @@ extern const struct language_data m2_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    m2_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
> index c72ced5e7e5..abd905127e2 100644
> --- a/gdb/objc-lang.c
> +++ b/gdb/objc-lang.c
> @@ -404,7 +404,6 @@ extern const struct language_data objc_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    c_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
> index dbfacd70716..6af521778dd 100644
> --- a/gdb/opencl-lang.c
> +++ b/gdb/opencl-lang.c
> @@ -1064,7 +1064,6 @@ extern const struct language_data opencl_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    c_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/p-lang.c b/gdb/p-lang.c
> index 8488b5d4520..0b46bc9f980 100644
> --- a/gdb/p-lang.c
> +++ b/gdb/p-lang.c
> @@ -419,7 +419,6 @@ extern const struct language_data pascal_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    pascal_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
> index 148a5cf187e..856fa210a25 100644
> --- a/gdb/rust-lang.c
> +++ b/gdb/rust-lang.c
> @@ -2096,7 +2096,6 @@ extern const struct language_data rust_language_data =
>    default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
> -  NULL,
>    rust_is_string_type_p,
>    "{...}"                      /* la_struct_too_deep_ellipsis */
>  };
> --
> 2.25.3
>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 0/9] Starting to convert languages to separate classes
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (8 preceding siblings ...)
  2020-05-11 22:35 ` [PATCH 9/9] gdb: Convert language la_search_name_hash " Andrew Burgess
@ 2020-05-12 23:17 ` Christian Biesinger
  2020-05-13  1:33 ` Simon Marchi
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 37+ messages in thread
From: Christian Biesinger @ 2020-05-12 23:17 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On Mon, May 11, 2020 at 5:36 PM Andrew Burgess
<andrew.burgess@embecosm.com> wrote:
> Anyway, I'd be interested to hear peoples thoughts on the series so,
> and of this as a piece of work in general, is this a good change or
> not.

I think this kind of change is great. It makes the code easier to
understand because semantics match general C++ semantics, and
overriding functions is simpler (can just add a function inline and
not worry about assigning function pointers)

Christian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 7/9] gdb: Convert language la_iterate_over_symbols field to a method
  2020-05-11 22:35 ` [PATCH 7/9] gdb: Convert language la_iterate_over_symbols " Andrew Burgess
@ 2020-05-12 23:21   ` Christian Biesinger
  0 siblings, 0 replies; 37+ messages in thread
From: Christian Biesinger @ 2020-05-12 23:21 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On Mon, May 11, 2020 at 5:36 PM Andrew Burgess
<andrew.burgess@embecosm.com> wrote:
> @@ -14122,6 +14099,27 @@ class ada_language : public language_defn
>      lai->bool_type_symbol = NULL;
>      lai->bool_type_default = builtin->builtin_bool;
>    }
> +
> +  /* See language.h.  */
> +
> +  bool iterate_over_symbols
> +       (const struct block *block, const lookup_name_info &name,
> +        domain_enum domain,
> +        gdb::function_view<symbol_found_callback_ftype> callback) const override
> +  {
> +    int ndefs, i;
> +    std::vector<struct block_symbol> results;
> +
> +    ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
> +
> +    for (i = 0; i < ndefs; ++i)

While touching this function, I would move the declaration of ndefs
and i to the line where they are first used.

Perhaps also change this to a range-based loop.

Christian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 0/9] Starting to convert languages to separate classes
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (9 preceding siblings ...)
  2020-05-12 23:17 ` [PATCH 0/9] Starting to convert languages to separate classes Christian Biesinger
@ 2020-05-13  1:33 ` Simon Marchi
  2020-05-14 19:57 ` Tom Tromey
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
  12 siblings, 0 replies; 37+ messages in thread
From: Simon Marchi @ 2020-05-13  1:33 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2020-05-11 6:35 p.m., Andrew Burgess wrote:
> This series starts the process of converting GDB's language structures
> into separate classes, one for each supported language.
> 
> In the first commit I actually perform the conversion, but do so in a
> way that basically doesn't change anything.  All the data is held in
> the base class, and accessed just as it was before.
> 
> In the following commits I begin converting function pointer fields
> within the language base class into real member functions.
> 
> I haven't converted all of the function pointers yet, I want to see
> what feedback this series gets before I invest any more time.
> 
> Further into the future I think it's possible that we could tweak the
> class hierarchy of languages, I do wonder if there will be some
> obvious inheritance around the c_language maybe, but I figure I'll
> convert all of the function pointers to methods first, then see what
> everyone implements.
> 
> My hope is that be performing this conversion it will be easier for
> people to add new methods into the language classes, to allow easier
> language specific specialisation, hopefully we should be able to
> remove some of the places where we check the language enum, and
> instead replace this with a method on the language class.
> 
> Further into the future, I wonder if some things like expression
> parsing, and maybe some of the value manipulation/printing code would
> be better off as methods within the language classes.
> 
> Anyway, I'd be interested to hear peoples thoughts on the series so,
> and of this as a piece of work in general, is this a good change or
> not.
> 
> Thanks,
> Andrew

Hi Andrew,

I looked through it, I think that's very nice.

Ultimately, I don't think we need to keep language_data, data fields can
be transformed into methods that return a simple value.  But I am fine with
what you have, it allows for the work to be incremental.

Simon

^ permalink raw reply	[flat|nested] 37+ messages in thread

* RE: [PATCH 4/9] gdb: Convert language la_pass_by_reference field to a method
  2020-05-11 22:35 ` [PATCH 4/9] gdb: Convert language la_pass_by_reference " Andrew Burgess
@ 2020-05-14 11:00   ` Aktemur, Tankut Baris
  2020-05-14 19:49     ` Tom Tromey
  2020-05-14 19:48   ` Tom Tromey
  1 sibling, 1 reply; 37+ messages in thread
From: Aktemur, Tankut Baris @ 2020-05-14 11:00 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On Tuesday, May 12, 2020 12:36 AM, Andrew Burgess wrote:
> This commit changes the language_data::la_pass_by_reference function
> pointer member variable into a member function of language_defn.
> 
...
> +struct language_pass_by_ref_info
> +language_defn::pass_by_reference_info (struct type *type) const
> +{
> +  return default_pass_by_reference (type);
> +}

A further cleanup idea is to get rid of default_pass_by_reference and
inline its definition at the call sites.  default_pass_by_reference simply
returns {}.  Afaict, aside from the new call above, there are two calls:
1) in cp-abi.c, and 2) in gnu-v3-abi.c.

Regards.
-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 3/9] gdb: Convert language la_read_var_value field to a method
  2020-05-11 22:35 ` [PATCH 3/9] gdb: Convert language la_read_var_value " Andrew Burgess
@ 2020-05-14 19:43   ` Tom Tromey
  0 siblings, 0 replies; 37+ messages in thread
From: Tom Tromey @ 2020-05-14 19:43 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> +  /* Implement the "read_var_value" language_defn method for Ada.  */
Andrew> +
Andrew> +  struct value *read_var_value (struct symbol *var,
Andrew> +				const struct block *var_block,
Andrew> +				struct frame_info *frame) const override
Andrew> +  {
...
Andrew> +    /* This is a typical case where we expect the default_read_var_value
Andrew> +       function to work.  */
Andrew> +    return default_read_var_value (var, var_block, frame);

It seems like this could call language_defn::read_var_value, and then
default_read_var_value could just be renamed.

Tom

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 4/9] gdb: Convert language la_pass_by_reference field to a method
  2020-05-11 22:35 ` [PATCH 4/9] gdb: Convert language la_pass_by_reference " Andrew Burgess
  2020-05-14 11:00   ` Aktemur, Tankut Baris
@ 2020-05-14 19:48   ` Tom Tromey
  1 sibling, 0 replies; 37+ messages in thread
From: Tom Tromey @ 2020-05-14 19:48 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> This commit changes the language_data::la_pass_by_reference function
Andrew> pointer member variable into a member function of language_defn.

Andrew> There should be no user visible changes after this commit.

Andrew> +  struct language_pass_by_ref_info pass_by_reference_info
Andrew> +	(struct type *type) const override
Andrew> +  {
Andrew> +    return cp_pass_by_reference (type);

It seems like cp_pass_by_reference could just be renamed.

Not default_pass_by_reference, though, it's called from one other spot.

Tom

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 4/9] gdb: Convert language la_pass_by_reference field to a method
  2020-05-14 11:00   ` Aktemur, Tankut Baris
@ 2020-05-14 19:49     ` Tom Tromey
  0 siblings, 0 replies; 37+ messages in thread
From: Tom Tromey @ 2020-05-14 19:49 UTC (permalink / raw)
  To: Aktemur, Tankut Baris via Gdb-patches

>>>>> ">" == Aktemur, Tankut Baris via Gdb-patches <gdb-patches@sourceware.org> writes:

>> A further cleanup idea is to get rid of default_pass_by_reference and
>> inline its definition at the call sites.  default_pass_by_reference simply
>> returns {}.  Afaict, aside from the new call above, there are two calls:
>> 1) in cp-abi.c, and 2) in gnu-v3-abi.c.

Good catch.

Tom

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 0/9] Starting to convert languages to separate classes
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (10 preceding siblings ...)
  2020-05-13  1:33 ` Simon Marchi
@ 2020-05-14 19:57 ` Tom Tromey
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
  12 siblings, 0 replies; 37+ messages in thread
From: Tom Tromey @ 2020-05-14 19:57 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> I haven't converted all of the function pointers yet, I want to see
Andrew> what feedback this series gets before I invest any more time.

I think it's a good direction.

Andrew> Further into the future, I wonder if some things like expression
Andrew> parsing, and maybe some of the value manipulation/printing code would
Andrew> be better off as methods within the language classes.

I think so; though ideally I'd like even more of the value printing to
be shared, following something like generic_value_print and
generic_val_print_decorations.

Tom

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 00/13] Starting to convert languages to separate classes
  2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
                   ` (11 preceding siblings ...)
  2020-05-14 19:57 ` Tom Tromey
@ 2020-05-15 15:06 ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 01/13] gdb: Represent all languages as sub-classes of language_defn Andrew Burgess
                     ` (14 more replies)
  12 siblings, 15 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

Thank you for all the feedback.

Differences from v1:

  - Addresses all of the improvements suggested in v1.

  - Added 4 additional field conversions.

Thanks,
Andrew



---

Andrew Burgess (13):
  gdb: Represent all languages as sub-classes of language_defn
  gdb: Convert language la_print_array_index field to a method
  gdb: Convert language la_read_var_value field to a method
  gdb: Convert language la_pass_by_reference field to a method
  gdb: Convert language la_language_arch_info field to a method
  gdb: Convert language la_lookup_transparent_type field to a method
  gdb: Convert language la_iterate_over_symbols field to a method
  gdb: Convert language la_get_compile_instance field to a method
  gdb: Convert language la_search_name_hash field to a method
  gdb: Convert language la_sniff_from_mangled_name field to a method
  gdb: Convert language la_print_type field to a method
  gdb: Convert language la_demangle field to a method
  gdb: Convert language skip_trampoline field to a method

 gdb/ChangeLog         | 531 ++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c        | 359 ++++++++++++++--------------
 gdb/c-lang.c          | 358 +++++++++++++++++++---------
 gdb/c-lang.h          |   4 +-
 gdb/compile/compile.c |   8 +-
 gdb/cp-abi.c          |   2 +-
 gdb/cp-support.c      |   9 -
 gdb/cp-support.h      |   4 -
 gdb/d-lang.c          | 194 ++++++++-------
 gdb/dictionary.c      |   2 +-
 gdb/f-lang.c          | 139 ++++++-----
 gdb/findvar.c         |  13 +-
 gdb/gnu-v3-abi.c      |   3 +-
 gdb/go-lang.c         | 167 +++++++------
 gdb/language.c        | 253 ++++++++++----------
 gdb/language.h        | 300 ++++++++++++------------
 gdb/linespec.c        |   2 +-
 gdb/m2-lang.c         |  91 ++++----
 gdb/objc-lang.c       | 136 ++++++-----
 gdb/opencl-lang.c     | 104 +++++----
 gdb/p-lang.c          | 137 ++++++-----
 gdb/rust-exp.y        |   4 +-
 gdb/rust-lang.c       | 163 ++++++-------
 gdb/symtab.c          |   8 +-
 gdb/value.h           |   4 -
 25 files changed, 1887 insertions(+), 1108 deletions(-)

-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 01/13] gdb: Represent all languages as sub-classes of language_defn
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 02/13] gdb: Convert language la_print_array_index field to a method Andrew Burgess
                     ` (13 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit converts all languages to sub-classes of a language_defn
base class.

The motivation for this change is to make it easier to add new methods
onto languages without having to update all of the individual language
structures.  In the future it might be possible to move more things,
like expression parsing, into the language class(es) for better
encapsulation, however I have no plans to tackle this in the short
term.

This commit sets up a strategy for transitioning from the current
language system, where each language is an instance of the
language_defn structure, to the class hierarchy system.

The plan is to rename the existing language_defn into language_data,
and make this a base class for the new language_defn class, something
like this:

  struct language_data
  {
    ... old language_defn fields here ...
  };

  struct language_defn : public language_data
  {
    language_defn (const language_data d)
      : language_data (d)
    { .... }
  };

Then each existing language, for example ada_language_defn can be
converted into an instance of language_data, and passed into the
constructor of a new language class, something like this:

  language_data ada_language_data =
  {
    ... old ada_language_defn values here ...
  };

  struct ada_language : public language_defn
  {
    ada_language (ada_language_data)
    { .... }
  };

What this means is that immediately after the conversion nothing much
changes.  Every language is now its own class, but all the old
language fields still exist and can be accessed in the same way.

In later commits I will convert function pointers from the old
language_defn structure into real class methods on language_defn, with
overrides on sub-classes where needed.

At this point I imagine that those fields of the old language_defn
structure that contained only data will probably remain as data fields
within the new language_data base structure, it is only the methods
that I plan to change initially.

I tweaked how we manage the list of languages a bit, each language is
now registered as it is created, and this resulted in a small number
of changes in language.c.

Most of the changes in the *-lang.c files are identical.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* gdb/ada-lang.c (ada_language_defn): Convert to...
	(ada_language_data): ...this.
	(class ada_language): New class.
	(ada_language_defn): New static global.
	* gdb/c-lang.c (c_language_defn): Convert to...
	(c_language_data): ...this.
	(class c_language): New class.
	(c_language_defn): New static global.
	(cplus_language_defn): Convert to...
	(cplus_language_data): ...this.
	(class cplus_language): New class.
	(cplus_language_defn): New static global.
	(asm_language_defn): Convert to...
	(asm_language_data): ...this.
	(class asm_language): New class.
	(asm_language_defn): New static global.
	(minimal_language_defn): Convert to...
	(minimal_language_data): ...this.
	(class minimal_language): New class.
	(minimal_language_defn): New static global.
	* gdb/d-lang.c (d_language_defn): Convert to...
	(d_language_data): ...this.
	(class d_language): New class.
	(d_language_defn): New static global.
	* gdb/f-lang.c (f_language_defn): Convert to...
	(f_language_data): ...this.
	(class f_language): New class.
	(f_language_defn): New static global.
	* gdb/go-lang.c (go_language_defn): Convert to...
	(go_language_data): ...this.
	(class go_language): New class.
	(go_language_defn): New static global.
	* gdb/language.c (unknown_language_defn): Remove declaration.
	(current_language): Initialize to nullptr, real initialization is
	moved to _initialize_language.
	(languages): Delete global.
	(language_defn::languages): Define.
	(set_language_command): Use language_defn::languages.
	(set_language): Likewise.
	(range_error): Likewise.
	(language_enum): Likewise.
	(language_def): Likewise.
	(add_set_language_command): Use language_def::languages for the
	language list, and language_def to lookup language pointers.
	(skip_language_trampoline): Use language_defn::languages.
	(unknown_language_defn): Convert to...
	(unknown_language_data): ...this.
	(class unknown_language): New class.
	(unknown_language_defn): New static global.
	(auto_language_defn): Convert to...
	(auto_language_data): ...this.
	(class auto_language): New class.
	(auto_language_defn): New static global.
	(language_gdbarch_post_init): Use language_defn::languages.
	(_initialize_language): Initialize current_language.
	* gdb/language.h (struct language_defn): Rename to...
	(struct language_data): ...this.
	(struct language_defn): New.
	(auto_language_defn): Delete.
	(unknown_language_defn): Delete.
	(minimal_language_defn): Delete.
	(ada_language_defn): Delete.
	(asm_language_defn): Delete.
	(c_language_defn): Delete.
	(cplus_language_defn): Delete.
	(d_language_defn): Delete.
	(f_language_defn): Delete.
	(go_language_defn): Delete.
	(m2_language_defn): Delete.
	(objc_language_defn): Delete.
	(opencl_language_defn): Delete.
	(pascal_language_defn): Delete.
	(rust_language_defn): Delete.
	* gdb/m2-lang.c (m2_language_defn): Convert to...
	(m2_language_data): ...this.
	(class m2_language): New class.
	(m2_language_defn): New static global.
	* gdb/objc-lang.c (objc_language_defn): Convert to...
	(objc_language_data): ...this.
	(class objc_language): New class.
	(objc_language_defn): New static global.
	* gdb/opencl-lang.c (opencl_language_defn): Convert to...
	(opencl_language_data): ...this.
	(class opencl_language): New class.
	(opencl_language_defn): New static global.
	* gdb/p-lang.c (pascal_language_defn): Convert to...
	(pascal_language_data): ...this.
	(class pascal_language): New class.
	(pascal_language_defn): New static global.
	* gdb/rust-exp.y (rust_lex_tests): Use language_def to find
	language pointer, update comment format.
	* gdb/rust-lang.c (rust_language_defn): Convert to...
	(rust_language_data): ...this.
	(class rust_language): New class.
	(rust_language_defn): New static global.
---
 gdb/ChangeLog     | 98 ++++++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 19 ++++++++-
 gdb/c-lang.c      | 68 ++++++++++++++++++++++++++++++--
 gdb/d-lang.c      | 18 ++++++++-
 gdb/f-lang.c      | 18 ++++++++-
 gdb/go-lang.c     | 18 ++++++++-
 gdb/language.c    | 99 +++++++++++++++++++++++++++--------------------
 gdb/language.h    | 51 ++++++++++++++----------
 gdb/m2-lang.c     | 18 ++++++++-
 gdb/objc-lang.c   | 19 ++++++++-
 gdb/opencl-lang.c | 17 +++++++-
 gdb/p-lang.c      | 18 ++++++++-
 gdb/rust-exp.y    |  4 +-
 gdb/rust-lang.c   | 18 ++++++++-
 14 files changed, 406 insertions(+), 77 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 02e34044301..83751aa6d04 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -14055,7 +14055,10 @@ static const char *ada_extensions[] =
   ".adb", ".ads", ".a", ".ada", ".dg", NULL
 };
 
-extern const struct language_defn ada_language_defn = {
+/* Constant data that describes the Ada language.  */
+
+extern const struct language_data ada_language_data =
+{
   "ada",                        /* Language name */
   "Ada",
   language_ada,
@@ -14104,6 +14107,20 @@ extern const struct language_defn ada_language_defn = {
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the Ada language.  */
+
+class ada_language : public language_defn
+{
+public:
+  ada_language ()
+    : language_defn (language_ada, ada_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Ada language class.  */
+
+static ada_language ada_language_defn;
+
 /* Command-list for the "set/show ada" prefix command.  */
 static struct cmd_list_element *set_ada_list;
 static struct cmd_list_element *show_ada_list;
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 9d4064f152c..d81bc927880 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -885,7 +885,9 @@ static const char *c_extensions[] =
   ".c", NULL
 };
 
-extern const struct language_defn c_language_defn =
+/* Constant data that describes the C language.  */
+
+extern const struct language_data c_language_data =
 {
   "c",				/* Language name */
   "C",
@@ -934,6 +936,20 @@ extern const struct language_defn c_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the C language.  */
+
+class c_language : public language_defn
+{
+public:
+  c_language ()
+    : language_defn (language_c, c_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the C language class.  */
+
+static c_language c_language_defn;
+
 enum cplus_primitive_types {
   cplus_primitive_type_int,
   cplus_primitive_type_long,
@@ -1030,7 +1046,9 @@ static const char *cplus_extensions[] =
   ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", NULL
 };
 
-extern const struct language_defn cplus_language_defn =
+/* Constant data that describes the C++ language.  */
+
+extern const struct language_data cplus_language_data =
 {
   "c++",			/* Language name */
   "C++",
@@ -1079,12 +1097,28 @@ extern const struct language_defn cplus_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* A class for the C++ language.  */
+
+class cplus_language : public language_defn
+{
+public:
+  cplus_language ()
+    : language_defn (language_cplus, cplus_language_data)
+  { /* Nothing.  */ }
+};
+
+/* The single instance of the C++ language class.  */
+
+static cplus_language cplus_language_defn;
+
 static const char *asm_extensions[] =
 {
   ".s", ".sx", ".S", NULL
 };
 
-extern const struct language_defn asm_language_defn =
+/* Constant data that describes the ASM language.  */
+
+extern const struct language_data asm_language_data =
 {
   "asm",			/* Language name */
   "assembly",
@@ -1133,12 +1167,25 @@ extern const struct language_defn asm_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* A class for the ASM language.  */
+
+class asm_language : public language_defn
+{
+public:
+  asm_language ()
+    : language_defn (language_asm, asm_language_data)
+  { /* Nothing.  */ }
+};
+
+/* The single instance of the ASM language class.  */
+static asm_language asm_language_defn;
+
 /* The following language_defn does not represent a real language.
    It just provides a minimal support a-la-C that should allow users
    to do some simple operations when debugging applications that use
    a language currently not supported by GDB.  */
 
-extern const struct language_defn minimal_language_defn =
+extern const struct language_data minimal_language_data =
 {
   "minimal",			/* Language name */
   "Minimal",
@@ -1186,3 +1233,16 @@ extern const struct language_defn minimal_language_defn =
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
+
+/* A class for the minimal language.  */
+
+class minimal_language : public language_defn
+{
+public:
+  minimal_language ()
+    : language_defn (language_minimal, minimal_language_data)
+  { /* Nothing.  */ }
+};
+
+/* The single instance of the minimal language class.  */
+static minimal_language minimal_language_defn;
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 951e664ceda..c572ad7890e 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -205,7 +205,9 @@ static const char *d_extensions[] =
   ".d", NULL
 };
 
-extern const struct language_defn d_language_defn =
+/* Constant data that describes the D language.  */
+
+extern const struct language_data d_language_data =
 {
   "d",
   "D",
@@ -255,6 +257,20 @@ extern const struct language_defn d_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the D language.  */
+
+class d_language : public language_defn
+{
+public:
+  d_language ()
+    : language_defn (language_d, d_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the D language class.  */
+
+static d_language d_language_defn;
+
 /* Build all D language types for the specified architecture.  */
 
 static void *
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 3c3e6ab34ba..46d386e0477 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -628,7 +628,9 @@ static const struct exp_descriptor exp_descriptor_f =
   evaluate_subexp_f
 };
 
-extern const struct language_defn f_language_defn =
+/* Constant data that describes the Fortran language.  */
+
+extern const struct language_data f_language_data =
 {
   "fortran",
   "Fortran",
@@ -683,6 +685,20 @@ extern const struct language_defn f_language_defn =
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the Fortran language.  */
+
+class f_language : public language_defn
+{
+public:
+  f_language ()
+    : language_defn (language_fortran, f_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Fortran language class.  */
+
+static f_language f_language_defn;
+
 static void *
 build_fortran_types (struct gdbarch *gdbarch)
 {
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 373c12db516..f2b878bde3c 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -576,7 +576,9 @@ go_language_arch_info (struct gdbarch *gdbarch,
   lai->bool_type_default = builtin->builtin_bool;
 }
 
-extern const struct language_defn go_language_defn =
+/* Constant data that describes the Go language.  */
+
+extern const struct language_data go_language_data =
 {
   "go",
   "Go",
@@ -626,6 +628,20 @@ extern const struct language_defn go_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the Go language.  */
+
+class go_language : public language_defn
+{
+public:
+  go_language ()
+    : language_defn (language_go, go_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Go language class.  */
+
+static go_language go_language_defn;
+
 static void *
 build_go_types (struct gdbarch *gdbarch)
 {
diff --git a/gdb/language.c b/gdb/language.c
index a7ecb7963ba..e2357088c74 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -62,9 +62,6 @@ static void unk_lang_value_print (struct value *, struct ui_file *,
 
 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
 
-/* Forward declaration */
-extern const struct language_defn unknown_language_defn;
-
 /* The current (default at startup) state of type and range checking.
    (If the modes are set to "auto", though, these are changed based
    on the default language at startup, and then again based on the
@@ -77,7 +74,7 @@ enum case_sensitivity case_sensitivity = case_sensitive_on;
 
 /* The current language and language_mode (see language.h).  */
 
-const struct language_defn *current_language = &unknown_language_defn;
+const struct language_defn *current_language = nullptr;
 enum language_mode language_mode = language_mode_auto;
 
 /* The language that the user expects to be typing in (the language
@@ -85,26 +82,9 @@ enum language_mode language_mode = language_mode_auto;
 
 const struct language_defn *expected_language;
 
-/* The list of supported languages.  Keep this in the same order as
-   the 'enum language' values.  */
-
-static const struct language_defn *languages[] = {
-  &unknown_language_defn,
-  &auto_language_defn,
-  &c_language_defn,
-  &objc_language_defn,
-  &cplus_language_defn,
-  &d_language_defn,
-  &go_language_defn,
-  &f_language_defn,
-  &m2_language_defn,
-  &asm_language_defn,
-  &pascal_language_defn,
-  &opencl_language_defn,
-  &rust_language_defn,
-  &minimal_language_defn,
-  &ada_language_defn,
-};
+/* Define the array containing all languages.  */
+
+const struct language_defn *language_defn::languages[nr_languages];
 
 /* The current values of the "set language/range/case-sensitive" enum
    commands.  */
@@ -162,7 +142,7 @@ set_language_command (const char *ignore,
     language = "auto";
 
   /* Search the list of languages for a match.  */
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     {
       if (strcmp (lang->la_name, language) == 0)
 	{
@@ -377,7 +357,7 @@ set_language (enum language lang)
   enum language prev_language;
 
   prev_language = current_language->la_language;
-  current_language = languages[lang];
+  current_language = language_def (lang);
   set_range_case ();
   return prev_language;
 }
@@ -474,7 +454,7 @@ range_error (const char *string,...)
 enum language
 language_enum (const char *str)
 {
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     if (strcmp (lang->la_name, str) == 0)
       return lang->la_language;
 
@@ -489,7 +469,9 @@ language_enum (const char *str)
 const struct language_defn *
 language_def (enum language lang)
 {
-  return languages[lang];
+  const struct language_defn *l = language_defn::languages[lang];
+  gdb_assert (l != nullptr);
+  return l;
 }
 
 /* Return the language as a string.  */
@@ -497,7 +479,7 @@ language_def (enum language lang)
 const char *
 language_str (enum language lang)
 {
-  return languages[lang]->la_name;
+  return language_def (lang)->la_name;
 }
 
 \f
@@ -512,16 +494,16 @@ add_set_language_command ()
   /* Build the language names array, to be used as enumeration in the
      "set language" enum command.  +1 for "local" and +1 for NULL
      termination.  */
-  language_names = new const char *[ARRAY_SIZE (languages) + 2];
+  language_names = new const char *[ARRAY_SIZE (language_defn::languages) + 2];
 
   /* Display "auto", "local" and "unknown" first, and then the rest,
      alpha sorted.  */
   const char **language_names_p = language_names;
-  *language_names_p++ = auto_language_defn.la_name;
+  *language_names_p++ = language_def (language_auto)->la_name;
   *language_names_p++ = "local";
-  *language_names_p++ = unknown_language_defn.la_name;
+  *language_names_p++ = language_def (language_unknown)->la_name;
   const char **sort_begin = language_names_p;
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     {
       /* Already handled above.  */
       if (lang->la_language == language_auto
@@ -533,7 +515,7 @@ add_set_language_command ()
   std::sort (sort_begin, language_names_p, compare_cstrings);
 
   /* Add the filename extensions.  */
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     if (lang->la_filename_extensions != NULL)
       {
 	for (size_t i = 0; lang->la_filename_extensions[i] != NULL; ++i)
@@ -548,7 +530,7 @@ add_set_language_command ()
 		"The currently understood settings are:\n\nlocal or "
 		"auto    Automatic setting based on source file"));
 
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     {
       /* Already dealt with these above.  */
       if (lang->la_language == language_unknown
@@ -583,7 +565,7 @@ add_set_language_command ()
 CORE_ADDR 
 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
 {
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     {
       if (lang->skip_trampoline != NULL)
 	{
@@ -826,7 +808,9 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 						       struct type *);
 }
 
-const struct language_defn unknown_language_defn =
+/* Constant data that describes the unknown language.  */
+
+extern const struct language_data unknown_language_data =
 {
   "unknown",
   "Unknown",
@@ -875,9 +859,23 @@ const struct language_defn unknown_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
-/* These two structs define fake entries for the "local" and "auto"
-   options.  */
-const struct language_defn auto_language_defn =
+/* Class representing the unknown language.  */
+
+class unknown_language : public language_defn
+{
+public:
+  unknown_language ()
+    : language_defn (language_unknown, unknown_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the unknown language class.  */
+
+static unknown_language unknown_language_defn;
+
+/* Constant data for the fake "auto" language.  */
+
+extern const struct language_data auto_language_data =
 {
   "auto",
   "Auto",
@@ -926,6 +924,20 @@ const struct language_defn auto_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the fake "auto" language.  */
+
+class auto_language : public language_defn
+{
+public:
+  auto_language ()
+    : language_defn (language_auto, auto_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the fake "auto" language.  */
+
+static auto_language auto_language_defn;
+
 \f
 /* Per-architecture language information.  */
 
@@ -944,7 +956,7 @@ language_gdbarch_post_init (struct gdbarch *gdbarch)
   struct language_gdbarch *l;
 
   l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
-  for (const auto &lang : languages)
+  for (const auto &lang : language_defn::languages)
     if (lang != NULL && lang->la_language_arch_info != NULL)
       {
 	lang->la_language_arch_info (gdbarch,
@@ -1165,6 +1177,11 @@ For Fortran the default is off; for other languages the default is on."),
 			show_case_command,
 			&setlist, &showlist);
 
+  /* In order to call SET_LANGUAGE (below) we need to make sure that
+     CURRENT_LANGUAGE is not NULL.  So first set the language to unknown,
+     then we can change the language to 'auto'.  */
+  current_language = language_def (language_unknown);
+
   add_set_language_command ();
 
   language = "auto";
diff --git a/gdb/language.h b/gdb/language.h
index ea8aae511b0..a07ed0637a6 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -169,9 +169,21 @@ struct language_pass_by_ref_info
   bool destructible = true;
 };
 
-/* Structure tying together assorted information about a language.  */
+/* Structure tying together assorted information about a language.
 
-struct language_defn
+   As we move over from the old structure based languages to a class
+   hierarchy of languages this structure will continue to contain a
+   mixture of both data and function pointers.
+
+   Once the class hierarchy of languages in place the first task is to
+   remove the function pointers from this structure and convert them into
+   member functions on the different language classes.
+
+   The current plan it to keep the constant data that describes a language
+   in this structure, and have each language pass in an instance of this
+   structure at construction time.  */
+
+struct language_data
   {
     /* Name of the language.  */
 
@@ -470,6 +482,22 @@ struct language_defn
 
   };
 
+/* Base class from which all other language classes derive.  */
+
+struct language_defn : language_data
+{
+  language_defn (enum language lang, const language_data &init_data)
+    : language_data (init_data)
+  {
+    /* We should only ever create one instance of each language.  */
+    gdb_assert (languages[lang] == nullptr);
+    languages[lang] = this;
+  }
+
+  /* List of all known languages.  */
+  static const struct language_defn *languages[nr_languages];
+};
+
 /* Pointer to the language_defn for our current language.  This pointer
    always points to *some* valid struct; it can be used without checking
    it for validity.
@@ -679,25 +707,6 @@ extern bool default_symbol_name_matcher
 symbol_name_matcher_ftype *get_symbol_name_matcher
   (const language_defn *lang, const lookup_name_info &lookup_name);
 
-/* The languages supported by GDB.  */
-
-extern const struct language_defn auto_language_defn;
-extern const struct language_defn unknown_language_defn;
-extern const struct language_defn minimal_language_defn;
-
-extern const struct language_defn ada_language_defn;
-extern const struct language_defn asm_language_defn;
-extern const struct language_defn c_language_defn;
-extern const struct language_defn cplus_language_defn;
-extern const struct language_defn d_language_defn;
-extern const struct language_defn f_language_defn;
-extern const struct language_defn go_language_defn;
-extern const struct language_defn m2_language_defn;
-extern const struct language_defn objc_language_defn;
-extern const struct language_defn opencl_language_defn;
-extern const struct language_defn pascal_language_defn;
-extern const struct language_defn rust_language_defn;
-
 /* Save the current language and restore it upon destruction.  */
 
 class scoped_restore_current_language
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 7f0255b22d8..a443ac538ec 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -375,7 +375,9 @@ const struct exp_descriptor exp_descriptor_modula2 =
   evaluate_subexp_modula2
 };
 
-extern const struct language_defn m2_language_defn =
+/* Constant data describing the M2 language.  */
+
+extern const struct language_data m2_language_data =
 {
   "modula-2",
   "Modula-2",
@@ -424,6 +426,20 @@ extern const struct language_defn m2_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the M2 language.  */
+
+class m2_language : public language_defn
+{
+public:
+  m2_language ()
+    : language_defn (language_m2, m2_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the M2 language.  */
+
+static m2_language m2_language_defn;
+
 static void *
 build_m2_types (struct gdbarch *gdbarch)
 {
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index d724433d565..a1d035962c2 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -364,7 +364,10 @@ static const char *objc_extensions[] =
   ".m", NULL
 };
 
-extern const struct language_defn objc_language_defn = {
+/* Constant data representing the Objective-C language.  */
+
+extern const struct language_data objc_language_data =
+{
   "objective-c",		/* Language name */
   "Objective-C",
   language_objc,
@@ -412,6 +415,20 @@ extern const struct language_defn objc_language_defn = {
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the Objective-C language.  */
+
+class objc_language : public language_defn
+{
+public:
+  objc_language ()
+    : language_defn (language_objc, objc_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the class representing the Objective-C language.  */
+
+static objc_language objc_language_defn;
+
 /*
  * ObjC:
  * Following functions help construct Objective-C message calls.
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 0cd3501c4d9..f7166691e96 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1042,7 +1042,8 @@ const struct exp_descriptor exp_descriptor_opencl =
   evaluate_subexp_opencl
 };
 
-extern const struct language_defn opencl_language_defn =
+/* Constant data representing the OpenCL language.  */
+extern const struct language_data opencl_language_data =
 {
   "opencl",			/* Language name */
   "OpenCL C",
@@ -1091,6 +1092,20 @@ extern const struct language_defn opencl_language_defn =
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
+/* Class representing the OpenCL language.  */
+
+class opencl_language : public language_defn
+{
+public:
+  opencl_language ()
+    : language_defn (language_opencl, opencl_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the OpenCL language class.  */
+
+static opencl_language opencl_language_defn;
+
 static void *
 build_opencl_types (struct gdbarch *gdbarch)
 {
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 19dd8507335..2f5652d5e29 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -429,7 +429,9 @@ static const char *p_extensions[] =
   ".pas", ".p", ".pp", NULL
 };
 
-extern const struct language_defn pascal_language_defn =
+/* Constant data representing the Pascal language.  */
+
+extern const struct language_data pascal_language_data =
 {
   "pascal",			/* Language name */
   "Pascal",
@@ -476,3 +478,17 @@ extern const struct language_defn pascal_language_defn =
   pascal_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
+
+/* Class representing the Pascal language.  */
+
+class pascal_language : public language_defn
+{
+public:
+  pascal_language ()
+    : language_defn (language_pascal, pascal_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Pascal language class.  */
+
+static pascal_language pascal_language_defn;
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 6e3e49259d0..57eca4d1c7b 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2725,8 +2725,8 @@ rust_lex_tests (void)
 {
   int i;
 
-  // Set up dummy "parser", so that rust_type works.
-  struct parser_state ps (&rust_language_defn, target_gdbarch (),
+  /* Set up dummy "parser", so that rust_type works.  */
+  struct parser_state ps (language_def (language_rust), target_gdbarch (),
 			  nullptr, 0, 0, nullptr, 0, nullptr);
   rust_parser parser (&ps);
 
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index b8cc4daab55..7f712669aed 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2101,7 +2101,9 @@ static const char *rust_extensions[] =
   ".rs", NULL
 };
 
-extern const struct language_defn rust_language_defn =
+/* Constant data representing the Rust language.  */
+
+extern const struct language_data rust_language_data =
 {
   "rust",
   "Rust",
@@ -2149,3 +2151,17 @@ extern const struct language_defn rust_language_defn =
   rust_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
+
+/* Class representing the Rust language.  */
+
+class rust_language : public language_defn
+{
+public:
+  rust_language ()
+    : language_defn (language_rust, rust_language_data)
+  { /* Nothing.  */ }
+};
+
+/* Single instance of the Rust language class.  */
+
+static rust_language rust_language_defn;
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 02/13] gdb: Convert language la_print_array_index field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 01/13] gdb: Represent all languages as sub-classes of language_defn Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 03/13] gdb: Convert language la_read_var_value " Andrew Burgess
                     ` (12 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_print_array_index function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_print_array_index): Delete function, move
	implementation to...
	(ada_language::print_array_index): ...here.
	(ada_language_data): Delete la_print_array_index initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (default_print_array_index): Delete function, move
	implementation to...
	(language_defn::print_array_index): ...here.
	(unknown_language_data): Delete la_print_array_index initializer.
	(auto_language_data): Likewise.
	* language.h (struct language_data): Delete la_print_array_index
	field.
	(language_defn::print_array_index): New member function.
	(LA_PRINT_ARRAY_INDEX): Update.
	(default_print_array_index): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_print_array_index
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog     | 29 +++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 21 ++++++++++-----------
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  9 ++++-----
 gdb/language.h    | 19 ++++++++-----------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 13 files changed, 51 insertions(+), 39 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 83751aa6d04..3c323047b77 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -495,16 +495,6 @@ ada_get_gdb_completer_word_break_characters (void)
   return ada_completer_word_break_characters;
 }
 
-/* Print an array element index using the Ada syntax.  */
-
-static void
-ada_print_array_index (struct value *index_value, struct ui_file *stream,
-                       const struct value_print_options *options)
-{
-  LA_VALUE_PRINT (index_value, stream, options);
-  fprintf_filtered (stream, " => ");
-}
-
 /* la_watch_location_expression for Ada.  */
 
 static gdb::unique_xmalloc_ptr<char>
@@ -14094,7 +14084,6 @@ extern const struct language_data ada_language_data =
   ada_get_gdb_completer_word_break_characters,
   ada_collect_symbol_completion_matches,
   ada_language_arch_info,
-  ada_print_array_index,
   default_pass_by_reference,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
@@ -14115,6 +14104,16 @@ class ada_language : public language_defn
   ada_language ()
     : language_defn (language_ada, ada_language_data)
   { /* Nothing.  */ }
+
+  /* Print an array element index using the Ada syntax.  */
+
+  void print_array_index (struct value *index_value,
+			  struct ui_file *stream,
+			  const value_print_options *options) const override
+  {
+    LA_VALUE_PRINT (index_value, stream, options);
+    fprintf_filtered (stream, " => ");
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index d81bc927880..f0bfe313996 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -923,7 +923,6 @@ extern const struct language_data c_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
@@ -1084,7 +1083,6 @@ extern const struct language_data cplus_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   cplus_language_arch_info,
-  default_print_array_index,
   cp_pass_by_reference,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
@@ -1154,7 +1152,6 @@ extern const struct language_data asm_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,		/* FIXME: la_language_arch_info.  */
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
@@ -1221,7 +1218,6 @@ extern const struct language_data minimal_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index c572ad7890e..af8143b9b13 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -244,7 +244,6 @@ extern const struct language_data d_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   d_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 46d386e0477..7288e727421 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -672,7 +672,6 @@ extern const struct language_data f_language_data =
   f_word_break_characters,
   f_collect_symbol_completion_matches,
   f_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index f2b878bde3c..8820dc537e9 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -615,7 +615,6 @@ extern const struct language_data go_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   go_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/language.c b/gdb/language.c
index e2357088c74..97bc216235e 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -650,11 +650,12 @@ default_word_break_characters (void)
   return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
 }
 
-/* Print the index of array elements using the C99 syntax.  */
+/* See language.h.  */
 
 void
-default_print_array_index (struct value *index_value, struct ui_file *stream,
-			   const struct value_print_options *options)
+language_defn::print_array_index (struct value *index_value,
+				  struct ui_file *stream,
+				  const value_print_options *options) const
 {
   fprintf_filtered (stream, "[");
   LA_VALUE_PRINT (index_value, stream, options);
@@ -846,7 +847,6 @@ extern const struct language_data unknown_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   unknown_language_arch_info,	/* la_language_arch_info.  */
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
@@ -911,7 +911,6 @@ extern const struct language_data auto_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   unknown_language_arch_info,	/* la_language_arch_info.  */
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/language.h b/gdb/language.h
index a07ed0637a6..307a08c13cd 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -387,11 +387,6 @@ struct language_data
     void (*la_language_arch_info) (struct gdbarch *,
 				   struct language_arch_info *);
 
-    /* Print the index of an element of an array.  */
-    void (*la_print_array_index) (struct value *index_value,
-                                  struct ui_file *stream,
-                                  const struct value_print_options *options);
-
     /* Return information about whether TYPE should be passed
        (and returned) by reference at the language level.  */
     struct language_pass_by_ref_info (*la_pass_by_reference)
@@ -494,6 +489,13 @@ struct language_defn : language_data
     languages[lang] = this;
   }
 
+  /* Print the index of an element of an array.  This default
+     implementation prints using C99 syntax.  */
+
+  virtual void print_array_index (struct value *index_value,
+				  struct ui_file *stream,
+				  const value_print_options *options) const;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
@@ -599,7 +601,7 @@ extern enum language set_language (enum language);
   (current_language->la_emitchar(ch, type, stream, quoter))
 
 #define LA_PRINT_ARRAY_INDEX(index_value, stream, options) \
-  (current_language->la_print_array_index(index_value, stream, options))
+  (current_language->print_array_index(index_value, stream, options))
 
 #define LA_ITERATE_OVER_SYMBOLS(BLOCK, NAME, DOMAIN, CALLBACK) \
   (current_language->la_iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK))
@@ -661,11 +663,6 @@ extern char *language_class_name_from_physname (const struct language_defn *,
 /* Splitting strings into words.  */
 extern const char *default_word_break_characters (void);
 
-/* Print the index of an array element using the C99 syntax.  */
-extern void default_print_array_index (struct value *index_value,
-                                       struct ui_file *stream,
-				       const struct value_print_options *options);
-
 /* Return information about whether TYPE should be passed
    (and returned) by reference at the language level.  */
 struct language_pass_by_ref_info language_pass_by_reference (struct type *type);
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index a443ac538ec..f193b829ccc 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -413,7 +413,6 @@ extern const struct language_data m2_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   m2_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index a1d035962c2..a877ed073de 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -402,7 +402,6 @@ extern const struct language_data objc_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index f7166691e96..90d3f1b5f6a 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1079,7 +1079,6 @@ extern const struct language_data opencl_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   opencl_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 2f5652d5e29..0579814f664 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -466,7 +466,6 @@ extern const struct language_data pascal_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   pascal_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 7f712669aed..1f8d19c5e1f 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2139,7 +2139,6 @@ extern const struct language_data rust_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   rust_language_arch_info,
-  default_print_array_index,
   default_pass_by_reference,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 03/13] gdb: Convert language la_read_var_value field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 01/13] gdb: Represent all languages as sub-classes of language_defn Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 02/13] gdb: Convert language la_print_array_index field to a method Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 04/13] gdb: Convert language la_pass_by_reference " Andrew Burgess
                     ` (11 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_read_var_value function
pointer member variable into a member function of language_defn.

An interesting aspect of this change is that the implementation of
language_defn::read_var_value is actually in findvar.c.  This is
partly historical, the new language_defn::read_var_value is a rename
of default_read_var_value, which was already in that file, but also,
that is the file that contains the helper functions needed by the
read_var_value method, so it makes sens that the method implementation
should continue to live there (I think).

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_read_var_value): Delete function, move
	implementation to...
	(ada_language::read_var_value): ...here.
	(ada_language_data): Delete la_read_var_value initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* findvar.c (default_read_var_value): Rename to...
	(language_defn::read_var_value): ...this.
	* findvar.c (read_var_value): Update header comment, and change to
	call member function instead of function pointer.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Delete la_read_var_value
	initializer.
	(auto_language_data): Likewise.
	* language.h (struct language_data): Delete la_read_var_value
	field.
	(language_defn::read_var_value): New member function.
	(default_read_var_value): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_read_var_value
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	* value.h (default_read_var_value): Delete declaration.
---
 gdb/ChangeLog     | 31 +++++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 41 ++++++++++++++++++++---------------------
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/findvar.c     | 13 ++++++-------
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 gdb/language.h    | 30 +++++++++++++++---------------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 gdb/value.h       |  4 ----
 15 files changed, 72 insertions(+), 61 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3c323047b77..484ec104295 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -14020,26 +14020,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
     }
 }
 
-/* Implement the "la_read_var_value" language_defn method for Ada.  */
-
-static struct value *
-ada_read_var_value (struct symbol *var, const struct block *var_block,
-		    struct frame_info *frame)
-{
-  /* The only case where default_read_var_value is not sufficient
-     is when VAR is a renaming...  */
-  if (frame != nullptr)
-    {
-      const struct block *frame_block = get_frame_block (frame, NULL);
-      if (frame_block != nullptr && ada_is_renaming_symbol (var))
-	return ada_read_renaming_var_value (var, frame_block);
-    }
-
-  /* This is a typical case where we expect the default_read_var_value
-     function to work.  */
-  return default_read_var_value (var, var_block, frame);
-}
-
 static const char *ada_extensions[] =
 {
   ".adb", ".ads", ".a", ".ada", ".dg", NULL
@@ -14068,7 +14048,6 @@ extern const struct language_data ada_language_data =
   ada_print_typedef,            /* Print a typedef using appropriate syntax */
   ada_value_print_inner,	/* la_value_print_inner */
   ada_value_print,              /* Print a top-level value */
-  ada_read_var_value,		/* la_read_var_value */
   NULL,                         /* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
@@ -14114,6 +14093,26 @@ class ada_language : public language_defn
     LA_VALUE_PRINT (index_value, stream, options);
     fprintf_filtered (stream, " => ");
   }
+
+  /* Implement the "read_var_value" language_defn method for Ada.  */
+
+  struct value *read_var_value (struct symbol *var,
+				const struct block *var_block,
+				struct frame_info *frame) const override
+  {
+    /* The only case where default_read_var_value is not sufficient
+       is when VAR is a renaming...  */
+    if (frame != nullptr)
+      {
+	const struct block *frame_block = get_frame_block (frame, NULL);
+	if (frame_block != nullptr && ada_is_renaming_symbol (var))
+	  return ada_read_renaming_var_value (var, frame_block);
+      }
+
+    /* This is a typical case where we expect the default_read_var_value
+       function to work.  */
+    return language_defn::read_var_value (var, var_block, frame);
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index f0bfe313996..94bf0e5273f 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -907,7 +907,6 @@ extern const struct language_data c_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
@@ -1067,7 +1066,6 @@ extern const struct language_data cplus_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   cplus_skip_trampoline,	/* Language specific skip_trampoline */
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -1136,7 +1134,6 @@ extern const struct language_data asm_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
@@ -1202,7 +1199,6 @@ extern const struct language_data minimal_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index af8143b9b13..e55d82e08be 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -228,7 +228,6 @@ extern const struct language_data d_language_data =
 				   syntax.  */
   d_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value.  */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline.  */
   "this",
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 7288e727421..53e44db5caf 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -650,7 +650,6 @@ extern const struct language_data f_language_data =
   f_print_typedef,		/* Print a typedef using appropriate syntax */
   f_value_print_innner,		/* la_value_print_inner */
   c_value_print,		/* FIXME */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 40cbe8b48f4..c7cd31ce1a6 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -578,12 +578,12 @@ get_hosting_frame (struct symbol *var, const struct block *var_block,
   return frame;
 }
 
-/* A default implementation for the "la_read_var_value" hook in
-   the language vector which should work in most situations.  */
+/* See language.h.  */
 
 struct value *
-default_read_var_value (struct symbol *var, const struct block *var_block,
-			struct frame_info *frame)
+language_defn::read_var_value (struct symbol *var,
+			       const struct block *var_block,
+			       struct frame_info *frame) const
 {
   struct value *v;
   struct type *type = SYMBOL_TYPE (var);
@@ -801,7 +801,7 @@ default_read_var_value (struct symbol *var, const struct block *var_block,
   return v;
 }
 
-/* Calls VAR's language la_read_var_value hook with the given arguments.  */
+/* Calls VAR's language read_var_value hook with the given arguments.  */
 
 struct value *
 read_var_value (struct symbol *var, const struct block *var_block,
@@ -810,9 +810,8 @@ read_var_value (struct symbol *var, const struct block *var_block,
   const struct language_defn *lang = language_def (var->language ());
 
   gdb_assert (lang != NULL);
-  gdb_assert (lang->la_read_var_value != NULL);
 
-  return lang->la_read_var_value (var, var_block, frame);
+  return lang->read_var_value (var, var_block, frame);
 }
 
 /* Install default attributes for register values.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 8820dc537e9..c5f56e56a33 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -599,7 +599,6 @@ extern const struct language_data go_language_data =
 				   syntax.  */
   go_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value.  */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline.  */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/language.c b/gdb/language.c
index 97bc216235e..c0e59123881 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -831,7 +831,6 @@ extern const struct language_data unknown_language_data =
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_value_print_inner,	/* la_value_print_inner */
   unk_lang_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
@@ -895,7 +894,6 @@ extern const struct language_data auto_language_data =
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_value_print_inner,	/* la_value_print_inner */
   unk_lang_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   unk_lang_trampoline,		/* Language specific skip_trampoline */
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
diff --git a/gdb/language.h b/gdb/language.h
index 307a08c13cd..2219bcf3869 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -272,21 +272,6 @@ struct language_data
     void (*la_value_print) (struct value *, struct ui_file *,
 			    const struct value_print_options *);
 
-    /* Given a symbol VAR, the corresponding block VAR_BLOCK (if any) and a
-       stack frame id FRAME, read the value of the variable and return (pointer
-       to a) struct value containing the value.
-
-       VAR_BLOCK is needed if there's a possibility for VAR to be outside
-       FRAME.  This is what happens if FRAME correspond to a nested function
-       and VAR is defined in the outer function.  If callers know that VAR is
-       located in FRAME or is global/static, NULL can be passed as VAR_BLOCK.
-
-       Throw an error if the variable cannot be found.  */
-
-    struct value *(*la_read_var_value) (struct symbol *var,
-					const struct block *var_block,
-					struct frame_info *frame);
-
     /* PC is possibly an unknown languages trampoline.
        If that PC falls in a trampoline belonging to this language,
        return the address of the first pc in the real function, or 0
@@ -496,6 +481,21 @@ struct language_defn : language_data
 				  struct ui_file *stream,
 				  const value_print_options *options) const;
 
+  /* Given a symbol VAR, the corresponding block VAR_BLOCK (if any) and a
+     stack frame id FRAME, read the value of the variable and return (pointer
+     to a) struct value containing the value.
+
+     VAR_BLOCK is needed if there's a possibility for VAR to be outside
+     FRAME.  This is what happens if FRAME correspond to a nested function
+     and VAR is defined in the outer function.  If callers know that VAR is
+     located in FRAME or is global/static, NULL can be passed as VAR_BLOCK.
+
+     Throw an error if the variable cannot be found.  */
+
+  virtual struct value *read_var_value (struct symbol *var,
+					const struct block *var_block,
+					struct frame_info *frame) const;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index f193b829ccc..8ec69ed0d79 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -397,7 +397,6 @@ extern const struct language_data m2_language_data =
   m2_print_typedef,		/* Print a typedef using appropriate syntax */
   m2_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index a877ed073de..f6fd8f5e465 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -386,7 +386,6 @@ extern const struct language_data objc_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   objc_skip_trampoline, 	/* Language specific skip_trampoline */
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 90d3f1b5f6a..a4ae878565b 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1063,7 +1063,6 @@ extern const struct language_data opencl_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 0579814f664..dc0d7a3da82 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -451,7 +451,6 @@ extern const struct language_data pascal_language_data =
   pascal_print_typedef,		/* Print a typedef using appropriate syntax */
   pascal_value_print_inner,	/* la_value_print_inner */
   pascal_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 1f8d19c5e1f..15f7567868b 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2123,7 +2123,6 @@ extern const struct language_data rust_language_data =
   rust_print_typedef,		/* Print a typedef using appropriate syntax */
   rust_value_print_inner,	/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  default_read_var_value,	/* la_read_var_value */
   NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/value.h b/gdb/value.h
index ae859ca7224..70c3d5667ae 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -744,10 +744,6 @@ extern struct value *read_var_value (struct symbol *var,
 				     const struct block *var_block,
 				     struct frame_info *frame);
 
-extern struct value *default_read_var_value (struct symbol *var,
-					     const struct block *var_block,
-					     struct frame_info *frame);
-
 extern struct value *allocate_value (struct type *type);
 extern struct value *allocate_value_lazy (struct type *type);
 extern void value_contents_copy (struct value *dst, LONGEST dst_offset,
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 04/13] gdb: Convert language la_pass_by_reference field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (2 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 03/13] gdb: Convert language la_read_var_value " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 05/13] gdb: Convert language la_language_arch_info " Andrew Burgess
                     ` (10 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_pass_by_reference function
pointer member variable into a member function of language_defn.

The interesting thing in this commit is that I have removed the
default_pass_by_reference function entirely.  This function only ever
returned a language_pass_by_ref_info struct in its default state, so
all uses of this function can be replaced by just default
initialisation of a language_pass_by_ref_info variable.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_pass_by_reference
	initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(cplus_language::pass_by_reference_info): New method.
	(asm_language_data): Delete la_pass_by_reference initializer.
	(minimal_language_data): Likewise.
	* cp-abi.c (cp_pass_by_reference): Remove use of
	default_pass_by_reference.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* gnu-v3-abi.c (gnuv3_pass_by_reference): Remove use of
	default_pass_by_reference.
	* go-lang.c (go_language_data): Likewise.
	* language.c (language_pass_by_reference): Update.
	(default_pass_by_reference): Delete.
	(unknown_language_data): Delete la_pass_by_reference
	initializer.
	(auto_language_data): Likewise.
	* language.h (struct language_data): Delete la_pass_by_reference
	field.
	(language_defn::pass_by_reference_info): New member function.
	(default_pass_by_reference): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_pass_by_reference
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog     | 32 ++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      | 12 ++++++++----
 gdb/cp-abi.c      |  2 +-
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/gnu-v3-abi.c  |  3 +--
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 14 +-------------
 gdb/language.h    | 21 +++++++++++----------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 15 files changed, 54 insertions(+), 39 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 484ec104295..e55bc4d0258 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -14063,7 +14063,6 @@ extern const struct language_data ada_language_data =
   ada_get_gdb_completer_word_break_characters,
   ada_collect_symbol_completion_matches,
   ada_language_arch_info,
-  default_pass_by_reference,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
   ada_iterate_over_symbols,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 94bf0e5273f..315ad48b08f 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -922,7 +922,6 @@ extern const struct language_data c_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1081,7 +1080,6 @@ extern const struct language_data cplus_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   cplus_language_arch_info,
-  cp_pass_by_reference,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
   iterate_over_symbols,
@@ -1101,6 +1099,14 @@ class cplus_language : public language_defn
   cplus_language ()
     : language_defn (language_cplus, cplus_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+
+  struct language_pass_by_ref_info pass_by_reference_info
+	(struct type *type) const override
+  {
+    return cp_pass_by_reference (type);
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1149,7 +1155,6 @@ extern const struct language_data asm_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,		/* FIXME: la_language_arch_info.  */
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1214,7 +1219,6 @@ extern const struct language_data minimal_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/cp-abi.c b/gdb/cp-abi.c
index 6997a7bdbe9..d8dd2ceb795 100644
--- a/gdb/cp-abi.c
+++ b/gdb/cp-abi.c
@@ -226,7 +226,7 @@ struct language_pass_by_ref_info
 cp_pass_by_reference (struct type *type)
 {
   if ((current_cp_abi.pass_by_reference) == NULL)
-    return default_pass_by_reference (type);
+    return {};
   return (*current_cp_abi.pass_by_reference) (type);
 }
 
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index e55d82e08be..28864420bad 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -243,7 +243,6 @@ extern const struct language_data d_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   d_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 53e44db5caf..78959b1ec57 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -671,7 +671,6 @@ extern const struct language_data f_language_data =
   f_word_break_characters,
   f_collect_symbol_completion_matches,
   f_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 1fe3a9670cf..a22ef564683 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -1406,8 +1406,7 @@ gnuv3_pass_by_reference (struct type *type)
   type = check_typedef (type);
 
   /* Start with the default values.  */
-  struct language_pass_by_ref_info info
-    = default_pass_by_reference (type);
+  struct language_pass_by_ref_info info;
 
   bool has_cc_attr = false;
   bool is_pass_by_value = false;
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index c5f56e56a33..0774638145c 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -614,7 +614,6 @@ extern const struct language_data go_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   go_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/language.c b/gdb/language.c
index c0e59123881..d08628af920 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -627,17 +627,7 @@ language_class_name_from_physname (const struct language_defn *lang,
 struct language_pass_by_ref_info
 language_pass_by_reference (struct type *type)
 {
-  return current_language->la_pass_by_reference (type);
-}
-
-/* Return a default struct that provides pass-by-reference information
-   about the given TYPE.  Languages should update the default values
-   as appropriate.  */
-
-struct language_pass_by_ref_info
-default_pass_by_reference (struct type *type)
-{
-  return {};
+  return current_language->pass_by_reference_info (type);
 }
 
 /* Return the default string containing the list of characters
@@ -846,7 +836,6 @@ extern const struct language_data unknown_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   unknown_language_arch_info,	/* la_language_arch_info.  */
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -909,7 +898,6 @@ extern const struct language_data auto_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   unknown_language_arch_info,	/* la_language_arch_info.  */
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/language.h b/gdb/language.h
index 2219bcf3869..21539374e89 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -372,11 +372,6 @@ struct language_data
     void (*la_language_arch_info) (struct gdbarch *,
 				   struct language_arch_info *);
 
-    /* Return information about whether TYPE should be passed
-       (and returned) by reference at the language level.  */
-    struct language_pass_by_ref_info (*la_pass_by_reference)
-      (struct type *type);
-
     /* Return an expression that can be used for a location
        watchpoint.  TYPE is a pointer type that points to the memory
        to watch, and ADDR is the address of the watched memory.  */
@@ -496,6 +491,17 @@ struct language_defn : language_data
 					const struct block *var_block,
 					struct frame_info *frame) const;
 
+  /* Return information about whether TYPE should be passed
+     (and returned) by reference at the language level.  The default
+     implementation returns a LANGUAGE_PASS_BY_REF_INFO initialised in its
+     default state.  */
+
+  virtual struct language_pass_by_ref_info pass_by_reference_info
+	(struct type *type) const
+  {
+    return {};
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
@@ -667,11 +673,6 @@ extern const char *default_word_break_characters (void);
    (and returned) by reference at the language level.  */
 struct language_pass_by_ref_info language_pass_by_reference (struct type *type);
 
-/* Return a default struct that provides pass-by-reference information
-   about the given TYPE.  Languages should update the default values
-   as appropriate.  */
-struct language_pass_by_ref_info default_pass_by_reference (struct type *type);
-
 /* The default implementation of la_print_typedef.  */
 void default_print_typedef (struct type *type, struct symbol *new_symbol,
 			    struct ui_file *stream);
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 8ec69ed0d79..5b83404720d 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -412,7 +412,6 @@ extern const struct language_data m2_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   m2_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index f6fd8f5e465..cf5b91b3388 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -401,7 +401,6 @@ extern const struct language_data objc_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   c_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index a4ae878565b..450e391ccec 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1078,7 +1078,6 @@ extern const struct language_data opencl_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   opencl_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index dc0d7a3da82..9f0d02215b1 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -465,7 +465,6 @@ extern const struct language_data pascal_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   pascal_language_arch_info,
-  default_pass_by_reference,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
   iterate_over_symbols,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 15f7567868b..bd7174a1255 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2138,7 +2138,6 @@ extern const struct language_data rust_language_data =
   default_word_break_characters,
   default_collect_symbol_completion_matches,
   rust_language_arch_info,
-  default_pass_by_reference,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 05/13] gdb: Convert language la_language_arch_info field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (3 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 04/13] gdb: Convert language la_pass_by_reference " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 06/13] gdb: Convert language la_lookup_transparent_type " Andrew Burgess
                     ` (9 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_language_arch_info function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_arch_info): Delete function, move
	implementation to...
	(ada_language::language_arch_info): ...here, a new member
	function.
	(ada_language_data): Delete la_language_arch_info.
	* c-lang.c (c_language_data): Likewise.
	(c_language::language_arch_info): New member function.
	(cplus_language_arch_info): Delete function, move
	implementation to...
	(cplus_language::language_arch_info): ...here, a new member
	function.
	(cplus_language_data): Delete la_language_arch_info.
	(asm_language_data): Likewise.
	(asm_language::language_arch_info): New member function.
	(minimal_language_data): Delete la_language_arch_info.
	(minimal_language::language_arch_info): New member function.
	* d-lang.c (d_language_arch_info): Delete function, move
	implementation to...
	(d_language::language_arch_info): ...here, a new member
	function.
	(d_language_data): Delete la_language_arch_info.
	* f-lang.c (f_language_arch_info): Delete function, move
	implementation to...
	(f_language::language_arch_info): ...here, a new member
	function.
	(f_language_data): Delete la_language_arch_info.
	* go-lang.c (go_language_arch_info): Delete function, move
	implementation to...
	(go_language::language_arch_info): ...here, a new member
	function.
	(go_language_data): Delete la_language_arch_info.
	* language.c (unknown_language_data): Likewise.
	(unknown_language::language_arch_info): New member function.
	(auto_language_data): Delete la_language_arch_info.
	(auto_language::language_arch_info): New member function.
	(language_gdbarch_post_init): Update call to
	la_language_arch_info.
	* language.h (language_data): Delete la_language_arch_info
	function pointer.
	(language_defn::language_arch_info): New function.
	* m2-lang.c (m2_language_arch_info): Delete function, move
	implementation to...
	(m2_language::language_arch_info): ...here, a new member
	function.
	(m2_language_data): Delete la_language_arch_info.
	* objc-lang.c (objc_language_arch_info): Delete function, move
	implementation to...
	(objc_language::language_arch_info): ...here, a new member
	function.
	(objc_language_data): Delete la_language_arch_info.
	* opencl-lang.c (opencl_language_arch_info): Delete function, move
	implementation to...
	(opencl_language::language_arch_info): ...here, a new member
	function.
	(opencl_language_data): Delete la_language_arch_info.
	* p-lang.c (pascal_language_arch_info): Delete function, move
	implementation to...
	(pascal_language::language_arch_info): ...here, a new member
	function.
	(pascal_language_data): Delete la_language_arch_info.
	* rust-lang.c (rust_language_arch_info): Delete function, move
	implementation to...
	(rust_language::language_arch_info): ...here, a new member
	function.
	(rust_language_data): Delete la_language_arch_info.
---
 gdb/ChangeLog     |  68 +++++++++++++++++++++
 gdb/ada-lang.c    | 133 ++++++++++++++++++++--------------------
 gdb/c-lang.c      | 153 ++++++++++++++++++++++++++--------------------
 gdb/d-lang.c      | 132 +++++++++++++++++++--------------------
 gdb/f-lang.c      |  77 ++++++++++++-----------
 gdb/go-lang.c     | 107 ++++++++++++++++----------------
 gdb/language.c    |  26 +++++---
 gdb/language.h    |   9 +--
 gdb/m2-lang.c     |  53 ++++++++--------
 gdb/objc-lang.c   |   8 ++-
 gdb/opencl-lang.c |  35 ++++++-----
 gdb/p-lang.c      |  99 +++++++++++++++---------------
 gdb/rust-lang.c   |  87 +++++++++++++-------------
 13 files changed, 538 insertions(+), 449 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e55bc4d0258..7e6ee9e5757 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -213,9 +213,6 @@ static int ada_resolve_function (struct block_symbol *, int,
 
 static int ada_is_direct_array_type (struct type *);
 
-static void ada_language_arch_info (struct gdbarch *,
-				    struct language_arch_info *);
-
 static struct value *ada_index_struct_field (int, struct value *, int,
 					     struct type *);
 
@@ -13780,70 +13777,6 @@ enum ada_primitive_types {
   nr_ada_primitive_types
 };
 
-static void
-ada_language_arch_info (struct gdbarch *gdbarch,
-			struct language_arch_info *lai)
-{
-  const struct builtin_type *builtin = builtin_type (gdbarch);
-
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
-			      struct type *);
-
-  lai->primitive_type_vector [ada_primitive_type_int]
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-			 0, "integer");
-  lai->primitive_type_vector [ada_primitive_type_long]
-    = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
-			 0, "long_integer");
-  lai->primitive_type_vector [ada_primitive_type_short]
-    = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
-			 0, "short_integer");
-  lai->string_char_type
-    = lai->primitive_type_vector [ada_primitive_type_char]
-    = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
-  lai->primitive_type_vector [ada_primitive_type_float]
-    = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
-		       "float", gdbarch_float_format (gdbarch));
-  lai->primitive_type_vector [ada_primitive_type_double]
-    = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
-		       "long_float", gdbarch_double_format (gdbarch));
-  lai->primitive_type_vector [ada_primitive_type_long_long]
-    = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
-			 0, "long_long_integer");
-  lai->primitive_type_vector [ada_primitive_type_long_double]
-    = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
-		       "long_long_float", gdbarch_long_double_format (gdbarch));
-  lai->primitive_type_vector [ada_primitive_type_natural]
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-			 0, "natural");
-  lai->primitive_type_vector [ada_primitive_type_positive]
-    = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
-			 0, "positive");
-  lai->primitive_type_vector [ada_primitive_type_void]
-    = builtin->builtin_void;
-
-  lai->primitive_type_vector [ada_primitive_type_system_address]
-    = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
-				      "void"));
-  TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
-    = "system__address";
-
-  /* Create the equivalent of the System.Storage_Elements.Storage_Offset
-     type.  This is a signed integral type whose size is the same as
-     the size of addresses.  */
-  {
-    unsigned int addr_length = TYPE_LENGTH
-      (lai->primitive_type_vector [ada_primitive_type_system_address]);
-
-    lai->primitive_type_vector [ada_primitive_type_storage_offset]
-      = arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0,
-			   "storage_offset");
-  }
-
-  lai->bool_type_symbol = NULL;
-  lai->bool_type_default = builtin->builtin_bool;
-}
 \f
 				/* Language vector */
 
@@ -14062,7 +13995,6 @@ extern const struct language_data ada_language_data =
   1,                            /* String lower bound */
   ada_get_gdb_completer_word_break_characters,
   ada_collect_symbol_completion_matches,
-  ada_language_arch_info,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
   ada_iterate_over_symbols,
@@ -14112,6 +14044,71 @@ class ada_language : public language_defn
        function to work.  */
     return language_defn::read_var_value (var, var_block, frame);
   }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_type *builtin = builtin_type (gdbarch);
+
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [ada_primitive_type_int]
+      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+			   0, "integer");
+    lai->primitive_type_vector [ada_primitive_type_long]
+      = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
+			   0, "long_integer");
+    lai->primitive_type_vector [ada_primitive_type_short]
+      = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
+			   0, "short_integer");
+    lai->string_char_type
+      = lai->primitive_type_vector [ada_primitive_type_char]
+      = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
+    lai->primitive_type_vector [ada_primitive_type_float]
+      = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
+			 "float", gdbarch_float_format (gdbarch));
+    lai->primitive_type_vector [ada_primitive_type_double]
+      = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
+			 "long_float", gdbarch_double_format (gdbarch));
+    lai->primitive_type_vector [ada_primitive_type_long_long]
+      = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
+			   0, "long_long_integer");
+    lai->primitive_type_vector [ada_primitive_type_long_double]
+      = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
+			 "long_long_float", gdbarch_long_double_format (gdbarch));
+    lai->primitive_type_vector [ada_primitive_type_natural]
+      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+			   0, "natural");
+    lai->primitive_type_vector [ada_primitive_type_positive]
+      = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+			   0, "positive");
+    lai->primitive_type_vector [ada_primitive_type_void]
+      = builtin->builtin_void;
+
+    lai->primitive_type_vector [ada_primitive_type_system_address]
+      = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
+					"void"));
+    TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
+      = "system__address";
+
+    /* Create the equivalent of the System.Storage_Elements.Storage_Offset
+       type.  This is a signed integral type whose size is the same as
+       the size of addresses.  */
+    {
+      unsigned int addr_length = TYPE_LENGTH
+	(lai->primitive_type_vector [ada_primitive_type_system_address]);
+
+      lai->primitive_type_vector [ada_primitive_type_storage_offset]
+	= arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0,
+			     "storage_offset");
+    }
+
+    lai->bool_type_symbol = NULL;
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 315ad48b08f..84303954dd7 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -921,7 +921,6 @@ extern const struct language_data c_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  c_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -941,6 +940,13 @@ class c_language : public language_defn
   c_language ()
     : language_defn (language_c, c_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    c_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* Single instance of the C language class.  */
@@ -975,69 +981,6 @@ enum cplus_primitive_types {
   nr_cplus_primitive_types
 };
 
-static void
-cplus_language_arch_info (struct gdbarch *gdbarch,
-			  struct language_arch_info *lai)
-{
-  const struct builtin_type *builtin = builtin_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
-			      struct type *);
-  lai->primitive_type_vector [cplus_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [cplus_primitive_type_long]
-    = builtin->builtin_long;
-  lai->primitive_type_vector [cplus_primitive_type_short]
-    = builtin->builtin_short;
-  lai->primitive_type_vector [cplus_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [cplus_primitive_type_float]
-    = builtin->builtin_float;
-  lai->primitive_type_vector [cplus_primitive_type_double]
-    = builtin->builtin_double;
-  lai->primitive_type_vector [cplus_primitive_type_void]
-    = builtin->builtin_void;
-  lai->primitive_type_vector [cplus_primitive_type_long_long]
-    = builtin->builtin_long_long;
-  lai->primitive_type_vector [cplus_primitive_type_signed_char]
-    = builtin->builtin_signed_char;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
-    = builtin->builtin_unsigned_char;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
-    = builtin->builtin_unsigned_short;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
-    = builtin->builtin_unsigned_int;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
-    = builtin->builtin_unsigned_long;
-  lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
-    = builtin->builtin_unsigned_long_long;
-  lai->primitive_type_vector [cplus_primitive_type_long_double]
-    = builtin->builtin_long_double;
-  lai->primitive_type_vector [cplus_primitive_type_complex]
-    = builtin->builtin_complex;
-  lai->primitive_type_vector [cplus_primitive_type_double_complex]
-    = builtin->builtin_double_complex;
-  lai->primitive_type_vector [cplus_primitive_type_bool]
-    = builtin->builtin_bool;
-  lai->primitive_type_vector [cplus_primitive_type_decfloat]
-    = builtin->builtin_decfloat;
-  lai->primitive_type_vector [cplus_primitive_type_decdouble]
-    = builtin->builtin_decdouble;
-  lai->primitive_type_vector [cplus_primitive_type_declong]
-    = builtin->builtin_declong;
-  lai->primitive_type_vector [cplus_primitive_type_char16_t]
-    = builtin->builtin_char16;
-  lai->primitive_type_vector [cplus_primitive_type_char32_t]
-    = builtin->builtin_char32;
-  lai->primitive_type_vector [cplus_primitive_type_wchar_t]
-    = builtin->builtin_wchar;
-
-  lai->bool_type_symbol = "bool";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 static const char *cplus_extensions[] =
 {
   ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", NULL
@@ -1079,7 +1022,6 @@ extern const struct language_data cplus_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  cplus_language_arch_info,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
   iterate_over_symbols,
@@ -1107,6 +1049,69 @@ class cplus_language : public language_defn
   {
     return cp_pass_by_reference (type);
   }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_type *builtin = builtin_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,
+				struct type *);
+    lai->primitive_type_vector [cplus_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [cplus_primitive_type_long]
+      = builtin->builtin_long;
+    lai->primitive_type_vector [cplus_primitive_type_short]
+      = builtin->builtin_short;
+    lai->primitive_type_vector [cplus_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [cplus_primitive_type_float]
+      = builtin->builtin_float;
+    lai->primitive_type_vector [cplus_primitive_type_double]
+      = builtin->builtin_double;
+    lai->primitive_type_vector [cplus_primitive_type_void]
+      = builtin->builtin_void;
+    lai->primitive_type_vector [cplus_primitive_type_long_long]
+      = builtin->builtin_long_long;
+    lai->primitive_type_vector [cplus_primitive_type_signed_char]
+      = builtin->builtin_signed_char;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_char]
+      = builtin->builtin_unsigned_char;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_short]
+      = builtin->builtin_unsigned_short;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_int]
+      = builtin->builtin_unsigned_int;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_long]
+      = builtin->builtin_unsigned_long;
+    lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long]
+      = builtin->builtin_unsigned_long_long;
+    lai->primitive_type_vector [cplus_primitive_type_long_double]
+      = builtin->builtin_long_double;
+    lai->primitive_type_vector [cplus_primitive_type_complex]
+      = builtin->builtin_complex;
+    lai->primitive_type_vector [cplus_primitive_type_double_complex]
+      = builtin->builtin_double_complex;
+    lai->primitive_type_vector [cplus_primitive_type_bool]
+      = builtin->builtin_bool;
+    lai->primitive_type_vector [cplus_primitive_type_decfloat]
+      = builtin->builtin_decfloat;
+    lai->primitive_type_vector [cplus_primitive_type_decdouble]
+      = builtin->builtin_decdouble;
+    lai->primitive_type_vector [cplus_primitive_type_declong]
+      = builtin->builtin_declong;
+    lai->primitive_type_vector [cplus_primitive_type_char16_t]
+      = builtin->builtin_char16;
+    lai->primitive_type_vector [cplus_primitive_type_char32_t]
+      = builtin->builtin_char32;
+    lai->primitive_type_vector [cplus_primitive_type_wchar_t]
+      = builtin->builtin_wchar;
+
+    lai->bool_type_symbol = "bool";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1154,7 +1159,6 @@ extern const struct language_data asm_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  c_language_arch_info,		/* FIXME: la_language_arch_info.  */
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1174,6 +1178,15 @@ class asm_language : public language_defn
   asm_language ()
     : language_defn (language_asm, asm_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.
+
+     FIXME: Should this have its own arch info method?  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    c_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* The single instance of the ASM language class.  */
@@ -1218,7 +1231,6 @@ extern const struct language_data minimal_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  c_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1238,6 +1250,13 @@ class minimal_language : public language_defn
   minimal_language ()
     : language_defn (language_minimal, minimal_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    c_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* The single instance of the minimal language class.  */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 28864420bad..778d77313c9 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -133,73 +133,6 @@ enum d_primitive_types {
   nr_d_primitive_types
 };
 
-/* Implements the la_language_arch_info language_defn routine
-   for language D.  */
-
-static void
-d_language_arch_info (struct gdbarch *gdbarch,
-		      struct language_arch_info *lai)
-{
-  const struct builtin_d_type *builtin = builtin_d_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_d_primitive_types + 1,
-			      struct type *);
-
-  lai->primitive_type_vector [d_primitive_type_void]
-    = builtin->builtin_void;
-  lai->primitive_type_vector [d_primitive_type_bool]
-    = builtin->builtin_bool;
-  lai->primitive_type_vector [d_primitive_type_byte]
-    = builtin->builtin_byte;
-  lai->primitive_type_vector [d_primitive_type_ubyte]
-    = builtin->builtin_ubyte;
-  lai->primitive_type_vector [d_primitive_type_short]
-    = builtin->builtin_short;
-  lai->primitive_type_vector [d_primitive_type_ushort]
-    = builtin->builtin_ushort;
-  lai->primitive_type_vector [d_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [d_primitive_type_uint]
-    = builtin->builtin_uint;
-  lai->primitive_type_vector [d_primitive_type_long]
-    = builtin->builtin_long;
-  lai->primitive_type_vector [d_primitive_type_ulong]
-    = builtin->builtin_ulong;
-  lai->primitive_type_vector [d_primitive_type_cent]
-    = builtin->builtin_cent;
-  lai->primitive_type_vector [d_primitive_type_ucent]
-    = builtin->builtin_ucent;
-  lai->primitive_type_vector [d_primitive_type_float]
-    = builtin->builtin_float;
-  lai->primitive_type_vector [d_primitive_type_double]
-    = builtin->builtin_double;
-  lai->primitive_type_vector [d_primitive_type_real]
-    = builtin->builtin_real;
-  lai->primitive_type_vector [d_primitive_type_ifloat]
-    = builtin->builtin_ifloat;
-  lai->primitive_type_vector [d_primitive_type_idouble]
-    = builtin->builtin_idouble;
-  lai->primitive_type_vector [d_primitive_type_ireal]
-    = builtin->builtin_ireal;
-  lai->primitive_type_vector [d_primitive_type_cfloat]
-    = builtin->builtin_cfloat;
-  lai->primitive_type_vector [d_primitive_type_cdouble]
-    = builtin->builtin_cdouble;
-  lai->primitive_type_vector [d_primitive_type_creal]
-    = builtin->builtin_creal;
-  lai->primitive_type_vector [d_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [d_primitive_type_wchar]
-    = builtin->builtin_wchar;
-  lai->primitive_type_vector [d_primitive_type_dchar]
-    = builtin->builtin_dchar;
-
-  lai->bool_type_symbol = "bool";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 static const char *d_extensions[] =
 {
   ".d", NULL
@@ -242,7 +175,6 @@ extern const struct language_data d_language_data =
   0,				/* String lower bound.  */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  d_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -262,6 +194,70 @@ class d_language : public language_defn
   d_language ()
     : language_defn (language_d, d_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_d_type *builtin = builtin_d_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_d_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [d_primitive_type_void]
+      = builtin->builtin_void;
+    lai->primitive_type_vector [d_primitive_type_bool]
+      = builtin->builtin_bool;
+    lai->primitive_type_vector [d_primitive_type_byte]
+      = builtin->builtin_byte;
+    lai->primitive_type_vector [d_primitive_type_ubyte]
+      = builtin->builtin_ubyte;
+    lai->primitive_type_vector [d_primitive_type_short]
+      = builtin->builtin_short;
+    lai->primitive_type_vector [d_primitive_type_ushort]
+      = builtin->builtin_ushort;
+    lai->primitive_type_vector [d_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [d_primitive_type_uint]
+      = builtin->builtin_uint;
+    lai->primitive_type_vector [d_primitive_type_long]
+      = builtin->builtin_long;
+    lai->primitive_type_vector [d_primitive_type_ulong]
+      = builtin->builtin_ulong;
+    lai->primitive_type_vector [d_primitive_type_cent]
+      = builtin->builtin_cent;
+    lai->primitive_type_vector [d_primitive_type_ucent]
+      = builtin->builtin_ucent;
+    lai->primitive_type_vector [d_primitive_type_float]
+      = builtin->builtin_float;
+    lai->primitive_type_vector [d_primitive_type_double]
+      = builtin->builtin_double;
+    lai->primitive_type_vector [d_primitive_type_real]
+      = builtin->builtin_real;
+    lai->primitive_type_vector [d_primitive_type_ifloat]
+      = builtin->builtin_ifloat;
+    lai->primitive_type_vector [d_primitive_type_idouble]
+      = builtin->builtin_idouble;
+    lai->primitive_type_vector [d_primitive_type_ireal]
+      = builtin->builtin_ireal;
+    lai->primitive_type_vector [d_primitive_type_cfloat]
+      = builtin->builtin_cfloat;
+    lai->primitive_type_vector [d_primitive_type_cdouble]
+      = builtin->builtin_cdouble;
+    lai->primitive_type_vector [d_primitive_type_creal]
+      = builtin->builtin_creal;
+    lai->primitive_type_vector [d_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [d_primitive_type_wchar]
+      = builtin->builtin_wchar;
+    lai->primitive_type_vector [d_primitive_type_dchar]
+      = builtin->builtin_dchar;
+
+    lai->bool_type_symbol = "bool";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the D language class.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 78959b1ec57..1eeb5070dee 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -165,44 +165,6 @@ enum f_primitive_types {
   nr_f_primitive_types
 };
 
-static void
-f_language_arch_info (struct gdbarch *gdbarch,
-		      struct language_arch_info *lai)
-{
-  const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_character;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1,
-                              struct type *);
-
-  lai->primitive_type_vector [f_primitive_type_character]
-    = builtin->builtin_character;
-  lai->primitive_type_vector [f_primitive_type_logical]
-    = builtin->builtin_logical;
-  lai->primitive_type_vector [f_primitive_type_logical_s1]
-    = builtin->builtin_logical_s1;
-  lai->primitive_type_vector [f_primitive_type_logical_s2]
-    = builtin->builtin_logical_s2;
-  lai->primitive_type_vector [f_primitive_type_logical_s8]
-    = builtin->builtin_logical_s8;
-  lai->primitive_type_vector [f_primitive_type_real]
-    = builtin->builtin_real;
-  lai->primitive_type_vector [f_primitive_type_real_s8]
-    = builtin->builtin_real_s8;
-  lai->primitive_type_vector [f_primitive_type_real_s16]
-    = builtin->builtin_real_s16;
-  lai->primitive_type_vector [f_primitive_type_complex_s8]
-    = builtin->builtin_complex_s8;
-  lai->primitive_type_vector [f_primitive_type_complex_s16]
-    = builtin->builtin_complex_s16;
-  lai->primitive_type_vector [f_primitive_type_void]
-    = builtin->builtin_void;
-
-  lai->bool_type_symbol = "logical";
-  lai->bool_type_default = builtin->builtin_logical_s2;
-}
-
 /* Remove the modules separator :: from the default break list.  */
 
 static const char *
@@ -670,7 +632,6 @@ extern const struct language_data f_language_data =
   1,				/* String lower bound */
   f_word_break_characters,
   f_collect_symbol_completion_matches,
-  f_language_arch_info,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -690,6 +651,44 @@ class f_language : public language_defn
   f_language ()
     : language_defn (language_fortran, f_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_character;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [f_primitive_type_character]
+      = builtin->builtin_character;
+    lai->primitive_type_vector [f_primitive_type_logical]
+      = builtin->builtin_logical;
+    lai->primitive_type_vector [f_primitive_type_logical_s1]
+      = builtin->builtin_logical_s1;
+    lai->primitive_type_vector [f_primitive_type_logical_s2]
+      = builtin->builtin_logical_s2;
+    lai->primitive_type_vector [f_primitive_type_logical_s8]
+      = builtin->builtin_logical_s8;
+    lai->primitive_type_vector [f_primitive_type_real]
+      = builtin->builtin_real;
+    lai->primitive_type_vector [f_primitive_type_real_s8]
+      = builtin->builtin_real_s8;
+    lai->primitive_type_vector [f_primitive_type_real_s16]
+      = builtin->builtin_real_s16;
+    lai->primitive_type_vector [f_primitive_type_complex_s8]
+      = builtin->builtin_complex_s8;
+    lai->primitive_type_vector [f_primitive_type_complex_s16]
+      = builtin->builtin_complex_s16;
+    lai->primitive_type_vector [f_primitive_type_void]
+      = builtin->builtin_void;
+
+    lai->bool_type_symbol = "logical";
+    lai->bool_type_default = builtin->builtin_logical_s2;
+  }
 };
 
 /* Single instance of the Fortran language class.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 0774638145c..a8b478d5a3c 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -523,59 +523,6 @@ enum go_primitive_types {
   nr_go_primitive_types
 };
 
-static void
-go_language_arch_info (struct gdbarch *gdbarch,
-		       struct language_arch_info *lai)
-{
-  const struct builtin_go_type *builtin = builtin_go_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_go_primitive_types + 1,
-			      struct type *);
-
-  lai->primitive_type_vector [go_primitive_type_void]
-    = builtin->builtin_void;
-  lai->primitive_type_vector [go_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [go_primitive_type_bool]
-    = builtin->builtin_bool;
-  lai->primitive_type_vector [go_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [go_primitive_type_uint]
-    = builtin->builtin_uint;
-  lai->primitive_type_vector [go_primitive_type_uintptr]
-    = builtin->builtin_uintptr;
-  lai->primitive_type_vector [go_primitive_type_int8]
-    = builtin->builtin_int8;
-  lai->primitive_type_vector [go_primitive_type_int16]
-    = builtin->builtin_int16;
-  lai->primitive_type_vector [go_primitive_type_int32]
-    = builtin->builtin_int32;
-  lai->primitive_type_vector [go_primitive_type_int64]
-    = builtin->builtin_int64;
-  lai->primitive_type_vector [go_primitive_type_uint8]
-    = builtin->builtin_uint8;
-  lai->primitive_type_vector [go_primitive_type_uint16]
-    = builtin->builtin_uint16;
-  lai->primitive_type_vector [go_primitive_type_uint32]
-    = builtin->builtin_uint32;
-  lai->primitive_type_vector [go_primitive_type_uint64]
-    = builtin->builtin_uint64;
-  lai->primitive_type_vector [go_primitive_type_float32]
-    = builtin->builtin_float32;
-  lai->primitive_type_vector [go_primitive_type_float64]
-    = builtin->builtin_float64;
-  lai->primitive_type_vector [go_primitive_type_complex64]
-    = builtin->builtin_complex64;
-  lai->primitive_type_vector [go_primitive_type_complex128]
-    = builtin->builtin_complex128;
-
-  lai->bool_type_symbol = "bool";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 /* Constant data that describes the Go language.  */
 
 extern const struct language_data go_language_data =
@@ -613,7 +560,6 @@ extern const struct language_data go_language_data =
   0,				/* String lower bound.  */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  go_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -633,6 +579,59 @@ class go_language : public language_defn
   go_language ()
     : language_defn (language_go, go_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_go_type *builtin = builtin_go_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_go_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [go_primitive_type_void]
+      = builtin->builtin_void;
+    lai->primitive_type_vector [go_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [go_primitive_type_bool]
+      = builtin->builtin_bool;
+    lai->primitive_type_vector [go_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [go_primitive_type_uint]
+      = builtin->builtin_uint;
+    lai->primitive_type_vector [go_primitive_type_uintptr]
+      = builtin->builtin_uintptr;
+    lai->primitive_type_vector [go_primitive_type_int8]
+      = builtin->builtin_int8;
+    lai->primitive_type_vector [go_primitive_type_int16]
+      = builtin->builtin_int16;
+    lai->primitive_type_vector [go_primitive_type_int32]
+      = builtin->builtin_int32;
+    lai->primitive_type_vector [go_primitive_type_int64]
+      = builtin->builtin_int64;
+    lai->primitive_type_vector [go_primitive_type_uint8]
+      = builtin->builtin_uint8;
+    lai->primitive_type_vector [go_primitive_type_uint16]
+      = builtin->builtin_uint16;
+    lai->primitive_type_vector [go_primitive_type_uint32]
+      = builtin->builtin_uint32;
+    lai->primitive_type_vector [go_primitive_type_uint64]
+      = builtin->builtin_uint64;
+    lai->primitive_type_vector [go_primitive_type_float32]
+      = builtin->builtin_float32;
+    lai->primitive_type_vector [go_primitive_type_float64]
+      = builtin->builtin_float64;
+    lai->primitive_type_vector [go_primitive_type_complex64]
+      = builtin->builtin_complex64;
+    lai->primitive_type_vector [go_primitive_type_complex128]
+      = builtin->builtin_complex128;
+
+    lai->bool_type_symbol = "bool";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the Go language class.  */
diff --git a/gdb/language.c b/gdb/language.c
index d08628af920..4807ab82b67 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -835,7 +835,6 @@ extern const struct language_data unknown_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  unknown_language_arch_info,	/* la_language_arch_info.  */
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -855,6 +854,13 @@ class unknown_language : public language_defn
   unknown_language ()
     : language_defn (language_unknown, unknown_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    unknown_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -897,7 +903,6 @@ extern const struct language_data auto_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  unknown_language_arch_info,	/* la_language_arch_info.  */
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -917,6 +922,13 @@ class auto_language : public language_defn
   auto_language ()
     : language_defn (language_auto, auto_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    unknown_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
@@ -942,11 +954,11 @@ language_gdbarch_post_init (struct gdbarch *gdbarch)
 
   l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
   for (const auto &lang : language_defn::languages)
-    if (lang != NULL && lang->la_language_arch_info != NULL)
-      {
-	lang->la_language_arch_info (gdbarch,
-				     l->arch_info + lang->la_language);
-      }
+    {
+      gdb_assert (lang != nullptr);
+      lang->language_arch_info (gdbarch,
+				l->arch_info + lang->la_language);
+    }
 
   return l;
 }
diff --git a/gdb/language.h b/gdb/language.h
index 21539374e89..b928e10bb80 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -368,10 +368,6 @@ struct language_data
        const char *word,
        enum type_code code);
 
-    /* The per-architecture (OS/ABI) language information.  */
-    void (*la_language_arch_info) (struct gdbarch *,
-				   struct language_arch_info *);
-
     /* Return an expression that can be used for a location
        watchpoint.  TYPE is a pointer type that points to the memory
        to watch, and ADDR is the address of the watched memory.  */
@@ -502,6 +498,11 @@ struct language_defn : language_data
     return {};
   }
 
+  /* The per-architecture (OS/ABI) language information.  */
+
+  virtual void language_arch_info (struct gdbarch *,
+				   struct language_arch_info *) const = 0;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 5b83404720d..de12f30fee1 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -339,32 +339,6 @@ enum m2_primitive_types {
   nr_m2_primitive_types
 };
 
-static void
-m2_language_arch_info (struct gdbarch *gdbarch,
-		       struct language_arch_info *lai)
-{
-  const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
-                              struct type *);
-
-  lai->primitive_type_vector [m2_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [m2_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [m2_primitive_type_card]
-    = builtin->builtin_card;
-  lai->primitive_type_vector [m2_primitive_type_real]
-    = builtin->builtin_real;
-  lai->primitive_type_vector [m2_primitive_type_bool]
-    = builtin->builtin_bool;
-
-  lai->bool_type_symbol = "BOOLEAN";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 const struct exp_descriptor exp_descriptor_modula2 = 
 {
   print_subexp_standard,
@@ -411,7 +385,6 @@ extern const struct language_data m2_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  m2_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -431,6 +404,32 @@ class m2_language : public language_defn
   m2_language ()
     : language_defn (language_m2, m2_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
+				struct type *);
+
+    lai->primitive_type_vector [m2_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [m2_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [m2_primitive_type_card]
+      = builtin->builtin_card;
+    lai->primitive_type_vector [m2_primitive_type_real]
+      = builtin->builtin_real;
+    lai->primitive_type_vector [m2_primitive_type_bool]
+      = builtin->builtin_bool;
+
+    lai->bool_type_symbol = "BOOLEAN";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index cf5b91b3388..87e5e681ec4 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -400,7 +400,6 @@ extern const struct language_data objc_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  c_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -420,6 +419,13 @@ class objc_language : public language_defn
   objc_language ()
     : language_defn (language_objc, objc_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    c_language_arch_info (gdbarch, lai);
+  }
 };
 
 /* Single instance of the class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 450e391ccec..2b7febe7cf4 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1015,23 +1015,6 @@ opencl_print_type (struct type *type, const char *varstring,
   c_print_type (type, varstring, stream, show, level, flags); 
 }
 
-static void
-opencl_language_arch_info (struct gdbarch *gdbarch,
-			   struct language_arch_info *lai)
-{
-  struct type **types = builtin_opencl_type (gdbarch);
-
-  /* Copy primitive types vector from gdbarch.  */
-  lai->primitive_type_vector = types;
-
-  /* Type of elements of strings.  */
-  lai->string_char_type = types [opencl_primitive_type_char];
-
-  /* Specifies the return type of logical and relational operations.  */
-  lai->bool_type_symbol = "int";
-  lai->bool_type_default = types [opencl_primitive_type_int];
-}
-
 const struct exp_descriptor exp_descriptor_opencl =
 {
   print_subexp_standard,
@@ -1077,7 +1060,6 @@ extern const struct language_data opencl_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  opencl_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -1097,6 +1079,23 @@ class opencl_language : public language_defn
   opencl_language ()
     : language_defn (language_opencl, opencl_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    struct type **types = builtin_opencl_type (gdbarch);
+
+    /* Copy primitive types vector from gdbarch.  */
+    lai->primitive_type_vector = types;
+
+    /* Type of elements of strings.  */
+    lai->string_char_type = types [opencl_primitive_type_char];
+
+    /* Specifies the return type of logical and relational operations.  */
+    lai->bool_type_symbol = "int";
+    lai->bool_type_default = types [opencl_primitive_type_int];
+  }
 };
 
 /* Single instance of the OpenCL language class.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 9f0d02215b1..7899a656449 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -375,55 +375,6 @@ enum pascal_primitive_types {
   nr_pascal_primitive_types
 };
 
-static void
-pascal_language_arch_info (struct gdbarch *gdbarch,
-			   struct language_arch_info *lai)
-{
-  const struct builtin_type *builtin = builtin_type (gdbarch);
-
-  lai->string_char_type = builtin->builtin_char;
-  lai->primitive_type_vector
-    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_pascal_primitive_types + 1,
-                              struct type *);
-  lai->primitive_type_vector [pascal_primitive_type_int]
-    = builtin->builtin_int;
-  lai->primitive_type_vector [pascal_primitive_type_long]
-    = builtin->builtin_long;
-  lai->primitive_type_vector [pascal_primitive_type_short]
-    = builtin->builtin_short;
-  lai->primitive_type_vector [pascal_primitive_type_char]
-    = builtin->builtin_char;
-  lai->primitive_type_vector [pascal_primitive_type_float]
-    = builtin->builtin_float;
-  lai->primitive_type_vector [pascal_primitive_type_double]
-    = builtin->builtin_double;
-  lai->primitive_type_vector [pascal_primitive_type_void]
-    = builtin->builtin_void;
-  lai->primitive_type_vector [pascal_primitive_type_long_long]
-    = builtin->builtin_long_long;
-  lai->primitive_type_vector [pascal_primitive_type_signed_char]
-    = builtin->builtin_signed_char;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_char]
-    = builtin->builtin_unsigned_char;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_short]
-    = builtin->builtin_unsigned_short;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_int]
-    = builtin->builtin_unsigned_int;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_long]
-    = builtin->builtin_unsigned_long;
-  lai->primitive_type_vector [pascal_primitive_type_unsigned_long_long]
-    = builtin->builtin_unsigned_long_long;
-  lai->primitive_type_vector [pascal_primitive_type_long_double]
-    = builtin->builtin_long_double;
-  lai->primitive_type_vector [pascal_primitive_type_complex]
-    = builtin->builtin_complex;
-  lai->primitive_type_vector [pascal_primitive_type_double_complex]
-    = builtin->builtin_double_complex;
-
-  lai->bool_type_symbol = "boolean";
-  lai->bool_type_default = builtin->builtin_bool;
-}
-
 static const char *p_extensions[] =
 {
   ".pas", ".p", ".pp", NULL
@@ -464,7 +415,6 @@ extern const struct language_data pascal_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  pascal_language_arch_info,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
   iterate_over_symbols,
@@ -484,6 +434,55 @@ class pascal_language : public language_defn
   pascal_language ()
     : language_defn (language_pascal, pascal_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_type *builtin = builtin_type (gdbarch);
+
+    lai->string_char_type = builtin->builtin_char;
+    lai->primitive_type_vector
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_pascal_primitive_types + 1,
+                              struct type *);
+    lai->primitive_type_vector [pascal_primitive_type_int]
+      = builtin->builtin_int;
+    lai->primitive_type_vector [pascal_primitive_type_long]
+      = builtin->builtin_long;
+    lai->primitive_type_vector [pascal_primitive_type_short]
+      = builtin->builtin_short;
+    lai->primitive_type_vector [pascal_primitive_type_char]
+      = builtin->builtin_char;
+    lai->primitive_type_vector [pascal_primitive_type_float]
+      = builtin->builtin_float;
+    lai->primitive_type_vector [pascal_primitive_type_double]
+      = builtin->builtin_double;
+    lai->primitive_type_vector [pascal_primitive_type_void]
+      = builtin->builtin_void;
+    lai->primitive_type_vector [pascal_primitive_type_long_long]
+      = builtin->builtin_long_long;
+    lai->primitive_type_vector [pascal_primitive_type_signed_char]
+      = builtin->builtin_signed_char;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_char]
+      = builtin->builtin_unsigned_char;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_short]
+      = builtin->builtin_unsigned_short;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_int]
+      = builtin->builtin_unsigned_int;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_long]
+      = builtin->builtin_unsigned_long;
+    lai->primitive_type_vector [pascal_primitive_type_unsigned_long_long]
+      = builtin->builtin_unsigned_long_long;
+    lai->primitive_type_vector [pascal_primitive_type_long_double]
+      = builtin->builtin_long_double;
+    lai->primitive_type_vector [pascal_primitive_type_complex]
+      = builtin->builtin_complex;
+    lai->primitive_type_vector [pascal_primitive_type_double_complex]
+      = builtin->builtin_double_complex;
+
+    lai->bool_type_symbol = "boolean";
+    lai->bool_type_default = builtin->builtin_bool;
+  }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index bd7174a1255..a8bc2a6d9f5 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1066,51 +1066,6 @@ enum rust_primitive_types
   nr_rust_primitive_types
 };
 
-/* la_language_arch_info implementation for Rust.  */
-
-static void
-rust_language_arch_info (struct gdbarch *gdbarch,
-			 struct language_arch_info *lai)
-{
-  const struct builtin_type *builtin = builtin_type (gdbarch);
-  struct type *tem;
-  struct type **types;
-  unsigned int length;
-
-  types = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_rust_primitive_types + 1,
-				  struct type *);
-
-  types[rust_primitive_bool] = arch_boolean_type (gdbarch, 8, 1, "bool");
-  types[rust_primitive_char] = arch_character_type (gdbarch, 32, 1, "char");
-  types[rust_primitive_i8] = arch_integer_type (gdbarch, 8, 0, "i8");
-  types[rust_primitive_u8] = arch_integer_type (gdbarch, 8, 1, "u8");
-  types[rust_primitive_i16] = arch_integer_type (gdbarch, 16, 0, "i16");
-  types[rust_primitive_u16] = arch_integer_type (gdbarch, 16, 1, "u16");
-  types[rust_primitive_i32] = arch_integer_type (gdbarch, 32, 0, "i32");
-  types[rust_primitive_u32] = arch_integer_type (gdbarch, 32, 1, "u32");
-  types[rust_primitive_i64] = arch_integer_type (gdbarch, 64, 0, "i64");
-  types[rust_primitive_u64] = arch_integer_type (gdbarch, 64, 1, "u64");
-
-  length = 8 * TYPE_LENGTH (builtin->builtin_data_ptr);
-  types[rust_primitive_isize] = arch_integer_type (gdbarch, length, 0, "isize");
-  types[rust_primitive_usize] = arch_integer_type (gdbarch, length, 1, "usize");
-
-  types[rust_primitive_f32] = arch_float_type (gdbarch, 32, "f32",
-					       floatformats_ieee_single);
-  types[rust_primitive_f64] = arch_float_type (gdbarch, 64, "f64",
-					       floatformats_ieee_double);
-
-  types[rust_primitive_unit] = arch_integer_type (gdbarch, 0, 1, "()");
-
-  tem = make_cv_type (1, 0, types[rust_primitive_u8], NULL);
-  types[rust_primitive_str] = rust_slice_type ("&str", tem,
-					       types[rust_primitive_usize]);
-
-  lai->primitive_type_vector = types;
-  lai->bool_type_default = types[rust_primitive_bool];
-  lai->string_char_type = types[rust_primitive_u8];
-}
-
 \f
 
 /* A helper for rust_evaluate_subexp that handles OP_FUNCALL.  */
@@ -2137,7 +2092,6 @@ extern const struct language_data rust_language_data =
   0,				/* String lower bound */
   default_word_break_characters,
   default_collect_symbol_completion_matches,
-  rust_language_arch_info,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
   iterate_over_symbols,
@@ -2157,6 +2111,47 @@ class rust_language : public language_defn
   rust_language ()
     : language_defn (language_rust, rust_language_data)
   { /* Nothing.  */ }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override
+  {
+    const struct builtin_type *builtin = builtin_type (gdbarch);
+
+    struct type **types
+      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_rust_primitive_types + 1,
+				struct type *);
+
+    types[rust_primitive_bool] = arch_boolean_type (gdbarch, 8, 1, "bool");
+    types[rust_primitive_char] = arch_character_type (gdbarch, 32, 1, "char");
+    types[rust_primitive_i8] = arch_integer_type (gdbarch, 8, 0, "i8");
+    types[rust_primitive_u8] = arch_integer_type (gdbarch, 8, 1, "u8");
+    types[rust_primitive_i16] = arch_integer_type (gdbarch, 16, 0, "i16");
+    types[rust_primitive_u16] = arch_integer_type (gdbarch, 16, 1, "u16");
+    types[rust_primitive_i32] = arch_integer_type (gdbarch, 32, 0, "i32");
+    types[rust_primitive_u32] = arch_integer_type (gdbarch, 32, 1, "u32");
+    types[rust_primitive_i64] = arch_integer_type (gdbarch, 64, 0, "i64");
+    types[rust_primitive_u64] = arch_integer_type (gdbarch, 64, 1, "u64");
+
+    unsigned int length = 8 * TYPE_LENGTH (builtin->builtin_data_ptr);
+    types[rust_primitive_isize] = arch_integer_type (gdbarch, length, 0, "isize");
+    types[rust_primitive_usize] = arch_integer_type (gdbarch, length, 1, "usize");
+
+    types[rust_primitive_f32] = arch_float_type (gdbarch, 32, "f32",
+						 floatformats_ieee_single);
+    types[rust_primitive_f64] = arch_float_type (gdbarch, 64, "f64",
+						 floatformats_ieee_double);
+
+    types[rust_primitive_unit] = arch_integer_type (gdbarch, 0, 1, "()");
+
+    struct type *tem = make_cv_type (1, 0, types[rust_primitive_u8], NULL);
+    types[rust_primitive_str] = rust_slice_type ("&str", tem,
+						 types[rust_primitive_usize]);
+
+    lai->primitive_type_vector = types;
+    lai->bool_type_default = types[rust_primitive_bool];
+    lai->string_char_type = types[rust_primitive_u8];
+  }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 06/13] gdb: Convert language la_lookup_transparent_type field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (4 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 05/13] gdb: Convert language la_language_arch_info " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 07/13] gdb: Convert language la_iterate_over_symbols " Andrew Burgess
                     ` (8 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_lookup_transparent_type
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete
	la_lookup_transparent_type initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(cplus_language::lookup_transparent_type): New member function.
	(asm_language_data): Delete la_lookup_transparent_type
	initializer.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (struct language_data): Delete
	la_lookup_transparent_type field.
	(language_defn::lookup_transparent_type): New member function.
	* m2-lang.c (m2_language_data): Delete la_lookup_transparent_type
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	* symtab.c (symbol_matches_domain): Update call.
---
 gdb/ChangeLog     | 26 ++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      | 10 ++++++----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 gdb/language.h    | 10 +++++++---
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 gdb/symtab.c      |  2 +-
 14 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7e6ee9e5757..e2d9aa7ab3a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13985,7 +13985,6 @@ extern const struct language_data ada_language_data =
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
-  basic_lookup_transparent_type,        /* lookup_transparent_type */
   ada_la_decode,                /* Language specific symbol demangler */
   ada_sniff_from_mangled_name,
   NULL,                         /* Language specific
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 84303954dd7..2eead3d8305 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -911,7 +911,6 @@ extern const struct language_data c_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
@@ -1012,7 +1011,6 @@ extern const struct language_data cplus_language_data =
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  cp_lookup_transparent_type,   /* lookup_transparent_type */
   gdb_demangle,			/* Language specific symbol demangler */
   gdb_sniff_from_mangled_name,
   cp_class_name_from_physname,  /* Language specific
@@ -1112,6 +1110,12 @@ class cplus_language : public language_defn
     lai->bool_type_symbol = "bool";
     lai->bool_type_default = builtin->builtin_bool;
   }
+
+  /* See language.h.  */
+  struct type *lookup_transparent_type (const char *name) const override
+  {
+    return cp_lookup_transparent_type (name);
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1149,7 +1153,6 @@ extern const struct language_data asm_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
@@ -1221,7 +1224,6 @@ extern const struct language_data minimal_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 778d77313c9..8c4ee44ac97 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -165,7 +165,6 @@ extern const struct language_data d_language_data =
   "this",
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_lookup_symbol_nonlocal,
-  basic_lookup_transparent_type,
   d_demangle,			/* Language specific symbol demangler.  */
   d_sniff_from_mangled_name,
   NULL,				/* Language specific
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 1eeb5070dee..32435fa856a 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -616,7 +616,6 @@ extern const struct language_data f_language_data =
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
 
   /* We could support demangling here to provide module namespaces
      also for inferiors with only minimal symbol table (ELF symbols).
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index a8b478d5a3c..edd4e7f167e 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -550,7 +550,6 @@ extern const struct language_data go_language_data =
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, 
-  basic_lookup_transparent_type,
   go_demangle,			/* Language specific symbol demangler.  */
   go_sniff_from_mangled_name,
   NULL,				/* Language specific
diff --git a/gdb/language.c b/gdb/language.c
index 4807ab82b67..d06cf4ac71a 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -825,7 +825,6 @@ extern const struct language_data unknown_language_data =
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
   NULL,
   unk_lang_class_name,		/* Language specific
@@ -893,7 +892,6 @@ extern const struct language_data auto_language_data =
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   unk_lang_demangle,		/* Language specific symbol demangler */
   NULL,
   unk_lang_class_name,		/* Language specific
diff --git a/gdb/language.h b/gdb/language.h
index b928e10bb80..a5ca641194f 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -315,9 +315,6 @@ struct language_data
        const struct block *,
        const domain_enum);
 
-    /* Find the definition of the type with the given name.  */
-    struct type *(*la_lookup_transparent_type) (const char *);
-
     /* Return demangled language symbol, or NULL.  */
     char *(*la_demangle) (const char *mangled, int options);
 
@@ -503,6 +500,13 @@ struct language_defn : language_data
   virtual void language_arch_info (struct gdbarch *,
 				   struct language_arch_info *) const = 0;
 
+  /* Find the definition of the type with the given name.  */
+
+  virtual struct type *lookup_transparent_type (const char *name) const
+  {
+    return basic_lookup_transparent_type (name);
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index de12f30fee1..71e26869424 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -375,7 +375,6 @@ extern const struct language_data m2_language_data =
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 87e5e681ec4..040226c81d5 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -390,7 +390,6 @@ extern const struct language_data objc_language_data =
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   objc_demangle,		/* Language specific symbol demangler */
   objc_sniff_from_mangled_name,
   NULL,				/* Language specific
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 2b7febe7cf4..55baac56b8c 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1050,7 +1050,6 @@ extern const struct language_data opencl_language_data =
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 7899a656449..287c01f2009 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -406,7 +406,6 @@ extern const struct language_data pascal_language_data =
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   NULL,				/* Language specific symbol demangler */
   NULL,
   NULL,				/* Language specific class_name_from_physname */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index a8bc2a6d9f5..e12a941afe2 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2082,7 +2082,6 @@ extern const struct language_data rust_language_data =
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   rust_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  basic_lookup_transparent_type,/* lookup_transparent_type */
   gdb_demangle,			/* Language specific symbol demangler */
   rust_sniff_from_mangled_name,
   NULL,				/* Language specific
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 2043d084140..817559fec1f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2738,7 +2738,7 @@ symbol_matches_domain (enum language symbol_language,
 struct type *
 lookup_transparent_type (const char *name)
 {
-  return current_language->la_lookup_transparent_type (name);
+  return current_language->lookup_transparent_type (name);
 }
 
 /* A helper for basic_lookup_transparent_type that interfaces with the
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 07/13] gdb: Convert language la_iterate_over_symbols field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (5 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 06/13] gdb: Convert language la_lookup_transparent_type " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 08/13] gdb: Convert language la_get_compile_instance " Andrew Burgess
                     ` (7 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_iterate_over_symbols
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_add_all_symbols): Update comment.
	(ada_iterate_over_symbols): Delete, move implementation to...
	(ada_language::iterate_over_symbols): ...here, a new member
	function, rewrite to use range based for loop.
	(ada_language_data): Delete la_iterate_over_symbols initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_iterate_over_symbols field.
	(language_defn::iterate_over_symbols): New member function.
	(LA_ITERATE_OVER_SYMBOLS): Update.
	* linespec.c (iterate_over_all_matching_symtabs): Update.
	* m2-lang.c (m2_language_data): Delete la_iterate_over_symbols
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog     | 27 +++++++++++++++++++++++++++
 gdb/ada-lang.c    | 44 ++++++++++++++++++++------------------------
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 gdb/language.h    | 41 ++++++++++++++++++++++-------------------
 gdb/linespec.c    |  2 +-
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 14 files changed, 70 insertions(+), 58 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e2d9aa7ab3a..ede6f90b422 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5686,7 +5686,7 @@ ada_add_all_symbols (struct obstack *obstackp,
       else
 	{
 	  /* In the !full_search case we're are being called by
-	     ada_iterate_over_symbols, and we don't want to search
+	     iterate_over_symbols, and we don't want to search
 	     superblocks.  */
 	  ada_add_block_symbols (obstackp, block, lookup_name, domain, NULL);
 	}
@@ -5787,28 +5787,6 @@ ada_lookup_symbol_list (const char *name, const struct block *block,
   return ada_lookup_symbol_list_worker (lookup_name, block, domain, results, 1);
 }
 
-/* Implementation of the la_iterate_over_symbols method.  */
-
-static bool
-ada_iterate_over_symbols
-  (const struct block *block, const lookup_name_info &name,
-   domain_enum domain,
-   gdb::function_view<symbol_found_callback_ftype> callback)
-{
-  int ndefs, i;
-  std::vector<struct block_symbol> results;
-
-  ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
-
-  for (i = 0; i < ndefs; ++i)
-    {
-      if (!callback (&results[i]))
-	return false;
-    }
-
-  return true;
-}
-
 /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
    to 1, but choosing the first symbol found if there are multiple
    choices.
@@ -13996,7 +13974,6 @@ extern const struct language_data ada_language_data =
   ada_collect_symbol_completion_matches,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
-  ada_iterate_over_symbols,
   default_search_name_hash,
   &ada_varobj_ops,
   NULL,
@@ -14108,6 +14085,25 @@ class ada_language : public language_defn
     lai->bool_type_symbol = NULL;
     lai->bool_type_default = builtin->builtin_bool;
   }
+
+  /* See language.h.  */
+
+  bool iterate_over_symbols
+	(const struct block *block, const lookup_name_info &name,
+	 domain_enum domain,
+	 gdb::function_view<symbol_found_callback_ftype> callback) const override
+  {
+    std::vector<struct block_symbol> results;
+
+    ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
+    for (block_symbol &sym : results)
+      {
+	if (!callback (&sym))
+	  return false;
+      }
+
+    return true;
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 2eead3d8305..f6fd3b3d287 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -922,7 +922,6 @@ extern const struct language_data c_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &c_varobj_ops,
   c_get_compile_context,
@@ -1022,7 +1021,6 @@ extern const struct language_data cplus_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
-  iterate_over_symbols,
   cp_search_name_hash,
   &cplus_varobj_ops,
   cplus_get_compile_context,
@@ -1164,7 +1162,6 @@ extern const struct language_data asm_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
@@ -1235,7 +1232,6 @@ extern const struct language_data minimal_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 8c4ee44ac97..57327780214 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -176,7 +176,6 @@ extern const struct language_data d_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 32435fa856a..ae559dee812 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -633,7 +633,6 @@ extern const struct language_data f_language_data =
   f_collect_symbol_completion_matches,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   cp_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index edd4e7f167e..7e0bd5d0934 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -561,7 +561,6 @@ extern const struct language_data go_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/language.c b/gdb/language.c
index d06cf4ac71a..7670db7d3ce 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -836,7 +836,6 @@ extern const struct language_data unknown_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
@@ -903,7 +902,6 @@ extern const struct language_data auto_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/language.h b/gdb/language.h
index a5ca641194f..73d7f7a3edb 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -384,24 +384,6 @@ struct language_data
     symbol_name_matcher_ftype *(*la_get_symbol_name_matcher)
       (const lookup_name_info &);
 
-    /* Find all symbols in the current program space matching NAME in
-       DOMAIN, according to this language's rules.
-
-       The search is done in BLOCK only.
-       The caller is responsible for iterating up through superblocks
-       if desired.
-
-       For each one, call CALLBACK with the symbol.  If CALLBACK
-       returns false, the iteration ends at that point.
-
-       This field may not be NULL.  If the language does not need any
-       special processing here, 'iterate_over_symbols' should be
-       used as the definition.  */
-    bool (*la_iterate_over_symbols)
-      (const struct block *block, const lookup_name_info &name,
-       domain_enum domain,
-       gdb::function_view<symbol_found_callback_ftype> callback);
-
     /* Hash the given symbol search name.  Use
        default_search_name_hash if no special treatment is
        required.  */
@@ -507,6 +489,27 @@ struct language_defn : language_data
     return basic_lookup_transparent_type (name);
   }
 
+  /* Find all symbols in the current program space matching NAME in
+     DOMAIN, according to this language's rules.
+
+     The search is done in BLOCK only.
+     The caller is responsible for iterating up through superblocks
+     if desired.
+
+     For each one, call CALLBACK with the symbol.  If CALLBACK
+     returns false, the iteration ends at that point.
+
+     This field may not be NULL.  If the language does not need any
+     special processing here, 'iterate_over_symbols' should be
+     used as the definition.  */
+  virtual bool iterate_over_symbols
+	(const struct block *block, const lookup_name_info &name,
+	 domain_enum domain,
+	 gdb::function_view<symbol_found_callback_ftype> callback) const
+  {
+    return ::iterate_over_symbols (block, name, domain, callback);
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
@@ -615,7 +618,7 @@ extern enum language set_language (enum language);
   (current_language->print_array_index(index_value, stream, options))
 
 #define LA_ITERATE_OVER_SYMBOLS(BLOCK, NAME, DOMAIN, CALLBACK) \
-  (current_language->la_iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK))
+  (current_language->iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK))
 
 /* Test a character to decide whether it can be printed in literal form
    or needs to be printed in another representation.  For example,
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 1e70cdb0dca..d891e05ab7d 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1168,7 +1168,7 @@ iterate_over_all_matching_symtabs
 		       i++)
 		    {
 		      block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), i);
-		      state->language->la_iterate_over_symbols
+		      state->language->iterate_over_symbols
 			(block, lookup_name, name_domain,
 			 [&] (block_symbol *bsym)
 			 {
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 71e26869424..128d236f880 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -386,7 +386,6 @@ extern const struct language_data m2_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 040226c81d5..6cf8bbbe091 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -401,7 +401,6 @@ extern const struct language_data objc_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 55baac56b8c..ebb07eb5c00 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1061,7 +1061,6 @@ extern const struct language_data opencl_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 287c01f2009..52d202786c0 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -416,7 +416,6 @@ extern const struct language_data pascal_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index e12a941afe2..2268ac3daf7 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2093,7 +2093,6 @@ extern const struct language_data rust_language_data =
   default_collect_symbol_completion_matches,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  iterate_over_symbols,
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 08/13] gdb: Convert language la_get_compile_instance field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (6 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 07/13] gdb: Convert language la_iterate_over_symbols " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 09/13] gdb: Convert language la_search_name_hash " Andrew Burgess
                     ` (6 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_get_compile_instance
function pointer member variable into a member function of
language_defn.  Unlike previous commits converting fields of
language_data to member function in language_defn, this field is NULL
for some languages.  As a result I had to change the API slightly so
that the base language_defn class provides an implementation.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_get_compile_instance
	initializer.
	* c-lang.c (class compile_instance): Declare.
	(c_language_data): Delete la_get_compile_instance initializer.
	(c_language::get_compile_instance): New member function.
	(cplus_language_data): Delete la_get_compile_instance initializer.
	(cplus_language::get_compile_instance): New member function.
	(asm_language_data): Delete la_get_compile_instance initializer.
	(minimal_language_data): Likewise.
	* c-lang.h (c_get_compile_context): Update comment.
	(cplus_get_compile_context): Update comment.
	* compile/compile.c (compile_to_object): Update calls, don't rely
	on function pointer being NULL.
	* d-lang.c (d_language_data): Delete la_get_compile_instance
	initializer.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_get_compile_instance field.
	(language_defn::get_compile_instance): New member function.
	* m2-lang.c (m2_language_data): Delete la_get_compile_instance
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog         | 30 ++++++++++++++++++++++++++++++
 gdb/ada-lang.c        |  1 -
 gdb/c-lang.c          | 18 ++++++++++++++----
 gdb/c-lang.h          |  4 ++--
 gdb/compile/compile.c |  8 +++-----
 gdb/d-lang.c          |  1 -
 gdb/f-lang.c          |  1 -
 gdb/go-lang.c         |  1 -
 gdb/language.c        |  2 --
 gdb/language.h        | 23 +++++++++++++----------
 gdb/m2-lang.c         |  1 -
 gdb/objc-lang.c       |  1 -
 gdb/opencl-lang.c     |  1 -
 gdb/p-lang.c          |  1 -
 gdb/rust-lang.c       |  1 -
 15 files changed, 62 insertions(+), 32 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index ede6f90b422..d0d8925acdb 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13977,7 +13977,6 @@ extern const struct language_data ada_language_data =
   default_search_name_hash,
   &ada_varobj_ops,
   NULL,
-  NULL,
   ada_is_string_type,
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index f6fd3b3d287..a74fd72ac08 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -37,6 +37,8 @@
 #include "gdbcore.h"
 #include "gdbarch.h"
 
+class compile_instance;
+
 /* Given a C string type, STR_TYPE, return the corresponding target
    character set name.  */
 
@@ -924,7 +926,6 @@ extern const struct language_data c_language_data =
   NULL,				/* la_get_symbol_name_matcher */
   default_search_name_hash,
   &c_varobj_ops,
-  c_get_compile_context,
   c_compute_program,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
@@ -945,6 +946,12 @@ class c_language : public language_defn
   {
     c_language_arch_info (gdbarch, lai);
   }
+
+  /* See language.h.  */
+  compile_instance *get_compile_instance () const override
+  {
+    return c_get_compile_context ();
+  }
 };
 
 /* Single instance of the C language class.  */
@@ -1023,7 +1030,6 @@ extern const struct language_data cplus_language_data =
   cp_get_symbol_name_matcher,
   cp_search_name_hash,
   &cplus_varobj_ops,
-  cplus_get_compile_context,
   cplus_compute_program,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
@@ -1114,6 +1120,12 @@ class cplus_language : public language_defn
   {
     return cp_lookup_transparent_type (name);
   }
+
+  /* See language.h.  */
+  compile_instance *get_compile_instance () const override
+  {
+    return cplus_get_compile_context ();
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1165,7 +1177,6 @@ extern const struct language_data asm_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
@@ -1235,7 +1246,6 @@ extern const struct language_data minimal_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/c-lang.h b/gdb/c-lang.h
index 642157125a8..3e07dc9c88d 100644
--- a/gdb/c-lang.h
+++ b/gdb/c-lang.h
@@ -157,7 +157,7 @@ extern int c_textual_element_type (struct type *, char);
    compiler is owned by the caller and must be freed using the destroy
    method.  This function never returns NULL, but rather throws an
    exception on failure.  This is suitable for use as the
-   la_get_compile_instance language method.  */
+   language_defn::get_compile_instance method.  */
 
 extern compile_instance *c_get_compile_context (void);
 
@@ -165,7 +165,7 @@ extern compile_instance *c_get_compile_context (void);
    compiler is owned by the caller and must be freed using the destroy
    method.  This function never returns NULL, but rather throws an
    exception on failure.  This is suitable for use as the
-   la_get_compile_instance language method.  */
+   language_defn::get_compile_instance method.  */
 
 extern compile_instance *cplus_get_compile_context ();
 
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 8d134d9cf18..3a3afa85736 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -691,13 +691,11 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
   expr_pc = get_frame_address_in_block (get_selected_frame (NULL));
 
   /* Set up instance and context for the compiler.  */
-  if (current_language->la_get_compile_instance == NULL)
+  std::unique_ptr <compile_instance> compiler
+			(current_language->get_compile_instance ());
+  if (compiler == nullptr)
     error (_("No compiler support for language %s."),
 	   current_language->la_name);
-
-  compile_instance *compiler_instance
-    = current_language->la_get_compile_instance ();
-  std::unique_ptr<compile_instance> compiler (compiler_instance);
   compiler->set_print_callback (print_callback, NULL);
   compiler->set_scope (scope);
   compiler->set_block (expr_block);
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 57327780214..08b884de733 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -179,7 +179,6 @@ extern const struct language_data d_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index ae559dee812..9e647f5374e 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -636,7 +636,6 @@ extern const struct language_data f_language_data =
   cp_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   f_is_string_type_p,
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 7e0bd5d0934..ea4058d63e1 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -564,7 +564,6 @@ extern const struct language_data go_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   go_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/language.c b/gdb/language.c
index 7670db7d3ce..a6b7f1400d5 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -839,7 +839,6 @@ extern const struct language_data unknown_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   default_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
@@ -905,7 +904,6 @@ extern const struct language_data auto_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   default_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/language.h b/gdb/language.h
index 73d7f7a3edb..15627506391 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -392,16 +392,6 @@ struct language_data
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
 
-    /* If this language allows compilation from the gdb command line,
-       this method should be non-NULL.  When called it should return
-       an instance of struct gcc_context appropriate to the language.
-       When defined this method must never return NULL; instead it
-       should throw an exception on failure.  The returned compiler
-       instance is owned by its caller and must be deallocated by
-       calling its 'destroy' method.  */
-
-    compile_instance *(*la_get_compile_instance) (void);
-
     /* This method must be defined if 'la_get_gcc_context' is defined.
        If 'la_get_gcc_context' is not defined, then this method is
        ignored.
@@ -510,6 +500,19 @@ struct language_defn : language_data
     return ::iterate_over_symbols (block, name, domain, callback);
   }
 
+  /* If this language allows compilation from the gdb command line, then
+     this method will return an instance of struct gcc_context appropriate
+     to the language.  If compilation for this language is generally
+     supported, but something goes wrong then an exception is thrown.  The
+     returned compiler instance is owned by its caller and must be
+     deallocated by the caller.  If compilation is not supported for this
+     language then this method returns NULL.  */
+
+  virtual compile_instance *get_compile_instance () const
+  {
+    return nullptr;
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 128d236f880..eb7ece58efd 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -389,7 +389,6 @@ extern const struct language_data m2_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   m2_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 6cf8bbbe091..4a84f84cb88 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -404,7 +404,6 @@ extern const struct language_data objc_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index ebb07eb5c00..cc479c153fc 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1064,7 +1064,6 @@ extern const struct language_data opencl_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 52d202786c0..1c0222e6c1f 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -419,7 +419,6 @@ extern const struct language_data pascal_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   pascal_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 2268ac3daf7..dc646507de5 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2096,7 +2096,6 @@ extern const struct language_data rust_language_data =
   default_search_name_hash,
   &default_varobj_ops,
   NULL,
-  NULL,
   rust_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 09/13] gdb: Convert language la_search_name_hash field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (7 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 08/13] gdb: Convert language la_get_compile_instance " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 17:47     ` Christian Biesinger
  2020-05-15 15:06   ` [PATCHv2 10/13] gdb: Convert language la_sniff_from_mangled_name " Andrew Burgess
                     ` (5 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_search_name_hash
function pointer member variable into a member function of
language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_search_name_hash
	initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(cplus_language::search_name_hash): New member function.
	(asm_language_data): Delete la_search_name_hash initializer.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* dictionary.c (default_search_name_hash): Rename to...
	(language_defn::search_name_hash): ...this.
	* f-lang.c (f_language_data): Likewise.
	(f_language::search_name_hash): New member function.
	* go-lang.c (go_language_data): Delete la_search_name_hash
	initializer.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (struct language_data): Delete la_search_name_hash
	field.
	(language_defn::search_name_hash): Declare new member function.
	(default_search_name_hash): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_search_name_hash
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	* symtab.c (search_name_hash): Update call.
---
 gdb/ChangeLog     | 30 ++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      | 10 ++++++----
 gdb/d-lang.c      |  1 -
 gdb/dictionary.c  |  2 +-
 gdb/f-lang.c      |  7 ++++++-
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  3 +--
 gdb/language.h    | 16 +++-------------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 gdb/symtab.c      |  2 +-
 15 files changed, 48 insertions(+), 30 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index d0d8925acdb..f2b941969f3 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13974,7 +13974,6 @@ extern const struct language_data ada_language_data =
   ada_collect_symbol_completion_matches,
   ada_watch_location_expression,
   ada_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &ada_varobj_ops,
   NULL,
   ada_is_string_type,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index a74fd72ac08..8cdcfd9b63f 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -924,7 +924,6 @@ extern const struct language_data c_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &c_varobj_ops,
   c_compute_program,
   c_is_string_type_p,
@@ -1028,7 +1027,6 @@ extern const struct language_data cplus_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,
-  cp_search_name_hash,
   &cplus_varobj_ops,
   cplus_compute_program,
   c_is_string_type_p,
@@ -1126,6 +1124,12 @@ class cplus_language : public language_defn
   {
     return cplus_get_compile_context ();
   }
+
+  /* See language.h.  */
+  unsigned int search_name_hash (const char *name) const override
+  {
+    return cp_search_name_hash (name);
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1174,7 +1178,6 @@ extern const struct language_data asm_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
@@ -1243,7 +1246,6 @@ extern const struct language_data minimal_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 08b884de733..c6ee6a231e6 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -176,7 +176,6 @@ extern const struct language_data d_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
diff --git a/gdb/dictionary.c b/gdb/dictionary.c
index 0e873b6cc4d..da44946a98c 100644
--- a/gdb/dictionary.c
+++ b/gdb/dictionary.c
@@ -719,7 +719,7 @@ expand_hashtable (struct dictionary *dict)
 /* See dictionary.h.  */
 
 unsigned int
-default_search_name_hash (const char *string0)
+language_defn::search_name_hash (const char *string0) const
 {
   /* The Ada-encoded version of a name P1.P2...Pn has either the form
      P1__P2__...Pn<suffix> or _ada_P1__P2__...Pn<suffix> (where the Pi
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 9e647f5374e..a2df46a8b4a 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -633,7 +633,6 @@ extern const struct language_data f_language_data =
   f_collect_symbol_completion_matches,
   c_watch_location_expression,
   cp_get_symbol_name_matcher,	/* la_get_symbol_name_matcher */
-  cp_search_name_hash,
   &default_varobj_ops,
   NULL,
   f_is_string_type_p,
@@ -686,6 +685,12 @@ class f_language : public language_defn
     lai->bool_type_symbol = "logical";
     lai->bool_type_default = builtin->builtin_logical_s2;
   }
+
+  /* See language.h.  */
+  unsigned int search_name_hash (const char *name) const override
+  {
+    return cp_search_name_hash (name);
+  }
 };
 
 /* Single instance of the Fortran language class.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index ea4058d63e1..a74458d572a 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -561,7 +561,6 @@ extern const struct language_data go_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   go_is_string_type_p,
diff --git a/gdb/language.c b/gdb/language.c
index a6b7f1400d5..425081a64c8 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -47,6 +47,7 @@
 #include <algorithm>
 #include "gdbarch.h"
 
+
 static int unk_lang_parser (struct parser_state *);
 
 static void set_range_case (void);
@@ -836,7 +837,6 @@ extern const struct language_data unknown_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   default_is_string_type_p,
@@ -901,7 +901,6 @@ extern const struct language_data auto_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   default_is_string_type_p,
diff --git a/gdb/language.h b/gdb/language.h
index 15627506391..1829be8085b 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -384,11 +384,6 @@ struct language_data
     symbol_name_matcher_ftype *(*la_get_symbol_name_matcher)
       (const lookup_name_info &);
 
-    /* Hash the given symbol search name.  Use
-       default_search_name_hash if no special treatment is
-       required.  */
-    unsigned int (*la_search_name_hash) (const char *name);
-
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
 
@@ -513,6 +508,9 @@ struct language_defn : language_data
     return nullptr;
   }
 
+  /* Hash the given symbol search name.  */
+  virtual unsigned int search_name_hash (const char *name) const;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
@@ -688,14 +686,6 @@ struct language_pass_by_ref_info language_pass_by_reference (struct type *type);
 void default_print_typedef (struct type *type, struct symbol *new_symbol,
 			    struct ui_file *stream);
 
-/* Default name hashing function.  */
-
-/* Produce an unsigned hash value from SEARCH_NAME that is consistent
-   with strcmp_iw, strcmp, and, at least on Ada symbols, wild_match.
-   That is, two identifiers equivalent according to any of those three
-   comparison operators hash to the same value.  */
-extern unsigned int default_search_name_hash (const char *search_name);
-
 void c_get_string (struct value *value,
 		   gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
 		   int *length, struct type **char_type,
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index eb7ece58efd..bd1058c9a96 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -386,7 +386,6 @@ extern const struct language_data m2_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   m2_is_string_type_p,
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 4a84f84cb88..afbb1fbed73 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -401,7 +401,6 @@ extern const struct language_data objc_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index cc479c153fc..3643320acd8 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1061,7 +1061,6 @@ extern const struct language_data opencl_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   c_is_string_type_p,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 1c0222e6c1f..7e7b6ff7b83 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -416,7 +416,6 @@ extern const struct language_data pascal_language_data =
   default_collect_symbol_completion_matches,
   c_watch_location_expression,
   NULL,				/* la_compare_symbol_for_completion */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   pascal_is_string_type_p,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index dc646507de5..cf9dce76e2d 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2093,7 +2093,6 @@ extern const struct language_data rust_language_data =
   default_collect_symbol_completion_matches,
   rust_watch_location_expression,
   NULL,				/* la_get_symbol_name_matcher */
-  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   rust_is_string_type_p,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 817559fec1f..6ad78933501 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1855,7 +1855,7 @@ demangle_for_lookup (const char *name, enum language lang,
 unsigned int
 search_name_hash (enum language language, const char *search_name)
 {
-  return language_def (language)->la_search_name_hash (search_name);
+  return language_def (language)->search_name_hash (search_name);
 }
 
 /* See symtab.h.
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 10/13] gdb: Convert language la_sniff_from_mangled_name field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (8 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 09/13] gdb: Convert language la_search_name_hash " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 11/13] gdb: Convert language la_print_type " Andrew Burgess
                     ` (4 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_sniff_from_mangled_name
function pointer member variable into a member function of
language_defn.

Previously the la_sniff_from_mangled_name pointer was NULL for some
languages, however, all uses of this function pointer were through the
function language_sniff_from_mangled_name which provided a default
implementation.

This default implementation now becomes the implementation in the base
class language_defn, which is then overridden as required in various
language sub-classes.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_sniff_from_mangled_name): Delete function,
	implementation moves to...
	(ada_language::sniff_from_mangled_name): ...here.  Update return
	type.
	(ada_language_data): Delete la_sniff_from_mangled_name
	initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(cplus_language::sniff_from_mangled_name): New member function,
	implementation taken from gdb_sniff_from_mangled_name.
	(asm_language_data): Delete la_sniff_from_mangled_name
	initializer.
	(minimal_language_data): Likewise.
	* cp-support.c (gdb_sniff_from_mangled_name): Delete,
	implementation moves to cplus_language::sniff_from_mangled_name.
	* cp-support.h (gdb_sniff_from_mangled_name): Delete declaration.
	* d-lang.c (d_sniff_from_mangled_name): Delete, implementation
	moves to...
	(d_language::sniff_from_mangled_name): ...here.
	(d_language_data): Delete la_sniff_from_mangled_name initializer.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_sniff_from_mangled_name): Delete, implementation
	moves to...
	(go_language::sniff_from_mangled_name): ...here.
	(go_language_data): Delete la_sniff_from_mangled_name initializer.
	* language.c (language_sniff_from_mangled_name): Delete.
	(unknown_language_data): Delete la_sniff_from_mangled_name
	initializer.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_sniff_from_mangled_name
	field.
	(language_defn::sniff_from_mangled_name): New function.
	(language_sniff_from_mangled_name): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_sniff_from_mangled_name
	field.
	* objc-lang.c (objc_sniff_from_mangled_name): Delete,
	implementation moves to...
	(objc_language::sniff_from_mangled_name): ...here.
	(objc_language_data): Delete la_sniff_from_mangled_name initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_sniff_from_mangled_name): Delete,
	implementation moves to...
	(rust_language::sniff_from_mangled_name): ...here.
	(rust_language_data): Delete la_sniff_from_mangled_name
	initializer.
	* symtab.c (symbol_find_demangled_name): Call
	sniff_from_mangled_name member function.
---
 gdb/ChangeLog     | 51 +++++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 78 +++++++++++++++++++++++------------------------
 gdb/c-lang.c      | 12 +++++---
 gdb/cp-support.c  |  9 ------
 gdb/cp-support.h  |  4 ---
 gdb/d-lang.c      | 18 +++++------
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     | 18 +++++------
 gdb/language.c    | 19 ------------
 gdb/language.h    | 44 +++++++++++++-------------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   | 18 +++++------
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   | 20 +++++-------
 gdb/symtab.c      |  4 +--
 16 files changed, 152 insertions(+), 147 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index f2b941969f3..7ad53956c45 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1375,45 +1375,6 @@ ada_la_decode (const char *encoded, int options)
   return xstrdup (ada_decode (encoded).c_str ());
 }
 
-/* Implement la_sniff_from_mangled_name for Ada.  */
-
-static int
-ada_sniff_from_mangled_name (const char *mangled, char **out)
-{
-  std::string demangled = ada_decode (mangled);
-
-  *out = NULL;
-
-  if (demangled != mangled && demangled[0] != '<')
-    {
-      /* Set the gsymbol language to Ada, but still return 0.
-	 Two reasons for that:
-
-	 1. For Ada, we prefer computing the symbol's decoded name
-	 on the fly rather than pre-compute it, in order to save
-	 memory (Ada projects are typically very large).
-
-	 2. There are some areas in the definition of the GNAT
-	 encoding where, with a bit of bad luck, we might be able
-	 to decode a non-Ada symbol, generating an incorrect
-	 demangled name (Eg: names ending with "TB" for instance
-	 are identified as task bodies and so stripped from
-	 the decoded name returned).
-
-	 Returning 1, here, but not setting *DEMANGLED, helps us get a
-	 little bit of the best of both worlds.  Because we're last,
-	 we should not affect any of the other languages that were
-	 able to demangle the symbol before us; we get to correctly
-	 tag Ada symbols as such; and even if we incorrectly tagged a
-	 non-Ada symbol, which should be rare, any routing through the
-	 Ada language should be transparent (Ada tries to behave much
-	 like C/C++ with non-Ada symbols).  */
-      return 1;
-    }
-
-  return 0;
-}
-
 \f
 
                                 /* Arrays */
@@ -13964,7 +13925,6 @@ extern const struct language_data ada_language_data =
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
   ada_la_decode,                /* Language specific symbol demangler */
-  ada_sniff_from_mangled_name,
   NULL,                         /* Language specific
 				   class_name_from_physname */
   ada_op_print_tab,             /* expression operators for printing */
@@ -14102,6 +14062,44 @@ class ada_language : public language_defn
 
     return true;
   }
+
+  /* See language.h.  */
+  bool sniff_from_mangled_name (const char *mangled,
+				char **out) const override
+  {
+    std::string demangled = ada_decode (mangled);
+
+    *out = NULL;
+
+    if (demangled != mangled && demangled[0] != '<')
+      {
+	/* Set the gsymbol language to Ada, but still return 0.
+	   Two reasons for that:
+
+	   1. For Ada, we prefer computing the symbol's decoded name
+	   on the fly rather than pre-compute it, in order to save
+	   memory (Ada projects are typically very large).
+
+	   2. There are some areas in the definition of the GNAT
+	   encoding where, with a bit of bad luck, we might be able
+	   to decode a non-Ada symbol, generating an incorrect
+	   demangled name (Eg: names ending with "TB" for instance
+	   are identified as task bodies and so stripped from
+	   the decoded name returned).
+
+	   Returning true, here, but not setting *DEMANGLED, helps us get
+	   a little bit of the best of both worlds.  Because we're last,
+	   we should not affect any of the other languages that were
+	   able to demangle the symbol before us; we get to correctly
+	   tag Ada symbols as such; and even if we incorrectly tagged a
+	   non-Ada symbol, which should be rare, any routing through the
+	   Ada language should be transparent (Ada tries to behave much
+	   like C/C++ with non-Ada symbols).  */
+	return true;
+      }
+
+    return false;
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 8cdcfd9b63f..be09d45478e 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -914,7 +914,6 @@ extern const struct language_data c_language_data =
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
-  NULL,
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -1017,7 +1016,6 @@ extern const struct language_data cplus_language_data =
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   gdb_demangle,			/* Language specific symbol demangler */
-  gdb_sniff_from_mangled_name,
   cp_class_name_from_physname,  /* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -1130,6 +1128,14 @@ class cplus_language : public language_defn
   {
     return cp_search_name_hash (name);
   }
+
+  /* See language.h.  */
+  bool sniff_from_mangled_name (const char *mangled,
+				char **demangled) const override
+  {
+    *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
+    return *demangled != NULL;
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1168,7 +1174,6 @@ extern const struct language_data asm_language_data =
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
-  NULL,
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -1236,7 +1241,6 @@ extern const struct language_data minimal_language_data =
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
-  NULL,
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index bc9e8d4eda5..955e0ae82f7 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1608,15 +1608,6 @@ gdb_demangle (const char *name, int options)
 
 /* See cp-support.h.  */
 
-int
-gdb_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
-  *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
-  return *demangled != NULL;
-}
-
-/* See cp-support.h.  */
-
 unsigned int
 cp_search_name_hash (const char *search_name)
 {
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index 6ca898315bb..7c948b212cb 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -191,8 +191,4 @@ extern struct cmd_list_element *maint_cplus_cmd_list;
 
 char *gdb_demangle (const char *name, int options);
 
-/* Like gdb_demangle, but suitable for use as la_sniff_from_mangled_name.  */
-
-int gdb_sniff_from_mangled_name (const char *mangled, char **demangled);
-
 #endif /* CP_SUPPORT_H */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index c6ee6a231e6..23b9464cb58 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -56,15 +56,6 @@ d_demangle (const char *symbol, int options)
   return gdb_demangle (symbol, options | DMGL_DLANG);
 }
 
-/* la_sniff_from_mangled_name implementation for D.  */
-
-static int
-d_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
-  *demangled = d_demangle (mangled, 0);
-  return *demangled != NULL;
-}
-
 /* Table mapping opcodes into strings for printing operators
    and precedences of the operators.  */
 static const struct op_print d_op_print_tab[] =
@@ -166,7 +157,6 @@ extern const struct language_data d_language_data =
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_lookup_symbol_nonlocal,
   d_demangle,			/* Language specific symbol demangler.  */
-  d_sniff_from_mangled_name,
   NULL,				/* Language specific
 				   class_name_from_physname.  */
   d_op_print_tab,		/* Expression operators for printing.  */
@@ -254,6 +244,14 @@ class d_language : public language_defn
     lai->bool_type_symbol = "bool";
     lai->bool_type_default = builtin->builtin_bool;
   }
+
+  /* See language.h.  */
+  bool sniff_from_mangled_name (const char *mangled,
+				char **demangled) const override
+  {
+    *demangled = d_demangle (mangled, 0);
+    return *demangled != NULL;
+  }
 };
 
 /* Single instance of the D language class.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index a2df46a8b4a..804b2823f31 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -623,7 +623,6 @@ extern const struct language_data f_language_data =
      and there is no DW_AT_producer available for inferiors with only
      the ELF symbols to check the mangling kind.  */
   NULL,				/* Language specific symbol demangler */
-  NULL,
   NULL,				/* Language specific
 				   class_name_from_physname */
   f_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index a74458d572a..eb89dc598b7 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -396,15 +396,6 @@ go_demangle (const char *mangled_name, int options)
   return result;
 }
 
-/* la_sniff_from_mangled_name for Go.  */
-
-static int
-go_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
-  *demangled = go_demangle (mangled, 0);
-  return *demangled != NULL;
-}
-
 /* Given a Go symbol, return its package or NULL if unknown.
    Space for the result is malloc'd, caller must free.  */
 
@@ -551,7 +542,6 @@ extern const struct language_data go_language_data =
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, 
   go_demangle,			/* Language specific symbol demangler.  */
-  go_sniff_from_mangled_name,
   NULL,				/* Language specific
 				   class_name_from_physname.  */
   go_op_print_tab,		/* Expression operators for printing.  */
@@ -628,6 +618,14 @@ class go_language : public language_defn
     lai->bool_type_symbol = "bool";
     lai->bool_type_default = builtin->builtin_bool;
   }
+
+  /* See language.h.  */
+  bool sniff_from_mangled_name (const char *mangled,
+				char **demangled) const override
+  {
+    *demangled = go_demangle (mangled, 0);
+    return *demangled != NULL;
+  }
 };
 
 /* Single instance of the Go language class.  */
diff --git a/gdb/language.c b/gdb/language.c
index 425081a64c8..2b46452f3b8 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -595,23 +595,6 @@ language_demangle (const struct language_defn *current_language,
   return NULL;
 }
 
-/* See language.h.  */
-
-int
-language_sniff_from_mangled_name (const struct language_defn *lang,
-				  const char *mangled, char **demangled)
-{
-  gdb_assert (lang != NULL);
-
-  if (lang->la_sniff_from_mangled_name == NULL)
-    {
-      *demangled = NULL;
-      return 0;
-    }
-
-  return lang->la_sniff_from_mangled_name (mangled, demangled);
-}
-
 /* Return class name from physname or NULL.  */
 char *
 language_class_name_from_physname (const struct language_defn *lang,
@@ -827,7 +810,6 @@ extern const struct language_data unknown_language_data =
   true,				/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
   unk_lang_demangle,		/* Language specific symbol demangler */
-  NULL,
   unk_lang_class_name,		/* Language specific
 				   class_name_from_physname */
   unk_op_print_tab,		/* expression operators for printing */
@@ -891,7 +873,6 @@ extern const struct language_data auto_language_data =
   false,			/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   unk_lang_demangle,		/* Language specific symbol demangler */
-  NULL,
   unk_lang_class_name,		/* Language specific
 				   class_name_from_physname */
   unk_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/language.h b/gdb/language.h
index 1829be8085b..78721de8e59 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -318,22 +318,6 @@ struct language_data
     /* Return demangled language symbol, or NULL.  */
     char *(*la_demangle) (const char *mangled, int options);
 
-    /* Demangle a symbol according to this language's rules.  Unlike
-       la_demangle, this does not take any options.
-
-       *DEMANGLED will be set by this function.
-       
-       If this function returns 0, then *DEMANGLED must always be set
-       to NULL.
-
-       If this function returns 1, the implementation may set this to
-       a xmalloc'd string holding the demangled form.  However, it is
-       not required to.  The string, if any, is owned by the caller.
-
-       The resulting string should be of the form that will be
-       installed into a symbol.  */
-    int (*la_sniff_from_mangled_name) (const char *mangled, char **demangled);
-
     /* Return class name of a mangled method name or NULL.  */
     char *(*la_class_name_from_physname) (const char *physname);
 
@@ -511,6 +495,27 @@ struct language_defn : language_data
   /* Hash the given symbol search name.  */
   virtual unsigned int search_name_hash (const char *name) const;
 
+  /* Demangle a symbol according to this language's rules.  Unlike
+     la_demangle, this does not take any options.
+
+     *DEMANGLED will be set by this function.
+
+     If this function returns false, then *DEMANGLED must always be set
+     to NULL.
+
+     If this function returns true, the implementation may set this to
+     a xmalloc'd string holding the demangled form.  However, it is
+     not required to.  The string, if any, is owned by the caller.
+
+     The resulting string should be of the form that will be
+     installed into a symbol.  */
+  virtual bool sniff_from_mangled_name (const char *mangled,
+					char **demangled) const
+  {
+    *demangled = nullptr;
+    return false;
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
@@ -664,13 +669,6 @@ extern CORE_ADDR skip_language_trampoline (struct frame_info *, CORE_ADDR pc);
 extern char *language_demangle (const struct language_defn *current_language, 
 				const char *mangled, int options);
 
-/* A wrapper for la_sniff_from_mangled_name.  The arguments and result
-   are as for the method.  */
-
-extern int language_sniff_from_mangled_name (const struct language_defn *lang,
-					     const char *mangled,
-					     char **demangled);
-
 /* Return class name from physname, or NULL.  */
 extern char *language_class_name_from_physname (const struct language_defn *,
 					        const char *physname);
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index bd1058c9a96..e27e11d9b52 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -376,7 +376,6 @@ extern const struct language_data m2_language_data =
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
-  NULL,
   NULL,				/* Language specific
 				   class_name_from_physname */
   m2_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index afbb1fbed73..3082a5d058a 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -281,15 +281,6 @@ objc_demangle (const char *mangled, int options)
     return NULL;	/* Not an objc mangled name.  */
 }
 
-/* la_sniff_from_mangled_name for ObjC.  */
-
-static int
-objc_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
-  *demangled = objc_demangle (mangled, 0);
-  return *demangled != NULL;
-}
-
 /* Determine if we are currently in the Objective-C dispatch function.
    If so, get the address of the method function that the dispatcher
    would call and use that as the function to step into instead.  Also
@@ -391,7 +382,6 @@ extern const struct language_data objc_language_data =
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   objc_demangle,		/* Language specific symbol demangler */
-  objc_sniff_from_mangled_name,
   NULL,				/* Language specific
 				   class_name_from_physname */
   objc_op_print_tab,		/* Expression operators for printing */
@@ -422,6 +412,14 @@ class objc_language : public language_defn
   {
     c_language_arch_info (gdbarch, lai);
   }
+
+  /* See language.h.  */
+  bool sniff_from_mangled_name (const char *mangled,
+				char **demangled) const override
+  {
+    *demangled = objc_demangle (mangled, 0);
+    return *demangled != NULL;
+  }
 };
 
 /* Single instance of the class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 3643320acd8..41598a0bec3 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1051,7 +1051,6 @@ extern const struct language_data opencl_language_data =
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
-  NULL,
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 7e7b6ff7b83..448637cbada 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -407,7 +407,6 @@ extern const struct language_data pascal_language_data =
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   NULL,				/* Language specific symbol demangler */
-  NULL,
   NULL,				/* Language specific class_name_from_physname */
   pascal_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index cf9dce76e2d..c9531579e8f 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2016,17 +2016,6 @@ rust_lookup_symbol_nonlocal (const struct language_defn *langdef,
 
 \f
 
-/* la_sniff_from_mangled_name for Rust.  */
-
-static int
-rust_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
-  *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
-  return *demangled != NULL;
-}
-
-\f
-
 /* la_watch_location_expression for Rust.  */
 
 static gdb::unique_xmalloc_ptr<char>
@@ -2083,7 +2072,6 @@ extern const struct language_data rust_language_data =
   false,			/* la_store_sym_names_in_linkage_form_p */
   rust_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
   gdb_demangle,			/* Language specific symbol demangler */
-  rust_sniff_from_mangled_name,
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -2148,6 +2136,14 @@ class rust_language : public language_defn
     lai->bool_type_default = types[rust_primitive_bool];
     lai->string_char_type = types[rust_primitive_u8];
   }
+
+  /* See language.h.  */
+  bool sniff_from_mangled_name (const char *mangled,
+				char **demangled) const override
+  {
+    *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
+    return *demangled != NULL;
+  }
 };
 
 /* Single instance of the Rust language class.  */
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 6ad78933501..6f1788c3916 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -807,7 +807,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
     {
       const struct language_defn *lang = language_def (gsymbol->language ());
 
-      language_sniff_from_mangled_name (lang, mangled, &demangled);
+      lang->sniff_from_mangled_name (mangled, &demangled);
       return demangled;
     }
 
@@ -816,7 +816,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
       enum language l = (enum language) i;
       const struct language_defn *lang = language_def (l);
 
-      if (language_sniff_from_mangled_name (lang, mangled, &demangled))
+      if (lang->sniff_from_mangled_name (mangled, &demangled))
 	{
 	  gsymbol->m_language = l;
 	  return demangled;
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 11/13] gdb: Convert language la_print_type field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (9 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 10/13] gdb: Convert language la_sniff_from_mangled_name " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 12/13] gdb: Convert language la_demangle " Andrew Burgess
                     ` (3 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_print_type function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_print_type
	initializer.
	(ada_language::print_type): New member function.
	* c-lang.c (c_language_data): Delete la_print_type initializer.
	(c_language::print_type): New member function.
	(cplus_language_data): Delete la_print_type initializer.
	(cplus_language::print_type): New member function.
	(asm_language_data): Delete la_print_type initializer.
	(asm_language::print_type): New member function.
	(minimal_language_data): Delete la_print_type initializer.
	(minimal_language::print_type): New member function.
	* d-lang.c (d_language_data): Delete la_print_type initializer.
	(d_language::print_type): New member function.
	* f-lang.c (f_language_data): Delete la_print_type initializer.
	(f_language::print_type): New member function.
	* go-lang.c (go_language_data): Delete la_print_type initializer.
	(go_language::print_type): New member function.
	* language.c (unk_lang_print_type): Delete.
	(unknown_language_data): Delete la_print_type initializer.
	(unknown_language::print_type): New member function.
	(auto_language_data): Delete la_print_type initializer.
	(auto_language::print_type): New member function.
	* language.h (language_data): Delete la_print_type field.
	(language_defn::print_type): New function.
	(LA_PRINT_TYPE): Update.
	* m2-lang.c (m2_language_data): Delete la_print_type initializer.
	(m2_language::print_type): New member function.
	* objc-lang.c (objc_language_data): Delete la_print_type
	initializer.
	(objc_language::print_type): New member function.
	* opencl-lang.c (opencl_print_type): Delete, implementation moved
	to opencl_language::print_type.
	(opencl_language_data): Delete la_print_type initializer.
	(opencl_language::print_type): New member function, implementation
	from opencl_print_type.
	* p-lang.c (pascal_language_data): Delete la_print_type
	initializer.
	(pascal_language::print_type): New member function.
	* rust-lang.c (rust_print_type): Delete, implementation moved to
	rust_language::print_type.
	(rust_language_data): Delete la_print_type initializer.
	(rust_language::print_type): New member function, implementation
	from rust_print_type.
---
 gdb/ChangeLog     | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 10 +++++++++-
 gdb/c-lang.c      | 40 ++++++++++++++++++++++++++++++++++++----
 gdb/d-lang.c      | 10 +++++++++-
 gdb/f-lang.c      | 10 +++++++++-
 gdb/go-lang.c     | 10 +++++++++-
 gdb/language.c    | 29 ++++++++++++++++++-----------
 gdb/language.h    | 12 ++++++------
 gdb/m2-lang.c     | 10 +++++++++-
 gdb/objc-lang.c   | 10 +++++++++-
 gdb/opencl-lang.c | 42 ++++++++++++++++++++----------------------
 gdb/p-lang.c      | 10 +++++++++-
 gdb/rust-lang.c   | 22 +++++++++++-----------
 13 files changed, 200 insertions(+), 61 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7ad53956c45..10b4c97b801 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13916,7 +13916,6 @@ extern const struct language_data ada_language_data =
   ada_printchar,                /* Print a character constant */
   ada_printstr,                 /* Function to print string constant */
   emit_char,                    /* Function to print single char (not used) */
-  ada_print_type,               /* Print a type using appropriate syntax */
   ada_print_typedef,            /* Print a typedef using appropriate syntax */
   ada_value_print_inner,	/* la_value_print_inner */
   ada_value_print,              /* Print a top-level value */
@@ -14100,6 +14099,15 @@ class ada_language : public language_defn
 
     return false;
   }
+
+  /* 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
+  {
+    ada_print_type (type, varstring, stream, show, level, flags);
+  }
 };
 
 /* Single instance of the Ada language class.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index be09d45478e..79e4494aa4d 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -905,7 +905,6 @@ extern const struct language_data c_language_data =
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
-  c_print_type,			/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
@@ -950,6 +949,15 @@ class c_language : public language_defn
   {
     return c_get_compile_context ();
   }
+
+  /* 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);
+  }
 };
 
 /* Single instance of the C language class.  */
@@ -1007,7 +1015,6 @@ extern const struct language_data cplus_language_data =
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
-  c_print_type,			/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
@@ -1136,6 +1143,15 @@ class cplus_language : public language_defn
     *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
     return *demangled != NULL;
   }
+
+  /* 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);
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1165,7 +1181,6 @@ extern const struct language_data asm_language_data =
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
-  c_print_type,			/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
@@ -1206,6 +1221,15 @@ class asm_language : public language_defn
   {
     c_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
+  {
+    c_print_type (type, varstring, stream, show, level, flags);
+  }
 };
 
 /* The single instance of the ASM language class.  */
@@ -1232,7 +1256,6 @@ extern const struct language_data minimal_language_data =
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
-  c_print_type,			/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
@@ -1271,6 +1294,15 @@ class minimal_language : public language_defn
   {
     c_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
+  {
+    c_print_type (type, varstring, stream, show, level, flags);
+  }
 };
 
 /* The single instance of the minimal language class.  */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 23b9464cb58..815b59734e0 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -147,7 +147,6 @@ extern const struct language_data d_language_data =
   c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
   c_emit_char,			/* Print a single char.  */
-  c_print_type,			/* Print a type using appropriate syntax.  */
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
   d_value_print_inner,		/* la_value_print_inner */
@@ -252,6 +251,15 @@ class d_language : public language_defn
     *demangled = d_demangle (mangled, 0);
     return *demangled != NULL;
   }
+
+  /* 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);
+  }
 };
 
 /* Single instance of the D language class.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 804b2823f31..1b0fec68c0e 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -608,7 +608,6 @@ extern const struct language_data f_language_data =
   f_printchar,			/* Print character constant */
   f_printstr,			/* function to print string constant */
   f_emit_char,			/* Function to print a single character */
-  f_print_type,			/* Print a type using appropriate syntax */
   f_print_typedef,		/* Print a typedef using appropriate syntax */
   f_value_print_innner,		/* la_value_print_inner */
   c_value_print,		/* FIXME */
@@ -690,6 +689,15 @@ class f_language : public language_defn
   {
     return cp_search_name_hash (name);
   }
+
+  /* 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
+  {
+    f_print_type (type, varstring, stream, show, level, flags);
+  }
 };
 
 /* Single instance of the Fortran language class.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index eb89dc598b7..36a46a403e2 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -532,7 +532,6 @@ extern const struct language_data go_language_data =
   c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
   c_emit_char,			/* Print a single char.  */
-  go_print_type,		/* Print a type using appropriate syntax.  */
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
   go_value_print_inner,		/* la_value_print_inner */
@@ -626,6 +625,15 @@ class go_language : public language_defn
     *demangled = go_demangle (mangled, 0);
     return *demangled != NULL;
   }
+
+  /* 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
+  {
+    go_print_type (type, varstring, stream, show, level, flags);
+  }
 };
 
 /* Single instance of the Go language class.  */
diff --git a/gdb/language.c b/gdb/language.c
index 2b46452f3b8..7df47b3ddee 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -726,15 +726,6 @@ unk_lang_printstr (struct ui_file *stream, struct type *type,
 	   "function unk_lang_printstr called."));
 }
 
-static void
-unk_lang_print_type (struct type *type, const char *varstring,
-		     struct ui_file *stream, int show, int level,
-		     const struct type_print_options *flags)
-{
-  error (_("internal error - unimplemented "
-	   "function unk_lang_print_type called."));
-}
-
 static void
 unk_lang_value_print_inner (struct value *val,
 			    struct ui_file *stream, int recurse,
@@ -801,7 +792,6 @@ extern const struct language_data unknown_language_data =
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
   unk_lang_emit_char,
-  unk_lang_print_type,		/* Print a type using appropriate syntax */
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_value_print_inner,	/* la_value_print_inner */
   unk_lang_value_print,		/* Print a top-level value */
@@ -840,6 +830,15 @@ class unknown_language : public language_defn
   {
     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 unknown_language::print_type called"));
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -864,7 +863,6 @@ extern const struct language_data auto_language_data =
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
   unk_lang_emit_char,
-  unk_lang_print_type,		/* Print a type using appropriate syntax */
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_value_print_inner,	/* la_value_print_inner */
   unk_lang_value_print,		/* Print a top-level value */
@@ -903,6 +901,15 @@ class auto_language : public language_defn
   {
     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"));
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index 78721de8e59..dd415bbef85 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -248,11 +248,6 @@ struct language_data
     void (*la_emitchar) (int ch, struct type *chtype,
 			 struct ui_file * stream, int quoter);
 
-    /* Print a type using syntax appropriate for this language.  */
-
-    void (*la_print_type) (struct type *, const char *, struct ui_file *, int,
-			   int, const struct type_print_options *);
-
     /* Print a typedef using syntax appropriate for this language.
        TYPE is the underlying type.  NEW_SYMBOL is the symbol naming
        the type.  STREAM is the output stream on which to print.  */
@@ -516,6 +511,11 @@ struct language_defn : language_data
     return false;
   }
 
+  /* Print a type using syntax appropriate for this language.  */
+
+  virtual void print_type (struct type *, const char *, struct ui_file *, int,
+			   int, const struct type_print_options *) const = 0;
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
@@ -604,7 +604,7 @@ extern enum language set_language (enum language);
    with the "set language" command.  */
 
 #define LA_PRINT_TYPE(type,varstring,stream,show,level,flags)		\
-  (current_language->la_print_type(type,varstring,stream,show,level,flags))
+  (current_language->print_type(type,varstring,stream,show,level,flags))
 
 #define LA_PRINT_TYPEDEF(type,new_symbol,stream) \
   (current_language->la_print_typedef(type,new_symbol,stream))
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index e27e11d9b52..68aad7d7367 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -367,7 +367,6 @@ extern const struct language_data m2_language_data =
   m2_printchar,			/* Print character constant */
   m2_printstr,			/* function to print string constant */
   m2_emit_char,			/* Function to print a single character */
-  m2_print_type,		/* Print a type using appropriate syntax */
   m2_print_typedef,		/* Print a typedef using appropriate syntax */
   m2_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
@@ -425,6 +424,15 @@ class m2_language : public language_defn
     lai->bool_type_symbol = "BOOLEAN";
     lai->bool_type_default = builtin->builtin_bool;
   }
+
+  /* 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
+  {
+    m2_print_type (type, varstring, stream, show, level, flags);
+  }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 3082a5d058a..0566ce8f188 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -373,7 +373,6 @@ extern const struct language_data objc_language_data =
   c_printchar,		       /* Print a character constant */
   c_printstr,		       /* Function to print string constant */
   c_emit_char,
-  c_print_type,			/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
@@ -420,6 +419,15 @@ class objc_language : public language_defn
     *demangled = objc_demangle (mangled, 0);
     return *demangled != NULL;
   }
+
+  /* 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);
+  }
 };
 
 /* Single instance of the class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 41598a0bec3..481fe1dba47 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -994,27 +994,6 @@ Cannot perform conditional operation on vectors with different sizes"));
   return evaluate_subexp_c (expect_type, exp, pos, noside);
 }
 
-/* Print OpenCL types.  */
-
-static void
-opencl_print_type (struct type *type, const char *varstring,
-		   struct ui_file *stream, int show, int level,
-		   const struct type_print_options *flags)
-{
-  /* We nearly always defer to C type printing, except that vector
-     types are considered primitive in OpenCL, and should always
-     be printed using their TYPE_NAME.  */
-  if (show > 0)
-    {
-      type = check_typedef (type);
-      if (type->code () == TYPE_CODE_ARRAY && TYPE_VECTOR (type)
-	  && TYPE_NAME (type) != NULL)
-	show = 0;
-    }
-
-  c_print_type (type, varstring, stream, show, level, flags); 
-}
-
 const struct exp_descriptor exp_descriptor_opencl =
 {
   print_subexp_standard,
@@ -1042,7 +1021,6 @@ extern const struct language_data opencl_language_data =
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
-  opencl_print_type,		/* Print a type using appropriate syntax */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
@@ -1091,6 +1069,26 @@ class opencl_language : public language_defn
     lai->bool_type_symbol = "int";
     lai->bool_type_default = types [opencl_primitive_type_int];
   }
+
+  /* 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
+  {
+    /* We nearly always defer to C type printing, except that vector types
+       are considered primitive in OpenCL, and should always be printed
+       using their TYPE_NAME.  */
+    if (show > 0)
+      {
+	type = check_typedef (type);
+	if (type->code () == TYPE_CODE_ARRAY && TYPE_VECTOR (type)
+	    && TYPE_NAME (type) != NULL)
+	  show = 0;
+      }
+
+    c_print_type (type, varstring, stream, show, level, flags);
+  }
 };
 
 /* Single instance of the OpenCL language class.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 448637cbada..82277739ec9 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -398,7 +398,6 @@ extern const struct language_data pascal_language_data =
   pascal_printchar,		/* Print a character constant */
   pascal_printstr,		/* Function to print string constant */
   pascal_emit_char,		/* Print a single char */
-  pascal_print_type,		/* Print a type using appropriate syntax */
   pascal_print_typedef,		/* Print a typedef using appropriate syntax */
   pascal_value_print_inner,	/* la_value_print_inner */
   pascal_value_print,		/* Print a top-level value */
@@ -478,6 +477,15 @@ class pascal_language : public language_defn
     lai->bool_type_symbol = "boolean";
     lai->bool_type_default = builtin->builtin_bool;
   }
+
+  /* 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
+  {
+    pascal_print_type (type, varstring, stream, show, level, flags);
+  }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index c9531579e8f..53dd7761847 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -951,16 +951,6 @@ rust_internal_print_type (struct type *type, const char *varstring,
     }
 }
 
-static void
-rust_print_type (struct type *type, const char *varstring,
-		 struct ui_file *stream, int show, int level,
-		 const struct type_print_options *flags)
-{
-  print_offset_data podata;
-  rust_internal_print_type (type, varstring, stream, show, level,
-			    flags, false, &podata);
-}
-
 \f
 
 /* Like arch_composite_type, but uses TYPE to decide how to allocate
@@ -2063,7 +2053,6 @@ extern const struct language_data rust_language_data =
   rust_printchar,		/* Print a character constant */
   rust_printstr,		/* Function to print string constant */
   rust_emitchar,		/* Print a single char */
-  rust_print_type,		/* Print a type using appropriate syntax */
   rust_print_typedef,		/* Print a typedef using appropriate syntax */
   rust_value_print_inner,	/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
@@ -2144,6 +2133,17 @@ class rust_language : public language_defn
     *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
     return *demangled != NULL;
   }
+
+  /* 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
+  {
+    print_offset_data podata;
+    rust_internal_print_type (type, varstring, stream, show, level,
+			      flags, false, &podata);
+  }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 12/13] gdb: Convert language la_demangle field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (10 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 11/13] gdb: Convert language la_print_type " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 15:06   ` [PATCHv2 13/13] gdb: Convert language skip_trampoline " Andrew Burgess
                     ` (2 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_demangle function pointer
member variable into a member function of language_defn.

The only slightly "weird" change in this commit is in f-lang.c, where
I have given the Fortran language a demangle method that is identical
to the default language_defn::demangle.  The only reason for this is
to give me somewhere to copy the comment that was previously embedded
within the f_language_data structure.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_demangle initializer.
	(ada_language::demangle): New member function.
	* c-lang.c (c_language_data): Delete la_demangle initializer.
	(cplus_language_data): Delete la_demangle initializer.
	(cplus_language::demangle): New member function.
	(asm_language_data): Delete la_demangle initializer.
	(minimal_language_data): Delete la_demangle initializer.
	* d-lang.c (d_language_data): Delete la_demangle initializer.
	(d_language::demangle): New member function.
	* f-lang.c (f_language_data): Delete la_demangle initializer.
	(f_language::demangle): New member function.
	* go-lang.c (go_language_data): Delete la_demangle initializer.
	(go_language::demangle): New member function.
	* language.c (language_demangle): Update.
	(unk_lang_demangle): Delete.
	(unknown_language_data): Delete la_demangle initializer.
	(unknown_language::demangle): New member function.
	(auto_language_data): Delete la_demangle initializer.
	(auto_language::demangle): New member function.
	* language.h (language_data): Delete la_demangle field.
	(language_defn::demangle): New function.
	* m2-lang.c (m2_language_data): Delete la_demangle initializer.
	* objc-lang.c (objc_language_data): Delete la_demangle
	initializer.
	(objc_language::demangle): New member function.
	* opencl-lang.c (opencl_language_data): Delete la_demangle
	initializer.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	(rust_language::demangle): New member functi
---
 gdb/ChangeLog     | 33 +++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  8 +++++++-
 gdb/c-lang.c      | 11 +++++++----
 gdb/d-lang.c      |  8 +++++++-
 gdb/f-lang.c      | 19 ++++++++++++-------
 gdb/go-lang.c     |  8 +++++++-
 gdb/language.c    | 28 ++++++++++++++++++----------
 gdb/language.h    |  9 ++++++---
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  8 +++++++-
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  8 +++++++-
 13 files changed, 111 insertions(+), 32 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 10b4c97b801..3c151588ecb 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13923,7 +13923,6 @@ extern const struct language_data ada_language_data =
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
-  ada_la_decode,                /* Language specific symbol demangler */
   NULL,                         /* Language specific
 				   class_name_from_physname */
   ada_op_print_tab,             /* expression operators for printing */
@@ -14102,6 +14101,13 @@ class ada_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return ada_la_decode (mangled, options);
+  }
+
+  /* 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
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 79e4494aa4d..75efb6ae592 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -912,7 +912,6 @@ extern const struct language_data c_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -1022,7 +1021,6 @@ extern const struct language_data cplus_language_data =
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  gdb_demangle,			/* Language specific symbol demangler */
   cp_class_name_from_physname,  /* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -1146,6 +1144,13 @@ class cplus_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return gdb_demangle (mangled, options);
+  }
+
+  /* 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
@@ -1188,7 +1193,6 @@ extern const struct language_data asm_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -1263,7 +1267,6 @@ extern const struct language_data minimal_language_data =
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 815b59734e0..fb56e1e9baf 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -155,7 +155,6 @@ extern const struct language_data d_language_data =
   "this",
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_lookup_symbol_nonlocal,
-  d_demangle,			/* Language specific symbol demangler.  */
   NULL,				/* Language specific
 				   class_name_from_physname.  */
   d_op_print_tab,		/* Expression operators for printing.  */
@@ -254,6 +253,13 @@ class d_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return d_demangle (mangled, options);
+  }
+
+  /* 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
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 1b0fec68c0e..bd5f78ccbef 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -615,13 +615,6 @@ extern const struct language_data f_language_data =
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-
-  /* We could support demangling here to provide module namespaces
-     also for inferiors with only minimal symbol table (ELF symbols).
-     Just the mangling standard is not standardized across compilers
-     and there is no DW_AT_producer available for inferiors with only
-     the ELF symbols to check the mangling kind.  */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   f_op_print_tab,		/* expression operators for printing */
@@ -692,6 +685,18 @@ class f_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+      /* We could support demangling here to provide module namespaces
+	 also for inferiors with only minimal symbol table (ELF symbols).
+	 Just the mangling standard is not standardized across compilers
+	 and there is no DW_AT_producer available for inferiors with only
+	 the ELF symbols to check the mangling kind.  */
+    return nullptr;
+  }
+
+  /* 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
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 36a46a403e2..47a4abcc2fe 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -540,7 +540,6 @@ extern const struct language_data go_language_data =
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, 
-  go_demangle,			/* Language specific symbol demangler.  */
   NULL,				/* Language specific
 				   class_name_from_physname.  */
   go_op_print_tab,		/* Expression operators for printing.  */
@@ -628,6 +627,13 @@ class go_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return go_demangle (mangled, options);
+  }
+
+  /* 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
diff --git a/gdb/language.c b/gdb/language.c
index 7df47b3ddee..e6ca03f4916 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -590,8 +590,8 @@ char *
 language_demangle (const struct language_defn *current_language, 
 				const char *mangled, int options)
 {
-  if (current_language != NULL && current_language->la_demangle)
-    return current_language->la_demangle (mangled, options);
+  if (current_language != NULL)
+    return current_language->demangle (mangled, options);
   return NULL;
 }
 
@@ -748,12 +748,6 @@ static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
   return 0;
 }
 
-/* Unknown languages just use the cplus demangler.  */
-static char *unk_lang_demangle (const char *mangled, int options)
-{
-  return gdb_demangle (mangled, options);
-}
-
 static char *unk_lang_class_name (const char *mangled)
 {
   return NULL;
@@ -799,7 +793,6 @@ extern const struct language_data unknown_language_data =
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
-  unk_lang_demangle,		/* Language specific symbol demangler */
   unk_lang_class_name,		/* Language specific
 				   class_name_from_physname */
   unk_op_print_tab,		/* expression operators for printing */
@@ -839,6 +832,14 @@ class unknown_language : public language_defn
   {
     error (_("unimplemented unknown_language::print_type called"));
   }
+
+  /* See language.h.  */
+
+  char *demangle (const char *mangled, int options) const override
+  {
+    /* The unknown language just uses the C++ demangler.  */
+    return gdb_demangle (mangled, options);
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -870,7 +871,6 @@ extern const struct language_data auto_language_data =
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  unk_lang_demangle,		/* Language specific symbol demangler */
   unk_lang_class_name,		/* Language specific
 				   class_name_from_physname */
   unk_op_print_tab,		/* expression operators for printing */
@@ -910,6 +910,14 @@ class auto_language : public language_defn
   {
     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);
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index dd415bbef85..bee479720ae 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -310,9 +310,6 @@ struct language_data
        const struct block *,
        const domain_enum);
 
-    /* Return demangled language symbol, or NULL.  */
-    char *(*la_demangle) (const char *mangled, int options);
-
     /* Return class name of a mangled method name or NULL.  */
     char *(*la_class_name_from_physname) (const char *physname);
 
@@ -511,6 +508,12 @@ struct language_defn : language_data
     return false;
   }
 
+  /* Return demangled language symbol version of MANGLED, or NULL.  */
+  virtual char *demangle (const char *mangled, int options) const
+  {
+    return nullptr;
+  }
+
   /* Print a type using syntax appropriate for this language.  */
 
   virtual void print_type (struct type *, const char *, struct ui_file *, int,
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 68aad7d7367..4bc25ce82fe 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -374,7 +374,6 @@ extern const struct language_data m2_language_data =
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   m2_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 0566ce8f188..1e3d1fd3616 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -380,7 +380,6 @@ extern const struct language_data objc_language_data =
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  objc_demangle,		/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   objc_op_print_tab,		/* Expression operators for printing */
@@ -422,6 +421,13 @@ class objc_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return objc_demangle (mangled, options);
+  }
+
+  /* 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
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 481fe1dba47..dc5d69873f6 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1028,7 +1028,6 @@ extern const struct language_data opencl_language_data =
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 82277739ec9..70f8e5af80a 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -405,7 +405,6 @@ extern const struct language_data pascal_language_data =
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  NULL,				/* Language specific symbol demangler */
   NULL,				/* Language specific class_name_from_physname */
   pascal_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 53dd7761847..9afe0b1f16f 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2060,7 +2060,6 @@ extern const struct language_data rust_language_data =
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   rust_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-  gdb_demangle,			/* Language specific symbol demangler */
   NULL,				/* Language specific
 				   class_name_from_physname */
   c_op_print_tab,		/* expression operators for printing */
@@ -2136,6 +2135,13 @@ class rust_language : public language_defn
 
   /* See language.h.  */
 
+  char *demangle (const char *mangled, int options) const override
+  {
+    return gdb_demangle (mangled, options);
+  }
+
+  /* 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
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCHv2 13/13] gdb: Convert language skip_trampoline field to a method
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (11 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 12/13] gdb: Convert language la_demangle " Andrew Burgess
@ 2020-05-15 15:06   ` Andrew Burgess
  2020-05-15 17:06   ` [PATCHv2 00/13] Starting to convert languages to separate classes Tom Tromey
  2020-06-01 16:02   ` Andrew Burgess
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-05-15 15:06 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::skip_trampoline function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete skip_trampoline
	initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(cplus_language::skip_trampoline): New member function.
	(asm_language_data): Delete skip_trampoline initializer.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unk_lang_trampoline): Delete function.
	(skip_language_trampoline): Update.
	(unknown_language_data): Delete skip_trampoline initializer.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete skip_trampoline field.
	(language_defn::skip_trampoline): New function.
	* m2-lang.c (m2_language_data): Delete skip_trampoline
	initializer.
	* objc-lang.c (objc_skip_trampoline): Delete function, move
	implementation to objc_language::skip_trampoline.
	(objc_language_data): Delete skip_trampoline initializer.
	(objc_language::skip_trampoline): New member function with
	implementation from objc_skip_trampoline.
	* opencl-lang.c (opencl_language_data): Delete skip_trampoline
	initializer.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
---
 gdb/ChangeLog     | 30 +++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      | 12 ++++++---
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 18 +++----------
 gdb/language.h    | 15 ++++++-----
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   | 66 ++++++++++++++++++++++++-----------------------
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 13 files changed, 84 insertions(+), 65 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3c151588ecb..6acaaa6d86a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13919,7 +13919,6 @@ extern const struct language_data ada_language_data =
   ada_print_typedef,            /* Print a typedef using appropriate syntax */
   ada_value_print_inner,	/* la_value_print_inner */
   ada_value_print,              /* Print a top-level value */
-  NULL,                         /* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 75efb6ae592..c998c5886b3 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -908,7 +908,6 @@ extern const struct language_data c_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
@@ -1017,7 +1016,6 @@ extern const struct language_data cplus_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  cplus_skip_trampoline,	/* Language specific skip_trampoline */
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
@@ -1157,6 +1155,14 @@ class cplus_language : public language_defn
   {
     c_print_type (type, varstring, stream, show, level, flags);
   }
+
+  /* See language.h.  */
+
+  CORE_ADDR skip_trampoline (struct frame_info *fi,
+			     CORE_ADDR pc) const override
+  {
+    return cplus_skip_trampoline (fi, pc);
+  }
 };
 
 /* The single instance of the C++ language class.  */
@@ -1189,7 +1195,6 @@ extern const struct language_data asm_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
@@ -1263,7 +1268,6 @@ extern const struct language_data minimal_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index fb56e1e9baf..81e3aac87ba 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -151,7 +151,6 @@ extern const struct language_data d_language_data =
 				   syntax.  */
   d_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value.  */
-  NULL,				/* Language specific skip_trampoline.  */
   "this",
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_lookup_symbol_nonlocal,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index bd5f78ccbef..90a794ef4ba 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -611,7 +611,6 @@ extern const struct language_data f_language_data =
   f_print_typedef,		/* Print a typedef using appropriate syntax */
   f_value_print_innner,		/* la_value_print_inner */
   c_value_print,		/* FIXME */
-  NULL,				/* Language specific skip_trampoline */
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   cp_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 47a4abcc2fe..76408f4fecb 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -536,7 +536,6 @@ extern const struct language_data go_language_data =
 				   syntax.  */
   go_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value.  */
-  NULL,				/* Language specific skip_trampoline.  */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, 
diff --git a/gdb/language.c b/gdb/language.c
index e6ca03f4916..f7faa2b8a4c 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -61,8 +61,6 @@ static void unk_lang_printchar (int c, struct type *type,
 static void unk_lang_value_print (struct value *, struct ui_file *,
 				  const struct value_print_options *);
 
-static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
-
 /* The current (default at startup) state of type and range checking.
    (If the modes are set to "auto", though, these are changed based
    on the default language at startup, and then again based on the
@@ -568,13 +566,10 @@ skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
 {
   for (const auto &lang : language_defn::languages)
     {
-      if (lang->skip_trampoline != NULL)
-	{
-	  CORE_ADDR real_pc = lang->skip_trampoline (frame, pc);
+      CORE_ADDR real_pc = lang->skip_trampoline (frame, pc);
 
-	  if (real_pc)
-	    return real_pc;
-	}
+      if (real_pc != 0)
+	return real_pc;
     }
 
   return 0;
@@ -743,11 +738,6 @@ unk_lang_value_print (struct value *val, struct ui_file *stream,
 	   "function unk_lang_value_print called."));
 }
 
-static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
-{
-  return 0;
-}
-
 static char *unk_lang_class_name (const char *mangled)
 {
   return NULL;
@@ -789,7 +779,6 @@ extern const struct language_data unknown_language_data =
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_value_print_inner,	/* la_value_print_inner */
   unk_lang_value_print,		/* Print a top-level value */
-  unk_lang_trampoline,		/* Language specific skip_trampoline */
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
@@ -867,7 +856,6 @@ extern const struct language_data auto_language_data =
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   unk_lang_value_print_inner,	/* la_value_print_inner */
   unk_lang_value_print,		/* Print a top-level value */
-  unk_lang_trampoline,		/* Language specific skip_trampoline */
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
diff --git a/gdb/language.h b/gdb/language.h
index bee479720ae..697cdb4909d 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -267,12 +267,6 @@ struct language_data
     void (*la_value_print) (struct value *, struct ui_file *,
 			    const struct value_print_options *);
 
-    /* PC is possibly an unknown languages trampoline.
-       If that PC falls in a trampoline belonging to this language,
-       return the address of the first pc in the real function, or 0
-       if it isn't a language tramp for this language.  */
-    CORE_ADDR (*skip_trampoline) (struct frame_info *, CORE_ADDR);
-
     /* Now come some hooks for lookup_symbol.  */
 
     /* If this is non-NULL, specifies the name that of the implicit
@@ -519,6 +513,15 @@ struct language_defn : language_data
   virtual void print_type (struct type *, const char *, struct ui_file *, int,
 			   int, const struct type_print_options *) const = 0;
 
+  /* PC is possibly an unknown languages trampoline.
+     If that PC falls in a trampoline belonging to this language, return
+     the address of the first pc in the real function, or 0 if it isn't a
+     language tramp for this language.  */
+  virtual CORE_ADDR skip_trampoline (struct frame_info *fi, CORE_ADDR pc) const
+  {
+    return (CORE_ADDR) 0;
+  }
+
   /* List of all known languages.  */
   static const struct language_defn *languages[nr_languages];
 };
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 4bc25ce82fe..7e306b4b2f4 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -370,7 +370,6 @@ extern const struct language_data m2_language_data =
   m2_print_typedef,		/* Print a typedef using appropriate syntax */
   m2_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  NULL,				/* Language specific skip_trampoline */
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 1e3d1fd3616..ff028fc012a 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -281,37 +281,6 @@ objc_demangle (const char *mangled, int options)
     return NULL;	/* Not an objc mangled name.  */
 }
 
-/* Determine if we are currently in the Objective-C dispatch function.
-   If so, get the address of the method function that the dispatcher
-   would call and use that as the function to step into instead.  Also
-   skip over the trampoline for the function (if any).  This is better
-   for the user since they are only interested in stepping into the
-   method function anyway.  */
-static CORE_ADDR 
-objc_skip_trampoline (struct frame_info *frame, CORE_ADDR stop_pc)
-{
-  struct gdbarch *gdbarch = get_frame_arch (frame);
-  CORE_ADDR real_stop_pc;
-  CORE_ADDR method_stop_pc;
-  
-  real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
-
-  if (real_stop_pc != 0)
-    find_objc_msgcall (real_stop_pc, &method_stop_pc);
-  else
-    find_objc_msgcall (stop_pc, &method_stop_pc);
-
-  if (method_stop_pc)
-    {
-      real_stop_pc = gdbarch_skip_trampoline_code
-		       (gdbarch, frame, method_stop_pc);
-      if (real_stop_pc == 0)
-	real_stop_pc = method_stop_pc;
-    }
-
-  return real_stop_pc;
-}
-
 
 /* Table mapping opcodes into strings for printing operators
    and precedences of the operators.  */
@@ -376,7 +345,6 @@ extern const struct language_data objc_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  objc_skip_trampoline, 	/* Language specific skip_trampoline */
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
@@ -434,6 +402,40 @@ class objc_language : public language_defn
   {
     c_print_type (type, varstring, stream, show, level, flags);
   }
+
+  /* See language.h.  */
+
+  CORE_ADDR skip_trampoline (struct frame_info *frame,
+			     CORE_ADDR stop_pc) const override
+  {
+    struct gdbarch *gdbarch = get_frame_arch (frame);
+    CORE_ADDR real_stop_pc;
+    CORE_ADDR method_stop_pc;
+
+    /* Determine if we are currently in the Objective-C dispatch function.
+       If so, get the address of the method function that the dispatcher
+       would call and use that as the function to step into instead.  Also
+       skip over the trampoline for the function (if any).  This is better
+       for the user since they are only interested in stepping into the
+       method function anyway.  */
+
+    real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
+
+    if (real_stop_pc != 0)
+      find_objc_msgcall (real_stop_pc, &method_stop_pc);
+    else
+      find_objc_msgcall (stop_pc, &method_stop_pc);
+
+    if (method_stop_pc)
+      {
+	real_stop_pc = gdbarch_skip_trampoline_code
+	  (gdbarch, frame, method_stop_pc);
+	if (real_stop_pc == 0)
+	  real_stop_pc = method_stop_pc;
+      }
+
+    return real_stop_pc;
+  }
 };
 
 /* Single instance of the class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index dc5d69873f6..e128fbc676a 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1024,7 +1024,6 @@ extern const struct language_data opencl_language_data =
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   c_value_print_inner,		/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  NULL,				/* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 70f8e5af80a..50143b9facd 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -401,7 +401,6 @@ extern const struct language_data pascal_language_data =
   pascal_print_typedef,		/* Print a typedef using appropriate syntax */
   pascal_value_print_inner,	/* la_value_print_inner */
   pascal_value_print,		/* Print a top-level value */
-  NULL,				/* Language specific skip_trampoline */
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 9afe0b1f16f..682dbf02214 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -2056,7 +2056,6 @@ extern const struct language_data rust_language_data =
   rust_print_typedef,		/* Print a typedef using appropriate syntax */
   rust_value_print_inner,	/* la_value_print_inner */
   c_value_print,		/* Print a top-level value */
-  NULL,				/* Language specific skip_trampoline */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   rust_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCHv2 00/13] Starting to convert languages to separate classes
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (12 preceding siblings ...)
  2020-05-15 15:06   ` [PATCHv2 13/13] gdb: Convert language skip_trampoline " Andrew Burgess
@ 2020-05-15 17:06   ` Tom Tromey
  2020-06-01 16:02   ` Andrew Burgess
  14 siblings, 0 replies; 37+ messages in thread
From: Tom Tromey @ 2020-05-15 17:06 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> Thank you for all the feedback.
Andrew> Differences from v1:

Andrew>   - Addresses all of the improvements suggested in v1.

Andrew>   - Added 4 additional field conversions.

This all looks good to me.

Tom

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCHv2 09/13] gdb: Convert language la_search_name_hash field to a method
  2020-05-15 15:06   ` [PATCHv2 09/13] gdb: Convert language la_search_name_hash " Andrew Burgess
@ 2020-05-15 17:47     ` Christian Biesinger
  0 siblings, 0 replies; 37+ messages in thread
From: Christian Biesinger @ 2020-05-15 17:47 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On Fri, May 15, 2020 at 10:08 AM Andrew Burgess
<andrew.burgess@embecosm.com> wrote:
> diff --git a/gdb/language.c b/gdb/language.c
> index a6b7f1400d5..425081a64c8 100644
> --- a/gdb/language.c
> +++ b/gdb/language.c
> @@ -47,6 +47,7 @@
>  #include <algorithm>
>  #include "gdbarch.h"
>
> +
>  static int unk_lang_parser (struct parser_state *);

That empty line seems like a mistake?

Christian

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCHv2 00/13] Starting to convert languages to separate classes
  2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
                     ` (13 preceding siblings ...)
  2020-05-15 17:06   ` [PATCHv2 00/13] Starting to convert languages to separate classes Tom Tromey
@ 2020-06-01 16:02   ` Andrew Burgess
  14 siblings, 0 replies; 37+ messages in thread
From: Andrew Burgess @ 2020-06-01 16:02 UTC (permalink / raw)
  To: gdb-patches

* Andrew Burgess <andrew.burgess@embecosm.com> [2020-05-15 16:06:39 +0100]:

> Thank you for all the feedback.
> 
> Differences from v1:
> 
>   - Addresses all of the improvements suggested in v1.
> 
>   - Added 4 additional field conversions.
> 
> Thanks,
> Andrew

I'm planning to commit this series soon, I'm currently working on the
next set of conversions which I'll post once this first set is merged.

Thanks,
Andrew



> 
> 
> 
> ---
> 
> Andrew Burgess (13):
>   gdb: Represent all languages as sub-classes of language_defn
>   gdb: Convert language la_print_array_index field to a method
>   gdb: Convert language la_read_var_value field to a method
>   gdb: Convert language la_pass_by_reference field to a method
>   gdb: Convert language la_language_arch_info field to a method
>   gdb: Convert language la_lookup_transparent_type field to a method
>   gdb: Convert language la_iterate_over_symbols field to a method
>   gdb: Convert language la_get_compile_instance field to a method
>   gdb: Convert language la_search_name_hash field to a method
>   gdb: Convert language la_sniff_from_mangled_name field to a method
>   gdb: Convert language la_print_type field to a method
>   gdb: Convert language la_demangle field to a method
>   gdb: Convert language skip_trampoline field to a method
> 
>  gdb/ChangeLog         | 531 ++++++++++++++++++++++++++++++++++++++++++
>  gdb/ada-lang.c        | 359 ++++++++++++++--------------
>  gdb/c-lang.c          | 358 +++++++++++++++++++---------
>  gdb/c-lang.h          |   4 +-
>  gdb/compile/compile.c |   8 +-
>  gdb/cp-abi.c          |   2 +-
>  gdb/cp-support.c      |   9 -
>  gdb/cp-support.h      |   4 -
>  gdb/d-lang.c          | 194 ++++++++-------
>  gdb/dictionary.c      |   2 +-
>  gdb/f-lang.c          | 139 ++++++-----
>  gdb/findvar.c         |  13 +-
>  gdb/gnu-v3-abi.c      |   3 +-
>  gdb/go-lang.c         | 167 +++++++------
>  gdb/language.c        | 253 ++++++++++----------
>  gdb/language.h        | 300 ++++++++++++------------
>  gdb/linespec.c        |   2 +-
>  gdb/m2-lang.c         |  91 ++++----
>  gdb/objc-lang.c       | 136 ++++++-----
>  gdb/opencl-lang.c     | 104 +++++----
>  gdb/p-lang.c          | 137 ++++++-----
>  gdb/rust-exp.y        |   4 +-
>  gdb/rust-lang.c       | 163 ++++++-------
>  gdb/symtab.c          |   8 +-
>  gdb/value.h           |   4 -
>  25 files changed, 1887 insertions(+), 1108 deletions(-)
> 
> -- 
> 2.25.4
> 

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2020-06-01 16:02 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 22:35 [PATCH 0/9] Starting to convert languages to separate classes Andrew Burgess
2020-05-11 22:35 ` [PATCH 1/9] gdb: Represent all languages as sub-classes of language_defn Andrew Burgess
2020-05-11 22:35 ` [PATCH 2/9] gdb: Convert language la_print_array_index field to a method Andrew Burgess
2020-05-11 22:35 ` [PATCH 3/9] gdb: Convert language la_read_var_value " Andrew Burgess
2020-05-14 19:43   ` Tom Tromey
2020-05-11 22:35 ` [PATCH 4/9] gdb: Convert language la_pass_by_reference " Andrew Burgess
2020-05-14 11:00   ` Aktemur, Tankut Baris
2020-05-14 19:49     ` Tom Tromey
2020-05-14 19:48   ` Tom Tromey
2020-05-11 22:35 ` [PATCH 5/9] gdb: Convert language la_language_arch_info " Andrew Burgess
2020-05-11 22:35 ` [PATCH 6/9] gdb: Convert language la_lookup_transparent_type " Andrew Burgess
2020-05-11 22:35 ` [PATCH 7/9] gdb: Convert language la_iterate_over_symbols " Andrew Burgess
2020-05-12 23:21   ` Christian Biesinger
2020-05-11 22:35 ` [PATCH 8/9] gdb: Convert language la_get_compile_instance " Andrew Burgess
2020-05-12 21:11   ` Christian Biesinger
2020-05-11 22:35 ` [PATCH 9/9] gdb: Convert language la_search_name_hash " Andrew Burgess
2020-05-12 21:10   ` Christian Biesinger
2020-05-12 23:17 ` [PATCH 0/9] Starting to convert languages to separate classes Christian Biesinger
2020-05-13  1:33 ` Simon Marchi
2020-05-14 19:57 ` Tom Tromey
2020-05-15 15:06 ` [PATCHv2 00/13] " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 01/13] gdb: Represent all languages as sub-classes of language_defn Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 02/13] gdb: Convert language la_print_array_index field to a method Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 03/13] gdb: Convert language la_read_var_value " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 04/13] gdb: Convert language la_pass_by_reference " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 05/13] gdb: Convert language la_language_arch_info " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 06/13] gdb: Convert language la_lookup_transparent_type " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 07/13] gdb: Convert language la_iterate_over_symbols " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 08/13] gdb: Convert language la_get_compile_instance " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 09/13] gdb: Convert language la_search_name_hash " Andrew Burgess
2020-05-15 17:47     ` Christian Biesinger
2020-05-15 15:06   ` [PATCHv2 10/13] gdb: Convert language la_sniff_from_mangled_name " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 11/13] gdb: Convert language la_print_type " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 12/13] gdb: Convert language la_demangle " Andrew Burgess
2020-05-15 15:06   ` [PATCHv2 13/13] gdb: Convert language skip_trampoline " Andrew Burgess
2020-05-15 17:06   ` [PATCHv2 00/13] Starting to convert languages to separate classes Tom Tromey
2020-06-01 16:02   ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).