1 /********************* */
4 ** Top contributors (to current version):
5 ** Morgan Deters, Dejan Jovanovic, Martin Brain
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
8 ** in the top-level source directory) and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing 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
;
61 class SortConstructorType
;
63 //class PredicateSubtype;
67 /** Hash function for Types */
68 struct CVC4_PUBLIC TypeHashFunction
{
69 /** Return a hash code for type t */
70 size_t operator()(const CVC4::Type
& t
) const;
71 };/* struct TypeHashFunction */
74 * Output operator for types
75 * @param out the stream to output to
76 * @param t the type to output
79 std::ostream
& operator<<(std::ostream
& out
, const Type
& t
) CVC4_PUBLIC
;
82 TypeNode
exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
83 }/* CVC4::expr namespace */
86 * Class encapsulating CVC4 expression types.
88 class CVC4_PUBLIC Type
{
90 friend class SmtEngine
;
91 friend class ExprManager
;
92 friend class NodeManager
;
93 friend class TypeNode
;
94 friend std::ostream
& CVC4::operator<<(std::ostream
& out
, const Type
& t
);
95 friend TypeNode
expr::exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
99 /** The internal expression representation */
100 TypeNode
* d_typeNode
;
102 /** The responsible expression manager */
103 NodeManager
* d_nodeManager
;
106 * Construct a new type given the typeNode, for internal use only.
107 * @param typeNode the TypeNode to use
108 * @return the Type corresponding to the TypeNode
110 Type
makeType(const TypeNode
& typeNode
) const;
113 * Constructor for internal purposes.
114 * @param em the expression manager that handles this expression
115 * @param typeNode the actual TypeNode pointer for this type
117 Type(NodeManager
* em
, TypeNode
* typeNode
);
119 /** Accessor for derived classes */
120 static TypeNode
* getTypeNode(const Type
& t
) throw() { return t
.d_typeNode
; }
124 /** Force a virtual destructor for safety. */
127 /** Default constructor */
132 * @param t the type to make a copy of
137 * Check whether this is a null type
138 * @return true if type is null
143 * Return the cardinality of this type.
145 Cardinality
getCardinality() const;
148 * Is this a well-founded type?
150 bool isWellFounded() const;
153 * Construct and return a ground term for this Type. Throws an
154 * exception if this type is not well-founded.
156 Expr
mkGroundTerm() const;
159 * Is this type a subtype of the given type?
161 bool isSubtypeOf(Type t
) const;
164 * Is this type comparable to the given type (i.e., do they share
165 * a common ancestor in the subtype tree)?
167 bool isComparableTo(Type t
) const;
170 * Get the most general base type of this type.
172 Type
getBaseType() const;
175 * Substitution of Types.
177 Type
substitute(const Type
& type
, const Type
& replacement
) const;
180 * Simultaneous substitution of Types.
182 Type
substitute(const std::vector
<Type
>& types
,
183 const std::vector
<Type
>& replacements
) const;
186 * Get this type's ExprManager.
188 ExprManager
* getExprManager() const;
191 * Exports this type into a different ExprManager.
193 Type
exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& vmap
) const;
196 * Assignment operator.
197 * @param t the type to assign to this type
198 * @return this type after assignment.
200 Type
& operator=(const Type
& t
);
203 * Comparison for structural equality.
204 * @param t the type to compare to
205 * @returns true if the types are equal
207 bool operator==(const Type
& t
) const;
210 * Comparison for structural disequality.
211 * @param t the type to compare to
212 * @returns true if the types are not equal
214 bool operator!=(const Type
& t
) const;
217 * An ordering on Types so they can be stored in maps, etc.
219 bool operator<(const Type
& t
) const;
222 * An ordering on Types so they can be stored in maps, etc.
224 bool operator<=(const Type
& t
) const;
227 * An ordering on Types so they can be stored in maps, etc.
229 bool operator>(const Type
& t
) const;
232 * An ordering on Types so they can be stored in maps, etc.
234 bool operator>=(const Type
& t
) const;
237 * Is this the Boolean type?
238 * @return true if the type is a Boolean type
240 bool isBoolean() const;
243 * Is this the integer type?
244 * @return true if the type is a integer type
246 bool isInteger() const;
249 * Is this the real type?
250 * @return true if the type is a real type
255 * Is this the string type?
256 * @return true if the type is the string type
258 bool isString() const;
261 * Is this the rounding mode type?
262 * @return true if the type is the rounding mode type
264 bool isRoundingMode() const;
267 * Is this the bit-vector type?
268 * @return true if the type is a bit-vector type
270 bool isBitVector() const;
273 * Is this the floating-point type?
274 * @return true if the type is a floating-point type
276 bool isFloatingPoint() const;
279 * Is this a function type?
280 * @return true if the type is a function type
282 bool isFunction() const;
285 * Is this a predicate type, i.e. if it's a function type mapping to Boolean.
286 * All predicate types are also function types.
287 * @return true if the type is a predicate type
289 bool isPredicate() const;
292 * Is this a tuple type?
293 * @return true if the type is a tuple type
295 bool isTuple() const;
298 * Is this a record type?
299 * @return true if the type is a record type
301 bool isRecord() const;
304 * Is this a symbolic expression type?
305 * @return true if the type is a symbolic expression type
307 bool isSExpr() const;
310 * Is this an array type?
311 * @return true if the type is a array type
313 bool isArray() const;
316 * Is this a Set type?
317 * @return true if the type is a Set type
322 * Is this a datatype type?
323 * @return true if the type is a datatype type
325 bool isDatatype() const;
328 * Is this a constructor type?
329 * @return true if the type is a constructor type
331 bool isConstructor() const;
334 * Is this a selector type?
335 * @return true if the type is a selector type
337 bool isSelector() const;
340 * Is this a tester type?
341 * @return true if the type is a tester type
343 bool isTester() const;
346 * Is this a sort kind?
347 * @return true if this is a sort kind
352 * Is this a sort constructor kind?
353 * @return true if this is a sort constructor kind
355 bool isSortConstructor() const;
358 * Is this a predicate subtype?
359 * @return true if this is a predicate subtype
361 // not in release 1.0
362 //bool isPredicateSubtype() const;
365 * Is this an integer subrange type?
366 * @return true if this is an integer subrange type
368 bool isSubrange() const;
371 * Outputs a string representation of this type to the stream.
372 * @param out the stream to output to
374 void toStream(std::ostream
& out
) const;
377 * Constructs a string representation of this type.
379 std::string
toString() const;
383 * Singleton class encapsulating the Boolean type.
385 class CVC4_PUBLIC BooleanType
: public Type
{
389 /** Construct from the base type */
390 BooleanType(const Type
& type
= Type()) throw(IllegalArgumentException
);
391 };/* class BooleanType */
394 * Singleton class encapsulating the integer type.
396 class CVC4_PUBLIC IntegerType
: public Type
{
400 /** Construct from the base type */
401 IntegerType(const Type
& type
= Type()) throw(IllegalArgumentException
);
402 };/* class IntegerType */
405 * Singleton class encapsulating the real type.
407 class CVC4_PUBLIC RealType
: public Type
{
411 /** Construct from the base type */
412 RealType(const Type
& type
= Type()) throw(IllegalArgumentException
);
413 };/* class RealType */
416 * Singleton class encapsulating the string type.
418 class CVC4_PUBLIC StringType
: public Type
{
422 /** Construct from the base type */
423 StringType(const Type
& type
) throw(IllegalArgumentException
);
424 };/* class StringType */
427 * Singleton class encapsulating the rounding mode type.
429 class CVC4_PUBLIC RoundingModeType
: public Type
{
433 /** Construct from the base type */
434 RoundingModeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
435 };/* class RoundingModeType */
440 * Class encapsulating a function type.
442 class CVC4_PUBLIC FunctionType
: public Type
{
446 /** Construct from the base type */
447 FunctionType(const Type
& type
= Type()) throw(IllegalArgumentException
);
449 /** Get the arity of the function type */
450 size_t getArity() const;
452 /** Get the argument types */
453 std::vector
<Type
> getArgTypes() const;
455 /** Get the range type (i.e., the type of the result). */
456 Type
getRangeType() const;
457 };/* class FunctionType */
460 * Class encapsulating a sexpr type.
462 class CVC4_PUBLIC SExprType
: public Type
{
466 /** Construct from the base type */
467 SExprType(const Type
& type
= Type()) throw(IllegalArgumentException
);
469 /** Get the constituent types */
470 std::vector
<Type
> getTypes() const;
471 };/* class SExprType */
474 * Class encapsulating an array type.
476 class CVC4_PUBLIC ArrayType
: public Type
{
480 /** Construct from the base type */
481 ArrayType(const Type
& type
= Type()) throw(IllegalArgumentException
);
483 /** Get the index type */
484 Type
getIndexType() const;
486 /** Get the constituent type */
487 Type
getConstituentType() const;
488 };/* class ArrayType */
491 * Class encapsulating an set type.
493 class CVC4_PUBLIC SetType
: public Type
{
497 /** Construct from the base type */
498 SetType(const Type
& type
= Type()) throw(IllegalArgumentException
);
500 /** Get the index type */
501 Type
getElementType() const;
502 };/* class SetType */
505 * Class encapsulating a user-defined sort.
507 class CVC4_PUBLIC SortType
: public Type
{
511 /** Construct from the base type */
512 SortType(const Type
& type
= Type()) throw(IllegalArgumentException
);
514 /** Get the name of the sort */
515 std::string
getName() const;
517 /** Is this type parameterized? */
518 bool isParameterized() const;
520 /** Get the parameter types */
521 std::vector
<Type
> getParamTypes() const;
523 };/* class SortType */
526 * Class encapsulating a user-defined sort constructor.
528 class CVC4_PUBLIC SortConstructorType
: public Type
{
532 /** Construct from the base type */
533 SortConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
535 /** Get the name of the sort constructor */
536 std::string
getName() const;
538 /** Get the arity of the sort constructor */
539 size_t getArity() const;
541 /** Instantiate a sort using this sort constructor */
542 SortType
instantiate(const std::vector
<Type
>& params
) const;
544 };/* class SortConstructorType */
546 // not in release 1.0
549 * Class encapsulating a predicate subtype.
551 class CVC4_PUBLIC PredicateSubtype
: public Type
{
555 /** Construct from the base type */
556 PredicateSubtype(const Type
& type
= Type()) throw(IllegalArgumentException
);
558 /** Get the LAMBDA defining this predicate subtype */
559 Expr
getPredicate() const;
562 * Get the parent type of this predicate subtype; note that this
563 * could be another predicate subtype.
565 Type
getParentType() const;
567 };/* class PredicateSubtype */
571 * Class encapsulating an integer subrange type.
573 class CVC4_PUBLIC SubrangeType
: public Type
{
577 /** Construct from the base type */
578 SubrangeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
580 /** Get the bounds defining this integer subrange */
581 SubrangeBounds
getSubrangeBounds() const;
583 };/* class SubrangeType */
586 * Class encapsulating the bit-vector type.
588 class CVC4_PUBLIC BitVectorType
: public Type
{
592 /** Construct from the base type */
593 BitVectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
596 * Returns the size of the bit-vector type.
597 * @return the width of the bit-vector type (> 0)
599 unsigned getSize() const;
601 };/* class BitVectorType */
605 * Class encapsulating the floating point type.
607 class CVC4_PUBLIC FloatingPointType
: public Type
{
611 /** Construct from the base type */
612 FloatingPointType(const Type
& type
= Type()) throw(IllegalArgumentException
);
615 * Returns the size of the floating-point exponent type.
616 * @return the width of the floating-point exponent type (> 0)
618 unsigned getExponentSize() const;
621 * Returns the size of the floating-point significand type.
622 * @return the width of the floating-point significand type (> 0)
624 unsigned getSignificandSize() const;
626 };/* class FloatingPointType */
630 * Class encapsulating the datatype type
632 class CVC4_PUBLIC DatatypeType
: public Type
{
636 /** Construct from the base type */
637 DatatypeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
639 /** Get the underlying datatype */
640 const Datatype
& getDatatype() const;
642 /** Is this datatype parametric? */
643 bool isParametric() const;
646 * Get the constructor operator associated to the given constructor
647 * name in this datatype.
649 Expr
getConstructor(std::string name
) const;
652 * Has this datatype been fully instantiated ?
654 * @return true if this datatype is not parametric or, if it is, it
655 * has been fully instantiated
657 bool isInstantiated() const;
660 * Has this datatype been instantiated for parameter N ?
662 bool isParameterInstantiated(unsigned n
) const;
664 /** Get the parameter types */
665 std::vector
<Type
> getParamTypes() const;
667 /** Get the arity of the datatype constructor */
668 size_t getArity() const;
670 /** Instantiate a datatype using this datatype constructor */
671 DatatypeType
instantiate(const std::vector
<Type
>& params
) const;
673 /** Get the length of a tuple type */
674 size_t getTupleLength() const;
676 /** Get the constituent types of a tuple type */
677 std::vector
<Type
> getTupleTypes() const;
679 /** Get the description of the record type */
680 const Record
& getRecord() const;
682 };/* class DatatypeType */
685 * Class encapsulating the constructor type
687 class CVC4_PUBLIC ConstructorType
: public Type
{
691 /** Construct from the base type */
692 ConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
694 /** Get the range type */
695 DatatypeType
getRangeType() const;
697 /** Get the argument types */
698 std::vector
<Type
> getArgTypes() const;
700 /** Get the number of constructor arguments */
701 size_t getArity() const;
703 };/* class ConstructorType */
707 * Class encapsulating the Selector type
709 class CVC4_PUBLIC SelectorType
: public Type
{
713 /** Construct from the base type */
714 SelectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
716 /** Get the domain type for this selector (the datatype type) */
717 DatatypeType
getDomain() const;
719 /** Get the range type for this selector (the field type) */
720 Type
getRangeType() const;
722 };/* class SelectorType */
725 * Class encapsulating the Tester type
727 class CVC4_PUBLIC TesterType
: public Type
{
731 /** Construct from the base type */
732 TesterType(const Type
& type
= Type()) throw(IllegalArgumentException
);
734 /** Get the type that this tester tests (the datatype type) */
735 DatatypeType
getDomain() const;
738 * Get the range type for this tester (included for sake of
739 * interface completeness), but doesn't give useful information).
741 BooleanType
getRangeType() const;
743 };/* class TesterType */
745 }/* CVC4 namespace */
747 #endif /* __CVC4__TYPE_H */