CVC3
|
00001 /*****************************************************************************/ 00002 /*! 00003 * \file theory_array.h 00004 * 00005 * Author: Clark Barrett 00006 * 00007 * Created: Wed Feb 26 18:32:06 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 */ 00019 /*****************************************************************************/ 00020 00021 #ifndef _cvc3__include__theory_array_h_ 00022 #define _cvc3__include__theory_array_h_ 00023 00024 #include "theory_core.h" 00025 00026 namespace CVC3 { 00027 00028 class ArrayProofRules; 00029 00030 typedef enum { 00031 ARRAY = 2000, 00032 READ, 00033 WRITE, 00034 // Array literal [ [type] e ]; creates a constant array holding 'e' 00035 // in all elements: (CONST_ARRAY type e) 00036 ARRAY_LITERAL 00037 } ArrayKinds; 00038 00039 /*****************************************************************************/ 00040 /*! 00041 *\class TheoryArray 00042 *\ingroup Theories 00043 *\brief This theory handles arrays. 00044 * 00045 * Author: Clark Barrett 00046 * 00047 * Created: Thu Feb 27 00:38:20 2003 00048 */ 00049 /*****************************************************************************/ 00050 class TheoryArray :public Theory { 00051 ArrayProofRules* d_rules; 00052 00053 //! Backtracking list of array reads, for building concrete models. 00054 CDList<Expr> d_reads; 00055 //! Set of renaming theorems \f$\exists x. t = x\f$ indexed by t 00056 ExprMap<Theorem> d_renameThms; 00057 //! Flag to include array reads to the concrete model 00058 const bool& d_applicationsInModel; 00059 //! Flag to lift ite's over reads 00060 const bool& d_liftReadIte; 00061 00062 //! Backtracking database of subterms of shared terms 00063 CDMap<Expr,Expr> d_sharedSubterms; 00064 //! Backtracking database of subterms of shared terms 00065 CDList<Expr> d_sharedSubtermsList; 00066 //! Used in checkSat 00067 CDO<unsigned> d_index; 00068 00069 CDO<size_t> d_sharedIdx1, d_sharedIdx2; 00070 00071 //! Flag for use in checkSat 00072 int d_inCheckSat; 00073 00074 //! Derived rule 00075 // w(...,i,v1,...,) => w(......,i,v1') 00076 // Returns Null Theorem if index does not appear 00077 Theorem pullIndex(const Expr& e, const Expr& index); 00078 00079 public: 00080 TheoryArray(TheoryCore* core); 00081 ~TheoryArray(); 00082 00083 // Trusted method that creates the proof rules class (used in constructor). 00084 // Implemented in array_theorem_producer.cpp 00085 ArrayProofRules* createProofRules(); 00086 00087 // Theory interface 00088 void addSharedTerm(const Expr& e); 00089 void assertFact(const Theorem& e); 00090 void checkSat(bool fullEffort); 00091 Theorem rewrite(const Expr& e); 00092 void setup(const Expr& e); 00093 void update(const Theorem& e, const Expr& d); 00094 Theorem solve(const Theorem& e); 00095 void checkType(const Expr& e); 00096 Cardinality finiteTypeInfo(Expr& e, Unsigned& n, 00097 bool enumerate, bool computeSize); 00098 void computeType(const Expr& e); 00099 Type computeBaseType(const Type& t); 00100 void computeModelTerm(const Expr& e, std::vector<Expr>& v); 00101 void computeModel(const Expr& e, std::vector<Expr>& vars); 00102 Expr computeTCC(const Expr& e); 00103 virtual Expr parseExprOp(const Expr& e); 00104 ExprStream& print(ExprStream& os, const Expr& e); 00105 Expr getBaseArray(const Expr& e) const; 00106 }; 00107 00108 // Array testers 00109 inline bool isArray(const Type& t) { return t.getExpr().getKind() == ARRAY; } 00110 inline bool isRead(const Expr& e) { return e.getKind() == READ; } 00111 inline bool isWrite(const Expr& e) { return e.getKind() == WRITE; } 00112 inline bool isArrayLiteral(const Expr& e) 00113 { return (e.isClosure() && e.getKind() == ARRAY_LITERAL); } 00114 00115 // Array constructors 00116 inline Type arrayType(const Type& type1, const Type& type2) 00117 { return Type(Expr(ARRAY, type1.getExpr(), type2.getExpr())); } 00118 00119 // Expr read(const Expr& arr, const Expr& index); 00120 // Expr write(const Expr& arr, const Expr& index, const Expr& value); 00121 Expr arrayLiteral(const Expr& ind, const Expr& body); 00122 } // end of namespace CVC3 00123 00124 #endif