From: Andrew Burgess Date: Fri, 3 Jul 2020 17:46:16 +0000 (+0100) Subject: gdb: Convert la_filename_extensions to a method X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e171d6f15e1a65a1fb5a951d2b186ed0c62aec0c;p=binutils-gdb.git gdb: Convert la_filename_extensions to a method 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a58c490d2d9..82a621de60e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,58 @@ +2020-09-16 Andrew Burgess + + * 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 * ada-lang.c (ada_language_data): Remove la_name and diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index fd9e6d32172..b9cd9a3cdcb 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 * 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 &filename_extensions () const override + { + static const std::vector 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 eb987f4dd25..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 * 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 &filename_extensions () const override + { + static const std::vector 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 &filename_extensions () const override + { + static const std::vector 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 &filename_extensions () const override + { + static const std::vector 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 ff2bdf0fe2e..2c0ea3865cd 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 * 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 &filename_extensions () const override + { + static const std::vector 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 ace0c565ab2..2c4d5231c62 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 * 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 &filename_extensions () const override + { + static const std::vector 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 &filename_extensions () const + { + static const std::vector 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 e63b9927a1c..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 * 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 &filename_extensions () const override + { + static const std::vector 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 9a311c1101b..a8d48577752 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -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 */ diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 486e90654e6..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 * 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 &filename_extensions () const override + { + static const std::vector 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 971d60b410a..a7b58351839 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -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 &filename_extensions () const override + { + static const std::vector 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_table; void add_filename_language (const char *ext, enum language lang) { + gdb_assert (ext != nullptr); filename_language_table.emplace_back (ext, lang); }