GCC Middle and Back End API Reference
tree-iterator.h
Go to the documentation of this file.
1/* Iterator routines for manipulating GENERIC tree statement list. -*- C++ -*-
2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21
22/* This file is dependent upon the implementation of tree's. It provides an
23 abstract interface to the tree objects such that if all tree creation and
24 manipulations are done through this interface, we can easily change the
25 implementation of tree's, and not impact other code. */
26
27#ifndef GCC_TREE_ITERATOR_H
28#define GCC_TREE_ITERATOR_H 1
29
30/* Iterator object for GENERIC or GIMPLE TREE statements. */
31
35
36 /* No need for user-defined constructors, the implicit definitions (or
37 aggregate initialization) are fine. */
38
40 { return b.ptr == ptr && b.container == container; }
41 bool operator!= (tree_stmt_iterator b) const { return !(*this == b); }
42 tree_stmt_iterator &operator++ () { ptr = ptr->next; return *this; }
43 tree_stmt_iterator &operator-- () { ptr = ptr->prev; return *this; }
45 { tree_stmt_iterator x = *this; ++*this; return x; }
47 { tree_stmt_iterator x = *this; --*this; return x; }
48 tree &operator* () { return ptr->stmt; }
49 tree operator* () const { return ptr->stmt; }
50};
51
54{
56
58 i.container = t;
59
60 return i;
61}
62
65{
67
69 i.container = t;
70
71 return i;
72}
73
74inline bool
76{
77 return i.ptr == NULL;
78}
79
80inline bool
82{
83 return i.ptr != NULL && i.ptr->next == NULL;
84}
85
86inline void
88{
89 ++(*i);
90}
91
92inline void
94{
95 --(*i);
96}
97
98inline tree *
100{
101 return &(*i);
102}
103
104inline tree
106{
107 return *i;
108}
109
110/* Make tree_stmt_iterator work as a C++ range, e.g.
111 for (tree stmt : tsi_range (stmt_list)) { ... } */
113{
115 public:
117 tree_stmt_iterator begin() const { return tsi_start (t); }
118 tree_stmt_iterator end() const { return { nullptr, t }; }
119};
120
122{
123 TSI_NEW_STMT, /* Only valid when single statement is added, move
124 iterator to it. */
125 TSI_SAME_STMT, /* Leave the iterator at the same statement. */
126 TSI_CHAIN_START, /* Only valid when chain of statements is added, move
127 iterator to the first statement in the chain. */
128 TSI_CHAIN_END, /* Only valid when chain of statements is added, move
129 iterator to the last statement in the chain. */
130 TSI_CONTINUE_LINKING /* Move iterator to whatever position is suitable for
131 linking other statements/chains of statements in
132 the same direction. */
134
139
140extern void tsi_delink (tree_stmt_iterator *);
141
142extern tree alloc_stmt_list (void);
143extern void free_stmt_list (tree);
144extern void append_to_statement_list (tree, tree *);
146extern tree expr_first (tree);
147extern tree expr_last (tree);
148extern tree expr_single (tree);
149
150#endif /* GCC_TREE_ITERATOR_H */
Definition tree-iterator.h:113
tsi_range(tree t)
Definition tree-iterator.h:116
tree_stmt_iterator end() const
Definition tree-iterator.h:118
tree_stmt_iterator begin() const
Definition tree-iterator.h:117
tree t
Definition tree-iterator.h:114
union tree_node * tree
Definition coretypes.h:97
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
i
Definition poly-int.h:772
Ca const poly_int< N, Cb > & b
Definition poly-int.h:767
Definition tree-iterator.h:32
struct tree_statement_list_node * ptr
Definition tree-iterator.h:33
tree & operator*()
Definition tree-iterator.h:48
tree_stmt_iterator & operator++()
Definition tree-iterator.h:42
bool operator==(tree_stmt_iterator b) const
Definition tree-iterator.h:39
tree_stmt_iterator & operator--()
Definition tree-iterator.h:43
bool operator!=(tree_stmt_iterator b) const
Definition tree-iterator.h:41
tree container
Definition tree-iterator.h:34
#define NULL
Definition system.h:50
void append_to_statement_list_force(tree, tree *)
Definition tree-iterator.cc:102
bool tsi_end_p(tree_stmt_iterator i)
Definition tree-iterator.h:75
bool tsi_one_before_end_p(tree_stmt_iterator i)
Definition tree-iterator.h:81
tree tsi_stmt(tree_stmt_iterator i)
Definition tree-iterator.h:105
void tsi_link_before(tree_stmt_iterator *, tree, enum tsi_iterator_update)
Definition tree-iterator.cc:111
void tsi_prev(tree_stmt_iterator *i)
Definition tree-iterator.h:93
void append_to_statement_list(tree, tree *)
Definition tree-iterator.cc:93
void tsi_link_after(tree_stmt_iterator *, tree, enum tsi_iterator_update)
Definition tree-iterator.cc:188
tree alloc_stmt_list(void)
Definition tree-iterator.cc:34
void tsi_next(tree_stmt_iterator *i)
Definition tree-iterator.h:87
void free_stmt_list(tree)
Definition tree-iterator.cc:53
void tsi_delink(tree_stmt_iterator *)
Definition tree-iterator.cc:264
tree * tsi_stmt_ptr(tree_stmt_iterator i)
Definition tree-iterator.h:99
tsi_iterator_update
Definition tree-iterator.h:122
@ TSI_SAME_STMT
Definition tree-iterator.h:125
@ TSI_CHAIN_END
Definition tree-iterator.h:128
@ TSI_CONTINUE_LINKING
Definition tree-iterator.h:130
@ TSI_NEW_STMT
Definition tree-iterator.h:123
@ TSI_CHAIN_START
Definition tree-iterator.h:126
tree_stmt_iterator tsi_start(tree t)
Definition tree-iterator.h:53
tree expr_single(tree)
Definition tree-iterator.cc:364
tree expr_last(tree)
Definition tree-iterator.cc:327
tree expr_first(tree)
Definition tree-iterator.cc:292
tree_stmt_iterator tsi_last(tree t)
Definition tree-iterator.h:64
#define STATEMENT_LIST_HEAD(NODE)
Definition tree.h:3586
#define STATEMENT_LIST_TAIL(NODE)
Definition tree.h:3588