tree-iterator.h revision 169690
1/* Iterator routines for manipulating GENERIC and GIMPLE tree statements. 2 Copyright (C) 2003, 2004 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 2, 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 COPYING. If not, write to 19the Free Software Foundation, 51 Franklin Street, Fifth Floor, 20Boston, MA 02110-1301, USA. */ 21 22 23/* This file is dependent upon the implementation of tree's. It provides an 24 abstract interface to the tree objects such that if all tree creation and 25 manipulations are done through this interface, we can easily change the 26 implementation of tree's, and not impact other code. */ 27 28#ifndef GCC_TREE_ITERATOR_H 29#define GCC_TREE_ITERATOR_H 1 30 31/* Iterator object for GENERIC or GIMPLE TREE statements. */ 32 33typedef struct { 34 struct tree_statement_list_node *ptr; 35 tree container; 36} tree_stmt_iterator; 37 38static inline tree_stmt_iterator 39tsi_start (tree t) 40{ 41 tree_stmt_iterator i; 42 43 i.ptr = STATEMENT_LIST_HEAD (t); 44 i.container = t; 45 46 return i; 47} 48 49static inline tree_stmt_iterator 50tsi_last (tree t) 51{ 52 tree_stmt_iterator i; 53 54 i.ptr = STATEMENT_LIST_TAIL (t); 55 i.container = t; 56 57 return i; 58} 59 60static inline bool 61tsi_end_p (tree_stmt_iterator i) 62{ 63 return i.ptr == NULL; 64} 65 66static inline bool 67tsi_one_before_end_p (tree_stmt_iterator i) 68{ 69 return i.ptr != NULL && i.ptr->next == NULL; 70} 71 72static inline void 73tsi_next (tree_stmt_iterator *i) 74{ 75 i->ptr = i->ptr->next; 76} 77 78static inline void 79tsi_prev (tree_stmt_iterator *i) 80{ 81 i->ptr = i->ptr->prev; 82} 83 84static inline tree * 85tsi_stmt_ptr (tree_stmt_iterator i) 86{ 87 return &i.ptr->stmt; 88} 89 90static inline tree 91tsi_stmt (tree_stmt_iterator i) 92{ 93 return i.ptr->stmt; 94} 95 96enum tsi_iterator_update 97{ 98 TSI_NEW_STMT, /* Only valid when single statement is added, move 99 iterator to it. */ 100 TSI_SAME_STMT, /* Leave the iterator at the same statement. */ 101 TSI_CHAIN_START, /* Only valid when chain of statements is added, move 102 iterator to the first statement in the chain. */ 103 TSI_CHAIN_END, /* Only valid when chain of statements is added, move 104 iterator to the last statement in the chain. */ 105 TSI_CONTINUE_LINKING /* Move iterator to whatever position is suitable for 106 linking other statements/chains of statements in 107 the same direction. */ 108}; 109 110extern void tsi_link_before (tree_stmt_iterator *, tree, 111 enum tsi_iterator_update); 112extern void tsi_link_after (tree_stmt_iterator *, tree, 113 enum tsi_iterator_update); 114 115void tsi_delink (tree_stmt_iterator *); 116 117tree tsi_split_statement_list_after (const tree_stmt_iterator *); 118tree tsi_split_statement_list_before (tree_stmt_iterator *); 119 120void append_to_statement_list (tree, tree *); 121void append_to_statement_list_force (tree, tree *); 122 123#endif /* GCC_TREE_ITERATOR_H */ 124