From 4ffc13fb0e4a1c5158cdf00f2751378653101207 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Thu, 18 Jun 2020 21:38:50 +0100 Subject: [PATCH] gdb: Convert language la_print_typedef field to a method This commit changes the language_data::la_print_typedef 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 (ada_language_data): Delete la_print_typedef initializer. (ada_language::print_typedef): New member function. * c-lang.c (c_language_data): Delete la_print_typedef initializer. (cplus_language_data): Likewise. (asm_language_data): Likewise. (minimal_language_data): Likewise. * d-lang.c (d_language_data): Likewise. * f-lang.c (f_language_data): Likewise. (f_language::print_typedef): New member function. * go-lang.c (go_language_data): Delete la_print_typedef initializer. * language.c (language_defn::print_typedef): Define member function. (unknown_language_data): Delete la_print_typedef initializer. (unknown_language::print_typedef): New member function. (auto_language_data): Delete la_print_typedef initializer. (auto_language::print_typedef): New member function. * language.h (language_data): Delete la_print_typedef field. (language_defn::print_typedef): Declare new member function. (LA_PRINT_TYPEDEF): Update call to print_typedef. (default_print_typedef): Delete declaration. * m2-lang.c (m2_language_data): Delete la_print_typedef initializer. (m2_language::print_typedef): New member function. * objc-lang.c (objc_language_data): Delete la_print_typedef initializer. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. (pascal_language::print_typedef): New member function. * rust-lang.c (rust_print_typedef): Delete function, implementation moved to rust_language::print_typedef. (rust_language): Delete la_print_typedef initializer. (rust_language::print_typedef): New member function, implementation from rust_print_typedef. * typeprint.c (default_print_typedef): Delete. --- gdb/ChangeLog | 39 +++++++++++++++++++++++++++++++++++++++ gdb/ada-lang.c | 9 ++++++++- gdb/c-lang.c | 4 ---- gdb/d-lang.c | 2 -- gdb/f-lang.c | 9 ++++++++- gdb/go-lang.c | 2 -- gdb/language.c | 27 +++++++++++++++++++++++++-- gdb/language.h | 21 +++++++++------------ gdb/m2-lang.c | 10 +++++++++- gdb/objc-lang.c | 1 - gdb/opencl-lang.c | 1 - gdb/p-lang.c | 10 +++++++++- gdb/rust-lang.c | 25 +++++++++++-------------- gdb/typeprint.c | 9 --------- 14 files changed, 118 insertions(+), 51 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e768e447f42..de348bb4770 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,42 @@ +2020-06-23 Andrew Burgess + + * ada-lang.c (ada_language_data): Delete la_print_typedef + initializer. + (ada_language::print_typedef): New member function. + * c-lang.c (c_language_data): Delete la_print_typedef initializer. + (cplus_language_data): Likewise. + (asm_language_data): Likewise. + (minimal_language_data): Likewise. + * d-lang.c (d_language_data): Likewise. + * f-lang.c (f_language_data): Likewise. + (f_language::print_typedef): New member function. + * go-lang.c (go_language_data): Delete la_print_typedef + initializer. + * language.c (language_defn::print_typedef): Define member + function. + (unknown_language_data): Delete la_print_typedef initializer. + (unknown_language::print_typedef): New member function. + (auto_language_data): Delete la_print_typedef initializer. + (auto_language::print_typedef): New member function. + * language.h (language_data): Delete la_print_typedef field. + (language_defn::print_typedef): Declare new member function. + (LA_PRINT_TYPEDEF): Update call to print_typedef. + (default_print_typedef): Delete declaration. + * m2-lang.c (m2_language_data): Delete la_print_typedef + initializer. + (m2_language::print_typedef): New member function. + * objc-lang.c (objc_language_data): Delete la_print_typedef + initializer. + * opencl-lang.c (opencl_language_data): Likewise. + * p-lang.c (pascal_language_data): Likewise. + (pascal_language::print_typedef): New member function. + * rust-lang.c (rust_print_typedef): Delete function, + implementation moved to rust_language::print_typedef. + (rust_language): Delete la_print_typedef initializer. + (rust_language::print_typedef): New member function, + implementation from rust_print_typedef. + * typeprint.c (default_print_typedef): Delete. + 2020-06-23 Andrew Burgess * ada-lang.c (ada_language_data): Delete la_printstr initializer. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 62ea21a3857..752bf44cef0 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13681,7 +13681,6 @@ extern const struct language_data ada_language_data = macro_expansion_no, ada_extensions, &ada_exp_descriptor, - ada_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ ada_op_print_tab, /* expression operators for printing */ @@ -14132,6 +14131,14 @@ public: force_ellipses, options); } + /* See language.h. */ + + void print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) const override + { + ada_print_typedef (type, new_symbol, stream); + } + protected: /* See language.h. */ diff --git a/gdb/c-lang.c b/gdb/c-lang.c index d6bbc025bc7..aca0d7a6bc9 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -889,7 +889,6 @@ extern const struct language_data c_language_data = macro_expansion_c, c_extensions, &exp_descriptor_c, - c_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ c_op_print_tab, /* expression operators for printing */ @@ -992,7 +991,6 @@ extern const struct language_data cplus_language_data = macro_expansion_c, cplus_extensions, &exp_descriptor_c, - c_print_typedef, /* Print a typedef using appropriate syntax */ "this", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ c_op_print_tab, /* expression operators for printing */ @@ -1192,7 +1190,6 @@ extern const struct language_data asm_language_data = macro_expansion_c, asm_extensions, &exp_descriptor_c, - c_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ c_op_print_tab, /* expression operators for printing */ @@ -1250,7 +1247,6 @@ extern const struct language_data minimal_language_data = macro_expansion_c, NULL, &exp_descriptor_c, - c_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ 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 17ab38ee511..b907dd750e0 100644 --- a/gdb/d-lang.c +++ b/gdb/d-lang.c @@ -142,8 +142,6 @@ extern const struct language_data d_language_data = macro_expansion_no, d_extensions, &exp_descriptor_c, - c_print_typedef, /* Print a typedef using appropriate - syntax. */ "this", false, /* la_store_sym_names_in_linkage_form_p */ d_op_print_tab, /* Expression operators for printing. */ diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 67c2ea34b64..946d5bc25af 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -513,7 +513,6 @@ extern const struct language_data f_language_data = macro_expansion_no, f_extensions, &exp_descriptor_f, - f_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ f_op_print_tab, /* expression operators for printing */ @@ -702,6 +701,14 @@ public: force_ellipses, '\'', 0, options); } + /* See language.h. */ + + void print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) const override + { + f_print_typedef (type, new_symbol, stream); + } + protected: /* See language.h. */ diff --git a/gdb/go-lang.c b/gdb/go-lang.c index 69f14b8c56c..fa263997b12 100644 --- a/gdb/go-lang.c +++ b/gdb/go-lang.c @@ -527,8 +527,6 @@ extern const struct language_data go_language_data = macro_expansion_no, NULL, &exp_descriptor_c, - c_print_typedef, /* Print a typedef using appropriate - syntax. */ NULL, /* name_of_this */ 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 9867ac4b4b5..5ae8c46879c 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -681,6 +681,15 @@ language_defn::printstr (struct ui_file *stream, struct type *elttype, options); } +/* See language.h. */ + +void +language_defn::print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) const +{ + c_print_typedef (type, new_symbol, stream); +} + /* The default implementation of the get_symbol_name_matcher_inner method from the language_defn class. Matches with strncmp_iw. */ @@ -774,7 +783,6 @@ extern const struct language_data unknown_language_data = macro_expansion_no, NULL, &exp_descriptor_standard, - default_print_typedef, /* Print a typedef using appropriate syntax */ "this", /* name_of_this */ true, /* store_sym_names_in_linkage_form_p */ unk_op_print_tab, /* expression operators for printing */ @@ -868,6 +876,14 @@ public: { error (_("unimplemented unknown_language::printstr called")); } + + /* See language.h. */ + + void print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) const override + { + error (_("unimplemented unknown_language::print_typedef called")); + } }; /* Single instance of the unknown language class. */ @@ -887,7 +903,6 @@ extern const struct language_data auto_language_data = macro_expansion_no, NULL, &exp_descriptor_standard, - default_print_typedef, /* Print a typedef using appropriate syntax */ "this", /* name_of_this */ false, /* store_sym_names_in_linkage_form_p */ unk_op_print_tab, /* expression operators for printing */ @@ -981,6 +996,14 @@ public: { error (_("unimplemented auto_language::printstr called")); } + + /* See language.h. */ + + void print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) const override + { + error (_("unimplemented auto_language::print_typedef called")); + } }; /* Single instance of the fake "auto" language. */ diff --git a/gdb/language.h b/gdb/language.h index a68b6dfdcae..19cd8205718 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -225,13 +225,6 @@ struct language_data const struct exp_descriptor *la_exp_desc; - /* 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. */ - - void (*la_print_typedef) (struct type *type, struct symbol *new_symbol, - struct ui_file *stream); - /* Now come some hooks for lookup_symbol. */ /* If this is non-NULL, specifies the name that of the implicit @@ -552,6 +545,14 @@ struct language_defn : language_data const char *encoding, int force_ellipses, const struct value_print_options *options) const; + + /* 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. */ + + virtual void print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) const; + protected: /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method. @@ -648,7 +649,7 @@ extern enum language set_language (enum language); (current_language->print_type(type,varstring,stream,show,level,flags)) #define LA_PRINT_TYPEDEF(type,new_symbol,stream) \ - (current_language->la_print_typedef(type,new_symbol,stream)) + (current_language->print_typedef (type,new_symbol,stream)) #define LA_VALUE_PRINT(val,stream,options) \ (current_language->value_print (val,stream,options)) @@ -715,10 +716,6 @@ extern char *language_demangle (const struct language_defn *current_language, (and returned) by reference at the language level. */ struct language_pass_by_ref_info language_pass_by_reference (struct type *type); -/* The default implementation of la_print_typedef. */ -void default_print_typedef (struct type *type, struct symbol *new_symbol, - struct ui_file *stream); - void c_get_string (struct value *value, gdb::unique_xmalloc_ptr *buffer, int *length, struct type **char_type, diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index b84a9a49f84..f0f7c22fb5d 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -229,7 +229,6 @@ extern const struct language_data m2_language_data = macro_expansion_no, NULL, &exp_descriptor_modula2, - m2_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ m2_op_print_tab, /* expression operators for printing */ @@ -427,6 +426,15 @@ public: if (force_ellipses || i < length) fputs_filtered ("...", stream); } + + /* See language.h. */ + + void print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) const override + { + m2_print_typedef (type, new_symbol, stream); + } + }; /* Single instance of the M2 language. */ diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 95c6c0a1fc5..0c952730a96 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -337,7 +337,6 @@ extern const struct language_data objc_language_data = macro_expansion_c, objc_extensions, &exp_descriptor_standard, - c_print_typedef, /* Print a typedef using appropriate syntax */ "self", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ objc_op_print_tab, /* Expression operators for printing */ diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index 765202aac0a..2431faed00e 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -1016,7 +1016,6 @@ extern const struct language_data opencl_language_data = macro_expansion_c, NULL, &exp_descriptor_opencl, - c_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ 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 1c6aea90b6c..9fd823185b1 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -276,7 +276,6 @@ extern const struct language_data pascal_language_data = macro_expansion_no, p_extensions, &exp_descriptor_standard, - pascal_print_typedef, /* Print a typedef using appropriate syntax */ "this", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ pascal_op_print_tab, /* expression operators for printing */ @@ -494,6 +493,15 @@ public: if (force_ellipses || i < length) fputs_filtered ("...", stream); } + + /* See language.h. */ + + void print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) const override + { + pascal_print_typedef (type, new_symbol, stream); + } + }; /* Single instance of the Pascal language class. */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index b13623fe619..083b3f73277 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -765,19 +765,6 @@ rust_print_struct_def (struct type *type, const char *varstring, fputs_filtered (is_tuple_struct ? ")" : "}", stream); } -/* la_print_typedef implementation for Rust. */ - -static void -rust_print_typedef (struct type *type, - struct symbol *new_symbol, - struct ui_file *stream) -{ - type = check_typedef (type); - fprintf_filtered (stream, "type %s = ", new_symbol->print_name ()); - type_print (type, "", stream, 0); - fprintf_filtered (stream, ";"); -} - /* la_print_type implementation for Rust. */ static void @@ -1953,7 +1940,6 @@ extern const struct language_data rust_language_data = macro_expansion_no, rust_extensions, &exp_descriptor_rust, - rust_print_typedef, /* Print a typedef using appropriate syntax */ NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ c_op_print_tab, /* expression operators for printing */ @@ -2155,6 +2141,17 @@ public: rust_printstr (stream, elttype, string, length, encoding, force_ellipses, options); } + + /* See language.h. */ + + void print_typedef (struct type *type, struct symbol *new_symbol, + struct ui_file *stream) const override + { + type = check_typedef (type); + fprintf_filtered (stream, "type %s = ", new_symbol->print_name ()); + type_print (type, "", stream, 0); + fprintf_filtered (stream, ";"); + } }; /* Single instance of the Rust language class. */ diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 37409d9a210..08b9a426eac 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -368,15 +368,6 @@ typedef_print (struct type *type, struct symbol *newobj, struct ui_file *stream) LA_PRINT_TYPEDEF (type, newobj, stream); } -/* The default way to print a typedef. */ - -void -default_print_typedef (struct type *type, struct symbol *new_symbol, - struct ui_file *stream) -{ - error (_("Language not supported.")); -} - /* Print a description of a type TYPE in the form of a declaration of a variable named VARSTRING. (VARSTRING is demangled if necessary.) Output goes to STREAM (via stdio). -- 2.30.2