1 /********************* */
4 ** Original author: Christopher L. Conway
5 ** Major contributors: Dejan Jovanovic, Morgan Deters
6 ** Minor contributors (to current version): Andrew Reynolds, Kshitij Bansal
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2014 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
;
43 template <bool ref_count
>
50 class RoundingModeType
;
55 class ConstructorType
;
63 class SortConstructorType
;
65 //class PredicateSubtype;
69 /** Hash function for Types */
70 struct CVC4_PUBLIC TypeHashFunction
{
71 /** Return a hash code for type t */
72 size_t operator()(const CVC4::Type
& t
) const;
73 };/* struct TypeHashFunction */
76 * Output operator for types
77 * @param out the stream to output to
78 * @param t the type to output
81 std::ostream
& operator<<(std::ostream
& out
, const Type
& t
) CVC4_PUBLIC
;
84 TypeNode
exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
85 }/* CVC4::expr namespace */
88 * Class encapsulating CVC4 expression types.
90 class CVC4_PUBLIC Type
{
92 friend class SmtEngine
;
93 friend class ExprManager
;
94 friend class NodeManager
;
95 friend class TypeNode
;
96 friend std::ostream
& CVC4::operator<<(std::ostream
& out
, const Type
& t
);
97 friend TypeNode
expr::exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
101 /** The internal expression representation */
102 TypeNode
* d_typeNode
;
104 /** The responsible expression manager */
105 NodeManager
* d_nodeManager
;
108 * Construct a new type given the typeNode, for internal use only.
109 * @param typeNode the TypeNode to use
110 * @return the Type corresponding to the TypeNode
112 Type
makeType(const TypeNode
& typeNode
) const;
115 * Constructor for internal purposes.
116 * @param em the expression manager that handles this expression
117 * @param typeNode the actual TypeNode pointer for this type
119 Type(NodeManager
* em
, TypeNode
* typeNode
);
121 /** Accessor for derived classes */
122 static TypeNode
* getTypeNode(const Type
& t
) throw() { return t
.d_typeNode
; }
126 /** Force a virtual destructor for safety. */
129 /** Default constructor */
134 * @param t the type to make a copy of
139 * Check whether this is a null type
140 * @return true if type is null
145 * Return the cardinality of this type.
147 Cardinality
getCardinality() const;
150 * Is this a well-founded type?
152 bool isWellFounded() const;
155 * Construct and return a ground term for this Type. Throws an
156 * exception if this type is not well-founded.
158 Expr
mkGroundTerm() const;
161 * Is this type a subtype of the given type?
163 bool isSubtypeOf(Type t
) const;
166 * Is this type comparable to the given type (i.e., do they share
167 * a common ancestor in the subtype tree)?
169 bool isComparableTo(Type t
) const;
172 * Get the most general base type of this type.
174 Type
getBaseType() const;
177 * Substitution of Types.
179 Type
substitute(const Type
& type
, const Type
& replacement
) const;
182 * Simultaneous substitution of Types.
184 Type
substitute(const std::vector
<Type
>& types
,
185 const std::vector
<Type
>& replacements
) const;
188 * Get this type's ExprManager.
190 ExprManager
* getExprManager() const;
193 * Exports this type into a different ExprManager.
195 Type
exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& vmap
) const;
198 * Assignment operator.
199 * @param t the type to assign to this type
200 * @return this type after assignment.
202 Type
& operator=(const Type
& t
);
205 * Comparison for structural equality.
206 * @param t the type to compare to
207 * @returns true if the types are equal
209 bool operator==(const Type
& t
) const;
212 * Comparison for structural disequality.
213 * @param t the type to compare to
214 * @returns true if the types are not equal
216 bool operator!=(const Type
& t
) const;
219 * An ordering on Types so they can be stored in maps, etc.
221 bool operator<(const Type
& t
) const;
224 * An ordering on Types so they can be stored in maps, etc.
226 bool operator<=(const Type
& t
) const;
229 * An ordering on Types so they can be stored in maps, etc.
231 bool operator>(const Type
& t
) const;
234 * An ordering on Types so they can be stored in maps, etc.
236 bool operator>=(const Type
& t
) const;
239 * Is this the Boolean type?
240 * @return true if the type is a Boolean type
242 bool isBoolean() const;
245 * Is this the integer type?
246 * @return true if the type is a integer type
248 bool isInteger() const;
251 * Is this the real type?
252 * @return true if the type is a real type
257 * Is this the string type?
258 * @return true if the type is the string type
260 bool isString() const;
263 * Is this the rounding mode type?
264 * @return true if the type is the rounding mode type
266 bool isRoundingMode() const;
269 * Is this the bit-vector type?
270 * @return true if the type is a bit-vector type
272 bool isBitVector() const;
275 * Is this the floating-point type?
276 * @return true if the type is a floating-point type
278 bool isFloatingPoint() const;
281 * Is this a function type?
282 * @return true if the type is a function type
284 bool isFunction() const;
287 * Is this a predicate type, i.e. if it's a function type mapping to Boolean.
288 * All predicate types are also function types.
289 * @return true if the type is a predicate type
291 bool isPredicate() const;
294 * Is this a tuple type?
295 * @return true if the type is a tuple type
297 bool isTuple() const;
300 * Is this a record type?
301 * @return true if the type is a record type
303 bool isRecord() const;
306 * Is this a symbolic expression type?
307 * @return true if the type is a symbolic expression type
309 bool isSExpr() const;
312 * Is this an array type?
313 * @return true if the type is a array type
315 bool isArray() const;
318 * Is this a Set type?
319 * @return true if the type is a Set type
324 * Is this a datatype type?
325 * @return true if the type is a datatype type
327 bool isDatatype() const;
330 * Is this a constructor type?
331 * @return true if the type is a constructor type
333 bool isConstructor() const;
336 * Is this a selector type?
337 * @return true if the type is a selector type
339 bool isSelector() const;
342 * Is this a tester type?
343 * @return true if the type is a tester type
345 bool isTester() const;
348 * Is this a sort kind?
349 * @return true if this is a sort kind
354 * Is this a sort constructor kind?
355 * @return true if this is a sort constructor kind
357 bool isSortConstructor() const;
360 * Is this a predicate subtype?
361 * @return true if this is a predicate subtype
363 // not in release 1.0
364 //bool isPredicateSubtype() const;
367 * Is this an integer subrange type?
368 * @return true if this is an integer subrange type
370 bool isSubrange() const;
373 * Outputs a string representation of this type to the stream.
374 * @param out the stream to output to
376 void toStream(std::ostream
& out
) const;
379 * Constructs a string representation of this type.
381 std::string
toString() const;
385 * Singleton class encapsulating the Boolean type.
387 class CVC4_PUBLIC BooleanType
: public Type
{
391 /** Construct from the base type */
392 BooleanType(const Type
& type
= Type()) throw(IllegalArgumentException
);
393 };/* class BooleanType */
396 * Singleton class encapsulating the integer type.
398 class CVC4_PUBLIC IntegerType
: public Type
{
402 /** Construct from the base type */
403 IntegerType(const Type
& type
= Type()) throw(IllegalArgumentException
);
404 };/* class IntegerType */
407 * Singleton class encapsulating the real type.
409 class CVC4_PUBLIC RealType
: public Type
{
413 /** Construct from the base type */
414 RealType(const Type
& type
= Type()) throw(IllegalArgumentException
);
415 };/* class RealType */
418 * Singleton class encapsulating the string type.
420 class CVC4_PUBLIC StringType
: public Type
{
424 /** Construct from the base type */
425 StringType(const Type
& type
) throw(IllegalArgumentException
);
426 };/* class StringType */
429 * Singleton class encapsulating the rounding mode type.
431 class CVC4_PUBLIC RoundingModeType
: public Type
{
435 /** Construct from the base type */
436 RoundingModeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
437 };/* class RoundingModeType */
442 * Class encapsulating a function type.
444 class CVC4_PUBLIC FunctionType
: public Type
{
448 /** Construct from the base type */
449 FunctionType(const Type
& type
= Type()) throw(IllegalArgumentException
);
451 /** Get the arity of the function type */
452 size_t getArity() const;
454 /** Get the argument types */
455 std::vector
<Type
> getArgTypes() const;
457 /** Get the range type (i.e., the type of the result). */
458 Type
getRangeType() const;
459 };/* class FunctionType */
462 * Class encapsulating a tuple type.
464 class CVC4_PUBLIC TupleType
: public Type
{
468 /** Construct from the base type */
469 TupleType(const Type
& type
= Type()) throw(IllegalArgumentException
);
471 /** Get the length of the tuple. The same as getTypes().size(). */
472 size_t getLength() const;
474 /** Get the constituent types */
475 std::vector
<Type
> getTypes() const;
477 };/* class TupleType */
480 * Class encapsulating a record type.
482 class CVC4_PUBLIC RecordType
: public Type
{
486 /** Construct from the base type */
487 RecordType(const Type
& type
= Type()) throw(IllegalArgumentException
);
489 /** Get the constituent types */
490 const Record
& getRecord() const;
491 };/* class RecordType */
494 * Class encapsulating a tuple type.
496 class CVC4_PUBLIC SExprType
: public Type
{
500 /** Construct from the base type */
501 SExprType(const Type
& type
= Type()) throw(IllegalArgumentException
);
503 /** Get the constituent types */
504 std::vector
<Type
> getTypes() const;
505 };/* class SExprType */
508 * Class encapsulating an array type.
510 class CVC4_PUBLIC ArrayType
: public Type
{
514 /** Construct from the base type */
515 ArrayType(const Type
& type
= Type()) throw(IllegalArgumentException
);
517 /** Get the index type */
518 Type
getIndexType() const;
520 /** Get the constituent type */
521 Type
getConstituentType() const;
522 };/* class ArrayType */
525 * Class encapsulating an set type.
527 class CVC4_PUBLIC SetType
: public Type
{
531 /** Construct from the base type */
532 SetType(const Type
& type
= Type()) throw(IllegalArgumentException
);
534 /** Get the index type */
535 Type
getElementType() const;
536 };/* class SetType */
539 * Class encapsulating a user-defined sort.
541 class CVC4_PUBLIC SortType
: public Type
{
545 /** Construct from the base type */
546 SortType(const Type
& type
= Type()) throw(IllegalArgumentException
);
548 /** Get the name of the sort */
549 std::string
getName() const;
551 /** Is this type parameterized? */
552 bool isParameterized() const;
554 /** Get the parameter types */
555 std::vector
<Type
> getParamTypes() const;
557 };/* class SortType */
560 * Class encapsulating a user-defined sort constructor.
562 class CVC4_PUBLIC SortConstructorType
: public Type
{
566 /** Construct from the base type */
567 SortConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
569 /** Get the name of the sort constructor */
570 std::string
getName() const;
572 /** Get the arity of the sort constructor */
573 size_t getArity() const;
575 /** Instantiate a sort using this sort constructor */
576 SortType
instantiate(const std::vector
<Type
>& params
) const;
578 };/* class SortConstructorType */
580 // not in release 1.0
583 * Class encapsulating a predicate subtype.
585 class CVC4_PUBLIC PredicateSubtype
: public Type
{
589 /** Construct from the base type */
590 PredicateSubtype(const Type
& type
= Type()) throw(IllegalArgumentException
);
592 /** Get the LAMBDA defining this predicate subtype */
593 Expr
getPredicate() const;
596 * Get the parent type of this predicate subtype; note that this
597 * could be another predicate subtype.
599 Type
getParentType() const;
601 };/* class PredicateSubtype */
605 * Class encapsulating an integer subrange type.
607 class CVC4_PUBLIC SubrangeType
: public Type
{
611 /** Construct from the base type */
612 SubrangeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
614 /** Get the bounds defining this integer subrange */
615 SubrangeBounds
getSubrangeBounds() const;
617 };/* class SubrangeType */
620 * Class encapsulating the bit-vector type.
622 class CVC4_PUBLIC BitVectorType
: public Type
{
626 /** Construct from the base type */
627 BitVectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
630 * Returns the size of the bit-vector type.
631 * @return the width of the bit-vector type (> 0)
633 unsigned getSize() const;
635 };/* class BitVectorType */
639 * Class encapsulating the floating point type.
641 class CVC4_PUBLIC FloatingPointType
: public Type
{
645 /** Construct from the base type */
646 FloatingPointType(const Type
& type
= Type()) throw(IllegalArgumentException
);
649 * Returns the size of the floating-point exponent type.
650 * @return the width of the floating-point exponent type (> 0)
652 unsigned getExponentSize() const;
655 * Returns the size of the floating-point significand type.
656 * @return the width of the floating-point significand type (> 0)
658 unsigned getSignificandSize() const;
660 };/* class FloatingPointType */
664 * Class encapsulating the datatype type
666 class CVC4_PUBLIC DatatypeType
: public Type
{
670 /** Construct from the base type */
671 DatatypeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
673 /** Get the underlying datatype */
674 const Datatype
& getDatatype() const;
676 /** Is this datatype parametric? */
677 bool isParametric() const;
680 * Get the constructor operator associated to the given constructor
681 * name in this datatype.
683 Expr
getConstructor(std::string name
) const;
686 * Has this datatype been fully instantiated ?
688 * @return true if this datatype is not parametric or, if it is, it
689 * has been fully instantiated
691 bool isInstantiated() const;
694 * Has this datatype been instantiated for parameter N ?
696 bool isParameterInstantiated(unsigned n
) const;
698 /** Get the parameter types */
699 std::vector
<Type
> getParamTypes() const;
701 /** Get the arity of the datatype constructor */
702 size_t getArity() const;
704 /** Instantiate a datatype using this datatype constructor */
705 DatatypeType
instantiate(const std::vector
<Type
>& params
) const;
707 };/* class DatatypeType */
710 * Class encapsulating the constructor type
712 class CVC4_PUBLIC ConstructorType
: public Type
{
716 /** Construct from the base type */
717 ConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
719 /** Get the range type */
720 DatatypeType
getRangeType() const;
722 /** Get the argument types */
723 std::vector
<Type
> getArgTypes() const;
725 /** Get the number of constructor arguments */
726 size_t getArity() const;
728 };/* class ConstructorType */
732 * Class encapsulating the Selector type
734 class CVC4_PUBLIC SelectorType
: public Type
{
738 /** Construct from the base type */
739 SelectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
741 /** Get the domain type for this selector (the datatype type) */
742 DatatypeType
getDomain() const;
744 /** Get the range type for this selector (the field type) */
745 Type
getRangeType() const;
747 };/* class SelectorType */
750 * Class encapsulating the Tester type
752 class CVC4_PUBLIC TesterType
: public Type
{
756 /** Construct from the base type */
757 TesterType(const Type
& type
= Type()) throw(IllegalArgumentException
);
759 /** Get the type that this tester tests (the datatype type) */
760 DatatypeType
getDomain() const;
763 * Get the range type for this tester (included for sake of
764 * interface completeness), but doesn't give useful information).
766 BooleanType
getRangeType() const;
768 };/* class TesterType */
770 }/* CVC4 namespace */
772 #endif /* __CVC4__TYPE_H */