00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "MP_boolean.hpp"
00010 #include "MP_constant.hpp"
00011 #include "MP_domain.hpp"
00012 #include "MP_set.hpp"
00013 #include "MP_index.hpp"
00014
00015 namespace flopc {
00016
00017 class Boolean_bool : public Boolean_base {
00018 friend class MP_boolean;
00019 private:
00020 Boolean_bool(bool b) : B(b) {}
00021 bool evaluate() const {
00022 return B;
00023 }
00024 bool B;
00025 };
00026
00027 class Boolean_Constant : public Boolean_base {
00028 friend class MP_boolean;
00029 private:
00030 Boolean_Constant(const Constant& c) : C(c) {}
00031 bool evaluate() const {
00032 return C->evaluate();
00033 }
00034 Constant C;
00035 };
00036
00037 class Boolean_SUBSETREF : public Boolean_base {
00038 friend class MP_boolean;
00039 private:
00040 Boolean_SUBSETREF(SUBSETREF& c) : C(&c) {}
00041 bool evaluate() const {
00042 if (C->evaluate() == outOfBound) {
00043 return false;
00044 } else {
00045 return true;
00046 }
00047 }
00048 SUBSETREF* C;
00049 };
00050
00051 class Boolean_negate : public Boolean_base {
00052 friend MP_boolean operator!(const MP_boolean& b);
00053 private:
00054 Boolean_negate(const MP_boolean& b) : B(b) {}
00055 bool evaluate() const {
00056 return !(B->evaluate());
00057 }
00058 MP_boolean B;
00059 };
00060
00061 class Boolean_and : public Boolean_base {
00062 friend MP_boolean operator&&(const MP_boolean& e1, const MP_boolean& e2);
00063 private:
00064 Boolean_and(const MP_boolean& e1, const MP_boolean e2) : left(e1), right(e2) {}
00065 bool evaluate() const {
00066 return left->evaluate() && right->evaluate();
00067 }
00068 MP_boolean left, right;
00069 };
00070
00071 class Boolean_or : public Boolean_base {
00072 friend MP_boolean operator||(const MP_boolean& e1, const MP_boolean& e2);
00073 private:
00074 Boolean_or(const MP_boolean& e1, const MP_boolean& e2) : left(e1), right(e2) {}
00075 bool evaluate() const {
00076 return left->evaluate() || right->evaluate();
00077 }
00078 MP_boolean left, right;
00079 };
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 class Comparison : public Boolean_base {
00093 protected:
00094 Comparison(const Constant& e1, const Constant& e2) : left(e1), right(e2) {}
00095 Constant left,right;
00096 };
00097
00098 class Boolean_lessEq : public Comparison {
00099 friend MP_boolean operator<=(const MP_index_exp& e1,const MP_index_exp& e2);
00100 friend MP_boolean operator<=(const Constant& e1, const Constant& e2);
00101 private:
00102 Boolean_lessEq(const Constant& e1, const Constant& e2):Comparison(e1,e2) {}
00103 bool evaluate() const {
00104 return (left->evaluate() <= right->evaluate());
00105 }
00106 };
00107
00108 class Boolean_less : public Comparison {
00109 friend MP_boolean operator<(const MP_index_exp& e1,
00110 const MP_index_exp& e2);
00111 friend MP_boolean operator<(const Constant& e1, const Constant& e2);
00112 private:
00113 Boolean_less(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
00114 bool evaluate() const {
00115 return (left->evaluate() < right->evaluate());
00116 }
00117 };
00118
00119 class Boolean_greaterEq : public Comparison {
00120 friend MP_boolean operator>=(MP_index& e1, MP_index& e2);
00121 friend MP_boolean operator>=(const MP_index_exp& e1,
00122 const MP_index_exp& e2);
00123 friend MP_boolean operator>=(const Constant& e1, const Constant& e2);
00124 private:
00125 Boolean_greaterEq(const Constant& e1, const Constant& e2) :
00126 Comparison(e1,e2) {}
00127 bool evaluate() const {
00128 return (left->evaluate() >= right->evaluate());
00129 }
00130 };
00131
00132 class Boolean_greater : public Comparison {
00133 friend MP_boolean operator>(const MP_index_exp& e1, const MP_index_exp& e2);
00134 friend MP_boolean operator>(const Constant& e1, const Constant& e2);
00135 private:
00136 Boolean_greater(const Constant& e1, const Constant& e2): Comparison(e1,e2) {}
00137 bool evaluate() const {
00138 return (left->evaluate() > right->evaluate());
00139 }
00140 };
00141
00142 class Boolean_equal : public Comparison {
00143 friend MP_boolean operator==(const MP_index_exp& e1, const MP_index_exp& e2);
00144 friend MP_boolean operator==(const Constant& e1, const Constant& e2);
00145 private:
00146 Boolean_equal(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
00147 bool evaluate() const {
00148 return (left->evaluate() == right->evaluate());
00149 }
00150 };
00151
00152 class Boolean_not_equal : public Comparison {
00153 friend MP_boolean operator!=(const MP_index_exp& e1, const MP_index_exp& e2);
00154 friend MP_boolean operator!=(const Constant& e1, const Constant& e2);
00155 private:
00156 Boolean_not_equal(const Constant& e1, const Constant& e2) : Comparison(e1,e2) {}
00157 bool evaluate() const {
00158 return (left->evaluate() != right->evaluate());
00159 }
00160 };
00161
00162
00163
00164
00165
00166 MP_boolean operator!(const MP_boolean& b) {
00167 return new Boolean_negate(b);
00168 }
00169 MP_boolean operator&&(const MP_boolean& e1, const MP_boolean& e2) {
00170 return new Boolean_and(e1, e2);
00171 }
00172 MP_boolean operator||(const MP_boolean& e1, const MP_boolean& e2) {
00173 return new Boolean_or(e1, e2);
00174 }
00175 MP_boolean operator<=(const MP_index_exp& e1, const MP_index_exp& e2) {
00176 return new Boolean_lessEq(e1, e2);
00177 }
00178 MP_boolean operator<=(const Constant& e1, const Constant& e2) {
00179 return new Boolean_lessEq(e1, e2);
00180 }
00181 MP_boolean operator<(const MP_index_exp& e1, const MP_index_exp& e2) {
00182 return new Boolean_less(e1, e2);
00183 }
00184 MP_boolean operator<(const Constant& e1, const Constant& e2) {
00185 return new Boolean_less(e1, e2);
00186 }
00187 MP_boolean operator>=(const MP_index_exp& e1, const MP_index_exp& e2) {
00188 return new Boolean_greaterEq(e1, e2);
00189 }
00190 MP_boolean operator>=(const Constant& e1, const Constant& e2) {
00191 return new Boolean_greaterEq(e1, e2);
00192 }
00193 MP_boolean operator>(const MP_index_exp& e1, const MP_index_exp& e2) {
00194 return new Boolean_greater(e1, e2);
00195 }
00196 MP_boolean operator>(const Constant& e1, const Constant& e2) {
00197 return new Boolean_greater(e1, e2);
00198 }
00199 MP_boolean operator==(const MP_index_exp& e1, const MP_index_exp& e2) {
00200 return new Boolean_equal(e1, e2);
00201 }
00202 MP_boolean operator!=(const MP_index_exp& e1, const MP_index_exp& e2) {
00203 return new Boolean_not_equal(e1, e2);
00204 }
00205 MP_boolean operator==(const Constant& e1, const Constant& e2) {
00206 return new Boolean_equal(e1, e2);
00207 }
00208 MP_boolean operator!=(const Constant& e1, const Constant& e2) {
00209 return new Boolean_not_equal(e1, e2);
00210 }
00211
00212 }
00213
00214 using namespace flopc;
00215
00216 MP_boolean::MP_boolean(bool b) : Handle<Boolean_base*>(new Boolean_bool(b)) {}
00217
00218 MP_boolean::MP_boolean(const Constant& c) : Handle<Boolean_base*>(new Boolean_Constant(c)) {}
00219
00220 MP_boolean::MP_boolean(SUBSETREF& c) : Handle<Boolean_base*>(new Boolean_SUBSETREF(c)) {}