1 /********************* */
4 ** Original author: cconway
5 ** Major contributors: dejan, mdeters
6 ** Minor contributors (to current version): ajreynol
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009-2012 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
>
53 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 bit-vector type?
262 * @return true if the type is a bit-vector type
264 bool isBitVector() const;
267 * Is this a function type?
268 * @return true if the type is a function type
270 bool isFunction() const;
273 * Is this a predicate type, i.e. if it's a function type mapping to Boolean.
274 * All predicate types are also function types.
275 * @return true if the type is a predicate type
277 bool isPredicate() const;
280 * Is this a tuple type?
281 * @return true if the type is a tuple type
283 bool isTuple() const;
286 * Is this a record type?
287 * @return true if the type is a record type
289 bool isRecord() const;
292 * Is this a symbolic expression type?
293 * @return true if the type is a symbolic expression type
295 bool isSExpr() const;
298 * Is this an array type?
299 * @return true if the type is a array type
301 bool isArray() const;
304 * Is this a datatype type?
305 * @return true if the type is a datatype type
307 bool isDatatype() const;
310 * Is this a constructor type?
311 * @return true if the type is a constructor type
313 bool isConstructor() const;
316 * Is this a selector type?
317 * @return true if the type is a selector type
319 bool isSelector() const;
322 * Is this a tester type?
323 * @return true if the type is a tester type
325 bool isTester() const;
328 * Is this a sort kind?
329 * @return true if this is a sort kind
334 * Is this a sort constructor kind?
335 * @return true if this is a sort constructor kind
337 bool isSortConstructor() const;
340 * Is this a predicate subtype?
341 * @return true if this is a predicate subtype
343 // not in release 1.0
344 //bool isPredicateSubtype() const;
347 * Is this an integer subrange type?
348 * @return true if this is an integer subrange type
350 bool isSubrange() const;
353 * Outputs a string representation of this type to the stream.
354 * @param out the stream to output to
356 void toStream(std::ostream
& out
) const;
359 * Constructs a string representation of this type.
361 std::string
toString() const;
365 * Singleton class encapsulating the Boolean type.
367 class CVC4_PUBLIC BooleanType
: public Type
{
371 /** Construct from the base type */
372 BooleanType(const Type
& type
= Type()) throw(IllegalArgumentException
);
373 };/* class BooleanType */
376 * Singleton class encapsulating the integer type.
378 class CVC4_PUBLIC IntegerType
: public Type
{
382 /** Construct from the base type */
383 IntegerType(const Type
& type
= Type()) throw(IllegalArgumentException
);
384 };/* class IntegerType */
387 * Singleton class encapsulating the real type.
389 class CVC4_PUBLIC RealType
: public Type
{
393 /** Construct from the base type */
394 RealType(const Type
& type
= Type()) throw(IllegalArgumentException
);
395 };/* class RealType */
398 * Singleton class encapsulating the string type.
400 class CVC4_PUBLIC StringType
: public Type
{
404 /** Construct from the base type */
405 StringType(const Type
& type
) throw(IllegalArgumentException
);
406 };/* class StringType */
409 * Class encapsulating a function type.
411 class CVC4_PUBLIC FunctionType
: public Type
{
415 /** Construct from the base type */
416 FunctionType(const Type
& type
= Type()) throw(IllegalArgumentException
);
418 /** Get the argument types */
419 std::vector
<Type
> getArgTypes() const;
421 /** Get the range type (i.e., the type of the result). */
422 Type
getRangeType() const;
423 };/* class FunctionType */
426 * Class encapsulating a tuple type.
428 class CVC4_PUBLIC TupleType
: public Type
{
432 /** Construct from the base type */
433 TupleType(const Type
& type
= Type()) throw(IllegalArgumentException
);
435 /** Get the length of the tuple. The same as getTypes().size(). */
436 size_t getLength() const;
438 /** Get the constituent types */
439 std::vector
<Type
> getTypes() const;
441 };/* class TupleType */
444 * Class encapsulating a record type.
446 class CVC4_PUBLIC RecordType
: public Type
{
450 /** Construct from the base type */
451 RecordType(const Type
& type
= Type()) throw(IllegalArgumentException
);
453 /** Get the constituent types */
454 const Record
& getRecord() const;
455 };/* class RecordType */
458 * Class encapsulating a tuple type.
460 class CVC4_PUBLIC SExprType
: public Type
{
464 /** Construct from the base type */
465 SExprType(const Type
& type
= Type()) throw(IllegalArgumentException
);
467 /** Get the constituent types */
468 std::vector
<Type
> getTypes() const;
469 };/* class SExprType */
472 * Class encapsulating an array type.
474 class CVC4_PUBLIC ArrayType
: public Type
{
478 /** Construct from the base type */
479 ArrayType(const Type
& type
= Type()) throw(IllegalArgumentException
);
481 /** Get the index type */
482 Type
getIndexType() const;
484 /** Get the constituent type */
485 Type
getConstituentType() const;
486 };/* class ArrayType */
489 * Class encapsulating a user-defined sort.
491 class CVC4_PUBLIC SortType
: public Type
{
495 /** Construct from the base type */
496 SortType(const Type
& type
= Type()) throw(IllegalArgumentException
);
498 /** Get the name of the sort */
499 std::string
getName() const;
501 /** Is this type parameterized? */
502 bool isParameterized() const;
504 /** Get the parameter types */
505 std::vector
<Type
> getParamTypes() const;
507 };/* class SortType */
510 * Class encapsulating a user-defined sort constructor.
512 class CVC4_PUBLIC SortConstructorType
: public Type
{
516 /** Construct from the base type */
517 SortConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
519 /** Get the name of the sort constructor */
520 std::string
getName() const;
522 /** Get the arity of the sort constructor */
523 size_t getArity() const;
525 /** Instantiate a sort using this sort constructor */
526 SortType
instantiate(const std::vector
<Type
>& params
) const;
528 };/* class SortConstructorType */
530 // not in release 1.0
533 * Class encapsulating a predicate subtype.
535 class CVC4_PUBLIC PredicateSubtype
: public Type
{
539 /** Construct from the base type */
540 PredicateSubtype(const Type
& type
= Type()) throw(IllegalArgumentException
);
542 /** Get the LAMBDA defining this predicate subtype */
543 Expr
getPredicate() const;
546 * Get the parent type of this predicate subtype; note that this
547 * could be another predicate subtype.
549 Type
getParentType() const;
551 };/* class PredicateSubtype */
555 * Class encapsulating an integer subrange type.
557 class CVC4_PUBLIC SubrangeType
: public Type
{
561 /** Construct from the base type */
562 SubrangeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
564 /** Get the bounds defining this integer subrange */
565 SubrangeBounds
getSubrangeBounds() const;
567 };/* class SubrangeType */
570 * Class encapsulating the bit-vector type.
572 class CVC4_PUBLIC BitVectorType
: public Type
{
576 /** Construct from the base type */
577 BitVectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
580 * Returns the size of the bit-vector type.
581 * @return the width of the bit-vector type (> 0)
583 unsigned getSize() const;
585 };/* class BitVectorType */
589 * Class encapsulating the datatype type
591 class CVC4_PUBLIC DatatypeType
: public Type
{
595 /** Construct from the base type */
596 DatatypeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
598 /** Get the underlying datatype */
599 const Datatype
& getDatatype() const;
601 /** Is this datatype parametric? */
602 bool isParametric() const;
605 * Get the constructor operator associated to the given constructor
606 * name in this datatype.
608 Expr
getConstructor(std::string name
) const;
611 * Has this datatype been fully instantiated ?
613 * @return true if this datatype is not parametric or, if it is, it
614 * has been fully instantiated
616 bool isInstantiated() const;
619 * Has this datatype been instantiated for parameter N ?
621 bool isParameterInstantiated(unsigned n
) const;
623 /** Get the parameter types */
624 std::vector
<Type
> getParamTypes() const;
626 /** Get the arity of the datatype constructor */
627 size_t getArity() const;
629 /** Instantiate a datatype using this datatype constructor */
630 DatatypeType
instantiate(const std::vector
<Type
>& params
) const;
632 };/* class DatatypeType */
635 * Class encapsulating the constructor type
637 class CVC4_PUBLIC ConstructorType
: public Type
{
641 /** Construct from the base type */
642 ConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
644 /** Get the range type */
645 DatatypeType
getRangeType() const;
647 /** Get the argument types */
648 std::vector
<Type
> getArgTypes() const;
650 /** Get the number of constructor arguments */
651 size_t getArity() const;
653 };/* class ConstructorType */
657 * Class encapsulating the Selector type
659 class CVC4_PUBLIC SelectorType
: public Type
{
663 /** Construct from the base type */
664 SelectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
666 /** Get the domain type for this selector (the datatype type) */
667 DatatypeType
getDomain() const;
669 /** Get the range type for this selector (the field type) */
670 Type
getRangeType() const;
672 };/* class SelectorType */
675 * Class encapsulating the Tester type
677 class CVC4_PUBLIC TesterType
: public Type
{
681 /** Construct from the base type */
682 TesterType(const Type
& type
= Type()) throw(IllegalArgumentException
);
684 /** Get the type that this tester tests (the datatype type) */
685 DatatypeType
getDomain() const;
688 * Get the range type for this tester (included for sake of
689 * interface completeness), but doesn't give useful information).
691 BooleanType
getRangeType() const;
693 };/* class TesterType */
695 }/* CVC4 namespace */
697 #endif /* __CVC4__TYPE_H */