From patchwork Sun Jun 3 22:28:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27610 Received: (qmail 109530 invoked by alias); 3 Jun 2018 22:28:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 109521 invoked by uid 89); 3 Jun 2018 22:28:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1668, sk:parse_e, sk:type_pr, UD:c-lang.h X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (50.116.127.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 03 Jun 2018 22:28:31 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 50ABB8D3C for ; Sun, 3 Jun 2018 17:28:30 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id PbUEfikeG79N3PbUEfDIzw; Sun, 03 Jun 2018 17:28:30 -0500 X-Authority-Reason: nr=8 Received: from 75-166-42-107.hlrn.qwest.net ([75.166.42.107]:35666 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fPbUD-000mfa-Vb; Sun, 03 Jun 2018 17:28:30 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Remove la_error Date: Sun, 3 Jun 2018 16:28:28 -0600 Message-Id: <20180603222828.19224-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fPbUD-000mfa-Vb X-Source-Sender: 75-166-42-107.hlrn.qwest.net (bapiya.Home) [75.166.42.107]:35666 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes 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-03 Tom Tromey * 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) : 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. --- gdb/ChangeLog | 34 ++++++++++++++++++++++++++++++++++ gdb/ada-exp.y | 4 ++-- gdb/ada-lang.c | 1 - gdb/ada-lang.h | 2 -- gdb/c-exp.y | 6 +++--- gdb/c-lang.c | 4 ---- gdb/c-lang.h | 2 -- gdb/d-exp.y | 6 +++--- gdb/d-lang.c | 1 - gdb/d-lang.h | 2 -- gdb/f-exp.y | 6 +++--- gdb/f-lang.c | 1 - gdb/f-lang.h | 2 -- gdb/go-exp.y | 6 +++--- gdb/go-lang.c | 1 - gdb/go-lang.h | 2 -- gdb/language.c | 10 ---------- gdb/language.h | 4 ---- gdb/m2-exp.y | 6 +++--- gdb/m2-lang.c | 1 - gdb/m2-lang.h | 2 -- gdb/objc-lang.c | 1 - gdb/opencl-lang.c | 1 - gdb/p-exp.y | 6 +++--- gdb/p-lang.c | 1 - gdb/p-lang.h | 2 -- gdb/parse.c | 3 +-- gdb/rust-exp.y | 5 +++-- gdb/rust-lang.c | 1 - gdb/rust-lang.h | 3 --- 30 files changed, 58 insertions(+), 68 deletions(-) diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index ac4c341bfe9..f0b501f25b0 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -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); diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7d66a9ac550..1a48cf0bc3d 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -14392,7 +14392,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 */ diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index a4192fc8a5a..123f22a6234 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -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 *); diff --git a/gdb/c-exp.y b/gdb/c-exp.y index ae31af52dfb..a9ccbdcb65e 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -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); } diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 6bbb4709571..1c283a8b963 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -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 */ diff --git a/gdb/c-lang.h b/gdb/c-lang.h index a250fb34a6b..e961826407e 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -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 */ diff --git a/gdb/d-exp.y b/gdb/d-exp.y index 508927bb00f..74e4b637d0d 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -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); } diff --git a/gdb/d-lang.c b/gdb/d-lang.c index 688ae981bb1..fe792d85582 100644 --- a/gdb/d-lang.c +++ b/gdb/d-lang.c @@ -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. */ diff --git a/gdb/d-lang.h b/gdb/d-lang.h index 391ea8665bb..e31c76238a9 100644 --- a/gdb/d-lang.h +++ b/gdb/d-lang.h @@ -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); diff --git a/gdb/f-exp.y b/gdb/f-exp.y index e39f68417c2..5ef16125f5d 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -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); } diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 81922f73fb6..1b7994fbd3f 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -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 */ diff --git a/gdb/f-lang.h b/gdb/f-lang.h index e9d0f3a857d..d60cf1b95ff 100644 --- a/gdb/f-lang.h +++ b/gdb/f-lang.h @@ -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 *); diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 936d507c374..47570d59111 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -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); } diff --git a/gdb/go-lang.c b/gdb/go-lang.c index 60ab2f3dc3d..49a6b9efca0 100644 --- a/gdb/go-lang.c +++ b/gdb/go-lang.c @@ -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. */ diff --git a/gdb/go-lang.h b/gdb/go-lang.h index 84af9389e7c..963ee2f91a7 100644 --- a/gdb/go-lang.h +++ b/gdb/go-lang.h @@ -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); diff --git a/gdb/language.c b/gdb/language.c index 22199e0c0d6..44bbeb4cb3b 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -46,8 +46,6 @@ #include "c-lang.h" #include -static void unk_lang_error (const char *); - static int unk_lang_parser (struct parser_state *); static void set_range_case (void); @@ -751,12 +749,6 @@ unk_lang_parser (struct parser_state *ps) } 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, diff --git a/gdb/language.h b/gdb/language.h index 029de4a7abb..e103a936618 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -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 diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index 2cf026c77a5..2cf2bb53635 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -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); } diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index 6e6434b846d..d849f8c306d 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -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 */ diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h index d7e1aec6730..467b984b39f 100644 --- a/gdb/m2-lang.h +++ b/gdb/m2-lang.h @@ -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 *); diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index f8b28b21d24..6da8af1a461 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -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 */ diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index 8af63f76206..6bfdbde3054 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -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 */ diff --git a/gdb/p-exp.y b/gdb/p-exp.y index d527b776d9f..9ffaccdbe3f 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -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); } diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 3ff7f5694f4..56dfa19ce07 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -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 */ diff --git a/gdb/p-lang.h b/gdb/p-lang.h index 61ee752fe73..a3313c2c449 100644 --- a/gdb/p-lang.h +++ b/gdb/p-lang.h @@ -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 *); diff --git a/gdb/parse.c b/gdb/parse.c index 193abe853f4..acb08f24363 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -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) { diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index 9f21498d4c9..b60997681ae 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -70,6 +70,7 @@ struct set_field typedef std::vector 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); } diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 167f35398eb..d9807d0ac1a 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -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 */ diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h index ce30e332761..f81f47fa8d2 100644 --- a/gdb/rust-lang.h +++ b/gdb/rust-lang.h @@ -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);