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 #include "expr.h" 00032 00033 #ifndef _cvcl__include__type_h_ 00034 #define _cvcl__include__type_h_ 00035 00036 #include <string> 00037 #include <iostream> 00038 #include <vector> 00039 #include "expr_manager.h" 00040 00041 namespace CVCL { 00042 00043 /////////////////////////////////////////////////////////////////////////////// 00044 // // 00045 // Class: Type // 00046 // Author: Clark Barrett // 00047 // Created: Thu Dec 12 12:53:34 2002 // 00048 // Description: Wrapper around expr for api // 00049 // // 00050 /////////////////////////////////////////////////////////////////////////////// 00051 class Type { 00052 Expr d_expr; 00053 00054 public: 00055 Type() {} 00056 Type(Expr expr) : d_expr(expr) {} 00057 const Expr& getExpr() const { return d_expr; } 00058 00059 // Core testers 00060 00061 bool isType() const { return d_expr.getKind() == TYPE; } 00062 bool isBool() const { return d_expr.getKind() == BOOLEAN; } 00063 /* bool isReal() const { return d_expr.getKind() == REAL; } */ 00064 /* bool isInt() const { return d_expr.getKind() == INT; } */ 00065 /* bool isSubrange() const { return d_expr.getKind() == SUBRANGE; } */ 00066 bool isSubtype() const { return d_expr.getKind() == SUBTYPE; } 00067 /* bool isTuple() const { return d_expr.getKind() == TUPLE_TYPE; } */ 00068 bool isFunction() const { return d_expr.getKind() == ARROW; } 00069 /* bool isRecord() const {return d_expr.getKind() == RECORD_TYPE; } */ 00070 bool isTypeDecl() const {return d_expr.getKind() == TYPEDECL; } 00071 bool isNull() const { return d_expr.isNull(); } 00072 bool isFinite() const {return isBool();} 00073 00074 int arity() const { return d_expr.arity(); } 00075 Type operator[](int i) const { return Type(d_expr[i]); } 00076 00077 const std::string& getTypeDeclName() const { 00078 DebugAssert(isTypeDecl(),"TypeDecl expected"); 00079 return d_expr[0].getString(); 00080 } 00081 00082 // Core constructors 00083 00084 static Type typeBool(ExprManager* em) { return Type(em->boolExpr()); } 00085 // static Type typeReal(ExprManager* em) { return Type(newExpr(em, REAL)); } 00086 // static Type typeInt(ExprManager* em) { return Type(newExpr(em, INT)); } 00087 // static Type typeSubrange(const Expr& l, const Expr& r) { 00088 // return Type(newExpr(l.getEM(), SUBRANGE, l, r)); 00089 // } 00090 // Type tupleType(const Type& type1) const 00091 // { return Type(newExpr(d_expr.getEM(), TUPLE_TYPE, d_expr, type1.d_expr)); } 00092 // Type tupleType(const Type& type1, const Type& type2) const 00093 // { return Type(newExpr(d_expr.getEM(), TUPLE_TYPE, d_expr, 00094 // type1.d_expr, type2.d_expr)); } 00095 // static Type tupleType(const std::vector<Type>& types) { 00096 // DebugAssert(types.size() > 0, "tupleType()"); 00097 // std::vector<Expr> eVec; 00098 // for (unsigned i=0; i < types.size(); i++) eVec.push_back(types[i].d_expr); 00099 // return Type(newExpr(types[0].getExpr().getEM(), TUPLE_TYPE, eVec)); 00100 // } 00101 Type funType(const Type& typeRan) const 00102 { return Type(newExpr(d_expr.getEM(), ARROW, d_expr, typeRan.d_expr)); } 00103 00104 // Printing 00105 std::string toString() const { return getExpr().toString(); } 00106 }; 00107 00108 //! n-ary function type 00109 Type funType(const std::vector<Type>& typeDom, const Type& typeRan); 00110 00111 inline bool operator==(const Type& t1, const Type& t2) 00112 { return t1.getExpr() == t2.getExpr(); } 00113 00114 inline bool operator!=(const Type& t1, const Type& t2) 00115 { return t1.getExpr() != t2.getExpr(); } 00116 00117 // Printing 00118 inline std::ostream& operator<<(std::ostream& os, const Type& t) { 00119 return os << t.getExpr(); 00120 } 00121 00122 } 00123 00124 #endif
1.3.9.1