public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Introduce a block iterator wrapper
@ 2023-02-19 23:38 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-02-19 23:38 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0f50815c894bea5d8f7c14b7c1639325bd0b4abb

commit 0f50815c894bea5d8f7c14b7c1639325bd0b4abb
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Jan 19 18:44:38 2023 -0700

    Introduce a block iterator wrapper
    
    This introduces a C++-style iterator that wraps the existing
    block_iterator.  It also adds a range adapter.  These will be used in
    a later patch.

Diff:
---
 gdb/block.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/gdb/block.h b/gdb/block.h
index 03aeebddc6b..7341d03a07e 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -486,6 +486,56 @@ extern struct symbol *block_iterator_first
 
 extern struct symbol *block_iterator_next (struct block_iterator *iterator);
 
+/* An iterator that wraps a block_iterator.  The naming here is
+   unfortunate, but block_iterator was named before gdb switched to
+   C++.  */
+struct block_iterator_wrapper
+{
+  typedef block_iterator_wrapper self_type;
+  typedef struct symbol *value_type;
+
+  explicit block_iterator_wrapper (const struct block *block,
+				   const lookup_name_info *name = nullptr)
+    : m_sym (block_iterator_first (block, &m_iter, name))
+  {
+  }
+
+  block_iterator_wrapper ()
+    : m_sym (nullptr)
+  {
+  }
+
+  value_type operator* () const
+  {
+    return m_sym;
+  }
+
+  bool operator== (const self_type &other) const
+  {
+    return m_sym == other.m_sym;
+  }
+
+  bool operator!= (const self_type &other) const
+  {
+    return m_sym != other.m_sym;
+  }
+
+  self_type &operator++ ()
+  {
+    m_sym = block_iterator_next (&m_iter);
+    return *this;
+  }
+
+private:
+
+  struct symbol *m_sym;
+  struct block_iterator m_iter;
+};
+
+/* An iterator range for block_iterator_wrapper.  */
+
+typedef iterator_range<block_iterator_wrapper> block_iterator_range;
+
 /* Return true if symbol A is the best match possible for DOMAIN.  */
 
 extern bool best_symbol (struct symbol *a, const domain_enum domain);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-19 23:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-19 23:38 [binutils-gdb] Introduce a block iterator wrapper 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).