Move filename extensions into language_defn
authorTom Tromey <tom@tromey.com>
Thu, 26 May 2016 16:33:28 +0000 (10:33 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 24 Jun 2016 03:11:47 +0000 (21:11 -0600)
This moves filename extensions from a function in symfile.c out to
each language_defn.  I think this is an improvement because it means
less digging around when writing a new language port.

2016-06-23  Tom Tromey  <tom@tromey.com>

* ada-lang.c (ada_extensions): New array.
(ada_language_defn): Use it.
* c-lang.c (c_extensions): New array.
(c_language_defn): Use it.
(cplus_extensions): New array.
(cplus_language_defn): Use it.
(asm_extensions): New array.
(asm_language_defn): Use it.
(minimal_language_defn): Update.
* d-lang.c (d_extensions): New array.
(d_language_defn): Use it.
* f-lang.c (f_extensions): New array.
(f_language_defn): Use it.
* go-lang.c (go_language_defn): Update.
* jv-lang.c (java_extensions): New array.
(java_language_defn): Use it.
* language.c (add_language): Call add_filename_language.
(unknown_language_defn, auto_language_defn, local_language_defn):
Update.
* language.h (struct language_defn) <la_filename_extensions>: New
field.
* m2-lang.c (m2_language_defn): Update.
* objc-lang.c (objc_extensions): New array.
(objc_language_defn): Use it.
* opencl-lang.c (opencl_language_defn): Update.
* p-lang.c (p_extensions): New array.
(pascal_language_defn): Use it.
* rust-lang.c (rust_extensions): New array.
(rust_language_defn): Use it.
* symfile.c (add_filename_language): No longer static.  Make "ext"
const.
(init_filename_language_table): Remove.
(_initialize_symfile): Update.
* symfile.h (add_filename_language): Declare.

16 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/jv-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
gdb/symfile.h

index 69fcc3b29987ca9e619746db024048f4cb40944a..222410934f70f3e7fe7dc87e0b0e62c28102d3a7 100644 (file)
@@ -1,3 +1,40 @@
+2016-06-23  Tom Tromey  <tom@tromey.com>
+
+       * ada-lang.c (ada_extensions): New array.
+       (ada_language_defn): Use it.
+       * c-lang.c (c_extensions): New array.
+       (c_language_defn): Use it.
+       (cplus_extensions): New array.
+       (cplus_language_defn): Use it.
+       (asm_extensions): New array.
+       (asm_language_defn): Use it.
+       (minimal_language_defn): Update.
+       * d-lang.c (d_extensions): New array.
+       (d_language_defn): Use it.
+       * f-lang.c (f_extensions): New array.
+       (f_language_defn): Use it.
+       * go-lang.c (go_language_defn): Update.
+       * jv-lang.c (java_extensions): New array.
+       (java_language_defn): Use it.
+       * language.c (add_language): Call add_filename_language.
+       (unknown_language_defn, auto_language_defn, local_language_defn):
+       Update.
+       * language.h (struct language_defn) <la_filename_extensions>: New
+       field.
+       * m2-lang.c (m2_language_defn): Update.
+       * objc-lang.c (objc_extensions): New array.
+       (objc_language_defn): Use it.
+       * opencl-lang.c (opencl_language_defn): Update.
+       * p-lang.c (p_extensions): New array.
+       (pascal_language_defn): Use it.
+       * rust-lang.c (rust_extensions): New array.
+       (rust_language_defn): Use it.
+       * symfile.c (add_filename_language): No longer static.  Make "ext"
+       const.
+       (init_filename_language_table): Remove.
+       (_initialize_symfile): Update.
+       * symfile.h (add_filename_language): Declare.
+
 2016-06-23  Tom Tromey  <tom@tromey.com>
 
        * symfile.c (filename_language_table): Now a VEC.
index 3c5ab26b405870d190404c0710d64ca9b4a2e23b..796dc6536ef0d217c9d605304d98a9d9879f9c16 100644 (file)
@@ -14054,6 +14054,11 @@ ada_read_var_value (struct symbol *var, const struct block *var_block,
   return default_read_var_value (var, var_block, frame);
 }
 
+static const char *ada_extensions[] =
+{
+  ".adb", ".ads", ".a", ".ada", ".dg", NULL
+};
+
 const struct language_defn ada_language_defn = {
   "ada",                        /* Language name */
   "Ada",
@@ -14063,6 +14068,7 @@ const struct language_defn ada_language_defn = {
                                    that's not quite what this means.  */
   array_row_major,
   macro_expansion_no,
+  ada_extensions,
   &ada_exp_descriptor,
   parse,
   ada_yyerror,
index 8192e97942f4e24647d8e486944aadf2b65f1aa2..9ccb87f032ceb8164106583904a503d958539f02 100644 (file)
@@ -824,6 +824,11 @@ const struct exp_descriptor exp_descriptor_c =
   evaluate_subexp_c
 };
 
+static const char *c_extensions[] =
+{
+  ".c", NULL
+};
+
 const struct language_defn c_language_defn =
 {
   "c",                         /* Language name */
@@ -833,6 +838,7 @@ const struct language_defn c_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
+  c_extensions,
   &exp_descriptor_c,
   c_parse,
   c_yyerror,
@@ -951,6 +957,11 @@ cplus_language_arch_info (struct gdbarch *gdbarch,
   lai->bool_type_default = builtin->builtin_bool;
 }
 
+static const char *cplus_extensions[] =
+{
+  ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", NULL
+};
+
 const struct language_defn cplus_language_defn =
 {
   "c++",                       /* Language name */
@@ -960,6 +971,7 @@ const struct language_defn cplus_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
+  cplus_extensions,
   &exp_descriptor_c,
   c_parse,
   c_yyerror,
@@ -996,6 +1008,11 @@ const struct language_defn cplus_language_defn =
   LANG_MAGIC
 };
 
+static const char *asm_extensions[] =
+{
+  ".s", ".sx", ".S", NULL
+};
+
 const struct language_defn asm_language_defn =
 {
   "asm",                       /* Language name */
@@ -1005,6 +1022,7 @@ const struct language_defn asm_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
+  asm_extensions,
   &exp_descriptor_c,
   c_parse,
   c_yyerror,
@@ -1055,6 +1073,7 @@ const struct language_defn minimal_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
+  NULL,
   &exp_descriptor_c,
   c_parse,
   c_yyerror,
index 0075fea9f602ba585eb7a894fc234b495ab262dc..b25136dfb22fc5ec9a383132e8bbcd541022decf 100644 (file)
@@ -190,6 +190,11 @@ d_language_arch_info (struct gdbarch *gdbarch,
   lai->bool_type_default = builtin->builtin_bool;
 }
 
+static const char *d_extensions[] =
+{
+  ".d", NULL
+};
+
 static const struct language_defn d_language_defn =
 {
   "d",
@@ -199,6 +204,7 @@ static const struct language_defn d_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
+  d_extensions,
   &exp_descriptor_c,
   d_parse,
   d_yyerror,
index 22c308f92128ed0593d1d119abf021fb0b08b139..719083bec16a71fdeb9758508fa1356de94f45b6 100644 (file)
@@ -235,6 +235,13 @@ f_make_symbol_completion_list (const char *text, const char *word,
   return default_make_symbol_completion_list_break_on (text, word, ":", code);
 }
 
+static const char *f_extensions[] =
+{
+  ".f", ".F", ".for", ".FOR", ".ftn", ".FTN", ".fpp", ".FPP",
+  ".f90", ".F90", ".f95", ".F95", ".f03", ".F03", ".f08", ".F08",
+  NULL
+};
+
 const struct language_defn f_language_defn =
 {
   "fortran",
@@ -244,6 +251,7 @@ const struct language_defn f_language_defn =
   case_sensitive_off,
   array_column_major,
   macro_expansion_no,
+  f_extensions,
   &exp_descriptor_standard,
   f_parse,                     /* parser */
   f_yyerror,                   /* parser error function */
index 84a366ac5ac5a9310a6e95c9ccf9f00dc9d547c4..15ca78bc8b76a124ffead6c889df829286c9c50f 100644 (file)
@@ -565,6 +565,7 @@ static const struct language_defn go_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
+  NULL,
   &exp_descriptor_c,
   go_parse,
   go_yyerror,
index 14aa0e0295c90f22b1d0090edcac9873fe3bfbc2..797a7f0833873a4d1a7aaa6aa0e3903af09da746 100644 (file)
@@ -1162,6 +1162,11 @@ const struct exp_descriptor exp_descriptor_java =
   evaluate_subexp_java
 };
 
+static const char *java_extensions[] =
+{
+  ".java", ".class", NULL
+};
+
 const struct language_defn java_language_defn =
 {
   "java",                      /* Language name */
@@ -1171,6 +1176,7 @@ const struct language_defn java_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
+  java_extensions,
   &exp_descriptor_java,
   java_parse,
   java_yyerror,
index 84697540279b5f507217ebdcc7c6194740db0242..02e21ca18b300ef7d2a8d5e0be27d4e9b491b607 100644 (file)
@@ -575,6 +575,16 @@ add_language (const struct language_defn *lang)
     language_names[i] = languages[i]->la_name;
   language_names[i] = NULL;
 
+  /* Add the filename extensions.  */
+  if (lang->la_filename_extensions != NULL)
+    {
+      int i;
+
+      for (i = 0; lang->la_filename_extensions[i] != NULL; ++i)
+       add_filename_language (lang->la_filename_extensions[i],
+                              lang->la_language);
+    }
+
   /* Build the "help set language" docs.  */
   tmp_stream = mem_fileopen ();
 
@@ -815,6 +825,7 @@ const struct language_defn unknown_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
+  NULL,
   &exp_descriptor_standard,
   unk_lang_parser,
   unk_lang_error,
@@ -862,6 +873,7 @@ const struct language_defn auto_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
+  NULL,
   &exp_descriptor_standard,
   unk_lang_parser,
   unk_lang_error,
@@ -907,6 +919,7 @@ const struct language_defn local_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
+  NULL,
   &exp_descriptor_standard,
   unk_lang_parser,
   unk_lang_error,
index 49243a9e4a0fedd15188135982c73d544d33cc7e..d57c60e8804ce3a1aea954db0fd89522302433a3 100644 (file)
@@ -164,6 +164,13 @@ struct language_defn
     /* 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.  */
 
index 917da15d8084da571febdc0c52c31e4e81e89071..4626bfc6e79a7239b4eef232c48b10eee5cb44d6 100644 (file)
@@ -363,6 +363,7 @@ const struct language_defn m2_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
+  NULL,
   &exp_descriptor_modula2,
   m2_parse,                    /* parser */
   m2_yyerror,                  /* parser error function */
index 34f90e872eac1fb16a9c189f8cf5661fc7752268..fe3e082a8ce0b0bbe4a14cae9d4d72990a071988 100644 (file)
@@ -350,6 +350,11 @@ static const struct op_print objc_op_print_tab[] =
     {NULL, OP_NULL, PREC_NULL, 0}
 };
 
+static const char *objc_extensions[] =
+{
+  ".m", NULL
+};
+
 const struct language_defn objc_language_defn = {
   "objective-c",               /* Language name */
   "Objective-C",
@@ -358,6 +363,7 @@ const struct language_defn objc_language_defn = {
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
+  objc_extensions,
   &exp_descriptor_standard,
   c_parse,
   c_yyerror,
index 767d3bc73e0236dbb2f512a5dce466ae77317fe6..74651bcfbddfa1d21e7901c43728872001e99c81 100644 (file)
@@ -1052,6 +1052,7 @@ const struct language_defn opencl_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
+  NULL,
   &exp_descriptor_opencl,
   c_parse,
   c_yyerror,
index 8ff2682bf26de85c86aab94893e1f938c77146fd..0897be241144245e6d402b1516bfc995a78bb261 100644 (file)
@@ -412,6 +412,11 @@ pascal_language_arch_info (struct gdbarch *gdbarch,
   lai->bool_type_default = builtin->builtin_bool;
 }
 
+static const char *p_extensions[] =
+{
+  ".pas", ".p", ".pp", NULL
+};
+
 const struct language_defn pascal_language_defn =
 {
   "pascal",                    /* Language name */
@@ -421,6 +426,7 @@ const struct language_defn pascal_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
+  p_extensions,
   &exp_descriptor_standard,
   pascal_parse,
   pascal_yyerror,
index 5df99ced28d2883e0188260d0bff151b08b0a27f..36dab6788df5447c3528107a3c71be33cc7c0e61 100644 (file)
@@ -1998,6 +1998,11 @@ static const struct exp_descriptor exp_descriptor_rust =
   rust_evaluate_subexp
 };
 
+static const char *rust_extensions[] =
+{
+  ".rs", NULL
+};
+
 static const struct language_defn rust_language_defn =
 {
   "rust",
@@ -2007,6 +2012,7 @@ static const struct language_defn rust_language_defn =
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
+  rust_extensions,
   &exp_descriptor_rust,
   rust_parse,
   rustyyerror,
index f7f56c600e478889123d9ebac6fcc9b5a71a745b..d29e96c2579fe6736960a82bf647d8831ea06f5e 100644 (file)
@@ -114,12 +114,8 @@ static int simple_read_overlay_table (void);
 
 static int simple_overlay_update_1 (struct obj_section *);
 
-static void add_filename_language (char *ext, enum language lang);
-
 static void info_ext_lang_command (char *args, int from_tty);
 
-static void init_filename_language_table (void);
-
 static void symfile_find_segment_sections (struct objfile *objfile);
 
 void _initialize_symfile (void);
@@ -2719,8 +2715,10 @@ DEF_VEC_O (filename_language);
 
 static VEC (filename_language) *filename_language_table;
 
-static void
-add_filename_language (char *ext, enum language lang)
+/* See symfile.h.  */
+
+void
+add_filename_language (const char *ext, enum language lang)
 {
   filename_language entry;
 
@@ -2818,54 +2816,6 @@ info_ext_lang_command (char *args, int from_tty)
     printf_filtered ("\t%s\t- %s\n", entry->ext, language_str (entry->lang));
 }
 
-static void
-init_filename_language_table (void)
-{
-  /* Protect against repetition.  */
-  if (VEC_empty (filename_language, filename_language_table))
-    {
-      add_filename_language (".c", language_c);
-      add_filename_language (".d", language_d);
-      add_filename_language (".C", language_cplus);
-      add_filename_language (".cc", language_cplus);
-      add_filename_language (".cp", language_cplus);
-      add_filename_language (".cpp", language_cplus);
-      add_filename_language (".cxx", language_cplus);
-      add_filename_language (".c++", language_cplus);
-      add_filename_language (".java", language_java);
-      add_filename_language (".class", language_java);
-      add_filename_language (".m", language_objc);
-      add_filename_language (".f", language_fortran);
-      add_filename_language (".F", language_fortran);
-      add_filename_language (".for", language_fortran);
-      add_filename_language (".FOR", language_fortran);
-      add_filename_language (".ftn", language_fortran);
-      add_filename_language (".FTN", language_fortran);
-      add_filename_language (".fpp", language_fortran);
-      add_filename_language (".FPP", language_fortran);
-      add_filename_language (".f90", language_fortran);
-      add_filename_language (".F90", language_fortran);
-      add_filename_language (".f95", language_fortran);
-      add_filename_language (".F95", language_fortran);
-      add_filename_language (".f03", language_fortran);
-      add_filename_language (".F03", language_fortran);
-      add_filename_language (".f08", language_fortran);
-      add_filename_language (".F08", language_fortran);
-      add_filename_language (".s", language_asm);
-      add_filename_language (".sx", language_asm);
-      add_filename_language (".S", language_asm);
-      add_filename_language (".pas", language_pascal);
-      add_filename_language (".p", language_pascal);
-      add_filename_language (".pp", language_pascal);
-      add_filename_language (".adb", language_ada);
-      add_filename_language (".ads", language_ada);
-      add_filename_language (".a", language_ada);
-      add_filename_language (".ada", language_ada);
-      add_filename_language (".dg", language_ada);
-      add_filename_language (".rs", language_rust);
-    }
-}
-
 enum language
 deduce_language_from_filename (const char *filename)
 {
@@ -4018,7 +3968,6 @@ A load OFFSET may also be given."), &cmdlist);
           _("Read the overlay mapping state from the target."), &overlaylist);
 
   /* Filename extension to source language lookup table: */
-  init_filename_language_table ();
   add_setshow_string_noescape_cmd ("extension-language", class_files,
                                   &ext_args, _("\
 Set mapping between filename extension and source language."), _("\
index c538e0598a203561d120ebc5a8c19299245da5b5..a11c48aa4fa0373dc38bb52763210e63b709f74f 100644 (file)
@@ -440,6 +440,11 @@ extern void clear_symtab_users (int add_flags);
 
 extern enum language deduce_language_from_filename (const char *);
 
+/* Map the filename extension EXT to the language LANG.  Any previous
+   association of EXT will be removed.  EXT will be copied by this
+   function.  */
+extern void add_filename_language (const char *ext, enum language lang);
+
 /* This enum encodes bit-flags passed as ADD_FLAGS parameter to
    symbol_file_add, etc.  */