gdb: Convert la_filename_extensions to a method
authorAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 3 Jul 2020 17:46:16 +0000 (18:46 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 16 Sep 2020 09:16:46 +0000 (10:16 +0100)
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.

14 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/c-lang.c
gdb/d-lang.c
gdb/f-lang.c
gdb/go-lang.c
gdb/language.c
gdb/language.h
gdb/m2-lang.c
gdb/objc-lang.c
gdb/opencl-lang.c
gdb/p-lang.c
gdb/rust-lang.c
gdb/symfile.c

index a58c490d2d937b729208280ac8e39bec05b49974..82a621de60e2a139e5b87f54154ec2d23cc404e9 100644 (file)
@@ -1,3 +1,58 @@
+2020-09-16  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * 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.
+
 2020-09-16  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * ada-lang.c (ada_language_data): Remove la_name and
index fd9e6d32172c4d24954dce4e2be5e47c05648d60..b9cd9a3cdcbcd7bdd075c53a8d5d00c8aa773e53 100644 (file)
@@ -13704,11 +13704,6 @@ ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
     }
 }
 
-static const char * const 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 @@ public:
   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,
index eb987f4dd25337a80f521e3c1103c15dbfcb82c0..ce4620a136cb9ce75b1adb388f5ee6e7327b4d6b 100644 (file)
@@ -871,11 +871,6 @@ const struct exp_descriptor exp_descriptor_c =
   evaluate_subexp_c
 };
 
-static const char * const 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 @@ public:
   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 * const 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 @@ public:
 
   /* 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 @@ protected:
 
 static cplus_language cplus_language_defn;
 
-static const char * const 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 @@ public:
   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 */
index ff2bdf0fe2e5d911f8fcd39436770cf6a9b3d94f..2c0ea3865cd95ee4bc3ea27477ddbe1aea027b87 100644 (file)
@@ -124,11 +124,6 @@ enum d_primitive_types {
   nr_d_primitive_types
 };
 
-static const char * const 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 @@ public:
   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
index ace0c565ab2f8c3818c2f7d817b964f9f68d0562..2c4d5231c62ffd9b18e3c85b68f59c2ff742b9c3 100644 (file)
@@ -471,13 +471,6 @@ operator_check_f (struct expression *exp, int pos,
   return 0;
 }
 
-static const char * const 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 @@ public:
   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
index 6e9b487569668339082cc0ad05780cdcffd9262e..13fa0edb9a118eb81becc1f1b7627043c880f8f1 100644 (file)
@@ -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.  */
index 0b1b4882038c87391646375d3bda37bfe00bde94..cc4076253a5bc396cf7dacc814f2ea433384eb31 100644 (file)
@@ -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 */
index 980e3647af994469b753dc4bfa30fdc29d85d6ac..9a7ad214d88ee0407734f7d53a7624a0c5ce9c56 100644 (file)
@@ -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.  */
 
index 9806caf6103dbf65d02c9a258bfaf878b110b458..ef4153811698c62cd31d599bda28cd8c982e64e2 100644 (file)
@@ -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 */
index e63b9927a1c3ca79773de1d6eb64aafc3f480999..ff9735e59d9be41e3880acb96576f95b0c3537d7 100644 (file)
@@ -319,11 +319,6 @@ static const struct op_print objc_op_print_tab[] =
     {NULL, OP_NULL, PREC_NULL, 0}
 };
 
-static const char * const 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 @@ public:
   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
index 9a311c1101b1ad0508db2916c7ce49989d0d6188..a8d485777523a6c07941ca717fa2ec4bb8a24714 100644 (file)
@@ -1011,7 +1011,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 */
index 486e90654e6ea2e421b76dd1a63d892423a9e9c8..da48a52a9abc65094762448898e6880d06cf4e83 100644 (file)
@@ -248,11 +248,6 @@ enum pascal_primitive_types {
   nr_pascal_primitive_types
 };
 
-static const char * const 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 @@ public:
   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,
index 971d60b410a33f4c97c2f052305a85d3ecf99f4f..a7b58351839ad7c066cfffcde0e21a428c465907 100644 (file)
@@ -1897,11 +1897,6 @@ static const struct exp_descriptor exp_descriptor_rust =
   rust_evaluate_subexp
 };
 
-static const char * const rust_extensions[] =
-{
-  ".rs", NULL
-};
-
 /* Constant data representing the Rust language.  */
 
 extern const struct language_data rust_language_data =
@@ -1911,7 +1906,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 */
@@ -1939,6 +1933,14 @@ public:
   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
index 2c38ce4431a6218c0f98c04e057ce0f890140183..d5aa11fef9e07204f7ec971a7f9c6f08a09119b5 100644 (file)
@@ -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);
 }