ROSE  0.11.96.11
RoseAst.h
1 
2 #ifndef ROSE_AST_H
3 #define ROSE_AST_H
4 
5 /*************************************************************
6  * Author : Markus Schordan *
7  *************************************************************/
8 
9 #include <stack>
10 #include "roseInternal.h"
11 
26 class RoseAst {
27  public:
28  typedef SgNode elementType;
29  typedef elementType* pointer;
30  typedef elementType& reference;
31  typedef size_t size_type;
32 
33  // no default constructor
34 
39  RoseAst(SgNode* astNode);
40 
54  class iterator {
55  public:
56 
60  iterator();
61 
63  iterator(SgNode* x,bool withNullValues, bool withTemplates);
64 
74  bool operator==(const iterator& x) const;
75 
79  bool operator!=(const iterator& x) const;
80 
86  SgNode* operator*() const;
87 
95  iterator& operator++(); // prefix
96  iterator operator++(int); // postfix
105  void skipChildrenOnForward();
106 
125  iterator& withoutTemplates();
126  iterator& withTemplates();
127 
132  SgNode* parent() const;
133 
137  bool is_at_root() const;
138 
143  bool is_at_first_child() const;
144 
149  bool is_at_last_child() const;
150 
151  // internal
152  bool is_past_the_end() const;
153  // internal
154  std::string current_node_id() const;
155  // internal
156  std::string parent_node_id() const;
157  // internal
158  void print_top_element() const;
159 
161  int stack_size() const;
162 
163  protected:
164  SgNode* _startNode;
165  bool _skipChildrenOnForward;
166  bool _withNullValues;
167  bool _withTemplates;
168 
169  private:
170  static const int ROOT_NODE_INDEX=-2;
171  friend class RoseAst;
172  typedef struct {SgNode* node; int index;} stack_element;
173  std::stack<stack_element> _stack;
174  SgNode* access_node_by_parent_and_index(SgNode* p, int index) const;
175 
176  // not necessary with a children iterator
177  int num_children(SgNode* p) const;
178  };
179 
184  iterator begin();
185 
189  iterator end();
190 
191  // ast access function
192  SgFunctionDefinition* findFunctionByName(std::string name);
193  std::list<SgFunctionDeclaration*> findFunctionDeclarationsByName(std::string name);
194 
196  static bool isTemplateInstantiationNode(SgNode* node);
197 
199  static bool isTemplateNode(SgNode* node);
200 
202 static bool isSubTypeOf(VariantT DerivedClassVariant, VariantT BaseClassVariant);
204 static bool isSubType(VariantT DerivedClassVariant, VariantT BaseClassVariant);
205  void setWithNullValues(bool flag);
206  void setWithTemplates(bool flag);
207 
208  protected:
209  static SgNode* parent(SgNode* astNode);
210  private:
211  SgNode* _startNode;
212  bool _withNullValues;
213  bool _withTemplates;
214 };
215 
216 #endif
RoseAst::isSubTypeOf
static bool isSubTypeOf(VariantT DerivedClassVariant, VariantT BaseClassVariant)
determines based on VariantT whether a ROSE-AST node is a subtype of another node type.
RoseAst::iterator::operator!=
bool operator!=(const iterator &x) const
Test iterator inequality.
RoseAst::iterator::operator*
SgNode * operator*() const
Dereference an iterator.
RoseAst::iterator::operator++
iterator & operator++()
Advance the iterator.
RoseAst::begin
iterator begin()
Iterator positioned at root of subtree.
RoseAst::iterator::skipChildrenOnForward
void skipChildrenOnForward()
Cause children to be skipped on the next advancement.
RoseAst
Interface for iterating over an AST.
Definition: RoseAst.h:26
RoseAst::RoseAst
RoseAst(SgNode *astNode)
Defines the starting node for traversal.
RoseAst::iterator
AST iterator.
Definition: RoseAst.h:56
RoseAst::iterator::withoutNullValues
iterator & withoutNullValues()
Mode to enable or disable skipping null child pointers.
RoseAst::iterator::operator==
bool operator==(const iterator &x) const
Test iterator equality.
RoseAst::isTemplateInstantiationNode
static bool isTemplateInstantiationNode(SgNode *node)
determines whether a node is used to represent the root node of a template instantiation
SgNode
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:6739
RoseAst::iterator::stack_size
int stack_size() const
Depth of traversal.
RoseAst::iterator::parent
SgNode * parent() const
Parent AST node relative to the iteration.
RoseAst::isTemplateNode
static bool isTemplateNode(SgNode *node)
determines whether a node is used to represent the root node of a template.
SgFunctionDefinition
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
Definition: Cxx_Grammar.h:126549
RoseAst::iterator::withNullValues
iterator & withNullValues()
Mode to enable or disable skipping null child pointers.
RoseAst::end
iterator end()
Iterator positioned at the end of the traversal.
RoseAst::iterator::is_at_first_child
bool is_at_first_child() const
Test whether iterator is at the first child of its parent.
RoseAst::iterator::is_at_root
bool is_at_root() const
Test whether iterator is pointing to root node of AST to be traversed.
RoseAst::iterator::iterator
iterator()
Default constructor.
RoseAst::iterator::is_at_last_child
bool is_at_last_child() const
Test whether iterator as at the last child of its parent.
RoseAst::isSubType
static bool isSubType(VariantT DerivedClassVariant, VariantT BaseClassVariant)
deprecated, use isSubTypeOf instead