From fbfb0a463fc7de88a2da8858ac5cd6c2f4796514 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Thu, 14 May 2020 18:41:39 +0100 Subject: [PATCH] gdb: Convert language la_print_type field to a method This commit changes the language_data::la_print_type 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_type initializer. (ada_language::print_type): New member function. * c-lang.c (c_language_data): Delete la_print_type initializer. (c_language::print_type): New member function. (cplus_language_data): Delete la_print_type initializer. (cplus_language::print_type): New member function. (asm_language_data): Delete la_print_type initializer. (asm_language::print_type): New member function. (minimal_language_data): Delete la_print_type initializer. (minimal_language::print_type): New member function. * d-lang.c (d_language_data): Delete la_print_type initializer. (d_language::print_type): New member function. * f-lang.c (f_language_data): Delete la_print_type initializer. (f_language::print_type): New member function. * go-lang.c (go_language_data): Delete la_print_type initializer. (go_language::print_type): New member function. * language.c (unk_lang_print_type): Delete. (unknown_language_data): Delete la_print_type initializer. (unknown_language::print_type): New member function. (auto_language_data): Delete la_print_type initializer. (auto_language::print_type): New member function. * language.h (language_data): Delete la_print_type field. (language_defn::print_type): New function. (LA_PRINT_TYPE): Update. * m2-lang.c (m2_language_data): Delete la_print_type initializer. (m2_language::print_type): New member function. * objc-lang.c (objc_language_data): Delete la_print_type initializer. (objc_language::print_type): New member function. * opencl-lang.c (opencl_print_type): Delete, implementation moved to opencl_language::print_type. (opencl_language_data): Delete la_print_type initializer. (opencl_language::print_type): New member function, implementation from opencl_print_type. * p-lang.c (pascal_language_data): Delete la_print_type initializer. (pascal_language::print_type): New member function. * rust-lang.c (rust_print_type): Delete, implementation moved to rust_language::print_type. (rust_language_data): Delete la_print_type initializer. (rust_language::print_type): New member function, implementation from rust_print_type. --- gdb/ChangeLog | 46 ++++++++++++++++++++++++++++++++++++++++++++++ gdb/ada-lang.c | 10 +++++++++- gdb/c-lang.c | 40 ++++++++++++++++++++++++++++++++++++---- gdb/d-lang.c | 10 +++++++++- gdb/f-lang.c | 10 +++++++++- gdb/go-lang.c | 10 +++++++++- gdb/language.c | 29 ++++++++++++++++++----------- gdb/language.h | 12 ++++++------ gdb/m2-lang.c | 10 +++++++++- gdb/objc-lang.c | 10 +++++++++- gdb/opencl-lang.c | 42 ++++++++++++++++++++---------------------- gdb/p-lang.c | 10 +++++++++- gdb/rust-lang.c | 22 +++++++++++----------- 13 files changed, 200 insertions(+), 61 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 46ca0113926..bf690af9c43 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,49 @@ +2020-06-02 Andrew Burgess + + * ada-lang.c (ada_language_data): Delete la_print_type + initializer. + (ada_language::print_type): New member function. + * c-lang.c (c_language_data): Delete la_print_type initializer. + (c_language::print_type): New member function. + (cplus_language_data): Delete la_print_type initializer. + (cplus_language::print_type): New member function. + (asm_language_data): Delete la_print_type initializer. + (asm_language::print_type): New member function. + (minimal_language_data): Delete la_print_type initializer. + (minimal_language::print_type): New member function. + * d-lang.c (d_language_data): Delete la_print_type initializer. + (d_language::print_type): New member function. + * f-lang.c (f_language_data): Delete la_print_type initializer. + (f_language::print_type): New member function. + * go-lang.c (go_language_data): Delete la_print_type initializer. + (go_language::print_type): New member function. + * language.c (unk_lang_print_type): Delete. + (unknown_language_data): Delete la_print_type initializer. + (unknown_language::print_type): New member function. + (auto_language_data): Delete la_print_type initializer. + (auto_language::print_type): New member function. + * language.h (language_data): Delete la_print_type field. + (language_defn::print_type): New function. + (LA_PRINT_TYPE): Update. + * m2-lang.c (m2_language_data): Delete la_print_type initializer. + (m2_language::print_type): New member function. + * objc-lang.c (objc_language_data): Delete la_print_type + initializer. + (objc_language::print_type): New member function. + * opencl-lang.c (opencl_print_type): Delete, implementation moved + to opencl_language::print_type. + (opencl_language_data): Delete la_print_type initializer. + (opencl_language::print_type): New member function, implementation + from opencl_print_type. + * p-lang.c (pascal_language_data): Delete la_print_type + initializer. + (pascal_language::print_type): New member function. + * rust-lang.c (rust_print_type): Delete, implementation moved to + rust_language::print_type. + (rust_language_data): Delete la_print_type initializer. + (rust_language::print_type): New member function, implementation + from rust_print_type. + 2020-06-02 Andrew Burgess * ada-lang.c (ada_sniff_from_mangled_name): Delete function, diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 6bfc0256b66..f84f02f897d 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13919,7 +13919,6 @@ extern const struct language_data ada_language_data = ada_printchar, /* Print a character constant */ ada_printstr, /* Function to print string constant */ emit_char, /* Function to print single char (not used) */ - ada_print_type, /* Print a type using appropriate syntax */ ada_print_typedef, /* Print a typedef using appropriate syntax */ ada_value_print_inner, /* la_value_print_inner */ ada_value_print, /* Print a top-level value */ @@ -14106,6 +14105,15 @@ public: return false; } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + ada_print_type (type, varstring, stream, show, level, flags); + } }; /* Single instance of the Ada language class. */ diff --git a/gdb/c-lang.c b/gdb/c-lang.c index a5f7d822866..abcdc528867 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -905,7 +905,6 @@ extern const struct language_data c_language_data = c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ - c_print_type, /* Print a type using appropriate syntax */ c_print_typedef, /* Print a typedef using appropriate syntax */ c_value_print_inner, /* la_value_print_inner */ c_value_print, /* Print a top-level value */ @@ -950,6 +949,15 @@ public: { return c_get_compile_context (); } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + c_print_type (type, varstring, stream, show, level, flags); + } }; /* Single instance of the C language class. */ @@ -1007,7 +1015,6 @@ extern const struct language_data cplus_language_data = c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ - c_print_type, /* Print a type using appropriate syntax */ c_print_typedef, /* Print a typedef using appropriate syntax */ c_value_print_inner, /* la_value_print_inner */ c_value_print, /* Print a top-level value */ @@ -1136,6 +1143,15 @@ public: *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI); return *demangled != NULL; } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + c_print_type (type, varstring, stream, show, level, flags); + } }; /* The single instance of the C++ language class. */ @@ -1165,7 +1181,6 @@ extern const struct language_data asm_language_data = c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ - c_print_type, /* Print a type using appropriate syntax */ c_print_typedef, /* Print a typedef using appropriate syntax */ c_value_print_inner, /* la_value_print_inner */ c_value_print, /* Print a top-level value */ @@ -1206,6 +1221,15 @@ public: { c_language_arch_info (gdbarch, lai); } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + c_print_type (type, varstring, stream, show, level, flags); + } }; /* The single instance of the ASM language class. */ @@ -1232,7 +1256,6 @@ extern const struct language_data minimal_language_data = c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ - c_print_type, /* Print a type using appropriate syntax */ c_print_typedef, /* Print a typedef using appropriate syntax */ c_value_print_inner, /* la_value_print_inner */ c_value_print, /* Print a top-level value */ @@ -1271,6 +1294,15 @@ public: { c_language_arch_info (gdbarch, lai); } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + c_print_type (type, varstring, stream, show, level, flags); + } }; /* The single instance of the minimal language class. */ diff --git a/gdb/d-lang.c b/gdb/d-lang.c index 23b9464cb58..815b59734e0 100644 --- a/gdb/d-lang.c +++ b/gdb/d-lang.c @@ -147,7 +147,6 @@ extern const struct language_data d_language_data = c_printchar, /* Print a character constant. */ c_printstr, /* Function to print string constant. */ c_emit_char, /* Print a single char. */ - c_print_type, /* Print a type using appropriate syntax. */ c_print_typedef, /* Print a typedef using appropriate syntax. */ d_value_print_inner, /* la_value_print_inner */ @@ -252,6 +251,15 @@ public: *demangled = d_demangle (mangled, 0); return *demangled != NULL; } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + c_print_type (type, varstring, stream, show, level, flags); + } }; /* Single instance of the D language class. */ diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 804b2823f31..1b0fec68c0e 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -608,7 +608,6 @@ extern const struct language_data f_language_data = f_printchar, /* Print character constant */ f_printstr, /* function to print string constant */ f_emit_char, /* Function to print a single character */ - f_print_type, /* Print a type using appropriate syntax */ f_print_typedef, /* Print a typedef using appropriate syntax */ f_value_print_innner, /* la_value_print_inner */ c_value_print, /* FIXME */ @@ -690,6 +689,15 @@ public: { return cp_search_name_hash (name); } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + f_print_type (type, varstring, stream, show, level, flags); + } }; /* Single instance of the Fortran language class. */ diff --git a/gdb/go-lang.c b/gdb/go-lang.c index dce7e6ab769..1ec53474cf0 100644 --- a/gdb/go-lang.c +++ b/gdb/go-lang.c @@ -532,7 +532,6 @@ extern const struct language_data go_language_data = c_printchar, /* Print a character constant. */ c_printstr, /* Function to print string constant. */ c_emit_char, /* Print a single char. */ - go_print_type, /* Print a type using appropriate syntax. */ c_print_typedef, /* Print a typedef using appropriate syntax. */ go_value_print_inner, /* la_value_print_inner */ @@ -626,6 +625,15 @@ public: *demangled = go_demangle (mangled, 0); return *demangled != NULL; } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + go_print_type (type, varstring, stream, show, level, flags); + } }; /* Single instance of the Go language class. */ diff --git a/gdb/language.c b/gdb/language.c index 2a66f1fd6ea..c8f0349901b 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -727,15 +727,6 @@ unk_lang_printstr (struct ui_file *stream, struct type *type, "function unk_lang_printstr called.")); } -static void -unk_lang_print_type (struct type *type, const char *varstring, - struct ui_file *stream, int show, int level, - const struct type_print_options *flags) -{ - error (_("internal error - unimplemented " - "function unk_lang_print_type called.")); -} - static void unk_lang_value_print_inner (struct value *val, struct ui_file *stream, int recurse, @@ -802,7 +793,6 @@ extern const struct language_data unknown_language_data = unk_lang_printchar, /* Print character constant */ unk_lang_printstr, unk_lang_emit_char, - unk_lang_print_type, /* Print a type using appropriate syntax */ default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_value_print_inner, /* la_value_print_inner */ unk_lang_value_print, /* Print a top-level value */ @@ -841,6 +831,15 @@ public: { unknown_language_arch_info (gdbarch, lai); } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + error (_("unimplemented unknown_language::print_type called")); + } }; /* Single instance of the unknown language class. */ @@ -865,7 +864,6 @@ extern const struct language_data auto_language_data = unk_lang_printchar, /* Print character constant */ unk_lang_printstr, unk_lang_emit_char, - unk_lang_print_type, /* Print a type using appropriate syntax */ default_print_typedef, /* Print a typedef using appropriate syntax */ unk_lang_value_print_inner, /* la_value_print_inner */ unk_lang_value_print, /* Print a top-level value */ @@ -904,6 +902,15 @@ public: { unknown_language_arch_info (gdbarch, lai); } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + error (_("unimplemented auto_language::print_type called")); + } }; /* Single instance of the fake "auto" language. */ diff --git a/gdb/language.h b/gdb/language.h index d5013bf8324..8defe959015 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -248,11 +248,6 @@ struct language_data void (*la_emitchar) (int ch, struct type *chtype, struct ui_file * stream, int quoter); - /* Print a type using syntax appropriate for this language. */ - - void (*la_print_type) (struct type *, const char *, struct ui_file *, int, - int, const struct type_print_options *); - /* 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. */ @@ -517,6 +512,11 @@ struct language_defn : language_data return false; } + /* Print a type using syntax appropriate for this language. */ + + virtual void print_type (struct type *, const char *, struct ui_file *, int, + int, const struct type_print_options *) const = 0; + /* List of all known languages. */ static const struct language_defn *languages[nr_languages]; }; @@ -605,7 +605,7 @@ extern enum language set_language (enum language); with the "set language" command. */ #define LA_PRINT_TYPE(type,varstring,stream,show,level,flags) \ - (current_language->la_print_type(type,varstring,stream,show,level,flags)) + (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)) diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index fbfdcff71f3..098a2aadd95 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -367,7 +367,6 @@ extern const struct language_data m2_language_data = m2_printchar, /* Print character constant */ m2_printstr, /* function to print string constant */ m2_emit_char, /* Function to print a single character */ - m2_print_type, /* Print a type using appropriate syntax */ m2_print_typedef, /* Print a typedef using appropriate syntax */ m2_value_print_inner, /* la_value_print_inner */ c_value_print, /* Print a top-level value */ @@ -425,6 +424,15 @@ public: lai->bool_type_symbol = "BOOLEAN"; lai->bool_type_default = builtin->builtin_bool; } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + m2_print_type (type, varstring, stream, show, level, flags); + } }; /* Single instance of the M2 language. */ diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 3082a5d058a..0566ce8f188 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -373,7 +373,6 @@ extern const struct language_data objc_language_data = c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ c_emit_char, - c_print_type, /* Print a type using appropriate syntax */ c_print_typedef, /* Print a typedef using appropriate syntax */ c_value_print_inner, /* la_value_print_inner */ c_value_print, /* Print a top-level value */ @@ -420,6 +419,15 @@ public: *demangled = objc_demangle (mangled, 0); return *demangled != NULL; } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + c_print_type (type, varstring, stream, show, level, flags); + } }; /* Single instance of the class representing the Objective-C language. */ diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index 4080c51854f..d1ca29d32f7 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -994,27 +994,6 @@ Cannot perform conditional operation on vectors with different sizes")); return evaluate_subexp_c (expect_type, exp, pos, noside); } -/* Print OpenCL types. */ - -static void -opencl_print_type (struct type *type, const char *varstring, - struct ui_file *stream, int show, int level, - const struct type_print_options *flags) -{ - /* We nearly always defer to C type printing, except that vector - types are considered primitive in OpenCL, and should always - be printed using their TYPE_NAME. */ - if (show > 0) - { - type = check_typedef (type); - if (type->code () == TYPE_CODE_ARRAY && TYPE_VECTOR (type) - && type->name () != NULL) - show = 0; - } - - c_print_type (type, varstring, stream, show, level, flags); -} - const struct exp_descriptor exp_descriptor_opencl = { print_subexp_standard, @@ -1042,7 +1021,6 @@ extern const struct language_data opencl_language_data = c_printchar, /* Print a character constant */ c_printstr, /* Function to print string constant */ c_emit_char, /* Print a single char */ - opencl_print_type, /* Print a type using appropriate syntax */ c_print_typedef, /* Print a typedef using appropriate syntax */ c_value_print_inner, /* la_value_print_inner */ c_value_print, /* Print a top-level value */ @@ -1091,6 +1069,26 @@ public: lai->bool_type_symbol = "int"; lai->bool_type_default = types [opencl_primitive_type_int]; } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + /* We nearly always defer to C type printing, except that vector types + are considered primitive in OpenCL, and should always be printed + using their TYPE_NAME. */ + if (show > 0) + { + type = check_typedef (type); + if (type->code () == TYPE_CODE_ARRAY && TYPE_VECTOR (type) + && type->name () != NULL) + show = 0; + } + + c_print_type (type, varstring, stream, show, level, flags); + } }; /* Single instance of the OpenCL language class. */ diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 8d96dd15832..9aa03de6a59 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -398,7 +398,6 @@ extern const struct language_data pascal_language_data = pascal_printchar, /* Print a character constant */ pascal_printstr, /* Function to print string constant */ pascal_emit_char, /* Print a single char */ - pascal_print_type, /* Print a type using appropriate syntax */ pascal_print_typedef, /* Print a typedef using appropriate syntax */ pascal_value_print_inner, /* la_value_print_inner */ pascal_value_print, /* Print a top-level value */ @@ -478,6 +477,15 @@ public: lai->bool_type_symbol = "boolean"; lai->bool_type_default = builtin->builtin_bool; } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + pascal_print_type (type, varstring, stream, show, level, flags); + } }; /* Single instance of the Pascal language class. */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index d75f34d0d9a..f78686ae1c8 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -951,16 +951,6 @@ rust_internal_print_type (struct type *type, const char *varstring, } } -static void -rust_print_type (struct type *type, const char *varstring, - struct ui_file *stream, int show, int level, - const struct type_print_options *flags) -{ - print_offset_data podata; - rust_internal_print_type (type, varstring, stream, show, level, - flags, false, &podata); -} - /* Like arch_composite_type, but uses TYPE to decide how to allocate @@ -2063,7 +2053,6 @@ extern const struct language_data rust_language_data = rust_printchar, /* Print a character constant */ rust_printstr, /* Function to print string constant */ rust_emitchar, /* Print a single char */ - rust_print_type, /* Print a type using appropriate syntax */ rust_print_typedef, /* Print a typedef using appropriate syntax */ rust_value_print_inner, /* la_value_print_inner */ c_value_print, /* Print a top-level value */ @@ -2144,6 +2133,17 @@ public: *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI); return *demangled != NULL; } + + /* See language.h. */ + + void print_type (struct type *type, const char *varstring, + struct ui_file *stream, int show, int level, + const struct type_print_options *flags) const override + { + print_offset_data podata; + rust_internal_print_type (type, varstring, stream, show, level, + flags, false, &podata); + } }; /* Single instance of the Rust language class. */