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

Generated on Thu Apr 13 16:57:31 2006 for CVC Lite by  doxygen 1.4.4