From ec8cec5b96e2ebbd5e25a737c69d311970a8b219 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 2 Jun 2020 21:54:49 +0100 Subject: [PATCH] gdb: Convert language la_emitchar field to a method This commit changes the language_data::la_emitchar function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (emit_char): Renamed to ada_language::emitchar. (ada_language_data): Delete la_emitchar initializer. (ada_language::emitchar): New member function, implementation from emit_char. * c-lang.c (c_language_data): Delete la_emitchar initializer. (cplus_language_data): Likewise. (asm_language_data): Likewise. (minimal_language_data): Likewise. * d-lang.c (d_language_data): Likewise. * f-lang.c (f_emit_char): Rename to f_language::emitchar. (f_language_data): Delete la_emitchar initializer. (f_language::emitchar): New member function, implementation from f_emit_char. * go-lang.c (go_language_data): Delete la_emitchar initializer. * language.c (unk_lang_emit_char): Delete. (language_defn::emitchar): New member function definition. (unknown_language_data): Delete la_emitchar initializer. (unknown_language::emitchar): New member function. (auto_language_data): Delete la_emitchar initializer. (auto_language::emitchar): New member function. * language.h (language_data): Delete la_emitchar field. (language_defn::emitchar): New member field declaration. (LA_EMIT_CHAR): Update call to emitchar. * m2-lang.c (m2_emit_char): Rename to m2_language::emitchar. (m2_language_data): Delete la_emitchar initializer. (m2_language::emitchar): New member function, implementation from m2_emit_char. * objc-lang.c (objc_language_data): Delete la_emitchar initializer. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_emit_char): Rename to pascal_language::emitchar. (pascal_language_data): Delete la_emitchar initializer. (pascal_language::emitchar): New member function, implementation from pascal_emit_char. * rust-lang.c (rust_emitchar): Rename to rust_language::emitchar. (rust_language_data): Delete la_emitchar initializer. (rust_language::emitchar): New member function, implementation from rust_emitchar. --- gdb/ChangeLog | 41 ++++++++++++++++++++ gdb/ada-lang.c | 17 ++++---- gdb/c-lang.c | 4 -- gdb/d-lang.c | 1 - gdb/f-lang.c | 26 +++++-------- gdb/go-lang.c | 1 - gdb/language.c | 40 ++++++++++++------- gdb/language.h | 11 ++++-- gdb/m2-lang.c | 99 +++++++++++++++++++++-------------------------- gdb/objc-lang.c | 1 - gdb/opencl-lang.c | 1 - gdb/p-lang.c | 30 ++++++-------- gdb/rust-lang.c | 53 +++++++++++++------------ 13 files changed, 173 insertions(+), 152 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 098014a429..d402fb590b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,44 @@ +2020-06-23 Andrew Burgess + + * ada-lang.c (emit_char): Renamed to ada_language::emitchar. + (ada_language_data): Delete la_emitchar initializer. + (ada_language::emitchar): New member function, implementation from + emit_char. + * c-lang.c (c_language_data): Delete la_emitchar initializer. + (cplus_language_data): Likewise. + (asm_language_data): Likewise. + (minimal_language_data): Likewise. + * d-lang.c (d_language_data): Likewise. + * f-lang.c (f_emit_char): Rename to f_language::emitchar. + (f_language_data): Delete la_emitchar initializer. + (f_language::emitchar): New member function, implementation from + f_emit_char. + * go-lang.c (go_language_data): Delete la_emitchar initializer. + * language.c (unk_lang_emit_char): Delete. + (language_defn::emitchar): New member function definition. + (unknown_language_data): Delete la_emitchar initializer. + (unknown_language::emitchar): New member function. + (auto_language_data): Delete la_emitchar initializer. + (auto_language::emitchar): New member function. + * language.h (language_data): Delete la_emitchar field. + (language_defn::emitchar): New member field declaration. + (LA_EMIT_CHAR): Update call to emitchar. + * m2-lang.c (m2_emit_char): Rename to m2_language::emitchar. + (m2_language_data): Delete la_emitchar initializer. + (m2_language::emitchar): New member function, implementation from + m2_emit_char. + * objc-lang.c (objc_language_data): Delete la_emitchar + initializer. + * opencl-lang.c (opencl_language_data): Likewise. + * p-lang.c (pascal_emit_char): Rename to pascal_language::emitchar. + (pascal_language_data): Delete la_emitchar initializer. + (pascal_language::emitchar): New member function, implementation + from pascal_emit_char. + * rust-lang.c (rust_emitchar): Rename to rust_language::emitchar. + (rust_language_data): Delete la_emitchar initializer. + (rust_language::emitchar): New member function, implementation + from rust_emitchar. + 2020-06-23 Andrew Burgess * ada-lang.c (resolve): Rename to ada_language::post_parser. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index bb6d011e13..7858679f5b 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13504,14 +13504,6 @@ enum ada_primitive_types { /* Language vector */ -/* Not really used, but needed in the ada_language_defn. */ - -static void -emit_char (int c, struct type *type, struct ui_file *stream, int quoter) -{ - ada_emit_char (c, type, stream, quoter, 1); -} - static const struct exp_descriptor ada_exp_descriptor = { ada_print_subexp, ada_operator_length, @@ -13691,7 +13683,6 @@ extern const struct language_data ada_language_data = &ada_exp_descriptor, ada_printchar, /* Print a character constant */ ada_printstr, /* Function to print string constant */ - emit_char, /* Function to print single char (not used) */ ada_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ @@ -14116,6 +14107,14 @@ public: resolve_subexp (expp, &pc, 1, context_type, completing, tracker); } + /* See language.h. */ + + void emitchar (int ch, struct type *chtype, + struct ui_file *stream, int quoter) const override + { + ada_emit_char (ch, chtype, stream, quoter, 1); + } + protected: /* See language.h. */ diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 363c896b7a..fbd564d041 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -891,7 +891,6 @@ extern const struct language_data c_language_data = &exp_descriptor_c, c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ - c_emit_char, /* Print a single char */ c_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ @@ -997,7 +996,6 @@ extern const struct language_data cplus_language_data = &exp_descriptor_c, c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ - c_emit_char, /* Print a single char */ c_print_typedef, /* Print a typedef using appropriate syntax */ "this", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ @@ -1200,7 +1198,6 @@ extern const struct language_data asm_language_data = &exp_descriptor_c, c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ - c_emit_char, /* Print a single char */ c_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ @@ -1261,7 +1258,6 @@ extern const struct language_data minimal_language_data = &exp_descriptor_c, c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ - c_emit_char, /* Print a single char */ c_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ diff --git a/gdb/d-lang.c b/gdb/d-lang.c index facc82c201..fa6df33738 100644 --- a/gdb/d-lang.c +++ b/gdb/d-lang.c @@ -144,7 +144,6 @@ extern const struct language_data d_language_data = &exp_descriptor_c, c_printchar, /* Print a character constant. */ c_printstr, /* Function to print string constant. */ - c_emit_char, /* Print a single char. */ c_print_typedef, /* Print a typedef using appropriate syntax. */ "this", diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 1b545b27b3..90b2e86128 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -42,8 +42,6 @@ /* Local functions */ static void f_printchar (int c, struct type *type, struct ui_file * stream); -static void f_emit_char (int c, struct type *type, - struct ui_file * stream, int quoter); /* Return the encoding that should be used for the character type TYPE. */ @@ -72,20 +70,6 @@ f_get_encoding (struct type *type) return encoding; } -/* Print the character C on STREAM as part of the contents of a literal - string whose delimiter is QUOTER. Note that that format for printing - characters and strings is language specific. - FIXME: This is a copy of the same function from c-exp.y. It should - be replaced with a true F77 version. */ - -static void -f_emit_char (int c, struct type *type, struct ui_file *stream, int quoter) -{ - const char *encoding = f_get_encoding (type); - - generic_emit_char (c, type, stream, quoter, encoding); -} - /* Implementation of la_printchar. */ static void @@ -566,7 +550,6 @@ extern const struct language_data f_language_data = &exp_descriptor_f, f_printchar, /* Print character constant */ f_printstr, /* function to print string constant */ - f_emit_char, /* Function to print a single character */ f_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ @@ -718,6 +701,15 @@ public: return f_parse (ps); } + /* See language.h. */ + + void emitchar (int ch, struct type *chtype, + struct ui_file *stream, int quoter) const override + { + const char *encoding = f_get_encoding (chtype); + generic_emit_char (ch, chtype, stream, quoter, encoding); + } + protected: /* See language.h. */ diff --git a/gdb/go-lang.c b/gdb/go-lang.c index c26dee9a06..f167543278 100644 --- a/gdb/go-lang.c +++ b/gdb/go-lang.c @@ -529,7 +529,6 @@ extern const struct language_data go_language_data = &exp_descriptor_c, c_printchar, /* Print a character constant. */ c_printstr, /* Function to print string constant. */ - c_emit_char, /* Print a single char. */ c_print_typedef, /* Print a typedef using appropriate syntax. */ NULL, /* name_of_this */ diff --git a/gdb/language.c b/gdb/language.c index 72fa1e4513..6778646bec 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -49,9 +49,6 @@ static void set_range_case (void); -static void unk_lang_emit_char (int c, struct type *type, - struct ui_file *stream, int quoter); - static void unk_lang_printchar (int c, struct type *type, struct ui_file *stream); @@ -657,6 +654,15 @@ language_defn::value_print_inner return c_value_print_inner (val, stream, recurse, options); } +/* See language.h. */ + +void +language_defn::emitchar (int ch, struct type *chtype, + struct ui_file * stream, int quoter) const +{ + c_emit_char (ch, chtype, stream, quoter); +} + /* The default implementation of the get_symbol_name_matcher_inner method from the language_defn class. Matches with strncmp_iw. */ @@ -722,16 +728,6 @@ default_is_string_type_p (struct type *type) return (type->code () == TYPE_CODE_STRING); } -/* Define the language that is no language. */ - -static void -unk_lang_emit_char (int c, struct type *type, struct ui_file *stream, - int quoter) -{ - error (_("internal error - unimplemented " - "function unk_lang_emit_char called.")); -} - static void unk_lang_printchar (int c, struct type *type, struct ui_file *stream) { @@ -779,7 +775,6 @@ extern const struct language_data unknown_language_data = &exp_descriptor_standard, unk_lang_printchar, /* Print character constant */ unk_lang_printstr, - unk_lang_emit_char, default_print_typedef, /* Print a typedef using appropriate syntax */ "this", /* name_of_this */ true, /* store_sym_names_in_linkage_form_p */ @@ -848,6 +843,14 @@ public: /* No parsing is done, just claim success. */ return 1; } + + /* See language.h. */ + + void emitchar (int ch, struct type *chtype, + struct ui_file *stream, int quoter) const override + { + error (_("unimplemented unknown_language::emitchar called")); + } }; /* Single instance of the unknown language class. */ @@ -869,7 +872,6 @@ extern const struct language_data auto_language_data = &exp_descriptor_standard, unk_lang_printchar, /* Print character constant */ unk_lang_printstr, - unk_lang_emit_char, default_print_typedef, /* Print a typedef using appropriate syntax */ "this", /* name_of_this */ false, /* store_sym_names_in_linkage_form_p */ @@ -938,6 +940,14 @@ public: /* No parsing is done, just claim success. */ return 1; } + + /* See language.h. */ + + void emitchar (int ch, struct type *chtype, + struct ui_file *stream, int quoter) const override + { + error (_("unimplemented auto_language::emitchar called")); + } }; /* Single instance of the fake "auto" language. */ diff --git a/gdb/language.h b/gdb/language.h index d5b106d84e..612afb3c5f 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -233,9 +233,6 @@ struct language_data const char *encoding, int force_ellipses, const struct value_print_options *); - void (*la_emitchar) (int ch, struct type *chtype, - struct ui_file * stream, int quoter); - /* Print a typedef using syntax appropriate for this language. TYPE is the underlying type. NEW_SYMBOL is the symbol naming the type. STREAM is the output stream on which to print. */ @@ -544,6 +541,12 @@ struct language_defn : language_data /* By default the post-parser does nothing. */ } + /* Print the character CH (of type CHTYPE) on STREAM as part of the + contents of a literal string whose delimiter is QUOTER. */ + + virtual void emitchar (int ch, struct type *chtype, + struct ui_file *stream, int quoter) const; + protected: /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method. @@ -651,7 +654,7 @@ extern enum language set_language (enum language); (current_language->la_printstr(stream, elttype, string, length, \ encoding, force_ellipses,options)) #define LA_EMIT_CHAR(ch, type, stream, quoter) \ - (current_language->la_emitchar(ch, type, stream, quoter)) + (current_language->emitchar (ch, type, stream, quoter)) #define LA_PRINT_ARRAY_INDEX(index_type, index_value, stream, options) \ (current_language->print_array_index(index_type, index_value, stream, \ diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index 5aca833496..d8f7f00528 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -30,59 +30,6 @@ #include "gdbarch.h" static void m2_printchar (int, struct type *, struct ui_file *); -static void m2_emit_char (int, struct type *, struct ui_file *, int); - -/* Print the character C on STREAM as part of the contents of a literal - string whose delimiter is QUOTER. Note that that format for printing - characters and strings is language specific. - FIXME: This is a copy of the same function from c-exp.y. It should - be replaced with a true Modula version. */ - -static void -m2_emit_char (int c, struct type *type, struct ui_file *stream, int quoter) -{ - - c &= 0xFF; /* Avoid sign bit follies. */ - - if (PRINT_LITERAL_FORM (c)) - { - if (c == '\\' || c == quoter) - { - fputs_filtered ("\\", stream); - } - fprintf_filtered (stream, "%c", c); - } - else - { - switch (c) - { - case '\n': - fputs_filtered ("\\n", stream); - break; - case '\b': - fputs_filtered ("\\b", stream); - break; - case '\t': - fputs_filtered ("\\t", stream); - break; - case '\f': - fputs_filtered ("\\f", stream); - break; - case '\r': - fputs_filtered ("\\r", stream); - break; - case '\033': - fputs_filtered ("\\e", stream); - break; - case '\007': - fputs_filtered ("\\a", stream); - break; - default: - fprintf_filtered (stream, "\\%.3o", (unsigned int) c); - break; - } - } -} /* FIXME: This is a copy of the same function from c-exp.y. It should be replaced with a true Modula version. */ @@ -364,7 +311,6 @@ extern const struct language_data m2_language_data = &exp_descriptor_modula2, m2_printchar, /* Print character constant */ m2_printstr, /* function to print string constant */ - m2_emit_char, /* Function to print a single character */ m2_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ @@ -435,6 +381,51 @@ public: { return m2_parse (ps); } + + /* See language.h. */ + + void emitchar (int ch, struct type *chtype, + struct ui_file *stream, int quoter) const override + { + ch &= 0xFF; /* Avoid sign bit follies. */ + + if (PRINT_LITERAL_FORM (ch)) + { + if (ch == '\\' || ch == quoter) + fputs_filtered ("\\", stream); + fprintf_filtered (stream, "%c", ch); + } + else + { + switch (ch) + { + case '\n': + fputs_filtered ("\\n", stream); + break; + case '\b': + fputs_filtered ("\\b", stream); + break; + case '\t': + fputs_filtered ("\\t", stream); + break; + case '\f': + fputs_filtered ("\\f", stream); + break; + case '\r': + fputs_filtered ("\\r", stream); + break; + case '\033': + fputs_filtered ("\\e", stream); + break; + case '\007': + fputs_filtered ("\\a", stream); + break; + default: + fprintf_filtered (stream, "\\%.3o", (unsigned int) ch); + break; + } + } + } }; /* Single instance of the M2 language. */ diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 2ec87774f4..ffde14a97a 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -339,7 +339,6 @@ extern const struct language_data objc_language_data = &exp_descriptor_standard, c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ - c_emit_char, c_print_typedef, /* Print a typedef using appropriate syntax */ "self", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index f314eff55f..3789c211ca 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -1018,7 +1018,6 @@ extern const struct language_data opencl_language_data = &exp_descriptor_opencl, c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ - c_emit_char, /* Print a single char */ c_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 14ca5d7833..b0465f4a35 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -192,23 +192,6 @@ pascal_one_char (int c, struct ui_file *stream, int *in_quotes) } } -static void pascal_emit_char (int c, struct type *type, - struct ui_file *stream, int quoter); - -/* Print the character C on STREAM as part of the contents of a literal - string whose delimiter is QUOTER. Note that that format for printing - characters and strings is language specific. */ - -static void -pascal_emit_char (int c, struct type *type, struct ui_file *stream, int quoter) -{ - int in_quotes = 0; - - pascal_one_char (c, stream, &in_quotes); - if (in_quotes) - fputs_filtered ("'", stream); -} - void pascal_printchar (int c, struct type *type, struct ui_file *stream) { @@ -395,7 +378,6 @@ extern const struct language_data pascal_language_data = &exp_descriptor_standard, pascal_printchar, /* Print a character constant */ pascal_printstr, /* Function to print string constant */ - pascal_emit_char, /* Print a single char */ pascal_print_typedef, /* Print a typedef using appropriate syntax */ "this", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ @@ -497,6 +479,18 @@ public: { return pascal_parse (ps); } + + /* See language.h. */ + + void emitchar (int ch, struct type *chtype, + struct ui_file *stream, int quoter) const override + { + int in_quotes = 0; + + pascal_one_char (ch, stream, &in_quotes); + if (in_quotes) + fputs_filtered ("'", stream); + } }; /* Single instance of the Pascal language class. */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 846fe1fa40..2d6cb8bf0b 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -281,32 +281,6 @@ rust_get_trait_object_pointer (struct value *value) -/* la_emitchar implementation for Rust. */ - -static void -rust_emitchar (int c, struct type *type, struct ui_file *stream, int quoter) -{ - if (!rust_chartype_p (type)) - generic_emit_char (c, type, stream, quoter, - target_charset (get_type_arch (type))); - else if (c == '\\' || c == quoter) - fprintf_filtered (stream, "\\%c", c); - else if (c == '\n') - fputs_filtered ("\\n", stream); - else if (c == '\r') - fputs_filtered ("\\r", stream); - else if (c == '\t') - fputs_filtered ("\\t", stream); - else if (c == '\0') - fputs_filtered ("\\0", stream); - else if (c >= 32 && c <= 127 && isprint (c)) - fputc_filtered (c, stream); - else if (c <= 255) - fprintf_filtered (stream, "\\x%02x", c); - else - fprintf_filtered (stream, "\\u{%06x}", c); -} - /* la_printchar implementation for Rust. */ static void @@ -1991,7 +1965,6 @@ extern const struct language_data rust_language_data = &exp_descriptor_rust, rust_printchar, /* Print a character constant */ rust_printstr, /* Function to print string constant */ - rust_emitchar, /* Print a single char */ rust_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ @@ -2147,6 +2120,32 @@ public: { return rust_parse (ps); } + + /* See language.h. */ + + void emitchar (int ch, struct type *chtype, + struct ui_file *stream, int quoter) const override + { + if (!rust_chartype_p (chtype)) + generic_emit_char (ch, chtype, stream, quoter, + target_charset (get_type_arch (chtype))); + else if (ch == '\\' || ch == quoter) + fprintf_filtered (stream, "\\%c", ch); + else if (ch == '\n') + fputs_filtered ("\\n", stream); + else if (ch == '\r') + fputs_filtered ("\\r", stream); + else if (ch == '\t') + fputs_filtered ("\\t", stream); + else if (ch == '\0') + fputs_filtered ("\\0", stream); + else if (ch >= 32 && ch <= 127 && isprint (ch)) + fputc_filtered (ch, stream); + else if (ch <= 255) + fprintf_filtered (stream, "\\x%02x", ch); + else + fprintf_filtered (stream, "\\u{%06x}", ch); + } }; /* Single instance of the Rust language class. */ -- 2.34.1