[PATCH 9/9] gdb: Convert language la_search_name_hash field to a method

Christian Biesinger cbiesinger@google.com
Tue May 12 21:10:08 GMT 2020


On Mon, May 11, 2020 at 5:36 PM Andrew Burgess
<andrew.burgess@embecosm.com> wrote:
>
> This commit changes the language_data::la_search_name_hash
> 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_search_name_hash
>         initializer.
>         * c-lang.c (c_language_data): Likewise.
>         (cplus_language_data): Likewise.
>         (cplus_language::search_name_hash): New member function.
>         (asm_language_data): Delete la_search_name_hash initializer.
>         (minimal_language_data): Likewise.
>         * d-lang.c (d_language_data): Likewise.
>         * f-lang.c (f_language_data): Likewise.
>         (f_language::search_name_hash): New member function.
>         * go-lang.c (go_language_data): Delete la_search_name_hash
>         initializer.
>         * language.c (unknown_language_data): Likewise.
>         (auto_language_data): Likewise.
>         * language.h (default_search_name_hash): Move declaration of
>         function to here from later in the file.
>         (struct language_data): Delete la_search_name_hash field.
>         (language_defn::search_name_hash): New member function.
>         * m2-lang.c (m2_language_data): Delete la_search_name_hash
>         initializer.
>         * objc-lang.c (objc_language_data): Likewise.
>         * opencl-lang.c (opencl_language_data): Likewise.
>         * p-lang.c (pascal_language_data): Likewise.
>         * rust-lang.c (rust_language_data): Likewise.
>         * symtab.c (search_name_hash): Update call.
> ---
>  gdb/ChangeLog     | 28 ++++++++++++++++++++++++++++
>  gdb/ada-lang.c    |  1 -
>  gdb/c-lang.c      | 10 ++++++----
>  gdb/d-lang.c      |  1 -
>  gdb/f-lang.c      |  7 ++++++-
>  gdb/go-lang.c     |  1 -
>  gdb/language.c    |  2 --
>  gdb/language.h    | 27 ++++++++++++++-------------
>  gdb/m2-lang.c     |  1 -
>  gdb/objc-lang.c   |  1 -
>  gdb/opencl-lang.c |  1 -
>  gdb/p-lang.c      |  1 -
>  gdb/rust-lang.c   |  1 -
>  gdb/symtab.c      |  2 +-
>  14 files changed, 55 insertions(+), 29 deletions(-)
>
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index 73f3f52b2e4..e9d9a402a95 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -13988,7 +13988,6 @@ extern const struct language_data ada_language_data =
>    ada_collect_symbol_completion_matches,
>    ada_watch_location_expression,
>    ada_get_symbol_name_matcher, /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &ada_varobj_ops,
>    NULL,
>    ada_is_string_type,
> diff --git a/gdb/c-lang.c b/gdb/c-lang.c
> index 30adb86581e..757b68d4cce 100644
> --- a/gdb/c-lang.c
> +++ b/gdb/c-lang.c
> @@ -924,7 +924,6 @@ extern const struct language_data c_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &c_varobj_ops,
>    c_compute_program,
>    c_is_string_type_p,
> @@ -1028,7 +1027,6 @@ extern const struct language_data cplus_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    cp_get_symbol_name_matcher,
> -  cp_search_name_hash,
>    &cplus_varobj_ops,
>    cplus_compute_program,
>    c_is_string_type_p,
> @@ -1126,6 +1124,12 @@ class cplus_language : public language_defn
>    {
>      return cplus_get_compile_context ();
>    }
> +
> +  /* See language.h.  */
> +  unsigned int search_name_hash (const char *name) const override
> +  {
> +    return cp_search_name_hash (name);
> +  }
>  };
>
>  /* The single instance of the C++ language class.  */
> @@ -1174,7 +1178,6 @@ extern const struct language_data asm_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> @@ -1243,7 +1246,6 @@ extern const struct language_data minimal_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> diff --git a/gdb/d-lang.c b/gdb/d-lang.c
> index 08b884de733..c6ee6a231e6 100644
> --- a/gdb/d-lang.c
> +++ b/gdb/d-lang.c
> @@ -176,7 +176,6 @@ extern const struct language_data d_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> diff --git a/gdb/f-lang.c b/gdb/f-lang.c
> index b80adec8eb0..a28bb8c0c96 100644
> --- a/gdb/f-lang.c
> +++ b/gdb/f-lang.c
> @@ -633,7 +633,6 @@ extern const struct language_data f_language_data =
>    f_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    cp_get_symbol_name_matcher,  /* la_get_symbol_name_matcher */
> -  cp_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    f_is_string_type_p,
> @@ -686,6 +685,12 @@ class f_language : public language_defn
>      lai->bool_type_symbol = "logical";
>      lai->bool_type_default = builtin->builtin_logical_s2;
>    }
> +
> +  /* See language.h.  */
> +  unsigned int search_name_hash (const char *name) const override
> +  {
> +    return cp_search_name_hash (name);
> +  }
>  };
>
>  /* Single instance of the Fortran language class.  */
> diff --git a/gdb/go-lang.c b/gdb/go-lang.c
> index 6c0633ccebc..5b6e2f04425 100644
> --- a/gdb/go-lang.c
> +++ b/gdb/go-lang.c
> @@ -561,7 +561,6 @@ extern const struct language_data go_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    go_is_string_type_p,
> diff --git a/gdb/language.c b/gdb/language.c
> index 2a0ef94be30..99f211e36c1 100644
> --- a/gdb/language.c
> +++ b/gdb/language.c
> @@ -862,7 +862,6 @@ extern const struct language_data unknown_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    default_is_string_type_p,
> @@ -927,7 +926,6 @@ extern const struct language_data auto_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    default_is_string_type_p,
> diff --git a/gdb/language.h b/gdb/language.h
> index 44cb1683e6c..053b5c944ac 100644
> --- a/gdb/language.h
> +++ b/gdb/language.h
> @@ -169,6 +169,14 @@ struct language_pass_by_ref_info
>    bool destructible = true;
>  };
>
> +/* Default name hashing function.
> +
> +   Produce an unsigned hash value from SEARCH_NAME that is consistent
> +   with strcmp_iw, strcmp, and, at least on Ada symbols, wild_match.
> +   That is, two identifiers equivalent according to any of those three
> +   comparison operators hash to the same value.  */
> +extern unsigned int default_search_name_hash (const char *search_name);

I like this change in general! Question about this line... is this
function still needed elsewhere or could it just become part of the
default search_name_hash impl?

> +
>  /* Structure tying together assorted information about a language.
>
>     As we move over from the old structure based languages to a class
> @@ -384,11 +392,6 @@ struct language_data
>      symbol_name_matcher_ftype *(*la_get_symbol_name_matcher)
>        (const lookup_name_info &);
>
> -    /* Hash the given symbol search name.  Use
> -       default_search_name_hash if no special treatment is
> -       required.  */
> -    unsigned int (*la_search_name_hash) (const char *name);
> -
>      /* Various operations on varobj.  */
>      const struct lang_varobj_ops *la_varobj_ops;
>
> @@ -510,6 +513,12 @@ struct language_defn : language_data
>      return nullptr;
>    }
>
> +  /* Hash the given symbol search name.  */
> +  virtual unsigned int search_name_hash (const char *name) const
> +  {
> +    return default_search_name_hash (name);
> +  }
> +
>    /* List of all known languages.  */
>    static const struct language_defn *languages[nr_languages];
>  };
> @@ -690,14 +699,6 @@ struct language_pass_by_ref_info default_pass_by_reference (struct type *type);
>  void default_print_typedef (struct type *type, struct symbol *new_symbol,
>                             struct ui_file *stream);
>
> -/* Default name hashing function.  */
> -
> -/* Produce an unsigned hash value from SEARCH_NAME that is consistent
> -   with strcmp_iw, strcmp, and, at least on Ada symbols, wild_match.
> -   That is, two identifiers equivalent according to any of those three
> -   comparison operators hash to the same value.  */
> -extern unsigned int default_search_name_hash (const char *search_name);
> -
>  void c_get_string (struct value *value,
>                    gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
>                    int *length, struct type **char_type,
> diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
> index 5f198c659e9..b5b11c715f3 100644
> --- a/gdb/m2-lang.c
> +++ b/gdb/m2-lang.c
> @@ -386,7 +386,6 @@ extern const struct language_data m2_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    m2_is_string_type_p,
> diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
> index abd905127e2..4fc670e1291 100644
> --- a/gdb/objc-lang.c
> +++ b/gdb/objc-lang.c
> @@ -401,7 +401,6 @@ extern const struct language_data objc_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
> index 6af521778dd..fca685e1ead 100644
> --- a/gdb/opencl-lang.c
> +++ b/gdb/opencl-lang.c
> @@ -1061,7 +1061,6 @@ extern const struct language_data opencl_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    c_is_string_type_p,
> diff --git a/gdb/p-lang.c b/gdb/p-lang.c
> index 0b46bc9f980..c022390bb26 100644
> --- a/gdb/p-lang.c
> +++ b/gdb/p-lang.c
> @@ -416,7 +416,6 @@ extern const struct language_data pascal_language_data =
>    default_collect_symbol_completion_matches,
>    c_watch_location_expression,
>    NULL,                                /* la_compare_symbol_for_completion */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    pascal_is_string_type_p,
> diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
> index 856fa210a25..5c13fe4487f 100644
> --- a/gdb/rust-lang.c
> +++ b/gdb/rust-lang.c
> @@ -2093,7 +2093,6 @@ extern const struct language_data rust_language_data =
>    default_collect_symbol_completion_matches,
>    rust_watch_location_expression,
>    NULL,                                /* la_get_symbol_name_matcher */
> -  default_search_name_hash,
>    &default_varobj_ops,
>    NULL,
>    rust_is_string_type_p,
> diff --git a/gdb/symtab.c b/gdb/symtab.c
> index 932b744fa8c..6a8f7d3e3dd 100644
> --- a/gdb/symtab.c
> +++ b/gdb/symtab.c
> @@ -1855,7 +1855,7 @@ demangle_for_lookup (const char *name, enum language lang,
>  unsigned int
>  search_name_hash (enum language language, const char *search_name)
>  {
> -  return language_def (language)->la_search_name_hash (search_name);
> +  return language_def (language)->search_name_hash (search_name);
>  }
>
>  /* See symtab.h.
> --
> 2.25.3
>


More information about the Gdb-patches mailing list