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 #ifndef _CVC_lite__expr_h_
00031 #define _CVC_lite__expr_h_
00032
00033 #include <stdlib.h>
00034 #include <sstream>
00035 #include <set>
00036 #include <functional>
00037 #include <iterator>
00038 #include <map>
00039
00040 #include "compat_hash_map.h"
00041 #include "compat_hash_set.h"
00042 #include "rational.h"
00043 #include "kinds.h"
00044 #include "cdo.h"
00045 #include "cdflags.h"
00046 #include "lang.h"
00047 #include "memory_manager.h"
00048
00049 class CInterface;
00050
00051 namespace CVCL {
00052
00053 class NotifyList;
00054 class Theory;
00055 class Op;
00056 class Type;
00057 class Theorem;
00058
00059 template<class Data>
00060 class ExprHashMap;
00061
00062 class ExprManager;
00063
00064 class ExprValue;
00065 class ExprNode;
00066
00067 class ExprStream;
00068
00069
00070
00071
00072 typedef enum {
00073 EXPR_VALUE,
00074 EXPR_NODE,
00075 EXPR_APPLY,
00076 EXPR_STRING,
00077 EXPR_RATIONAL,
00078 EXPR_SKOLEM,
00079 EXPR_UCONST,
00080 EXPR_SYMBOL,
00081 EXPR_BOUND_VAR,
00082 EXPR_CLOSURE,
00083 EXPR_VALUE_TYPE_LAST
00084 } ExprValueType;
00085
00086
00087 typedef long long unsigned ExprIndex;
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 class Expr {
00134 friend class ExprHasher;
00135 friend class ExprManager;
00136 friend class Op;
00137 friend class ExprValue;
00138 friend class ExprNode;
00139 friend class ::CInterface;
00140
00141
00142
00143
00144
00145 typedef enum {
00146
00147 VALID_TYPE = 0x1,
00148
00149 VALID_IS_ATOMIC = 0x2,
00150
00151 IS_ATOMIC = 0x4,
00152
00153 REWRITE_NORMAL = 0x8,
00154
00155 IS_FINITE = 0x400,
00156
00157 WELL_FOUNDED = 0x800,
00158
00159 COMPUTE_TRANS_CLOSURE = 0x1000
00160 } StaticFlagsEnum;
00161
00162
00163
00164 typedef enum {
00165
00166 IMPLIED_LITERAL = 0x10,
00167 IS_USER_ASSUMPTION = 0x20,
00168 IS_INT_ASSUMPTION = 0x40,
00169 IS_JUSTIFIED = 0x80,
00170 IS_TRANSLATED = 0x100,
00171 IS_USER_REGISTERED_ATOM = 0x200,
00172 IS_SELECTED = 0x2000
00173 } DynamicFlagsEnum;
00174
00175
00176 static Expr s_null;
00177
00178
00179
00180
00181
00182 ExprValue* d_expr;
00183
00184
00185
00186
00187
00188
00189 Expr(ExprValue* expr);
00190
00191 Expr recursiveSubst(const ExprHashMap<Expr>& subst,
00192 ExprHashMap<Expr>& visited) const;
00193 public:
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 class iterator
00209 : public std::iterator<std::input_iterator_tag,Expr,ptrdiff_t>
00210 {
00211 friend class Expr;
00212 private:
00213 std::vector<Expr>::const_iterator d_it;
00214
00215
00216
00217 iterator(std::vector<Expr>::const_iterator it): d_it(it) { }
00218
00219 public:
00220
00221 iterator() { }
00222
00223
00224
00225 bool operator==(const iterator& i) const {
00226 return d_it == i.d_it;
00227 }
00228
00229 bool operator!=(const iterator& i) const { return !(*this == i); }
00230
00231 const Expr& operator*() const;
00232
00233 const Expr* operator->() const;
00234
00235 iterator& operator++() {
00236 d_it++;
00237 return *this;
00238 }
00239
00240
00241 class Proxy {
00242 const Expr* d_e;
00243 public:
00244 Proxy(const Expr& e) : d_e(&e) { }
00245 Expr operator*() { return *d_e; }
00246 };
00247
00248
00249
00250
00251
00252
00253
00254 Proxy operator++(int) {
00255 Proxy e(*(*this));
00256 ++(*this);
00257 return e;
00258 }
00259 };
00260
00261
00262
00263
00264
00265
00266 Expr(): d_expr(NULL) {}
00267
00268
00269
00270 Expr(const Expr& e);
00271
00272 Expr& operator=(const Expr& e);
00273
00274
00275
00276
00277 Expr(const Op& op, const Expr& child);
00278 Expr(const Op& op, const Expr& child0, const Expr& child1);
00279 Expr(const Op& op, const Expr& child0, const Expr& child1,
00280 const Expr& child2);
00281 Expr(const Op& op, const Expr& child0, const Expr& child1,
00282 const Expr& child2, const Expr& child3);
00283 Expr(const Op& op, const std::vector<Expr>& children,
00284 ExprManager* em = NULL);
00285
00286
00287 ~Expr();
00288
00289
00290 Expr eqExpr(const Expr& right) const;
00291 Expr notExpr() const;
00292 Expr negate() const;
00293 Expr andExpr(const Expr& right) const;
00294 Expr orExpr(const Expr& right) const;
00295 Expr iteExpr(const Expr& thenpart, const Expr& elsepart) const;
00296 Expr iffExpr(const Expr& right) const;
00297 Expr impExpr(const Expr& right) const;
00298
00299 Expr skolemExpr(int i) const;
00300
00301
00302
00303 Expr rebuild(ExprManager* em) const;
00304
00305
00306 Expr substExpr(const std::vector<Expr>& oldTerms,
00307 const std::vector<Expr>& newTerms) const;
00308 Expr substExpr(const ExprHashMap<Expr>& oldToNew) const;
00309
00310 Expr operator!() const { return notExpr(); }
00311 Expr operator&&(const Expr& right) const { return andExpr(right); }
00312 Expr operator||(const Expr& right) const { return orExpr(right); }
00313
00314
00315
00316
00317
00318 static size_t hash(const Expr& e);
00319
00320
00321
00322
00323
00324 size_t hash() const;
00325
00326
00327
00328 bool isFalse() const { return getKind() == FALSE; }
00329 bool isTrue() const { return getKind() == TRUE; }
00330 bool isBoolConst() const { return isFalse() || isTrue(); }
00331 bool isVar() const;
00332 bool isBoundVar() const { return getKind() == BOUND_VAR; }
00333 bool isString() const;
00334 bool isClosure() const;
00335 bool isQuantifier() const;
00336 bool isLambda() const;
00337 bool isApply() const;
00338 bool isSymbol() const;
00339
00340 bool isType() const;
00341
00342
00343
00344
00345
00346
00347
00348
00349 const ExprValue* getExprValue() const;
00350
00351
00352 bool isTerm() const;
00353
00354
00355
00356
00357 bool isAtomic() const;
00358
00359
00360
00361
00362
00363 bool isAtomicFormula() const;
00364
00365 bool isAbsAtomicFormula() const
00366 { return isQuantifier() || isAtomicFormula(); }
00367
00368
00369
00370 bool isLiteral() const
00371 { return (isAtomicFormula() || (isNot() && (*this)[0].isAtomicFormula())); }
00372
00373 bool isAbsLiteral() const
00374 { return (isAbsAtomicFormula() || (isNot() && (*this)[0].isAbsAtomicFormula())); }
00375
00376 bool isBoolConnective() const;
00377
00378 bool isPropAtom() const { return !isBoolConnective(); }
00379
00380 bool isPropLiteral() const
00381 { return (isNot() && (*this)[0].isPropAtom()) || isPropAtom(); }
00382
00383 bool isEq() const { return getKind() == EQ; }
00384 bool isNot() const { return getKind() == NOT; }
00385 bool isAnd() const { return getKind() == AND; }
00386 bool isOr() const { return getKind() == OR; }
00387 bool isITE() const { return getKind() == ITE; }
00388 bool isIff() const { return getKind() == IFF; }
00389 bool isImpl() const { return getKind() == IMPLIES; }
00390 bool isXor() const { return getKind() == XOR;}
00391
00392 bool isForall() const { return getKind() == FORALL; }
00393 bool isExists() const { return getKind() == EXISTS; }
00394
00395 bool isRational() const { return getKind() == RATIONAL_EXPR; }
00396 bool isSkolem() const { return getKind() == SKOLEM_VAR;}
00397
00398
00399
00400
00401
00402 const std::string& getName() const;
00403
00404 const std::string& getUid() const;
00405
00406
00407 const std::string& getString() const;
00408
00409 const std::vector<Expr>& getVars() const;
00410
00411 const Expr& getExistential() const;
00412
00413 int getBoundIndex() const;
00414
00415
00416 const Expr& getBody() const;
00417
00418 const Rational& getRational() const;
00419
00420
00421 ExprManager *getEM() const;
00422
00423
00424 const std::vector<Expr>& getKids() const;
00425
00426
00427 int getKind() const;
00428
00429
00430 ExprIndex getIndex() const;
00431
00432
00433 bool hasLastIndex() const;
00434
00435
00436 Op mkOp() const;
00437
00438
00439 Op getOp() const;
00440
00441
00442 Expr getOpExpr() const;
00443
00444
00445 int getOpKind() const;
00446
00447
00448
00449
00450
00451 int arity() const;
00452
00453
00454
00455 const Expr& operator[](int i) const;
00456
00457
00458 const Expr& unnegate() const { return isNot() ? (*this)[0] : *this; }
00459
00460
00461 iterator begin() const;
00462
00463 iterator end() const;
00464
00465
00466 bool isNull() const;
00467
00468
00469 bool isInitialized() const { return d_expr != NULL; }
00470
00471 size_t getMMIndex() const;
00472
00473
00474
00475
00476 bool hasFind() const;
00477
00478
00479
00480
00481
00482
00483 Theorem getFind() const;
00484
00485
00486 NotifyList* getNotify() const;
00487
00488
00489 const Type getType() const;
00490
00491 const Type lookupType() const;
00492
00493 const Expr lookupTCC() const;
00494
00495 const Theorem lookupSubtypePred() const;
00496
00497
00498
00499 bool validSimpCache() const;
00500
00501
00502 const Theorem& getSimpCache() const;
00503
00504
00505 bool isValidType() const;
00506
00507
00508 bool validIsAtomicFlag() const;
00509
00510
00511 bool getIsAtomicFlag() const;
00512
00513
00514 bool isRewriteNormal() const;
00515
00516
00517 bool isFinite() const;
00518
00519
00520 bool isWellFounded() const;
00521
00522
00523 bool computeTransClosure() const;
00524
00525
00526 bool isImpliedLiteral() const;
00527
00528
00529 bool isUserAssumption() const;
00530
00531
00532 bool isIntAssumption() const;
00533
00534
00535 bool isJustified() const;
00536
00537
00538 bool isTranslated() const;
00539
00540
00541 bool isUserRegisteredAtom() const;
00542
00543
00544 bool isSelected() const;
00545
00546
00547 bool getFlag() const;
00548
00549 void setFlag() const;
00550
00551 void clearFlags() const;
00552
00553
00554
00555
00556 std::string toString() const;
00557
00558 std::string toString(InputLanguage lang) const;
00559
00560 void print(InputLanguage lang, bool dagify = true) const;
00561
00562
00563 void print() const { print(AST_LANG); }
00564
00565 void printnodag() const;
00566
00567
00568 void pprint() const;
00569
00570 void pprintnodag() const;
00571
00572
00573
00574
00575
00576 ExprStream& print(ExprStream& os) const;
00577
00578
00579
00580 ExprStream& printAST(ExprStream& os) const;
00581
00582
00583
00584
00585
00586 Expr& indent(int n, bool permanent = false);
00587
00588
00589
00590
00591
00592
00593
00594
00595 void setFind(const Theorem& e) const;
00596
00597
00598 void addToNotify(Theory* i, const Expr& e) const;
00599
00600
00601 void setType(const Type& t) const;
00602
00603 void setTCC(const Expr& tcc) const;
00604
00605 void setSubtypePred(const Theorem& pred) const;
00606
00607
00608 void setSimpCache(const Theorem& e) const;
00609
00610
00611 void setValidType() const;
00612
00613
00614 void setIsAtomicFlag(bool value) const;
00615
00616
00617 void setRewriteNormal() const;
00618 void clearRewriteNormal() const;
00619
00620
00621 void setFinite() const;
00622
00623
00624 void setWellFounded() const;
00625
00626
00627 void setComputeTransClosure() const;
00628
00629
00630 void setImpliedLiteral() const;
00631
00632
00633 void setUserAssumption(int scope = -1) const;
00634
00635
00636 void setIntAssumption() const;
00637
00638
00639 void setJustified() const;
00640
00641
00642 void setTranslated(int scope = -1) const;
00643
00644
00645 void setUserRegisteredAtom() const;
00646
00647
00648 void setSelected() const;
00649
00650
00651 bool subExprOf(const Expr& e) const;
00652
00653
00654 inline int getHeight() const;
00655
00656
00657 inline int getHighestKid() const;
00658
00659
00660
00661 inline bool hasSimpFrom() const;
00662 inline const Expr& getSimpFrom() const;
00663 inline void setSimpFrom(const Expr& simpFrom);
00664
00665
00666 bool hasSig() const;
00667 bool hasRep() const;
00668 const Theorem& getSig() const;
00669 const Theorem& getRep() const;
00670 void setSig(const Theorem& e) const;
00671 void setRep(const Theorem& e) const;
00672
00673
00674
00675
00676
00677 friend std::ostream& operator<<(std::ostream& os, const Expr& e);
00678
00679
00680
00681
00682
00683 friend int compare(const Expr& e1, const Expr& e2);
00684
00685 friend bool operator==(const Expr& e1, const Expr& e2);
00686 friend bool operator!=(const Expr& e1, const Expr& e2);
00687
00688 friend bool operator<(const Expr& e1, const Expr& e2);
00689 friend bool operator<=(const Expr& e1, const Expr& e2);
00690 friend bool operator>(const Expr& e1, const Expr& e2);
00691 friend bool operator>=(const Expr& e1, const Expr& e2);
00692
00693
00694
00695 };
00696
00697 }
00698
00699
00700
00701 #ifndef DOXYGEN
00702 #include "expr_op.h"
00703 #include "expr_manager.h"
00704 #endif
00705 namespace CVCL {
00706
00707 inline Expr::Expr(ExprValue* expr) : d_expr(expr) { d_expr->incRefcount(); }
00708
00709 inline Expr::Expr(const Expr& e) : d_expr(e.d_expr) {
00710 if (d_expr != NULL) d_expr->incRefcount();
00711 }
00712
00713 inline Expr& Expr::operator=(const Expr& e) {
00714 if(&e == this) return *this;
00715 if(d_expr != NULL) {
00716 d_expr->decRefcount();
00717 }
00718 d_expr = e.d_expr;
00719 if(d_expr != NULL)
00720 d_expr->incRefcount();
00721 return *this;
00722 }
00723
00724 inline Expr::Expr(const Op& op, const Expr& child) {
00725 std::vector<Expr> kids;
00726 kids.push_back(child);
00727 ExprManager* em = child.getEM();
00728 if (op.getExpr().isNull()) {
00729 ExprNode ev(em, op.getKind(), kids);
00730 d_expr = em->newExprValue(&ev);
00731 } else {
00732 ExprApply ev(em, op, kids);
00733 d_expr = em->newExprValue(&ev);
00734 }
00735 d_expr->incRefcount();
00736 }
00737
00738 inline Expr::Expr(const Op& op, const Expr& child0, const Expr& child1) {
00739 std::vector<Expr> kids;
00740 kids.push_back(child0);
00741 kids.push_back(child1);
00742 ExprManager* em = child0.getEM();
00743 if (op.getExpr().isNull()) {
00744 ExprNode ev(em, op.getKind(), kids);
00745 d_expr = em->newExprValue(&ev);
00746 } else {
00747 ExprApply ev(em, op, kids);
00748 d_expr = em->newExprValue(&ev);
00749 }
00750 d_expr->incRefcount();
00751 }
00752
00753 inline Expr::Expr(const Op& op, const Expr& child0, const Expr& child1,
00754 const Expr& child2) {
00755 ExprManager* em = child0.getEM();
00756 std::vector<Expr> kids;
00757 kids.push_back(child0);
00758 kids.push_back(child1);
00759 kids.push_back(child2);
00760 if (op.getExpr().isNull()) {
00761 ExprNode ev(em, op.getKind(), kids);
00762 d_expr = em->newExprValue(&ev);
00763 } else {
00764 ExprApply ev(em, op, kids);
00765 d_expr = em->newExprValue(&ev);
00766 }
00767 d_expr->incRefcount();
00768 }
00769
00770 inline Expr::Expr(const Op& op, const Expr& child0, const Expr& child1,
00771 const Expr& child2, const Expr& child3) {
00772 ExprManager* em = child0.getEM();
00773 std::vector<Expr> kids;
00774 kids.push_back(child0);
00775 kids.push_back(child1);
00776 kids.push_back(child2);
00777 kids.push_back(child3);
00778 if (op.getExpr().isNull()) {
00779 ExprNode ev(em, op.getKind(), kids);
00780 d_expr = em->newExprValue(&ev);
00781 } else {
00782 ExprApply ev(em, op, kids);
00783 d_expr = em->newExprValue(&ev);
00784 }
00785 d_expr->incRefcount();
00786 }
00787
00788 inline Expr::Expr(const Op& op, const std::vector<Expr>& children,
00789 ExprManager* em) {
00790 if (em == NULL) {
00791 if (!op.getExpr().isNull()) em = op.getExpr().getEM();
00792 else {
00793 DebugAssert(children.size() > 0,
00794 "Expr::Expr(Op, children): op's EM is NULL and "
00795 "no children given");
00796 em = children[0].getEM();
00797 }
00798 }
00799 if (op.getExpr().isNull()) {
00800 ExprNode ev(em, op.getKind(), children);
00801 d_expr = em->newExprValue(&ev);
00802 } else {
00803 ExprApply ev(em, op, children);
00804 d_expr = em->newExprValue(&ev);
00805 }
00806 d_expr->incRefcount();
00807 }
00808
00809 inline Expr Expr::eqExpr(const Expr& right) const {
00810 return Expr(EQ, *this, right);
00811 }
00812
00813 inline Expr Expr::notExpr() const {
00814 return Expr(NOT, *this);
00815 }
00816
00817 inline Expr Expr::negate() const {
00818 return isNot() ? (*this)[0] : this->notExpr();
00819 }
00820
00821 inline Expr Expr::andExpr(const Expr& right) const {
00822 return Expr(AND, *this, right);
00823 }
00824
00825 inline Expr andExpr(const std::vector <Expr>& children) {
00826 DebugAssert(children.size()>0 && !children[0].isNull(),
00827 "Expr::andExpr(kids)");
00828 return Expr(AND, children);
00829 }
00830
00831 inline Expr Expr::orExpr(const Expr& right) const {
00832 return Expr(OR, *this, right);
00833 }
00834
00835 inline Expr orExpr(const std::vector <Expr>& children) {
00836 DebugAssert(children.size()>0 && !children[0].isNull(),
00837 "Expr::andExpr(kids)");
00838 return Expr(OR, children);
00839 }
00840
00841 inline Expr Expr::iteExpr(const Expr& thenpart, const Expr& elsepart) const {
00842 return Expr(ITE, *this, thenpart, elsepart);
00843 }
00844
00845 inline Expr Expr::iffExpr(const Expr& right) const {
00846 return Expr(IFF, *this, right);
00847 }
00848
00849 inline Expr Expr::impExpr(const Expr& right) const {
00850 return Expr(IMPLIES, *this, right);
00851 }
00852
00853 inline Expr Expr::skolemExpr(int i) const {
00854 return getEM()->newSkolemExpr(*this, i);
00855 }
00856
00857 inline Expr Expr::rebuild(ExprManager* em) const {
00858 return em->rebuild(*this);
00859 }
00860
00861 inline Expr::~Expr() {
00862 if(d_expr != NULL && !d_expr->d_em->d_disableGC) {
00863 d_expr->decRefcount();
00864 }
00865 }
00866
00867 inline size_t Expr::hash(const Expr& e) { return e.getEM()->hash(e); }
00868
00869
00870
00871
00872
00873 inline size_t Expr::hash() const { return getEM()->hash(*this); }
00874
00875 inline const ExprValue* Expr::getExprValue() const
00876 { return d_expr->getExprValue(); }
00877
00878
00879
00880 inline bool Expr::isVar() const { return d_expr->isVar(); }
00881 inline bool Expr::isString() const { return d_expr->isString(); }
00882 inline bool Expr::isClosure() const { return d_expr->isClosure(); }
00883 inline bool Expr::isQuantifier() const {
00884 return (isClosure() && (getKind() == FORALL || getKind() == EXISTS));
00885 }
00886 inline bool Expr::isLambda() const {
00887 return (isClosure() && getKind() == LAMBDA);
00888 }
00889 inline bool Expr::isApply() const
00890 { DebugAssert((getKind() != APPLY || d_expr->isApply()) &&
00891 (!d_expr->isApply() || getKind() == APPLY), "APPLY mismatch");
00892 return d_expr->isApply(); }
00893 inline bool Expr::isSymbol() const { return d_expr->isSymbol(); }
00894 inline bool Expr::isType() const { return getEM()->isTypeKind(getOpKind()); }
00895 inline bool Expr::isTerm() const { return !getType().isBool(); }
00896 inline bool Expr::isBoolConnective() const {
00897 if (!getType().isBool()) return false;
00898 switch (getKind()) {
00899 case NOT: case AND: case OR: case IMPLIES: case IFF: case XOR: case ITE:
00900 return true; }
00901 return false;
00902 }
00903
00904 inline int Expr::getHeight() const { return d_expr->getHeight(); }
00905 inline int Expr::getHighestKid() const { return d_expr->getHighestKid(); }
00906
00907 inline bool Expr::hasSimpFrom() const
00908 { return !d_expr->getSimpFrom().isNull(); }
00909 inline const Expr& Expr::getSimpFrom() const
00910 { return hasSimpFrom() ? d_expr->getSimpFrom() : *this; }
00911 inline void Expr::setSimpFrom(const Expr& simpFrom)
00912 { d_expr->setSimpFrom(simpFrom); }
00913
00914
00915
00916 inline const std::string& Expr::getName() const {
00917 DebugAssert(!isNull(), "Expr::getName() on Null expr");
00918 return d_expr->getName();
00919 }
00920
00921 inline const std::string& Expr::getString() const {
00922 DebugAssert(isString(),
00923 "CVCL::Expr::getString(): not a string Expr:\n "
00924 + toString(AST_LANG));
00925 return d_expr->getString();
00926 }
00927
00928 inline const std::vector<Expr>& Expr::getVars() const {
00929 DebugAssert(isClosure(),
00930 "CVCL::Expr::getVars(): not a closure Expr:\n "
00931 + toString(AST_LANG));
00932 return d_expr->getVars();
00933 }
00934
00935 inline const Expr& Expr::getBody() const {
00936 DebugAssert(isClosure(),
00937 "CVCL::Expr::getBody(): not a closure Expr:\n "
00938 + toString(AST_LANG));
00939 return d_expr->getBody();
00940 }
00941
00942 inline const Expr& Expr::getExistential() const {
00943 DebugAssert(isSkolem(),
00944 "CVCL::Expr::getExistential() not a skolem variable");
00945 return d_expr->getExistential();
00946 }
00947 inline int Expr::getBoundIndex() const {
00948 DebugAssert(isSkolem(),
00949 "CVCL::Expr::getBoundIndex() not a skolem variable");
00950 return d_expr->getBoundIndex();
00951 }
00952
00953
00954 inline const Rational& Expr::getRational() const {
00955 DebugAssert(isRational(),
00956 "CVCL::Expr::getRational(): not a rational Expr:\n "
00957 + toString(AST_LANG));
00958 return d_expr->getRational();
00959 }
00960
00961 inline const std::string& Expr::getUid() const {
00962 DebugAssert(getKind() == BOUND_VAR,
00963 "CVCL::Expr::getUid(): not a BOUND_VAR Expr:\n "
00964 + toString(AST_LANG));
00965 return d_expr->getUid();
00966 }
00967
00968 inline ExprManager* Expr::getEM() const {
00969 DebugAssert(d_expr != NULL,
00970 "CVCL::Expr:getEM: on Null Expr (not initialized)");
00971 return d_expr->d_em;
00972 }
00973
00974 inline const std::vector<Expr>& Expr::getKids() const {
00975 DebugAssert(d_expr != NULL, "Expr::getKids on Null Expr");
00976 if(isNull()) return getEM()->getEmptyVector();
00977 else return d_expr->getKids();
00978 }
00979
00980 inline int Expr::getKind() const {
00981 if(d_expr == NULL) return NULL_KIND;
00982 return d_expr->d_kind;
00983 }
00984
00985 inline ExprIndex Expr::getIndex() const { return d_expr->d_index; }
00986
00987 inline bool Expr::hasLastIndex() const
00988 { return d_expr->d_em->lastIndex() == getIndex(); }
00989
00990 inline Op Expr::mkOp() const {
00991 DebugAssert(!isNull(), "Expr::mkOp() on Null expr");
00992 return Op(*this);
00993 }
00994
00995 inline Op Expr::getOp() const {
00996 DebugAssert(!isNull(), "Expr::getOp() on Null expr");
00997 if (isApply()) return d_expr->getOp();
00998 DebugAssert(arity() > 0,
00999 "Expr::getOp() called on non-apply expr with no children");
01000 return Op(getKind());
01001 }
01002
01003 inline Expr Expr::getOpExpr() const {
01004 DebugAssert(isApply(), "getOpExpr() called on non-apply");
01005 return getOp().getExpr();
01006 }
01007
01008 inline int Expr::getOpKind() const {
01009 if (!isApply()) return getKind();
01010 return getOp().getExpr().getKind();
01011 }
01012
01013 inline int Expr::arity() const {
01014 if(isNull()) return 0;
01015 else return d_expr->arity();
01016 }
01017
01018 inline const Expr& Expr::operator[](int i) const {
01019 DebugAssert(i < arity(), "out of bounds access");
01020 return (d_expr->getKids())[i];
01021 }
01022
01023 inline bool Expr::isNull() const {
01024 return (d_expr == NULL) || (d_expr->d_kind == NULL_KIND);
01025 }
01026
01027 inline size_t Expr::getMMIndex() const {
01028 DebugAssert(!isNull(), "Expr::getMMIndex()");
01029 return d_expr->getMMIndex();
01030 }
01031
01032 inline bool Expr::hasFind() const {
01033 DebugAssert(!isNull(), "hasFind called on NULL Expr");
01034 return (d_expr->d_find && !(d_expr->d_find->get().isNull()));
01035 }
01036
01037 inline Theorem Expr::getFind() const {
01038 DebugAssert(hasFind(), "Should only be called if find is valid");
01039 return d_expr->d_find->get();
01040 }
01041
01042 inline NotifyList* Expr::getNotify() const {
01043 if(isNull()) return NULL;
01044 else return d_expr->d_notifyList;
01045 }
01046
01047 inline const Type Expr::getType() const {
01048 if (isNull()) return s_null;
01049 if(d_expr->d_type.isNull()) getEM()->computeType(*this);
01050 return d_expr->d_type;
01051 }
01052
01053 inline const Type Expr::lookupType() const {
01054 if (isNull()) return s_null;
01055 return d_expr->d_type;
01056 }
01057
01058 inline const Expr Expr::lookupTCC() const {
01059 if(isNull()) return s_null;
01060 else return d_expr->d_tcc;
01061 }
01062
01063 inline const Theorem Expr::lookupSubtypePred() const {
01064 if(isNull()) return Theorem();
01065 else return d_expr->d_subtypePred;
01066 }
01067
01068 inline bool Expr::validSimpCache() const {
01069 return d_expr->d_simpCacheTag == getEM()->getSimpCacheTag();
01070 }
01071
01072 inline const Theorem& Expr::getSimpCache() const {
01073 return d_expr->d_simpCache;
01074 }
01075
01076 inline bool Expr::isValidType() const {
01077 return d_expr->d_dynamicFlags.get(VALID_TYPE);
01078 }
01079
01080 inline bool Expr::validIsAtomicFlag() const {
01081 return d_expr->d_dynamicFlags.get(VALID_IS_ATOMIC);
01082 }
01083
01084 inline bool Expr::getIsAtomicFlag() const {
01085 return d_expr->d_dynamicFlags.get(IS_ATOMIC);
01086 }
01087
01088 inline bool Expr::isRewriteNormal() const {
01089 return d_expr->d_dynamicFlags.get(REWRITE_NORMAL);
01090 }
01091
01092 inline bool Expr::isFinite() const {
01093 return d_expr->d_dynamicFlags.get(IS_FINITE);
01094 }
01095
01096 inline bool Expr::isWellFounded() const {
01097 return d_expr->d_dynamicFlags.get(WELL_FOUNDED);
01098 }
01099
01100 inline bool Expr::computeTransClosure() const {
01101 return d_expr->d_dynamicFlags.get(COMPUTE_TRANS_CLOSURE);
01102 }
01103
01104 inline bool Expr::isImpliedLiteral() const {
01105 return d_expr->d_dynamicFlags.get(IMPLIED_LITERAL);
01106 }
01107
01108 inline bool Expr::isUserAssumption() const {
01109 return d_expr->d_dynamicFlags.get(IS_USER_ASSUMPTION);
01110 }
01111
01112 inline bool Expr::isIntAssumption() const {
01113 return d_expr->d_dynamicFlags.get(IS_INT_ASSUMPTION);
01114 }
01115
01116 inline bool Expr::isJustified() const {
01117 return d_expr->d_dynamicFlags.get(IS_JUSTIFIED);
01118 }
01119
01120 inline bool Expr::isTranslated() const {
01121 return d_expr->d_dynamicFlags.get(IS_TRANSLATED);
01122 }
01123
01124 inline bool Expr::isUserRegisteredAtom() const {
01125 return d_expr->d_dynamicFlags.get(IS_USER_REGISTERED_ATOM);
01126 }
01127
01128 inline bool Expr::isSelected() const {
01129 return d_expr->d_dynamicFlags.get(IS_SELECTED);
01130 }
01131
01132 inline bool Expr::getFlag() const {
01133 DebugAssert(!isNull(), "Expr::getFlag() on Null Expr");
01134 return (d_expr->d_flag == getEM()->getFlag());
01135 }
01136
01137 inline void Expr::setFlag() const {
01138 DebugAssert(!isNull(), "Expr::setFlag() on Null Expr");
01139 d_expr->d_flag = getEM()->getFlag();
01140 }
01141
01142 inline void Expr::clearFlags() const {
01143 DebugAssert(!isNull(), "Expr::clearFlags() on Null Expr");
01144 getEM()->clearFlags();
01145 }
01146
01147 inline void Expr::setFind(const Theorem& e) const {
01148 DebugAssert(!isNull(), "Expr::setFind() on Null expr");
01149 DebugAssert(e.getLHS() == *this, "bad call to setFind");
01150 if (d_expr->d_find) d_expr->d_find->set(e);
01151 else {
01152 CDO<Theorem>* tmp = new CDO<Theorem>(getEM()->getCurrentContext(), e);
01153 d_expr->d_find = tmp;
01154 IF_DEBUG(tmp->setName("CDO[Expr.find]"));
01155 }
01156 }
01157
01158 inline void Expr::setType(const Type& t) const {
01159 DebugAssert(!isNull(), "Expr::setType() on Null expr");
01160 d_expr->d_type = t;
01161 }
01162
01163 inline void Expr::setTCC(const Expr& tcc) const {
01164 DebugAssert(!isNull(), "Expr::setTCC() on Null expr");
01165 d_expr->d_tcc = tcc;
01166 }
01167
01168 inline void Expr::setSubtypePred(const Theorem& pred) const {
01169 DebugAssert(!isNull(), "Expr::setSubtypePred() on Null expr");
01170 d_expr->d_subtypePred = pred;
01171 }
01172
01173 inline void Expr::setSimpCache(const Theorem& e) const {
01174 DebugAssert(!isNull(), "Expr::setSimpCache() on Null expr");
01175 d_expr->d_simpCache = e;
01176 d_expr->d_simpCacheTag = getEM()->getSimpCacheTag();
01177 }
01178
01179 inline void Expr::setValidType() const {
01180 DebugAssert(!isNull(), "Expr::setValidType() on Null expr");
01181 d_expr->d_dynamicFlags.set(VALID_TYPE, 0);
01182 }
01183
01184 inline void Expr::setIsAtomicFlag(bool value) const {
01185 DebugAssert(!isNull(), "Expr::setIsAtomicFlag() on Null expr");
01186 d_expr->d_dynamicFlags.set(VALID_IS_ATOMIC, 0);
01187 if (value) d_expr->d_dynamicFlags.set(IS_ATOMIC, 0);
01188 else d_expr->d_dynamicFlags.clear(IS_ATOMIC, 0);
01189 }
01190
01191 inline void Expr::setRewriteNormal() const {
01192 DebugAssert(!isNull(), "Expr::setRewriteNormal() on Null expr");
01193 TRACE("setRewriteNormal", "setRewriteNormal(", *this, ")");
01194 d_expr->d_dynamicFlags.set(REWRITE_NORMAL, 0);
01195 }
01196
01197 inline void Expr::setFinite() const {
01198 DebugAssert(!isNull(), "Expr::setFinite() on Null expr");
01199 d_expr->d_dynamicFlags.set(IS_FINITE, 0);
01200 }
01201
01202 inline void Expr::setWellFounded() const {
01203 DebugAssert(!isNull(), "Expr::setWellFounded() on Null expr");
01204 d_expr->d_dynamicFlags.set(WELL_FOUNDED, 0);
01205 }
01206
01207 inline void Expr::setComputeTransClosure() const {
01208 DebugAssert(!isNull(), "Expr::setComputeTransClosure() on Null expr");
01209 d_expr->d_dynamicFlags.set(COMPUTE_TRANS_CLOSURE, 0);
01210 }
01211
01212 inline void Expr::setImpliedLiteral() const {
01213 DebugAssert(!isNull(), "Expr::setImpliedLiteral() on Null expr");
01214 d_expr->d_dynamicFlags.set(IMPLIED_LITERAL);
01215 }
01216
01217 inline void Expr::setUserAssumption(int scope) const {
01218 DebugAssert(!isNull(), "Expr::setUserAssumption() on Null expr");
01219 d_expr->d_dynamicFlags.set(IS_USER_ASSUMPTION, scope);
01220 }
01221
01222 inline void Expr::setIntAssumption() const {
01223 DebugAssert(!isNull(), "Expr::setIntAssumption() on Null expr");
01224 d_expr->d_dynamicFlags.set(IS_INT_ASSUMPTION);
01225 }
01226
01227 inline void Expr::setJustified() const {
01228 DebugAssert(!isNull(), "Expr::setJustified() on Null expr");
01229 d_expr->d_dynamicFlags.set(IS_JUSTIFIED);
01230 }
01231
01232 inline void Expr::setTranslated(int scope) const {
01233 DebugAssert(!isNull(), "Expr::setTranslated() on Null expr");
01234 d_expr->d_dynamicFlags.set(IS_TRANSLATED, scope);
01235 }
01236
01237 inline void Expr::setUserRegisteredAtom() const {
01238 DebugAssert(!isNull(), "Expr::setUserRegisteredAtom() on Null expr");
01239 d_expr->d_dynamicFlags.set(IS_USER_REGISTERED_ATOM);
01240 }
01241
01242 inline void Expr::setSelected() const {
01243 DebugAssert(!isNull(), "Expr::setSelected() on Null expr");
01244 d_expr->d_dynamicFlags.set(IS_SELECTED);
01245 }
01246
01247 inline void Expr::clearRewriteNormal() const {
01248 DebugAssert(!isNull(), "Expr::clearRewriteNormal() on Null expr");
01249 d_expr->d_dynamicFlags.clear(REWRITE_NORMAL, 0);
01250 }
01251
01252 inline bool Expr::hasSig() const {
01253 return (!isNull()
01254 && d_expr->getSig() != NULL
01255 && !(d_expr->getSig()->get().isNull()));
01256 }
01257
01258 inline bool Expr::hasRep() const {
01259 return (!isNull()
01260 && d_expr->getRep() != NULL
01261 && !(d_expr->getRep()->get().isNull()));
01262 }
01263
01264 inline const Theorem& Expr::getSig() const {
01265 static Theorem nullThm;
01266 DebugAssert(!isNull(), "Expr::getSig() on Null expr");
01267 if(d_expr->getSig() != NULL)
01268 return d_expr->getSig()->get();
01269 else
01270 return nullThm;
01271 }
01272
01273 inline const Theorem& Expr::getRep() const {
01274 static Theorem nullThm;
01275 DebugAssert(!isNull(), "Expr::getRep() on Null expr");
01276 if(d_expr->getRep() != NULL)
01277 return d_expr->getRep()->get();
01278 else
01279 return nullThm;
01280 }
01281
01282 inline void Expr::setSig(const Theorem& e) const {
01283 DebugAssert(!isNull(), "Expr::setSig() on Null expr");
01284 CDO<Theorem>* sig = d_expr->getSig();
01285 if(sig != NULL) sig->set(e);
01286 else {
01287 CDO<Theorem>* tmp = new CDO<Theorem>(getEM()->getCurrentContext(), e);
01288 d_expr->setSig(tmp);
01289 IF_DEBUG(tmp->setName("CDO[Expr.sig] in "+toString()));
01290 }
01291 }
01292
01293 inline void Expr::setRep(const Theorem& e) const {
01294 DebugAssert(!isNull(), "Expr::setRep() on Null expr");
01295 CDO<Theorem>* rep = d_expr->getRep();
01296 if(rep != NULL) rep->set(e);
01297 else {
01298 CDO<Theorem>* tmp = new CDO<Theorem>(getEM()->getCurrentContext(), e);
01299 d_expr->setRep(tmp);
01300 IF_DEBUG(tmp->setName("CDO[Expr.rep] in "+toString()));
01301 }
01302 }
01303
01304 inline bool operator==(const Expr& e1, const Expr& e2) {
01305
01306 return e1.d_expr == e2.d_expr;
01307 }
01308
01309 inline bool operator!=(const Expr& e1, const Expr& e2)
01310 { return !(e1 == e2); }
01311
01312
01313
01314 inline bool operator<(const Expr& e1, const Expr& e2)
01315 { return compare(e1,e2) < 0; }
01316 inline bool operator<=(const Expr& e1, const Expr& e2)
01317 { return compare(e1,e2) <= 0; }
01318 inline bool operator>(const Expr& e1, const Expr& e2)
01319 { return compare(e1,e2) > 0; }
01320 inline bool operator>=(const Expr& e1, const Expr& e2)
01321 { return compare(e1,e2) >= 0; }
01322
01323 }
01324
01325 #endif