]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-iterator.h
PR fortran/95090 - ICE: identifier overflow
[thirdparty/gcc.git] / gcc / tree-iterator.h
CommitLineData
f4ce02c5 1/* Iterator routines for manipulating GENERIC tree statement list.
8d9254fc 2 Copyright (C) 2003-2020 Free Software Foundation, Inc.
6de9cd9a
DN
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
9dcd6f09 9the Free Software Foundation; either version 3, or (at your option)
6de9cd9a
DN
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
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
6de9cd9a
DN
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
84562394 32struct tree_stmt_iterator {
6de9cd9a
DN
33 struct tree_statement_list_node *ptr;
34 tree container;
84562394 35};
6de9cd9a
DN
36
37static inline tree_stmt_iterator
38tsi_start (tree t)
39{
40 tree_stmt_iterator i;
41
42 i.ptr = STATEMENT_LIST_HEAD (t);
43 i.container = t;
44
45 return i;
46}
47
48static inline tree_stmt_iterator
49tsi_last (tree t)
50{
51 tree_stmt_iterator i;
52
53 i.ptr = STATEMENT_LIST_TAIL (t);
54 i.container = t;
55
56 return i;
57}
58
59static inline bool
60tsi_end_p (tree_stmt_iterator i)
61{
62 return i.ptr == NULL;
63}
64
65static inline bool
66tsi_one_before_end_p (tree_stmt_iterator i)
67{
68 return i.ptr != NULL && i.ptr->next == NULL;
69}
70
71static inline void
72tsi_next (tree_stmt_iterator *i)
73{
74 i->ptr = i->ptr->next;
75}
76
77static inline void
78tsi_prev (tree_stmt_iterator *i)
79{
80 i->ptr = i->ptr->prev;
81}
82
83static inline tree *
84tsi_stmt_ptr (tree_stmt_iterator i)
85{
86 return &i.ptr->stmt;
87}
88
89static inline tree
90tsi_stmt (tree_stmt_iterator i)
91{
92 return i.ptr->stmt;
93}
94
95enum tsi_iterator_update
96{
00b847e3 97 TSI_NEW_STMT, /* Only valid when single statement is added, move
6de9cd9a 98 iterator to it. */
00b847e3 99 TSI_SAME_STMT, /* Leave the iterator at the same statement. */
6de9cd9a
DN
100 TSI_CHAIN_START, /* Only valid when chain of statements is added, move
101 iterator to the first statement in the chain. */
102 TSI_CHAIN_END, /* Only valid when chain of statements is added, move
103 iterator to the last statement in the chain. */
104 TSI_CONTINUE_LINKING /* Move iterator to whatever position is suitable for
105 linking other statements/chains of statements in
106 the same direction. */
107};
108
109extern void tsi_link_before (tree_stmt_iterator *, tree,
110 enum tsi_iterator_update);
111extern void tsi_link_after (tree_stmt_iterator *, tree,
112 enum tsi_iterator_update);
113
f4ce02c5 114extern void tsi_delink (tree_stmt_iterator *);
6de9cd9a 115
f4ce02c5
SB
116extern tree alloc_stmt_list (void);
117extern void free_stmt_list (tree);
118extern void append_to_statement_list (tree, tree *);
119extern void append_to_statement_list_force (tree, tree *);
d8a2d370
DN
120extern tree expr_first (tree);
121extern tree expr_last (tree);
aae5d08a 122extern tree expr_single (tree);
325c3691 123
6de9cd9a 124#endif /* GCC_TREE_ITERATOR_H */