[PATCHv2 11/13] gdb: Convert language la_print_type field to a method
Andrew Burgess
andrew.burgess@embecosm.com
Fri May 15 15:06:50 GMT 2020
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/ada-lang.c b/gdb/ada-lang.c
index 7ad53956c45..10b4c97b801 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13916,7 +13916,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 */
@@ -14100,6 +14099,15 @@ class ada_language : public language_defn
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 be09d45478e..79e4494aa4d 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 @@ class c_language : public language_defn
{
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 @@ class cplus_language : public language_defn
*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 @@ class asm_language : public language_defn
{
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 @@ class minimal_language : public language_defn
{
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 @@ class d_language : public language_defn
*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 @@ class f_language : public language_defn
{
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 eb89dc598b7..36a46a403e2 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 @@ class go_language : public language_defn
*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 2b46452f3b8..7df47b3ddee 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -726,15 +726,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,
@@ -801,7 +792,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 */
@@ -840,6 +830,15 @@ class unknown_language : public language_defn
{
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. */
@@ -864,7 +863,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 */
@@ -903,6 +901,15 @@ class auto_language : public language_defn
{
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 78721de8e59..dd415bbef85 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. */
@@ -516,6 +511,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];
};
@@ -604,7 +604,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 e27e11d9b52..68aad7d7367 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 @@ class m2_language : public language_defn
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 @@ class objc_language : public language_defn
*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 41598a0bec3..481fe1dba47 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 (type) != 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 @@ class opencl_language : public language_defn
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 (type) != 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 448637cbada..82277739ec9 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 @@ class pascal_language : public language_defn
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 c9531579e8f..53dd7761847 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 @@ class rust_language : public language_defn
*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. */
--
2.25.4
More information about the Gdb-patches
mailing list