aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2023-01-19 18:44:38 -0700
committerTom Tromey <tom@tromey.com>2023-02-19 12:51:06 -0700
commit0f50815c894bea5d8f7c14b7c1639325bd0b4abb (patch)
tree75d621675339d458dc531a9747ff10f3b1e010df /gdb
parent81326ac076332230286e23d69978cc2698d004b9 (diff)
downloadbinutils-0f50815c894bea5d8f7c14b7c1639325bd0b4abb.zip
binutils-0f50815c894bea5d8f7c14b7c1639325bd0b4abb.tar.gz
binutils-0f50815c894bea5d8f7c14b7c1639325bd0b4abb.tar.bz2
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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/block.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/gdb/block.h b/gdb/block.h
index 03aeebd..7341d03 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);