theory_datatype.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  *\file theory_datatype.h
00004  *
00005  * Author: Clark Barrett
00006  *
00007  * Created: Wed Dec  1 22:24:32 2004
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  */
00027 /*****************************************************************************/
00028 
00029 #ifndef _cvcl__include__theory_datatype_h_
00030 #define _cvcl__include__theory_datatype_h_
00031 
00032 #include "theory.h"
00033 #include "smartcdo.h"
00034 #include "cdmap.h"
00035 
00036 namespace CVCL {
00037 
00038 class DatatypeProofRules;
00039 
00040 //! Local kinds for datatypes
00041   typedef enum {
00042     DATATYPE = 600,
00043     CONSTRUCTOR,
00044     SELECTOR,
00045     TESTER,
00046   } DatatypeKinds;
00047 
00048 /*****************************************************************************/
00049 /*!
00050  *\class TheoryDatatype
00051  *\ingroup Theories
00052  *\brief This theory handles datatypes.
00053  *
00054  * Author: Clark Barrett
00055  *
00056  * Created: Wed Dec  1 22:27:12 2004
00057  */
00058 /*****************************************************************************/
00059 class TheoryDatatype :public Theory {
00060 protected:
00061   DatatypeProofRules* d_rules;
00062 
00063   ExprMap<ExprMap<unsigned> > d_datatypes;
00064   ExprMap<std::pair<Expr,unsigned> > d_selectorMap;
00065   ExprMap<Expr> d_testerMap;
00066   ExprMap<Op> d_reach;
00067 
00068   typedef unsigned bigunsigned;
00069   CDMap<Expr, SmartCDO<bigunsigned> > d_labels;
00070 
00071   CDList<Theorem> d_facts;
00072   CDList<Expr> d_splitters;
00073   CDO<unsigned> d_splittersIndex;
00074   CDO<bool> d_splitterAsserted;
00075   const bool& d_smartSplits;
00076 
00077 protected:
00078   virtual void instantiate(const Expr& e, const bigunsigned& u);
00079   virtual void initializeLabels(const Expr& e, const Type& t);
00080   virtual void mergeLabels(const Theorem& thm, const Expr& e1, const Expr& e2);
00081   virtual void mergeLabels(const Theorem& thm, const Expr& e,
00082                            unsigned position, bool positive);
00083 
00084 public:
00085   TheoryDatatype(TheoryCore* theoryCore);
00086   virtual ~TheoryDatatype();
00087 
00088   // Trusted method that creates the proof rules class (used in constructor).
00089   // Implemented in datatype_theorem_producer.cpp
00090   DatatypeProofRules* createProofRules();
00091 
00092   // Theory interface
00093   void addSharedTerm(const Expr& e);
00094   void assertFact(const Theorem& e);
00095   virtual void checkSat(bool fullEffort);
00096   Theorem rewrite(const Expr& e);
00097   virtual void setup(const Expr& e);
00098   virtual void update(const Theorem& e, const Expr& d);
00099   Theorem solve(const Theorem& e);
00100   void checkType(const Expr& e);
00101   void computeType(const Expr& e);
00102   void computeModelTerm(const Expr& e, std::vector<Expr>& v);
00103   Expr computeTCC(const Expr& e);
00104   Expr parseExprOp(const Expr& e);
00105   ExprStream& print(ExprStream& os, const Expr& e);
00106 
00107   Type dataType(const std::string& name,
00108                 const std::vector<std::string>& constructors,
00109                 const std::vector<std::vector<std::string> >& selectors,
00110                 const std::vector<std::vector<Expr> >& types);
00111 
00112   void dataType(const std::vector<std::string>& names,
00113                 const std::vector<std::vector<std::string> >& constructors,
00114                 const std::vector<std::vector<std::vector<std::string> > >& selectors,
00115                 const std::vector<std::vector<std::vector<Expr> > >& types,
00116                 std::vector<Type>& returnTypes);
00117 
00118   Expr datatypeConsExpr(const std::string& constructor,
00119                         const std::vector<Expr>& args);
00120   Expr datatypeSelExpr(const std::string& selector, const Expr& arg);
00121   Expr datatypeTestExpr(const std::string& constructor, const Expr& arg);
00122 
00123   const std::pair<Expr,unsigned>& getSelectorInfo(const Expr& e);
00124   Expr getConsForTester(const Expr& e);
00125   unsigned getConsPos(const Expr& e);
00126   Expr getConstant(const Type& t);
00127   const Op& getReachablePredicate(const Type& t);
00128   bool canCollapse(const Expr& e);
00129 
00130 };
00131 
00132 inline bool isDatatype(const Type& t)
00133   { return t.getExpr().getKind() == DATATYPE; }
00134 
00135 inline bool isConstructor(const Expr& e)
00136   { return e.getKind() == CONSTRUCTOR && e.getType().arity()==1 ||
00137            e.isApply() && e.getOpKind() == CONSTRUCTOR; }
00138 
00139 inline bool isSelector(const Expr& e)
00140   { return e.isApply() && e.getOpKind() == SELECTOR; }
00141 
00142 inline bool isTester(const Expr& e)
00143   { return e.isApply() && e.getOpKind() == TESTER; }
00144 
00145 inline Expr getConstructor(const Expr& e)
00146   { DebugAssert(isConstructor(e), "Constructor expected");
00147     return e.isApply() ? e.getOpExpr() : e; }
00148 
00149 }
00150 
00151 #endif

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