OSDN Git Service

5b8113a4560c602e3316e903d641954f346661e2
[pf3gnuchains/gcc-fork.git] / gcc / tree-iterator.h
1 /* Iterator routines for manipulating GENERIC and GIMPLE tree statements.
2    Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
3    Contributed by Andrew MacLeod  <amacleod@redhat.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along 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
32 typedef struct {
33   struct tree_statement_list_node *ptr;
34   tree container;
35 } tree_stmt_iterator;
36
37 typedef struct {
38   struct tree_statement_list_node *ptr;
39   const_tree container;
40 } const_tree_stmt_iterator;
41
42 static inline tree_stmt_iterator
43 tsi_start (tree t)
44 {
45   tree_stmt_iterator i;
46
47   i.ptr = STATEMENT_LIST_HEAD (t);
48   i.container = t;
49
50   return i;
51 }
52
53 static inline const_tree_stmt_iterator
54 ctsi_start (const_tree t)
55 {
56   const_tree_stmt_iterator i;
57
58   i.ptr = STATEMENT_LIST_HEAD (t);
59   i.container = t;
60
61   return i;
62 }
63
64 static inline tree_stmt_iterator
65 tsi_last (tree t)
66 {
67   tree_stmt_iterator i;
68
69   i.ptr = STATEMENT_LIST_TAIL (t);
70   i.container = t;
71
72   return i;
73 }
74
75 static inline const_tree_stmt_iterator
76 ctsi_last (tree t)
77 {
78   const_tree_stmt_iterator i;
79
80   i.ptr = STATEMENT_LIST_TAIL (t);
81   i.container = t;
82
83   return i;
84 }
85
86 static inline bool
87 tsi_end_p (tree_stmt_iterator i)
88 {
89   return i.ptr == NULL;
90 }
91
92 static inline bool
93 ctsi_end_p (const_tree_stmt_iterator i)
94 {
95   return i.ptr == NULL;
96 }
97
98 static inline bool
99 tsi_one_before_end_p (tree_stmt_iterator i)
100 {
101   return i.ptr != NULL && i.ptr->next == NULL;
102 }
103
104 static inline bool
105 ctsi_one_before_end_p (const_tree_stmt_iterator i)
106 {
107   return i.ptr != NULL && i.ptr->next == NULL;
108 }
109
110 static inline void
111 tsi_next (tree_stmt_iterator *i)
112 {
113   i->ptr = i->ptr->next;
114 }
115
116 static inline void
117 ctsi_next (const_tree_stmt_iterator *i)
118 {
119   i->ptr = i->ptr->next;
120 }
121
122 static inline void
123 tsi_prev (tree_stmt_iterator *i)
124 {
125   i->ptr = i->ptr->prev;
126 }
127
128 static inline void
129 ctsi_prev (const_tree_stmt_iterator *i)
130 {
131   i->ptr = i->ptr->prev;
132 }
133
134 static inline tree *
135 tsi_stmt_ptr (tree_stmt_iterator i)
136 {
137   return &i.ptr->stmt;
138 }
139
140 static inline tree
141 tsi_stmt (tree_stmt_iterator i)
142 {
143   return i.ptr->stmt;
144 }
145
146 static inline const_tree
147 ctsi_stmt (const_tree_stmt_iterator i)
148 {
149   return i.ptr->stmt;
150 }
151
152 enum tsi_iterator_update
153 {
154   TSI_NEW_STMT,         /* Only valid when single statement is added, move
155                            iterator to it.  */
156   TSI_SAME_STMT,        /* Leave the iterator at the same statement.  */
157   TSI_CHAIN_START,      /* Only valid when chain of statements is added, move
158                            iterator to the first statement in the chain.  */
159   TSI_CHAIN_END,        /* Only valid when chain of statements is added, move
160                            iterator to the last statement in the chain.  */
161   TSI_CONTINUE_LINKING  /* Move iterator to whatever position is suitable for
162                            linking other statements/chains of statements in
163                            the same direction.  */
164 };
165
166 extern void tsi_link_before (tree_stmt_iterator *, tree,
167                              enum tsi_iterator_update);
168 extern void tsi_link_after (tree_stmt_iterator *, tree,
169                             enum tsi_iterator_update);
170
171 void tsi_delink (tree_stmt_iterator *);
172
173 tree tsi_split_statement_list_after (const tree_stmt_iterator *);
174 tree tsi_split_statement_list_before (tree_stmt_iterator *);
175
176 void append_to_statement_list (tree, tree *);
177 void append_to_statement_list_force (tree, tree *);
178
179 #endif /* GCC_TREE_ITERATOR_H  */