tree-iterator.h revision 169689
179455Sobrien/* Iterator routines for manipulating GENERIC and GIMPLE tree statements.
279455Sobrien   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
379455Sobrien   Contributed by Andrew MacLeod  <amacleod@redhat.com>
479455Sobrien
579455SobrienThis file is part of GCC.
679455Sobrien
779455SobrienGCC is free software; you can redistribute it and/or modify
879455Sobrienit under the terms of the GNU General Public License as published by
979455Sobrienthe Free Software Foundation; either version 2, or (at your option)
1079455Sobrienany later version.
1179455Sobrien
1279455SobrienGCC is distributed in the hope that it will be useful,
1379455Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
1479455SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1579455SobrienGNU General Public License for more details.
1679455Sobrien
1779455SobrienYou should have received a copy of the GNU General Public License
1879455Sobrienalong with GCC; see the file COPYING.  If not, write to
1979455Sobrienthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
2079455SobrienBoston, MA 02110-1301, USA.  */
2179455Sobrien
2279455Sobrien
2379455Sobrien/* This file is dependent upon the implementation of tree's. It provides an
2479455Sobrien   abstract interface to the tree objects such that if all tree creation and
2579455Sobrien   manipulations are done through this interface, we can easily change the
2679455Sobrien   implementation of tree's, and not impact other code.  */
2779455Sobrien
2879455Sobrien#ifndef GCC_TREE_ITERATOR_H
2979455Sobrien#define GCC_TREE_ITERATOR_H 1
3079455Sobrien
3179455Sobrien/* Iterator object for GENERIC or GIMPLE TREE statements.  */
3279455Sobrien
3379455Sobrientypedef struct {
3479455Sobrien  struct tree_statement_list_node *ptr;
3579455Sobrien  tree container;
3679455Sobrien} tree_stmt_iterator;
3779455Sobrien
3879455Sobrienstatic inline tree_stmt_iterator
3979455Sobrientsi_start (tree t)
4079455Sobrien{
4179455Sobrien  tree_stmt_iterator i;
4279455Sobrien
4379455Sobrien  i.ptr = STATEMENT_LIST_HEAD (t);
4479455Sobrien  i.container = t;
4579455Sobrien
4679455Sobrien  return i;
4779455Sobrien}
4879455Sobrien
4979455Sobrienstatic inline tree_stmt_iterator
5079455Sobrientsi_last (tree t)
5179455Sobrien{
5279455Sobrien  tree_stmt_iterator i;
5379455Sobrien
5479455Sobrien  i.ptr = STATEMENT_LIST_TAIL (t);
5579455Sobrien  i.container = t;
5679455Sobrien
5779455Sobrien  return i;
5879455Sobrien}
5979455Sobrien
6079455Sobrienstatic inline bool
6179455Sobrientsi_end_p (tree_stmt_iterator i)
6279455Sobrien{
6379455Sobrien  return i.ptr == NULL;
6479455Sobrien}
6579455Sobrien
6679455Sobrienstatic inline bool
6779455Sobrientsi_one_before_end_p (tree_stmt_iterator i)
6879455Sobrien{
6979455Sobrien  return i.ptr != NULL && i.ptr->next == NULL;
7079455Sobrien}
7179455Sobrien
7279455Sobrienstatic inline void
7379455Sobrientsi_next (tree_stmt_iterator *i)
7479455Sobrien{
7579455Sobrien  i->ptr = i->ptr->next;
7679455Sobrien}
7779455Sobrien
7879455Sobrienstatic inline void
7979455Sobrientsi_prev (tree_stmt_iterator *i)
8079455Sobrien{
8179455Sobrien  i->ptr = i->ptr->prev;
8279455Sobrien}
8379455Sobrien
8479455Sobrienstatic inline tree *
8579455Sobrientsi_stmt_ptr (tree_stmt_iterator i)
8679455Sobrien{
8779455Sobrien  return &i.ptr->stmt;
8879455Sobrien}
8979455Sobrien
9079455Sobrienstatic inline tree
9179455Sobrientsi_stmt (tree_stmt_iterator i)
9279455Sobrien{
9379455Sobrien  return i.ptr->stmt;
9479455Sobrien}
9579455Sobrien
9679455Sobrienenum tsi_iterator_update
9779455Sobrien{
9879455Sobrien  TSI_NEW_STMT,		/* Only valid when single statement is added, move
9979455Sobrien			   iterator to it.  */
10079455Sobrien  TSI_SAME_STMT,	/* Leave the iterator at the same statement.  */
10179455Sobrien  TSI_CHAIN_START,	/* Only valid when chain of statements is added, move
10279455Sobrien			   iterator to the first statement in the chain.  */
10379455Sobrien  TSI_CHAIN_END,	/* Only valid when chain of statements is added, move
10479455Sobrien			   iterator to the last statement in the chain.  */
10579455Sobrien  TSI_CONTINUE_LINKING	/* Move iterator to whatever position is suitable for
10679455Sobrien			   linking other statements/chains of statements in
10779455Sobrien			   the same direction.  */
10879455Sobrien};
10979455Sobrien
11079455Sobrienextern void tsi_link_before (tree_stmt_iterator *, tree,
11179455Sobrien			     enum tsi_iterator_update);
11279455Sobrienextern void tsi_link_after (tree_stmt_iterator *, tree,
11379455Sobrien			    enum tsi_iterator_update);
11479455Sobrien
11579455Sobrienvoid tsi_delink (tree_stmt_iterator *);
11679455Sobrien
11779455Sobrientree tsi_split_statement_list_after (const tree_stmt_iterator *);
11879455Sobrientree tsi_split_statement_list_before (tree_stmt_iterator *);
11979455Sobrien
12079455Sobrienvoid append_to_statement_list (tree, tree *);
12179455Sobrienvoid append_to_statement_list_force (tree, tree *);
12279455Sobrien
12379455Sobrien#endif /* GCC_TREE_ITERATOR_H  */
12479455Sobrien