gdb: Convert language la_sniff_from_mangled_name field to a method

This commit changes the language_data::la_sniff_from_mangled_name
function pointer member variable into a member function of
language_defn.

Previously the la_sniff_from_mangled_name pointer was NULL for some
languages, however, all uses of this function pointer were through the
function language_sniff_from_mangled_name which provided a default
implementation.

This default implementation now becomes the implementation in the base
class language_defn, which is then overridden as required in various
language sub-classes.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_sniff_from_mangled_name): Delete function,
	implementation moves to...
	(ada_language::sniff_from_mangled_name): ...here.  Update return
	type.
	(ada_language_data): Delete la_sniff_from_mangled_name
	initializer.
	* c-lang.c (c_language_data): Likewise.
	(cplus_language_data): Likewise.
	(cplus_language::sniff_from_mangled_name): New member function,
	implementation taken from gdb_sniff_from_mangled_name.
	(asm_language_data): Delete la_sniff_from_mangled_name
	initializer.
	(minimal_language_data): Likewise.
	* cp-support.c (gdb_sniff_from_mangled_name): Delete,
	implementation moves to cplus_language::sniff_from_mangled_name.
	* cp-support.h (gdb_sniff_from_mangled_name): Delete declaration.
	* d-lang.c (d_sniff_from_mangled_name): Delete, implementation
	moves to...
	(d_language::sniff_from_mangled_name): ...here.
	(d_language_data): Delete la_sniff_from_mangled_name initializer.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_sniff_from_mangled_name): Delete, implementation
	moves to...
	(go_language::sniff_from_mangled_name): ...here.
	(go_language_data): Delete la_sniff_from_mangled_name initializer.
	* language.c (language_sniff_from_mangled_name): Delete.
	(unknown_language_data): Delete la_sniff_from_mangled_name
	initializer.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_sniff_from_mangled_name
	field.
	(language_defn::sniff_from_mangled_name): New function.
	(language_sniff_from_mangled_name): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_sniff_from_mangled_name
	field.
	* objc-lang.c (objc_sniff_from_mangled_name): Delete,
	implementation moves to...
	(objc_language::sniff_from_mangled_name): ...here.
	(objc_language_data): Delete la_sniff_from_mangled_name initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* rust-lang.c (rust_sniff_from_mangled_name): Delete,
	implementation moves to...
	(rust_language::sniff_from_mangled_name): ...here.
	(rust_language_data): Delete la_sniff_from_mangled_name
	initializer.
	* symtab.c (symbol_find_demangled_name): Call
	sniff_from_mangled_name member function.
This commit is contained in:
Andrew Burgess 2020-05-13 18:04:30 +01:00
parent fb8006fd35
commit 6f8270197a
16 changed files with 152 additions and 147 deletions

View file

@ -1377,45 +1377,6 @@ ada_la_decode (const char *encoded, int options)
return xstrdup (ada_decode (encoded).c_str ());
}
/* Implement la_sniff_from_mangled_name for Ada. */
static int
ada_sniff_from_mangled_name (const char *mangled, char **out)
{
std::string demangled = ada_decode (mangled);
*out = NULL;
if (demangled != mangled && demangled[0] != '<')
{
/* Set the gsymbol language to Ada, but still return 0.
Two reasons for that:
1. For Ada, we prefer computing the symbol's decoded name
on the fly rather than pre-compute it, in order to save
memory (Ada projects are typically very large).
2. There are some areas in the definition of the GNAT
encoding where, with a bit of bad luck, we might be able
to decode a non-Ada symbol, generating an incorrect
demangled name (Eg: names ending with "TB" for instance
are identified as task bodies and so stripped from
the decoded name returned).
Returning 1, here, but not setting *DEMANGLED, helps us get a
little bit of the best of both worlds. Because we're last,
we should not affect any of the other languages that were
able to demangle the symbol before us; we get to correctly
tag Ada symbols as such; and even if we incorrectly tagged a
non-Ada symbol, which should be rare, any routing through the
Ada language should be transparent (Ada tries to behave much
like C/C++ with non-Ada symbols). */
return 1;
}
return 0;
}
/* Arrays */
@ -13967,7 +13928,6 @@ extern const struct language_data ada_language_data =
true, /* la_store_sym_names_in_linkage_form_p */
ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */
ada_la_decode, /* Language specific symbol demangler */
ada_sniff_from_mangled_name,
NULL, /* Language specific
class_name_from_physname */
ada_op_print_tab, /* expression operators for printing */
@ -14108,6 +14068,44 @@ public:
return true;
}
/* See language.h. */
bool sniff_from_mangled_name (const char *mangled,
char **out) const override
{
std::string demangled = ada_decode (mangled);
*out = NULL;
if (demangled != mangled && demangled[0] != '<')
{
/* Set the gsymbol language to Ada, but still return 0.
Two reasons for that:
1. For Ada, we prefer computing the symbol's decoded name
on the fly rather than pre-compute it, in order to save
memory (Ada projects are typically very large).
2. There are some areas in the definition of the GNAT
encoding where, with a bit of bad luck, we might be able
to decode a non-Ada symbol, generating an incorrect
demangled name (Eg: names ending with "TB" for instance
are identified as task bodies and so stripped from
the decoded name returned).
Returning true, here, but not setting *DEMANGLED, helps us get
a little bit of the best of both worlds. Because we're last,
we should not affect any of the other languages that were
able to demangle the symbol before us; we get to correctly
tag Ada symbols as such; and even if we incorrectly tagged a
non-Ada symbol, which should be rare, any routing through the
Ada language should be transparent (Ada tries to behave much
like C/C++ with non-Ada symbols). */
return true;
}
return false;
}
};
/* Single instance of the Ada language class. */