00001 #ifndef _CTREE_H_ 00002 #define _CTREE_H_ 00003 00004 #include "stree.h" 00005 00007 00013 class ContextMatch : public Node 00014 { 00015 protected: 00017 Node* node; 00019 Tester* tester; 00020 public: 00022 ContextMatch(Node* inode, Tester* itester) : node(inode), tester(itester) {}; 00023 00025 virtual ~ContextMatch(){ 00026 delete node; 00027 delete tester; 00028 }; 00029 00030 virtual SType getType() const { return node->getType(); }; 00031 00032 virtual string getName() const { return node->getName(); }; 00033 00034 virtual ostream& print(ostream &os) const{ 00035 os << "ContextMatch{"; 00036 node->print(os); 00037 os << "}"; 00038 return os; 00039 }; 00040 00041 virtual ostream& php(ostream &os) const{ 00042 return node->php(os); 00043 } 00044 00045 virtual bool match(const Node* p, Assignment &assign, const NameSpace &nameSpace)const { 00046 Tester* toTest = tester->copy()->substitute(assign); 00047 if (!toTest->test(p, nameSpace)) { 00048 delete toTest; 00049 return false; 00050 } 00051 delete toTest; 00052 return node->match(p,assign,nameSpace); 00053 }; 00054 00055 virtual bool matchToBegining(const List* p, Assignment &assign, const NameSpace &nameSpace)const { 00056 if (!tester->test(p, nameSpace)) return false; 00057 return node->matchToBegining(p,assign,nameSpace); 00058 }; 00059 00060 virtual bool compare(const Node* p) const { 00061 return node->compare(p); 00062 }; 00063 00064 virtual Node* copy() const { 00065 return new ContextMatch(node->copy(), tester->copy()); 00066 }; 00067 00068 virtual void getVariables(VariableList &vlist) const{ 00069 node->getVariables(vlist); 00070 }; 00071 00072 virtual string evaluate(const NameSpace &nameSpace) const{ 00073 return node->evaluate(nameSpace); 00074 }; 00075 00076 virtual int getLength() const{ 00077 return node->getLength(); 00078 }; 00079 00080 protected: 00081 00082 virtual Node* substitute(const Assignment &assign){ 00083 substituteNode(node,assign); 00084 return this; 00085 }; 00086 00087 }; 00088 00090 00095 class AttributeValue : public Node 00096 { 00097 protected: 00099 Node* variable; 00101 Node* attribute; 00103 const bool global; 00104 public: 00106 AttributeValue(Node* ivariable, Node* iattribute, bool iglobal) : variable(ivariable), attribute(iattribute), global(iglobal) {}; 00107 00109 virtual ~AttributeValue(){ 00110 delete variable; 00111 delete attribute; 00112 }; 00113 00114 virtual SType getType() const { throw "ERROR: AttributeValue::getType"; }; 00115 00116 virtual string getName() const { throw "ERROR: AttributeValue::getName"; }; 00117 00118 virtual ostream& print(ostream &os) const{ 00119 os << "AttributeValue{"; 00120 variable->print(os); 00121 attribute->print(os); 00122 os << "}"; 00123 return os; 00124 }; 00125 00126 virtual ostream& php(ostream &os) const{ 00127 throw "ERROR: AttributeValue::php"; 00128 } 00129 00130 virtual bool match(const Node* p, Assignment &assign, const NameSpace &nameSpace)const { 00131 throw "ERROR: AttributeValue::match"; 00132 }; 00133 00134 virtual bool matchToBegining(const List* p, Assignment &assign, const NameSpace &nameSpace)const { 00135 throw "ERROR: AttributeValue::matchToBegining"; 00136 }; 00137 00138 virtual bool compare(const Node* p) const { 00139 throw "ERROR: AttributeValue::compare"; 00140 }; 00141 00142 virtual Node* copy() const { 00143 return new AttributeValue(variable->copy(), attribute->copy(),global); 00144 }; 00145 00146 virtual void getVariables(VariableList &vlist) const{ 00147 throw "ERROR: AttributeValue::getVariables"; 00148 }; 00149 00150 virtual string evaluate(const NameSpace &nameSpace) const{ 00151 return nameSpace.getAttributeValue(variable->toString(), attribute->toString(),global); 00152 }; 00153 00154 protected: 00155 00156 virtual Node* substitute(const Assignment &assign){ 00157 substituteNode(variable,assign); 00158 substituteNode(attribute,assign); 00159 return this; 00160 }; 00161 00162 }; 00163 00164 00165 #endif