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 #ifndef _cvc3__theorem_value_h_
00046 #define _cvc3__theorem_value_h_
00047
00048 #include "assumptions.h"
00049 #include "theorem_manager.h"
00050
00051
00052
00053 namespace CVC3 {
00054
00055
00056 class TheoremValue
00057 {
00058
00059 friend class Theorem;
00060 friend class RegTheoremValue;
00061 friend class RWTheoremValue;
00062
00063 protected:
00064
00065 TheoremManager* d_tm;
00066
00067
00068 Expr d_thm;
00069
00070
00071 Proof d_proof;
00072
00073
00074 unsigned d_refcount;
00075
00076
00077 int d_scopeLevel;
00078
00079
00080 unsigned d_quantLevel;
00081
00082
00083
00084
00085
00086
00087 unsigned d_flag;
00088
00089
00090 int d_cachedValue : 28;
00091
00092 bool d_isSubst : 1;
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
00107
00108
00109
00110 TheoremValue(TheoremManager* tm, const Expr &thm,
00111 const Proof& pf, bool isAssump) :
00112 d_tm(tm), d_thm(thm), d_proof(pf), d_refcount(0),
00113 d_scopeLevel(0), d_quantLevel(0), d_flag(0), d_cachedValue(0),
00114 d_isSubst(0), d_isAssump(isAssump), d_expand(0), d_clauselit(0) {}
00115
00116
00117 TheoremValue(const TheoremValue& t) {
00118 FatalAssert(false, "TheoremValue() copy constructor called");
00119 }
00120 TheoremValue& operator=(const TheoremValue& t) {
00121 FatalAssert(false, "TheoremValue assignment operator called");
00122 return *this;
00123 }
00124
00125 bool isFlagged() const {
00126 return d_flag == d_tm->getFlag();
00127 }
00128
00129 void clearAllFlags() {
00130 d_tm->clearAllFlags();
00131 }
00132
00133 void setFlag() {
00134 d_flag = d_tm->getFlag();
00135 }
00136
00137 void setCachedValue(int value) {
00138 d_cachedValue = value;
00139 }
00140
00141 int getCachedValue() const {
00142 return d_cachedValue;
00143 }
00144
00145 void setSubst() { d_isSubst = true; }
00146 bool isSubst() { return d_isSubst; }
00147
00148 void setExpandFlag(bool val) {
00149 d_expand = val;
00150 }
00151
00152 bool getExpandFlag() {
00153 return d_expand;
00154 }
00155
00156 void setLitFlag(bool val) {
00157 d_clauselit = val;
00158 }
00159
00160 bool getLitFlag() {
00161 return d_clauselit;
00162 }
00163
00164 int getScope() {
00165 return d_scopeLevel;
00166 }
00167
00168 unsigned getQuantLevel() { return d_quantLevel; }
00169
00170 unsigned getQuantLevelDebug() {
00171 return 0;
00172
00173 }
00174
00175 void setQuantLevel(unsigned level) { d_quantLevel = level; }
00176
00177 unsigned recQuantLevel(Expr proof){
00178 return d_quantLevel;
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 }
00246
00247 unsigned findQuantLevelDebug(){
00248 return d_quantLevel;
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 }
00292
00293
00294
00295 virtual bool isRewrite() const { return false; }
00296
00297 virtual const Expr& getExpr() const { return d_thm; }
00298 virtual const Expr& getLHS() const {
00299
00300 DebugAssert(isRewrite(),
00301 "TheoremValue::getLHS() called on non-rewrite theorem:\n"
00302 +toString());
00303 return d_thm[0];
00304 }
00305 virtual const Expr& getRHS() const {
00306
00307 DebugAssert(isRewrite(),
00308 "TheoremValue::getRHS() called on non-rewrite theorem:\n"
00309 +toString());
00310 return d_thm[1];
00311 }
00312
00313 virtual const Assumptions& getAssumptionsRef() const = 0;
00314
00315 bool isAssump() const { return d_isAssump; }
00316 const Proof& getProof() { return d_proof; }
00317
00318 public:
00319
00320 virtual ~TheoremValue() {
00321 IF_DEBUG(FatalAssert(d_refcount == 0,
00322 "Thm::TheoremValue::~TheoremValue(): refcount != 0.");)
00323 }
00324
00325 std::string toString() const {
00326 return getAssumptionsRef().toString() + " |- " + getExpr().toString();
00327 }
00328
00329
00330 virtual MemoryManager* getMM() = 0;
00331
00332 };
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 class RegTheoremValue :public TheoremValue
00344 {
00345 friend class Theorem;
00346
00347 protected:
00348
00349 Assumptions d_assump;
00350
00351
00352 private:
00353
00354 RegTheoremValue(TheoremManager* tm, const Expr& thm,
00355 const Assumptions& assump, const Proof& pf, bool isAssump,
00356 int scope = -1)
00357 : TheoremValue(tm, thm, pf, isAssump), d_assump(assump)
00358 {
00359 DebugAssert(d_tm->isActive(), "TheoremValue()");
00360 if (isAssump) {
00361 DebugAssert(assump.empty(), "Expected empty assumptions");
00362
00363 d_refcount = 1;
00364 {
00365 Theorem t(this);
00366 d_assump.add1(t);
00367 }
00368 d_refcount = 0;
00369 if (scope == -1) d_scopeLevel = tm->getCM()->scopeLevel();
00370 else d_scopeLevel = scope;
00371
00372 }
00373 else {
00374 if (!d_assump.empty()) {
00375 const Assumptions::iterator iend = d_assump.end();
00376 for (Assumptions::iterator i = d_assump.begin();
00377 i != iend; ++i) {
00378 if (i->getScope() > d_scopeLevel)
00379 d_scopeLevel = i->getScope();
00380 if (i->getQuantLevel() > d_quantLevel){
00381 d_quantLevel = i->getQuantLevel();
00382 }
00383 }
00384
00385 }
00386 else{
00387 TRACE("quantlevel","empty assumptions found ", thm , "");
00388 }
00389 }
00390
00391
00392
00393 }
00394
00395 public:
00396
00397 ~RegTheoremValue() {
00398 if (d_isAssump) {
00399 IF_DEBUG(FatalAssert(d_assump.size() == 1, "Expected size 1");)
00400 IF_DEBUG(FatalAssert(d_assump.getFirst().thm() == this, "Expected loop");)
00401 d_assump.getFirst().d_thm = 0;
00402 }
00403 }
00404
00405 const Assumptions& getAssumptionsRef() const { return d_assump; }
00406
00407
00408 MemoryManager* getMM() { return d_tm->getMM(); }
00409
00410 void* operator new(size_t size, MemoryManager* mm) {
00411 return mm->newData(size);
00412 }
00413 void operator delete(void* pMem, MemoryManager* mm) {
00414 mm->deleteData(pMem);
00415 }
00416
00417 void operator delete(void* d) { }
00418
00419 };
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 class RWTheoremValue :public TheoremValue
00433 {
00434 friend class Theorem;
00435
00436 protected:
00437
00438
00439 Expr d_lhs;
00440 Expr d_rhs;
00441 Assumptions* d_assump;
00442
00443 private:
00444 void init(const Assumptions& assump, int scope)
00445 {
00446 DebugAssert(d_tm->isActive(), "TheoremValue()");
00447 if (d_isAssump) {
00448 DebugAssert(assump.empty(), "Expected empty assumptions");
00449
00450 d_refcount = 1;
00451 {
00452 Theorem t(this);
00453 d_assump = new Assumptions(t);
00454 }
00455 d_refcount = 0;
00456 if (scope == -1) d_scopeLevel = d_tm->getCM()->scopeLevel();
00457 else d_scopeLevel = scope;
00458
00459 }
00460 else {
00461 if (!assump.empty()) {
00462 d_assump = new Assumptions(assump);
00463 const Assumptions::iterator iend = assump.end();
00464 for (Assumptions::iterator i = assump.begin();
00465 i != iend; ++i) {
00466 if (i->getScope() > d_scopeLevel)
00467 d_scopeLevel = i->getScope();
00468 if (i->getQuantLevel() > d_quantLevel){
00469 d_quantLevel = i->getQuantLevel();
00470
00471 }
00472 }
00473
00474 }
00475 else{
00476 TRACE("quantlevel", "RW empty assup found lhs << " , d_lhs, "" );
00477 TRACE("quantlevel", "RW empty assup found rhs >> " , d_rhs, "" );
00478 }
00479
00480 }
00481
00482
00483
00484 }
00485
00486
00487 RWTheoremValue(TheoremManager* tm, const Expr& lhs, const Expr& rhs,
00488 const Assumptions& assump, const Proof& pf, bool isAssump,
00489 int scope = -1)
00490 : TheoremValue(tm, Expr(), pf, isAssump), d_lhs(lhs), d_rhs(rhs), d_assump(NULL)
00491 { init(assump, scope); }
00492
00493
00494 RWTheoremValue(TheoremManager* tm, const Expr& thm,
00495 const Assumptions& assump, const Proof& pf, bool isAssump,
00496 int scope = -1)
00497 : TheoremValue(tm, thm, pf, isAssump), d_lhs(thm[0]), d_rhs(thm[1]), d_assump(NULL)
00498 { init(assump, scope); }
00499
00500 const Expr& getExpr() const {
00501 if (d_thm.isNull()) {
00502 bool isBool = d_lhs.getType().isBool();
00503
00504 Expr* pexpr = const_cast<Expr*>(&d_thm);
00505 *pexpr = isBool ? d_lhs.iffExpr(d_rhs) : d_lhs.eqExpr(d_rhs);
00506
00507 }
00508 return d_thm;
00509 }
00510
00511 const Expr& getLHS() const { return d_lhs; }
00512 const Expr& getRHS() const { return d_rhs; }
00513
00514 public:
00515
00516 ~RWTheoremValue() {
00517 if (d_isAssump) {
00518 IF_DEBUG(FatalAssert(d_assump && d_assump->size() == 1, "Expected size 1");)
00519 IF_DEBUG(FatalAssert(d_assump->getFirst().thm() == this, "Expected loop");)
00520 d_assump->getFirst().d_thm = 0;
00521 }
00522 if (d_assump) delete d_assump;
00523 }
00524
00525 bool isRewrite() const { return true; }
00526 const Assumptions& getAssumptionsRef() const {
00527 if (d_assump) return *d_assump;
00528 else return Assumptions::emptyAssump();
00529 }
00530
00531
00532 MemoryManager* getMM() { return d_tm->getRWMM(); }
00533
00534 void* operator new(size_t size, MemoryManager* mm) {
00535 return mm->newData(size);
00536 }
00537 void operator delete(void* pMem, MemoryManager* mm) {
00538 mm->deleteData(pMem);
00539 }
00540
00541 void operator delete(void* d) { }
00542
00543 };
00544
00545 }
00546
00547 #endif