public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCHv2 00/18] Further updates for the language class structure
@ 2020-08-05 14:45 Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 01/18] gdb: Convert la_struct_too_deep_ellipsis to a method Andrew Burgess
                   ` (18 more replies)
  0 siblings, 19 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

This v2 series replaces, and extends the earlier series I posted here:

    https://sourceware.org/pipermail/gdb-patches/2020-July/170288.html

The first 10 patches are the same as the previous series, while the
remaining 8 are new in this version of the series.

After this series the language_data base class is completely removed.

As I mentioned in the original patch series, I'm not 100% sure that
converting static data fields from language_data into virtual methods
on language_defn is the right approach, but getting rid of
language_data does feel like a good thing, so I pushed through and
completed the task.

I'd be interested in any feedback, do people think this is the right
approach, or are there any suggestions for a better approach.

Thanks,
Andrew

---

Andrew Burgess (18):
  gdb: Convert la_struct_too_deep_ellipsis to a method
  gdb: Convert la_name_of_this to a method
  gdb: Convert la_name and la_natural_name to methods
  gdb: Convert la_filename_extensions to a method
  gdb: Move la_language into the language_defn class
  gdb: Convert language_data::c_style_arrays to a method
  gdb: Fix an incorrect comment
  gdb: Convert language_data::string_lower_bound to a method
  gdb: Convert la_store_sym_names_in_linkage_form_p to a method
  gdb: Override store_sym_names_in_linkage_form_p for Go language
  gdb: Convert language_data::la_range_check to a method
  gdb: Convert language_data::la_case_sensitivity to a method
  gdb: Convert language_data::la_array_ordering to a method
  gdb: Convert language_data::la_macro_expansion to a method
  gdb: Convert language_data::la_varobj_ops to a method
  gdb: Convert language_data::la_exp_desc to a method
  gdb: Convert language_data::la_op_print_tab to a method
  gdb: Remove language_data struct

 gdb/ChangeLog         | 627 ++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c        |  78 ++++--
 gdb/ax-gdb.c          |   2 +-
 gdb/c-exp.y           |   2 +-
 gdb/c-lang.c          | 268 ++++++++++--------
 gdb/compile/compile.c |   2 +-
 gdb/cp-valprint.c     |   4 +-
 gdb/d-lang.c          |  62 +++--
 gdb/dwarf2/read.c     |  10 +-
 gdb/eval.c            |   4 +-
 gdb/expprint.c        |  22 +-
 gdb/f-lang.c          |  87 ++++--
 gdb/go-lang.c         |  48 ++--
 gdb/infcall.c         |   2 +-
 gdb/language.c        | 186 ++++++++-----
 gdb/language.h        | 238 ++++++++--------
 gdb/m2-lang.c         |  60 ++--
 gdb/mi/mi-cmd-var.c   |   2 +-
 gdb/objc-lang.c       |  62 +++--
 gdb/opencl-lang.c     |  48 ++--
 gdb/p-lang.c          |  63 +++--
 gdb/parse.c           |   9 +-
 gdb/rust-lang.c       |  62 +++--
 gdb/symfile.c         |   1 +
 gdb/symtab.c          |  10 +-
 gdb/valarith.c        |   6 +-
 gdb/valops.c          |  14 +-
 gdb/valprint.c        |   4 +-
 gdb/value.c           |   7 +-
 gdb/varobj.c          |   2 +-
 gdb/varobj.h          |   2 -
 31 files changed, 1395 insertions(+), 599 deletions(-)

-- 
2.25.4


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

* [PATCHv2 01/18] gdb: Convert la_struct_too_deep_ellipsis to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 02/18] gdb: Convert la_name_of_this " Andrew Burgess
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_struct_too_deep_ellipsis member variable to
a method in language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove
	la_struct_too_deep_ellipsis initializer.
	(ada_language::struct_too_deep_ellipsis): New member function.
	* c-lang.c (c_language_data): Remove la_struct_too_deep_ellipsis
	initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* cp-valprint.c (cp_print_value): Update call to
	struct_too_deep_ellipsis.
	* d-lang.c (d_language_data): Remove la_struct_too_deep_ellipsis
	initializer.
	* f-lang.c (f_language_data): Likewise.
	(f_language::struct_too_deep_ellipsis): New member function.
	* go-lang.c (go_language_data): Remove la_struct_too_deep_ellipsis
	initializer.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_struct_too_deep_ellipsis
	member variable.
	(language_defn::struct_too_deep_ellipsis): New member function.
	* m2-lang.c (m2_language_data): Remove la_struct_too_deep_ellipsis
	initializer.Q
	* 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.
	* valprint.c (val_print_check_max_depth): Update call to
	struct_too_deep_ellipsis.
---
 gdb/ChangeLog     | 32 ++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  5 ++++-
 gdb/c-lang.c      |  4 ----
 gdb/cp-valprint.c |  4 ++--
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  6 +++++-
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 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/valprint.c    |  4 ++--
 15 files changed, 55 insertions(+), 25 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 29951528e5e..835bbf2abf6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13729,7 +13729,6 @@ extern const struct language_data ada_language_data =
   0,                            /* c-style arrays */
   1,                            /* String lower bound */
   &ada_varobj_ops,
-  "(...)"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the Ada language.  */
@@ -14187,6 +14186,10 @@ class ada_language : public language_defn
     return ada_is_string_type (type);
   }
 
+  /* See language.h.  */
+
+  const char *struct_too_deep_ellipsis () const override
+  { return "(...)"; }
 
 protected:
   /* See language.h.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index f29f2cef610..36c49f7c8a2 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -895,7 +895,6 @@ extern const struct language_data c_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &c_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the C language.  */
@@ -996,7 +995,6 @@ extern const struct language_data cplus_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &cplus_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* A class for the C++ language.  */
@@ -1194,7 +1192,6 @@ extern const struct language_data asm_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* A class for the ASM language.  */
@@ -1250,7 +1247,6 @@ extern const struct language_data minimal_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* A class for the minimal language.  */
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index a02fee6b552..819736dac9e 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -499,8 +499,8 @@ cp_print_value (struct value *val, struct ui_file *stream,
 	      && recurse >= options->max_depth)
 	    {
 	      const struct language_defn *language = current_language;
-	      gdb_assert (language->la_struct_too_deep_ellipsis != NULL);
-	      fputs_filtered (language->la_struct_too_deep_ellipsis, stream);
+	      gdb_assert (language->struct_too_deep_ellipsis () != NULL);
+	      fputs_filtered (language->struct_too_deep_ellipsis (), stream);
 	    }
 	  else
 	    {
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 4ebb011ee9b..b027c89ff8e 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -148,7 +148,6 @@ extern const struct language_data d_language_data =
   1,				/* C-style arrays.  */
   0,				/* String lower bound.  */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the D language.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 58b41d11d11..c9320012923 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -508,7 +508,6 @@ extern const struct language_data f_language_data =
   0,				/* arrays are first-class (not c-style) */
   1,				/* String lower bound */
   &default_varobj_ops,
-  "(...)"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the Fortran language.  */
@@ -707,6 +706,11 @@ class f_language : public language_defn
 		&& TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_CHAR));
   }
 
+  /* See language.h.  */
+
+  const char *struct_too_deep_ellipsis () const override
+  { return "(...)"; }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index cb42ef1b7cf..deff33a8abf 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -523,7 +523,6 @@ extern const struct language_data go_language_data =
   1,				/* C-style arrays.  */
   0,				/* String lower bound.  */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the Go language.  */
diff --git a/gdb/language.c b/gdb/language.c
index c993cfc57a6..914c75b08e7 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -798,7 +798,6 @@ extern const struct language_data unknown_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the unknown language.  */
@@ -924,7 +923,6 @@ extern const struct language_data auto_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index d2e5b733077..f2195ed4e8d 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -266,12 +266,6 @@ struct language_data
 
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
-
-    /* This string is used by the 'set print max-depth' setting.  When GDB
-       replaces a struct or union (during value printing) that is "too
-       deep" this string is displayed instead.  */
-    const char *la_struct_too_deep_ellipsis;
-
   };
 
 /* Base class from which all other language classes derive.  */
@@ -553,6 +547,16 @@ struct language_defn : language_data
   /* Return true if TYPE is a string type.  */
   virtual bool is_string_type_p (struct type *type) const;
 
+  /* Return a string that is used by the 'set print max-depth' setting.
+     When GDB replaces a struct or union (during value printing) that is
+     "too deep" this string is displayed instead.  The default value here
+     suits most languages.  If overriding then the string here should
+     ideally be similar in style to the default; an opener, three '.', and
+     a closer.  */
+
+  virtual const char *struct_too_deep_ellipsis () const
+  { return "{...}"; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 2c39359d289..9e2d0d75f17 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -214,7 +214,6 @@ extern const struct language_data m2_language_data =
   0,				/* arrays are first-class (not c-style) */
   0,				/* String lower bound */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 63cdac1b035..00d77041b45 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -343,7 +343,6 @@ extern const struct language_data objc_language_data =
   1,				/* C-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index eccf1df9621..dade720cd53 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1022,7 +1022,6 @@ extern const struct language_data opencl_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the OpenCL language.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 07afbdda5bb..2a6389344da 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -272,7 +272,6 @@ extern const struct language_data pascal_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the Pascal language.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index ddd4b57d294..a903dae1758 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1926,7 +1926,6 @@ extern const struct language_data rust_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
 /* Class representing the Rust language.  */
diff --git a/gdb/valprint.c b/gdb/valprint.c
index db98ca2abc9..f3519bdc954 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -997,8 +997,8 @@ val_print_check_max_depth (struct ui_file *stream, int recurse,
 {
   if (options->max_depth > -1 && recurse >= options->max_depth)
     {
-      gdb_assert (language->la_struct_too_deep_ellipsis != NULL);
-      fputs_filtered (language->la_struct_too_deep_ellipsis, stream);
+      gdb_assert (language->struct_too_deep_ellipsis () != NULL);
+      fputs_filtered (language->struct_too_deep_ellipsis (), stream);
       return true;
     }
 
-- 
2.25.4


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

* [PATCHv2 02/18] gdb: Convert la_name_of_this to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 01/18] gdb: Convert la_struct_too_deep_ellipsis to a method Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 03/18] gdb: Convert la_name and la_natural_name to methods Andrew Burgess
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_name_of_this member variable to a virtual
method language_defn::name_of_this.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_name_of_this
	initializer.
	* ax-gdb.c (gen_expr): Update call to name_of_this.
	* c-exp.y (classify_name): Likewise.
	* c-lang.c (c_language_data): Remove la_name_of_this initializer.
	(cplus_language_data): Likewise.
	(cplus_language::name_of_this): New member function.
	(asm_language_data): Remove la_name_of_this initializer.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	(d_language::name_of_this): New member function.
	* expprint.c (print_subexp_standard): Update call to name_of_this.
	* f-lang.c (f_language_data): Remove la_name_of_this initializer.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Likewise.
	(unknown_language::name_of_this): New member function.
	(auto_language_data): Remove la_name_of_this initializer.
	(auto_language::name_of_this): New member function.
	* language.h (language_data): Delete la_name_of_this member
	variable.
	(language_defn::name_of_this): New member function.
	* m2-lang.c (m2_language_data): Remove la_name_of_this
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	(objc_language::name_of_this): New member function.
	* opencl-lang.c (opencl_language_data): Remove la_name_of_this
	initializer.
	* p-lang.c (pascal_language_data): Likewise.
	(pascal_language::name_of_this): New member function.
	* rust-lang.c (rust_language_data): Remove la_name_of_this
	initializer.
	* symtab.c (lookup_language_this): Update call to name_of_this.
	(lookup_symbol_aux): Likewise.
	* valops.c (value_of_this): Likewise.
---
 gdb/ChangeLog     | 37 +++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/ax-gdb.c      |  2 +-
 gdb/c-exp.y       |  2 +-
 gdb/c-lang.c      |  9 +++++----
 gdb/d-lang.c      |  6 +++++-
 gdb/expprint.c    |  4 ++--
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 12 ++++++++++--
 gdb/language.h    | 13 ++++++++-----
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  6 +++++-
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  6 +++++-
 gdb/rust-lang.c   |  1 -
 gdb/symtab.c      |  6 +++---
 gdb/valops.c      |  4 ++--
 18 files changed, 84 insertions(+), 29 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 835bbf2abf6..3c40eca03f2 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13723,7 +13723,6 @@ extern const struct language_data ada_language_data =
   macro_expansion_no,
   ada_extensions,
   &ada_exp_descriptor,
-  NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_op_print_tab,             /* expression operators for printing */
   0,                            /* c-style arrays */
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 34e22b289ec..ddc862a4c2d 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2234,7 +2234,7 @@ gen_expr (struct expression *exp, union exp_element **pc,
 
 	sym = lookup_language_this (lang, b).symbol;
 	if (!sym)
-	  error (_("no `%s' found"), lang->la_name_of_this);
+	  error (_("no `%s' found"), lang->name_of_this ());
 
 	gen_var_ref (ax, value, sym);
 
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 7fc23c4c8d2..b03855ba7af 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -3036,7 +3036,7 @@ classify_name (struct parser_state *par_state, const struct block *block,
   memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
 
   bsym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN,
-			par_state->language ()->la_name_of_this
+			par_state->language ()->name_of_this ()
 			? &is_a_field_of_this : NULL);
 
   if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK)
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 36c49f7c8a2..484ac814b56 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -889,7 +889,6 @@ extern const struct language_data c_language_data =
   macro_expansion_c,
   c_extensions,
   &exp_descriptor_c,
-  NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
@@ -989,7 +988,6 @@ extern const struct language_data cplus_language_data =
   macro_expansion_c,
   cplus_extensions,
   &exp_descriptor_c,
-  "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
@@ -1153,6 +1151,11 @@ class cplus_language : public language_defn
     return cp_lookup_symbol_nonlocal (this, name, block, domain);
   }
 
+  /* See language.h.  */
+
+  const char *name_of_this () const override
+  { return "this"; }
+
 protected:
 
   /* See language.h.  */
@@ -1186,7 +1189,6 @@ extern const struct language_data asm_language_data =
   macro_expansion_c,
   asm_extensions,
   &exp_descriptor_c,
-  NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
@@ -1241,7 +1243,6 @@ extern const struct language_data minimal_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_c,
-  NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index b027c89ff8e..c60e0702b22 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -142,7 +142,6 @@ extern const struct language_data d_language_data =
   macro_expansion_no,
   d_extensions,
   &exp_descriptor_c,
-  "this",
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_op_print_tab,		/* Expression operators for printing.  */
   1,				/* C-style arrays.  */
@@ -271,6 +270,11 @@ class d_language : public language_defn
   {
     return d_parse (ps);
   }
+
+  /* See language.h.  */
+
+  const char *name_of_this () const override
+  { return "this"; }
 };
 
 /* Single instance of the D language class.  */
diff --git a/gdb/expprint.c b/gdb/expprint.c
index 5427a56f6ae..24d647e006c 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -504,8 +504,8 @@ print_subexp_standard (struct expression *exp, int *pos,
 
     case OP_THIS:
       ++(*pos);
-      if (exp->language_defn->la_name_of_this)
-	fputs_filtered (exp->language_defn->la_name_of_this, stream);
+      if (exp->language_defn->name_of_this () != NULL)
+	fputs_filtered (exp->language_defn->name_of_this (), stream);
       else
 	fprintf_styled (stream, metadata_style.style (),
 			_("<language %s has no 'this'>"),
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index c9320012923..a27f2157b42 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -502,7 +502,6 @@ extern const struct language_data f_language_data =
   macro_expansion_no,
   f_extensions,
   &exp_descriptor_f,
-  NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   f_op_print_tab,		/* expression operators for printing */
   0,				/* arrays are first-class (not c-style) */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index deff33a8abf..df7cbc79b19 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -517,7 +517,6 @@ extern const struct language_data go_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_c,
-  NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   go_op_print_tab,		/* Expression operators for printing.  */
   1,				/* C-style arrays.  */
diff --git a/gdb/language.c b/gdb/language.c
index 914c75b08e7..7ccd0ac2b8e 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -792,7 +792,6 @@ extern const struct language_data unknown_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
@@ -898,6 +897,11 @@ class unknown_language : public language_defn
   {
     return default_is_string_type_p (type);
   }
+
+  /* See language.h.  */
+
+  const char *name_of_this () const override
+  { return "this"; }
 };
 
 /* Single instance of the unknown language class.  */
@@ -917,7 +921,6 @@ extern const struct language_data auto_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
@@ -1023,6 +1026,11 @@ class auto_language : public language_defn
   {
     return default_is_string_type_p (type);
   }
+
+  /* See language.h.  */
+
+  const char *name_of_this () const override
+  { return "this"; }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index f2195ed4e8d..4c9453f33cb 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -227,11 +227,6 @@ struct language_data
 
     /* Now come some hooks for lookup_symbol.  */
 
-    /* If this is non-NULL, specifies the name that of the implicit
-       local variable that refers to the current object instance.  */
-
-    const char *la_name_of_this;
-
     /* True if the symbols names should be stored in GDB's data structures
        for minimal/partial/full symbols using their linkage (aka mangled)
        form; false if the symbol names should be demangled first.
@@ -557,6 +552,14 @@ struct language_defn : language_data
   virtual const char *struct_too_deep_ellipsis () const
   { return "{...}"; }
 
+  /* If this returns non-NULL then the string returned specifies the name
+     of the implicit local variable that refers to the current object
+     instance.  Return NULL (the default) for languages that have no name
+     for the current object instance.  */
+
+  virtual const char *name_of_this () const
+  { return nullptr; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 9e2d0d75f17..3ba5026b2bc 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -208,7 +208,6 @@ extern const struct language_data m2_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_modula2,
-  NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   m2_op_print_tab,		/* expression operators for printing */
   0,				/* arrays are first-class (not c-style) */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 00d77041b45..f18a7761532 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -337,7 +337,6 @@ extern const struct language_data objc_language_data =
   macro_expansion_c,
   objc_extensions,
   &exp_descriptor_standard,
-  "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   objc_op_print_tab,		/* Expression operators for printing */
   1,				/* C-style arrays */
@@ -418,6 +417,11 @@ class objc_language : public language_defn
 
     return real_stop_pc;
   }
+
+  /* See language.h.  */
+
+  const char *name_of_this () const override
+  { return "self"; }
 };
 
 /* Single instance of the class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index dade720cd53..37ac1386b2d 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1016,7 +1016,6 @@ extern const struct language_data opencl_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_opencl,
-  NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 2a6389344da..ab24d48bf8f 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -266,7 +266,6 @@ extern const struct language_data pascal_language_data =
   macro_expansion_no,
   p_extensions,
   &exp_descriptor_standard,
-  "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   pascal_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
@@ -497,6 +496,11 @@ class pascal_language : public language_defn
     return is_pascal_string_type (type, nullptr, nullptr, nullptr,
 				  nullptr, nullptr) > 0;
   }
+
+  /* See language.h.  */
+
+  const char *name_of_this () const override
+  { return "this"; }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index a903dae1758..94515ed17e2 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1920,7 +1920,6 @@ extern const struct language_data rust_language_data =
   macro_expansion_no,
   rust_extensions,
   &exp_descriptor_rust,
-  NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   1,				/* c-style arrays */
diff --git a/gdb/symtab.c b/gdb/symtab.c
index f96ad9554d9..ff88adfe020 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1912,7 +1912,7 @@ struct block_symbol
 lookup_language_this (const struct language_defn *lang,
 		      const struct block *block)
 {
-  if (lang->la_name_of_this == NULL || block == NULL)
+  if (lang->name_of_this () == NULL || block == NULL)
     return {};
 
   if (symbol_lookup_debug > 1)
@@ -1929,7 +1929,7 @@ lookup_language_this (const struct language_defn *lang,
     {
       struct symbol *sym;
 
-      sym = block_lookup_symbol (block, lang->la_name_of_this,
+      sym = block_lookup_symbol (block, lang->name_of_this (),
 				 symbol_name_match_type::SEARCH_NAME,
 				 VAR_DOMAIN);
       if (sym != NULL)
@@ -2069,7 +2069,7 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
 	  if (t->code () != TYPE_CODE_STRUCT
 	      && t->code () != TYPE_CODE_UNION)
 	    error (_("Internal error: `%s' is not an aggregate"),
-		   langdef->la_name_of_this);
+		   langdef->name_of_this ());
 
 	  if (check_field (t, name, is_a_field_of_this))
 	    {
diff --git a/gdb/valops.c b/gdb/valops.c
index 0eb2b096211..d05cad77b3c 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3716,7 +3716,7 @@ value_of_this (const struct language_defn *lang)
   const struct block *b;
   struct frame_info *frame;
 
-  if (!lang->la_name_of_this)
+  if (lang->name_of_this () == NULL)
     error (_("no `this' in current language"));
 
   frame = get_selected_frame (_("no frame selected"));
@@ -3726,7 +3726,7 @@ value_of_this (const struct language_defn *lang)
   sym = lookup_language_this (lang, b);
   if (sym.symbol == NULL)
     error (_("current stack frame does not contain a variable named `%s'"),
-	   lang->la_name_of_this);
+	   lang->name_of_this ());
 
   return read_var_value (sym.symbol, sym.block, frame);
 }
-- 
2.25.4


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

* [PATCHv2 03/18] gdb: Convert la_name and la_natural_name to methods
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 01/18] gdb: Convert la_struct_too_deep_ellipsis to a method Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 02/18] gdb: Convert la_name_of_this " Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 04/18] gdb: Convert la_filename_extensions to a method Andrew Burgess
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert the two language_data member variables la_name and
la_natural_name to virtual methods in language_defn struct called name
and natural_name respectively.

The virtual methods in the language_defn base class are pure virtual,
as every language must implement these, and as every language has a
unique name there's no sensible default here.

Given that every language must implement these methods I did wonder
about making this data passed into the base class constructor, but in
the end I went with the virtual method approach.  I'm open to changing
this approach if people prefer the constructor approach.

During updating the calls to language_defn::name I found in
add_set_language_command a place where we took la_name and then
capitalised the first letter to create a language name that could be
used in the documentation string.  I replaced this with a use of
natural_name instead as this seemed a better choice, in most cases
this will make no difference, as for most languages the natural_name
is just the name with the first character in upper case, but for some
languages, for example 'Open-CL' and 'Objective-C' this is not the
case.

In the case of asm_language the name is 'asm', while the natural_name
was previously 'assembly'.  I changed the natural name to 'Assembly',
this makes the documentation string case above cleaner, however, this
will change the MI output for -var-info-expression, where the 'lang'
field will change from 'assembly' to 'Assembly'.  It is possible this
could be a breaking change if a front-end is relying on the existing
name.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_name and
	la_natural_name initializers.
	(ada_language::name): New member function.
	(ada_language::natural_name): New member function.
	* c-lang.c (c_language_data): Remove la_name and
	la_natural_name initializers.
	(c_language::name): New member function.
	(c_language::natural_name): New member function.
	(cplus_language_data): Remove la_name and
	la_natural_name initializers.
	(cplus_language::name): New member function.
	(cplus_language::natural_name): New member function.
	(asm_language_data): Remove la_name and
	la_natural_name initializers.
	(asm_language::name): New member function.
	(asm_language::natural_name): New member function.
	(minimal_language_data): Remove la_name and
	la_natural_name initializers.
	(minimal_language::name): New member function.
	(minimal_language::natural_name): New member function.
	* compile/compile.c (compile_to_object): Update call to
	lanugage_defn::name.
	* d-lang.c (d_language_data): Remove la_name and
	la_natural_name initializers.
	(d_language::name): New member function.
	(d_language::natural_name): New member function.
	* expprint.c (print_subexp_standard): Update call to
	language_defn::name.
	(dump_raw_expression): Likewise
	(dump_prefix_expression): Likewise.
	* f-lang.c (f_language_data): Remove la_name and
	la_natural_name initializers.
	(f_language::name): New member function.
	(f_language::natural_name): New member function.
	* go-lang.c (go_language_data): Remove la_name and
	la_natural_name initializers.
	(go_language::name): New member function.
	(go_language::natural_name): New member function.
	* language.c (show_language_command): Update call to
	language_defn::name.
	(set_language_command): Likewise.
	(language_enum): Likewise.
	(language_str): Likewise.
	(add_set_language_command): Likewise, use
	language_defn::natural_name in the doc string.
	(unknown_language_data): Remove la_name and
	la_natural_name initializers.
	(unknown_language::name): New member function.
	(unknown_language::natural_name): New member function.
	(auto_language_data): Remove la_name and
	la_natural_name initializers.
	(auto_language::name): New member function.
	(auto_language::natural_name): New member function.
	(language_lookup_primitive_type_as_symbol): Update call to
	language_defn::name.
	* language.h (language_data): Remove la_name and la_natural_name
	member variables.
	(language_defn::name): New member function.
	(language_defn::natural_name): New member function.
	* m2-lang.c (m2_language_data): Remove la_name and
	la_natural_name initializers.
	(m2_language::name): New member function.
	(m2_language::natural_name): New member function.
	* mi/mi-cmd-var.c (mi_cmd_var_info_expression): Update call to
	language_defn::natural_name.
	* objc-lang.c (objc_language_data): Remove la_name and
	la_natural_name initializers.
	(objc_language::name): New member function.
	(objc_language::natural_name): New member function.
	* opencl-lang.c (opencl_language_data): Remove la_name and
	la_natural_name initializers.
	(opencl_language::name): New member function.
	(opencl_language::natural_name): New member function.
	* p-lang.c (pascal_language_data): Remove la_name and
	la_natural_name initializers.
	(pascal_language::name): New member function.
	(pascal_language::natural_name): New member function.
	* rust-lang.c (rust_language_data): Remove la_name and
	la_natural_name initializers.
	(rust_language::name): New member function.
	(rust_language::natural_name): New member function.
	* symtab.c (lookup_language_this): Update call to
	language_defn::name.
---
 gdb/ChangeLog         | 86 +++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c        | 12 +++++-
 gdb/c-lang.c          | 48 ++++++++++++++++++++----
 gdb/compile/compile.c |  2 +-
 gdb/d-lang.c          | 12 +++++-
 gdb/expprint.c        |  6 +--
 gdb/f-lang.c          | 12 +++++-
 gdb/go-lang.c         | 12 +++++-
 gdb/language.c        | 52 ++++++++++++++++----------
 gdb/language.h        | 16 ++++----
 gdb/m2-lang.c         | 12 +++++-
 gdb/mi/mi-cmd-var.c   |  2 +-
 gdb/objc-lang.c       | 12 +++++-
 gdb/opencl-lang.c     | 12 +++++-
 gdb/p-lang.c          | 13 ++++++-
 gdb/rust-lang.c       | 12 +++++-
 gdb/symtab.c          |  2 +-
 17 files changed, 263 insertions(+), 60 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3c40eca03f2..019abceb0c5 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13713,8 +13713,6 @@ static const char *ada_extensions[] =
 
 extern const struct language_data ada_language_data =
 {
-  "ada",                        /* Language name */
-  "Ada",
   language_ada,
   range_check_off,
   case_sensitive_on,            /* Yes, Ada is case-insensitive, but
@@ -13739,6 +13737,16 @@ class ada_language : public language_defn
     : language_defn (language_ada, ada_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "ada"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Ada"; }
+
   /* Print an array element index using the Ada syntax.  */
 
   void print_array_index (struct type *index_type,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 484ac814b56..04e9eae8912 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -880,8 +880,6 @@ static const char *c_extensions[] =
 
 extern const struct language_data c_language_data =
 {
-  "c",				/* Language name */
-  "C",
   language_c,
   range_check_off,
   case_sensitive_on,
@@ -905,6 +903,16 @@ class c_language : public language_defn
     : language_defn (language_c, c_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "c"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "C"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
@@ -979,8 +987,6 @@ static const char *cplus_extensions[] =
 
 extern const struct language_data cplus_language_data =
 {
-  "c++",			/* Language name */
-  "C++",
   language_cplus,
   range_check_off,
   case_sensitive_on,
@@ -1006,6 +1012,16 @@ class cplus_language : public language_defn
 
   /* See language.h.  */
 
+  const char *name () const override
+  { return "c++"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "C++"; }
+
+  /* See language.h.  */
+
   struct language_pass_by_ref_info pass_by_reference_info
 	(struct type *type) const override
   {
@@ -1180,8 +1196,6 @@ static const char *asm_extensions[] =
 
 extern const struct language_data asm_language_data =
 {
-  "asm",			/* Language name */
-  "assembly",
   language_asm,
   range_check_off,
   case_sensitive_on,
@@ -1205,6 +1219,16 @@ class asm_language : public language_defn
     : language_defn (language_asm, asm_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "asm"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Assembly"; }
+
   /* See language.h.
 
      FIXME: Should this have its own arch info method?  */
@@ -1234,8 +1258,6 @@ static asm_language asm_language_defn;
 
 extern const struct language_data minimal_language_data =
 {
-  "minimal",			/* Language name */
-  "Minimal",
   language_minimal,
   range_check_off,
   case_sensitive_on,
@@ -1259,6 +1281,16 @@ class minimal_language : public language_defn
     : language_defn (language_minimal, minimal_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "minimal"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Minimal"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 0c29a0476e7..8d8c2b14eba 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -695,7 +695,7 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
 			(current_language->get_compile_instance ());
   if (compiler == nullptr)
     error (_("No compiler support for language %s."),
-	   current_language->la_name);
+	   current_language->name ());
   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 c60e0702b22..0985f535743 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -133,8 +133,6 @@ static const char *d_extensions[] =
 
 extern const struct language_data d_language_data =
 {
-  "d",
-  "D",
   language_d,
   range_check_off,
   case_sensitive_on,
@@ -158,6 +156,16 @@ class d_language : public language_defn
     : language_defn (language_d, d_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "d"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "D"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/expprint.c b/gdb/expprint.c
index 24d647e006c..36e18ea1a9f 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -509,7 +509,7 @@ print_subexp_standard (struct expression *exp, int *pos,
       else
 	fprintf_styled (stream, metadata_style.style (),
 			_("<language %s has no 'this'>"),
-			exp->language_defn->la_name);
+			exp->language_defn->name ());
       return;
 
       /* Modula-2 ops */
@@ -734,7 +734,7 @@ dump_raw_expression (struct expression *exp, struct ui_file *stream,
   if (note)
     fprintf_filtered (stream, ", %s:", note);
   fprintf_filtered (stream, "\n\tLanguage %s, %d elements, %ld bytes each.\n",
-		    exp->language_defn->la_name, exp->nelts,
+		    exp->language_defn->name (), exp->nelts,
 		    (long) sizeof (union exp_element));
   fprintf_filtered (stream, "\t%5s  %20s  %16s  %s\n", "Index", "Opcode",
 		    "Hex Value", "String Value");
@@ -1159,7 +1159,7 @@ dump_prefix_expression (struct expression *exp, struct ui_file *stream)
   fputs_filtered (", after conversion to prefix form:\nExpression: `", stream);
   print_expression (exp, stream);
   fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
-		    exp->language_defn->la_name, exp->nelts,
+		    exp->language_defn->name (), exp->nelts,
 		    (long) sizeof (union exp_element));
   fputs_filtered ("\n", stream);
 
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index a27f2157b42..a31f863cc09 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -493,8 +493,6 @@ static const struct exp_descriptor exp_descriptor_f =
 
 extern const struct language_data f_language_data =
 {
-  "fortran",
-  "Fortran",
   language_fortran,
   range_check_on,
   case_sensitive_off,
@@ -518,6 +516,16 @@ class f_language : public language_defn
     : language_defn (language_fortran, f_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "fortran"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Fortran"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index df7cbc79b19..6e9b4875696 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -508,8 +508,6 @@ enum go_primitive_types {
 
 extern const struct language_data go_language_data =
 {
-  "go",
-  "Go",
   language_go,
   range_check_off,
   case_sensitive_on,
@@ -533,6 +531,16 @@ class go_language : public language_defn
     : language_defn (language_go, go_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "go"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Go"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/language.c b/gdb/language.c
index 7ccd0ac2b8e..0b1b4882038 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -98,11 +98,11 @@ show_language_command (struct ui_file *file, int from_tty,
     fprintf_filtered (gdb_stdout,
 		      _("The current source language is "
 			"\"auto; currently %s\".\n"),
-		      current_language->la_name);
+		      current_language->name ());
   else
     fprintf_filtered (gdb_stdout,
 		      _("The current source language is \"%s\".\n"),
-		      current_language->la_name);
+		      current_language->name ());
 
   if (has_stack_frames ())
     {
@@ -131,7 +131,7 @@ set_language_command (const char *ignore,
   /* Search the list of languages for a match.  */
   for (const auto &lang : language_defn::languages)
     {
-      if (strcmp (lang->la_name, language) == 0)
+      if (strcmp (lang->name (), language) == 0)
 	{
 	  /* Found it!  Go into manual mode, and use this language.  */
 	  if (lang->la_language == language_auto)
@@ -442,7 +442,7 @@ enum language
 language_enum (const char *str)
 {
   for (const auto &lang : language_defn::languages)
-    if (strcmp (lang->la_name, str) == 0)
+    if (strcmp (lang->name (), str) == 0)
       return lang->la_language;
 
   if (strcmp (str, "local") == 0)
@@ -466,7 +466,7 @@ language_def (enum language lang)
 const char *
 language_str (enum language lang)
 {
-  return language_def (lang)->la_name;
+  return language_def (lang)->name ();
 }
 
 \f
@@ -486,9 +486,9 @@ add_set_language_command ()
   /* Display "auto", "local" and "unknown" first, and then the rest,
      alpha sorted.  */
   const char **language_names_p = language_names;
-  *language_names_p++ = language_def (language_auto)->la_name;
+  *language_names_p++ = language_def (language_auto)->name ();
   *language_names_p++ = "local";
-  *language_names_p++ = language_def (language_unknown)->la_name;
+  *language_names_p++ = language_def (language_unknown)->name ();
   const char **sort_begin = language_names_p;
   for (const auto &lang : language_defn::languages)
     {
@@ -496,7 +496,7 @@ add_set_language_command ()
       if (lang->la_language == language_auto
 	  || lang->la_language == language_unknown)
 	continue;
-      *language_names_p++ = lang->la_name;
+      *language_names_p++ = lang->name ();
     }
   *language_names_p = NULL;
   std::sort (sort_begin, language_names_p, compare_cstrings);
@@ -524,15 +524,11 @@ add_set_language_command ()
 	  || lang->la_language == language_auto)
 	continue;
 
-      /* FIXME: i18n: for now assume that the human-readable name is
-	 just a capitalization of the internal name.  */
       /* Note that we add the newline at the front, so we don't wind
 	 up with a trailing newline.  */
-      doc.printf ("\n%-16s Use the %c%s language",
-		  lang->la_name,
-		  /* Capitalize first letter of language name.  */
-		  toupper (lang->la_name[0]),
-		  lang->la_name + 1);
+      doc.printf ("\n%-16s Use the %s language",
+		  lang->name (),
+		  lang->natural_name ());
     }
 
   add_setshow_enum_cmd ("language", class_support,
@@ -783,8 +779,6 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 
 extern const struct language_data unknown_language_data =
 {
-  "unknown",
-  "Unknown",
   language_unknown,
   range_check_off,
   case_sensitive_on,
@@ -808,6 +802,16 @@ class unknown_language : public language_defn
     : language_defn (language_unknown, unknown_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "unknown"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Unknown"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
@@ -912,8 +916,6 @@ static unknown_language unknown_language_defn;
 
 extern const struct language_data auto_language_data =
 {
-  "auto",
-  "Auto",
   language_auto,
   range_check_off,
   case_sensitive_on,
@@ -937,6 +939,16 @@ class auto_language : public language_defn
     : language_defn (language_auto, auto_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "auto"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Auto"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
@@ -1209,7 +1221,7 @@ language_lookup_primitive_type_as_symbol (const struct language_defn *la,
       fprintf_unfiltered (gdb_stdlog,
 			  "language_lookup_primitive_type_as_symbol"
 			  " (%s, %s, %s)",
-			  la->la_name, host_address_to_string (gdbarch), name);
+			  la->name (), host_address_to_string (gdbarch), name);
     }
 
   typep = language_lookup_primitive_type_1 (lai, name);
diff --git a/gdb/language.h b/gdb/language.h
index 4c9453f33cb..980e3647af9 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -188,14 +188,6 @@ extern const char *default_word_break_characters (void);
 
 struct language_data
   {
-    /* Name of the language.  */
-
-    const char *la_name;
-
-    /* Natural or official name of the language.  */
-
-    const char *la_natural_name;
-
     /* its symtab language-enum (defs.h).  */
 
     enum language la_language;
@@ -275,6 +267,14 @@ struct language_defn : language_data
     languages[lang] = this;
   }
 
+  /* Name of the language.  */
+
+  virtual const char *name () const = 0;
+
+  /* Natural or official name of the language.  */
+
+  virtual const char *natural_name () const = 0;
+
   /* Print the index of an element of an array.  This default
      implementation prints using C99 syntax.  */
 
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 3ba5026b2bc..9806caf6103 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -199,8 +199,6 @@ const struct exp_descriptor exp_descriptor_modula2 =
 
 extern const struct language_data m2_language_data =
 {
-  "modula-2",
-  "Modula-2",
   language_m2,
   range_check_on,
   case_sensitive_on,
@@ -224,6 +222,16 @@ class m2_language : public language_defn
     : language_defn (language_m2, m2_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "modula-2"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Modula-2"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index da5bf2d7fac..65a2ba146dd 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -458,7 +458,7 @@ mi_cmd_var_info_expression (const char *command, char **argv, int argc)
 
   lang = varobj_get_language (var);
 
-  uiout->field_string ("lang", lang->la_natural_name);
+  uiout->field_string ("lang", lang->natural_name ());
 
   std::string exp = varobj_get_expression (var);
   uiout->field_string ("exp", exp.c_str ());
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index f18a7761532..99306a6c9c3 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -328,8 +328,6 @@ static const char *objc_extensions[] =
 
 extern const struct language_data objc_language_data =
 {
-  "objective-c",		/* Language name */
-  "Objective-C",
   language_objc,
   range_check_off,
   case_sensitive_on,
@@ -353,6 +351,16 @@ class objc_language : public language_defn
     : language_defn (language_objc, objc_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "objective-c"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Objective-C"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 37ac1386b2d..08fc05b2310 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1007,8 +1007,6 @@ const struct exp_descriptor exp_descriptor_opencl =
 /* Constant data representing the OpenCL language.  */
 extern const struct language_data opencl_language_data =
 {
-  "opencl",			/* Language name */
-  "OpenCL C",
   language_opencl,
   range_check_off,
   case_sensitive_on,
@@ -1032,6 +1030,16 @@ class opencl_language : public language_defn
     : language_defn (language_opencl, opencl_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "opencl"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "OpenCL C"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index ab24d48bf8f..9fa6cf7e15c 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -257,8 +257,6 @@ static const char *p_extensions[] =
 
 extern const struct language_data pascal_language_data =
 {
-  "pascal",			/* Language name */
-  "Pascal",
   language_pascal,
   range_check_on,
   case_sensitive_on,
@@ -282,6 +280,17 @@ class pascal_language : public language_defn
     : language_defn (language_pascal, pascal_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "pascal"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Pascal"; }
+
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 94515ed17e2..dd330a74eb4 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1911,8 +1911,6 @@ static const char *rust_extensions[] =
 
 extern const struct language_data rust_language_data =
 {
-  "rust",
-  "Rust",
   language_rust,
   range_check_on,
   case_sensitive_on,
@@ -1936,6 +1934,16 @@ class rust_language : public language_defn
     : language_defn (language_rust, rust_language_data)
   { /* Nothing.  */ }
 
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "rust"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Rust"; }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/symtab.c b/gdb/symtab.c
index ff88adfe020..61f96b2ab8c 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1921,7 +1921,7 @@ lookup_language_this (const struct language_defn *lang,
 
       fprintf_unfiltered (gdb_stdlog,
 			  "lookup_language_this (%s, %s (objfile %s))",
-			  lang->la_name, host_address_to_string (block),
+			  lang->name (), host_address_to_string (block),
 			  objfile_debug_name (objfile));
     }
 
-- 
2.25.4


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

* [PATCHv2 04/18] gdb: Convert la_filename_extensions to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (2 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 03/18] gdb: Convert la_name and la_natural_name to methods Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 05/18] gdb: Move la_language into the language_defn class Andrew Burgess
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_filename_extensions member variable to a
virtual method language_defn::filename_extensions.

The new method returns a vector of filename extensions, which means
that where previously we needed a NULL marker on the end of the list,
we can now discard this.

All of the old arrays that contained the extensions now become static
data within each languages filename_extensions method.

I've updated the single use of the filename_extensions method to make
use of this method returning a vector.  And, just in case anyone
accidentally adds a NULL marked into a languages extensions list, I've
added a new assert in add_filename_language (symtab.c) to catch this.

gdb/ChangeLog:

	* ada-lang.c (ada_extensions): Delete, moved into
	ada_language::filename_extensions.
	(ada_language_data): Remove la_filename_extensions initializer.
	(ada_language::filename_extensions): New member function.
	* c-lang.c (c_extensions): Delete, moved into
	c_language::filename_extensions.
	(c_language_data): Remove la_filename_extensions initializer.
	(c_language::filename_extensions): New member function.
	(cplus_extensions): Delete, moved into
	cplus_language::filename_extensions.
	(cplus_language_data): Remove la_filename_extensions initializer.
	(cplus_language::filename_extensions): New member function.
	(asm_extensions): Delete, moved into
	asm_language::filename_extensions.
	(asm_language_data): Remove la_filename_extensions initializer.
	(asm_language::filename_extensions): New member function.
	(minimal_language_data): Remove la_filename_extensions
	initializer.
	* d-lang.c (d_extensions): Delete, moved into
	d_language::filename_extensions.
	(d_language_data): Remove la_filename_extensions initializer.
	(d_language::filename_extensions): New member function.
	* f-lang.c (f_extensions): Delete, moved into
	f_language::filename_extensions.
	(f_language_data): Remove la_filename_extensions initializer.
	(f_language::filename_extensions): New member function.
	* go-lang.c (go_language_data): Remove la_filename_extensions
	initializer.
	* language.c (add_set_language_command): Update now that
	filename_extensions returns a vector.
	(unknown_language_data): Remove la_filename_extensions
	initializer.
	(auto_language_data): Likewise.
	* language.h (language_data): Remove la_filename_extensions field.
	(language_defn::filename_extensions): New member function.
	* m2-lang.c (m2_language_data): Remove la_filename_extensions
	initializer.
	* objc-lang.c (objc_extensions): Delete, moved into
	objc_language::filename_extensions.
	(objc_language_data): Remove la_filename_extensions initializer.
	(objc_language::filename_extensions): New member function.
	* opencl-lang.c (opencl_language_data): Remove
	la_filename_extensions initializer.
	* p-lang.c (pascal_extensions): Delete, moved into
	pascal_language::filename_extensions.
	(pascal_language_data): Remove la_filename_extensions initializer.
	(pascal_language::filename_extensions): New member function.
	* rust-lang.c (rust_extensions): Delete, moved into
	rust_language::filename_extensions.
	(rust_language_data): Remove la_filename_extensions initializer.
	(rust_language::filename_extensions): New member function.
	* symfile.c (add_filename_language): Add new assert.
---
 gdb/ChangeLog     | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 15 +++++++------
 gdb/c-lang.c      | 45 ++++++++++++++++++++++----------------
 gdb/d-lang.c      | 14 ++++++------
 gdb/f-lang.c      | 19 +++++++++-------
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 10 ++-------
 gdb/language.h    | 18 ++++++++++------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   | 14 ++++++------
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      | 14 ++++++------
 gdb/rust-lang.c   | 14 ++++++------
 gdb/symfile.c     |  1 +
 14 files changed, 147 insertions(+), 75 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 019abceb0c5..00bf6f4f7a2 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13704,11 +13704,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
     }
 }
 
-static const char *ada_extensions[] =
-{
-  ".adb", ".ads", ".a", ".ada", ".dg", NULL
-};
-
 /* Constant data that describes the Ada language.  */
 
 extern const struct language_data ada_language_data =
@@ -13719,7 +13714,6 @@ extern const struct language_data ada_language_data =
                                    that's not quite what this means.  */
   array_row_major,
   macro_expansion_no,
-  ada_extensions,
   &ada_exp_descriptor,
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_op_print_tab,             /* expression operators for printing */
@@ -13747,6 +13741,15 @@ class ada_language : public language_defn
   const char *natural_name () const override
   { return "Ada"; }
 
+  /* See language.h.  */
+
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions
+      = { ".adb", ".ads", ".a", ".ada", ".dg" };
+    return extensions;
+  }
+
   /* Print an array element index using the Ada syntax.  */
 
   void print_array_index (struct type *index_type,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 04e9eae8912..ce4620a136c 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -871,11 +871,6 @@ const struct exp_descriptor exp_descriptor_c =
   evaluate_subexp_c
 };
 
-static const char *c_extensions[] =
-{
-  ".c", NULL
-};
-
 /* Constant data that describes the C language.  */
 
 extern const struct language_data c_language_data =
@@ -885,7 +880,6 @@ extern const struct language_data c_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
-  c_extensions,
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
@@ -913,6 +907,14 @@ class c_language : public language_defn
   const char *natural_name () const override
   { return "C"; }
 
+  /* See language.h.  */
+
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions = { ".c" };
+    return extensions;
+  }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
@@ -978,11 +980,6 @@ enum cplus_primitive_types {
   nr_cplus_primitive_types
 };
 
-static const char *cplus_extensions[] =
-{
-  ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", NULL
-};
-
 /* Constant data that describes the C++ language.  */
 
 extern const struct language_data cplus_language_data =
@@ -992,7 +989,6 @@ extern const struct language_data cplus_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
-  cplus_extensions,
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
@@ -1022,6 +1018,15 @@ class cplus_language : public language_defn
 
   /* See language.h.  */
 
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions
+      = { ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++" };
+    return extensions;
+  }
+
+  /* See language.h.  */
+
   struct language_pass_by_ref_info pass_by_reference_info
 	(struct type *type) const override
   {
@@ -1187,11 +1192,6 @@ class cplus_language : public language_defn
 
 static cplus_language cplus_language_defn;
 
-static const char *asm_extensions[] =
-{
-  ".s", ".sx", ".S", NULL
-};
-
 /* Constant data that describes the ASM language.  */
 
 extern const struct language_data asm_language_data =
@@ -1201,7 +1201,6 @@ extern const struct language_data asm_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
-  asm_extensions,
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
@@ -1229,6 +1228,15 @@ class asm_language : public language_defn
   const char *natural_name () const override
   { return "Assembly"; }
 
+  /* See language.h.  */
+
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions
+      = { ".s", ".sx", ".S" };
+    return extensions;
+  }
+
   /* See language.h.
 
      FIXME: Should this have its own arch info method?  */
@@ -1263,7 +1271,6 @@ extern const struct language_data minimal_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
-  NULL,
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 0985f535743..fcb7caa7207 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -124,11 +124,6 @@ enum d_primitive_types {
   nr_d_primitive_types
 };
 
-static const char *d_extensions[] =
-{
-  ".d", NULL
-};
-
 /* Constant data that describes the D language.  */
 
 extern const struct language_data d_language_data =
@@ -138,7 +133,6 @@ extern const struct language_data d_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
-  d_extensions,
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_op_print_tab,		/* Expression operators for printing.  */
@@ -166,6 +160,14 @@ class d_language : public language_defn
   const char *natural_name () const override
   { return "D"; }
 
+  /* See language.h.  */
+
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions = { ".d" };
+    return extensions;
+  }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index a31f863cc09..010ff51ef46 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -471,13 +471,6 @@ operator_check_f (struct expression *exp, int pos,
   return 0;
 }
 
-static const char *f_extensions[] =
-{
-  ".f", ".F", ".for", ".FOR", ".ftn", ".FTN", ".fpp", ".FPP",
-  ".f90", ".F90", ".f95", ".F95", ".f03", ".F03", ".f08", ".F08",
-  NULL
-};
-
 /* Expression processing for Fortran.  */
 static const struct exp_descriptor exp_descriptor_f =
 {
@@ -498,7 +491,6 @@ extern const struct language_data f_language_data =
   case_sensitive_off,
   array_column_major,
   macro_expansion_no,
-  f_extensions,
   &exp_descriptor_f,
   false,			/* la_store_sym_names_in_linkage_form_p */
   f_op_print_tab,		/* expression operators for printing */
@@ -526,6 +518,17 @@ class f_language : public language_defn
   const char *natural_name () const override
   { return "Fortran"; }
 
+  /* See language.h.  */
+
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions = {
+      ".f", ".F", ".for", ".FOR", ".ftn", ".FTN", ".fpp", ".FPP",
+      ".f90", ".F90", ".f95", ".F95", ".f03", ".F03", ".f08", ".F08"
+    };
+    return extensions;
+  }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 6e9b4875696..13fa0edb9a1 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -513,7 +513,6 @@ extern const struct language_data go_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
-  NULL,
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   go_op_print_tab,		/* Expression operators for printing.  */
diff --git a/gdb/language.c b/gdb/language.c
index 0b1b4882038..cc4076253a5 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -503,12 +503,8 @@ add_set_language_command ()
 
   /* Add the filename extensions.  */
   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)
-	  add_filename_language (lang->la_filename_extensions[i],
-				 lang->la_language);
-      }
+    for (const char * const &ext : lang->filename_extensions ())
+      add_filename_language (ext, lang->la_language);
 
   /* Build the "help set language" docs.  */
   string_file doc;
@@ -784,7 +780,6 @@ extern const struct language_data unknown_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
-  NULL,
   &exp_descriptor_standard,
   true,				/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
@@ -921,7 +916,6 @@ extern const struct language_data auto_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
-  NULL,
   &exp_descriptor_standard,
   false,			/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/language.h b/gdb/language.h
index 980e3647af9..9a7ad214d88 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -205,13 +205,6 @@ struct language_data
     /* Style of macro expansion, if any, supported by this language.  */
     enum macro_expansion la_macro_expansion;
 
-    /* A NULL-terminated array of file extensions for this language.
-       The extension must include the ".", like ".c".  If this
-       language doesn't need to provide any filename extensions, this
-       may be NULL.  */
-
-    const char *const *la_filename_extensions;
-
     /* Definitions related to expression printing, prefixifying, and
        dumping.  */
 
@@ -275,6 +268,17 @@ struct language_defn : language_data
 
   virtual const char *natural_name () const = 0;
 
+  /* Return a vector of file extensions for this language.  The extension
+     must include the ".", like ".c".  If this language doesn't need to
+     provide any filename extensions, this may be an empty vector (which is
+     the default).  */
+
+  virtual const std::vector<const char *> &filename_extensions () const
+  {
+    static const std::vector<const char *> no_extensions;
+    return no_extensions;
+  }
+
   /* Print the index of an element of an array.  This default
      implementation prints using C99 syntax.  */
 
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 9806caf6103..ef415381169 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -204,7 +204,6 @@ extern const struct language_data m2_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
-  NULL,
   &exp_descriptor_modula2,
   false,			/* la_store_sym_names_in_linkage_form_p */
   m2_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 99306a6c9c3..ff9735e59d9 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -319,11 +319,6 @@ static const struct op_print objc_op_print_tab[] =
     {NULL, OP_NULL, PREC_NULL, 0}
 };
 
-static const char *objc_extensions[] =
-{
-  ".m", NULL
-};
-
 /* Constant data representing the Objective-C language.  */
 
 extern const struct language_data objc_language_data =
@@ -333,7 +328,6 @@ extern const struct language_data objc_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
-  objc_extensions,
   &exp_descriptor_standard,
   false,			/* la_store_sym_names_in_linkage_form_p */
   objc_op_print_tab,		/* Expression operators for printing */
@@ -361,6 +355,14 @@ class objc_language : public language_defn
   const char *natural_name () const override
   { return "Objective-C"; }
 
+  /* See language.h.  */
+
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions = { ".m" };
+    return extensions;
+  }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 08fc05b2310..ee4133f6f11 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1012,7 +1012,6 @@ extern const struct language_data opencl_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
-  NULL,
   &exp_descriptor_opencl,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 9fa6cf7e15c..da48a52a9ab 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -248,11 +248,6 @@ enum pascal_primitive_types {
   nr_pascal_primitive_types
 };
 
-static const char *p_extensions[] =
-{
-  ".pas", ".p", ".pp", NULL
-};
-
 /* Constant data representing the Pascal language.  */
 
 extern const struct language_data pascal_language_data =
@@ -262,7 +257,6 @@ extern const struct language_data pascal_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
-  p_extensions,
   &exp_descriptor_standard,
   false,			/* la_store_sym_names_in_linkage_form_p */
   pascal_op_print_tab,		/* expression operators for printing */
@@ -290,6 +284,14 @@ class pascal_language : public language_defn
   const char *natural_name () const override
   { return "Pascal"; }
 
+  /* See language.h.  */
+
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions
+      = { ".pas", ".p", ".pp" };
+    return extensions;
+  }
 
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index dd330a74eb4..d1c63ca13ea 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1902,11 +1902,6 @@ static const struct exp_descriptor exp_descriptor_rust =
   rust_evaluate_subexp
 };
 
-static const char *rust_extensions[] =
-{
-  ".rs", NULL
-};
-
 /* Constant data representing the Rust language.  */
 
 extern const struct language_data rust_language_data =
@@ -1916,7 +1911,6 @@ extern const struct language_data rust_language_data =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
-  rust_extensions,
   &exp_descriptor_rust,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
@@ -1944,6 +1938,14 @@ class rust_language : public language_defn
   const char *natural_name () const override
   { return "Rust"; }
 
+  /* See language.h.  */
+
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions = { ".rs" };
+    return extensions;
+  }
+
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 2c38ce4431a..d5aa11fef9e 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2672,6 +2672,7 @@ static std::vector<filename_language> filename_language_table;
 void
 add_filename_language (const char *ext, enum language lang)
 {
+  gdb_assert (ext != nullptr);
   filename_language_table.emplace_back (ext, lang);
 }
 
-- 
2.25.4


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

* [PATCHv2 05/18] gdb: Move la_language into the language_defn class
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (3 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 04/18] gdb: Convert la_filename_extensions to a method Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 06/18] gdb: Convert language_data::c_style_arrays to a method Andrew Burgess
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Move the language_data::la_language member variable into the
langage_defn class.

I have not made the la_language member variable a method of
langage_defn simply because of the large number of places that
la_language is referenced throughout GDB.  I have made the new member
variable constant though, so this should prevent accidental
assignment.

In the future we might consider converting la_language to a method,
but right now my goal is to remove the langage_data class, so I'm
happy to leave la_language as a constant member variable.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_language 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): Remove la_language field.
	(language_defn::language_defn): Initialise la_language field.
	(language_defn::la_language): New member variable.
	* m2-lang.c (m2_language_data): Remove la_language field.
	* 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     | 21 +++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 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    | 11 ++++++-----
 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, 27 insertions(+), 20 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 00bf6f4f7a2..9e2681b02ab 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13708,7 +13708,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 
 extern const struct language_data ada_language_data =
 {
-  language_ada,
   range_check_off,
   case_sensitive_on,            /* Yes, Ada is case-insensitive, but
                                    that's not quite what this means.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index ce4620a136c..d8d66c24103 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -875,7 +875,6 @@ const struct exp_descriptor exp_descriptor_c =
 
 extern const struct language_data c_language_data =
 {
-  language_c,
   range_check_off,
   case_sensitive_on,
   array_row_major,
@@ -984,7 +983,6 @@ enum cplus_primitive_types {
 
 extern const struct language_data cplus_language_data =
 {
-  language_cplus,
   range_check_off,
   case_sensitive_on,
   array_row_major,
@@ -1196,7 +1194,6 @@ static cplus_language cplus_language_defn;
 
 extern const struct language_data asm_language_data =
 {
-  language_asm,
   range_check_off,
   case_sensitive_on,
   array_row_major,
@@ -1266,7 +1263,6 @@ static asm_language asm_language_defn;
 
 extern const struct language_data minimal_language_data =
 {
-  language_minimal,
   range_check_off,
   case_sensitive_on,
   array_row_major,
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index fcb7caa7207..34af2588269 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -128,7 +128,6 @@ enum d_primitive_types {
 
 extern const struct language_data d_language_data =
 {
-  language_d,
   range_check_off,
   case_sensitive_on,
   array_row_major,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 010ff51ef46..0e8b7a7e526 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -486,7 +486,6 @@ static const struct exp_descriptor exp_descriptor_f =
 
 extern const struct language_data f_language_data =
 {
-  language_fortran,
   range_check_on,
   case_sensitive_off,
   array_column_major,
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 13fa0edb9a1..ed7fcd1f425 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -508,7 +508,6 @@ enum go_primitive_types {
 
 extern const struct language_data go_language_data =
 {
-  language_go,
   range_check_off,
   case_sensitive_on,
   array_row_major,
diff --git a/gdb/language.c b/gdb/language.c
index cc4076253a5..55e8104132b 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -775,7 +775,6 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 
 extern const struct language_data unknown_language_data =
 {
-  language_unknown,
   range_check_off,
   case_sensitive_on,
   array_row_major,
@@ -911,7 +910,6 @@ static unknown_language unknown_language_defn;
 
 extern const struct language_data auto_language_data =
 {
-  language_auto,
   range_check_off,
   case_sensitive_on,
   array_row_major,
diff --git a/gdb/language.h b/gdb/language.h
index 9a7ad214d88..731b641d261 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -188,10 +188,6 @@ extern const char *default_word_break_characters (void);
 
 struct language_data
   {
-    /* its symtab language-enum (defs.h).  */
-
-    enum language la_language;
-
     /* Default range checking.  */
 
     enum range_check la_range_check;
@@ -253,13 +249,18 @@ struct language_data
 struct language_defn : language_data
 {
   language_defn (enum language lang, const language_data &init_data)
-    : language_data (init_data)
+    : language_data (init_data),
+      la_language (lang)
   {
     /* We should only ever create one instance of each language.  */
     gdb_assert (languages[lang] == nullptr);
     languages[lang] = this;
   }
 
+  /* Which language this is.  */
+
+  const enum language la_language;
+
   /* Name of the language.  */
 
   virtual const char *name () const = 0;
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index ef415381169..94340b0d9b2 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -199,7 +199,6 @@ const struct exp_descriptor exp_descriptor_modula2 =
 
 extern const struct language_data m2_language_data =
 {
-  language_m2,
   range_check_on,
   case_sensitive_on,
   array_row_major,
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index ff9735e59d9..f605c2194b0 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -323,7 +323,6 @@ static const struct op_print objc_op_print_tab[] =
 
 extern const struct language_data objc_language_data =
 {
-  language_objc,
   range_check_off,
   case_sensitive_on,
   array_row_major,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index ee4133f6f11..6a2df1a2e18 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1007,7 +1007,6 @@ const struct exp_descriptor exp_descriptor_opencl =
 /* Constant data representing the OpenCL language.  */
 extern const struct language_data opencl_language_data =
 {
-  language_opencl,
   range_check_off,
   case_sensitive_on,
   array_row_major,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index da48a52a9ab..aef908c7dc6 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -252,7 +252,6 @@ enum pascal_primitive_types {
 
 extern const struct language_data pascal_language_data =
 {
-  language_pascal,
   range_check_on,
   case_sensitive_on,
   array_row_major,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index d1c63ca13ea..0b4132dc745 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1906,7 +1906,6 @@ static const struct exp_descriptor exp_descriptor_rust =
 
 extern const struct language_data rust_language_data =
 {
-  language_rust,
   range_check_on,
   case_sensitive_on,
   array_row_major,
-- 
2.25.4


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

* [PATCHv2 06/18] gdb: Convert language_data::c_style_arrays to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (4 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 05/18] gdb: Move la_language into the language_defn class Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 07/18] gdb: Fix an incorrect comment Andrew Burgess
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::c_style_arrays member variable to a virtual
method language_defn::c_style_arrays_p.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove c_style_arrays
	initializer.
	(ada_language::c_style_arrays_p): New member fuction.
	* c-lang.c (c_language_data): Remove c_style_arrays
	initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* eval.c (ptrmath_type_p): Update call to c_style_arrays_p.
	* f-lang.c (f_language_data): Remove c_style_arrays initializer.
	(f_language::c_style_arrays_p): New member function.
	* go-lang.c (go_language_data): Remove c_style_arrays initializer.
	* infcall.c (value_arg_coerce): Update call to c_style_arrays_p.
	* language.c (unknown_language_data): Remove c_style_arrays
	initializer.
	(auto_language_data): Likewise.
	* language.h (language_data): Remove c_style_arrays field.
	(language_defn::c_style_arrays_p): New member function.
	* m2-lang.c (m2_language_data): Remove c_style_arrays initializer.
	(m2_language::c_style_arrays_p): New member function.
	* objc-lang.c (objc_language_data): Remove c_style_arrays
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	* valarith.c (value_subscript): Update call to c_style_arrays_p,
	and update local variable to a bool.
	* valops.c (value_cast): Update call to c_style_arrays_p.
	(value_array): Likewise.
	* value.c (coerce_array): Likewise.
---
 gdb/ChangeLog     | 34 ++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  6 +++++-
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/eval.c        |  2 +-
 gdb/f-lang.c      |  6 +++++-
 gdb/go-lang.c     |  1 -
 gdb/infcall.c     |  2 +-
 gdb/language.c    |  2 --
 gdb/language.h    | 13 ++++++++-----
 gdb/m2-lang.c     |  6 +++++-
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 gdb/valarith.c    |  6 +++---
 gdb/valops.c      |  4 ++--
 gdb/value.c       |  2 +-
 18 files changed, 65 insertions(+), 28 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 9e2681b02ab..25da1154395 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13716,7 +13716,6 @@ extern const struct language_data ada_language_data =
   &ada_exp_descriptor,
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_op_print_tab,             /* expression operators for printing */
-  0,                            /* c-style arrays */
   1,                            /* String lower bound */
   &ada_varobj_ops,
 };
@@ -14200,6 +14199,11 @@ class ada_language : public language_defn
   const char *struct_too_deep_ellipsis () const override
   { return "(...)"; }
 
+  /* See language.h.  */
+
+  bool c_style_arrays_p () const override
+  { return false; }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index d8d66c24103..41eac2d43a3 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -882,7 +882,6 @@ extern const struct language_data c_language_data =
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &c_varobj_ops,
 };
@@ -990,7 +989,6 @@ extern const struct language_data cplus_language_data =
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &cplus_varobj_ops,
 };
@@ -1201,7 +1199,6 @@ extern const struct language_data asm_language_data =
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
@@ -1270,7 +1267,6 @@ extern const struct language_data minimal_language_data =
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 34af2588269..8cf61722fdc 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -135,7 +135,6 @@ extern const struct language_data d_language_data =
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_op_print_tab,		/* Expression operators for printing.  */
-  1,				/* C-style arrays.  */
   0,				/* String lower bound.  */
   &default_varobj_ops,
 };
diff --git a/gdb/eval.c b/gdb/eval.c
index c62c35f3183..65c44ad4949 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -622,7 +622,7 @@ ptrmath_type_p (const struct language_defn *lang, struct type *type)
       return 1;
 
     case TYPE_CODE_ARRAY:
-      return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays;
+      return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays_p ();
 
     default:
       return 0;
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 0e8b7a7e526..7c2d43d854b 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -493,7 +493,6 @@ extern const struct language_data f_language_data =
   &exp_descriptor_f,
   false,			/* la_store_sym_names_in_linkage_form_p */
   f_op_print_tab,		/* expression operators for printing */
-  0,				/* arrays are first-class (not c-style) */
   1,				/* String lower bound */
   &default_varobj_ops,
 };
@@ -720,6 +719,11 @@ class f_language : public language_defn
   const char *struct_too_deep_ellipsis () const override
   { return "(...)"; }
 
+  /* See language.h.  */
+
+  bool c_style_arrays_p () const override
+  { return false; }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index ed7fcd1f425..c2724e3d7cc 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -515,7 +515,6 @@ extern const struct language_data go_language_data =
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   go_op_print_tab,		/* Expression operators for printing.  */
-  1,				/* C-style arrays.  */
   0,				/* String lower bound.  */
   &default_varobj_ops,
 };
diff --git a/gdb/infcall.c b/gdb/infcall.c
index cdb30137c35..f27f713b3e7 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -219,7 +219,7 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
       /* Arrays are coerced to pointers to their first element, unless
          they are vectors, in which case we want to leave them alone,
          because they are passed by value.  */
-      if (current_language->c_style_arrays)
+      if (current_language->c_style_arrays_p ())
 	if (!TYPE_VECTOR (type))
 	  type = lookup_pointer_type (TYPE_TARGET_TYPE (type));
       break;
diff --git a/gdb/language.c b/gdb/language.c
index 55e8104132b..9a496ae8548 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -782,7 +782,6 @@ extern const struct language_data unknown_language_data =
   &exp_descriptor_standard,
   true,				/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
@@ -917,7 +916,6 @@ extern const struct language_data auto_language_data =
   &exp_descriptor_standard,
   false,			/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/language.h b/gdb/language.h
index 731b641d261..83014e47789 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -232,11 +232,6 @@ struct language_data
 
     const struct op_print *la_op_print_tab;
 
-    /* Zero if the language has first-class arrays.  True if there are no
-       array values, and array objects decay to pointers, as in C.  */
-
-    char c_style_arrays;
-
     /* Index to use for extracting the first element of a string.  */
     char string_lower_bound;
 
@@ -565,6 +560,14 @@ struct language_defn : language_data
   virtual const char *name_of_this () const
   { return nullptr; }
 
+  /* Return false if the language has first-class arrays.  Return true if
+     there are no array values, and array objects decay to pointers, as in
+     C.  The default is true as currently most supported languages behave
+     in this manor.  */
+
+  virtual bool c_style_arrays_p () const
+  { return true; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 94340b0d9b2..9dd557777c0 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -206,7 +206,6 @@ extern const struct language_data m2_language_data =
   &exp_descriptor_modula2,
   false,			/* la_store_sym_names_in_linkage_form_p */
   m2_op_print_tab,		/* expression operators for printing */
-  0,				/* arrays are first-class (not c-style) */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
@@ -436,6 +435,11 @@ class m2_language : public language_defn
 
     return false;
   }
+
+  /* See language.h.  */
+
+  bool c_style_arrays_p () const override
+  { return false; }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index f605c2194b0..66b7b50144b 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -330,7 +330,6 @@ extern const struct language_data objc_language_data =
   &exp_descriptor_standard,
   false,			/* la_store_sym_names_in_linkage_form_p */
   objc_op_print_tab,		/* Expression operators for printing */
-  1,				/* C-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 6a2df1a2e18..8f930294937 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1014,7 +1014,6 @@ extern const struct language_data opencl_language_data =
   &exp_descriptor_opencl,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index aef908c7dc6..66ba51ac8eb 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -259,7 +259,6 @@ extern const struct language_data pascal_language_data =
   &exp_descriptor_standard,
   false,			/* la_store_sym_names_in_linkage_form_p */
   pascal_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 0b4132dc745..0a0486804e7 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1913,7 +1913,6 @@ extern const struct language_data rust_language_data =
   &exp_descriptor_rust,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
 };
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 0221bc6e939..cc37acb6e58 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -140,7 +140,7 @@ value_ptrdiff (struct value *arg1, struct value *arg2)
 struct value *
 value_subscript (struct value *array, LONGEST index)
 {
-  int c_style = current_language->c_style_arrays;
+  bool c_style = current_language->c_style_arrays_p ();
   struct type *tarray;
 
   array = coerce_ref (array);
@@ -156,7 +156,7 @@ value_subscript (struct value *array, LONGEST index)
       if (VALUE_LVAL (array) != lval_memory)
 	return value_subscripted_rvalue (array, index, lowerbound);
 
-      if (c_style == 0)
+      if (!c_style)
 	{
 	  if (index >= lowerbound && index <= upperbound)
 	    return value_subscripted_rvalue (array, index, lowerbound);
@@ -165,7 +165,7 @@ value_subscript (struct value *array, LONGEST index)
 	  if (upperbound > -1)
 	    warning (_("array or string index out of range"));
 	  /* fall doing C stuff */
-	  c_style = 1;
+	  c_style = true;
 	}
 
       index -= lowerbound;
diff --git a/gdb/valops.c b/gdb/valops.c
index d05cad77b3c..0c818736b76 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -414,7 +414,7 @@ value_cast (struct type *type, struct value *arg2)
 	}
     }
 
-  if (current_language->c_style_arrays
+  if (current_language->c_style_arrays_p ()
       && type2->code () == TYPE_CODE_ARRAY
       && !TYPE_VECTOR (type2))
     arg2 = value_coerce_array (arg2);
@@ -1622,7 +1622,7 @@ value_array (int lowbound, int highbound, struct value **elemvec)
   arraytype = lookup_array_range_type (value_enclosing_type (elemvec[0]),
 				       lowbound, highbound);
 
-  if (!current_language->c_style_arrays)
+  if (!current_language->c_style_arrays_p ())
     {
       val = allocate_value (arraytype);
       for (idx = 0; idx < nelem; idx++)
diff --git a/gdb/value.c b/gdb/value.c
index aac9baaaf56..6e18427d5fa 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3687,7 +3687,7 @@ coerce_array (struct value *arg)
   switch (type->code ())
     {
     case TYPE_CODE_ARRAY:
-      if (!TYPE_VECTOR (type) && current_language->c_style_arrays)
+      if (!TYPE_VECTOR (type) && current_language->c_style_arrays_p ())
 	arg = value_coerce_array (arg);
       break;
     case TYPE_CODE_FUNC:
-- 
2.25.4


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

* [PATCHv2 07/18] gdb: Fix an incorrect comment
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (5 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 06/18] gdb: Convert language_data::c_style_arrays to a method Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 08/18] gdb: Convert language_data::string_lower_bound to a method Andrew Burgess
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

A comment uses the wrong parameter name.  Fixed in this commit.

gdb/ChangeLog:

	* valops.c (value_repeat): Fix incorrect argument name in comment.
---
 gdb/ChangeLog | 4 ++++
 gdb/valops.c  | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/valops.c b/gdb/valops.c
index 0c818736b76..b7dd1f2ea97 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1258,7 +1258,7 @@ value_assign (struct value *toval, struct value *fromval)
   return val;
 }
 
-/* Extend a value VAL to COUNT repetitions of its type.  */
+/* Extend a value ARG1 to COUNT repetitions of its type.  */
 
 struct value *
 value_repeat (struct value *arg1, int count)
-- 
2.25.4


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

* [PATCHv2 08/18] gdb: Convert language_data::string_lower_bound to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (6 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 07/18] gdb: Fix an incorrect comment Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 09/18] gdb: Convert la_store_sym_names_in_linkage_form_p " Andrew Burgess
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::string_lower_bound member variable to a virtual
method language_defn::string_lower_bound.

Over all of the languages we currently support there are currently
only two values for the lower bound, 0 or 1.  I noticed that in all
cases, if a language has C style arrays then the lower bound is 0,
otherwise the lower bound is 1.  So the default for the virtual method
in language.h makes use of this, which means languages don't have to
worry about providing a string_lower_bound method at all.

Except for Modula2.  This language is defined to not have C style
arrays, but has a string_lower_bound index of 0, this behaviour is
maintained after this commit by having Modula2 be the only language
that overrides the string_lower_bound method.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove string_lower_bound
	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): Remove string_lower_bound field.
	(language_defn::string_lower_bound): New member function.
	* m2-lang.c (m2_language_data): Remove string_lower_bound
	initializer.
	(m2_language::string_lower_bound): New member function.
	* objc-lang.c (objc_language_data): Remove string_lower_bound
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_language_data): Likewise.
	* valops.c (value_cstring): Update call to string_lower_bound.
	(value_string): Likewise.
	* value.c (allocate_repeated_value): Likewise.
---
 gdb/ChangeLog     | 27 +++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 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    | 11 ++++++++---
 gdb/m2-lang.c     |  7 ++++++-
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 gdb/valops.c      |  4 ++--
 gdb/value.c       |  5 ++++-
 15 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 25da1154395..2be5a2b8bd9 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13716,7 +13716,6 @@ extern const struct language_data ada_language_data =
   &ada_exp_descriptor,
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_op_print_tab,             /* expression operators for printing */
-  1,                            /* String lower bound */
   &ada_varobj_ops,
 };
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 41eac2d43a3..ecb339c3f87 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -882,7 +882,6 @@ extern const struct language_data c_language_data =
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &c_varobj_ops,
 };
 
@@ -989,7 +988,6 @@ extern const struct language_data cplus_language_data =
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &cplus_varobj_ops,
 };
 
@@ -1199,7 +1197,6 @@ extern const struct language_data asm_language_data =
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &default_varobj_ops,
 };
 
@@ -1267,7 +1264,6 @@ extern const struct language_data minimal_language_data =
   &exp_descriptor_c,
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &default_varobj_ops,
 };
 
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 8cf61722fdc..eb05818c496 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -135,7 +135,6 @@ extern const struct language_data d_language_data =
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_op_print_tab,		/* Expression operators for printing.  */
-  0,				/* String lower bound.  */
   &default_varobj_ops,
 };
 
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 7c2d43d854b..22575b44a4f 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -493,7 +493,6 @@ extern const struct language_data f_language_data =
   &exp_descriptor_f,
   false,			/* la_store_sym_names_in_linkage_form_p */
   f_op_print_tab,		/* expression operators for printing */
-  1,				/* String lower bound */
   &default_varobj_ops,
 };
 
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index c2724e3d7cc..c0ad0be1362 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -515,7 +515,6 @@ extern const struct language_data go_language_data =
   &exp_descriptor_c,
   false,			/* la_store_sym_names_in_linkage_form_p */
   go_op_print_tab,		/* Expression operators for printing.  */
-  0,				/* String lower bound.  */
   &default_varobj_ops,
 };
 
diff --git a/gdb/language.c b/gdb/language.c
index 9a496ae8548..1866a964599 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -782,7 +782,6 @@ extern const struct language_data unknown_language_data =
   &exp_descriptor_standard,
   true,				/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &default_varobj_ops,
 };
 
@@ -916,7 +915,6 @@ extern const struct language_data auto_language_data =
   &exp_descriptor_standard,
   false,			/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &default_varobj_ops,
 };
 
diff --git a/gdb/language.h b/gdb/language.h
index 83014e47789..d83ea132a91 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -232,9 +232,6 @@ struct language_data
 
     const struct op_print *la_op_print_tab;
 
-    /* Index to use for extracting the first element of a string.  */
-    char string_lower_bound;
-
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
   };
@@ -568,6 +565,14 @@ struct language_defn : language_data
   virtual bool c_style_arrays_p () const
   { return true; }
 
+  /* Return the index to use for extracting the first element of a string,
+     or as the lower bound when creating a new string.  The default of
+     choosing 0 or 1 based on C_STYLE_ARRAYS_P works for all currently
+     supported languages except Modula-2.  */
+
+  virtual char string_lower_bound () const
+  { return c_style_arrays_p () ? 0 : 1; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 9dd557777c0..7bd9e710377 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -206,7 +206,6 @@ extern const struct language_data m2_language_data =
   &exp_descriptor_modula2,
   false,			/* la_store_sym_names_in_linkage_form_p */
   m2_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &default_varobj_ops,
 };
 
@@ -440,6 +439,12 @@ class m2_language : public language_defn
 
   bool c_style_arrays_p () const override
   { return false; }
+
+  /* See language.h.  Despite not having C-style arrays, Modula-2 uses 0
+     for its string lower bounds.  */
+
+  char string_lower_bound () const override
+  { return 0; }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 66b7b50144b..337b7a49f3c 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -330,7 +330,6 @@ extern const struct language_data objc_language_data =
   &exp_descriptor_standard,
   false,			/* la_store_sym_names_in_linkage_form_p */
   objc_op_print_tab,		/* Expression operators for printing */
-  0,				/* String lower bound */
   &default_varobj_ops,
 };
 
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 8f930294937..e11c4a86fdb 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1014,7 +1014,6 @@ extern const struct language_data opencl_language_data =
   &exp_descriptor_opencl,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &default_varobj_ops,
 };
 
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 66ba51ac8eb..b07557151db 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -259,7 +259,6 @@ extern const struct language_data pascal_language_data =
   &exp_descriptor_standard,
   false,			/* la_store_sym_names_in_linkage_form_p */
   pascal_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &default_varobj_ops,
 };
 
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 0a0486804e7..f300eee7829 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1913,7 +1913,6 @@ extern const struct language_data rust_language_data =
   &exp_descriptor_rust,
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
-  0,				/* String lower bound */
   &default_varobj_ops,
 };
 
diff --git a/gdb/valops.c b/gdb/valops.c
index b7dd1f2ea97..41c05bd05b0 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1644,7 +1644,7 @@ struct value *
 value_cstring (const char *ptr, ssize_t len, struct type *char_type)
 {
   struct value *val;
-  int lowbound = current_language->string_lower_bound;
+  int lowbound = current_language->string_lower_bound ();
   ssize_t highbound = len / TYPE_LENGTH (char_type);
   struct type *stringtype
     = lookup_array_range_type (char_type, lowbound, highbound + lowbound - 1);
@@ -1667,7 +1667,7 @@ struct value *
 value_string (const char *ptr, ssize_t len, struct type *char_type)
 {
   struct value *val;
-  int lowbound = current_language->string_lower_bound;
+  int lowbound = current_language->string_lower_bound ();
   ssize_t highbound = len / TYPE_LENGTH (char_type);
   struct type *stringtype
     = lookup_string_range_type (char_type, lowbound, highbound + lowbound - 1);
diff --git a/gdb/value.c b/gdb/value.c
index 6e18427d5fa..ab0d5586bc3 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1041,7 +1041,10 @@ allocate_value (struct type *type)
 struct value *
 allocate_repeat_value (struct type *type, int count)
 {
-  int low_bound = current_language->string_lower_bound;		/* ??? */
+  /* Despite the fact that we are really creating an array of TYPE here, we
+     use the string lower bound as the array lower bound.  This seems to
+     work fine for now.  */
+  int low_bound = current_language->string_lower_bound ();
   /* FIXME-type-allocation: need a way to free this type when we are
      done with it.  */
   struct type *array_type
-- 
2.25.4


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

* [PATCHv2 09/18] gdb: Convert la_store_sym_names_in_linkage_form_p to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (7 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 08/18] gdb: Convert language_data::string_lower_bound to a method Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 10/18] gdb: Override store_sym_names_in_linkage_form_p for Go language Andrew Burgess
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_store_sym_names_in_linkage_form_p member
variable to language_defn::store_sym_names_in_linkage_form_p virtual
function.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove
	la_store_sym_names_in_linkage_form_p initializer.
	(ada_language::store_sym_names_in_linkage_form_p): New member
	function.
	* c-lang.c (c_language_data): Remove
	la_store_sym_names_in_linkage_form_p initializer.
	(c_language::store_sym_names_in_linkage_form_p): New member
	function.
	(cplus_language_data): Remove la_store_sym_names_in_linkage_form_p
	initializer.
	(asm_language_data): Likewise.
	(asm_language::store_sym_names_in_linkage_form_p): New member
	function.
	(minimal_language_data): Remove
	la_store_sym_names_in_linkage_form_p initializer.
	(minimal_language::store_sym_names_in_linkage_form_p): New member
	function.
	* d-lang.c (d_language_data): Remove
	la_store_sym_names_in_linkage_form_p initializer.
	* dwarf2/read.c (dwarf2_physname): Update call to
	store_sym_names_in_linkage_form_p.
	* f-lang.c (f_language_data): Remove
	la_store_sym_names_in_linkage_form_p initializer.
	* go-lang.c (go_language_data): Remove
	la_store_sym_names_in_linkage_form_p initializer.
	* language.c (unknown_language_data): Remove
	la_store_sym_names_in_linkage_form_p initializer.
	(unknown_language::store_sym_names_in_linkage_form_p): New member
	function.
	(auto_language_data): Remove la_store_sym_names_in_linkage_form_p
	initializer.
	(auto_language::store_sym_names_in_linkage_form_p): New member
	function.
	* language.h (language_data): Remove
	la_store_sym_names_in_linkage_form_p member variable.
	(language_defn::store_sym_names_in_linkage_form_p): New member
	function.
	* m2-lang.c (m2_language_data): Remove
	la_store_sym_names_in_linkage_form_p 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     | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  6 +++++-
 gdb/c-lang.c      | 19 +++++++++++++++----
 gdb/d-lang.c      |  1 -
 gdb/dwarf2/read.c |  2 +-
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  7 +++++--
 gdb/language.h    | 43 +++++++++++++++++++++----------------------
 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, 93 insertions(+), 38 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 2be5a2b8bd9..58b3c7b654f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13714,7 +13714,6 @@ extern const struct language_data ada_language_data =
   array_row_major,
   macro_expansion_no,
   &ada_exp_descriptor,
-  true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_op_print_tab,             /* expression operators for printing */
   &ada_varobj_ops,
 };
@@ -14203,6 +14202,11 @@ class ada_language : public language_defn
   bool c_style_arrays_p () const override
   { return false; }
 
+  /* See language.h.  */
+
+  bool store_sym_names_in_linkage_form_p () const override
+  { return true; }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index ecb339c3f87..c8fe630c247 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -880,7 +880,6 @@ extern const struct language_data c_language_data =
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
-  true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   &c_varobj_ops,
 };
@@ -943,6 +942,11 @@ class c_language : public language_defn
   {
     c_print_type (type, varstring, stream, show, level, flags);
   }
+
+  /* See language.h.  */
+
+  bool store_sym_names_in_linkage_form_p () const override
+  { return true; }
 };
 
 /* Single instance of the C language class.  */
@@ -986,7 +990,6 @@ extern const struct language_data cplus_language_data =
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
-  false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   &cplus_varobj_ops,
 };
@@ -1195,7 +1198,6 @@ extern const struct language_data asm_language_data =
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
-  true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
 };
@@ -1245,6 +1247,11 @@ class asm_language : public language_defn
   {
     c_print_type (type, varstring, stream, show, level, flags);
   }
+
+  /* See language.h.  */
+
+  bool store_sym_names_in_linkage_form_p () const override
+  { return true; }
 };
 
 /* The single instance of the ASM language class.  */
@@ -1262,7 +1269,6 @@ extern const struct language_data minimal_language_data =
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
-  true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
 };
@@ -1301,6 +1307,11 @@ class minimal_language : public language_defn
   {
     c_print_type (type, varstring, stream, show, level, flags);
   }
+
+  /* See language.h.  */
+
+  bool store_sym_names_in_linkage_form_p () const override
+  { return true; }
 };
 
 /* The single instance of the minimal language class.  */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index eb05818c496..9d491c7b854 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -133,7 +133,6 @@ extern const struct language_data d_language_data =
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_c,
-  false,			/* la_store_sym_names_in_linkage_form_p */
   d_op_print_tab,		/* Expression operators for printing.  */
   &default_varobj_ops,
 };
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index f591ef62489..521e0dd5029 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -10596,7 +10596,7 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
   if (mangled != NULL)
     {
 
-      if (language_def (cu->language)->la_store_sym_names_in_linkage_form_p)
+      if (language_def (cu->language)->store_sym_names_in_linkage_form_p ())
 	{
 	  /* Do nothing (do not demangle the symbol name).  */
 	}
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 22575b44a4f..cffdf559cff 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -491,7 +491,6 @@ extern const struct language_data f_language_data =
   array_column_major,
   macro_expansion_no,
   &exp_descriptor_f,
-  false,			/* la_store_sym_names_in_linkage_form_p */
   f_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
 };
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index c0ad0be1362..ed18f01dbdc 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -513,7 +513,6 @@ extern const struct language_data go_language_data =
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_c,
-  false,			/* la_store_sym_names_in_linkage_form_p */
   go_op_print_tab,		/* Expression operators for printing.  */
   &default_varobj_ops,
 };
diff --git a/gdb/language.c b/gdb/language.c
index 1866a964599..3503408ad21 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -780,7 +780,6 @@ extern const struct language_data unknown_language_data =
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_standard,
-  true,				/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
 };
@@ -898,6 +897,11 @@ class unknown_language : public language_defn
 
   const char *name_of_this () const override
   { return "this"; }
+
+  /* See language.h.  */
+
+  bool store_sym_names_in_linkage_form_p () const override
+  { return true; }
 };
 
 /* Single instance of the unknown language class.  */
@@ -913,7 +917,6 @@ extern const struct language_data auto_language_data =
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_standard,
-  false,			/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
 };
diff --git a/gdb/language.h b/gdb/language.h
index d83ea132a91..10a9e707320 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -206,28 +206,6 @@ struct language_data
 
     const struct exp_descriptor *la_exp_desc;
 
-    /* Now come some hooks for lookup_symbol.  */
-
-    /* True if the symbols names should be stored in GDB's data structures
-       for minimal/partial/full symbols using their linkage (aka mangled)
-       form; false if the symbol names should be demangled first.
-
-       Most languages implement symbol lookup by comparing the demangled
-       names, in which case it is advantageous to store that information
-       already demangled, and so would set this field to false.
-
-       On the other hand, some languages have opted for doing symbol
-       lookups by comparing mangled names instead, for reasons usually
-       specific to the language.  Those languages should set this field
-       to true.
-
-       And finally, other languages such as C or Asm do not have
-       the concept of mangled vs demangled name, so those languages
-       should set this field to true as well, to prevent any accidental
-       demangling through an unrelated language's demangler.  */
-
-    const bool la_store_sym_names_in_linkage_form_p;
-
     /* Table for printing expressions.  */
 
     const struct op_print *la_op_print_tab;
@@ -573,6 +551,27 @@ struct language_defn : language_data
   virtual char string_lower_bound () const
   { return c_style_arrays_p () ? 0 : 1; }
 
+  /* Returns true if the symbols names should be stored in GDB's data
+     structures for minimal/partial/full symbols using their linkage (aka
+     mangled) form; false if the symbol names should be demangled first.
+
+     Most languages implement symbol lookup by comparing the demangled
+     names, in which case it is advantageous to store that information
+     already demangled, and so would return false, which is the default.
+
+     On the other hand, some languages have opted for doing symbol lookups
+     by comparing mangled names instead, for reasons usually specific to
+     the language.  Those languages should override this function and
+     return true.
+
+     And finally, other languages such as C or Asm do not have the concept
+     of mangled vs demangled name, so those languages should also override
+     this function and return true, to prevent any accidental demangling
+     through an unrelated language's demangler.  */
+
+  virtual bool store_sym_names_in_linkage_form_p () const
+  { return false; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 7bd9e710377..577d8192114 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -204,7 +204,6 @@ extern const struct language_data m2_language_data =
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_modula2,
-  false,			/* la_store_sym_names_in_linkage_form_p */
   m2_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
 };
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 337b7a49f3c..7b2dbd8bfa2 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -328,7 +328,6 @@ extern const struct language_data objc_language_data =
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_standard,
-  false,			/* la_store_sym_names_in_linkage_form_p */
   objc_op_print_tab,		/* Expression operators for printing */
   &default_varobj_ops,
 };
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index e11c4a86fdb..1e4c28ba230 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1012,7 +1012,6 @@ extern const struct language_data opencl_language_data =
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_opencl,
-  false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
 };
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index b07557151db..9ca1427098e 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -257,7 +257,6 @@ extern const struct language_data pascal_language_data =
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_standard,
-  false,			/* la_store_sym_names_in_linkage_form_p */
   pascal_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
 };
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f300eee7829..e2d011acde1 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1911,7 +1911,6 @@ extern const struct language_data rust_language_data =
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_rust,
-  false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
 };
-- 
2.25.4


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

* [PATCHv2 10/18] gdb: Override store_sym_names_in_linkage_form_p for Go language
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (8 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 09/18] gdb: Convert la_store_sym_names_in_linkage_form_p " Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 11/18] gdb: Convert language_data::la_range_check to a method Andrew Burgess
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

When store_sym_names_in_linkage_form_p was introduced in this commit:

  commit 59cc4834e53565da1de4a7b615ed8890ed55c7da
  Date:   Tue Mar 27 08:57:16 2018 -0500

      problem looking up some symbols when they have a linkage name

A special case was left behind for Go, however, this special case was
not really needed anymore, it could be handled by having
store_sym_names_in_linkage_form_p return the true for go, instead of
false.

This commit overrides store_sym_names_in_linkage_form_p for Go, and
then removes the special case.  As store_sym_names_in_linkage_form_p
is only called once throughout GDB this should be perfectly safe.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* dwarf2/read.c (dwarf2_physname): Remove special case for
	language_go.
	* go-lang.c (go_language::store_sym_names_in_linkage_form_p): New
	member function.
---
 gdb/ChangeLog     | 7 +++++++
 gdb/dwarf2/read.c | 6 ------
 gdb/go-lang.c     | 4 ++++
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 521e0dd5029..20d90d4a45f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -10600,12 +10600,6 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
 	{
 	  /* Do nothing (do not demangle the symbol name).  */
 	}
-      else if (cu->language == language_go)
-	{
-	  /* This is a lie, but we already lie to the caller new_symbol.
-	     new_symbol assumes we return the mangled name.
-	     This just undoes that lie until things are cleaned up.  */
-	}
       else
 	{
 	  /* Use DMGL_RET_DROP for C++ template functions to suppress
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index ed18f01dbdc..dfc0dddc616 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -638,6 +638,10 @@ class go_language : public language_defn
 	    && go_classify_struct_type (type) == GO_TYPE_STRING);
   }
 
+  /* See language.h.  */
+
+  bool store_sym_names_in_linkage_form_p () const override
+  { return true; }
 };
 
 /* Single instance of the Go language class.  */
-- 
2.25.4


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

* [PATCHv2 11/18] gdb: Convert language_data::la_range_check to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (9 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 10/18] gdb: Override store_sym_names_in_linkage_form_p for Go language Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 12/18] gdb: Convert language_data::la_case_sensitivity " Andrew Burgess
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_range_check member variable to a virtual
method language_defn::range_checking_on_by_default.

Where the previous member variable was of type 'enum range_check', the
new member function returns a boolean that selects between range
checking being on or off.  This removes the possibility of a language
having its default be the third enum state, range_check_warn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_range_check
	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.
	(f_language::range_checking_on_by_default): New member function.
	* go-lang.c (go_language_data): Remove la_range_check initializer.
	* language.c (enum range_mode): Moved here from language.h.
	(range_mode): Made static.
	(show_range_command): Update to use
	range_checking_on_by_default.
	(set_range_command): Likewise.
	(set_range_case): Likewise.
	(unknown_language_data): Remove la_range_check initializer.
	(auto_language_data): Likewise.
	* language.h (range_mode): Delete.  Enum definition moved to
	language.c.
	(language_data): Remove la_range_check field.
	(language_defn::range_checking_on_by_default): New member
	function.
	* m2-lang.c (m2_language_data): Remove la_range_check initializer.
	(m2_language::range_checking_on_by_default): New member function.
	* objc-lang.c (objc_language_data): Remove la_range_check
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	(pascal_language::range_checking_on_by_default): New member
	function.
	* rust-lang.c (rust_language_data): Remove la_range_check
	initializer.
	(rust_language::range_checking_on_by_default): New member
	function.
---
 gdb/ChangeLog     | 38 ++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  6 +++++-
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 24 ++++++++++++++++++------
 gdb/language.h    | 21 +++++++--------------
 gdb/m2-lang.c     |  6 +++++-
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  6 +++++-
 gdb/rust-lang.c   |  6 +++++-
 13 files changed, 83 insertions(+), 33 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 58b3c7b654f..1100742c1f5 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13708,7 +13708,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 
 extern const struct language_data ada_language_data =
 {
-  range_check_off,
   case_sensitive_on,            /* Yes, Ada is case-insensitive, but
                                    that's not quite what this means.  */
   array_row_major,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index c8fe630c247..88af4585b21 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -875,7 +875,6 @@ const struct exp_descriptor exp_descriptor_c =
 
 extern const struct language_data c_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
@@ -985,7 +984,6 @@ enum cplus_primitive_types {
 
 extern const struct language_data cplus_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
@@ -1193,7 +1191,6 @@ static cplus_language cplus_language_defn;
 
 extern const struct language_data asm_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
@@ -1264,7 +1261,6 @@ static asm_language asm_language_defn;
 
 extern const struct language_data minimal_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 9d491c7b854..d1dad29945a 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -128,7 +128,6 @@ enum d_primitive_types {
 
 extern const struct language_data d_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index cffdf559cff..5e1f0f79443 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -486,7 +486,6 @@ static const struct exp_descriptor exp_descriptor_f =
 
 extern const struct language_data f_language_data =
 {
-  range_check_on,
   case_sensitive_off,
   array_column_major,
   macro_expansion_no,
@@ -722,6 +721,11 @@ class f_language : public language_defn
   bool c_style_arrays_p () const override
   { return false; }
 
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index dfc0dddc616..f5abd518e22 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -508,7 +508,6 @@ enum go_primitive_types {
 
 extern const struct language_data go_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
diff --git a/gdb/language.c b/gdb/language.c
index 3503408ad21..56b3b2eb306 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -49,12 +49,21 @@
 
 static void set_range_case (void);
 
+/* range_mode ==
+   range_mode_auto:   range_check set automatically to default of language.
+   range_mode_manual: range_check set manually by user.  */
+
+enum range_mode
+  {
+    range_mode_auto, range_mode_manual
+  };
+
 /* 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
    language of the first source file.  */
 
-enum range_mode range_mode = range_mode_auto;
+static enum range_mode range_mode = range_mode_auto;
 enum range_check range_check = range_check_off;
 enum case_mode case_mode = case_mode_auto;
 enum case_sensitivity case_sensitivity = case_sensitive_on;
@@ -209,7 +218,9 @@ show_range_command (struct ui_file *file, int from_tty,
     fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"),
 		      value);
 
-  if (range_check != current_language->la_range_check)
+  if (range_check == range_check_warn
+      || ((range_check == range_check_on)
+	  != current_language->range_checking_on_by_default ()))
     warning (_("the current range check setting "
 	       "does not match the language.\n"));
 }
@@ -245,7 +256,9 @@ set_range_command (const char *ignore,
       internal_error (__FILE__, __LINE__,
 		      _("Unrecognized range check setting: \"%s\""), range);
     }
-  if (range_check != current_language->la_range_check)
+  if (range_check == range_check_warn
+      || ((range_check == range_check_on)
+	  != current_language->range_checking_on_by_default ()))
     warning (_("the current range check setting "
 	       "does not match the language.\n"));
 }
@@ -329,7 +342,8 @@ static void
 set_range_case (void)
 {
   if (range_mode == range_mode_auto)
-    range_check = current_language->la_range_check;
+    range_check = (current_language->range_checking_on_by_default ()
+		   ? range_check_on : range_check_off);
 
   if (case_mode == case_mode_auto)
     case_sensitivity = current_language->la_case_sensitivity;
@@ -775,7 +789,6 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 
 extern const struct language_data unknown_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
@@ -912,7 +925,6 @@ static unknown_language unknown_language_defn;
 
 extern const struct language_data auto_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
diff --git a/gdb/language.h b/gdb/language.h
index 10a9e707320..ffdcdbc21f8 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -42,16 +42,6 @@ class innermost_block_tracker;
 
 #define MAX_FORTRAN_DIMS  7	/* Maximum number of F77 array dims.  */
 
-/* range_mode ==
-   range_mode_auto:   range_check set automatically to default of language.
-   range_mode_manual: range_check set manually by user.  */
-
-extern enum range_mode
-  {
-    range_mode_auto, range_mode_manual
-  }
-range_mode;
-
 /* range_check ==
    range_check_on:    Ranges are checked in GDB expressions, producing errors.
    range_check_warn:  Ranges are checked, producing warnings.
@@ -188,10 +178,6 @@ extern const char *default_word_break_characters (void);
 
 struct language_data
   {
-    /* Default range checking.  */
-
-    enum range_check la_range_check;
-
     /* Default case sensitivity.  */
     enum case_sensitivity la_case_sensitivity;
 
@@ -572,6 +558,13 @@ struct language_defn : language_data
   virtual bool store_sym_names_in_linkage_form_p () const
   { return false; }
 
+  /* Default range checking preference.  The return value from this
+     function provides the automatic setting for 'set check range'.  As a
+     consequence a user is free to override this setting if they want.  */
+
+  virtual bool range_checking_on_by_default () const
+  { return false; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 577d8192114..785436c4f22 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -199,7 +199,6 @@ const struct exp_descriptor exp_descriptor_modula2 =
 
 extern const struct language_data m2_language_data =
 {
-  range_check_on,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
@@ -444,6 +443,11 @@ class m2_language : public language_defn
 
   char string_lower_bound () const override
   { return 0; }
+
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 7b2dbd8bfa2..1788910c8d5 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -323,7 +323,6 @@ static const struct op_print objc_op_print_tab[] =
 
 extern const struct language_data objc_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 1e4c28ba230..98486b1af59 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1007,7 +1007,6 @@ const struct exp_descriptor exp_descriptor_opencl =
 /* Constant data representing the OpenCL language.  */
 extern const struct language_data opencl_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 9ca1427098e..2325aca96b5 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -252,7 +252,6 @@ enum pascal_primitive_types {
 
 extern const struct language_data pascal_language_data =
 {
-  range_check_on,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
@@ -508,6 +507,11 @@ class pascal_language : public language_defn
 
   const char *name_of_this () const override
   { return "this"; }
+
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index e2d011acde1..b952d26d720 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1906,7 +1906,6 @@ static const struct exp_descriptor exp_descriptor_rust =
 
 extern const struct language_data rust_language_data =
 {
-  range_check_on,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
@@ -2154,6 +2153,11 @@ class rust_language : public language_defn
 		&& rust_slice_type_p (type)
 		&& strcmp (type->name (), "&str") == 0));
   }
+
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.4


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

* [PATCHv2 12/18] gdb: Convert language_data::la_case_sensitivity to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (10 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 11/18] gdb: Convert language_data::la_range_check to a method Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 13/18] gdb: Convert language_data::la_array_ordering " Andrew Burgess
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_case_sensitivity member variable to a virtual
method language_defn::case_sensitivity.

This is mostly straight forward.  The only slight problem is that I
ended up deleting this comment from ada-lang.c:

  /* Yes, Ada is case-insensitive, but that's not quite what this
     means.  */

However, as the comment (which has existed since Ada support was first
added to GDB) doesn't explain _why_ Ada sets case sensitivity to on
despite being a generally case insensitive language, this doesn't
really help me much.

If I understood _why_ the setting doesn't quite mean what it seems to
mean (at least as far as Ada is concerned) then I would extend the
comment on language_defn::case_sensitivity (in language.h) to include
the detail, and note how this impacts Ada.  But as it stands I've just
deleted the comment for now.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_case_sensitivity
	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.
	(f_language::case_sensitivity): New member function.
	* go-lang.c (go_language_data): Remove la_case_sensitivity
	initializer.
	* language.c (enum case_mode): Moved here from language.h.
	(case_mode): Make static.
	(show_case_command): Update for case_sensitivity being a method.
	(set_case_command): Likewise.
	(set_range_case): Likewise.
	(unknown_language_data): Remove la_case_sensitivity initializer.
	(auto_language_data): Likewise.
	* language.h (case_mode): Delete, move enum declaration to
	language.c.
	(language_data): Delete la_case_sensitivity field.
	(language_defn::case_sensitivity): New member function.
	* m2-lang.c (m2_language_data): Remove la_case_sensitivity
	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     | 31 +++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  2 --
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  6 +++++-
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 19 +++++++++++++------
 gdb/language.h    | 20 +++++++-------------
 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, 56 insertions(+), 33 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1100742c1f5..79c868c3e77 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13708,8 +13708,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 
 extern const struct language_data ada_language_data =
 {
-  case_sensitive_on,            /* Yes, Ada is case-insensitive, but
-                                   that's not quite what this means.  */
   array_row_major,
   macro_expansion_no,
   &ada_exp_descriptor,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 88af4585b21..c1aa02fb67f 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -875,7 +875,6 @@ const struct exp_descriptor exp_descriptor_c =
 
 extern const struct language_data c_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
@@ -984,7 +983,6 @@ enum cplus_primitive_types {
 
 extern const struct language_data cplus_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
@@ -1191,7 +1189,6 @@ static cplus_language cplus_language_defn;
 
 extern const struct language_data asm_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
@@ -1261,7 +1258,6 @@ static asm_language asm_language_defn;
 
 extern const struct language_data minimal_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index d1dad29945a..616f6b4d96c 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -128,7 +128,6 @@ enum d_primitive_types {
 
 extern const struct language_data d_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_c,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 5e1f0f79443..d11b240afcd 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -486,7 +486,6 @@ static const struct exp_descriptor exp_descriptor_f =
 
 extern const struct language_data f_language_data =
 {
-  case_sensitive_off,
   array_column_major,
   macro_expansion_no,
   &exp_descriptor_f,
@@ -726,6 +725,11 @@ class f_language : public language_defn
   bool range_checking_on_by_default () const override
   { return true; }
 
+  /* See language.h.  */
+
+  enum case_sensitivity case_sensitivity () const override
+  { return case_sensitive_off; }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index f5abd518e22..7ac7e9455fa 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -508,7 +508,6 @@ enum go_primitive_types {
 
 extern const struct language_data go_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_c,
diff --git a/gdb/language.c b/gdb/language.c
index 56b3b2eb306..41fdf357f1a 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -58,6 +58,15 @@ enum range_mode
     range_mode_auto, range_mode_manual
   };
 
+/* case_mode ==
+   case_mode_auto:   case_sensitivity set upon selection of scope.
+   case_mode_manual: case_sensitivity set only by user.  */
+
+enum case_mode
+  {
+    case_mode_auto, case_mode_manual
+  };
+
 /* 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
@@ -65,7 +74,7 @@ enum range_mode
 
 static enum range_mode range_mode = range_mode_auto;
 enum range_check range_check = range_check_off;
-enum case_mode case_mode = case_mode_auto;
+static enum case_mode case_mode = case_mode_auto;
 enum case_sensitivity case_sensitivity = case_sensitive_on;
 
 /* The current language and language_mode (see language.h).  */
@@ -296,7 +305,7 @@ show_case_command (struct ui_file *file, int from_tty,
 		      _("Case sensitivity in name search is \"%s\".\n"),
 		      value);
 
-  if (case_sensitivity != current_language->la_case_sensitivity)
+  if (case_sensitivity != current_language->case_sensitivity ())
     warning (_("the current case sensitivity setting does not match "
 	       "the language.\n"));
 }
@@ -329,7 +338,7 @@ set_case_command (const char *ignore, int from_tty, struct cmd_list_element *c)
 		       case_sensitive);
      }
 
-   if (case_sensitivity != current_language->la_case_sensitivity)
+   if (case_sensitivity != current_language->case_sensitivity ())
      warning (_("the current case sensitivity setting does not match "
 		"the language.\n"));
 }
@@ -346,7 +355,7 @@ set_range_case (void)
 		   ? range_check_on : range_check_off);
 
   if (case_mode == case_mode_auto)
-    case_sensitivity = current_language->la_case_sensitivity;
+    case_sensitivity = current_language->case_sensitivity ();
 }
 
 /* Set current language to (enum language) LANG.  Returns previous
@@ -789,7 +798,6 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 
 extern const struct language_data unknown_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_standard,
@@ -925,7 +933,6 @@ static unknown_language unknown_language_defn;
 
 extern const struct language_data auto_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_standard,
diff --git a/gdb/language.h b/gdb/language.h
index ffdcdbc21f8..b6d1d15c23f 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -53,16 +53,6 @@ extern enum range_check
   }
 range_check;
 
-/* case_mode ==
-   case_mode_auto:   case_sensitivity set upon selection of scope.
-   case_mode_manual: case_sensitivity set only by user.  */
-
-extern enum case_mode
-  {
-    case_mode_auto, case_mode_manual
-  }
-case_mode;
-
 /* array_ordering ==
    array_row_major:     Arrays are in row major order.
    array_column_major:  Arrays are in column major order.  */
@@ -178,9 +168,6 @@ extern const char *default_word_break_characters (void);
 
 struct language_data
   {
-    /* Default case sensitivity.  */
-    enum case_sensitivity la_case_sensitivity;
-
     /* Multi-dimensional array ordering.  */
     enum array_ordering la_array_ordering;
 
@@ -565,6 +552,13 @@ struct language_defn : language_data
   virtual bool range_checking_on_by_default () const
   { return false; }
 
+  /* Is this language case sensitive?  The return value from this function
+     provides the automativ setting for 'set case-sensitive', as a
+     consequence, a user is free to override this setting if they want.  */
+
+  virtual enum case_sensitivity case_sensitivity () const
+  { return case_sensitive_on; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 785436c4f22..94fa01243b3 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -199,7 +199,6 @@ const struct exp_descriptor exp_descriptor_modula2 =
 
 extern const struct language_data m2_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_modula2,
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 1788910c8d5..45936c9caec 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -323,7 +323,6 @@ static const struct op_print objc_op_print_tab[] =
 
 extern const struct language_data objc_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_standard,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 98486b1af59..9df6e8f6a2a 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1007,7 +1007,6 @@ const struct exp_descriptor exp_descriptor_opencl =
 /* Constant data representing the OpenCL language.  */
 extern const struct language_data opencl_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_c,
   &exp_descriptor_opencl,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 2325aca96b5..fcc0eb90f5c 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -252,7 +252,6 @@ enum pascal_primitive_types {
 
 extern const struct language_data pascal_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_standard,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index b952d26d720..f28b9e0e2b0 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1906,7 +1906,6 @@ static const struct exp_descriptor exp_descriptor_rust =
 
 extern const struct language_data rust_language_data =
 {
-  case_sensitive_on,
   array_row_major,
   macro_expansion_no,
   &exp_descriptor_rust,
-- 
2.25.4


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

* [PATCHv2 13/18] gdb: Convert language_data::la_array_ordering to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (11 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 12/18] gdb: Convert language_data::la_case_sensitivity " Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 14/18] gdb: Convert language_data::la_macro_expansion " Andrew Burgess
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_array_ordering member variable to a virtual
method language_defn::array_ordering.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_array_ordering
	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.
	* dwarf2/read.c (read_array_order): Update for call to
	array_ordering.
	* f-lang.c (f_language_data): Remove la_array_ordering
	initializer.
	(f_language::array_ordering): New member function.
	* go-lang.c (go_language_data): Remove la_array_ordering
	initializer.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_array_ordering field.
	(language_defn::array_ordering): New member function.
	* m2-lang.c (m2_language_data): Remove la_array_ordering
	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      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/dwarf2/read.c |  2 +-
 gdb/f-lang.c      |  6 +++++-
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 gdb/language.h    |  9 ++++++---
 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, 39 insertions(+), 19 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 79c868c3e77..f682cf12142 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13708,7 +13708,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 
 extern const struct language_data ada_language_data =
 {
-  array_row_major,
   macro_expansion_no,
   &ada_exp_descriptor,
   ada_op_print_tab,             /* expression operators for printing */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index c1aa02fb67f..e752e50a68f 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -875,7 +875,6 @@ const struct exp_descriptor exp_descriptor_c =
 
 extern const struct language_data c_language_data =
 {
-  array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
@@ -983,7 +982,6 @@ enum cplus_primitive_types {
 
 extern const struct language_data cplus_language_data =
 {
-  array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
@@ -1189,7 +1187,6 @@ static cplus_language cplus_language_defn;
 
 extern const struct language_data asm_language_data =
 {
-  array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
@@ -1258,7 +1255,6 @@ static asm_language asm_language_defn;
 
 extern const struct language_data minimal_language_data =
 {
-  array_row_major,
   macro_expansion_c,
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 616f6b4d96c..ef15a53e6b5 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -128,7 +128,6 @@ enum d_primitive_types {
 
 extern const struct language_data d_language_data =
 {
-  array_row_major,
   macro_expansion_no,
   &exp_descriptor_c,
   d_op_print_tab,		/* Expression operators for printing.  */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 20d90d4a45f..87b62552ef7 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16489,7 +16489,7 @@ read_array_order (struct die_info *die, struct dwarf2_cu *cu)
       return DW_ORD_row_major;
     }
 
-  switch (cu->language_defn->la_array_ordering)
+  switch (cu->language_defn->array_ordering ())
     {
     case array_column_major:
       return DW_ORD_col_major;
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index d11b240afcd..c0367270218 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -486,7 +486,6 @@ static const struct exp_descriptor exp_descriptor_f =
 
 extern const struct language_data f_language_data =
 {
-  array_column_major,
   macro_expansion_no,
   &exp_descriptor_f,
   f_op_print_tab,		/* expression operators for printing */
@@ -730,6 +729,11 @@ class f_language : public language_defn
   enum case_sensitivity case_sensitivity () const override
   { return case_sensitive_off; }
 
+  /* See language.h.  */
+
+  enum array_ordering array_ordering () const override
+  { return array_column_major; }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 7ac7e9455fa..ceda7aff89c 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -508,7 +508,6 @@ enum go_primitive_types {
 
 extern const struct language_data go_language_data =
 {
-  array_row_major,
   macro_expansion_no,
   &exp_descriptor_c,
   go_op_print_tab,		/* Expression operators for printing.  */
diff --git a/gdb/language.c b/gdb/language.c
index 41fdf357f1a..507c51a6fee 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -798,7 +798,6 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 
 extern const struct language_data unknown_language_data =
 {
-  array_row_major,
   macro_expansion_no,
   &exp_descriptor_standard,
   unk_op_print_tab,		/* expression operators for printing */
@@ -933,7 +932,6 @@ static unknown_language unknown_language_defn;
 
 extern const struct language_data auto_language_data =
 {
-  array_row_major,
   macro_expansion_no,
   &exp_descriptor_standard,
   unk_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/language.h b/gdb/language.h
index b6d1d15c23f..5ec5daa4aef 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -168,9 +168,6 @@ extern const char *default_word_break_characters (void);
 
 struct language_data
   {
-    /* Multi-dimensional array ordering.  */
-    enum array_ordering la_array_ordering;
-
     /* Style of macro expansion, if any, supported by this language.  */
     enum macro_expansion la_macro_expansion;
 
@@ -559,6 +556,12 @@ struct language_defn : language_data
   virtual enum case_sensitivity case_sensitivity () const
   { return case_sensitive_on; }
 
+
+  /* Multi-dimensional array ordering.  */
+
+  virtual enum array_ordering array_ordering () const
+  { return array_row_major; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 94fa01243b3..b587242e07b 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -199,7 +199,6 @@ const struct exp_descriptor exp_descriptor_modula2 =
 
 extern const struct language_data m2_language_data =
 {
-  array_row_major,
   macro_expansion_no,
   &exp_descriptor_modula2,
   m2_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 45936c9caec..60e0eaddbf4 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -323,7 +323,6 @@ static const struct op_print objc_op_print_tab[] =
 
 extern const struct language_data objc_language_data =
 {
-  array_row_major,
   macro_expansion_c,
   &exp_descriptor_standard,
   objc_op_print_tab,		/* Expression operators for printing */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 9df6e8f6a2a..1cd1087ff83 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1007,7 +1007,6 @@ const struct exp_descriptor exp_descriptor_opencl =
 /* Constant data representing the OpenCL language.  */
 extern const struct language_data opencl_language_data =
 {
-  array_row_major,
   macro_expansion_c,
   &exp_descriptor_opencl,
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index fcc0eb90f5c..d1e6e69cb04 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -252,7 +252,6 @@ enum pascal_primitive_types {
 
 extern const struct language_data pascal_language_data =
 {
-  array_row_major,
   macro_expansion_no,
   &exp_descriptor_standard,
   pascal_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f28b9e0e2b0..f158e3bd849 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1906,7 +1906,6 @@ static const struct exp_descriptor exp_descriptor_rust =
 
 extern const struct language_data rust_language_data =
 {
-  array_row_major,
   macro_expansion_no,
   &exp_descriptor_rust,
   c_op_print_tab,		/* expression operators for printing */
-- 
2.25.4


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

* [PATCHv2 14/18] gdb: Convert language_data::la_macro_expansion to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (12 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 13/18] gdb: Convert language_data::la_array_ordering " Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 15/18] gdb: Convert language_data::la_varobj_ops " Andrew Burgess
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_macro_expansion member variable to a virtual
method language_defn::macro_expansion.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_macro_expansion
	initializer.
	* c-lang.c (c_language_data): Likewise.
	(c_language::macro_expansion): New member function.
	(cplus_language_data): Likewise.
	(cplus_language::macro_expansion): New member function.
	(asm_language_data): Likewise.
	(asm_language::macro_expansion): New member function.
	(minimal_language_data): Likewise.
	(minimal_language::macro_expansion): New member function.
	* d-lang.c (d_language_data): Remove la_macro_expansion
	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): Remove la_macro_expansion field.
	(language_defn::macro_expansion): New member function.
	* m2-lang.c (m2_language_data): Remove la_macro_expansion
	initializer.
	* objc-lang.c (objc_language_data): Likewise.
	(objc_language::macro_expansion): New member function.
	* opencl-lang.c (opencl_language_data): Likewise.
	(opencl_language::macro_expansion): New member function.
	* p-lang.c (pascal_language_data): Remove la_macro_expansion
	initializer.
	* rust-lang.c (rust_language_data): Likewise.
	* symtab.c (default_collect_symbol_completion_matches_break_on):
	Update call to macro_expansion.
---
 gdb/ChangeLog     | 32 ++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      | 24 ++++++++++++++++++++----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 gdb/language.h    |  9 ++++++---
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  6 +++++-
 gdb/opencl-lang.c |  6 +++++-
 gdb/p-lang.c      |  1 -
 gdb/rust-lang.c   |  1 -
 gdb/symtab.c      |  2 +-
 14 files changed, 69 insertions(+), 19 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index f682cf12142..9da6625830e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13708,7 +13708,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 
 extern const struct language_data ada_language_data =
 {
-  macro_expansion_no,
   &ada_exp_descriptor,
   ada_op_print_tab,             /* expression operators for printing */
   &ada_varobj_ops,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index e752e50a68f..a478dd81b23 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -875,7 +875,6 @@ const struct exp_descriptor exp_descriptor_c =
 
 extern const struct language_data c_language_data =
 {
-  macro_expansion_c,
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
   &c_varobj_ops,
@@ -944,6 +943,11 @@ class c_language : public language_defn
 
   bool store_sym_names_in_linkage_form_p () const override
   { return true; }
+
+  /* See language.h.  */
+
+  enum macro_expansion macro_expansion () const override
+  { return macro_expansion_c; }
 };
 
 /* Single instance of the C language class.  */
@@ -982,7 +986,6 @@ enum cplus_primitive_types {
 
 extern const struct language_data cplus_language_data =
 {
-  macro_expansion_c,
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
   &cplus_varobj_ops,
@@ -1168,6 +1171,11 @@ class cplus_language : public language_defn
   const char *name_of_this () const override
   { return "this"; }
 
+  /* See language.h.  */
+
+  enum macro_expansion macro_expansion () const override
+  { return macro_expansion_c; }
+
 protected:
 
   /* See language.h.  */
@@ -1187,7 +1195,6 @@ static cplus_language cplus_language_defn;
 
 extern const struct language_data asm_language_data =
 {
-  macro_expansion_c,
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
@@ -1243,6 +1250,11 @@ class asm_language : public language_defn
 
   bool store_sym_names_in_linkage_form_p () const override
   { return true; }
+
+  /* See language.h.  */
+
+  enum macro_expansion macro_expansion () const override
+  { return macro_expansion_c; }
 };
 
 /* The single instance of the ASM language class.  */
@@ -1255,7 +1267,6 @@ static asm_language asm_language_defn;
 
 extern const struct language_data minimal_language_data =
 {
-  macro_expansion_c,
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
@@ -1300,6 +1311,11 @@ class minimal_language : public language_defn
 
   bool store_sym_names_in_linkage_form_p () const override
   { return true; }
+
+  /* See language.h.  */
+
+  enum macro_expansion macro_expansion () const override
+  { return macro_expansion_c; }
 };
 
 /* The single instance of the minimal language class.  */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index ef15a53e6b5..785440024d0 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -128,7 +128,6 @@ enum d_primitive_types {
 
 extern const struct language_data d_language_data =
 {
-  macro_expansion_no,
   &exp_descriptor_c,
   d_op_print_tab,		/* Expression operators for printing.  */
   &default_varobj_ops,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index c0367270218..eb7b70cdecc 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -486,7 +486,6 @@ static const struct exp_descriptor exp_descriptor_f =
 
 extern const struct language_data f_language_data =
 {
-  macro_expansion_no,
   &exp_descriptor_f,
   f_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index ceda7aff89c..92d2819ac4a 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -508,7 +508,6 @@ enum go_primitive_types {
 
 extern const struct language_data go_language_data =
 {
-  macro_expansion_no,
   &exp_descriptor_c,
   go_op_print_tab,		/* Expression operators for printing.  */
   &default_varobj_ops,
diff --git a/gdb/language.c b/gdb/language.c
index 507c51a6fee..d255035495b 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -798,7 +798,6 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 
 extern const struct language_data unknown_language_data =
 {
-  macro_expansion_no,
   &exp_descriptor_standard,
   unk_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
@@ -932,7 +931,6 @@ static unknown_language unknown_language_defn;
 
 extern const struct language_data auto_language_data =
 {
-  macro_expansion_no,
   &exp_descriptor_standard,
   unk_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
diff --git a/gdb/language.h b/gdb/language.h
index 5ec5daa4aef..a2a970e192b 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -168,9 +168,6 @@ extern const char *default_word_break_characters (void);
 
 struct language_data
   {
-    /* Style of macro expansion, if any, supported by this language.  */
-    enum macro_expansion la_macro_expansion;
-
     /* Definitions related to expression printing, prefixifying, and
        dumping.  */
 
@@ -562,6 +559,12 @@ struct language_defn : language_data
   virtual enum array_ordering array_ordering () const
   { return array_row_major; }
 
+  /* Style of macro expansion, if any, supported by this language.  The
+     default is no macro expansion.  */
+
+  virtual enum macro_expansion macro_expansion () const
+  { return macro_expansion_no; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index b587242e07b..ac251af24e8 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -199,7 +199,6 @@ const struct exp_descriptor exp_descriptor_modula2 =
 
 extern const struct language_data m2_language_data =
 {
-  macro_expansion_no,
   &exp_descriptor_modula2,
   m2_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 60e0eaddbf4..2246e125fc3 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -323,7 +323,6 @@ static const struct op_print objc_op_print_tab[] =
 
 extern const struct language_data objc_language_data =
 {
-  macro_expansion_c,
   &exp_descriptor_standard,
   objc_op_print_tab,		/* Expression operators for printing */
   &default_varobj_ops,
@@ -425,6 +424,11 @@ class objc_language : public language_defn
 
   const char *name_of_this () const override
   { return "self"; }
+
+  /* See language.h.  */
+
+  enum macro_expansion macro_expansion () const override
+  { return macro_expansion_c; }
 };
 
 /* Single instance of the class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 1cd1087ff83..6365d622fae 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1007,7 +1007,6 @@ const struct exp_descriptor exp_descriptor_opencl =
 /* Constant data representing the OpenCL language.  */
 extern const struct language_data opencl_language_data =
 {
-  macro_expansion_c,
   &exp_descriptor_opencl,
   c_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
@@ -1068,6 +1067,11 @@ class opencl_language : public language_defn
 
     c_print_type (type, varstring, stream, show, level, flags);
   }
+
+  /* See language.h.  */
+
+  enum macro_expansion macro_expansion () const override
+  { return macro_expansion_c; }
 };
 
 /* Single instance of the OpenCL language class.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index d1e6e69cb04..aa2b9fcb8ca 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -252,7 +252,6 @@ enum pascal_primitive_types {
 
 extern const struct language_data pascal_language_data =
 {
-  macro_expansion_no,
   &exp_descriptor_standard,
   pascal_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f158e3bd849..f099024d4e2 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1906,7 +1906,6 @@ static const struct exp_descriptor exp_descriptor_rust =
 
 extern const struct language_data rust_language_data =
 {
-  macro_expansion_no,
   &exp_descriptor_rust,
   c_op_print_tab,		/* expression operators for printing */
   &default_varobj_ops,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 61f96b2ab8c..04891c4a89b 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -5768,7 +5768,7 @@ default_collect_symbol_completion_matches_break_on
 
   /* Skip macros if we are completing a struct tag -- arguable but
      usually what is expected.  */
-  if (current_language->la_macro_expansion == macro_expansion_c
+  if (current_language->macro_expansion () == macro_expansion_c
       && code == TYPE_CODE_UNDEF)
     {
       gdb::unique_xmalloc_ptr<struct macro_scope> scope;
-- 
2.25.4


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

* [PATCHv2 15/18] gdb: Convert language_data::la_varobj_ops to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (13 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 14/18] gdb: Convert language_data::la_macro_expansion " Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 16/18] gdb: Convert language_data::la_exp_desc " Andrew Burgess
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_varobj_ops member variable to a virtual
method language_defn::varobj_ops.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_varobj_ops
	initializer.
	(ada_language::varobj_ops): New member function.
	* c-lang.c (c_language_data): Remove la_varobj_ops
	initializer.
	(cplus_language_data): Likewise.
	(cplus_language::varobj_ops): New member function.
	(asm_language_data): Remove la_varobj_ops 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_defn::varobj_ops): New function.
	(unknown_language_data): Remove la_varobj_ops
	initializer.
	(auto_language_data): Likewise.
	* language.h (language_data): Remove la_varobj_ops field.
	(language_defn::varobj_ops): Declare new member function.
	* m2-lang.c (m2_language_data): Remove la_varobj_ops 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.
	* varobj.c (varobj_create): Update call to varobj_ops.
	* varobj.h (default_varobj_ops): Delete define.
---
 gdb/ChangeLog     | 28 ++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  6 +++++-
 gdb/c-lang.c      |  9 +++++----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 12 ++++++++++--
 gdb/language.h    |  8 +++++---
 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/varobj.c      |  2 +-
 gdb/varobj.h      |  2 --
 15 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 9da6625830e..7b8676959cf 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13710,7 +13710,6 @@ extern const struct language_data ada_language_data =
 {
   &ada_exp_descriptor,
   ada_op_print_tab,             /* expression operators for printing */
-  &ada_varobj_ops,
 };
 
 /* Class representing the Ada language.  */
@@ -14202,6 +14201,11 @@ class ada_language : public language_defn
   bool store_sym_names_in_linkage_form_p () const override
   { return true; }
 
+  /* See language.h.  */
+
+  const struct lang_varobj_ops *varobj_ops () const override
+  { return &ada_varobj_ops; }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index a478dd81b23..9b21da15044 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -877,7 +877,6 @@ extern const struct language_data c_language_data =
 {
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
-  &c_varobj_ops,
 };
 
 /* Class representing the C language.  */
@@ -988,7 +987,6 @@ extern const struct language_data cplus_language_data =
 {
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
-  &cplus_varobj_ops,
 };
 
 /* A class for the C++ language.  */
@@ -1176,6 +1174,11 @@ class cplus_language : public language_defn
   enum macro_expansion macro_expansion () const override
   { return macro_expansion_c; }
 
+  /* See language.h.  */
+
+  const struct lang_varobj_ops *varobj_ops () const override
+  { return &cplus_varobj_ops; }
+
 protected:
 
   /* See language.h.  */
@@ -1197,7 +1200,6 @@ extern const struct language_data asm_language_data =
 {
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* A class for the ASM language.  */
@@ -1269,7 +1271,6 @@ extern const struct language_data minimal_language_data =
 {
   &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* A class for the minimal language.  */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 785440024d0..5630610536e 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -130,7 +130,6 @@ extern const struct language_data d_language_data =
 {
   &exp_descriptor_c,
   d_op_print_tab,		/* Expression operators for printing.  */
-  &default_varobj_ops,
 };
 
 /* Class representing the D language.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index eb7b70cdecc..b9651412efc 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -488,7 +488,6 @@ extern const struct language_data f_language_data =
 {
   &exp_descriptor_f,
   f_op_print_tab,		/* expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* Class representing the Fortran language.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 92d2819ac4a..c37e918e42a 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -510,7 +510,6 @@ extern const struct language_data go_language_data =
 {
   &exp_descriptor_c,
   go_op_print_tab,		/* Expression operators for printing.  */
-  &default_varobj_ops,
 };
 
 /* Class representing the Go language.  */
diff --git a/gdb/language.c b/gdb/language.c
index d255035495b..bcffd3e1338 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -764,6 +764,16 @@ language_defn::get_symbol_name_matcher_inner
   return default_symbol_name_matcher;
 }
 
+/* See language.h.  */
+
+const struct lang_varobj_ops *
+language_defn::varobj_ops () const
+{
+  /* The ops for the C language are suitable for the vast majority of the
+     supported languages.  */
+  return &c_varobj_ops;
+}
+
 /* Return true if TYPE is a string type, otherwise return false.  This
    default implementation only detects TYPE_CODE_STRING.  */
 
@@ -800,7 +810,6 @@ extern const struct language_data unknown_language_data =
 {
   &exp_descriptor_standard,
   unk_op_print_tab,		/* expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* Class representing the unknown language.  */
@@ -933,7 +942,6 @@ extern const struct language_data auto_language_data =
 {
   &exp_descriptor_standard,
   unk_op_print_tab,		/* expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* Class representing the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index a2a970e192b..414488ddfbd 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -176,9 +176,6 @@ struct language_data
     /* Table for printing expressions.  */
 
     const struct op_print *la_op_print_tab;
-
-    /* Various operations on varobj.  */
-    const struct lang_varobj_ops *la_varobj_ops;
   };
 
 /* Base class from which all other language classes derive.  */
@@ -565,6 +562,11 @@ struct language_defn : language_data
   virtual enum macro_expansion macro_expansion () const
   { return macro_expansion_no; }
 
+  /* Return a structure containing various operations on varobj specific
+     for this language.  */
+
+  virtual const struct lang_varobj_ops *varobj_ops () const;
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index ac251af24e8..c5206bbf901 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -201,7 +201,6 @@ extern const struct language_data m2_language_data =
 {
   &exp_descriptor_modula2,
   m2_op_print_tab,		/* expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* Class representing the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 2246e125fc3..523902a0774 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -325,7 +325,6 @@ extern const struct language_data objc_language_data =
 {
   &exp_descriptor_standard,
   objc_op_print_tab,		/* Expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* Class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 6365d622fae..235ee2dc47e 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1009,7 +1009,6 @@ extern const struct language_data opencl_language_data =
 {
   &exp_descriptor_opencl,
   c_op_print_tab,		/* expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* Class representing the OpenCL language.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index aa2b9fcb8ca..6dd0b988a54 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -254,7 +254,6 @@ extern const struct language_data pascal_language_data =
 {
   &exp_descriptor_standard,
   pascal_op_print_tab,		/* expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* Class representing the Pascal language.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f099024d4e2..4b5b9b08bdf 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1908,7 +1908,6 @@ extern const struct language_data rust_language_data =
 {
   &exp_descriptor_rust,
   c_op_print_tab,		/* expression operators for printing */
-  &default_varobj_ops,
 };
 
 /* Class representing the Rust language.  */
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 3358be4e77b..85530e3f3cf 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -386,7 +386,7 @@ varobj_create (const char *objname,
 	}
 
       /* Set language info */
-      var->root->lang_ops = var->root->exp->language_defn->la_varobj_ops;
+      var->root->lang_ops = var->root->exp->language_defn->varobj_ops ();
 
       install_new_value (var.get (), value, 1 /* Initial assignment */);
 
diff --git a/gdb/varobj.h b/gdb/varobj.h
index 3e6abaa709f..7831e76b973 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -233,8 +233,6 @@ extern const struct lang_varobj_ops c_varobj_ops;
 extern const struct lang_varobj_ops cplus_varobj_ops;
 extern const struct lang_varobj_ops ada_varobj_ops;
 
-#define default_varobj_ops c_varobj_ops
-
 /* Non-zero if we want to see trace of varobj level stuff.  */
 
 extern unsigned int varobjdebug;
-- 
2.25.4


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

* [PATCHv2 16/18] gdb: Convert language_data::la_exp_desc to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (14 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 15/18] gdb: Convert language_data::la_varobj_ops " Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 17/18] gdb: Convert language_data::la_op_print_tab " Andrew Burgess
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_exp_desc member variable to a virtual
method language_defn::expression_ops.  The change of names brings this
method more into line with the existing varobj_ops method, that also
returns a table of function pointers.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_exp_desc initializer.
	(ada_language::expression_ops): New member function.
	* c-lang.c (c_language_data): Remove la_exp_desc initializer.
	(c_language::expression_ops): New member function.
	(cplus_language_data): Remove la_exp_desc initializer.
	(cplus_language::expression_ops): New member function.
	(asm_language_data): Remove la_exp_desc initializer.
	(asm_language::expression_ops): New member function.
	(minimal_language_data): Remove la_exp_desc initializer.
	(minimal_language::expression_ops): New member function.
	* d-lang.c (d_language_data): Remove la_exp_desc initializer.
	(d_language::expression_ops): New member function.
	* eval.c (evaluate_subexp): Update call to expression_ops.
	* expprint.c (print_subexp): Likewise.
	(op_name): Likewise.
	(dump_subexp_body): Likewise.
	* f-lang.c (f_language_data): Remove la_exp_desc initializer.
	(f_language::expression_ops): New member function.
	* go-lang.c (go_language_data): Remove la_exp_desc initializer.
	(go_language::expression_ops): New member function.
	* language.c (language_defn::expression_ops): New function.
	(unknown_language_data): Remove la_exp_desc initializer.
	(auto_language_data): Likewise.
	* language.h (language_data): Remove la_exp_desc field.
	(language_defn::expression_ops): Declare new member function.
	* m2-lang.c (m2_language_data): Remove la_exp_desc initializer.
	(m2_language::expression_ops): New member function.
	* objc-lang.c (objc_language_data): Remove la_exp_desc
	initializer.
	* opencl-lang.c (opencl_language_data): Remove la_exp_desc
	initializer.
	(opencl_language::expression_ops): New member function.
	* p-lang.c (pascal_language_data): Remove la_exp_desc initializer.
	* parse.c (operator_length): Update call to expression_ops.
	(exp_iterate): Likewise.
	* rust-lang.c (rust_language_data): Remove la_exp_desc
	initializer.
	(ruse_language::expression_ops): New member function.
---
 gdb/ChangeLog     | 41 +++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  6 +++++-
 gdb/c-lang.c      | 24 ++++++++++++++++++++----
 gdb/d-lang.c      |  6 +++++-
 gdb/eval.c        |  2 +-
 gdb/expprint.c    |  8 +++++---
 gdb/f-lang.c      |  6 +++++-
 gdb/go-lang.c     |  6 +++++-
 gdb/language.c    | 10 ++++++++--
 gdb/language.h    | 10 +++++-----
 gdb/m2-lang.c     |  6 +++++-
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  6 +++++-
 gdb/p-lang.c      |  1 -
 gdb/parse.c       |  9 +++++----
 gdb/rust-lang.c   |  6 +++++-
 16 files changed, 120 insertions(+), 28 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7b8676959cf..b5c066f470c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13708,7 +13708,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 
 extern const struct language_data ada_language_data =
 {
-  &ada_exp_descriptor,
   ada_op_print_tab,             /* expression operators for printing */
 };
 
@@ -14206,6 +14205,11 @@ class ada_language : public language_defn
   const struct lang_varobj_ops *varobj_ops () const override
   { return &ada_varobj_ops; }
 
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &ada_exp_descriptor; }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 9b21da15044..f29f3407e16 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -875,7 +875,6 @@ const struct exp_descriptor exp_descriptor_c =
 
 extern const struct language_data c_language_data =
 {
-  &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
 };
 
@@ -947,6 +946,11 @@ class c_language : public language_defn
 
   enum macro_expansion macro_expansion () const override
   { return macro_expansion_c; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_c; }
 };
 
 /* Single instance of the C language class.  */
@@ -985,7 +989,6 @@ enum cplus_primitive_types {
 
 extern const struct language_data cplus_language_data =
 {
-  &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
 };
 
@@ -1179,6 +1182,11 @@ class cplus_language : public language_defn
   const struct lang_varobj_ops *varobj_ops () const override
   { return &cplus_varobj_ops; }
 
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_c; }
+
 protected:
 
   /* See language.h.  */
@@ -1198,7 +1206,6 @@ static cplus_language cplus_language_defn;
 
 extern const struct language_data asm_language_data =
 {
-  &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
 };
 
@@ -1257,6 +1264,11 @@ class asm_language : public language_defn
 
   enum macro_expansion macro_expansion () const override
   { return macro_expansion_c; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_c; }
 };
 
 /* The single instance of the ASM language class.  */
@@ -1269,7 +1281,6 @@ static asm_language asm_language_defn;
 
 extern const struct language_data minimal_language_data =
 {
-  &exp_descriptor_c,
   c_op_print_tab,		/* expression operators for printing */
 };
 
@@ -1317,6 +1328,11 @@ class minimal_language : public language_defn
 
   enum macro_expansion macro_expansion () const override
   { return macro_expansion_c; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_c; }
 };
 
 /* The single instance of the minimal language class.  */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 5630610536e..107ee4a4a70 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -128,7 +128,6 @@ enum d_primitive_types {
 
 extern const struct language_data d_language_data =
 {
-  &exp_descriptor_c,
   d_op_print_tab,		/* Expression operators for printing.  */
 };
 
@@ -276,6 +275,11 @@ class d_language : public language_defn
 
   const char *name_of_this () const override
   { return "this"; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_c; }
 };
 
 /* Single instance of the D language class.  */
diff --git a/gdb/eval.c b/gdb/eval.c
index 65c44ad4949..34ec4325e9e 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -74,7 +74,7 @@ evaluate_subexp (struct type *expect_type, struct expression *exp,
       && !thread_stack_temporaries_enabled_p (inferior_thread ()))
     stack_temporaries.emplace (inferior_thread ());
 
-  retval = (*exp->language_defn->la_exp_desc->evaluate_exp)
+  retval = (*exp->language_defn->expression_ops ()->evaluate_exp)
     (expect_type, exp, pos, noside);
 
   if (stack_temporaries.has_value ()
diff --git a/gdb/expprint.c b/gdb/expprint.c
index 36e18ea1a9f..8cca5b4f92c 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -50,7 +50,8 @@ void
 print_subexp (struct expression *exp, int *pos,
 	      struct ui_file *stream, enum precedence prec)
 {
-  exp->language_defn->la_exp_desc->print_subexp (exp, pos, stream, prec);
+  exp->language_defn->expression_ops ()->print_subexp (exp, pos, stream,
+						       prec);
 }
 
 /* Standard implementation of print_subexp for use in language_defn
@@ -692,7 +693,7 @@ op_name (struct expression *exp, enum exp_opcode opcode)
 		 unsigned (opcode));
       return cell;
     }
-  return exp->language_defn->la_exp_desc->op_name (opcode);
+  return exp->language_defn->expression_ops ()->op_name (opcode);
 }
 
 /* Default name for the standard operator OPCODE (i.e., one defined in
@@ -793,7 +794,8 @@ dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
 static int
 dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
 {
-  return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt);
+  return exp->language_defn->expression_ops ()->dump_subexp_body (exp, stream,
+								  elt);
 }
 
 /* Default value for subexp_body in exp_descriptor vector.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index b9651412efc..8069fa4c17f 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -486,7 +486,6 @@ static const struct exp_descriptor exp_descriptor_f =
 
 extern const struct language_data f_language_data =
 {
-  &exp_descriptor_f,
   f_op_print_tab,		/* expression operators for printing */
 };
 
@@ -732,6 +731,11 @@ class f_language : public language_defn
   enum array_ordering array_ordering () const override
   { return array_column_major; }
 
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_f; }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index c37e918e42a..eacc4debf42 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -508,7 +508,6 @@ enum go_primitive_types {
 
 extern const struct language_data go_language_data =
 {
-  &exp_descriptor_c,
   go_op_print_tab,		/* Expression operators for printing.  */
 };
 
@@ -637,6 +636,11 @@ class go_language : public language_defn
 
   bool store_sym_names_in_linkage_form_p () const override
   { return true; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_c; }
 };
 
 /* Single instance of the Go language class.  */
diff --git a/gdb/language.c b/gdb/language.c
index bcffd3e1338..b467512e80d 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -774,6 +774,14 @@ language_defn::varobj_ops () const
   return &c_varobj_ops;
 }
 
+/* See language.h.  */
+
+const struct exp_descriptor *
+language_defn::expression_ops () const
+{
+  return &exp_descriptor_standard;
+}
+
 /* Return true if TYPE is a string type, otherwise return false.  This
    default implementation only detects TYPE_CODE_STRING.  */
 
@@ -808,7 +816,6 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 
 extern const struct language_data unknown_language_data =
 {
-  &exp_descriptor_standard,
   unk_op_print_tab,		/* expression operators for printing */
 };
 
@@ -940,7 +947,6 @@ static unknown_language unknown_language_defn;
 
 extern const struct language_data auto_language_data =
 {
-  &exp_descriptor_standard,
   unk_op_print_tab,		/* expression operators for printing */
 };
 
diff --git a/gdb/language.h b/gdb/language.h
index 414488ddfbd..cfb3461a8cd 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -168,11 +168,6 @@ extern const char *default_word_break_characters (void);
 
 struct language_data
   {
-    /* Definitions related to expression printing, prefixifying, and
-       dumping.  */
-
-    const struct exp_descriptor *la_exp_desc;
-
     /* Table for printing expressions.  */
 
     const struct op_print *la_op_print_tab;
@@ -567,6 +562,11 @@ struct language_defn : language_data
 
   virtual const struct lang_varobj_ops *varobj_ops () const;
 
+  /* Definitions related to expression printing, prefixifying, and
+     dumping.  */
+
+  virtual const struct exp_descriptor *expression_ops () const;
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index c5206bbf901..b41d0b48d6e 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -199,7 +199,6 @@ const struct exp_descriptor exp_descriptor_modula2 =
 
 extern const struct language_data m2_language_data =
 {
-  &exp_descriptor_modula2,
   m2_op_print_tab,		/* expression operators for printing */
 };
 
@@ -444,6 +443,11 @@ class m2_language : public language_defn
 
   bool range_checking_on_by_default () const override
   { return true; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_modula2; }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 523902a0774..e78e0871aa9 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -323,7 +323,6 @@ static const struct op_print objc_op_print_tab[] =
 
 extern const struct language_data objc_language_data =
 {
-  &exp_descriptor_standard,
   objc_op_print_tab,		/* Expression operators for printing */
 };
 
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 235ee2dc47e..8b77b875469 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1007,7 +1007,6 @@ const struct exp_descriptor exp_descriptor_opencl =
 /* Constant data representing the OpenCL language.  */
 extern const struct language_data opencl_language_data =
 {
-  &exp_descriptor_opencl,
   c_op_print_tab,		/* expression operators for printing */
 };
 
@@ -1071,6 +1070,11 @@ class opencl_language : public language_defn
 
   enum macro_expansion macro_expansion () const override
   { return macro_expansion_c; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_opencl; }
 };
 
 /* Single instance of the OpenCL language class.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 6dd0b988a54..1acd591d41c 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -252,7 +252,6 @@ enum pascal_primitive_types {
 
 extern const struct language_data pascal_language_data =
 {
-  &exp_descriptor_standard,
   pascal_op_print_tab,		/* expression operators for printing */
 };
 
diff --git a/gdb/parse.c b/gdb/parse.c
index 2fb474e27f1..37bafe4cf2d 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -762,8 +762,8 @@ void
 operator_length (const struct expression *expr, int endpos, int *oplenp,
 		 int *argsp)
 {
-  expr->language_defn->la_exp_desc->operator_length (expr, endpos,
-						     oplenp, argsp);
+  expr->language_defn->expression_ops ()->operator_length (expr, endpos,
+							   oplenp, argsp);
 }
 
 /* Default value for operator_length in exp_descriptor vectors.  */
@@ -1374,8 +1374,9 @@ exp_iterate (struct expression *exp,
       gdb_assert (oplen > 0);
 
       pos = endpos - oplen;
-      if (exp->language_defn->la_exp_desc->operator_check (exp, pos,
-							   objfile_func, data))
+      if (exp->language_defn->expression_ops ()->operator_check (exp, pos,
+								 objfile_func,
+								 data))
 	return 1;
 
       endpos = pos;
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 4b5b9b08bdf..d676f91da7d 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1906,7 +1906,6 @@ static const struct exp_descriptor exp_descriptor_rust =
 
 extern const struct language_data rust_language_data =
 {
-  &exp_descriptor_rust,
   c_op_print_tab,		/* expression operators for printing */
 };
 
@@ -2154,6 +2153,11 @@ class rust_language : public language_defn
 
   bool range_checking_on_by_default () const override
   { return true; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_rust; }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.4


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

* [PATCHv2 17/18] gdb: Convert language_data::la_op_print_tab to a method
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (15 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 16/18] gdb: Convert language_data::la_exp_desc " Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-08-05 14:45 ` [PATCHv2 18/18] gdb: Remove language_data struct Andrew Burgess
  2020-09-03 16:00 ` [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

Convert language_data::la_op_print_tab member variable to a virtual
method language_defn::opcode_print_table.  I changed the name in order
to make it clearer (I hope) what the method does.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_op_print_tab
	initializer.
	(ada_language::opcode_print_table): New member function.
	* c-lang.c (c_language_data): Remove la_op_print_tab initializer.
	(c_language::opcode_print_table): New member function.
	(cplus_language_data): Remove la_op_print_tab initializer.
	(cplus_language::opcode_print_table): New member function.
	(asm_language_data): Remove la_op_print_tab initializer.
	(asm_language::opcode_print_table): New member function.
	(minimal_language_data): Remove la_op_print_tab initializer.
	(minimal_language::opcode_print_table): New member function.
	* d-lang.c (d_language_data): Remove la_op_print_tab initializer.
	(d_language::opcode_print_table): New member function.
	* expprint.c (print_subexp_standard): Update call to
	opcode_print_table.
	(op_string): Likewise.
	* f-lang.c (f_language_data): Remove la_op_print_tab initializer.
	(f_language::opcode_print_table): New member function.
	* go-lang.c (go_language_data): Remove la_op_print_tab
	initializer.
	(go_language::opcode_print_table): New member function.
	* language.c (unknown_language_data): Remove la_op_print_tab
	initializer.
	(unknown_language::opcode_print_table): New member function.
	(auto_language_data): Remove la_op_print_tab initializer.
	(auto_language::opcode_print_table): New member function.
	* language.h (language_data): Remove la_op_print_tab field.
	(language_defn::opcode_print_table): Declare new member function.
	* m2-lang.c (m2_language_data): Remove la_op_print_tab
	initializer.
	(m2_language::opcode_print_table): New member function.
	* objc-lang.c (objc_language_data): Remove la_op_print_tab
	initializer.
	(objc_language::opcode_print_table): New member function.
	* opencl-lang.c (opencl_language_data): Remove la_op_print_tab
	initializer.
	(opencl_language::opcode_print_table): New member function.
	* p-lang.c (pascal_language_data): Remove la_op_print_tab
	initializer.
	(pascal_language::opcode_print_table): New member function.
	* rust-lang.c (rust_language_data): Remove la_op_print_tab
	initializer.
	(rust_language::opcode_print_table): New member function.
---
 gdb/ChangeLog     | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  6 +++++-
 gdb/c-lang.c      | 24 ++++++++++++++++++++----
 gdb/d-lang.c      |  6 +++++-
 gdb/expprint.c    |  4 ++--
 gdb/f-lang.c      |  6 +++++-
 gdb/go-lang.c     |  6 +++++-
 gdb/language.c    | 12 ++++++++++--
 gdb/language.h    |  7 ++++---
 gdb/m2-lang.c     |  6 +++++-
 gdb/objc-lang.c   |  6 +++++-
 gdb/opencl-lang.c |  6 +++++-
 gdb/p-lang.c      |  6 +++++-
 gdb/rust-lang.c   |  6 +++++-
 14 files changed, 127 insertions(+), 20 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b5c066f470c..dbfaebc66e2 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13708,7 +13708,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 
 extern const struct language_data ada_language_data =
 {
-  ada_op_print_tab,             /* expression operators for printing */
 };
 
 /* Class representing the Ada language.  */
@@ -14210,6 +14209,11 @@ class ada_language : public language_defn
   const struct exp_descriptor *expression_ops () const override
   { return &ada_exp_descriptor; }
 
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return ada_op_print_tab; }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index f29f3407e16..73968ed20f4 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -875,7 +875,6 @@ const struct exp_descriptor exp_descriptor_c =
 
 extern const struct language_data c_language_data =
 {
-  c_op_print_tab,		/* expression operators for printing */
 };
 
 /* Class representing the C language.  */
@@ -951,6 +950,11 @@ class c_language : public language_defn
 
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_c; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return c_op_print_tab; }
 };
 
 /* Single instance of the C language class.  */
@@ -989,7 +993,6 @@ enum cplus_primitive_types {
 
 extern const struct language_data cplus_language_data =
 {
-  c_op_print_tab,		/* expression operators for printing */
 };
 
 /* A class for the C++ language.  */
@@ -1187,6 +1190,11 @@ class cplus_language : public language_defn
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_c; }
 
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return c_op_print_tab; }
+
 protected:
 
   /* See language.h.  */
@@ -1206,7 +1214,6 @@ static cplus_language cplus_language_defn;
 
 extern const struct language_data asm_language_data =
 {
-  c_op_print_tab,		/* expression operators for printing */
 };
 
 /* A class for the ASM language.  */
@@ -1269,6 +1276,11 @@ class asm_language : public language_defn
 
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_c; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return c_op_print_tab; }
 };
 
 /* The single instance of the ASM language class.  */
@@ -1281,7 +1293,6 @@ static asm_language asm_language_defn;
 
 extern const struct language_data minimal_language_data =
 {
-  c_op_print_tab,		/* expression operators for printing */
 };
 
 /* A class for the minimal language.  */
@@ -1333,6 +1344,11 @@ class minimal_language : public language_defn
 
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_c; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return c_op_print_tab; }
 };
 
 /* The single instance of the minimal language class.  */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 107ee4a4a70..f590d63d930 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -128,7 +128,6 @@ enum d_primitive_types {
 
 extern const struct language_data d_language_data =
 {
-  d_op_print_tab,		/* Expression operators for printing.  */
 };
 
 /* Class representing the D language.  */
@@ -280,6 +279,11 @@ class d_language : public language_defn
 
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_c; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return d_op_print_tab; }
 };
 
 /* Single instance of the D language class.  */
diff --git a/gdb/expprint.c b/gdb/expprint.c
index 8cca5b4f92c..5bd9553a411 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -73,7 +73,7 @@ print_subexp_standard (struct expression *exp, int *pos,
   struct value *val;
   char *tempstr = NULL;
 
-  op_print_tab = exp->language_defn->la_op_print_tab;
+  op_print_tab = exp->language_defn->opcode_print_table ();
   pc = (*pos)++;
   opcode = exp->elts[pc].opcode;
   switch (opcode)
@@ -669,7 +669,7 @@ op_string (enum exp_opcode op)
   int tem;
   const struct op_print *op_print_tab;
 
-  op_print_tab = current_language->la_op_print_tab;
+  op_print_tab = current_language->opcode_print_table ();
   for (tem = 0; op_print_tab[tem].opcode != OP_NULL; tem++)
     if (op_print_tab[tem].opcode == op)
       return op_print_tab[tem].string;
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 8069fa4c17f..101f4dbc1e5 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -486,7 +486,6 @@ static const struct exp_descriptor exp_descriptor_f =
 
 extern const struct language_data f_language_data =
 {
-  f_op_print_tab,		/* expression operators for printing */
 };
 
 /* Class representing the Fortran language.  */
@@ -736,6 +735,11 @@ class f_language : public language_defn
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_f; }
 
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return f_op_print_tab; }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index eacc4debf42..2b9be93b2e5 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -508,7 +508,6 @@ enum go_primitive_types {
 
 extern const struct language_data go_language_data =
 {
-  go_op_print_tab,		/* Expression operators for printing.  */
 };
 
 /* Class representing the Go language.  */
@@ -641,6 +640,11 @@ class go_language : public language_defn
 
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_c; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return go_op_print_tab; }
 };
 
 /* Single instance of the Go language class.  */
diff --git a/gdb/language.c b/gdb/language.c
index b467512e80d..37aef2cd73b 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -816,7 +816,6 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 
 extern const struct language_data unknown_language_data =
 {
-  unk_op_print_tab,		/* expression operators for printing */
 };
 
 /* Class representing the unknown language.  */
@@ -937,6 +936,11 @@ class unknown_language : public language_defn
 
   bool store_sym_names_in_linkage_form_p () const override
   { return true; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return unk_op_print_tab; }
 };
 
 /* Single instance of the unknown language class.  */
@@ -947,7 +951,6 @@ static unknown_language unknown_language_defn;
 
 extern const struct language_data auto_language_data =
 {
-  unk_op_print_tab,		/* expression operators for printing */
 };
 
 /* Class representing the fake "auto" language.  */
@@ -1063,6 +1066,11 @@ class auto_language : public language_defn
 
   const char *name_of_this () const override
   { return "this"; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return unk_op_print_tab; }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index cfb3461a8cd..2d13cfa9db9 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -168,9 +168,6 @@ extern const char *default_word_break_characters (void);
 
 struct language_data
   {
-    /* Table for printing expressions.  */
-
-    const struct op_print *la_op_print_tab;
   };
 
 /* Base class from which all other language classes derive.  */
@@ -567,6 +564,10 @@ struct language_defn : language_data
 
   virtual const struct exp_descriptor *expression_ops () const;
 
+  /* Table for printing expressions.  */
+
+  virtual const struct op_print *opcode_print_table () const = 0;
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index b41d0b48d6e..1f9c8a878e4 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -199,7 +199,6 @@ const struct exp_descriptor exp_descriptor_modula2 =
 
 extern const struct language_data m2_language_data =
 {
-  m2_op_print_tab,		/* expression operators for printing */
 };
 
 /* Class representing the M2 language.  */
@@ -448,6 +447,11 @@ class m2_language : public language_defn
 
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_modula2; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return m2_op_print_tab; }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index e78e0871aa9..b59a45b49be 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -323,7 +323,6 @@ static const struct op_print objc_op_print_tab[] =
 
 extern const struct language_data objc_language_data =
 {
-  objc_op_print_tab,		/* Expression operators for printing */
 };
 
 /* Class representing the Objective-C language.  */
@@ -427,6 +426,11 @@ class objc_language : public language_defn
 
   enum macro_expansion macro_expansion () const override
   { return macro_expansion_c; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return c_op_print_tab; }
 };
 
 /* Single instance of the class representing the Objective-C language.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 8b77b875469..9bc5f5698c6 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1007,7 +1007,6 @@ const struct exp_descriptor exp_descriptor_opencl =
 /* Constant data representing the OpenCL language.  */
 extern const struct language_data opencl_language_data =
 {
-  c_op_print_tab,		/* expression operators for printing */
 };
 
 /* Class representing the OpenCL language.  */
@@ -1075,6 +1074,11 @@ class opencl_language : public language_defn
 
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_opencl; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return c_op_print_tab; }
 };
 
 /* Single instance of the OpenCL language class.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 1acd591d41c..6a9811d869c 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -252,7 +252,6 @@ enum pascal_primitive_types {
 
 extern const struct language_data pascal_language_data =
 {
-  pascal_op_print_tab,		/* expression operators for printing */
 };
 
 /* Class representing the Pascal language.  */
@@ -507,6 +506,11 @@ class pascal_language : public language_defn
 
   bool range_checking_on_by_default () const override
   { return true; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return pascal_op_print_tab; }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index d676f91da7d..23508af96dc 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1906,7 +1906,6 @@ static const struct exp_descriptor exp_descriptor_rust =
 
 extern const struct language_data rust_language_data =
 {
-  c_op_print_tab,		/* expression operators for printing */
 };
 
 /* Class representing the Rust language.  */
@@ -2158,6 +2157,11 @@ class rust_language : public language_defn
 
   const struct exp_descriptor *expression_ops () const override
   { return &exp_descriptor_rust; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return c_op_print_tab; }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.4


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

* [PATCHv2 18/18] gdb: Remove language_data struct
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (16 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 17/18] gdb: Convert language_data::la_op_print_tab " Andrew Burgess
@ 2020-08-05 14:45 ` Andrew Burgess
  2020-09-03 16:00 ` [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
  18 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-08-05 14:45 UTC (permalink / raw)
  To: gdb-patches

The language_data type, from which language_defn inherits, is now
empty, and this commit removes it.

Each language is updated to no longer create and use a language_data
struct.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete.
	(ada_language): Remove references to ada_language_data.
	* c-lang.c (c_language_data): Delete.
	(c_language): Remove references to c_language_data.
	(cplus_language_data): Delete.
	(cplus_language): Remove references to cplus_language_data.
	(asm_language_data): Delete.
	(asm_language): Remove references to asm_language_data.
	(minimal_language_data): Delete.
	(minimal_language): Remove references to minimal_language_data.
	* d-lang.c (d_language_data): Delete.
	(d_language): Remove references to d_language_data.
	* f-lang.c (f_language_data): Delete.
	(f_language): Remove references to f_language_data.
	* go-lang.c (go_language_data): Delete.
	(go_language): Remove references to go_language_data.
	* language.c (unknown_language_data): Delete.
	(unknown_language): Remove references to unknown_language_data.
	(auto_language_data): Delete.
	(auto_language): Remove references to auto_language_data.
	* language.h (language_data): Delete struct.
	(language_defn): No longer inherit from language_data.
	* m2-lang.c (m2_language_data): Delete.
	(m2_language): Remove references to m2_language_data.
	* objc-lang.c (objc_language_data): Delete.
	(objc_language): Remove references to objc_language_data.
	* opencl-lang.c (opencl_language_data): Delete.
	(opencl_language): Remove references to opencl_language_data.
	* p-lang.c (pascal_language_data): Delete.
	(pascal_language): Remove references to pascal_language_data.
	* rust-lang.c (rust_language_data): Delete.
	(rust_language): Remove references to rust_language_data.
---
 gdb/ChangeLog     | 35 +++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  8 +-------
 gdb/c-lang.c      | 38 +++++++-------------------------------
 gdb/d-lang.c      |  8 +-------
 gdb/f-lang.c      |  8 +-------
 gdb/go-lang.c     |  8 +-------
 gdb/language.c    | 16 ++--------------
 gdb/language.h    | 25 +++----------------------
 gdb/m2-lang.c     |  8 +-------
 gdb/objc-lang.c   |  8 +-------
 gdb/opencl-lang.c |  7 +------
 gdb/p-lang.c      |  8 +-------
 gdb/rust-lang.c   |  8 +-------
 13 files changed, 56 insertions(+), 129 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index dbfaebc66e2..918870de491 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13704,19 +13704,13 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
     }
 }
 
-/* Constant data that describes the Ada language.  */
-
-extern const struct language_data ada_language_data =
-{
-};
-
 /* Class representing the Ada language.  */
 
 class ada_language : public language_defn
 {
 public:
   ada_language ()
-    : language_defn (language_ada, ada_language_data)
+    : language_defn (language_ada)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 73968ed20f4..4e942435177 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -871,19 +871,13 @@ const struct exp_descriptor exp_descriptor_c =
   evaluate_subexp_c
 };
 
-/* Constant data that describes the C language.  */
-
-extern const struct language_data c_language_data =
-{
-};
-
 /* Class representing the C language.  */
 
 class c_language : public language_defn
 {
 public:
   c_language ()
-    : language_defn (language_c, c_language_data)
+    : language_defn (language_c)
   { /* Nothing.  */ }
 
   /* See language.h.  */
@@ -989,19 +983,13 @@ enum cplus_primitive_types {
   nr_cplus_primitive_types
 };
 
-/* Constant data that describes the C++ language.  */
-
-extern const struct language_data cplus_language_data =
-{
-};
-
 /* A class for the C++ language.  */
 
 class cplus_language : public language_defn
 {
 public:
   cplus_language ()
-    : language_defn (language_cplus, cplus_language_data)
+    : language_defn (language_cplus)
   { /* Nothing.  */ }
 
   /* See language.h.  */
@@ -1210,19 +1198,13 @@ class cplus_language : public language_defn
 
 static cplus_language cplus_language_defn;
 
-/* Constant data that describes the ASM language.  */
-
-extern const struct language_data asm_language_data =
-{
-};
-
 /* A class for the ASM language.  */
 
 class asm_language : public language_defn
 {
 public:
   asm_language ()
-    : language_defn (language_asm, asm_language_data)
+    : language_defn (language_asm)
   { /* Nothing.  */ }
 
   /* See language.h.  */
@@ -1286,22 +1268,16 @@ class asm_language : public language_defn
 /* 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 class for the minimal language.  This 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_data minimal_language_data =
-{
-};
-
-/* A class for the minimal language.  */
-
 class minimal_language : public language_defn
 {
 public:
   minimal_language ()
-    : language_defn (language_minimal, minimal_language_data)
+    : language_defn (language_minimal)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index f590d63d930..58664f73349 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -124,19 +124,13 @@ enum d_primitive_types {
   nr_d_primitive_types
 };
 
-/* Constant data that describes the D language.  */
-
-extern const struct language_data d_language_data =
-{
-};
-
 /* Class representing the D language.  */
 
 class d_language : public language_defn
 {
 public:
   d_language ()
-    : language_defn (language_d, d_language_data)
+    : language_defn (language_d)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 101f4dbc1e5..ab7e524cada 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -482,19 +482,13 @@ static const struct exp_descriptor exp_descriptor_f =
   evaluate_subexp_f
 };
 
-/* Constant data that describes the Fortran language.  */
-
-extern const struct language_data f_language_data =
-{
-};
-
 /* Class representing the Fortran language.  */
 
 class f_language : public language_defn
 {
 public:
   f_language ()
-    : language_defn (language_fortran, f_language_data)
+    : language_defn (language_fortran)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 2b9be93b2e5..0322961179f 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -504,19 +504,13 @@ enum go_primitive_types {
   nr_go_primitive_types
 };
 
-/* Constant data that describes the Go language.  */
-
-extern const struct language_data go_language_data =
-{
-};
-
 /* Class representing the Go language.  */
 
 class go_language : public language_defn
 {
 public:
   go_language ()
-    : language_defn (language_go, go_language_data)
+    : language_defn (language_go)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/language.c b/gdb/language.c
index 37aef2cd73b..761f4966979 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -812,19 +812,13 @@ unknown_language_arch_info (struct gdbarch *gdbarch,
 						       struct type *);
 }
 
-/* Constant data that describes the unknown language.  */
-
-extern const struct language_data unknown_language_data =
-{
-};
-
 /* Class representing the unknown language.  */
 
 class unknown_language : public language_defn
 {
 public:
   unknown_language ()
-    : language_defn (language_unknown, unknown_language_data)
+    : language_defn (language_unknown)
   { /* Nothing.  */ }
 
   /* See language.h.  */
@@ -947,19 +941,13 @@ class unknown_language : public language_defn
 
 static unknown_language unknown_language_defn;
 
-/* Constant data for the fake "auto" language.  */
-
-extern const struct language_data auto_language_data =
-{
-};
-
 /* Class representing the fake "auto" language.  */
 
 class auto_language : public language_defn
 {
 public:
   auto_language ()
-    : language_defn (language_auto, auto_language_data)
+    : language_defn (language_auto)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/language.h b/gdb/language.h
index 2d13cfa9db9..3ee6476cbbb 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -152,31 +152,12 @@ struct language_pass_by_ref_info
 /* Splitting strings into words.  */
 extern const char *default_word_break_characters (void);
 
-/* Structure tying together assorted information about a language.
-
-   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
-  {
-  };
-
 /* Base class from which all other language classes derive.  */
 
-struct language_defn : language_data
+struct language_defn
 {
-  language_defn (enum language lang, const language_data &init_data)
-    : language_data (init_data),
-      la_language (lang)
+  language_defn (enum language lang)
+    : la_language (lang)
   {
     /* We should only ever create one instance of each language.  */
     gdb_assert (languages[lang] == nullptr);
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 1f9c8a878e4..3cc0364b4a1 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -195,19 +195,13 @@ const struct exp_descriptor exp_descriptor_modula2 =
   evaluate_subexp_modula2
 };
 
-/* Constant data describing the M2 language.  */
-
-extern const struct language_data m2_language_data =
-{
-};
-
 /* Class representing the M2 language.  */
 
 class m2_language : public language_defn
 {
 public:
   m2_language ()
-    : language_defn (language_m2, m2_language_data)
+    : language_defn (language_m2)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index b59a45b49be..9eaaf96a2a5 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -319,19 +319,13 @@ static const struct op_print objc_op_print_tab[] =
     {NULL, OP_NULL, PREC_NULL, 0}
 };
 
-/* Constant data representing the Objective-C language.  */
-
-extern const struct language_data objc_language_data =
-{
-};
-
 /* Class representing the Objective-C language.  */
 
 class objc_language : public language_defn
 {
 public:
   objc_language ()
-    : language_defn (language_objc, objc_language_data)
+    : language_defn (language_objc)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 9bc5f5698c6..bbb251e83e2 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1004,18 +1004,13 @@ const struct exp_descriptor exp_descriptor_opencl =
   evaluate_subexp_opencl
 };
 
-/* Constant data representing the OpenCL language.  */
-extern const struct language_data opencl_language_data =
-{
-};
-
 /* Class representing the OpenCL language.  */
 
 class opencl_language : public language_defn
 {
 public:
   opencl_language ()
-    : language_defn (language_opencl, opencl_language_data)
+    : language_defn (language_opencl)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 6a9811d869c..1867fd4b943 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -248,19 +248,13 @@ enum pascal_primitive_types {
   nr_pascal_primitive_types
 };
 
-/* Constant data representing the Pascal language.  */
-
-extern const struct language_data pascal_language_data =
-{
-};
-
 /* Class representing the Pascal language.  */
 
 class pascal_language : public language_defn
 {
 public:
   pascal_language ()
-    : language_defn (language_pascal, pascal_language_data)
+    : language_defn (language_pascal)
   { /* Nothing.  */ }
 
   /* See language.h.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 23508af96dc..0f61eb18fc1 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1902,19 +1902,13 @@ static const struct exp_descriptor exp_descriptor_rust =
   rust_evaluate_subexp
 };
 
-/* Constant data representing the Rust language.  */
-
-extern const struct language_data rust_language_data =
-{
-};
-
 /* Class representing the Rust language.  */
 
 class rust_language : public language_defn
 {
 public:
   rust_language ()
-    : language_defn (language_rust, rust_language_data)
+    : language_defn (language_rust)
   { /* Nothing.  */ }
 
   /* See language.h.  */
-- 
2.25.4


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

* Re: [PATCHv2 00/18] Further updates for the language class structure
  2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
                   ` (17 preceding siblings ...)
  2020-08-05 14:45 ` [PATCHv2 18/18] gdb: Remove language_data struct Andrew Burgess
@ 2020-09-03 16:00 ` Andrew Burgess
  2020-09-16 10:06   ` Andrew Burgess
  18 siblings, 1 reply; 21+ messages in thread
From: Andrew Burgess @ 2020-09-03 16:00 UTC (permalink / raw)
  To: gdb-patches

I'm going to take a look at rebasing and merging this series in the
next few days.  There's no functional change, it's just more movement
away from using the original language structure.

Any last minute feedback?

Thanks,
Andrew


* Andrew Burgess <andrew.burgess@embecosm.com> [2020-08-05 15:45:35 +0100]:

> This v2 series replaces, and extends the earlier series I posted here:
> 
>     https://sourceware.org/pipermail/gdb-patches/2020-July/170288.html
> 
> The first 10 patches are the same as the previous series, while the
> remaining 8 are new in this version of the series.
> 
> After this series the language_data base class is completely removed.
> 
> As I mentioned in the original patch series, I'm not 100% sure that
> converting static data fields from language_data into virtual methods
> on language_defn is the right approach, but getting rid of
> language_data does feel like a good thing, so I pushed through and
> completed the task.
> 
> I'd be interested in any feedback, do people think this is the right
> approach, or are there any suggestions for a better approach.
> 
> Thanks,
> Andrew
> 
> ---
> 
> Andrew Burgess (18):
>   gdb: Convert la_struct_too_deep_ellipsis to a method
>   gdb: Convert la_name_of_this to a method
>   gdb: Convert la_name and la_natural_name to methods
>   gdb: Convert la_filename_extensions to a method
>   gdb: Move la_language into the language_defn class
>   gdb: Convert language_data::c_style_arrays to a method
>   gdb: Fix an incorrect comment
>   gdb: Convert language_data::string_lower_bound to a method
>   gdb: Convert la_store_sym_names_in_linkage_form_p to a method
>   gdb: Override store_sym_names_in_linkage_form_p for Go language
>   gdb: Convert language_data::la_range_check to a method
>   gdb: Convert language_data::la_case_sensitivity to a method
>   gdb: Convert language_data::la_array_ordering to a method
>   gdb: Convert language_data::la_macro_expansion to a method
>   gdb: Convert language_data::la_varobj_ops to a method
>   gdb: Convert language_data::la_exp_desc to a method
>   gdb: Convert language_data::la_op_print_tab to a method
>   gdb: Remove language_data struct
> 
>  gdb/ChangeLog         | 627 ++++++++++++++++++++++++++++++++++++++++++
>  gdb/ada-lang.c        |  78 ++++--
>  gdb/ax-gdb.c          |   2 +-
>  gdb/c-exp.y           |   2 +-
>  gdb/c-lang.c          | 268 ++++++++++--------
>  gdb/compile/compile.c |   2 +-
>  gdb/cp-valprint.c     |   4 +-
>  gdb/d-lang.c          |  62 +++--
>  gdb/dwarf2/read.c     |  10 +-
>  gdb/eval.c            |   4 +-
>  gdb/expprint.c        |  22 +-
>  gdb/f-lang.c          |  87 ++++--
>  gdb/go-lang.c         |  48 ++--
>  gdb/infcall.c         |   2 +-
>  gdb/language.c        | 186 ++++++++-----
>  gdb/language.h        | 238 ++++++++--------
>  gdb/m2-lang.c         |  60 ++--
>  gdb/mi/mi-cmd-var.c   |   2 +-
>  gdb/objc-lang.c       |  62 +++--
>  gdb/opencl-lang.c     |  48 ++--
>  gdb/p-lang.c          |  63 +++--
>  gdb/parse.c           |   9 +-
>  gdb/rust-lang.c       |  62 +++--
>  gdb/symfile.c         |   1 +
>  gdb/symtab.c          |  10 +-
>  gdb/valarith.c        |   6 +-
>  gdb/valops.c          |  14 +-
>  gdb/valprint.c        |   4 +-
>  gdb/value.c           |   7 +-
>  gdb/varobj.c          |   2 +-
>  gdb/varobj.h          |   2 -
>  31 files changed, 1395 insertions(+), 599 deletions(-)
> 
> -- 
> 2.25.4
> 

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

* Re: [PATCHv2 00/18] Further updates for the language class structure
  2020-09-03 16:00 ` [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
@ 2020-09-16 10:06   ` Andrew Burgess
  0 siblings, 0 replies; 21+ messages in thread
From: Andrew Burgess @ 2020-09-16 10:06 UTC (permalink / raw)
  To: gdb-patches

I've now pushed this series.

Any post-commit feedback is still always welcome.

Thanks,
Andrew


* Andrew Burgess <andrew.burgess@embecosm.com> [2020-09-03 17:00:34 +0100]:

> I'm going to take a look at rebasing and merging this series in the
> next few days.  There's no functional change, it's just more movement
> away from using the original language structure.
> 
> Any last minute feedback?
> 
> Thanks,
> Andrew
> 
> 
> * Andrew Burgess <andrew.burgess@embecosm.com> [2020-08-05 15:45:35 +0100]:
> 
> > This v2 series replaces, and extends the earlier series I posted here:
> > 
> >     https://sourceware.org/pipermail/gdb-patches/2020-July/170288.html
> > 
> > The first 10 patches are the same as the previous series, while the
> > remaining 8 are new in this version of the series.
> > 
> > After this series the language_data base class is completely removed.
> > 
> > As I mentioned in the original patch series, I'm not 100% sure that
> > converting static data fields from language_data into virtual methods
> > on language_defn is the right approach, but getting rid of
> > language_data does feel like a good thing, so I pushed through and
> > completed the task.
> > 
> > I'd be interested in any feedback, do people think this is the right
> > approach, or are there any suggestions for a better approach.
> > 
> > Thanks,
> > Andrew
> > 
> > ---
> > 
> > Andrew Burgess (18):
> >   gdb: Convert la_struct_too_deep_ellipsis to a method
> >   gdb: Convert la_name_of_this to a method
> >   gdb: Convert la_name and la_natural_name to methods
> >   gdb: Convert la_filename_extensions to a method
> >   gdb: Move la_language into the language_defn class
> >   gdb: Convert language_data::c_style_arrays to a method
> >   gdb: Fix an incorrect comment
> >   gdb: Convert language_data::string_lower_bound to a method
> >   gdb: Convert la_store_sym_names_in_linkage_form_p to a method
> >   gdb: Override store_sym_names_in_linkage_form_p for Go language
> >   gdb: Convert language_data::la_range_check to a method
> >   gdb: Convert language_data::la_case_sensitivity to a method
> >   gdb: Convert language_data::la_array_ordering to a method
> >   gdb: Convert language_data::la_macro_expansion to a method
> >   gdb: Convert language_data::la_varobj_ops to a method
> >   gdb: Convert language_data::la_exp_desc to a method
> >   gdb: Convert language_data::la_op_print_tab to a method
> >   gdb: Remove language_data struct
> > 
> >  gdb/ChangeLog         | 627 ++++++++++++++++++++++++++++++++++++++++++
> >  gdb/ada-lang.c        |  78 ++++--
> >  gdb/ax-gdb.c          |   2 +-
> >  gdb/c-exp.y           |   2 +-
> >  gdb/c-lang.c          | 268 ++++++++++--------
> >  gdb/compile/compile.c |   2 +-
> >  gdb/cp-valprint.c     |   4 +-
> >  gdb/d-lang.c          |  62 +++--
> >  gdb/dwarf2/read.c     |  10 +-
> >  gdb/eval.c            |   4 +-
> >  gdb/expprint.c        |  22 +-
> >  gdb/f-lang.c          |  87 ++++--
> >  gdb/go-lang.c         |  48 ++--
> >  gdb/infcall.c         |   2 +-
> >  gdb/language.c        | 186 ++++++++-----
> >  gdb/language.h        | 238 ++++++++--------
> >  gdb/m2-lang.c         |  60 ++--
> >  gdb/mi/mi-cmd-var.c   |   2 +-
> >  gdb/objc-lang.c       |  62 +++--
> >  gdb/opencl-lang.c     |  48 ++--
> >  gdb/p-lang.c          |  63 +++--
> >  gdb/parse.c           |   9 +-
> >  gdb/rust-lang.c       |  62 +++--
> >  gdb/symfile.c         |   1 +
> >  gdb/symtab.c          |  10 +-
> >  gdb/valarith.c        |   6 +-
> >  gdb/valops.c          |  14 +-
> >  gdb/valprint.c        |   4 +-
> >  gdb/value.c           |   7 +-
> >  gdb/varobj.c          |   2 +-
> >  gdb/varobj.h          |   2 -
> >  31 files changed, 1395 insertions(+), 599 deletions(-)
> > 
> > -- 
> > 2.25.4
> > 

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

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

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-05 14:45 [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 01/18] gdb: Convert la_struct_too_deep_ellipsis to a method Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 02/18] gdb: Convert la_name_of_this " Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 03/18] gdb: Convert la_name and la_natural_name to methods Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 04/18] gdb: Convert la_filename_extensions to a method Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 05/18] gdb: Move la_language into the language_defn class Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 06/18] gdb: Convert language_data::c_style_arrays to a method Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 07/18] gdb: Fix an incorrect comment Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 08/18] gdb: Convert language_data::string_lower_bound to a method Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 09/18] gdb: Convert la_store_sym_names_in_linkage_form_p " Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 10/18] gdb: Override store_sym_names_in_linkage_form_p for Go language Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 11/18] gdb: Convert language_data::la_range_check to a method Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 12/18] gdb: Convert language_data::la_case_sensitivity " Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 13/18] gdb: Convert language_data::la_array_ordering " Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 14/18] gdb: Convert language_data::la_macro_expansion " Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 15/18] gdb: Convert language_data::la_varobj_ops " Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 16/18] gdb: Convert language_data::la_exp_desc " Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 17/18] gdb: Convert language_data::la_op_print_tab " Andrew Burgess
2020-08-05 14:45 ` [PATCHv2 18/18] gdb: Remove language_data struct Andrew Burgess
2020-09-03 16:00 ` [PATCHv2 00/18] Further updates for the language class structure Andrew Burgess
2020-09-16 10:06   ` 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).