public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/10] Further reduction of language_data struct
@ 2020-07-09 11:36 Andrew Burgess
  2020-07-09 11:36 ` [PATCH 01/10] gdb: Convert la_struct_too_deep_ellipsis to a method Andrew Burgess
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:36 UTC (permalink / raw)
  To: gdb-patches


In previous commits GDB's languages were converted to C++ classes, and
all attributes were placed into the language_data struct.

We then removed all of the function pointers from language_data and
converted these into virtual methods within the language_defn class,
this left the language_data base class containing nothing but member
variables.

This commit starts the process of converting the member variables from
language_data into virtual methods in language_defn.

I'm less confident about this set of changes.  I'm never sure when
using virtual methods that return simple data values is the best
strategy, and when we should be passing parameters to the constructor,
in which case the current model of placing all the data into the
language_data class is probably not that bad.

So, I'm interested in feedback.  Is this an improvement or not?

All thoughts / feedback welcome.

Thanks,
Andrew



---

Andrew Burgess (10):
  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/ChangeLog         | 349 ++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c        |  47 ++++--
 gdb/ax-gdb.c          |   2 +-
 gdb/c-exp.y           |   2 +-
 gdb/c-lang.c          | 137 +++++++++++------
 gdb/compile/compile.c |   2 +-
 gdb/cp-valprint.c     |   4 +-
 gdb/d-lang.c          |  37 +++--
 gdb/dwarf2/read.c     |   8 +-
 gdb/eval.c            |   2 +-
 gdb/expprint.c        |  10 +-
 gdb/f-lang.c          |  47 ++++--
 gdb/go-lang.c         |  23 +--
 gdb/infcall.c         |   2 +-
 gdb/language.c        |  89 ++++++-----
 gdb/language.h        | 141 +++++++++--------
 gdb/m2-lang.c         |  30 ++--
 gdb/mi/mi-cmd-var.c   |   2 +-
 gdb/objc-lang.c       |  37 +++--
 gdb/opencl-lang.c     |  19 +--
 gdb/p-lang.c          |  38 +++--
 gdb/rust-lang.c       |  32 ++--
 gdb/symfile.c         |   1 +
 gdb/symtab.c          |   8 +-
 gdb/valarith.c        |   6 +-
 gdb/valops.c          |  14 +-
 gdb/valprint.c        |   4 +-
 gdb/value.c           |   7 +-
 28 files changed, 797 insertions(+), 303 deletions(-)

-- 
2.25.4


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

* [PATCH 01/10] gdb: Convert la_struct_too_deep_ellipsis to a method
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
@ 2020-07-09 11:36 ` Andrew Burgess
  2020-07-09 11:36 ` [PATCH 02/10] gdb: Convert la_name_of_this " Andrew Burgess
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:36 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 98508c168bc..a66b0c6d03e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13687,7 +13687,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.  */
@@ -14145,6 +14144,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 d1efea19e91..6cd51d3622c 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] 11+ messages in thread

* [PATCH 02/10] gdb: Convert la_name_of_this to a method
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
  2020-07-09 11:36 ` [PATCH 01/10] gdb: Convert la_struct_too_deep_ellipsis to a method Andrew Burgess
@ 2020-07-09 11:36 ` Andrew Burgess
  2020-07-09 11:37 ` [PATCH 03/10] gdb: Convert la_name and la_natural_name to methods Andrew Burgess
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:36 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 a66b0c6d03e..3a8d4550b35 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13681,7 +13681,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 6cd51d3622c..38c7e2714b2 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 afdb429dc37..8dab121de9f 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3712,7 +3712,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"));
@@ -3722,7 +3722,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] 11+ messages in thread

* [PATCH 03/10] gdb: Convert la_name and la_natural_name to methods
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
  2020-07-09 11:36 ` [PATCH 01/10] gdb: Convert la_struct_too_deep_ellipsis to a method Andrew Burgess
  2020-07-09 11:36 ` [PATCH 02/10] gdb: Convert la_name_of_this " Andrew Burgess
@ 2020-07-09 11:37 ` Andrew Burgess
  2020-07-09 11:37 ` [PATCH 04/10] gdb: Convert la_filename_extensions to a method Andrew Burgess
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:37 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 3a8d4550b35..162187c6f22 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13671,8 +13671,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
@@ -13697,6 +13695,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 38c7e2714b2..2c040e8b6fd 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] 11+ messages in thread

* [PATCH 04/10] gdb: Convert la_filename_extensions to a method
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
                   ` (2 preceding siblings ...)
  2020-07-09 11:37 ` [PATCH 03/10] gdb: Convert la_name and la_natural_name to methods Andrew Burgess
@ 2020-07-09 11:37 ` Andrew Burgess
  2020-07-09 11:37 ` [PATCH 05/10] gdb: Move la_language into the language_defn class Andrew Burgess
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:37 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 162187c6f22..d620dc0c82f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13662,11 +13662,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 =
@@ -13677,7 +13672,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 */
@@ -13705,6 +13699,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 2c040e8b6fd..3ef3262d56a 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] 11+ messages in thread

* [PATCH 05/10] gdb: Move la_language into the language_defn class
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
                   ` (3 preceding siblings ...)
  2020-07-09 11:37 ` [PATCH 04/10] gdb: Convert la_filename_extensions to a method Andrew Burgess
@ 2020-07-09 11:37 ` Andrew Burgess
  2020-07-09 11:37 ` [PATCH 06/10] gdb: Convert language_data::c_style_arrays to a method Andrew Burgess
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:37 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 d620dc0c82f..64511d0eec3 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13666,7 +13666,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 3ef3262d56a..4dd36eefbed 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] 11+ messages in thread

* [PATCH 06/10] gdb: Convert language_data::c_style_arrays to a method
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
                   ` (4 preceding siblings ...)
  2020-07-09 11:37 ` [PATCH 05/10] gdb: Move la_language into the language_defn class Andrew Burgess
@ 2020-07-09 11:37 ` Andrew Burgess
  2020-07-09 11:37 ` [PATCH 07/10] gdb: Fix an incorrect comment Andrew Burgess
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:37 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 64511d0eec3..0323b525577 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13674,7 +13674,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,
 };
@@ -14158,6 +14157,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 f9750816216..1066fd46bb3 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 4dd36eefbed..3b515fa003a 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 a5779a3aff9..b13d762a40d 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 8dab121de9f..c2d0ce05f69 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);
@@ -1618,7 +1618,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 97a099ddbd3..bb3111531a5 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3667,7 +3667,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] 11+ messages in thread

* [PATCH 07/10] gdb: Fix an incorrect comment
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
                   ` (5 preceding siblings ...)
  2020-07-09 11:37 ` [PATCH 06/10] gdb: Convert language_data::c_style_arrays to a method Andrew Burgess
@ 2020-07-09 11:37 ` Andrew Burgess
  2020-07-09 11:37 ` [PATCH 08/10] gdb: Convert language_data::string_lower_bound to a method Andrew Burgess
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:37 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 c2d0ce05f69..f6d5cc6f963 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] 11+ messages in thread

* [PATCH 08/10] gdb: Convert language_data::string_lower_bound to a method
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
                   ` (6 preceding siblings ...)
  2020-07-09 11:37 ` [PATCH 07/10] gdb: Fix an incorrect comment Andrew Burgess
@ 2020-07-09 11:37 ` Andrew Burgess
  2020-07-09 11:37 ` [PATCH 09/10] gdb: Convert la_store_sym_names_in_linkage_form_p " Andrew Burgess
  2020-07-09 11:37 ` [PATCH 10/10] gdb: Override store_sym_names_in_linkage_form_p for Go language Andrew Burgess
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:37 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 0323b525577..22c24485767 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13674,7 +13674,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 3b515fa003a..261530be9b9 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 f6d5cc6f963..03786d9574e 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1640,7 +1640,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);
@@ -1663,7 +1663,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 bb3111531a5..3f89e44bfab 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] 11+ messages in thread

* [PATCH 09/10] gdb: Convert la_store_sym_names_in_linkage_form_p to a method
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
                   ` (7 preceding siblings ...)
  2020-07-09 11:37 ` [PATCH 08/10] gdb: Convert language_data::string_lower_bound to a method Andrew Burgess
@ 2020-07-09 11:37 ` Andrew Burgess
  2020-07-09 11:37 ` [PATCH 10/10] gdb: Override store_sym_names_in_linkage_form_p for Go language Andrew Burgess
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:37 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 22c24485767..121819237b3 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13672,7 +13672,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,
 };
@@ -14161,6 +14160,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 405b5fb3348..c9de742d292 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -10587,7 +10587,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 261530be9b9..3ae2f859043 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] 11+ messages in thread

* [PATCH 10/10] gdb: Override store_sym_names_in_linkage_form_p for Go language
  2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
                   ` (8 preceding siblings ...)
  2020-07-09 11:37 ` [PATCH 09/10] gdb: Convert la_store_sym_names_in_linkage_form_p " Andrew Burgess
@ 2020-07-09 11:37 ` Andrew Burgess
  9 siblings, 0 replies; 11+ messages in thread
From: Andrew Burgess @ 2020-07-09 11:37 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 "other" value.

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 c9de742d292..9720eeca270 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -10591,12 +10591,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] 11+ messages in thread

end of thread, other threads:[~2020-07-09 11:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09 11:36 [PATCH 00/10] Further reduction of language_data struct Andrew Burgess
2020-07-09 11:36 ` [PATCH 01/10] gdb: Convert la_struct_too_deep_ellipsis to a method Andrew Burgess
2020-07-09 11:36 ` [PATCH 02/10] gdb: Convert la_name_of_this " Andrew Burgess
2020-07-09 11:37 ` [PATCH 03/10] gdb: Convert la_name and la_natural_name to methods Andrew Burgess
2020-07-09 11:37 ` [PATCH 04/10] gdb: Convert la_filename_extensions to a method Andrew Burgess
2020-07-09 11:37 ` [PATCH 05/10] gdb: Move la_language into the language_defn class Andrew Burgess
2020-07-09 11:37 ` [PATCH 06/10] gdb: Convert language_data::c_style_arrays to a method Andrew Burgess
2020-07-09 11:37 ` [PATCH 07/10] gdb: Fix an incorrect comment Andrew Burgess
2020-07-09 11:37 ` [PATCH 08/10] gdb: Convert language_data::string_lower_bound to a method Andrew Burgess
2020-07-09 11:37 ` [PATCH 09/10] gdb: Convert la_store_sym_names_in_linkage_form_p " Andrew Burgess
2020-07-09 11:37 ` [PATCH 10/10] gdb: Override store_sym_names_in_linkage_form_p for Go language 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).