expr_value.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file expr_value.h
00004  * 
00005  * Author: Sergey Berezin
00006  * 
00007  * Created: Fri Feb  7 15:07:18 2003
00008  *
00009  * <hr>
00010  *
00011  * License to use, copy, modify, sell and/or distribute this software
00012  * and its documentation for any purpose is hereby granted without
00013  * royalty, subject to the terms and conditions defined in the \ref
00014  * LICENSE file provided with this distribution.
00015  * 
00016  * <hr>
00017  * 
00018  * Class ExprValue: the value holding class of Expr.  No one should
00019  * use it directly; use Expr API instead.  To enforce that, the
00020  * constructors are made protected, and only Expr, ExprManager, and
00021  * subclasses can use them.
00022  */
00023 /*****************************************************************************/
00024 
00025 // *** HACK ATTACK *** (trick from Aaron Stump's code)
00026 
00027 // In order to inline the Expr constructors (for efficiency), this
00028 // file (expr_value.h) must be included in expr.h.  However, we also
00029 // need to include expr.h here, hence, circular dependency.  A way to
00030 // break it is to include expr_value.h in the middle of expr.h after
00031 // the definition of class Expr, but before the definition of its
00032 // inlined methods.  So, expr.h included below will also suck in
00033 // expr_value.h recursively, meaning that we then should skip the rest
00034 // of the file (since it's already been included). 
00035 
00036 // That's why expr.h is outside of #ifndef.  The same is true for
00037 // type.h and theorem.h.
00038 
00039 #ifndef _cvc3__expr_h_
00040 #include "expr.h"
00041 #endif
00042 
00043 #ifndef _cvc3__expr_value_h_
00044 #define _cvc3__expr_value_h_
00045 
00046 #include "theorem.h"
00047 #include "type.h"
00048 
00049 // The prime number used in the hash function for a vector of elements
00050 #define PRIME 131
00051 
00052 namespace CVC3 {
00053   
00054 /*****************************************************************************/
00055 /*!
00056  *\class ExprValue
00057  *\brief The base class for holding the actual data in expressions
00058  * 
00059  *
00060  * Author: Sergey Berezin
00061  *
00062  * Created: long time ago
00063  *
00064  * \anchor ExprValue The base class just holds the operator.
00065  * All the additional data resides in subclasses.
00066  * 
00067  */
00068 /*****************************************************************************/
00069 class ExprValue {
00070   friend class Expr;
00071   friend class Expr::iterator;
00072   friend class ExprManager;
00073   friend class ::CInterface;
00074   friend class ExprApply;
00075   friend class Theorem;
00076 
00077   //! Unique expression id
00078   ExprIndex d_index;
00079 
00080   //! Reference counter for garbage collection
00081   unsigned d_refcount;
00082   
00083   //! Cached hash value (initially 0)
00084   size_t d_hash; 
00085 
00086   //! The find attribute (may be NULL)
00087   CDO<Theorem>* d_find;
00088 
00089   //! The cached type of the expression (may be Null)
00090   Type d_type;
00091 
00092   //! The cached TCC of the expression (may be Null)
00093   //  Expr d_tcc;
00094 
00095   //! Subtyping predicate for the expression and all subexpressions
00096   //  Theorem d_subtypePred;
00097 
00098   //! Notify list may be NULL (== no such attribute)
00099   NotifyList* d_notifyList;
00100 
00101   //! For caching calls to Simplify
00102   Theorem d_simpCache;
00103 
00104   //! For checking whether simplify cache is valid
00105   unsigned d_simpCacheTag;
00106 
00107   //! context-dependent bit-vector for flags that are context-dependent
00108   CDFlags d_dynamicFlags;
00109 
00110   //! Height of this expression
00111   //  int d_height;
00112 
00113   //! Which child has the largest height
00114   //  int d_highestKid;
00115 
00116   //! Most distant expression we were simplified *from*
00117   //  Expr d_simpFrom;
00118 
00119   //! Generic flag for marking expressions (e.g. in DAG traversal)
00120   unsigned d_flag;
00121 
00122 protected:
00123   /*! @brief The kind of the expression.  In particular, it determines which
00124    * subclass of ExprValue is used to store the expression. */
00125   int d_kind;
00126 
00127   //! Our expr. manager
00128   ExprManager* d_em;
00129 
00130   // End of data members
00131 
00132 private:
00133 
00134   //! Set the ExprIndex
00135   void setIndex(ExprIndex idx) { d_index = idx; }
00136 
00137   //! Increment reference counter
00138   void incRefcount() { ++d_refcount; }
00139 
00140   //! Decrement reference counter
00141   void decRefcount() {
00142     // Cannot be DebugAssert, since we are called in a destructor
00143     // and should not throw an exception
00144     FatalAssert(d_refcount > 0, "Mis-handled the ref. counting");
00145     if((--d_refcount) == 0) d_em->gc(this);
00146   }
00147 
00148   //! Caching hash function
00149   /*! Do NOT implement it in subclasses! Implement computeHash() instead.
00150    */
00151   size_t hash() const {
00152     if(d_hash == 0)
00153       const_cast<ExprValue*>(this)->d_hash = computeHash();
00154     return d_hash;
00155   }
00156 
00157   //! Return height of Expr
00158   //  int getHeight() const { return d_height; }
00159 
00160   //! Return child with greatest height
00161   //  int getHighestKid() const { return d_highestKid; }
00162 
00163   //! Get Expr simplified to obtain this expr
00164   //  const Expr& getSimpFrom() const { return d_simpFrom; }
00165 
00166   //! Set Expr simplified to obtain this expr
00167   //  void setSimpFrom(const Expr& simpFrom) { d_simpFrom = simpFrom; }
00168 
00169 protected:
00170 
00171   // Static hash functions.  They don't depend on the context
00172   // (ExprManager and such), so it is still thread-safe to have them
00173   // static.
00174   static std::hash<char*> s_charHash;
00175   static std::hash<long int> s_intHash;
00176 
00177   static size_t pointerHash(void* p) { return s_intHash((long int)p); }
00178   // Hash function for subclasses with children
00179   static size_t hash(const int kind, const std::vector<Expr>& kids);
00180   // Hash function for kinds
00181   static size_t hash(const int n) { return s_intHash((long int)n); }
00182 
00183   //! Return the memory manager (for the benefit of subclasses)
00184   MemoryManager* getMM(size_t MMIndex) {
00185     DebugAssert(d_em!=NULL, "ExprValue::getMM()");
00186     return d_em->getMM(MMIndex);
00187   }
00188 
00189   //! Make a clean copy of itself using the given ExprManager
00190   ExprValue* rebuild(ExprManager* em) const
00191     { return copy(em, 0); }
00192 
00193   //! Make a clean copy of the expr using the given ExprManager
00194   Expr rebuild(Expr e, ExprManager* em) const
00195     { return em->rebuildRec(e); }
00196 
00197   // Protected API
00198 
00199   //! Non-caching hash function which actually computes the hash.
00200   /*! This is the method that all subclasses should implement */
00201   virtual size_t computeHash() const { return hash(d_kind); }
00202 
00203   //! Make a clean copy of itself using the given ExprManager
00204   virtual ExprValue* copy(ExprManager* em, ExprIndex idx) const;
00205 
00206 public:
00207   //! Constructor
00208   ExprValue(ExprManager* em, int kind, ExprIndex idx = 0)
00209     : d_index(idx), d_refcount(0),
00210       d_hash(0), d_find(NULL), d_notifyList(NULL),
00211       d_simpCacheTag(0),
00212       d_dynamicFlags(em->getCurrentContext()),
00213       //      d_height(0), d_highestKid(-1),
00214       d_flag(0), d_kind(kind), d_em(em)
00215   {
00216     DebugAssert(em != NULL, "NULL ExprManager is given to ExprValue()");
00217     DebugAssert(em->isKindRegistered(kind),
00218                 ("ExprValue(kind = " + int2string(kind)
00219                  + ")): kind is not registered").c_str());
00220     DebugAssert(kind != APPLY, "Only ExprApply should have APPLY kind");
00221 // #ifdef DEBUG //added by yeting, just hold a place to put my breakpoints in gdb
00222 //     if(idx != 0){
00223 //       TRACE("expr", "expr created ", idx, "");//the line added by yeting
00224 //       //      char * a;
00225 //       //      a="a";
00226 //       //      a[999999]=255;
00227 //     }
00228 // #endif
00229   }
00230   //! Destructor
00231   virtual ~ExprValue();
00232 
00233   //! Get the kind of the expression
00234   int getKind() const { return d_kind; }
00235 
00236   //! Overload operator new
00237   void* operator new(size_t size, MemoryManager* mm)
00238     { return mm->newData(size); }
00239   void operator delete(void* pMem, MemoryManager* mm) {
00240     mm->deleteData(pMem);
00241   }
00242 
00243   //! Overload operator delete
00244   void operator delete(void*) { }
00245 
00246   //! Get unique memory manager ID
00247   virtual size_t getMMIndex() const { return EXPR_VALUE; }
00248 
00249   //! Equality between any two ExprValue objects (including subclasses)
00250   virtual bool operator==(const ExprValue& ev2) const;
00251 
00252   // Testers
00253 
00254   //! Test whether the expression is a generic subclass
00255   /*!
00256    * \return 0 for the core classes, and getMMIndex() value for
00257    * generic subclasses (those defined in DPs)
00258    */
00259   virtual const ExprValue* getExprValue() const
00260     { throw Exception("Illegal call to getExprValue()"); }
00261   //! String expression tester
00262   virtual bool isString() const { return false; }
00263   //! Rational number expression tester
00264   virtual bool isRational() const { return false; }
00265   //! Uninterpreted constants
00266   virtual bool isVar() const { return false; }
00267   //! Application of another expression
00268   virtual bool isApply() const { return false; }
00269   //! Special named symbol
00270   virtual bool isSymbol() const { return false; }
00271   //! A LAMBDA-expression or a quantifier
00272   virtual bool isClosure() const { return false; }
00273   //! Special Expr holding a theorem
00274   virtual bool isTheorem() const { return false; }
00275 
00276   //! Get kids: by default, returns a ref to an empty vector
00277   virtual const std::vector<Expr>& getKids() const
00278     { return d_em->getEmptyVector(); }
00279 
00280   // Methods to access leaf data in subclasses
00281 
00282   //! Default arity = 0
00283   virtual unsigned arity() const { return 0; }
00284 
00285   //! Special attributes for uninterpreted functions
00286   virtual CDO<Theorem>* getSig() const {
00287     DebugAssert(false, "getSig() is called on ExprValue");
00288     return NULL;
00289   }
00290 
00291   virtual CDO<Theorem>* getRep() const {
00292     DebugAssert(false, "getRep() is called on ExprValue");
00293     return NULL;
00294   }
00295 
00296   virtual void setSig(CDO<Theorem>* sig) {
00297     DebugAssert(false, "setSig() is called on ExprValue");
00298   }
00299 
00300   virtual void setRep(CDO<Theorem>* rep) {
00301     DebugAssert(false, "setRep() is called on ExprValue");
00302   }
00303 
00304   virtual const std::string& getUid() const { 
00305     static std::string null;
00306     DebugAssert(false, "ExprValue::getUid() called in base class");
00307     return null;
00308   }
00309 
00310   virtual const std::string& getString() const {
00311     DebugAssert(false, "getString() is called on ExprValue");
00312     static std::string s("");
00313     return s;
00314   }
00315 
00316   virtual const Rational& getRational() const {
00317     DebugAssert(false, "getRational() is called on ExprValue");
00318     static Rational r(0);
00319     return r;
00320   }
00321 
00322   //! Returns the string name of UCONST and BOUND_VAR expr's.
00323   virtual const std::string& getName() const {
00324     static std::string ret = "";
00325     DebugAssert(false, "getName() is called on ExprValue");
00326     return ret;
00327   }
00328 
00329   //! Returns the original Boolean variable (for BoolVarExprValue)
00330   virtual const Expr& getVar() const {
00331     DebugAssert(false, "getVar() is called on ExprValue");
00332     static Expr null;
00333     return null;
00334   }
00335 
00336   //! Get the Op from an Apply Expr
00337   virtual Op getOp() const {
00338     DebugAssert(false, "getOp() is called on ExprValue");
00339     return Op(NULL_KIND);
00340   }
00341 
00342   virtual const std::vector<Expr>& getVars() const  {
00343     DebugAssert(false, "getVars() is called on ExprValue");
00344     static std::vector<Expr> null;
00345     return null;
00346   }
00347 
00348   virtual const Expr& getBody() const {
00349     DebugAssert(false, "getBody() is called on ExprValue");
00350     static Expr null;
00351     return null;
00352   }
00353 
00354   virtual const Expr& getExistential() const {
00355     DebugAssert(false, "getExistential() is called on ExprValue");
00356     static Expr null;
00357     return null;
00358   }
00359   virtual int getBoundIndex() const {
00360     DebugAssert(false, "getIndex() is called on ExprValue");
00361     return 0;
00362   }
00363 
00364   virtual const std::vector<std::string>& getFields() const {
00365     DebugAssert(false, "getFields() is called on ExprValue");
00366     static std::vector<std::string> null;
00367     return null;
00368   }
00369   virtual const std::string& getField() const {
00370     DebugAssert(false, "getField() is called on ExprValue");
00371     static std::string null;
00372     return null;
00373   }
00374   virtual int getTupleIndex() const {
00375     DebugAssert(false, "getTupleIndex() is called on ExprValue");
00376     return 0;
00377   }
00378   virtual const Theorem& getTheorem() const {
00379     static Theorem null;
00380     DebugAssert(false, "getTheorem() is called on ExprValue");
00381     return null;
00382   }
00383 
00384 }; // end of class ExprValue
00385 
00386 // Class ExprNode; it's an expression with children
00387 class ExprNode: public ExprValue {
00388   friend class Expr;
00389   friend class ExprManager;
00390 
00391 protected:
00392   //! Vector of children
00393   std::vector<Expr> d_children;
00394 
00395   // Special attributes for helping with congruence closure
00396   CDO<Theorem>* d_sig;
00397   CDO<Theorem>* d_rep;
00398 
00399 private:
00400 
00401   //! Tell ExprManager who we are
00402   size_t getMMIndex() const { return EXPR_NODE; }
00403 
00404 protected:
00405   //! Return number of children
00406   unsigned arity() const { return d_children.size(); }
00407 
00408   //! Return reference to children
00409   std::vector<Expr>& getKids1() { return d_children; }
00410 
00411   //! Return reference to children
00412   const std::vector<Expr>& getKids() const { return d_children; }
00413 
00414   //! Use our static hash() for the member method
00415   size_t computeHash() const {
00416     return ExprValue::hash(d_kind, d_children);
00417   }
00418 
00419   //! Make a clean copy of itself using the given memory manager
00420   virtual ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00421 
00422 public:
00423   //! Constructor
00424   ExprNode(ExprManager* em, int kind, ExprIndex idx = 0)
00425     : ExprValue(em, kind, idx), d_sig(NULL), d_rep(NULL) { }
00426   //! Constructor
00427   ExprNode(ExprManager* em, int kind, const std::vector<Expr>& kids,
00428            ExprIndex idx = 0)
00429     : ExprValue(em, kind, idx), d_children(kids), d_sig(NULL), d_rep(NULL) { }
00430   //! Destructor
00431   virtual ~ExprNode();
00432     
00433   //! Overload operator new
00434   void* operator new(size_t size, MemoryManager* mm)
00435     { return mm->newData(size); }
00436   void operator delete(void* pMem, MemoryManager* mm) {
00437     mm->deleteData(pMem);
00438   }
00439 
00440   //! Overload operator delete
00441   void operator delete(void*) { }
00442 
00443   //! Compare with another ExprValue
00444   virtual bool operator==(const ExprValue& ev2) const;
00445 
00446   virtual CDO<Theorem>* getSig() const { return d_sig; }
00447   virtual CDO<Theorem>* getRep() const { return d_rep; }
00448 
00449   virtual void setRep(CDO<Theorem>* rep) { d_rep = rep; }
00450   virtual void setSig(CDO<Theorem>* sig) { d_sig = sig; }
00451 
00452 }; // end of class ExprNode
00453 
00454 // Class ExprNodeTmp; special version of ExprNode for Expr constructor
00455 class ExprNodeTmp: public ExprValue {
00456   friend class Expr;
00457   friend class ExprManager;
00458 
00459 protected:
00460   //! Vector of children
00461   const std::vector<Expr>& d_children;
00462 
00463 private:
00464 
00465   //! Tell ExprManager who we are
00466   size_t getMMIndex() const { return EXPR_NODE; }
00467 
00468 protected:
00469   //! Return number of children
00470   unsigned arity() const { return d_children.size(); }
00471 
00472   //! Return reference to children
00473   const std::vector<Expr>& getKids() const { return d_children; }
00474 
00475   //! Use our static hash() for the member method
00476   size_t computeHash() const {
00477     return ExprValue::hash(d_kind, d_children);
00478   }
00479 
00480   //! Make a clean copy of itself using the given memory manager
00481   virtual ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00482 
00483 public:
00484   //! Constructor
00485   ExprNodeTmp(ExprManager* em, int kind, const std::vector<Expr>& kids)
00486     : ExprValue(em, kind, 0), d_children(kids) { }
00487 
00488   //! Destructor
00489   virtual ~ExprNodeTmp() {}
00490     
00491   //! Compare with another ExprValue
00492   virtual bool operator==(const ExprValue& ev2) const;
00493 
00494 }; // end of class ExprNodeTmp
00495 
00496 // Special version for Expr Constructor
00497 class ExprApplyTmp: public ExprNodeTmp {
00498   friend class Expr;
00499   friend class ExprManager;
00500 private:
00501   Expr d_opExpr;
00502 protected:
00503   size_t getMMIndex() const { return EXPR_APPLY; }
00504   size_t computeHash() const {
00505     return PRIME*ExprNodeTmp::computeHash() + d_opExpr.hash();
00506   }
00507   Op getOp() const { return Op(d_opExpr); }
00508   bool isApply() const { return true; }
00509   // Make a clean copy of itself using the given memory manager
00510   ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00511 public:
00512   // Constructor
00513   ExprApplyTmp(ExprManager* em, const Op& op,
00514                const std::vector<Expr>& kids)
00515     : ExprNodeTmp(em, NULL_KIND, kids), d_opExpr(op.getExpr())
00516   { DebugAssert(!op.getExpr().isNull(), "Expected non-null Op");
00517     d_kind = APPLY; }
00518   virtual ~ExprApplyTmp() { }
00519 
00520   bool operator==(const ExprValue& ev2) const;
00521 }; // end of class ExprApply
00522 
00523 class CVC_DLL ExprApply: public ExprNode {
00524   friend class Expr;
00525   friend class ExprManager;
00526 private:
00527   Expr d_opExpr;
00528 protected:
00529   size_t getMMIndex() const { return EXPR_APPLY; }
00530   size_t computeHash() const {
00531     return PRIME*ExprNode::computeHash() + d_opExpr.hash();
00532   }
00533   Op getOp() const { return Op(d_opExpr); }
00534   bool isApply() const { return true; }
00535   // Make a clean copy of itself using the given memory manager
00536   ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00537 public:
00538   // Constructor
00539   ExprApply(ExprManager* em, const Op& op, ExprIndex idx = 0)
00540     : ExprNode(em, NULL_KIND, idx), d_opExpr(op.getExpr())
00541   { DebugAssert(!op.getExpr().isNull(), "Expected non-null Op");
00542     d_kind = APPLY; }
00543   ExprApply(ExprManager* em, const Op& op,
00544             const std::vector<Expr>& kids, ExprIndex idx = 0)
00545     : ExprNode(em, NULL_KIND, kids, idx), d_opExpr(op.getExpr())
00546   { DebugAssert(!op.getExpr().isNull(), "Expected non-null Op");
00547     d_kind = APPLY; }
00548   virtual ~ExprApply() { }
00549 
00550   bool operator==(const ExprValue& ev2) const;
00551   // Memory management
00552   void* operator new(size_t size, MemoryManager* mm) {
00553     return mm->newData(size);
00554   }
00555   void operator delete(void* pMem, MemoryManager* mm) {
00556     mm->deleteData(pMem);
00557   }
00558   void operator delete(void*) { }
00559 }; // end of class ExprApply
00560 
00561 /*****************************************************************************/
00562 /*!
00563  *\class NamedExprValue
00564  *\brief NamedExprValue
00565  *
00566  * Author: Clark Barrett
00567  *
00568  * Created: Thu Dec  2 23:18:17 2004
00569  *
00570  * Subclass of ExprValue for kinds that have a name associated with them.
00571  */
00572 /*****************************************************************************/
00573 
00574 // class NamedExprValue : public ExprNode {
00575 //   friend class Expr;
00576 //   friend class ExprManager;
00577 
00578 // private:
00579 //   std::string d_name;
00580 
00581 // protected:
00582 
00583 //   ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const {
00584 //     return new(em->getMM(getMMIndex()))
00585 //       NamedExprValue(d_em, d_kind, d_name, d_children, idx);
00586 //   }
00587 
00588 //   ExprValue* copy(ExprManager* em, const std::vector<Expr>& kids,
00589 //            ExprIndex idx = 0) const {
00590 //     return new(em->getMM(getMMIndex()))
00591 //       NamedExprValue(d_em, d_kind, d_name, kids, idx);
00592 //   }
00593 
00594 //   size_t computeHash() const {
00595 //     return s_charHash(d_name.c_str())*PRIME + ExprNode::computeHash();
00596 //   }
00597 
00598 //   size_t getMMIndex() const { return EXPR_NAMED; }
00599 
00600 // public:
00601 //   // Constructor
00602 //   NamedExprValue(ExprManager *em, int kind, const std::string& name,
00603 //                  const std::vector<Expr>& kids, ExprIndex idx = 0)
00604 //     : ExprNode(em, kind, kids, idx), d_name(name) { }
00605 //   // virtual ~NamedExprValue();
00606 //   bool operator==(const ExprValue& ev2) const {
00607 //     if(getMMIndex() != ev2.getMMIndex()) return false;
00608 //     return (getName() == ev2.getName())
00609 //       && ExprNode::operator==(ev2);
00610 //   }
00611 
00612 //   const std::string& getName() const { return d_name; }
00613 
00614 //   // Memory management
00615 //   void* operator new(size_t size, MemoryManager* mm) {
00616 //     return mm->newData(size);
00617 //   }
00618 //   void operator delete(void*) { }
00619 // }; // end of class NamedExprValue
00620 
00621 // Leaf expressions
00622 class ExprString: public ExprValue {
00623   friend class Expr;
00624   friend class ExprManager;
00625 private:
00626   std::string d_str;
00627 
00628   // Hash function for this subclass
00629   static size_t hash(const std::string& str) {
00630     return s_charHash(str.c_str());
00631   }
00632 
00633   // Tell ExprManager who we are
00634   virtual size_t getMMIndex() const { return EXPR_STRING; }
00635 
00636 protected:
00637   // Use our static hash() for the member method
00638   virtual size_t computeHash() const { return hash(d_str); }
00639 
00640   virtual bool isString() const { return true; }
00641   virtual const std::string& getString() const { return d_str; }
00642 
00643   //! Make a clean copy of itself using the given memory manager
00644   virtual ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00645 public:
00646   // Constructor
00647   ExprString(ExprManager* em, const std::string& s, ExprIndex idx = 0)
00648     : ExprValue(em, STRING_EXPR, idx), d_str(s) { }
00649   // Destructor
00650   virtual ~ExprString() { }
00651 
00652   virtual bool operator==(const ExprValue& ev2) const;
00653   // Memory management
00654   void* operator new(size_t size, MemoryManager* mm) {
00655     return mm->newData(size);
00656   }
00657   void operator delete(void* pMem, MemoryManager* mm) {
00658     mm->deleteData(pMem);
00659   }
00660   void operator delete(void*) { }
00661 }; // end of class ExprString
00662 
00663 class ExprSkolem: public ExprValue {
00664   friend class Expr;
00665   friend class ExprManager;
00666 private:
00667   Expr d_quant; //!< The quantified expression to skolemize
00668   int d_idx; //!< Variable index in the quantified expression
00669   const Expr& getExistential() const {return d_quant;}
00670   int getBoundIndex() const {return d_idx;}
00671 
00672   // Tell ExprManager who we are
00673   size_t getMMIndex() const { return EXPR_SKOLEM;}
00674 
00675 protected:
00676   size_t computeHash() const {
00677     size_t res = getExistential().getBody().hash();
00678     res = PRIME*res + getBoundIndex();
00679     return res;
00680   }
00681 
00682   bool operator==(const ExprValue& ev2) const;
00683 
00684   //! Make a clean copy of itself using the given memory manager
00685   ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00686   bool isVar() const { return true; }
00687    
00688 public:
00689   // Constructor
00690   ExprSkolem(ExprManager* em, int index, const Expr& exist, ExprIndex idx = 0)
00691     : ExprValue(em, SKOLEM_VAR, idx), d_quant(exist), d_idx(index) { }
00692   // Destructor
00693   virtual ~ExprSkolem() { }
00694   // Memory management
00695   void* operator new(size_t size, MemoryManager* mm) {
00696     return mm->newData(size);
00697   }
00698   void operator delete(void* pMem, MemoryManager* mm) {
00699     mm->deleteData(pMem);
00700   }
00701   void operator delete(void*) { }
00702 }; // end of class ExprSkolem
00703 
00704 class ExprRational: public ExprValue {
00705   friend class Expr;
00706   friend class ExprManager;
00707 private:
00708   Rational d_r;
00709 
00710   virtual const Rational& getRational() const { return d_r; }
00711 
00712   // Hash function for this subclass
00713   static size_t hash(const Rational& r) {
00714     return s_charHash(r.toString().c_str());
00715   }
00716 
00717   // Tell ExprManager who we are
00718   virtual size_t getMMIndex() const { return EXPR_RATIONAL; }
00719 
00720 protected:
00721 
00722   virtual size_t computeHash() const { return hash(d_r); }
00723   virtual bool operator==(const ExprValue& ev2) const;
00724   //! Make a clean copy of itself using the given memory manager
00725   virtual ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00726   virtual bool isRational() const { return true; }
00727 
00728 public:
00729   // Constructor
00730   ExprRational(ExprManager* em, const Rational& r, ExprIndex idx = 0)
00731     : ExprValue(em, RATIONAL_EXPR, idx), d_r(r) { }
00732   // Destructor
00733   virtual ~ExprRational() { }
00734   // Memory management
00735   void* operator new(size_t size, MemoryManager* mm) {
00736     return mm->newData(size);
00737   }
00738   void operator delete(void* pMem, MemoryManager* mm) {
00739     mm->deleteData(pMem);
00740   }
00741   void operator delete(void*) { }
00742 }; // end of class ExprRational
00743 
00744 // Uninterpreted constants (variables)
00745 class ExprVar: public ExprValue {
00746   friend class Expr;
00747   friend class ExprManager;
00748 private:
00749   std::string d_name;
00750 
00751   virtual const std::string& getName() const { return d_name; }
00752 
00753   // Tell ExprManager who we are
00754   virtual size_t getMMIndex() const { return EXPR_UCONST; }
00755 protected:
00756 
00757   virtual size_t computeHash() const {
00758     return s_charHash(d_name.c_str());
00759   }
00760   virtual bool isVar() const { return true; }
00761 
00762   //! Make a clean copy of itself using the given memory manager
00763   virtual ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00764 
00765 public:
00766   // Constructor
00767   ExprVar(ExprManager *em, const std::string& name, ExprIndex idx = 0)
00768     : ExprValue(em, UCONST, idx), d_name(name) { }
00769   // Destructor
00770   virtual ~ExprVar() { }
00771 
00772   virtual bool operator==(const ExprValue& ev2) const;
00773   // Memory management
00774   void* operator new(size_t size, MemoryManager* mm) {
00775     return mm->newData(size);
00776   }
00777   void operator delete(void* pMem, MemoryManager* mm) {
00778     mm->deleteData(pMem);
00779   }
00780   void operator delete(void*) { }
00781 }; // end of class ExprVar
00782 
00783 // Interpreted symbols: similar to UCONST, but returns false for isVar().
00784 class ExprSymbol: public ExprValue {
00785   friend class Expr;
00786   friend class ExprManager;
00787 private:
00788   std::string d_name;
00789 
00790   virtual const std::string& getName() const { return d_name; }
00791 
00792   // Tell ExprManager who we are
00793   virtual size_t getMMIndex() const { return EXPR_SYMBOL; }
00794 protected:
00795 
00796   virtual size_t computeHash() const {
00797     return s_charHash(d_name.c_str())*PRIME + s_intHash(d_kind);
00798   }
00799   //! Make a clean copy of itself using the given memory manager
00800   virtual ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00801   bool isSymbol() const { return true; }
00802 
00803 public:
00804   // Constructor
00805   ExprSymbol(ExprManager *em, int kind, const std::string& name,
00806              ExprIndex idx = 0)
00807     : ExprValue(em, kind, idx), d_name(name) { }
00808   // Destructor
00809   virtual ~ExprSymbol() { }
00810 
00811   virtual bool operator==(const ExprValue& ev2) const;
00812   // Memory management
00813   void* operator new(size_t size, MemoryManager* mm) {
00814     return mm->newData(size);
00815   }
00816   void operator delete(void* pMem, MemoryManager* mm) {
00817     mm->deleteData(pMem);
00818   }
00819   void operator delete(void*) { }
00820 }; // end of class ExprSymbol
00821 
00822 class ExprBoundVar: public ExprValue {
00823   friend class Expr;
00824   friend class ExprManager;
00825 private:
00826   std::string d_name;
00827   std::string d_uid;
00828 
00829   virtual const std::string& getName() const { return d_name; }
00830   virtual const std::string& getUid() const { return d_uid; }
00831 
00832   // Tell ExprManager who we are
00833   virtual size_t getMMIndex() const { return EXPR_BOUND_VAR; }
00834 protected:
00835 
00836   virtual size_t computeHash() const {
00837     return s_charHash(d_name.c_str())*PRIME + s_charHash(d_uid.c_str());
00838   }
00839   virtual bool isVar() const { return true; }
00840   //! Make a clean copy of itself using the given memory manager
00841   virtual ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00842 
00843 public:
00844   // Constructor
00845   ExprBoundVar(ExprManager *em, const std::string& name,
00846                const std::string& uid, ExprIndex idx = 0)
00847     : ExprValue(em, BOUND_VAR, idx), d_name(name), d_uid(uid) { }
00848   // Destructor
00849   virtual ~ExprBoundVar() { }
00850 
00851   virtual bool operator==(const ExprValue& ev2) const;
00852   // Memory management
00853   void* operator new(size_t size, MemoryManager* mm) {
00854     return mm->newData(size);
00855   }
00856   void operator delete(void* pMem, MemoryManager* mm) {
00857     mm->deleteData(pMem);
00858   }
00859   void operator delete(void*) { }
00860 }; // end of class ExprBoundVar
00861 
00862 /*! @brief A "closure" expression which binds variables used in the
00863   "body".  Used by LAMBDA and quantifiers. */
00864 class ExprClosure: public ExprValue {
00865   friend class Expr;
00866   friend class ExprManager;
00867 private:
00868   //! Bound variables
00869   std::vector<Expr> d_vars;
00870   //! The body of the quantifier/lambda
00871   Expr d_body;
00872 
00873   //! Tell ExprManager who we are
00874   virtual size_t getMMIndex() const { return EXPR_CLOSURE; }
00875 
00876   virtual const std::vector<Expr>& getVars() const { return d_vars; }
00877   virtual const Expr& getBody() const { return d_body; }
00878 
00879 
00880 protected:
00881 
00882   size_t computeHash() const;
00883   //! Make a clean copy of itself using the given memory manager
00884   ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00885 
00886 public:
00887   // Constructor
00888   ExprClosure(ExprManager *em, int kind, const std::vector<Expr>& vars,
00889               const Expr& body, ExprIndex idx = 0)
00890     : ExprValue(em, kind, idx), d_vars(vars), d_body(body) { }
00891   // Destructor
00892   virtual ~ExprClosure() { }
00893 
00894   bool operator==(const ExprValue& ev2) const;
00895   // Memory management
00896   void* operator new(size_t size, MemoryManager* mm) {
00897     return mm->newData(size);
00898   }
00899   void operator delete(void* pMem, MemoryManager* mm) {
00900     mm->deleteData(pMem);
00901   }
00902   void operator delete(void*) { }
00903   virtual bool isClosure() const { return true; }
00904 }; // end of class ExprClosure
00905 
00906 // Expr that stores a theorem
00907 class ExprTheorem: public ExprValue {
00908   friend class Expr;
00909   friend class ExprManager;
00910 private:
00911   Theorem d_thm;
00912 
00913   virtual const Theorem& getTheorem() const { return d_thm; }
00914 
00915   // Tell ExprManager who we are
00916   virtual size_t getMMIndex() const { return EXPR_THEOREM; }
00917 protected:
00918 
00919   virtual size_t computeHash() const {
00920     return d_thm.hash();
00921   }
00922   //! Make a clean copy of itself using the given memory manager
00923   virtual ExprValue* copy(ExprManager* em, ExprIndex idx = 0) const;
00924   bool isTheorem() const { return true; }
00925 
00926 public:
00927   // Constructor
00928   ExprTheorem(ExprManager *em, const Theorem& thm, ExprIndex idx = 0)
00929     : ExprValue(em, THEOREM_KIND, idx), d_thm(thm) { }
00930   // Destructor
00931   virtual ~ExprTheorem() { }
00932 
00933   virtual bool operator==(const ExprValue& ev2) const;
00934   // Memory management
00935   void* operator new(size_t size, MemoryManager* mm) {
00936     return mm->newData(size);
00937   }
00938   void operator delete(void* pMem, MemoryManager* mm) {
00939     mm->deleteData(pMem);
00940   }
00941   void operator delete(void*) { }
00942 
00943 };
00944 
00945 } // end of namespace CVC3
00946 
00947 #endif

Generated on Tue Jul 3 14:33:37 2007 for CVC3 by  doxygen 1.5.1