00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _cvc3__include__theory_datatype_h_
00022 #define _cvc3__include__theory_datatype_h_
00023
00024 #include "theory.h"
00025 #include "smartcdo.h"
00026 #include "cdmap.h"
00027
00028 namespace CVC3 {
00029
00030 class DatatypeProofRules;
00031
00032
00033 typedef enum {
00034 DATATYPE = 600,
00035 CONSTRUCTOR,
00036 SELECTOR,
00037 TESTER,
00038 } DatatypeKinds;
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 class TheoryDatatype :public Theory {
00052 protected:
00053 DatatypeProofRules* d_rules;
00054
00055 ExprMap<ExprMap<unsigned> > d_datatypes;
00056 ExprMap<std::pair<Expr,unsigned> > d_selectorMap;
00057 ExprMap<Expr> d_testerMap;
00058 ExprMap<Op> d_reach;
00059
00060 typedef unsigned bigunsigned;
00061 CDMap<Expr, SmartCDO<bigunsigned> > d_labels;
00062
00063 CDList<Theorem> d_facts;
00064 CDList<Expr> d_splitters;
00065 CDO<unsigned> d_splittersIndex;
00066 CDO<bool> d_splitterAsserted;
00067 const bool& d_smartSplits;
00068
00069 protected:
00070 virtual void instantiate(const Expr& e, const bigunsigned& u);
00071 virtual void initializeLabels(const Expr& e, const Type& t);
00072 virtual void mergeLabels(const Theorem& thm, const Expr& e1, const Expr& e2);
00073 virtual void mergeLabels(const Theorem& thm, const Expr& e,
00074 unsigned position, bool positive);
00075
00076 public:
00077 TheoryDatatype(TheoryCore* theoryCore);
00078 virtual ~TheoryDatatype();
00079
00080
00081
00082 DatatypeProofRules* createProofRules();
00083
00084
00085 void addSharedTerm(const Expr& e);
00086 void assertFact(const Theorem& e);
00087 virtual void checkSat(bool fullEffort);
00088 Theorem rewrite(const Expr& e);
00089 virtual void setup(const Expr& e);
00090 virtual void update(const Theorem& e, const Expr& d);
00091 Theorem solve(const Theorem& e);
00092 void checkType(const Expr& e);
00093 void computeType(const Expr& e);
00094 void computeModelTerm(const Expr& e, std::vector<Expr>& v);
00095 Expr computeTCC(const Expr& e);
00096 Expr parseExprOp(const Expr& e);
00097 ExprStream& print(ExprStream& os, const Expr& e);
00098
00099 Type dataType(const std::string& name,
00100 const std::vector<std::string>& constructors,
00101 const std::vector<std::vector<std::string> >& selectors,
00102 const std::vector<std::vector<Expr> >& types);
00103
00104 void dataType(const std::vector<std::string>& names,
00105 const std::vector<std::vector<std::string> >& constructors,
00106 const std::vector<std::vector<std::vector<std::string> > >& selectors,
00107 const std::vector<std::vector<std::vector<Expr> > >& types,
00108 std::vector<Type>& returnTypes);
00109
00110 Expr datatypeConsExpr(const std::string& constructor,
00111 const std::vector<Expr>& args);
00112 Expr datatypeSelExpr(const std::string& selector, const Expr& arg);
00113 Expr datatypeTestExpr(const std::string& constructor, const Expr& arg);
00114
00115 const std::pair<Expr,unsigned>& getSelectorInfo(const Expr& e);
00116 Expr getConsForTester(const Expr& e);
00117 unsigned getConsPos(const Expr& e);
00118 Expr getConstant(const Type& t);
00119 const Op& getReachablePredicate(const Type& t);
00120 bool canCollapse(const Expr& e);
00121
00122 };
00123
00124 inline bool isDatatype(const Type& t)
00125 { return t.getExpr().getKind() == DATATYPE; }
00126
00127 inline bool isConstructor(const Expr& e)
00128 { return e.getKind() == CONSTRUCTOR && e.getType().arity()==1 ||
00129 e.isApply() && e.getOpKind() == CONSTRUCTOR; }
00130
00131 inline bool isSelector(const Expr& e)
00132 { return e.isApply() && e.getOpKind() == SELECTOR; }
00133
00134 inline bool isTester(const Expr& e)
00135 { return e.isApply() && e.getOpKind() == TESTER; }
00136
00137 inline Expr getConstructor(const Expr& e)
00138 { DebugAssert(isConstructor(e), "Constructor expected");
00139 return e.isApply() ? e.getOpExpr() : e; }
00140
00141 }
00142
00143 #endif