00001 // Author: Markus Schordan, Vienna University of Technology, 2004. 00002 // $Id: Ast.h,v 1.4 2008/01/08 02:56:38 dquinlan Exp $ 00003 00004 // WORK IN PROGRESS : only use the public interface (!) 00005 // - currently only the forward iterator is supported 00006 // - copy-by-value will be replaced by references and using const 00007 // - null_iterator may also be added (including encountered null pointers) 00008 00009 #ifndef AST_H 00010 #define AST_H 00011 00012 #include <vector> 00013 #include "roseInternal.h" 00014 //#include "sage3.h" 00015 00019 00020 class Ast { 00021 public: 00022 typedef SgNode elementType; 00023 typedef elementType* pointer; 00024 typedef elementType& reference; 00025 typedef size_t size_type; 00026 // no default constructor 00027 00029 Ast(SgNode* astNode); 00030 SgNode* operator*(); 00031 00032 class iterator { 00033 private: 00034 friend class Ast; 00035 SgNode* findNextNode(SgNode* p); 00036 00037 protected: 00038 // DQ (10/24/2004): Swapped order of declaration to avoid compiler warning 00039 SgNode* node; 00040 SgNode* startNode; 00041 iterator(SgNode* x) : node(x),startNode(x) {} 00042 00043 public: 00044 iterator() {} 00045 bool operator==(const iterator& x) const { return node == x.node; } 00046 bool operator!=(const iterator& x) const { return node != x.node; } 00047 reference operator*() const { return (*node); } 00048 iterator& operator++(); 00049 iterator operator++(int) { 00050 iterator tmp = *this; 00051 ++*this; 00052 return tmp; 00053 } 00054 }; 00055 00057 iterator begin() { return iterator(startNode); } 00059 iterator end() { return iterator(0); } 00060 00061 protected: 00062 typedef std::vector<SgNode*> NodeList; 00063 static NodeList successors(SgNode* astNode); 00064 static unsigned int numSuccessors(SgNode* astNode); 00065 static NodeList rightSiblings(SgNode* astNode); 00066 static unsigned int numRightSiblings(SgNode* astNode); 00067 static SgNode* nextRightSibling(SgNode* astNode); 00068 static SgNode* parent(SgNode* astNode); 00069 private: 00070 static SgNode* first(NodeList l) { return *(l.begin()); } 00071 SgNode* startNode; 00072 }; 00073 00074 #endif
1.4.7