1*38fd1498Szrj /* Iterator routines for manipulating GENERIC tree statement list.
2*38fd1498Szrj Copyright (C) 2003-2018 Free Software Foundation, Inc.
3*38fd1498Szrj Contributed by Andrew MacLeod <amacleod@redhat.com>
4*38fd1498Szrj
5*38fd1498Szrj This file is part of GCC.
6*38fd1498Szrj
7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify
8*38fd1498Szrj it under the terms of the GNU General Public License as published by
9*38fd1498Szrj the Free Software Foundation; either version 3, or (at your option)
10*38fd1498Szrj any later version.
11*38fd1498Szrj
12*38fd1498Szrj GCC is distributed in the hope that it will be useful,
13*38fd1498Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
14*38fd1498Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*38fd1498Szrj GNU General Public License for more details.
16*38fd1498Szrj
17*38fd1498Szrj You should have received a copy of the GNU General Public License
18*38fd1498Szrj along with GCC; see the file COPYING3. If not see
19*38fd1498Szrj <http://www.gnu.org/licenses/>. */
20*38fd1498Szrj
21*38fd1498Szrj
22*38fd1498Szrj /* This file is dependent upon the implementation of tree's. It provides an
23*38fd1498Szrj abstract interface to the tree objects such that if all tree creation and
24*38fd1498Szrj manipulations are done through this interface, we can easily change the
25*38fd1498Szrj implementation of tree's, and not impact other code. */
26*38fd1498Szrj
27*38fd1498Szrj #ifndef GCC_TREE_ITERATOR_H
28*38fd1498Szrj #define GCC_TREE_ITERATOR_H 1
29*38fd1498Szrj
30*38fd1498Szrj /* Iterator object for GENERIC or GIMPLE TREE statements. */
31*38fd1498Szrj
32*38fd1498Szrj struct tree_stmt_iterator {
33*38fd1498Szrj struct tree_statement_list_node *ptr;
34*38fd1498Szrj tree container;
35*38fd1498Szrj };
36*38fd1498Szrj
37*38fd1498Szrj static inline tree_stmt_iterator
tsi_start(tree t)38*38fd1498Szrj tsi_start (tree t)
39*38fd1498Szrj {
40*38fd1498Szrj tree_stmt_iterator i;
41*38fd1498Szrj
42*38fd1498Szrj i.ptr = STATEMENT_LIST_HEAD (t);
43*38fd1498Szrj i.container = t;
44*38fd1498Szrj
45*38fd1498Szrj return i;
46*38fd1498Szrj }
47*38fd1498Szrj
48*38fd1498Szrj static inline tree_stmt_iterator
tsi_last(tree t)49*38fd1498Szrj tsi_last (tree t)
50*38fd1498Szrj {
51*38fd1498Szrj tree_stmt_iterator i;
52*38fd1498Szrj
53*38fd1498Szrj i.ptr = STATEMENT_LIST_TAIL (t);
54*38fd1498Szrj i.container = t;
55*38fd1498Szrj
56*38fd1498Szrj return i;
57*38fd1498Szrj }
58*38fd1498Szrj
59*38fd1498Szrj static inline bool
tsi_end_p(tree_stmt_iterator i)60*38fd1498Szrj tsi_end_p (tree_stmt_iterator i)
61*38fd1498Szrj {
62*38fd1498Szrj return i.ptr == NULL;
63*38fd1498Szrj }
64*38fd1498Szrj
65*38fd1498Szrj static inline bool
tsi_one_before_end_p(tree_stmt_iterator i)66*38fd1498Szrj tsi_one_before_end_p (tree_stmt_iterator i)
67*38fd1498Szrj {
68*38fd1498Szrj return i.ptr != NULL && i.ptr->next == NULL;
69*38fd1498Szrj }
70*38fd1498Szrj
71*38fd1498Szrj static inline void
tsi_next(tree_stmt_iterator * i)72*38fd1498Szrj tsi_next (tree_stmt_iterator *i)
73*38fd1498Szrj {
74*38fd1498Szrj i->ptr = i->ptr->next;
75*38fd1498Szrj }
76*38fd1498Szrj
77*38fd1498Szrj static inline void
tsi_prev(tree_stmt_iterator * i)78*38fd1498Szrj tsi_prev (tree_stmt_iterator *i)
79*38fd1498Szrj {
80*38fd1498Szrj i->ptr = i->ptr->prev;
81*38fd1498Szrj }
82*38fd1498Szrj
83*38fd1498Szrj static inline tree *
tsi_stmt_ptr(tree_stmt_iterator i)84*38fd1498Szrj tsi_stmt_ptr (tree_stmt_iterator i)
85*38fd1498Szrj {
86*38fd1498Szrj return &i.ptr->stmt;
87*38fd1498Szrj }
88*38fd1498Szrj
89*38fd1498Szrj static inline tree
tsi_stmt(tree_stmt_iterator i)90*38fd1498Szrj tsi_stmt (tree_stmt_iterator i)
91*38fd1498Szrj {
92*38fd1498Szrj return i.ptr->stmt;
93*38fd1498Szrj }
94*38fd1498Szrj
95*38fd1498Szrj enum tsi_iterator_update
96*38fd1498Szrj {
97*38fd1498Szrj TSI_NEW_STMT, /* Only valid when single statement is added, move
98*38fd1498Szrj iterator to it. */
99*38fd1498Szrj TSI_SAME_STMT, /* Leave the iterator at the same statement. */
100*38fd1498Szrj TSI_CHAIN_START, /* Only valid when chain of statements is added, move
101*38fd1498Szrj iterator to the first statement in the chain. */
102*38fd1498Szrj TSI_CHAIN_END, /* Only valid when chain of statements is added, move
103*38fd1498Szrj iterator to the last statement in the chain. */
104*38fd1498Szrj TSI_CONTINUE_LINKING /* Move iterator to whatever position is suitable for
105*38fd1498Szrj linking other statements/chains of statements in
106*38fd1498Szrj the same direction. */
107*38fd1498Szrj };
108*38fd1498Szrj
109*38fd1498Szrj extern void tsi_link_before (tree_stmt_iterator *, tree,
110*38fd1498Szrj enum tsi_iterator_update);
111*38fd1498Szrj extern void tsi_link_after (tree_stmt_iterator *, tree,
112*38fd1498Szrj enum tsi_iterator_update);
113*38fd1498Szrj
114*38fd1498Szrj extern void tsi_delink (tree_stmt_iterator *);
115*38fd1498Szrj
116*38fd1498Szrj extern tree alloc_stmt_list (void);
117*38fd1498Szrj extern void free_stmt_list (tree);
118*38fd1498Szrj extern void append_to_statement_list (tree, tree *);
119*38fd1498Szrj extern void append_to_statement_list_force (tree, tree *);
120*38fd1498Szrj extern tree expr_first (tree);
121*38fd1498Szrj extern tree expr_last (tree);
122*38fd1498Szrj
123*38fd1498Szrj #endif /* GCC_TREE_ITERATOR_H */
124