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

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