gdb: Convert language la_get_symbol_name_matcher field to a method

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

There should be no user visible changes after this commit.

Before this commit access to the la_get_symbol_name_matcher function
pointer was through the get_symbol_name_matcher function, which looked
something like this (is pseudo-code):

  <return-type>
  get_symbol_name_matcher (language_defn *lang, <other args>)
  {
    if (current_language == ada)
      current_language->la_get_symbol_name_matcher (<other args>);
    else
      lang->la_get_symbol_name_matcher (<other args>);
  }

In this commit I moved the get_symbol_name_matcher as a non-virtual
function in the language_defn base class, I then add a new virtual
method that is only used from within get_symbol_name_matcher, this can
then be overridden by specific languages as needed.  So we now have:

  class language_defn
  {
    <return-type> get_symbol_name_matcher (<args>)
    {
      if (current_language == ada)
        return current_language->get_symbol_name_matcher_inner (<args>);
      else
        return this->get_symbol_name_matcher_inner (<args>);
    }

    virtual <return-type> get_symbol_name_matcher_inner (<args>)
    {
        ....
    }
  }

gdb/ChangeLog:

	* ada-lang.c (ada_get_symbol_name_matcher): Update header comment.
	(ada_language_data): Delete la_get_symbol_name_matcher
	initializer.
	(language_defn::get_symbol_name_matcher_inner): New member
	function.
	* c-lang.c (c_language_data): Delete la_get_symbol_name_matcher
	initializer.
	(cplus_language_data): Likewise.
	(cplus_language::get_symbol_name_matcher_inner): New member
	function.
	(asm_language_data): Delete la_get_symbol_name_matcher initializer.
	(minimal_language_data): Likewise.
	* cp-support.h (cp_get_symbol_name_matcher): Update header comment.
	* d-lang.c (d_language_data): Delete la_get_symbol_name_matcher
	initializer.
	* dictionary.c (iter_match_first_hashed): Update call to
	get_symbol_name_matcher.
	(iter_match_next_hashed): Likewise.
	(iter_match_next_linear): Likewise.
	* dwarf2/read.c (dw2_expand_symtabs_matching_symbol): Likewise.
	* f-lang.c (f_language_data): Delete la_get_symbol_name_matcher
	initializer.
	(f_language::get_symbol_name_matcher_inner): New member function.
	* go-lang.c (go_language_data): Delete la_get_symbol_name_matcher
	initializer.
	* language.c (default_symbol_name_matcher): Update header comment,
	make static.
	(language_defn::get_symbol_name_matcher): New definition.
	(language_defn::get_symbol_name_matcher_inner): Likewise.
	(get_symbol_name_matcher): Delete.
	(unknown_language_data): Delete la_get_symbol_name_matcher
	initializer.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_get_symbol_name_matcher
	field.
	(language_defn::get_symbol_name_matcher): New member function.
	(language_defn::get_symbol_name_matcher_inner): Likewise.
	(default_symbol_name_matcher): Delete declaration.
	* linespec.c (find_methods): Update call to
	get_symbol_name_matcher.
	* m2-lang.c (m2_language_data): Delete la_get_symbol_name_matcher
	initializer.
	* minsyms.c (lookup_minimal_symbol): Update call to
	get_symbol_name_matcher.
	(iterate_over_minimal_symbols): Likewise.
	* objc-lang.c (objc_language_data): Delete
	la_get_symbol_name_matcher initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* psymtab.c (psymbol_name_matches): Update call to
	get_symbol_name_matcher.
	* rust-lang.c (rust_language_data): Delete
	la_get_symbol_name_matcher initializer.
	* symtab.c (symbol_matches_search_name): Update call to
	get_symbol_name_matcher.
	(compare_symbol_name): Likewise.
This commit is contained in:
Andrew Burgess 2020-06-01 11:46:54 +01:00
parent 9a49ad8c52
commit c9debfb97e
20 changed files with 151 additions and 69 deletions

View File

@ -1,3 +1,62 @@
2020-06-17 Andrew Burgess <andrew.burgess@embecosm.com>
* ada-lang.c (ada_get_symbol_name_matcher): Update header comment.
(ada_language_data): Delete la_get_symbol_name_matcher
initializer.
(language_defn::get_symbol_name_matcher_inner): New member
function.
* c-lang.c (c_language_data): Delete la_get_symbol_name_matcher
initializer.
(cplus_language_data): Likewise.
(cplus_language::get_symbol_name_matcher_inner): New member
function.
(asm_language_data): Delete la_get_symbol_name_matcher initializer.
(minimal_language_data): Likewise.
* cp-support.h (cp_get_symbol_name_matcher): Update header comment.
* d-lang.c (d_language_data): Delete la_get_symbol_name_matcher
initializer.
* dictionary.c (iter_match_first_hashed): Update call to
get_symbol_name_matcher.
(iter_match_next_hashed): Likewise.
(iter_match_next_linear): Likewise.
* dwarf2/read.c (dw2_expand_symtabs_matching_symbol): Likewise.
* f-lang.c (f_language_data): Delete la_get_symbol_name_matcher
initializer.
(f_language::get_symbol_name_matcher_inner): New member function.
* go-lang.c (go_language_data): Delete la_get_symbol_name_matcher
initializer.
* language.c (default_symbol_name_matcher): Update header comment,
make static.
(language_defn::get_symbol_name_matcher): New definition.
(language_defn::get_symbol_name_matcher_inner): Likewise.
(get_symbol_name_matcher): Delete.
(unknown_language_data): Delete la_get_symbol_name_matcher
initializer.
(auto_language_data): Likewise.
* language.h (language_data): Delete la_get_symbol_name_matcher
field.
(language_defn::get_symbol_name_matcher): New member function.
(language_defn::get_symbol_name_matcher_inner): Likewise.
(default_symbol_name_matcher): Delete declaration.
* linespec.c (find_methods): Update call to
get_symbol_name_matcher.
* m2-lang.c (m2_language_data): Delete la_get_symbol_name_matcher
initializer.
* minsyms.c (lookup_minimal_symbol): Update call to
get_symbol_name_matcher.
(iterate_over_minimal_symbols): Likewise.
* objc-lang.c (objc_language_data): Delete
la_get_symbol_name_matcher initializer.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* psymtab.c (psymbol_name_matches): Update call to
get_symbol_name_matcher.
* rust-lang.c (rust_language_data): Delete
la_get_symbol_name_matcher initializer.
* symtab.c (symbol_matches_search_name): Update call to
get_symbol_name_matcher.
(compare_symbol_name): Likewise.
2020-06-17 Andrew Burgess <andrew.burgess@embecosm.com>
* ada-lang.c (ada_language_data): Delete la_compute_program

View File

@ -13862,7 +13862,7 @@ literal_symbol_name_matcher (const char *symbol_search_name,
return false;
}
/* Implement the "la_get_symbol_name_matcher" language_defn method for
/* Implement the "get_symbol_name_matcher" language_defn method for
Ada. */
static symbol_name_matcher_ftype *
@ -13920,7 +13920,6 @@ extern const struct language_data ada_language_data =
ada_get_gdb_completer_word_break_characters,
ada_collect_symbol_completion_matches,
ada_watch_location_expression,
ada_get_symbol_name_matcher, /* la_get_symbol_name_matcher */
&ada_varobj_ops,
ada_is_string_type,
"(...)" /* la_struct_too_deep_ellipsis */
@ -14105,6 +14104,15 @@ public:
{
ada_print_type (type, varstring, stream, show, level, flags);
}
protected:
/* See language.h. */
symbol_name_matcher_ftype *get_symbol_name_matcher_inner
(const lookup_name_info &lookup_name) const override
{
return ada_get_symbol_name_matcher (lookup_name);
}
};
/* Single instance of the Ada language class. */

View File

@ -917,7 +917,6 @@ extern const struct language_data c_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&c_varobj_ops,
c_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */
@ -1032,7 +1031,6 @@ extern const struct language_data cplus_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
cp_get_symbol_name_matcher,
&cplus_varobj_ops,
c_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */
@ -1184,6 +1182,16 @@ public:
{
return cp_class_name_from_physname (physname);
}
protected:
/* See language.h. */
symbol_name_matcher_ftype *get_symbol_name_matcher_inner
(const lookup_name_info &lookup_name) const override
{
return cp_get_symbol_name_matcher (lookup_name);
}
};
/* The single instance of the C++ language class. */
@ -1225,7 +1233,6 @@ extern const struct language_data asm_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
c_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */
@ -1295,7 +1302,6 @@ extern const struct language_data minimal_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
c_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */

View File

@ -127,8 +127,7 @@ extern struct type *cp_lookup_rtti_type (const char *name,
"function" or "bar::function" in all namespaces is possible. */
extern unsigned int cp_search_name_hash (const char *search_name);
/* Implement the "la_get_symbol_name_matcher" language_defn method for
C++. */
/* Implement the "get_symbol_name_matcher" language_defn method for C++. */
extern symbol_name_matcher_ftype *cp_get_symbol_name_matcher
(const lookup_name_info &lookup_name);

View File

@ -160,7 +160,6 @@ extern const struct language_data d_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
c_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */

View File

@ -584,7 +584,7 @@ iter_match_first_hashed (const struct dictionary *dict,
unsigned int hash_index = (name.search_name_hash (lang->la_language)
% DICT_HASHED_NBUCKETS (dict));
symbol_name_matcher_ftype *matches_name
= get_symbol_name_matcher (lang, name);
= lang->get_symbol_name_matcher (name);
struct symbol *sym;
DICT_ITERATOR_DICT (iterator) = dict;
@ -612,7 +612,7 @@ iter_match_next_hashed (const lookup_name_info &name,
{
const language_defn *lang = DICT_LANGUAGE (DICT_ITERATOR_DICT (iterator));
symbol_name_matcher_ftype *matches_name
= get_symbol_name_matcher (lang, name);
= lang->get_symbol_name_matcher (name);
struct symbol *next;
for (next = DICT_ITERATOR_CURRENT (iterator)->hash_next;
@ -828,7 +828,7 @@ iter_match_next_linear (const lookup_name_info &name,
const struct dictionary *dict = DICT_ITERATOR_DICT (iterator);
const language_defn *lang = DICT_LANGUAGE (dict);
symbol_name_matcher_ftype *matches_name
= get_symbol_name_matcher (lang, name);
= lang->get_symbol_name_matcher (name);
int i, nsyms = DICT_LINEAR_NSYMS (dict);
struct symbol *sym, *retval = NULL;

View File

@ -4097,7 +4097,7 @@ dw2_expand_symtabs_matching_symbol
const language_defn *lang = language_def (lang_e);
symbol_name_matcher_ftype *name_matcher
= get_symbol_name_matcher (lang, lookup_name_without_params);
= lang->get_symbol_name_matcher (lookup_name_without_params);
name_and_matcher key {
name_matcher,

View File

@ -620,7 +620,6 @@ extern const struct language_data f_language_data =
f_word_break_characters,
f_collect_symbol_completion_matches,
c_watch_location_expression,
cp_get_symbol_name_matcher, /* la_get_symbol_name_matcher */
&default_varobj_ops,
f_is_string_type_p,
"(...)" /* la_struct_too_deep_ellipsis */
@ -699,6 +698,16 @@ public:
{
f_print_type (type, varstring, stream, show, level, flags);
}
protected:
/* See language.h. */
symbol_name_matcher_ftype *get_symbol_name_matcher_inner
(const lookup_name_info &lookup_name) const override
{
return cp_get_symbol_name_matcher (lookup_name);
}
};
/* Single instance of the Fortran language class. */

View File

@ -545,7 +545,6 @@ extern const struct language_data go_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
go_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */

View File

@ -622,9 +622,10 @@ language_defn::print_array_index (struct type *index_type, LONGEST index,
fprintf_filtered (stream, "] = ");
}
/* See language.h. */
/* The default implementation of the get_symbol_name_matcher_inner method
from the language_defn class. Matches with strncmp_iw. */
bool
static bool
default_symbol_name_matcher (const char *symbol_search_name,
const lookup_name_info &lookup_name,
completion_match_result *comp_match_res)
@ -649,6 +650,31 @@ default_symbol_name_matcher (const char *symbol_search_name,
/* See language.h. */
symbol_name_matcher_ftype *
language_defn::get_symbol_name_matcher
(const lookup_name_info &lookup_name) const
{
/* If currently in Ada mode, and the lookup name is wrapped in
'<...>', hijack all symbol name comparisons using the Ada
matcher, which handles the verbatim matching. */
if (current_language->la_language == language_ada
&& lookup_name.ada ().verbatim_p ())
return current_language->get_symbol_name_matcher_inner (lookup_name);
return this->get_symbol_name_matcher_inner (lookup_name);
}
/* See language.h. */
symbol_name_matcher_ftype *
language_defn::get_symbol_name_matcher_inner
(const lookup_name_info &lookup_name) const
{
return default_symbol_name_matcher;
}
/* See language.h. */
bool
default_is_string_type_p (struct type *type)
{
@ -661,24 +687,6 @@ default_is_string_type_p (struct type *type)
return (type->code () == TYPE_CODE_STRING);
}
/* See language.h. */
symbol_name_matcher_ftype *
get_symbol_name_matcher (const language_defn *lang,
const lookup_name_info &lookup_name)
{
/* If currently in Ada mode, and the lookup name is wrapped in
'<...>', hijack all symbol name comparisons using the Ada
matcher, which handles the verbatim matching. */
if (current_language->la_language == language_ada
&& lookup_name.ada ().verbatim_p ())
return current_language->la_get_symbol_name_matcher (lookup_name);
if (lang->la_get_symbol_name_matcher != nullptr)
return lang->la_get_symbol_name_matcher (lookup_name);
return default_symbol_name_matcher;
}
/* Define the language that is no language. */
static int
@ -774,7 +782,6 @@ extern const struct language_data unknown_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
default_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */
@ -848,7 +855,6 @@ extern const struct language_data auto_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
default_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */

View File

@ -338,19 +338,6 @@ struct language_data
gdb::unique_xmalloc_ptr<char> (*la_watch_location_expression)
(struct type *type, CORE_ADDR addr);
/* Return a pointer to the function that should be used to match a
symbol name against LOOKUP_NAME, according to this language's
rules. The matching algorithm depends on LOOKUP_NAME. For
example, on Ada, the matching algorithm depends on the symbol
name (wild/full/verbatim matching), and on whether we're doing
a normal lookup or a completion match lookup.
This field may be NULL, in which case
default_symbol_name_matcher is used to perform the
matching. */
symbol_name_matcher_ftype *(*la_get_symbol_name_matcher)
(const lookup_name_info &);
/* Various operations on varobj. */
const struct lang_varobj_ops *la_varobj_ops;
@ -443,6 +430,20 @@ struct language_defn : language_data
return ::iterate_over_symbols (block, name, domain, callback);
}
/* Return a pointer to the function that should be used to match a
symbol name against LOOKUP_NAME, according to this language's
rules. The matching algorithm depends on LOOKUP_NAME. For
example, on Ada, the matching algorithm depends on the symbol
name (wild/full/verbatim matching), and on whether we're doing
a normal lookup or a completion match lookup.
As Ada wants to capture symbol matching for all languages in some
cases, then this method is a non-overridable interface. Languages
should override GET_SYMBOL_NAME_MATCHER_INNER if they need to. */
symbol_name_matcher_ftype *get_symbol_name_matcher
(const lookup_name_info &lookup_name) const;
/* If this language allows compilation from the gdb command line, then
this method will return an instance of struct gcc_context appropriate
to the language. If compilation for this language is generally
@ -530,6 +531,14 @@ struct language_defn : language_data
/* List of all known languages. */
static const struct language_defn *languages[nr_languages];
protected:
/* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
See that method for a description of the arguments. */
virtual symbol_name_matcher_ftype *get_symbol_name_matcher_inner
(const lookup_name_info &lookup_name) const;
};
/* Pointer to the language_defn for our current language. This pointer
@ -698,13 +707,6 @@ void c_get_string (struct value *value,
int *length, struct type **char_type,
const char **charset);
/* The default implementation of la_symbol_name_matcher. Matches with
strncmp_iw. */
extern bool default_symbol_name_matcher
(const char *symbol_search_name,
const lookup_name_info &lookup_name,
completion_match_result *comp_match_res);
/* Get LANG's symbol_name_matcher method for LOOKUP_NAME. Returns
default_symbol_name_matcher if not set. LANG is used as a hint;
the function may ignore it depending on the current language and

View File

@ -1232,7 +1232,7 @@ find_methods (struct type *t, enum language t_lang, const char *name,
int method_counter;
lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
symbol_name_matcher_ftype *symbol_name_compare
= get_symbol_name_matcher (language_def (t_lang), lookup_name);
= language_def (t_lang)->get_symbol_name_matcher (lookup_name);
t = check_typedef (t);

View File

@ -379,7 +379,6 @@ extern const struct language_data m2_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
m2_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */

View File

@ -363,8 +363,8 @@ lookup_minimal_symbol (const char *name, const char *sfile,
% MINIMAL_SYMBOL_HASH_SIZE);
symbol_name_matcher_ftype *match
= get_symbol_name_matcher (language_def (lang),
lookup_name);
= language_def (lang)->get_symbol_name_matcher
(lookup_name);
struct minimal_symbol **msymbol_demangled_hash
= objfile->per_bfd->msymbol_demangled_hash;
@ -507,7 +507,7 @@ iterate_over_minimal_symbols
enum language lang = (enum language) liter;
const language_defn *lang_def = language_def (lang);
symbol_name_matcher_ftype *name_match
= get_symbol_name_matcher (lang_def, lookup_name);
= lang_def->get_symbol_name_matcher (lookup_name);
unsigned int hash
= lookup_name.search_name_hash (lang) % MINIMAL_SYMBOL_HASH_SIZE;

View File

@ -354,7 +354,6 @@ extern const struct language_data objc_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
c_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */

View File

@ -1033,7 +1033,6 @@ extern const struct language_data opencl_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
c_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */

View File

@ -410,7 +410,6 @@ extern const struct language_data pascal_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
c_watch_location_expression,
NULL, /* la_compare_symbol_for_completion */
&default_varobj_ops,
pascal_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */

View File

@ -557,7 +557,7 @@ psymbol_name_matches (partial_symbol *psym,
{
const language_defn *lang = language_def (psym->ginfo.language ());
symbol_name_matcher_ftype *name_match
= get_symbol_name_matcher (lang, lookup_name);
= lang->get_symbol_name_matcher (lookup_name);
return name_match (psym->ginfo.search_name (), lookup_name, NULL);
}

View File

@ -2065,7 +2065,6 @@ extern const struct language_data rust_language_data =
default_word_break_characters,
default_collect_symbol_completion_matches,
rust_watch_location_expression,
NULL, /* la_get_symbol_name_matcher */
&default_varobj_ops,
rust_is_string_type_p,
"{...}" /* la_struct_too_deep_ellipsis */

View File

@ -1016,7 +1016,7 @@ symbol_matches_search_name (const struct general_symbol_info *gsymbol,
const lookup_name_info &name)
{
symbol_name_matcher_ftype *name_match
= get_symbol_name_matcher (language_def (gsymbol->language ()), name);
= language_def (gsymbol->language ())->get_symbol_name_matcher (name);
return name_match (gsymbol->search_name (), name, NULL);
}
@ -5258,7 +5258,7 @@ compare_symbol_name (const char *symbol_name, language symbol_language,
const language_defn *lang = language_def (symbol_language);
symbol_name_matcher_ftype *name_match
= get_symbol_name_matcher (lang, lookup_name);
= lang->get_symbol_name_matcher (lookup_name);
return name_match (symbol_name, lookup_name, &match_res);
}