]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove la_error
authorTom Tromey <tom@tromey.com>
Sat, 2 Jun 2018 05:02:37 +0000 (23:02 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 18 Jun 2018 18:29:15 +0000 (12:29 -0600)
While working on the parser code, I noticed that yyerror is exported
from each parser.  It is used by this code in parse.c:

   TRY
     {
       if (lang->la_parser (&ps))
         lang->la_error (NULL);
     }

However, it seems to me that la_error will never be called here,
because in every case, la_parser throws an exception on error -- each
implementation of yyerror just calls error.

So, this patch removes la_error and makes all the yyerror functions
static.  This is handy primarily because it makes it simpler to make
the expression parsers pure.

Tested by the buildbot.

gdb/ChangeLog
2018-06-18  Tom Tromey  <tom@tromey.com>

* rust-lang.h (rust_yyerror): Don't declare.
* rust-lang.c (rust_language_defn): Update.
* rust-exp.y (yyerror): Now static.
* parse.c (parse_exp_in_context_1): Update.
* p-lang.h (p_yyerror): Don't declare.
* p-lang.c (p_language_defn): Update.
* p-exp.y (yyerror): Now static.
* opencl-lang.c (opencl_language_defn): Update.
* objc-lang.c (objc_language_defn): Update.
* m2-lang.h (m2_yyerror): Don't declare.
* m2-lang.c (m2_language_defn): Update.
* m2-exp.y (yyerror): Now static.
* language.h (struct language_defn) <la_error>: Remove.
* language.c (unk_lang_error): Remove.
(unknown_language_defn, auto_language_defn): Remove.
* go-lang.h (go_yyerror): Don't declare.
* go-lang.c (go_language_defn): Update.
* go-exp.y (yyerror): Now static.
* f-lang.h (f_yyerror): Don't declare.
* f-lang.c (f_language_defn): Update.
* f-exp.y (yyerror): Now static.
* d-lang.h (d_yyerror): Don't declare.
* d-lang.c (d_language_defn): Update.
* d-exp.y (yyerror): Now static.
* c-lang.h (c_yyerror): Don't declare.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Update.
* c-exp.y (yyerror): Now static.
* ada-lang.h (ada_yyerror): Don't declare.
* ada-lang.c (ada_language_defn): Update.
* ada-exp.y (yyerror): Now static.

30 files changed:
gdb/ChangeLog
gdb/ada-exp.y
gdb/ada-lang.c
gdb/ada-lang.h
gdb/c-exp.y
gdb/c-lang.c
gdb/c-lang.h
gdb/d-exp.y
gdb/d-lang.c
gdb/d-lang.h
gdb/f-exp.y
gdb/f-lang.c
gdb/f-lang.h
gdb/go-exp.y
gdb/go-lang.c
gdb/go-lang.h
gdb/language.c
gdb/language.h
gdb/m2-exp.y
gdb/m2-lang.c
gdb/m2-lang.h
gdb/objc-lang.c
gdb/opencl-lang.c
gdb/p-exp.y
gdb/p-lang.c
gdb/p-lang.h
gdb/parse.c
gdb/rust-exp.y
gdb/rust-lang.c
gdb/rust-lang.h

index 4217b08d9c18d952e1f67d07f85c9caa1e4fc15b..f80eda0c39833178a5d305073ebb6e0de44cb2a0 100644 (file)
@@ -1,3 +1,37 @@
+2018-06-18  Tom Tromey  <tom@tromey.com>
+
+       * rust-lang.h (rust_yyerror): Don't declare.
+       * rust-lang.c (rust_language_defn): Update.
+       * rust-exp.y (yyerror): Now static.
+       * parse.c (parse_exp_in_context_1): Update.
+       * p-lang.h (p_yyerror): Don't declare.
+       * p-lang.c (p_language_defn): Update.
+       * p-exp.y (yyerror): Now static.
+       * opencl-lang.c (opencl_language_defn): Update.
+       * objc-lang.c (objc_language_defn): Update.
+       * m2-lang.h (m2_yyerror): Don't declare.
+       * m2-lang.c (m2_language_defn): Update.
+       * m2-exp.y (yyerror): Now static.
+       * language.h (struct language_defn) <la_error>: Remove.
+       * language.c (unk_lang_error): Remove.
+       (unknown_language_defn, auto_language_defn): Remove.
+       * go-lang.h (go_yyerror): Don't declare.
+       * go-lang.c (go_language_defn): Update.
+       * go-exp.y (yyerror): Now static.
+       * f-lang.h (f_yyerror): Don't declare.
+       * f-lang.c (f_language_defn): Update.
+       * f-exp.y (yyerror): Now static.
+       * d-lang.h (d_yyerror): Don't declare.
+       * d-lang.c (d_language_defn): Update.
+       * d-exp.y (yyerror): Now static.
+       * c-lang.h (c_yyerror): Don't declare.
+       * c-lang.c (c_language_defn, cplus_language_defn)
+       (asm_language_defn, minimal_language_defn): Update.
+       * c-exp.y (yyerror): Now static.
+       * ada-lang.h (ada_yyerror): Don't declare.
+       * ada-lang.c (ada_language_defn): Update.
+       * ada-exp.y (yyerror): Now static.
+
 2018-06-18  Alan Hayward  <alan.hayward@arm.com>
 
        * aarch64-linux-nat.c (fetch_sveregs_from_thread): New function.
index 864f9bc754b81913f6a74439de6a12da0bd8ba61..6dc4865a595f662987c137a1c11e8de43fe58134 100644 (file)
@@ -77,7 +77,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (const char *);
+static void yyerror (const char *);
 
 static void write_int (struct parser_state *, LONGEST, struct type *);
 
@@ -742,7 +742,7 @@ ada_parse (struct parser_state *par_state)
   return yyparse ();
 }
 
-void
+static void
 yyerror (const char *msg)
 {
   error (_("Error in expression, near `%s'."), lexptr);
index b34efa919ea356d57f4c2fd5dbc9afa960b6edb4..298adf7a8dc520b5c58de629437bd11e4f52e4d4 100644 (file)
@@ -14360,7 +14360,6 @@ extern const struct language_defn ada_language_defn = {
   ada_extensions,
   &ada_exp_descriptor,
   parse,
-  ada_yyerror,
   resolve,
   ada_printchar,                /* Print a character constant */
   ada_printstr,                 /* Function to print string constant */
index 8e7bd50cd2b4487f08375ca1ed442fd7a109b971..9dcc5de355312deed42519ad402e607aa7bbf1b6 100644 (file)
@@ -166,8 +166,6 @@ extern int ada_get_field_index (const struct type *type,
 
 extern int ada_parse (struct parser_state *);    /* Defined in ada-exp.y */
 
-extern void ada_yyerror (const char *); /* Defined in ada-exp.y */
-
                         /* Defined in ada-typeprint.c */
 extern void ada_print_type (struct type *, const char *, struct ui_file *, int,
                             int, const struct type_print_options *);
index ae31af52dfb89e71c6de9b84dc79a0244ac54a3b..a9ccbdcb65e1f8428e1fd0d4d165e5f1dc283cc7 100644 (file)
@@ -70,7 +70,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (const char *);
+static void yyerror (const char *);
 
 static int type_aggregate_p (struct type *);
 
@@ -3334,11 +3334,11 @@ c_print_token (FILE *file, int type, YYSTYPE value)
 
 #endif
 
-void
+static void
 yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, lexptr);
 }
index 6bbb47095713ea4513c7b01ad386de2edeec9d13..1c283a8b9632aa589a1a4c624722853be94047cd 100644 (file)
@@ -843,7 +843,6 @@ extern const struct language_defn c_language_defn =
   c_extensions,
   &exp_descriptor_c,
   c_parse,
-  c_yyerror,
   null_post_parser,
   c_printchar,                 /* Print a character constant */
   c_printstr,                  /* Function to print string constant */
@@ -989,7 +988,6 @@ extern const struct language_defn cplus_language_defn =
   cplus_extensions,
   &exp_descriptor_c,
   c_parse,
-  c_yyerror,
   null_post_parser,
   c_printchar,                 /* Print a character constant */
   c_printstr,                  /* Function to print string constant */
@@ -1044,7 +1042,6 @@ extern const struct language_defn asm_language_defn =
   asm_extensions,
   &exp_descriptor_c,
   c_parse,
-  c_yyerror,
   null_post_parser,
   c_printchar,                 /* Print a character constant */
   c_printstr,                  /* Function to print string constant */
@@ -1099,7 +1096,6 @@ extern const struct language_defn minimal_language_defn =
   NULL,
   &exp_descriptor_c,
   c_parse,
-  c_yyerror,
   null_post_parser,
   c_printchar,                 /* Print a character constant */
   c_printstr,                  /* Function to print string constant */
index a250fb34a6bf01b66b6fe1bfe6022881a0bbc38d..e961826407e63c03c1d5fa5015ae8d04e7fd6f88 100644 (file)
@@ -63,8 +63,6 @@ DEF_ENUM_FLAGS_TYPE (enum c_string_type_values, c_string_type);
 
 extern int c_parse (struct parser_state *);
 
-extern void c_yyerror (const char *);
-
 extern int c_parse_escape (const char **, struct obstack *);
 
 /* Defined in c-typeprint.c */
index 508927bb00f0858484e274178769fc2bbcd9a398..74e4b637d0dde17d9960341dcb6dfa39d6ac1cb9 100644 (file)
@@ -69,7 +69,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (const char *);
+static void yyerror (const char *);
 
 static int type_aggregate_p (struct type *);
 
@@ -1627,12 +1627,12 @@ d_parse (struct parser_state *par_state)
   return yyparse ();
 }
 
-void
+static void
 yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, lexptr);
 }
 
index 688ae981bb1bbdc2afe3788cac28bcbedcf8a176..fe792d855827d983a48813bc4d500a16ae8cf3bf 100644 (file)
@@ -216,7 +216,6 @@ extern const struct language_defn d_language_defn =
   d_extensions,
   &exp_descriptor_c,
   d_parse,
-  d_yyerror,
   null_post_parser,
   c_printchar,                 /* Print a character constant.  */
   c_printstr,                  /* Function to print string constant.  */
index 391ea8665bb9bd11f1af918b4f692372c570faa1..e31c76238a941e3220b82775248154cb4981be1d 100644 (file)
@@ -58,8 +58,6 @@ struct builtin_d_type
 
 extern int d_parse (struct parser_state *);
 
-extern void d_yyerror (const char *);
-
 /* Defined in d-lang.c  */
 
 extern const char *d_main_name (void);
index e39f68417c2d7e40bb309098ba95f32fc0a6fa60..5ef16125f5dad844820d2c3280b1d57b6247879a 100644 (file)
@@ -72,7 +72,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (const char *);
+static void yyerror (const char *);
 
 static void growbuf_by_size (int);
 
@@ -1216,11 +1216,11 @@ f_parse (struct parser_state *par_state)
   return yyparse ();
 }
 
-void
+static void
 yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, lexptr);
 }
index 81922f73fb6a6edc3a273277fd4aeab9946325d5..1b7994fbd3f059bbdb5b3c82117666d246775612 100644 (file)
@@ -257,7 +257,6 @@ extern const struct language_defn f_language_defn =
   f_extensions,
   &exp_descriptor_standard,
   f_parse,                     /* parser */
-  f_yyerror,                   /* parser error function */
   null_post_parser,
   f_printchar,                 /* Print character constant */
   f_printstr,                  /* function to print string constant */
index e9d0f3a857d16fc94b71b0860343b68c18bc5e70..d60cf1b95ff0ca6c3cf59e83fcd68720ebbfe6a0 100644 (file)
@@ -25,8 +25,6 @@ struct parser_state;
 
 extern int f_parse (struct parser_state *);
 
-extern void f_yyerror (const char *);  /* Defined in f-exp.y */
-
 extern void f_print_type (struct type *, const char *, struct ui_file *, int,
                          int, const struct type_print_options *);
 
index 936d507c374957a497e350bb0b4ffb5fd9076684..47570d59111bcd7851aa807371e897860fc9849b 100644 (file)
@@ -81,7 +81,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (const char *);
+static void yyerror (const char *);
 
 %}
 
@@ -1578,11 +1578,11 @@ go_parse (struct parser_state *par_state)
   return yyparse ();
 }
 
-void
+static void
 yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, lexptr);
 }
index 60ab2f3dc3d57b4f83af02e17e7ffc769ce5e1e4..49a6b9efca0a6d1bb38b24fab367b25138f38208 100644 (file)
@@ -577,7 +577,6 @@ extern const struct language_defn go_language_defn =
   NULL,
   &exp_descriptor_c,
   go_parse,
-  go_yyerror,
   null_post_parser,
   c_printchar,                 /* Print a character constant.  */
   c_printstr,                  /* Function to print string constant.  */
index 84af9389e7c8c4d066e6c4e18446a9d7e3e35684..963ee2f91a7ff8c374bc885afed09a39c620c9a0 100644 (file)
@@ -60,8 +60,6 @@ enum go_type
 
 extern int go_parse (struct parser_state *);
 
-extern void go_yyerror (const char *);
-
 /* Defined in go-lang.c.  */
 
 extern const char *go_main_name (void);
index 22199e0c0d673dec406f77aac8eed1e82877ccf2..44bbeb4cb3b91978aded56c1b7cc7bc4974913e6 100644 (file)
@@ -46,8 +46,6 @@
 #include "c-lang.h"
 #include <algorithm>
 
-static void unk_lang_error (const char *);
-
 static int unk_lang_parser (struct parser_state *);
 
 static void set_range_case (void);
@@ -750,12 +748,6 @@ unk_lang_parser (struct parser_state *ps)
   return 1;
 }
 
-static void
-unk_lang_error (const char *msg)
-{
-  error (_("Attempted to parse an expression with unknown language"));
-}
-
 static void
 unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
                    int quoter)
@@ -852,7 +844,6 @@ const struct language_defn unknown_language_defn =
   NULL,
   &exp_descriptor_standard,
   unk_lang_parser,
-  unk_lang_error,
   null_post_parser,
   unk_lang_printchar,          /* Print character constant */
   unk_lang_printstr,
@@ -904,7 +895,6 @@ const struct language_defn auto_language_defn =
   NULL,
   &exp_descriptor_standard,
   unk_lang_parser,
-  unk_lang_error,
   null_post_parser,
   unk_lang_printchar,          /* Print character constant */
   unk_lang_printstr,
index 029de4a7abb31a5bcae07ebb22b8640862bc643a..e103a9366185a0670e077ea74a7332a0c3c11e85 100644 (file)
@@ -172,10 +172,6 @@ struct language_defn
 
     int (*la_parser) (struct parser_state *);
 
-    /* Parser error function.  */
-
-    void (*la_error) (const char *);
-
     /* Given an expression *EXPP created by prefixifying the result of
        la_parser, perform any remaining processing necessary to complete
        its translation.  *EXPP may change; la_post_parser is responsible 
index 2cf026c77a5c8c257e102af418d005cc8013f2f7..2cf2bb536355d915a6b20a7dc5f36680ad360314 100644 (file)
@@ -65,7 +65,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (const char *);
+static void yyerror (const char *);
 
 static int parse_number (int);
 
@@ -1038,11 +1038,11 @@ m2_parse (struct parser_state *par_state)
   return yyparse ();
 }
 
-void
+static void
 yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, lexptr);
 }
index 6e6434b846d0620fa7f1a75691c482fee0999b9b..d849f8c306da7a470f9e13f33421c07c9817ec37 100644 (file)
@@ -365,7 +365,6 @@ extern const struct language_defn m2_language_defn =
   NULL,
   &exp_descriptor_modula2,
   m2_parse,                    /* parser */
-  m2_yyerror,                  /* parser error function */
   null_post_parser,
   m2_printchar,                        /* Print character constant */
   m2_printstr,                 /* function to print string constant */
index d7e1aec67305ca4b330e86de0d3694e4bfb7903c..467b984b39f68196f36ae3f14a1cba3dd26030bf 100644 (file)
@@ -22,8 +22,6 @@ struct parser_state;
 
 extern int m2_parse (struct parser_state *); /* Defined in m2-exp.y */
 
-extern void m2_yyerror (const char *); /* Defined in m2-exp.y */
-
 /* Defined in m2-typeprint.c */
 extern void m2_print_type (struct type *, const char *, struct ui_file *, int,
                           int, const struct type_print_options *);
index f8b28b21d24917c8e0903d9b4a306e3bc5988b81..6da8af1a46159c4fabad11f39105d4f54a028d22 100644 (file)
@@ -376,7 +376,6 @@ extern const struct language_defn objc_language_defn = {
   objc_extensions,
   &exp_descriptor_standard,
   c_parse,
-  c_yyerror,
   null_post_parser,
   c_printchar,                /* Print a character constant */
   c_printstr,                 /* Function to print string constant */
index 8af63f76206f3df69ffb6c71334890265182092d..6bfdbde305418e8cc0f25cac41c18ccf57c34254 100644 (file)
@@ -1053,7 +1053,6 @@ extern const struct language_defn opencl_language_defn =
   NULL,
   &exp_descriptor_opencl,
   c_parse,
-  c_yyerror,
   null_post_parser,
   c_printchar,                 /* Print a character constant */
   c_printstr,                  /* Function to print string constant */
index d527b776d9f14ccfd943adc881f88b2eae29d333..9ffaccdbe3ff765c8e3a8da15eec5cd82ff84393 100644 (file)
@@ -72,7 +72,7 @@ int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (const char *);
+static void yyerror (const char *);
 
 static char *uptok (const char *, int);
 %}
@@ -1722,11 +1722,11 @@ pascal_parse (struct parser_state *par_state)
   return yyparse ();
 }
 
-void
+static void
 yyerror (const char *msg)
 {
   if (prev_lexptr)
     lexptr = prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, lexptr);
 }
index 3ff7f5694f40edd20e853353dcd6c869340dfa2a..56dfa19ce07a098988290ee5105e06011ca376ef 100644 (file)
@@ -427,7 +427,6 @@ extern const struct language_defn pascal_language_defn =
   p_extensions,
   &exp_descriptor_standard,
   pascal_parse,
-  pascal_yyerror,
   null_post_parser,
   pascal_printchar,            /* Print a character constant */
   pascal_printstr,             /* Function to print string constant */
index 61ee752fe738fb38b6dd54cd163927a04126315f..a3313c2c4492c3515dbfaaa44aa3df293939a0be 100644 (file)
@@ -27,8 +27,6 @@ extern const char *pascal_main_name (void);
 
 extern int pascal_parse (struct parser_state *); /* Defined in p-exp.y */
 
-extern void pascal_yyerror (const char *);     /* Defined in p-exp.y */
-
 /* Defined in p-typeprint.c */
 extern void pascal_print_type (struct type *, const char *, struct ui_file *,
                               int, int, const struct type_print_options *);
index 193abe853f4bb543a037f741aea8eed2c55cd2b8..acb08f243639b47b51031dc0579a42ad92923222 100644 (file)
@@ -1202,8 +1202,7 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
 
   TRY
     {
-      if (lang->la_parser (&ps))
-        lang->la_error (NULL);
+      lang->la_parser (&ps);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
index 9f21498d4c9aa5d5584189ac2ba76f349b8caabf..b60997681ae4d7c81b8be972da65018383e73a21 100644 (file)
@@ -70,6 +70,7 @@ struct set_field
 typedef std::vector<set_field> rust_set_vector;
 
 static int rustyylex (void);
+static void rustyyerror (const char *msg);
 static void rust_push_back (char c);
 static const char *rust_copy_name (const char *, int);
 static struct stoken rust_concat3 (const char *, const char *, const char *);
@@ -2538,11 +2539,11 @@ rust_parse (struct parser_state *state)
 
 /* The parser error handler.  */
 
-void
+static void
 rustyyerror (const char *msg)
 {
   const char *where = prev_lexptr ? prev_lexptr : lexptr;
-  error (_("%s in expression, near `%s'."), (msg ? msg : "Error"), where);
+  error (_("%s in expression, near `%s'."), msg, where);
 }
 
 \f
index 167f35398eb4687c782f74e6b680532a1f051d22..d9807d0ac1a41ee5b9e883cd5b684a318b50f6eb 100644 (file)
@@ -2013,7 +2013,6 @@ extern const struct language_defn rust_language_defn =
   rust_extensions,
   &exp_descriptor_rust,
   rust_parse,
-  rustyyerror,
   null_post_parser,
   rust_printchar,              /* Print a character constant */
   rust_printstr,               /* Function to print string constant */
index ce30e3327616ffa0de87e2a7a9e2b98c0e23810d..f81f47fa8d21f6fe66c987024ae03a904e1c88fb 100644 (file)
@@ -26,9 +26,6 @@ struct type;
 /* The la_parser implementation for Rust.  */
 extern int rust_parse (struct parser_state *);
 
-/* The la_error implementation for Rust.  */
-extern void rustyyerror (const char *);
-
 /* Return true if TYPE is a tuple type; otherwise false.  */
 extern bool rust_tuple_type_p (struct type *type);