ROSE  0.10.5.0
RoseAst.h
1 
2 #ifndef ROSE_AST_H
3 #define ROSE_AST_H
4 
5 /*************************************************************
6  * Copyright: (C) 2012 Markus Schordan *
7  * Author : Markus Schordan *
8  * License : see file LICENSE in the CodeThorn distribution *
9  *************************************************************/
10 
11 #include <stack>
12 #include "roseInternal.h"
13 
28 class RoseAst {
29  public:
30  typedef SgNode elementType;
31  typedef elementType* pointer;
32  typedef elementType& reference;
33  typedef size_t size_type;
34 
35  // no default constructor
36 
41  RoseAst(SgNode* astNode);
42 
56  class iterator {
57  public:
58 
62  iterator();
63 
65  iterator(SgNode* x,bool withNullValues, bool withTemplates);
66 
76  bool operator==(const iterator& x) const;
77 
81  bool operator!=(const iterator& x) const;
82 
88  SgNode* operator*() const;
89 
97  iterator& operator++(); // prefix
98  iterator operator++(int); // postfix
107  void skipChildrenOnForward();
108 
127  iterator& withoutTemplates();
128  iterator& withTemplates();
129 
134  SgNode* parent() const;
135 
139  bool is_at_root() const;
140 
145  bool is_at_first_child() const;
146 
151  bool is_at_last_child() const;
152 
153  // internal
154  bool is_past_the_end() const;
155  // internal
156  std::string current_node_id() const;
157  // internal
158  std::string parent_node_id() const;
159  // internal
160  void print_top_element() const;
161 
163  int stack_size() const;
164 
165  protected:
166  SgNode* _startNode;
167  bool _skipChildrenOnForward;
168  bool _withNullValues;
169  bool _withTemplates;
170 
171  private:
172  static const int ROOT_NODE_INDEX=-2;
173  friend class RoseAst;
174  typedef struct {SgNode* node; int index;} stack_element;
175  std::stack<stack_element> _stack;
176  SgNode* access_node_by_parent_and_index(SgNode* p, int index) const;
177 
178  // not necessary with a children iterator
179  int num_children(SgNode* p) const;
180  };
181 
186  iterator begin();
187 
191  iterator end();
192 
193  // ast access function
194  SgFunctionDefinition* findFunctionByName(std::string name);
195  std::list<SgFunctionDeclaration*> findFunctionDeclarationsByName(std::string name);
196 
198  static bool isTemplateInstantiationNode(SgNode* node);
199 
201  static bool isTemplateNode(SgNode* node);
202 
204 static bool isSubTypeOf(VariantT DerivedClassVariant, VariantT BaseClassVariant);
206 static bool isSubType(VariantT DerivedClassVariant, VariantT BaseClassVariant);
207  void setWithNullValues(bool flag);
208  void setWithTemplates(bool flag);
209 
210  protected:
211  static SgNode* parent(SgNode* astNode);
212  private:
213  SgNode* _startNode;
214  bool _withNullValues;
215  bool _withTemplates;
216 };
217 
218 #endif
SgNode * parent() const
Parent AST node relative to the iteration.
iterator & operator++()
Advance the iterator.
bool operator!=(const iterator &x) const
Test iterator inequality.
RoseAst(SgNode *astNode)
Defines the starting node for traversal.
static bool isSubTypeOf(VariantT DerivedClassVariant, VariantT BaseClassVariant)
determines based on VariantT whether a ROSE-AST node is a subtype of another node type...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
static bool isTemplateInstantiationNode(SgNode *node)
determines whether a node is used to represent the root node of a template instantiation ...
bool operator==(const iterator &x) const
Test iterator equality.
AST iterator.
Definition: RoseAst.h:56
Interface for iterating over an AST.
Definition: RoseAst.h:28
SgNode * operator*() const
Dereference an iterator.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9176
bool is_at_last_child() const
Test whether iterator as at the last child of its parent.
iterator end()
Iterator positioned at the end of the traversal.
static bool isTemplateNode(SgNode *node)
determines whether a node is used to represent the root node of a template.
bool is_at_first_child() const
Test whether iterator is at the first child of its parent.
bool is_at_root() const
Test whether iterator is pointing to root node of AST to be traversed.
iterator begin()
Iterator positioned at root of subtree.
iterator & withoutNullValues()
Mode to enable or disable skipping null child pointers.
iterator & withNullValues()
Mode to enable or disable skipping null child pointers.
iterator()
Default constructor.
static bool isSubType(VariantT DerivedClassVariant, VariantT BaseClassVariant)
deprecated, use isSubTypeOf instead
void skipChildrenOnForward()
Cause children to be skipped on the next advancement.
int stack_size() const
Depth of traversal.