]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use an iterator range for 'using' directives
authorTom Tromey <tromey@adacore.com>
Wed, 23 Oct 2024 16:50:32 +0000 (10:50 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 11 Nov 2024 14:51:05 +0000 (07:51 -0700)
This patch changes block::get_using to return an iterator range.  This
seemed cleaner to me than the current approach of returning a pointer
to the first using directive; all the callers actually use this to
iterate.

gdb/ada-lang.c
gdb/block.c
gdb/block.h
gdb/cp-namespace.c
gdb/cp-support.c
gdb/d-namespace.c

index 6c0621f66432ab54fd5a43c13fc25d038177da61..74dd09091a4f49d174604e43b8dbcbe1c33cbb27 100644 (file)
@@ -5431,15 +5431,12 @@ ada_add_block_renamings (std::vector<struct block_symbol> &result,
                         const lookup_name_info &lookup_name,
                         domain_search_flags domain)
 {
-  struct using_direct *renaming;
   int defns_mark = result.size ();
 
   symbol_name_matcher_ftype *name_match
     = ada_get_symbol_name_matcher (lookup_name);
 
-  for (renaming = block->get_using ();
-       renaming != NULL;
-       renaming = renaming->next)
+  for (using_direct *renaming : block->get_using ())
     {
       const char *r_name;
 
index 6f60877785499db98c6e964c3c8f56a32fb2182d..cf7ca6785b0c9ef4f3d809a245261d18ffaf06d8 100644 (file)
@@ -322,13 +322,13 @@ block::set_scope (const char *scope, struct obstack *obstack)
 
 /* See block.h.  */
 
-struct using_direct *
+next_range<using_direct>
 block::get_using () const
 {
   if (m_namespace_info == nullptr)
-    return nullptr;
+    return {};
   else
-    return m_namespace_info->using_decl;
+    return next_range<using_direct> (m_namespace_info->using_decl);
 }
 
 /* See block.h.  */
index c3babad52f3f8e127d22e2265dfaffc6dd5d570c..b70c82949d1e33beb7c6f1f5d79969c37677fd39 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "dictionary.h"
 #include "gdbsupport/array-view.h"
+#include "gdbsupport/next-iterator.h"
 
 /* Opaque declarations.  */
 
@@ -227,7 +228,7 @@ struct block : public allocate_on_obstack<block>
   /* This returns the using directives list associated with this
      block, if any.  */
 
-  struct using_direct *get_using () const;
+  next_range<using_direct> get_using () const;
 
   /* Set this block's using member to USING; if needed, allocate
      memory via OBSTACK.  (It won't make a copy of USING, however, so
index 9d86fe2722863e6dccc197b2dff4f3ba1d0852b1..dc018a2ef286cf84a1b5b38f073849043037faf3 100644 (file)
@@ -394,7 +394,6 @@ cp_lookup_symbol_via_imports (const char *scope,
                              std::map<std::string,
                                       struct block_symbol>& found_symbols)
 {
-  struct using_direct *current;
   struct block_symbol sym = {};
   int len;
   int directive_match;
@@ -420,9 +419,7 @@ cp_lookup_symbol_via_imports (const char *scope,
   /* Go through the using directives.  If any of them add new names to
      the namespace we're searching in, see if we can find a match by
      applying them.  */
-  for (current = block->get_using ();
-       current != NULL;
-       current = current->next)
+  for (using_direct *current : block->get_using ())
     {
       const char **excludep;
 
index bd714ad32ce949a5ca76b0cbbd7990052a200940..c9b25b2951b546816aa571d2eb6bf75881d74ad6 100644 (file)
@@ -1390,7 +1390,6 @@ add_symbol_overload_list_using (const char *func_name,
                                const char *the_namespace,
                                std::vector<symbol *> *overload_list)
 {
-  struct using_direct *current;
   const struct block *block;
 
   /* First, go through the using directives.  If any of them apply,
@@ -1400,9 +1399,7 @@ add_symbol_overload_list_using (const char *func_name,
   for (block = get_selected_block (0);
        block != NULL;
        block = block->superblock ())
-    for (current = block->get_using ();
-       current != NULL;
-       current = current->next)
+    for (using_direct *current : block->get_using ())
       {
        /* Prevent recursive calls.  */
        if (current->searched)
index 0bcd75dac10c783db35086a63e9c38b36775f3c4..530349e1f07066f040961c7fec455afcb80af8b2 100644 (file)
@@ -362,7 +362,6 @@ d_lookup_symbol_imports (const char *scope, const char *name,
                         const struct block *block,
                         const domain_search_flags domain)
 {
-  struct using_direct *current;
   struct block_symbol sym;
 
   /* First, try to find the symbol in the given module.  */
@@ -375,9 +374,7 @@ d_lookup_symbol_imports (const char *scope, const char *name,
      the module we're searching in, see if we can find a match by
      applying them.  */
 
-  for (current = block->get_using ();
-       current != NULL;
-       current = current->next)
+  for (using_direct *current : block->get_using ())
     {
       const char **excludep;