public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Introduce language_defn::lookup_symbol_local
@ 2024-06-14 17:17 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2024-06-14 17:17 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9c23c0df0dc47560bf3e253186e0192bc9630c80
commit 9c23c0df0dc47560bf3e253186e0192bc9630c80
Author: Tom Tromey <tromey@adacore.com>
Date: Thu May 23 10:30:16 2024 -0600
Introduce language_defn::lookup_symbol_local
This introduces the new method language_defn::lookup_symbol_local, and
then changes lookup_symbol_local to use it. This removes an explicit
language check from this function, and makes it easier for other
languages to hook into this code.
Diff:
---
gdb/c-lang.c | 11 +++++++++++
gdb/f-lang.c | 11 +++++++++++
gdb/f-lang.h | 8 ++++++++
gdb/language.h | 17 +++++++++++++++++
gdb/symtab.c | 22 +++++++++-------------
5 files changed, 56 insertions(+), 13 deletions(-)
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 2b6cf087f54..24cdde624b2 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -1014,6 +1014,17 @@ class cplus_language : public language_defn
/* See language.h. */
+ struct block_symbol lookup_symbol_local
+ (const char *scope,
+ const char *name,
+ const struct block *block,
+ const domain_search_flags domain) const override
+ {
+ return cp_lookup_symbol_imports (scope, name, block, domain);
+ }
+
+ /* See language.h. */
+
struct block_symbol lookup_symbol_nonlocal
(const char *name, const struct block *block,
const domain_search_flags domain) const override
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 58f35bf0f3f..db967532235 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1711,6 +1711,17 @@ f_language::search_name_hash (const char *name) const
/* See language.h. */
+struct block_symbol
+f_language::lookup_symbol_local (const char *scope,
+ const char *name,
+ const struct block *block,
+ const domain_search_flags domain) const
+{
+ return cp_lookup_symbol_imports (scope, name, block, domain);
+}
+
+/* See language.h. */
+
struct block_symbol
f_language::lookup_symbol_nonlocal (const char *name,
const struct block *block,
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index c2034258513..6b3962f5348 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -140,6 +140,14 @@ class f_language : public language_defn
/* See language.h. */
+ struct block_symbol lookup_symbol_local
+ (const char *scope,
+ const char *name,
+ const struct block *block,
+ const domain_search_flags domain) const override;
+
+ /* See language.h. */
+
struct block_symbol lookup_symbol_nonlocal
(const char *name, const struct block *block,
const domain_search_flags domain) const override;
diff --git a/gdb/language.h b/gdb/language.h
index e67150d7596..a2ce1697edb 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -507,6 +507,23 @@ struct language_defn
(tracker, mode, name_match_type, text, word, "", code);
}
+ /* This is called by lookup_local_symbol after checking a block. It
+ can be used by a language to augment the local lookup, for
+ instance for searching imported namespaces. SCOPE is the current
+ scope (from block::scope), NAME is the name being searched for,
+ BLOCK is the block being searched, and DOMAIN is the search
+ domain. Returns a block symbol, or an empty block symbol if not
+ found. */
+
+ virtual struct block_symbol lookup_symbol_local
+ (const char *scope,
+ const char *name,
+ const struct block *block,
+ const domain_search_flags domain) const
+ {
+ return {};
+ }
+
/* This is a function that lookup_symbol will call when it gets to
the part of symbol lookup where C looks up static and global
variables. This default implements the basic C lookup rules. */
diff --git a/gdb/symtab.c b/gdb/symtab.c
index c65d562f783..4888ebcbf68 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -93,7 +93,7 @@ struct block_symbol lookup_local_symbol (const char *name,
symbol_name_match_type match_type,
const struct block *block,
const domain_search_flags domain,
- enum language language);
+ const struct language_defn *langdef);
static struct block_symbol
lookup_symbol_in_objfile (struct objfile *objfile,
@@ -2140,10 +2140,12 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
if (is_a_field_of_this != NULL)
memset (is_a_field_of_this, 0, sizeof (*is_a_field_of_this));
+ langdef = language_def (language);
+
/* Search specified block and its superiors. Don't search
STATIC_BLOCK or GLOBAL_BLOCK. */
- result = lookup_local_symbol (name, match_type, block, domain, language);
+ result = lookup_local_symbol (name, match_type, block, domain, langdef);
if (result.symbol != NULL)
{
symbol_lookup_debug_printf
@@ -2155,8 +2157,6 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
/* If requested to do so by the caller and if appropriate for LANGUAGE,
check to see if NAME is a field of `this'. */
- langdef = language_def (language);
-
/* Don't do this check if we are searching for a struct. It will
not be found by check_field, but will be found by other
means. */
@@ -2217,7 +2217,7 @@ lookup_local_symbol (const char *name,
symbol_name_match_type match_type,
const struct block *block,
const domain_search_flags domain,
- enum language language)
+ const struct language_defn *langdef)
{
if (block == nullptr)
return {};
@@ -2242,14 +2242,10 @@ lookup_local_symbol (const char *name,
return (struct block_symbol) {sym, block};
}
- if (language == language_cplus || language == language_fortran)
- {
- struct block_symbol blocksym
- = cp_lookup_symbol_imports (scope, name, block, domain);
-
- if (blocksym.symbol != NULL)
- return blocksym;
- }
+ struct block_symbol blocksym
+ = langdef->lookup_symbol_local (scope, name, block, domain);
+ if (blocksym.symbol != nullptr)
+ return blocksym;
if (block->inlined_p ())
break;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-06-14 17:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-14 17:17 [binutils-gdb] Introduce language_defn::lookup_symbol_local Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).