tree-iterator.h 3.2 KB

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