aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-10-23 10:50:32 -0600
committerTom Tromey <tromey@adacore.com>2024-11-11 07:51:05 -0700
commitb6829c3c917a3557beee70fcdd86990661404ea5 (patch)
tree4176e6319077dea150f148ff4584ed88de0e1fbe
parentfba3b6d16c206882c3ccb98da38271cf36100629 (diff)
downloadbinutils-b6829c3c917a3557beee70fcdd86990661404ea5.zip
binutils-b6829c3c917a3557beee70fcdd86990661404ea5.tar.gz
binutils-b6829c3c917a3557beee70fcdd86990661404ea5.tar.bz2
Use an iterator range for 'using' directives
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.
-rw-r--r--gdb/ada-lang.c5
-rw-r--r--gdb/block.c6
-rw-r--r--gdb/block.h3
-rw-r--r--gdb/cp-namespace.c5
-rw-r--r--gdb/cp-support.c5
-rw-r--r--gdb/d-namespace.c5
6 files changed, 9 insertions, 20 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 6c0621f..74dd090 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -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;
diff --git a/gdb/block.c b/gdb/block.c
index 6f60877..cf7ca67 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -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. */
diff --git a/gdb/block.h b/gdb/block.h
index c3babad..b70c829 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -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
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 9d86fe2..dc018a2 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -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;
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index bd714ad..c9b25b2 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -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)
diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c
index 0bcd75d..530349e 100644
--- a/gdb/d-namespace.c
+++ b/gdb/d-namespace.c
@@ -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;