CVC3

theory_records.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file theory_records.h
00004  * 
00005  * Author: Daniel Wichs
00006  * 
00007  * Created: 7/22/03
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 #ifndef _cvc3__include__theory_records_h_
00021 #define _cvc3__include__theory_records_h_
00022 
00023 #include "theory.h"
00024 
00025 namespace CVC3 {
00026 
00027   class RecordsProofRules;
00028 
00029  typedef enum {
00030    RECORD = 2500,
00031    RECORD_SELECT,
00032    RECORD_UPDATE,
00033    RECORD_TYPE,
00034    TUPLE,
00035    TUPLE_SELECT,
00036    TUPLE_UPDATE,
00037    TUPLE_TYPE
00038  } RecordKinds;
00039                                     
00040 /*****************************************************************************/
00041 /*!
00042  *\class TheoryRecords
00043  *\ingroup Theories
00044  *\brief This theory handles records.
00045  *
00046  * Author: Daniel Wichs
00047  *
00048  * Created: 7/22/03
00049  */
00050 /*****************************************************************************/
00051 class TheoryRecords :public Theory {
00052   RecordsProofRules* d_rules;
00053   //! Auxiliary rewrites: Processing of AND and OR of equations.  Returns e=e'.
00054   Theorem rewriteAux(const Expr& e);
00055   //! Takes Thm(e), returns Thm(e'), where e rewrites to e' by rewriteAux.
00056   Theorem rewriteAux(const Theorem& thm);
00057 
00058 public:
00059   TheoryRecords(TheoryCore* core); //!< Constructor
00060   ~TheoryRecords(); //!< Destructor
00061   //! creates a reference to the proof rules
00062   RecordsProofRules* createProofRules();
00063   
00064   // Theory interface
00065 
00066   //! assert a fact to the theory of records
00067   void assertFact(const Theorem& e);
00068   //! empty implementation to fit theory interface
00069   void checkSat(bool fullEffort) {}
00070   //! rewrites an expression e to one of several allowed forms
00071   Theorem rewrite(const Expr& e);
00072   //! check record or tuple type
00073   void checkType(const Expr& e);
00074   Cardinality finiteTypeInfo(Expr& e, Unsigned& n,
00075                              bool enumerate, bool computeSize);
00076   //! computes the type of a record or a tuple
00077   void computeType(const Expr& e);
00078   Type computeBaseType(const Type& t);
00079   
00080   Expr computeTypePred(const Type& t, const Expr& e);
00081   void computeModelTerm(const Expr& e, std::vector<Expr>& v);
00082   void computeModel(const Expr& e, std::vector<Expr>& vars);
00083 
00084   Expr computeTCC(const Expr& e);
00085   virtual Expr parseExprOp(const Expr& e);
00086   void setup(const Expr& e);
00087   void update(const Theorem& e, const Expr& d);
00088   //! pretty printing
00089   ExprStream& print(ExprStream& os, const Expr& e);
00090   //! Test whether expr is a record literal
00091   bool isRecord(const Expr& e) {
00092     return e.isApply() && e.getOpKind() == RECORD;
00093   }
00094   //! Test whether expr is a record type
00095   bool isRecordType(const Expr& e) {
00096     return e.isApply() && e.getOpKind() == RECORD_TYPE;
00097   }
00098   //! Test whether expr is a record type
00099   bool isRecordType(const Type& t) {
00100     return isRecordType(t.getExpr());
00101   }
00102   //! Test whether expr is a record select/update subclass
00103   bool isRecordAccess(const Expr& e)
00104   { return e.isApply() &&
00105       (e.getOpKind() == RECORD_SELECT || e.getOpKind() == RECORD_UPDATE); }
00106   //! Create a record literal
00107   Expr recordExpr(const std::vector<std::string>& fields,
00108       const std::vector<Expr>& kids);
00109   //! Create a record literal
00110   Expr recordExpr(const std::vector<Expr>& fields,
00111       const std::vector<Expr>& kids);
00112   //! Create a record type
00113   Type recordType(const std::vector<std::string>& fields,
00114       const std::vector<Type>& types);
00115   //! Create a record type (field types are given as a vector of Expr)
00116   Type recordType(const std::vector<std::string>& fields,
00117       const std::vector<Expr>& types);
00118   //! Create a record type (fields and types are given as a vector of Expr)
00119   Type recordType(const std::vector<Expr>& fields,
00120       const std::vector<Expr>& types);
00121   //! Create a record field select expression
00122   Expr recordSelect(const Expr& r, const std::string& field);
00123   //! Create a record field update expression
00124   Expr recordUpdate(const Expr& r, const std::string& field, const Expr& val);
00125   //! Get the list of fields from a record literal
00126   const std::vector<Expr>& getFields(const Expr& r);
00127   //! Get the i-th field name from the record literal or type
00128   const std::string& getField(const Expr& e, int i);
00129   //! Get the field index in the record literal or type
00130   /*! The field must be present in the record; otherwise it's an error. */
00131   int getFieldIndex(const Expr& e, const std::string& field);
00132   //! Get the field name from the record select and update expressions
00133   const std::string& getField(const Expr& e);
00134   //! Create a tuple literal
00135   Expr tupleExpr(const std::vector<Expr>& kids);
00136   //! Create a tuple type
00137   Type tupleType(const std::vector<Type>& types);
00138   //! Create a tuple type (types of components are given as Exprs)
00139   Type tupleType(const std::vector<Expr>& types);
00140   //! Create a tuple index selector expression
00141   Expr tupleSelect(const Expr& tup, int i);
00142   //! Create a tuple index update expression
00143   Expr tupleUpdate(const Expr& tup, int i, const Expr& val);
00144   //! Get the index from the tuple select and update expressions
00145   int getIndex(const Expr& e);
00146   //! Test whether expr is a tuple select/update subclass
00147   bool isTupleAccess(const Expr& e)
00148     { return e.isApply() &&
00149         (e.getOpKind() == TUPLE_SELECT || e.getOpKind() == TUPLE_UPDATE); }
00150   //! Test if expr is a tuple literal
00151   bool isTuple(const Expr& e) { return e.isApply() && e.getOpKind() == TUPLE; }
00152   //! Test if expr represents a tuple type
00153   bool isTupleType(const Expr& e)
00154     { return e.isApply() && e.getOpKind() == TUPLE_TYPE; }
00155   //! Test if 'tp' is a tuple type
00156   bool isTupleType(const Type& tp) { return isTupleType(tp.getExpr()); }
00157 };  // end of class TheoryRecords
00158 
00159 }
00160 
00161 #endif