1 /********************* */
4 ** Top contributors (to current version):
5 ** Morgan Deters, Dejan Jovanovic, Andrew Reynolds
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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"
27 #include "util/cardinality.h"
32 class CVC4_PUBLIC ExprManager
;
33 class CVC4_PUBLIC Expr
;
35 struct CVC4_PUBLIC ExprManagerMapCollection
;
37 class CVC4_PUBLIC SmtEngine
;
39 class CVC4_PUBLIC Datatype
;
42 template <bool ref_count
>
50 class RoundingModeType
;
55 class ConstructorType
;
61 class SortConstructorType
;
64 /** Hash function for Types */
65 struct CVC4_PUBLIC TypeHashFunction
{
66 /** Return a hash code for type t */
67 size_t operator()(const CVC4::Type
& t
) const;
68 };/* struct TypeHashFunction */
71 * Output operator for types
72 * @param out the stream to output to
73 * @param t the type to output
76 std::ostream
& operator<<(std::ostream
& out
, const Type
& t
) CVC4_PUBLIC
;
79 TypeNode
exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
80 }/* CVC4::expr namespace */
83 * Class encapsulating CVC4 expression types.
85 class CVC4_PUBLIC Type
{
87 friend class SmtEngine
;
88 friend class ExprManager
;
89 friend class NodeManager
;
90 friend class TypeNode
;
91 friend std::ostream
& CVC4::operator<<(std::ostream
& out
, const Type
& t
);
92 friend TypeNode
expr::exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
96 /** The internal expression representation */
99 /** The responsible expression manager */
100 NodeManager
* d_nodeManager
;
103 * Construct a new type given the typeNode, for internal use only.
104 * @param typeNode the TypeNode to use
105 * @return the Type corresponding to the TypeNode
107 Type
makeType(const TypeNode
& typeNode
) const;
110 * Constructor for internal purposes.
111 * @param em the expression manager that handles this expression
112 * @param typeNode the actual TypeNode pointer for this type
114 Type(NodeManager
* em
, TypeNode
* typeNode
);
116 /** Accessor for derived classes */
117 static TypeNode
* getTypeNode(const Type
& t
) { return t
.d_typeNode
; }
119 /** Force a virtual destructor for safety. */
122 /** Default constructor */
127 * @param t the type to make a copy of
132 * Check whether this is a null type
133 * @return true if type is null
138 * Return the cardinality of this type.
140 Cardinality
getCardinality() const;
143 * Is this type finite? This assumes uninterpreted sorts have infinite
146 bool isFinite() const;
149 * Is this type interpreted as being finite.
150 * If finite model finding is enabled, this assumes all uninterpreted sorts
151 * are interpreted as finite.
153 bool isInterpretedFinite() const;
156 * Is this a well-founded type?
158 bool isWellFounded() const;
161 * Is this a first-class type?
163 * First-class types are types for which:
164 * (1) we handle equalities between terms of that type, and
165 * (2) they are allowed to be parameters of parametric types (e.g. index or
166 * element types of arrays).
168 * Examples of types that are not first-class include constructor types,
169 * selector types, tester types, regular expressions and SExprs.
171 bool isFirstClass() const;
174 * Is this a function-LIKE type?
176 * Anything function-like except arrays (e.g., datatype selectors) is
177 * considered a function here. Function-like terms can not be the argument
178 * or return value for any term that is function-like.
179 * This is mainly to avoid higher order.
181 * Note that arrays are explicitly not considered function-like here.
183 * @return true if this is a function-like type
185 bool isFunctionLike() const;
188 * Construct and return a ground term for this Type. Throws an
189 * exception if this type is not well-founded.
191 Expr
mkGroundTerm() const;
194 * Construct and return a ground value for this Type. Throws an
195 * exception if this type is not well-founded.
197 * This is the same as mkGroundTerm, but constructs a constant value instead
198 * of a canonical ground term. These two notions typically coincide. However,
199 * for uninterpreted sorts, they do not: mkGroundTerm returns a fresh variable
200 * whereas mkValue returns an uninterpreted constant. The motivation for
201 * mkGroundTerm is that unintepreted constants should never appear in lemmas.
202 * The motivation for mkGroundValue is for e.g. type enumeration and model
205 Expr
mkGroundValue() const;
208 * Is this type a subtype of the given type?
210 bool isSubtypeOf(Type t
) const;
213 * Is this type comparable to the given type (i.e., do they share
214 * a common ancestor in the subtype tree)?
216 bool isComparableTo(Type t
) const;
219 * Get the most general base type of this type.
221 Type
getBaseType() const;
224 * Substitution of Types.
226 Type
substitute(const Type
& type
, const Type
& replacement
) const;
229 * Simultaneous substitution of Types.
231 Type
substitute(const std::vector
<Type
>& types
,
232 const std::vector
<Type
>& replacements
) const;
235 * Get this type's ExprManager.
237 ExprManager
* getExprManager() const;
240 * Exports this type into a different ExprManager.
242 Type
exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& vmap
) const;
245 * Assignment operator.
246 * @param t the type to assign to this type
247 * @return this type after assignment.
249 Type
& operator=(const Type
& t
);
252 * Comparison for structural equality.
253 * @param t the type to compare to
254 * @returns true if the types are equal
256 bool operator==(const Type
& t
) const;
259 * Comparison for structural disequality.
260 * @param t the type to compare to
261 * @returns true if the types are not equal
263 bool operator!=(const Type
& t
) const;
266 * An ordering on Types so they can be stored in maps, etc.
268 bool operator<(const Type
& t
) const;
271 * An ordering on Types so they can be stored in maps, etc.
273 bool operator<=(const Type
& t
) const;
276 * An ordering on Types so they can be stored in maps, etc.
278 bool operator>(const Type
& t
) const;
281 * An ordering on Types so they can be stored in maps, etc.
283 bool operator>=(const Type
& t
) const;
286 * Is this the Boolean type?
287 * @return true if the type is a Boolean type
289 bool isBoolean() const;
292 * Is this the integer type?
293 * @return true if the type is a integer type
295 bool isInteger() const;
298 * Is this the real type?
299 * @return true if the type is a real type
304 * Is this the string type?
305 * @return true if the type is the string type
307 bool isString() const;
310 * Is this the regexp type?
311 * @return true if the type is the regexp type
313 bool isRegExp() const;
316 * Is this the rounding mode type?
317 * @return true if the type is the rounding mode type
319 bool isRoundingMode() const;
322 * Is this the bit-vector type?
323 * @return true if the type is a bit-vector type
325 bool isBitVector() const;
328 * Is this the floating-point type?
329 * @return true if the type is a floating-point type
331 bool isFloatingPoint() const;
334 * Is this a function type?
335 * @return true if the type is a function type
337 bool isFunction() const;
340 * Is this a predicate type, i.e. if it's a function type mapping to Boolean.
341 * All predicate types are also function types.
342 * @return true if the type is a predicate type
344 bool isPredicate() const;
347 * Is this a tuple type?
348 * @return true if the type is a tuple type
350 bool isTuple() const;
353 * Is this a record type?
354 * @return true if the type is a record type
356 bool isRecord() const;
359 * Is this a symbolic expression type?
360 * @return true if the type is a symbolic expression type
362 bool isSExpr() const;
365 * Is this an array type?
366 * @return true if the type is a array type
368 bool isArray() const;
371 * Is this a Set type?
372 * @return true if the type is a Set type
377 * Is this a Sequence type?
378 * @return true if the type is a Sequence type
380 bool isSequence() const;
383 * Is this a datatype type?
384 * @return true if the type is a datatype type
386 bool isDatatype() const;
389 * Is this a constructor type?
390 * @return true if the type is a constructor type
392 bool isConstructor() const;
395 * Is this a selector type?
396 * @return true if the type is a selector type
398 bool isSelector() const;
401 * Is this a tester type?
402 * @return true if the type is a tester type
404 bool isTester() const;
407 * Is this a sort kind?
408 * @return true if this is a sort kind
413 * Is this a sort constructor kind?
414 * @return true if this is a sort constructor kind
416 bool isSortConstructor() const;
419 * Is this a predicate subtype?
420 * @return true if this is a predicate subtype
422 // not in release 1.0
423 //bool isPredicateSubtype() const;
426 * Is this an integer subrange type?
427 * @return true if this is an integer subrange type
429 //bool isSubrange() const;
432 * Outputs a string representation of this type to the stream.
433 * @param out the stream to output to
435 void toStream(std::ostream
& out
) const;
438 * Constructs a string representation of this type.
440 std::string
toString() const;
443 /** Singleton class encapsulating the Boolean type. */
444 class CVC4_PUBLIC BooleanType
: public Type
{
446 /** Construct from the base type */
447 BooleanType(const Type
& type
= Type());
448 };/* class BooleanType */
450 /** Singleton class encapsulating the integer type. */
451 class CVC4_PUBLIC IntegerType
: public Type
{
453 /** Construct from the base type */
454 IntegerType(const Type
& type
= Type());
455 };/* class IntegerType */
457 /** Singleton class encapsulating the real type. */
458 class CVC4_PUBLIC RealType
: public Type
{
460 /** Construct from the base type */
461 RealType(const Type
& type
= Type());
462 };/* class RealType */
464 /** Singleton class encapsulating the string type. */
465 class CVC4_PUBLIC StringType
: public Type
{
467 /** Construct from the base type */
468 StringType(const Type
& type
);
469 };/* class StringType */
471 /** Singleton class encapsulating the string type. */
472 class CVC4_PUBLIC RegExpType
: public Type
{
474 /** Construct from the base type */
475 RegExpType(const Type
& type
);
476 };/* class RegExpType */
478 /** Singleton class encapsulating the rounding mode type. */
479 class CVC4_PUBLIC RoundingModeType
: public Type
{
481 /** Construct from the base type */
482 RoundingModeType(const Type
& type
= Type());
483 };/* class RoundingModeType */
485 /** Class encapsulating a function type. */
486 class CVC4_PUBLIC FunctionType
: public Type
{
488 /** Construct from the base type */
489 FunctionType(const Type
& type
= Type());
491 /** Get the arity of the function type */
492 size_t getArity() const;
494 /** Get the argument types */
495 std::vector
<Type
> getArgTypes() const;
497 /** Get the range type (i.e., the type of the result). */
498 Type
getRangeType() const;
499 };/* class FunctionType */
501 /** Class encapsulating a sexpr type. */
502 class CVC4_PUBLIC SExprType
: public Type
{
504 /** Construct from the base type */
505 SExprType(const Type
& type
= Type());
507 /** Get the constituent types */
508 std::vector
<Type
> getTypes() const;
509 };/* class SExprType */
511 /** Class encapsulating an array type. */
512 class CVC4_PUBLIC ArrayType
: public Type
{
514 /** Construct from the base type */
515 ArrayType(const Type
& type
= Type());
517 /** Get the index type */
518 Type
getIndexType() const;
520 /** Get the constituent type */
521 Type
getConstituentType() const;
522 };/* class ArrayType */
524 /** Class encapsulating a set type. */
525 class CVC4_PUBLIC SetType
: public Type
{
527 /** Construct from the base type */
528 SetType(const Type
& type
= Type());
530 /** Get the element type */
531 Type
getElementType() const;
532 }; /* class SetType */
534 /** Class encapsulating a sequence type. */
535 class CVC4_PUBLIC SequenceType
: public Type
538 /** Construct from the base type */
539 SequenceType(const Type
& type
= Type());
541 /** Get the element type */
542 Type
getElementType() const;
543 }; /* class SetType */
545 /** Class encapsulating a user-defined sort. */
546 class CVC4_PUBLIC SortType
: public Type
{
548 /** Construct from the base type */
549 SortType(const Type
& type
= Type());
551 /** Get the name of the sort */
552 std::string
getName() const;
554 /** Is this type parameterized? */
555 bool isParameterized() const;
557 /** Get the parameter types */
558 std::vector
<Type
> getParamTypes() const;
560 };/* class SortType */
562 /** Class encapsulating a user-defined sort constructor. */
563 class CVC4_PUBLIC SortConstructorType
: public Type
{
565 /** Construct from the base type */
566 SortConstructorType(const Type
& type
= Type());
568 /** Get the name of the sort constructor */
569 std::string
getName() const;
571 /** Get the arity of the sort constructor */
572 size_t getArity() const;
574 /** Instantiate a sort using this sort constructor */
575 SortType
instantiate(const std::vector
<Type
>& params
) const;
577 };/* class SortConstructorType */
579 /** Class encapsulating the bit-vector type. */
580 class CVC4_PUBLIC BitVectorType
: public Type
{
582 /** Construct from the base type */
583 BitVectorType(const Type
& type
= Type());
586 * Returns the size of the bit-vector type.
587 * @return the width of the bit-vector type (> 0)
589 unsigned getSize() const;
591 };/* class BitVectorType */
593 /** Class encapsulating the floating point type. */
594 class CVC4_PUBLIC FloatingPointType
: public Type
{
596 /** Construct from the base type */
597 FloatingPointType(const Type
& type
= Type());
600 * Returns the size of the floating-point exponent type.
601 * @return the width of the floating-point exponent type (> 0)
603 unsigned getExponentSize() const;
606 * Returns the size of the floating-point significand type.
607 * @return the width of the floating-point significand type (> 0)
609 unsigned getSignificandSize() const;
611 };/* class FloatingPointType */
613 /** Class encapsulating the datatype type */
614 class CVC4_PUBLIC DatatypeType
: public Type
{
616 /** Construct from the base type */
617 DatatypeType(const Type
& type
= Type());
619 /** Get the underlying datatype */
620 const Datatype
& getDatatype() const;
622 /** Is this datatype parametric? */
623 bool isParametric() const;
625 * Has this datatype been fully instantiated ?
627 * @return true if this datatype is not parametric or, if it is, it
628 * has been fully instantiated
630 bool isInstantiated() const;
632 /** Has this datatype been instantiated for parameter `n` ? */
633 bool isParameterInstantiated(unsigned n
) const;
635 /** Get the parameter types */
636 std::vector
<Type
> getParamTypes() const;
638 /** Get the arity of the datatype constructor */
639 size_t getArity() const;
641 /** Instantiate a datatype using this datatype constructor */
642 DatatypeType
instantiate(const std::vector
<Type
>& params
) const;
644 /** Get the length of a tuple type */
645 size_t getTupleLength() const;
647 /** Get the constituent types of a tuple type */
648 std::vector
<Type
> getTupleTypes() const;
650 };/* class DatatypeType */
652 /** Class encapsulating the constructor type. */
653 class CVC4_PUBLIC ConstructorType
: public Type
{
655 /** Construct from the base type */
656 ConstructorType(const Type
& type
= Type());
658 /** Get the range type */
659 DatatypeType
getRangeType() const;
661 /** Get the argument types */
662 std::vector
<Type
> getArgTypes() const;
664 /** Get the number of constructor arguments */
665 size_t getArity() const;
667 };/* class ConstructorType */
669 /** Class encapsulating the Selector type. */
670 class CVC4_PUBLIC SelectorType
: public Type
{
672 /** Construct from the base type */
673 SelectorType(const Type
& type
= Type());
675 /** Get the domain type for this selector (the datatype type) */
676 DatatypeType
getDomain() const;
678 /** Get the range type for this selector (the field type) */
679 Type
getRangeType() const;
681 };/* class SelectorType */
683 /** Class encapsulating the Tester type. */
684 class CVC4_PUBLIC TesterType
: public Type
{
686 /** Construct from the base type */
687 TesterType(const Type
& type
= Type());
689 /** Get the type that this tester tests (the datatype type) */
690 DatatypeType
getDomain() const;
693 * Get the range type for this tester (included for sake of
694 * interface completeness), but doesn't give useful information).
696 BooleanType
getRangeType() const;
698 };/* class TesterType */
700 }/* CVC4 namespace */
702 #endif /* CVC4__TYPE_H */