]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Combine both styles of block iterator
authorTom Tromey <tom@tromey.com>
Fri, 20 Jan 2023 01:41:21 +0000 (18:41 -0700)
committerTom Tromey <tom@tromey.com>
Sun, 19 Feb 2023 19:51:06 +0000 (12:51 -0700)
This merges the two styles of block iterator, having the
initialization API decide which to use based on an optional parameter.

gdb/ada-lang.c
gdb/block.c
gdb/block.h

index 8b503b35ed576455db3a0b7301e99f9fdd7dc79a..0361730bda0014cff4151ef6e13f9bf5da30141f 100644 (file)
@@ -6079,9 +6079,9 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
 
   arg_sym = NULL;
   found_sym = false;
-  for (sym = block_iter_match_first (block, lookup_name, &iter);
+  for (sym = block_iterator_first (block, &iter, &lookup_name);
        sym != NULL;
-       sym = block_iter_match_next (&iter))
+       sym = block_iterator_next (&iter))
     {
       if (symbol_matches_domain (sym->language (), sym->domain (), domain))
        {
index e56c95013b86765a70927d6fe9f899d3237e6484..e7a51af8cea3ab3ca212f23049d282ae1f9f3ed1 100644 (file)
@@ -556,31 +556,6 @@ block_iterator_step (struct block_iterator *iterator, int first)
     }
 }
 
-/* See block.h.  */
-
-struct symbol *
-block_iterator_first (const struct block *block,
-                     struct block_iterator *iterator)
-{
-  initialize_block_iterator (block, iterator);
-
-  if (iterator->which == FIRST_LOCAL_BLOCK)
-    return mdict_iterator_first (block->multidict (), &iterator->mdict_iter);
-
-  return block_iterator_step (iterator, 1);
-}
-
-/* See block.h.  */
-
-struct symbol *
-block_iterator_next (struct block_iterator *iterator)
-{
-  if (iterator->which == FIRST_LOCAL_BLOCK)
-    return mdict_iterator_next (&iterator->mdict_iter);
-
-  return block_iterator_step (iterator, 0);
-}
-
 /* Perform a single step for a "match" block iterator, iterating
    across symbol tables as needed.  Returns the next symbol, or NULL
    when iteration is complete.  */
@@ -626,14 +601,23 @@ block_iter_match_step (struct block_iterator *iterator,
 /* See block.h.  */
 
 struct symbol *
-block_iter_match_first (const struct block *block,
-                       const lookup_name_info &name,
-                       struct block_iterator *iterator)
+block_iterator_first (const struct block *block,
+                     struct block_iterator *iterator,
+                     const lookup_name_info *name)
 {
-  initialize_block_iterator (block, iterator, &name);
+  initialize_block_iterator (block, iterator, name);
+
+  if (name == nullptr)
+    {
+      if (iterator->which == FIRST_LOCAL_BLOCK)
+       return mdict_iterator_first (block->multidict (),
+                                    &iterator->mdict_iter);
+
+      return block_iterator_step (iterator, 1);
+    }
 
   if (iterator->which == FIRST_LOCAL_BLOCK)
-    return mdict_iter_match_first (block->multidict (), name,
+    return mdict_iter_match_first (block->multidict (), *name,
                                   &iterator->mdict_iter);
 
   return block_iter_match_step (iterator, 1);
@@ -642,9 +626,15 @@ block_iter_match_first (const struct block *block,
 /* See block.h.  */
 
 struct symbol *
-block_iter_match_next (struct block_iterator *iterator)
+block_iterator_next (struct block_iterator *iterator)
 {
-  gdb_assert (iterator->name != nullptr);
+  if (iterator->name == nullptr)
+    {
+      if (iterator->which == FIRST_LOCAL_BLOCK)
+       return mdict_iterator_next (&iterator->mdict_iter);
+
+      return block_iterator_step (iterator, 0);
+    }
 
   if (iterator->which == FIRST_LOCAL_BLOCK)
     return mdict_iter_match_next (*iterator->name, &iterator->mdict_iter);
index 5fc41c6df02b145d7e15e50a6b885b4c7f3fe0b3..03aeebddc6b13152b20094d5d8dab6a33d19a57a 100644 (file)
@@ -471,10 +471,13 @@ struct block_iterator
 };
 
 /* Initialize ITERATOR to point at the first symbol in BLOCK, and
-   return that first symbol, or NULL if BLOCK is empty.  */
+   return that first symbol, or NULL if BLOCK is empty.  If NAME is
+   not NULL, only return symbols matching that name.  */
 
-extern struct symbol *block_iterator_first (const struct block *block,
-                                           struct block_iterator *iterator);
+extern struct symbol *block_iterator_first
+     (const struct block *block,
+      struct block_iterator *iterator,
+      const lookup_name_info *name = nullptr);
 
 /* Advance ITERATOR, and return the next symbol, or NULL if there are
    no more symbols.  Don't call this if you've previously received
@@ -483,23 +486,6 @@ extern struct symbol *block_iterator_first (const struct block *block,
 
 extern struct symbol *block_iterator_next (struct block_iterator *iterator);
 
-/* Initialize ITERATOR to point at the first symbol in BLOCK whose
-   search_name () matches NAME, and return that first symbol, or
-   NULL if there are no such symbols.  */
-
-extern struct symbol *block_iter_match_first (const struct block *block,
-                                             const lookup_name_info &name,
-                                             struct block_iterator *iterator);
-
-/* Advance ITERATOR to point at the next symbol in BLOCK whose
-   search_name () matches NAME, or NULL if there are no more such
-   symbols.  Don't call this if you've previously received NULL from
-   block_iterator_match_first or block_iterator_match_next on this
-   iteration.  And don't call it unless ITERATOR was created by a
-   previous call to block_iter_match_first.  */
-
-extern struct symbol *block_iter_match_next (struct block_iterator *iterator);
-
 /* Return true if symbol A is the best match possible for DOMAIN.  */
 
 extern bool best_symbol (struct symbol *a, const domain_enum domain);
@@ -574,9 +560,9 @@ extern int block_find_non_opaque_type_preferred (struct symbol *sym,
    current symbol.  */
 
 #define ALL_BLOCK_SYMBOLS_WITH_NAME(block, name, iter, sym)            \
-  for ((sym) = block_iter_match_first ((block), (name), &(iter));      \
+  for ((sym) = block_iterator_first ((block), &(iter), &(name));       \
        (sym) != NULL;                                                  \
-       (sym) = block_iter_match_next (&(iter)))
+       (sym) = block_iterator_next (&(iter)))
 
 /* Given a vector of pairs, allocate and build an obstack allocated
    blockranges struct for a block.  */