[PATCHv2,04/18] gdb: Convert la_filename_extensions to a method

Message ID 9d9acafd997be6823b1d816b1db3e581d3eba3a6.1596638295.git.andrew.burgess@embecosm.com
State New
Headers show
Series
  • Further updates for the language class structure
Related show

Commit Message

Andrew Burgess Aug. 5, 2020, 2:45 p.m.
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(-)

-- 
2.25.4

Patch

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