1169689Skan/* Iterator routines for manipulating GENERIC and GIMPLE tree statements.
2169689Skan   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3169689Skan   Contributed by Andrew MacLeod  <amacleod@redhat.com>
4169689Skan
5169689SkanThis file is part of GCC.
6169689Skan
7169689SkanGCC is free software; you can redistribute it and/or modify
8169689Skanit under the terms of the GNU General Public License as published by
9169689Skanthe Free Software Foundation; either version 2, or (at your option)
10169689Skanany later version.
11169689Skan
12169689SkanGCC is distributed in the hope that it will be useful,
13169689Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
14169689SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15169689SkanGNU General Public License for more details.
16169689Skan
17169689SkanYou should have received a copy of the GNU General Public License
18169689Skanalong with GCC; see the file COPYING.  If not, write to
19169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
20169689SkanBoston, MA 02110-1301, USA.  */
21169689Skan
22169689Skan
23169689Skan/* This file is dependent upon the implementation of tree's. It provides an
24169689Skan   abstract interface to the tree objects such that if all tree creation and
25169689Skan   manipulations are done through this interface, we can easily change the
26169689Skan   implementation of tree's, and not impact other code.  */
27169689Skan
28169689Skan#ifndef GCC_TREE_ITERATOR_H
29169689Skan#define GCC_TREE_ITERATOR_H 1
30169689Skan
31169689Skan/* Iterator object for GENERIC or GIMPLE TREE statements.  */
32169689Skan
33169689Skantypedef struct {
34169689Skan  struct tree_statement_list_node *ptr;
35169689Skan  tree container;
36169689Skan} tree_stmt_iterator;
37169689Skan
38169689Skanstatic inline tree_stmt_iterator
39169689Skantsi_start (tree t)
40169689Skan{
41169689Skan  tree_stmt_iterator i;
42169689Skan
43169689Skan  i.ptr = STATEMENT_LIST_HEAD (t);
44169689Skan  i.container = t;
45169689Skan
46169689Skan  return i;
47169689Skan}
48169689Skan
49169689Skanstatic inline tree_stmt_iterator
50169689Skantsi_last (tree t)
51169689Skan{
52169689Skan  tree_stmt_iterator i;
53169689Skan
54169689Skan  i.ptr = STATEMENT_LIST_TAIL (t);
55169689Skan  i.container = t;
56169689Skan
57169689Skan  return i;
58169689Skan}
59169689Skan
60169689Skanstatic inline bool
61169689Skantsi_end_p (tree_stmt_iterator i)
62169689Skan{
63169689Skan  return i.ptr == NULL;
64169689Skan}
65169689Skan
66169689Skanstatic inline bool
67169689Skantsi_one_before_end_p (tree_stmt_iterator i)
68169689Skan{
69169689Skan  return i.ptr != NULL && i.ptr->next == NULL;
70169689Skan}
71169689Skan
72169689Skanstatic inline void
73169689Skantsi_next (tree_stmt_iterator *i)
74169689Skan{
75169689Skan  i->ptr = i->ptr->next;
76169689Skan}
77169689Skan
78169689Skanstatic inline void
79169689Skantsi_prev (tree_stmt_iterator *i)
80169689Skan{
81169689Skan  i->ptr = i->ptr->prev;
82169689Skan}
83169689Skan
84169689Skanstatic inline tree *
85169689Skantsi_stmt_ptr (tree_stmt_iterator i)
86169689Skan{
87169689Skan  return &i.ptr->stmt;
88169689Skan}
89169689Skan
90169689Skanstatic inline tree
91169689Skantsi_stmt (tree_stmt_iterator i)
92169689Skan{
93169689Skan  return i.ptr->stmt;
94169689Skan}
95169689Skan
96169689Skanenum tsi_iterator_update
97169689Skan{
98169689Skan  TSI_NEW_STMT,		/* Only valid when single statement is added, move
99169689Skan			   iterator to it.  */
100169689Skan  TSI_SAME_STMT,	/* Leave the iterator at the same statement.  */
101169689Skan  TSI_CHAIN_START,	/* Only valid when chain of statements is added, move
102169689Skan			   iterator to the first statement in the chain.  */
103169689Skan  TSI_CHAIN_END,	/* Only valid when chain of statements is added, move
104169689Skan			   iterator to the last statement in the chain.  */
105169689Skan  TSI_CONTINUE_LINKING	/* Move iterator to whatever position is suitable for
106169689Skan			   linking other statements/chains of statements in
107169689Skan			   the same direction.  */
108169689Skan};
109169689Skan
110169689Skanextern void tsi_link_before (tree_stmt_iterator *, tree,
111169689Skan			     enum tsi_iterator_update);
112169689Skanextern void tsi_link_after (tree_stmt_iterator *, tree,
113169689Skan			    enum tsi_iterator_update);
114169689Skan
115169689Skanvoid tsi_delink (tree_stmt_iterator *);
116169689Skan
117169689Skantree tsi_split_statement_list_after (const tree_stmt_iterator *);
118169689Skantree tsi_split_statement_list_before (tree_stmt_iterator *);
119169689Skan
120169689Skanvoid append_to_statement_list (tree, tree *);
121169689Skanvoid append_to_statement_list_force (tree, tree *);
122169689Skan
123169689Skan#endif /* GCC_TREE_ITERATOR_H  */
124