type.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file type.h
00004  * 
00005  * Author: Clark Barrett
00006  * 
00007  * Created: Thu Dec 12 12:53:28 2002
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 // expr.h Has to be included outside of #ifndef, since it sources us
00030 // recursively (read comments in expr_value.h).
00031 #ifndef _CVC_lite__expr_h_
00032 #include "expr.h"
00033 #endif
00034 
00035 #ifndef _cvcl__include__type_h_
00036 #define _cvcl__include__type_h_
00037 
00038 namespace CVCL {
00039 
00040 ///////////////////////////////////////////////////////////////////////////////
00041 //                                                                           //
00042 // Class: Type                                                               //
00043 // Author: Clark Barrett                                                     //
00044 // Created: Thu Dec 12 12:53:34 2002                                         //
00045 // Description: Wrapper around expr for api                                  //
00046 //                                                                           //
00047 ///////////////////////////////////////////////////////////////////////////////
00048 class Type {
00049   Expr d_expr;
00050 
00051 public:
00052   Type() {}
00053   Type(Expr expr);
00054   //! Special constructor that doesn't check if expr is a type
00055   //TODO: make this private
00056   Type(Expr expr, bool dummy) :d_expr(expr) {}
00057   const Expr& getExpr() const { return d_expr; }
00058 
00059   // Reasoning about children
00060   int arity() const { return d_expr.arity(); }
00061   Type operator[](int i) const { return Type(d_expr[i]); }
00062 
00063   // Core testers
00064   bool isNull() const { return d_expr.isNull(); }
00065   bool isBool() const { return d_expr.getKind() == BOOLEAN; }
00066   bool isSubtype() const { return d_expr.getKind() == SUBTYPE; }
00067   bool isFunction() const { return d_expr.getKind() == ARROW; }
00068 
00069   // Core constructors
00070   static Type typeBool(ExprManager* em) { return Type(em->boolExpr(), true); }
00071   static Type funType(const std::vector<Type>& typeDom, const Type& typeRan);
00072   Type funType(const Type& typeRan) const
00073   { return Type(Expr(ARROW, d_expr, typeRan.d_expr)); }
00074 
00075   // Printing
00076   std::string toString() const { return getExpr().toString(); }
00077 };
00078 
00079 inline bool operator==(const Type& t1, const Type& t2)
00080 { return t1.getExpr() == t2.getExpr(); }
00081 
00082 inline bool operator!=(const Type& t1, const Type& t2)
00083 { return t1.getExpr() != t2.getExpr(); }
00084 
00085 // Printing
00086 inline std::ostream& operator<<(std::ostream& os, const Type& t) {
00087   return os << t.getExpr();
00088 }
00089 
00090 }
00091 
00092 #endif

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