1 /********************* */
4 ** Top contributors (to current version):
5 ** Morgan Deters, Dejan Jovanovic, Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 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 datatype type?
378 * @return true if the type is a datatype type
380 bool isDatatype() const;
383 * Is this a constructor type?
384 * @return true if the type is a constructor type
386 bool isConstructor() const;
389 * Is this a selector type?
390 * @return true if the type is a selector type
392 bool isSelector() const;
395 * Is this a tester type?
396 * @return true if the type is a tester type
398 bool isTester() const;
401 * Is this a sort kind?
402 * @return true if this is a sort kind
407 * Is this a sort constructor kind?
408 * @return true if this is a sort constructor kind
410 bool isSortConstructor() const;
413 * Is this a predicate subtype?
414 * @return true if this is a predicate subtype
416 // not in release 1.0
417 //bool isPredicateSubtype() const;
420 * Is this an integer subrange type?
421 * @return true if this is an integer subrange type
423 //bool isSubrange() const;
426 * Outputs a string representation of this type to the stream.
427 * @param out the stream to output to
429 void toStream(std::ostream
& out
) const;
432 * Constructs a string representation of this type.
434 std::string
toString() const;
437 /** Singleton class encapsulating the Boolean type. */
438 class CVC4_PUBLIC BooleanType
: public Type
{
440 /** Construct from the base type */
441 BooleanType(const Type
& type
= Type());
442 };/* class BooleanType */
444 /** Singleton class encapsulating the integer type. */
445 class CVC4_PUBLIC IntegerType
: public Type
{
447 /** Construct from the base type */
448 IntegerType(const Type
& type
= Type());
449 };/* class IntegerType */
451 /** Singleton class encapsulating the real type. */
452 class CVC4_PUBLIC RealType
: public Type
{
454 /** Construct from the base type */
455 RealType(const Type
& type
= Type());
456 };/* class RealType */
458 /** Singleton class encapsulating the string type. */
459 class CVC4_PUBLIC StringType
: public Type
{
461 /** Construct from the base type */
462 StringType(const Type
& type
);
463 };/* class StringType */
465 /** Singleton class encapsulating the string type. */
466 class CVC4_PUBLIC RegExpType
: public Type
{
468 /** Construct from the base type */
469 RegExpType(const Type
& type
);
470 };/* class RegExpType */
472 /** Singleton class encapsulating the rounding mode type. */
473 class CVC4_PUBLIC RoundingModeType
: public Type
{
475 /** Construct from the base type */
476 RoundingModeType(const Type
& type
= Type());
477 };/* class RoundingModeType */
479 /** Class encapsulating a function type. */
480 class CVC4_PUBLIC FunctionType
: public Type
{
482 /** Construct from the base type */
483 FunctionType(const Type
& type
= Type());
485 /** Get the arity of the function type */
486 size_t getArity() const;
488 /** Get the argument types */
489 std::vector
<Type
> getArgTypes() const;
491 /** Get the range type (i.e., the type of the result). */
492 Type
getRangeType() const;
493 };/* class FunctionType */
495 /** Class encapsulating a sexpr type. */
496 class CVC4_PUBLIC SExprType
: public Type
{
498 /** Construct from the base type */
499 SExprType(const Type
& type
= Type());
501 /** Get the constituent types */
502 std::vector
<Type
> getTypes() const;
503 };/* class SExprType */
505 /** Class encapsulating an array type. */
506 class CVC4_PUBLIC ArrayType
: public Type
{
508 /** Construct from the base type */
509 ArrayType(const Type
& type
= Type());
511 /** Get the index type */
512 Type
getIndexType() const;
514 /** Get the constituent type */
515 Type
getConstituentType() const;
516 };/* class ArrayType */
518 /** Class encapsulating an set type. */
519 class CVC4_PUBLIC SetType
: public Type
{
521 /** Construct from the base type */
522 SetType(const Type
& type
= Type());
524 /** Get the index type */
525 Type
getElementType() const;
526 };/* class SetType */
528 /** Class encapsulating a user-defined sort. */
529 class CVC4_PUBLIC SortType
: public Type
{
531 /** Construct from the base type */
532 SortType(const Type
& type
= Type());
534 /** Get the name of the sort */
535 std::string
getName() const;
537 /** Is this type parameterized? */
538 bool isParameterized() const;
540 /** Get the parameter types */
541 std::vector
<Type
> getParamTypes() const;
543 };/* class SortType */
545 /** Class encapsulating a user-defined sort constructor. */
546 class CVC4_PUBLIC SortConstructorType
: public Type
{
548 /** Construct from the base type */
549 SortConstructorType(const Type
& type
= Type());
551 /** Get the name of the sort constructor */
552 std::string
getName() const;
554 /** Get the arity of the sort constructor */
555 size_t getArity() const;
557 /** Instantiate a sort using this sort constructor */
558 SortType
instantiate(const std::vector
<Type
>& params
) const;
560 };/* class SortConstructorType */
562 /** Class encapsulating the bit-vector type. */
563 class CVC4_PUBLIC BitVectorType
: public Type
{
565 /** Construct from the base type */
566 BitVectorType(const Type
& type
= Type());
569 * Returns the size of the bit-vector type.
570 * @return the width of the bit-vector type (> 0)
572 unsigned getSize() const;
574 };/* class BitVectorType */
576 /** Class encapsulating the floating point type. */
577 class CVC4_PUBLIC FloatingPointType
: public Type
{
579 /** Construct from the base type */
580 FloatingPointType(const Type
& type
= Type());
583 * Returns the size of the floating-point exponent type.
584 * @return the width of the floating-point exponent type (> 0)
586 unsigned getExponentSize() const;
589 * Returns the size of the floating-point significand type.
590 * @return the width of the floating-point significand type (> 0)
592 unsigned getSignificandSize() const;
594 };/* class FloatingPointType */
596 /** Class encapsulating the datatype type */
597 class CVC4_PUBLIC DatatypeType
: public Type
{
599 /** Construct from the base type */
600 DatatypeType(const Type
& type
= Type());
602 /** Get the underlying datatype */
603 const Datatype
& getDatatype() const;
605 /** Is this datatype parametric? */
606 bool isParametric() const;
609 * Get the constructor operator associated to the given constructor
610 * name in this datatype.
612 Expr
getConstructor(std::string name
) const;
615 * Has this datatype been fully instantiated ?
617 * @return true if this datatype is not parametric or, if it is, it
618 * has been fully instantiated
620 bool isInstantiated() const;
622 /** Has this datatype been instantiated for parameter `n` ? */
623 bool isParameterInstantiated(unsigned n
) const;
625 /** Get the parameter types */
626 std::vector
<Type
> getParamTypes() const;
628 /** Get the arity of the datatype constructor */
629 size_t getArity() const;
631 /** Instantiate a datatype using this datatype constructor */
632 DatatypeType
instantiate(const std::vector
<Type
>& params
) const;
634 /** Get the length of a tuple type */
635 size_t getTupleLength() const;
637 /** Get the constituent types of a tuple type */
638 std::vector
<Type
> getTupleTypes() const;
640 /** Get the description of the record type */
641 const Record
& getRecord() const;
643 };/* class DatatypeType */
645 /** Class encapsulating the constructor type. */
646 class CVC4_PUBLIC ConstructorType
: public Type
{
648 /** Construct from the base type */
649 ConstructorType(const Type
& type
= Type());
651 /** Get the range type */
652 DatatypeType
getRangeType() const;
654 /** Get the argument types */
655 std::vector
<Type
> getArgTypes() const;
657 /** Get the number of constructor arguments */
658 size_t getArity() const;
660 };/* class ConstructorType */
662 /** Class encapsulating the Selector type. */
663 class CVC4_PUBLIC SelectorType
: public Type
{
665 /** Construct from the base type */
666 SelectorType(const Type
& type
= Type());
668 /** Get the domain type for this selector (the datatype type) */
669 DatatypeType
getDomain() const;
671 /** Get the range type for this selector (the field type) */
672 Type
getRangeType() const;
674 };/* class SelectorType */
676 /** Class encapsulating the Tester type. */
677 class CVC4_PUBLIC TesterType
: public Type
{
679 /** Construct from the base type */
680 TesterType(const Type
& type
= Type());
682 /** Get the type that this tester tests (the datatype type) */
683 DatatypeType
getDomain() const;
686 * Get the range type for this tester (included for sake of
687 * interface completeness), but doesn't give useful information).
689 BooleanType
getRangeType() const;
691 };/* class TesterType */
693 }/* CVC4 namespace */
695 #endif /* CVC4__TYPE_H */