00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef _CVC_lite__theorem_value_h_
00054 #define _CVC_lite__theorem_value_h_
00055
00056 #include "theorem.h"
00057 #include "theorem_manager.h"
00058
00059 namespace CVCL {
00060
00061 class TheoremValue
00062 {
00063
00064 friend class Theorem;
00065 friend class RWTheoremValue;
00066 friend class ReflexivityTheoremValue;
00067
00068 protected:
00069
00070 TheoremManager* d_tm;
00071
00072
00073 Expr d_thm;
00074
00075
00076 Assumptions d_assump;
00077
00078
00079 Proof d_proof;
00080
00081
00082 int d_refcount : 16;
00083
00084
00085 int d_scopeLevel : 16;
00086
00087
00088 unsigned d_flag;
00089
00090
00091 int d_cachedValue : 29;
00092
00093 bool d_isAssump : 1;
00094 bool d_expand : 1;
00095 bool d_clauselit : 1;
00096
00097
00098 private:
00099
00100
00101
00102
00103
00104
00105
00106 TheoremValue(TheoremManager* tm, const Expr &thm,
00107 const Assumptions& assump, const Proof& pf,
00108 bool isAssump, int scope = -1) :
00109 d_tm(tm), d_thm(thm), d_proof(pf), d_refcount(0),
00110 d_scopeLevel(0), d_flag(0), d_isAssump(isAssump) {
00111 DebugAssert(d_tm->isActive(), "TheoremValue()");
00112 if (isAssump) {
00113 if (scope == -1) d_scopeLevel = tm->getCM()->scopeLevel();
00114 else d_scopeLevel = scope;
00115 }
00116 else {
00117 d_assump = assump;
00118 d_assump.setConst();
00119 if (!d_assump.isNull() && !d_assump.empty()) {
00120
00121 const Assumptions::iterator iend = d_assump.end();
00122 for (Assumptions::iterator i = d_assump.begin();
00123 i != iend; ++i)
00124 if (i->getScope() > d_scopeLevel)
00125 d_scopeLevel = i->getScope();
00126 }
00127 }
00128 }
00129
00130 TheoremValue(const TheoremValue& t) {
00131 FatalAssert(false, "TheoremValue() copy constructor called");
00132 }
00133 TheoremValue& operator=(const TheoremValue& t) {
00134 FatalAssert(false, "TheoremValue assignment operator called");
00135 return *this;
00136 }
00137
00138 bool isFlagged() const {
00139 return d_flag == d_tm->getFlag();
00140 }
00141
00142 void clearAllFlags() {
00143 d_tm->clearAllFlags();
00144 }
00145
00146 void setFlag() {
00147 d_flag = d_tm->getFlag();
00148 }
00149
00150 void setCachedValue(int value) {
00151 d_cachedValue = value;
00152 }
00153
00154 int getCachedValue() const {
00155 return d_cachedValue;
00156 }
00157
00158 void setExpandFlag(bool val) {
00159 d_expand = val;
00160 }
00161
00162 bool getExpandFlag() {
00163 return d_expand;
00164 }
00165
00166 void setLitFlag(bool val) {
00167 d_clauselit = val;
00168 }
00169
00170 bool getLitFlag() {
00171 return d_clauselit;
00172 }
00173
00174 int getScope() {
00175 return d_scopeLevel;
00176 }
00177
00178
00179 virtual bool isRewrite() const { return false; }
00180
00181 virtual const Expr& getExpr() const { return d_thm; }
00182 virtual const Expr& getLHS() const {
00183
00184 DebugAssert(isRewrite(),
00185 "TheoremValue::getLHS() called on non-rewrite theorem:\n"
00186 +toString());
00187 return d_thm[0];
00188 }
00189 virtual const Expr& getRHS() const {
00190
00191 DebugAssert(isRewrite(),
00192 "TheoremValue::getRHS() called on non-rewrite theorem:\n"
00193 +toString());
00194 return d_thm[1];
00195 }
00196
00197 const Assumptions& getAssumptionsRef() const { return d_assump; }
00198
00199 bool isAssump() const { return d_isAssump; }
00200 const Proof& getProof() { return d_proof; }
00201
00202 public:
00203
00204 virtual ~TheoremValue() {
00205 DebugAssert(d_refcount == 0,
00206 "Thm::TheoremValue::~TheoremValue(): refcount != 0.");
00207 }
00208
00209 std::string toString() const {
00210 return d_assump.toString() + " |- " + getExpr().toString();
00211 }
00212
00213
00214 virtual MemoryManager* getMM() { return d_tm->getMM(); }
00215
00216 void* operator new(size_t size, MemoryManager* mm) {
00217 return mm->newData(size);
00218 }
00219
00220 void operator delete(void* d) { }
00221
00222 };
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 class RWTheoremValue :public TheoremValue
00236 {
00237 friend class Theorem;
00238
00239 protected:
00240
00241
00242 Expr d_lhs;
00243 Expr d_rhs;
00244
00245 private:
00246
00247 RWTheoremValue(TheoremManager* tm, const Expr& lhs, const Expr& rhs,
00248 const Assumptions& assump, const Proof& pf, bool isAssump,
00249 int scope = -1)
00250 : TheoremValue(tm, Expr(), assump, pf, isAssump, scope),
00251 d_lhs(lhs), d_rhs(rhs) { }
00252
00253
00254 RWTheoremValue(TheoremManager* tm, const Expr& thm,
00255 const Assumptions& assump, const Proof& pf, bool isAssump,
00256 int scope = -1)
00257 : TheoremValue(tm, thm, assump, pf, isAssump, scope),
00258 d_lhs(thm[0]), d_rhs(thm[1]) { }
00259
00260 const Expr& getExpr() const {
00261 if (d_thm.isNull()) {
00262 bool isBool = d_lhs.getType().isBool();
00263
00264 Expr* pexpr = const_cast<Expr*>(&d_thm);
00265 *pexpr = isBool ? d_lhs.iffExpr(d_rhs) : d_lhs.eqExpr(d_rhs);
00266
00267 }
00268 return d_thm;
00269 }
00270
00271 const Expr& getLHS() const { return d_lhs; }
00272 const Expr& getRHS() const { return d_rhs; }
00273
00274 public:
00275
00276 ~RWTheoremValue() {}
00277
00278 bool isRewrite() const { return true; }
00279
00280
00281 MemoryManager* getMM() { return d_tm->getRWMM(); }
00282
00283 void* operator new(size_t size, MemoryManager* mm) {
00284 return mm->newData(size);
00285 }
00286
00287 void operator delete(void* d) { }
00288
00289 };
00290
00291
00292
00293
00294
00295 class ReflexivityTheoremValue: public TheoremValue {
00296 friend class Theorem;
00297 private:
00298
00299 Expr d_expr;
00300
00301 ReflexivityTheoremValue(TheoremManager* tm, const Expr& e, const Proof& pf)
00302 : TheoremValue(tm, Expr(), Assumptions(), pf, false), d_expr(e) { }
00303
00304 ~ReflexivityTheoremValue() { }
00305
00306 bool isRewrite() const { return true; }
00307 const Expr& getLHS() const { return d_expr; }
00308 const Expr& getRHS() const { return d_expr; }
00309
00310 const Expr& getExpr() const {
00311 if (d_thm.isNull()) {
00312 bool isBool = d_expr.getType().isBool();
00313
00314 Expr* pexpr = const_cast<Expr*>(&d_thm);
00315 *pexpr = isBool ? d_expr.iffExpr(d_expr) : d_expr.eqExpr(d_expr);
00316 }
00317 return d_thm;
00318 }
00319
00320
00321 MemoryManager* getMM() { return d_tm->getReflMM(); }
00322
00323 void* operator new(size_t size, MemoryManager* mm) {
00324 return mm->newData(size);
00325 }
00326
00327 void operator delete(void* d) { }
00328
00329 };
00330
00331 };
00332
00333 #endif