00001 #ifndef _STREE_NODE_H_ 00002 #define _STREE_NODE_H_ 00003 00004 #include "location.h" 00005 00006 #include <map> 00007 #include <string> 00008 #include <set> 00009 #include <iostream> 00010 00011 #ifndef DOXYSKIP 00012 using namespace std; 00013 #endif 00014 00016 enum SType { 00017 SVariable, 00018 SConstant, 00019 SList, 00020 SPin, 00021 SContext 00022 }; 00023 00024 class NameSpace; 00025 class List; 00026 00028 class Node 00029 { 00030 protected: 00032 Location location; 00033 00034 public: 00036 class Assignment : public map<int,const Node*>{ 00037 public: 00038 ~Assignment(){ 00039 iterator it = begin(); 00040 iterator eit = end(); 00041 while (it!=eit){ 00042 delete it->second; 00043 it++; 00044 }; 00045 }; 00046 }; 00047 00049 class Transformer { 00050 public: 00051 virtual Node* transform(Node* node) const = 0; 00052 }; 00053 00055 class Tester { 00056 public: 00057 virtual bool test(const Node* node, const NameSpace &nameSpace) const = 0; 00058 virtual Tester* copy() const = 0; 00059 virtual Tester* substitute(const Assignment &assign) = 0; 00060 virtual ~Tester() {}; 00061 }; 00062 00064 typedef set<int> VariableList; 00065 00067 friend ostream& operator<<(ostream &os, const Assignment &data); 00068 00070 Node(const string &icomment, const int ilineno = 0) : location(icomment,ilineno) {} 00071 00073 Node() : location("",0) {}; 00074 00076 virtual ~Node() {}; 00077 00079 virtual SType getType() const = 0; 00080 00082 virtual string getName() const = 0; 00083 00085 virtual ostream& print(ostream &os) const = 0; 00086 00088 virtual ostream& php(ostream &os) const = 0; 00089 00091 virtual bool match(const Node *p, Assignment &assign, const NameSpace &nameSpace) const = 0; 00092 00094 virtual bool matchToBegining(const List *p, Assignment &assign, const NameSpace &nameSpace) const = 0; 00095 00097 virtual bool compare(const Node *p) const = 0; 00098 00100 virtual Node* copy() const = 0; 00101 00103 virtual void getVariables(VariableList &vlist) const = 0; 00104 00106 friend ostream& operator<<(ostream &os, const Node *data); 00107 00109 string toString() const; 00110 00112 virtual Node* push_back(Node *statement); 00113 00115 virtual Node* transform(const Transformer* transformer); 00116 00118 virtual bool forall(const Tester* tester, const NameSpace &nameSpace) const; 00119 00121 virtual bool exists(const Tester* tester, const NameSpace &nameSpace) const; 00122 00124 friend void substituteNode(Node* &node, const Assignment &assign); 00125 00127 virtual string evaluate(const NameSpace &nameSpace) const = 0; 00128 00130 virtual int getLength() const; 00131 00132 protected: 00134 virtual Node* substitute(const Assignment &assign) = 0; 00135 }; 00136 00137 #endif 00138