1 /********************* */
4 ** Original author: Christopher L. Conway
5 ** Major contributors: Dejan Jovanovic, Morgan Deters
6 ** Minor contributors (to current version): Andrew Reynolds
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2013 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief Interface for expression types.
14 ** Interface for expression types
17 #include "cvc4_public.h"
19 #ifndef __CVC4__TYPE_H
20 #define __CVC4__TYPE_H
27 #include "util/cardinality.h"
28 #include "util/subrange_bound.h"
33 class CVC4_PUBLIC ExprManager
;
34 class CVC4_PUBLIC Expr
;
36 struct CVC4_PUBLIC ExprManagerMapCollection
;
38 class CVC4_PUBLIC SmtEngine
;
40 class CVC4_PUBLIC Datatype
;
41 class CVC4_PUBLIC Record
;
43 template <bool ref_count
>
54 class ConstructorType
;
62 class SortConstructorType
;
64 //class PredicateSubtype;
68 /** Hash function for Types */
69 struct CVC4_PUBLIC TypeHashFunction
{
70 /** Return a hash code for type t */
71 size_t operator()(const CVC4::Type
& t
) const;
72 };/* struct TypeHashFunction */
75 * Output operator for types
76 * @param out the stream to output to
77 * @param t the type to output
80 std::ostream
& operator<<(std::ostream
& out
, const Type
& t
) CVC4_PUBLIC
;
83 TypeNode
exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
84 }/* CVC4::expr namespace */
87 * Class encapsulating CVC4 expression types.
89 class CVC4_PUBLIC Type
{
91 friend class SmtEngine
;
92 friend class ExprManager
;
93 friend class NodeManager
;
94 friend class TypeNode
;
95 friend std::ostream
& CVC4::operator<<(std::ostream
& out
, const Type
& t
);
96 friend TypeNode
expr::exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
100 /** The internal expression representation */
101 TypeNode
* d_typeNode
;
103 /** The responsible expression manager */
104 NodeManager
* d_nodeManager
;
107 * Construct a new type given the typeNode, for internal use only.
108 * @param typeNode the TypeNode to use
109 * @return the Type corresponding to the TypeNode
111 Type
makeType(const TypeNode
& typeNode
) const;
114 * Constructor for internal purposes.
115 * @param em the expression manager that handles this expression
116 * @param typeNode the actual TypeNode pointer for this type
118 Type(NodeManager
* em
, TypeNode
* typeNode
);
120 /** Accessor for derived classes */
121 static TypeNode
* getTypeNode(const Type
& t
) throw() { return t
.d_typeNode
; }
125 /** Force a virtual destructor for safety. */
128 /** Default constructor */
133 * @param t the type to make a copy of
138 * Check whether this is a null type
139 * @return true if type is null
144 * Return the cardinality of this type.
146 Cardinality
getCardinality() const;
149 * Is this a well-founded type?
151 bool isWellFounded() const;
154 * Construct and return a ground term for this Type. Throws an
155 * exception if this type is not well-founded.
157 Expr
mkGroundTerm() const;
160 * Is this type a subtype of the given type?
162 bool isSubtypeOf(Type t
) const;
165 * Is this type comparable to the given type (i.e., do they share
166 * a common ancestor in the subtype tree)?
168 bool isComparableTo(Type t
) const;
171 * Get the most general base type of this type.
173 Type
getBaseType() const;
176 * Substitution of Types.
178 Type
substitute(const Type
& type
, const Type
& replacement
) const;
181 * Simultaneous substitution of Types.
183 Type
substitute(const std::vector
<Type
>& types
,
184 const std::vector
<Type
>& replacements
) const;
187 * Get this type's ExprManager.
189 ExprManager
* getExprManager() const;
192 * Exports this type into a different ExprManager.
194 Type
exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& vmap
) const;
197 * Assignment operator.
198 * @param t the type to assign to this type
199 * @return this type after assignment.
201 Type
& operator=(const Type
& t
);
204 * Comparison for structural equality.
205 * @param t the type to compare to
206 * @returns true if the types are equal
208 bool operator==(const Type
& t
) const;
211 * Comparison for structural disequality.
212 * @param t the type to compare to
213 * @returns true if the types are not equal
215 bool operator!=(const Type
& t
) const;
218 * An ordering on Types so they can be stored in maps, etc.
220 bool operator<(const Type
& t
) const;
223 * An ordering on Types so they can be stored in maps, etc.
225 bool operator<=(const Type
& t
) const;
228 * An ordering on Types so they can be stored in maps, etc.
230 bool operator>(const Type
& t
) const;
233 * An ordering on Types so they can be stored in maps, etc.
235 bool operator>=(const Type
& t
) const;
238 * Is this the Boolean type?
239 * @return true if the type is a Boolean type
241 bool isBoolean() const;
244 * Is this the integer type?
245 * @return true if the type is a integer type
247 bool isInteger() const;
250 * Is this the real type?
251 * @return true if the type is a real type
256 * Is this the string type?
257 * @return true if the type is the string type
259 bool isString() const;
262 * Is this the bit-vector type?
263 * @return true if the type is a bit-vector type
265 bool isBitVector() const;
268 * Is this a function type?
269 * @return true if the type is a function type
271 bool isFunction() const;
274 * Is this a predicate type, i.e. if it's a function type mapping to Boolean.
275 * All predicate types are also function types.
276 * @return true if the type is a predicate type
278 bool isPredicate() const;
281 * Is this a tuple type?
282 * @return true if the type is a tuple type
284 bool isTuple() const;
287 * Is this a record type?
288 * @return true if the type is a record type
290 bool isRecord() const;
293 * Is this a symbolic expression type?
294 * @return true if the type is a symbolic expression type
296 bool isSExpr() const;
299 * Is this an array type?
300 * @return true if the type is a array type
302 bool isArray() const;
305 * Is this a Set type?
306 * @return true if the type is a Set type
311 * Is this a datatype type?
312 * @return true if the type is a datatype type
314 bool isDatatype() const;
317 * Is this a constructor type?
318 * @return true if the type is a constructor type
320 bool isConstructor() const;
323 * Is this a selector type?
324 * @return true if the type is a selector type
326 bool isSelector() const;
329 * Is this a tester type?
330 * @return true if the type is a tester type
332 bool isTester() const;
335 * Is this a sort kind?
336 * @return true if this is a sort kind
341 * Is this a sort constructor kind?
342 * @return true if this is a sort constructor kind
344 bool isSortConstructor() const;
347 * Is this a predicate subtype?
348 * @return true if this is a predicate subtype
350 // not in release 1.0
351 //bool isPredicateSubtype() const;
354 * Is this an integer subrange type?
355 * @return true if this is an integer subrange type
357 bool isSubrange() const;
360 * Outputs a string representation of this type to the stream.
361 * @param out the stream to output to
363 void toStream(std::ostream
& out
) const;
366 * Constructs a string representation of this type.
368 std::string
toString() const;
372 * Singleton class encapsulating the Boolean type.
374 class CVC4_PUBLIC BooleanType
: public Type
{
378 /** Construct from the base type */
379 BooleanType(const Type
& type
= Type()) throw(IllegalArgumentException
);
380 };/* class BooleanType */
383 * Singleton class encapsulating the integer type.
385 class CVC4_PUBLIC IntegerType
: public Type
{
389 /** Construct from the base type */
390 IntegerType(const Type
& type
= Type()) throw(IllegalArgumentException
);
391 };/* class IntegerType */
394 * Singleton class encapsulating the real type.
396 class CVC4_PUBLIC RealType
: public Type
{
400 /** Construct from the base type */
401 RealType(const Type
& type
= Type()) throw(IllegalArgumentException
);
402 };/* class RealType */
405 * Singleton class encapsulating the string type.
407 class CVC4_PUBLIC StringType
: public Type
{
411 /** Construct from the base type */
412 StringType(const Type
& type
) throw(IllegalArgumentException
);
413 };/* class StringType */
416 * Class encapsulating a function type.
418 class CVC4_PUBLIC FunctionType
: public Type
{
422 /** Construct from the base type */
423 FunctionType(const Type
& type
= Type()) throw(IllegalArgumentException
);
425 /** Get the arity of the function type */
426 size_t getArity() const;
428 /** Get the argument types */
429 std::vector
<Type
> getArgTypes() const;
431 /** Get the range type (i.e., the type of the result). */
432 Type
getRangeType() const;
433 };/* class FunctionType */
436 * Class encapsulating a tuple type.
438 class CVC4_PUBLIC TupleType
: public Type
{
442 /** Construct from the base type */
443 TupleType(const Type
& type
= Type()) throw(IllegalArgumentException
);
445 /** Get the length of the tuple. The same as getTypes().size(). */
446 size_t getLength() const;
448 /** Get the constituent types */
449 std::vector
<Type
> getTypes() const;
451 };/* class TupleType */
454 * Class encapsulating a record type.
456 class CVC4_PUBLIC RecordType
: public Type
{
460 /** Construct from the base type */
461 RecordType(const Type
& type
= Type()) throw(IllegalArgumentException
);
463 /** Get the constituent types */
464 const Record
& getRecord() const;
465 };/* class RecordType */
468 * Class encapsulating a tuple type.
470 class CVC4_PUBLIC SExprType
: public Type
{
474 /** Construct from the base type */
475 SExprType(const Type
& type
= Type()) throw(IllegalArgumentException
);
477 /** Get the constituent types */
478 std::vector
<Type
> getTypes() const;
479 };/* class SExprType */
482 * Class encapsulating an array type.
484 class CVC4_PUBLIC ArrayType
: public Type
{
488 /** Construct from the base type */
489 ArrayType(const Type
& type
= Type()) throw(IllegalArgumentException
);
491 /** Get the index type */
492 Type
getIndexType() const;
494 /** Get the constituent type */
495 Type
getConstituentType() const;
496 };/* class ArrayType */
499 * Class encapsulating an set type.
501 class CVC4_PUBLIC SetType
: public Type
{
505 /** Construct from the base type */
506 SetType(const Type
& type
= Type()) throw(IllegalArgumentException
);
508 /** Get the index type */
509 Type
getElementType() const;
510 };/* class SetType */
513 * Class encapsulating a user-defined sort.
515 class CVC4_PUBLIC SortType
: public Type
{
519 /** Construct from the base type */
520 SortType(const Type
& type
= Type()) throw(IllegalArgumentException
);
522 /** Get the name of the sort */
523 std::string
getName() const;
525 /** Is this type parameterized? */
526 bool isParameterized() const;
528 /** Get the parameter types */
529 std::vector
<Type
> getParamTypes() const;
531 };/* class SortType */
534 * Class encapsulating a user-defined sort constructor.
536 class CVC4_PUBLIC SortConstructorType
: public Type
{
540 /** Construct from the base type */
541 SortConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
543 /** Get the name of the sort constructor */
544 std::string
getName() const;
546 /** Get the arity of the sort constructor */
547 size_t getArity() const;
549 /** Instantiate a sort using this sort constructor */
550 SortType
instantiate(const std::vector
<Type
>& params
) const;
552 };/* class SortConstructorType */
554 // not in release 1.0
557 * Class encapsulating a predicate subtype.
559 class CVC4_PUBLIC PredicateSubtype
: public Type
{
563 /** Construct from the base type */
564 PredicateSubtype(const Type
& type
= Type()) throw(IllegalArgumentException
);
566 /** Get the LAMBDA defining this predicate subtype */
567 Expr
getPredicate() const;
570 * Get the parent type of this predicate subtype; note that this
571 * could be another predicate subtype.
573 Type
getParentType() const;
575 };/* class PredicateSubtype */
579 * Class encapsulating an integer subrange type.
581 class CVC4_PUBLIC SubrangeType
: public Type
{
585 /** Construct from the base type */
586 SubrangeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
588 /** Get the bounds defining this integer subrange */
589 SubrangeBounds
getSubrangeBounds() const;
591 };/* class SubrangeType */
594 * Class encapsulating the bit-vector type.
596 class CVC4_PUBLIC BitVectorType
: public Type
{
600 /** Construct from the base type */
601 BitVectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
604 * Returns the size of the bit-vector type.
605 * @return the width of the bit-vector type (> 0)
607 unsigned getSize() const;
609 };/* class BitVectorType */
613 * Class encapsulating the datatype type
615 class CVC4_PUBLIC DatatypeType
: public Type
{
619 /** Construct from the base type */
620 DatatypeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
622 /** Get the underlying datatype */
623 const Datatype
& getDatatype() const;
625 /** Is this datatype parametric? */
626 bool isParametric() const;
629 * Get the constructor operator associated to the given constructor
630 * name in this datatype.
632 Expr
getConstructor(std::string name
) const;
635 * Has this datatype been fully instantiated ?
637 * @return true if this datatype is not parametric or, if it is, it
638 * has been fully instantiated
640 bool isInstantiated() const;
643 * Has this datatype been instantiated for parameter N ?
645 bool isParameterInstantiated(unsigned n
) const;
647 /** Get the parameter types */
648 std::vector
<Type
> getParamTypes() const;
650 /** Get the arity of the datatype constructor */
651 size_t getArity() const;
653 /** Instantiate a datatype using this datatype constructor */
654 DatatypeType
instantiate(const std::vector
<Type
>& params
) const;
656 };/* class DatatypeType */
659 * Class encapsulating the constructor type
661 class CVC4_PUBLIC ConstructorType
: public Type
{
665 /** Construct from the base type */
666 ConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
668 /** Get the range type */
669 DatatypeType
getRangeType() const;
671 /** Get the argument types */
672 std::vector
<Type
> getArgTypes() const;
674 /** Get the number of constructor arguments */
675 size_t getArity() const;
677 };/* class ConstructorType */
681 * Class encapsulating the Selector type
683 class CVC4_PUBLIC SelectorType
: public Type
{
687 /** Construct from the base type */
688 SelectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
690 /** Get the domain type for this selector (the datatype type) */
691 DatatypeType
getDomain() const;
693 /** Get the range type for this selector (the field type) */
694 Type
getRangeType() const;
696 };/* class SelectorType */
699 * Class encapsulating the Tester type
701 class CVC4_PUBLIC TesterType
: public Type
{
705 /** Construct from the base type */
706 TesterType(const Type
& type
= Type()) throw(IllegalArgumentException
);
708 /** Get the type that this tester tests (the datatype type) */
709 DatatypeType
getDomain() const;
712 * Get the range type for this tester (included for sake of
713 * interface completeness), but doesn't give useful information).
715 BooleanType
getRangeType() const;
717 };/* class TesterType */
719 }/* CVC4 namespace */
721 #endif /* __CVC4__TYPE_H */