]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Introduce language_defn::lookup_symbol_local
authorTom Tromey <tromey@adacore.com>
Thu, 23 May 2024 16:30:16 +0000 (10:30 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 14 Jun 2024 16:56:37 +0000 (10:56 -0600)
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.

gdb/c-lang.c
gdb/f-lang.c
gdb/f-lang.h
gdb/language.h
gdb/symtab.c

index 2b6cf087f548b10083afa1b546587b478a79eb59..24cdde624b2e47d8d7530ba48771053349446010 100644 (file)
@@ -1014,6 +1014,17 @@ public:
 
   /* 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
index 58f35bf0f3fd3510878c721869cebe9281922917..db967532235e05f3dedf8be7bf9dc34c10a3e48c 100644 (file)
@@ -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,
index c2034258513adf4599081c490726a3f1b1923d7c..6b3962f534872b9771e2bb079b495be0a701a231 100644 (file)
@@ -140,6 +140,14 @@ public:
 
   /* 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;
index e67150d75961882dae3891e83d0a70abe459af71..a2ce1697edb72c4a6e87e26feefae56b61c63615 100644 (file)
@@ -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.  */
index c65d562f783298e8f821341c18218cb5df41cae6..4888ebcbf68c914d490cb3680a2c619e7f9b2e98 100644 (file)
@@ -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;