aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-iterator.h
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-09-13 10:37:49 -0700
committerIan Lance Taylor <iant@golang.org>2021-09-13 10:37:49 -0700
commite252b51ccde010cbd2a146485d8045103cd99533 (patch)
treee060f101cdc32bf5e520de8e5275db9d4236b74c /gcc/tree-iterator.h
parentf10c7c4596dda99d2ee872c995ae4aeda65adbdf (diff)
parent104c05c5284b7822d770ee51a7d91946c7e56d50 (diff)
downloadgcc-e252b51ccde010cbd2a146485d8045103cd99533.zip
gcc-e252b51ccde010cbd2a146485d8045103cd99533.tar.gz
gcc-e252b51ccde010cbd2a146485d8045103cd99533.tar.bz2
Merge from trunk revision 104c05c5284b7822d770ee51a7d91946c7e56d50.
Diffstat (limited to 'gcc/tree-iterator.h')
-rw-r--r--gcc/tree-iterator.h36
1 files changed, 31 insertions, 5 deletions
diff --git a/gcc/tree-iterator.h b/gcc/tree-iterator.h
index 076fff8..a72d0d3 100644
--- a/gcc/tree-iterator.h
+++ b/gcc/tree-iterator.h
@@ -1,4 +1,4 @@
-/* Iterator routines for manipulating GENERIC tree statement list.
+/* Iterator routines for manipulating GENERIC tree statement list. -*- C++ -*-
Copyright (C) 2003-2021 Free Software Foundation, Inc.
Contributed by Andrew MacLeod <amacleod@redhat.com>
@@ -32,6 +32,21 @@ along with GCC; see the file COPYING3. If not see
struct tree_stmt_iterator {
struct tree_statement_list_node *ptr;
tree container;
+
+ /* No need for user-defined constructors, the implicit definitions (or
+ aggregate initialization) are fine. */
+
+ bool operator== (tree_stmt_iterator b) const
+ { return b.ptr == ptr && b.container == container; }
+ bool operator!= (tree_stmt_iterator b) const { return !(*this == b); }
+ tree_stmt_iterator &operator++ () { ptr = ptr->next; return *this; }
+ tree_stmt_iterator &operator-- () { ptr = ptr->prev; return *this; }
+ tree_stmt_iterator operator++ (int)
+ { tree_stmt_iterator x = *this; ++*this; return x; }
+ tree_stmt_iterator operator-- (int)
+ { tree_stmt_iterator x = *this; --*this; return x; }
+ tree &operator* () { return ptr->stmt; }
+ tree operator* () const { return ptr->stmt; }
};
static inline tree_stmt_iterator
@@ -71,27 +86,38 @@ tsi_one_before_end_p (tree_stmt_iterator i)
static inline void
tsi_next (tree_stmt_iterator *i)
{
- i->ptr = i->ptr->next;
+ ++(*i);
}
static inline void
tsi_prev (tree_stmt_iterator *i)
{
- i->ptr = i->ptr->prev;
+ --(*i);
}
static inline tree *
tsi_stmt_ptr (tree_stmt_iterator i)
{
- return &i.ptr->stmt;
+ return &(*i);
}
static inline tree
tsi_stmt (tree_stmt_iterator i)
{
- return i.ptr->stmt;
+ return *i;
}
+/* Make tree_stmt_iterator work as a C++ range, e.g.
+ for (tree stmt : tsi_range (stmt_list)) { ... } */
+class tsi_range
+{
+ tree t;
+ public:
+ tsi_range (tree t): t(t) { }
+ tree_stmt_iterator begin() const { return tsi_start (t); }
+ tree_stmt_iterator end() const { return { nullptr, t }; }
+};
+
enum tsi_iterator_update
{
TSI_NEW_STMT, /* Only valid when single statement is added, move