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"
36 class ExprManagerMapCollection
;
42 template <bool ref_count
>
52 class ConstructorType
;
59 class SortConstructorType
;
61 //class PredicateSubtype;
65 /** Hash function for Types */
66 struct CVC4_PUBLIC TypeHashFunction
{
67 /** Return a hash code for type t */
68 size_t operator()(const CVC4::Type
& t
) const;
69 };/* struct TypeHashFunction */
72 * Output operator for types
73 * @param out the stream to output to
74 * @param t the type to output
77 std::ostream
& operator<<(std::ostream
& out
, const Type
& t
) CVC4_PUBLIC
;
80 TypeNode
exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
81 }/* CVC4::expr namespace */
84 * Class encapsulating CVC4 expression types.
86 class CVC4_PUBLIC Type
{
88 friend class SmtEngine
;
89 friend class ExprManager
;
90 friend class NodeManager
;
91 friend class TypeNode
;
92 friend std::ostream
& CVC4::operator<<(std::ostream
& out
, const Type
& t
);
93 friend TypeNode
expr::exportTypeInternal(TypeNode n
, NodeManager
* from
, NodeManager
* nm
, ExprManagerMapCollection
& vmap
);
97 /** The internal expression representation */
100 /** The responsible expression manager */
101 NodeManager
* d_nodeManager
;
104 * Construct a new type given the typeNode, for internal use only.
105 * @param typeNode the TypeNode to use
106 * @return the Type corresponding to the TypeNode
108 Type
makeType(const TypeNode
& typeNode
) const;
111 * Constructor for internal purposes.
112 * @param em the expression manager that handles this expression
113 * @param typeNode the actual TypeNode pointer for this type
115 Type(NodeManager
* em
, TypeNode
* typeNode
);
117 /** Accessor for derived classes */
118 static TypeNode
* getTypeNode(const Type
& t
) throw() { return t
.d_typeNode
; }
122 /** Force a virtual destructor for safety. */
125 /** Default constructor */
130 * @param t the type to make a copy of
135 * Check whether this is a null type
136 * @return true if type is null
141 * Return the cardinality of this type.
143 Cardinality
getCardinality() const;
146 * Is this a well-founded type?
148 bool isWellFounded() const;
151 * Construct and return a ground term for this Type. Throws an
152 * exception if this type is not well-founded.
154 Expr
mkGroundTerm() const;
157 * Is this type a subtype of the given type?
159 bool isSubtypeOf(Type t
) const;
162 * Is this type comparable to the given type (i.e., do they share
163 * a common ancestor in the subtype tree)?
165 bool isComparableTo(Type t
) const;
168 * Get the most general base type of this type.
170 Type
getBaseType() const;
173 * Substitution of Types.
175 Type
substitute(const Type
& type
, const Type
& replacement
) const;
178 * Simultaneous substitution of Types.
180 Type
substitute(const std::vector
<Type
>& types
,
181 const std::vector
<Type
>& replacements
) const;
184 * Get this type's ExprManager.
186 ExprManager
* getExprManager() const;
189 * Exports this type into a different ExprManager.
191 Type
exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& vmap
) const;
194 * Assignment operator.
195 * @param t the type to assign to this type
196 * @return this type after assignment.
198 Type
& operator=(const Type
& t
);
201 * Comparison for structural equality.
202 * @param t the type to compare to
203 * @returns true if the types are equal
205 bool operator==(const Type
& t
) const;
208 * Comparison for structural disequality.
209 * @param t the type to compare to
210 * @returns true if the types are not equal
212 bool operator!=(const Type
& t
) const;
215 * An ordering on Types so they can be stored in maps, etc.
217 bool operator<(const Type
& t
) const;
220 * An ordering on Types so they can be stored in maps, etc.
222 bool operator<=(const Type
& t
) const;
225 * An ordering on Types so they can be stored in maps, etc.
227 bool operator>(const Type
& t
) const;
230 * An ordering on Types so they can be stored in maps, etc.
232 bool operator>=(const Type
& t
) const;
235 * Is this the Boolean type?
236 * @return true if the type is a Boolean type
238 bool isBoolean() const;
241 * Cast this type to a Boolean type
242 * @return the BooleanType
244 operator BooleanType() const throw(IllegalArgumentException
);
247 * Is this the integer type?
248 * @return true if the type is a integer type
250 bool isInteger() const;
253 * Cast this type to a integer type
254 * @return the IntegerType
256 operator IntegerType() const throw(IllegalArgumentException
);
259 * Is this the real type?
260 * @return true if the type is a real type
265 * Cast this type to a real type
266 * @return the RealType
268 operator RealType() const throw(IllegalArgumentException
);
271 * Is this the string type?
272 * @return true if the type is the string type
274 bool isString() const;
277 * Cast this type to a string type
278 * @return the StringType
280 operator StringType() const throw(IllegalArgumentException
);
283 * Is this the bit-vector type?
284 * @return true if the type is a bit-vector type
286 bool isBitVector() const;
289 * Cast this type to a bit-vector type
290 * @return the BitVectorType
292 operator BitVectorType() const throw(IllegalArgumentException
);
295 * Is this a function type?
296 * @return true if the type is a function type
298 bool isFunction() const;
301 * Is this a predicate type, i.e. if it's a function type mapping to Boolean.
302 * All predicate types are also function types.
303 * @return true if the type is a predicate type
305 bool isPredicate() const;
308 * Cast this type to a function type
309 * @return the FunctionType
311 operator FunctionType() const throw(IllegalArgumentException
);
314 * Is this a tuple type?
315 * @return true if the type is a tuple type
317 bool isTuple() const;
320 * Cast this type to a tuple type
321 * @return the TupleType
323 operator TupleType() const throw(IllegalArgumentException
);
326 * Is this a symbolic expression type?
327 * @return true if the type is a symbolic expression type
329 bool isSExpr() const;
332 * Cast this type to a symbolic expression type
333 * @return the SExprType
335 operator SExprType() const throw(IllegalArgumentException
);
338 * Is this an array type?
339 * @return true if the type is a array type
341 bool isArray() const;
344 * Cast this type to an array type
345 * @return the ArrayType
347 operator ArrayType() const throw(IllegalArgumentException
);
350 * Is this a datatype type?
351 * @return true if the type is a datatype type
353 bool isDatatype() const;
356 * Cast this type to a datatype type
357 * @return the DatatypeType
359 operator DatatypeType() const throw(IllegalArgumentException
);
362 * Is this a constructor type?
363 * @return true if the type is a constructor type
365 bool isConstructor() const;
368 * Cast this type to a constructor type
369 * @return the ConstructorType
371 operator ConstructorType() const throw(IllegalArgumentException
);
374 * Is this a selector type?
375 * @return true if the type is a selector type
377 bool isSelector() const;
380 * Cast this type to a selector type
381 * @return the SelectorType
383 operator SelectorType() const throw(IllegalArgumentException
);
386 * Is this a tester type?
387 * @return true if the type is a tester type
389 bool isTester() const;
392 * Cast this type to a tester type
393 * @return the TesterType
395 operator TesterType() const throw(IllegalArgumentException
);
398 * Is this a sort kind?
399 * @return true if this is a sort kind
404 * Cast this type to a sort type
405 * @return the sort type
407 operator SortType() const throw(IllegalArgumentException
);
410 * Is this a sort constructor kind?
411 * @return true if this is a sort constructor kind
413 bool isSortConstructor() const;
416 * Cast this type to a sort constructor type
417 * @return the sort constructor type
419 operator SortConstructorType() const throw(IllegalArgumentException
);
422 * Is this a predicate subtype?
423 * @return true if this is a predicate subtype
425 // not in release 1.0
426 //bool isPredicateSubtype() const;
429 * Cast this type to a predicate subtype
430 * @return the predicate subtype
432 // not in release 1.0
433 //operator PredicateSubtype() const throw(IllegalArgumentException);
436 * Is this an integer subrange type?
437 * @return true if this is an integer subrange type
439 bool isSubrange() const;
442 * Cast this type to an integer subrange type
443 * @return the integer subrange type
445 operator SubrangeType() const throw(IllegalArgumentException
);
448 * Outputs a string representation of this type to the stream.
449 * @param out the stream to output to
451 void toStream(std::ostream
& out
) const;
454 * Constructs a string representation of this type.
456 std::string
toString() const;
460 * Singleton class encapsulating the Boolean type.
462 class CVC4_PUBLIC BooleanType
: public Type
{
466 /** Construct from the base type */
467 BooleanType(const Type
& type
= Type()) throw(IllegalArgumentException
);
468 };/* class BooleanType */
471 * Singleton class encapsulating the integer type.
473 class CVC4_PUBLIC IntegerType
: public Type
{
477 /** Construct from the base type */
478 IntegerType(const Type
& type
= Type()) throw(IllegalArgumentException
);
479 };/* class IntegerType */
482 * Singleton class encapsulating the real type.
484 class CVC4_PUBLIC RealType
: public Type
{
488 /** Construct from the base type */
489 RealType(const Type
& type
= Type()) throw(IllegalArgumentException
);
490 };/* class RealType */
493 * Singleton class encapsulating the string type.
495 class CVC4_PUBLIC StringType
: public Type
{
499 /** Construct from the base type */
500 StringType(const Type
& type
) throw(IllegalArgumentException
);
501 };/* class StringType */
504 * Class encapsulating a function type.
506 class CVC4_PUBLIC FunctionType
: public Type
{
510 /** Construct from the base type */
511 FunctionType(const Type
& type
= Type()) throw(IllegalArgumentException
);
513 /** Get the argument types */
514 std::vector
<Type
> getArgTypes() const;
516 /** Get the range type (i.e., the type of the result). */
517 Type
getRangeType() const;
518 };/* class FunctionType */
521 * Class encapsulating a tuple type.
523 class CVC4_PUBLIC TupleType
: public Type
{
527 /** Construct from the base type */
528 TupleType(const Type
& type
= Type()) throw(IllegalArgumentException
);
530 /** Get the constituent types */
531 std::vector
<Type
> getTypes() const;
532 };/* class TupleType */
535 * Class encapsulating a tuple type.
537 class CVC4_PUBLIC SExprType
: public Type
{
541 /** Construct from the base type */
542 SExprType(const Type
& type
= Type()) throw(IllegalArgumentException
);
544 /** Get the constituent types */
545 std::vector
<Type
> getTypes() const;
546 };/* class SExprType */
549 * Class encapsulating an array type.
551 class CVC4_PUBLIC ArrayType
: public Type
{
555 /** Construct from the base type */
556 ArrayType(const Type
& type
= Type()) throw(IllegalArgumentException
);
558 /** Get the index type */
559 Type
getIndexType() const;
561 /** Get the constituent type */
562 Type
getConstituentType() const;
563 };/* class ArrayType */
566 * Class encapsulating a user-defined sort.
568 class CVC4_PUBLIC SortType
: public Type
{
572 /** Construct from the base type */
573 SortType(const Type
& type
= Type()) throw(IllegalArgumentException
);
575 /** Get the name of the sort */
576 std::string
getName() const;
578 /** Is this type parameterized? */
579 bool isParameterized() const;
581 /** Get the parameter types */
582 std::vector
<Type
> getParamTypes() const;
584 };/* class SortType */
587 * Class encapsulating a user-defined sort constructor.
589 class CVC4_PUBLIC SortConstructorType
: public Type
{
593 /** Construct from the base type */
594 SortConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
596 /** Get the name of the sort constructor */
597 std::string
getName() const;
599 /** Get the arity of the sort constructor */
600 size_t getArity() const;
602 /** Instantiate a sort using this sort constructor */
603 SortType
instantiate(const std::vector
<Type
>& params
) const;
605 };/* class SortConstructorType */
607 // not in release 1.0
610 * Class encapsulating a predicate subtype.
612 class CVC4_PUBLIC PredicateSubtype
: public Type
{
616 /** Construct from the base type */
617 PredicateSubtype(const Type
& type
= Type()) throw(IllegalArgumentException
);
619 /** Get the LAMBDA defining this predicate subtype */
620 Expr
getPredicate() const;
623 * Get the parent type of this predicate subtype; note that this
624 * could be another predicate subtype.
626 Type
getParentType() const;
628 };/* class PredicateSubtype */
632 * Class encapsulating an integer subrange type.
634 class CVC4_PUBLIC SubrangeType
: public Type
{
638 /** Construct from the base type */
639 SubrangeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
641 /** Get the bounds defining this integer subrange */
642 SubrangeBounds
getSubrangeBounds() const;
644 };/* class SubrangeType */
647 * Class encapsulating the bit-vector type.
649 class CVC4_PUBLIC BitVectorType
: public Type
{
653 /** Construct from the base type */
654 BitVectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
657 * Returns the size of the bit-vector type.
658 * @return the width of the bit-vector type (> 0)
660 unsigned getSize() const;
662 };/* class BitVectorType */
666 * Class encapsulating the datatype type
668 class CVC4_PUBLIC DatatypeType
: public Type
{
672 /** Construct from the base type */
673 DatatypeType(const Type
& type
= Type()) throw(IllegalArgumentException
);
675 /** Get the underlying datatype */
676 const Datatype
& getDatatype() const;
678 /** Is this datatype parametric? */
679 bool isParametric() const;
682 * Get the constructor operator associated to the given constructor
683 * name in this datatype.
685 Expr
getConstructor(std::string name
) const;
688 * Has this datatype been fully instantiated ?
690 * @return true if this datatype is not parametric or, if it is, it
691 * has been fully instantiated
693 bool isInstantiated() const;
696 * Has this datatype been instantiated for parameter N ?
698 bool isParameterInstantiated(unsigned n
) const;
700 /** Get the parameter types */
701 std::vector
<Type
> getParamTypes() const;
703 /** Get the arity of the datatype constructor */
704 size_t getArity() const;
706 /** Instantiate a datatype using this datatype constructor */
707 DatatypeType
instantiate(const std::vector
<Type
>& params
) const;
709 };/* class DatatypeType */
712 * Class encapsulating the constructor type
714 class CVC4_PUBLIC ConstructorType
: public Type
{
718 /** Construct from the base type */
719 ConstructorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
721 /** Get the range type */
722 DatatypeType
getRangeType() const;
724 /** Get the argument types */
725 std::vector
<Type
> getArgTypes() const;
727 /** Get the number of constructor arguments */
728 size_t getArity() const;
730 };/* class ConstructorType */
734 * Class encapsulating the Selector type
736 class CVC4_PUBLIC SelectorType
: public Type
{
740 /** Construct from the base type */
741 SelectorType(const Type
& type
= Type()) throw(IllegalArgumentException
);
743 /** Get the domain type for this selector (the datatype type) */
744 DatatypeType
getDomain() const;
746 /** Get the range type for this selector (the field type) */
747 Type
getRangeType() const;
749 };/* class SelectorType */
752 * Class encapsulating the Tester type
754 class CVC4_PUBLIC TesterType
: public Type
{
758 /** Construct from the base type */
759 TesterType(const Type
& type
= Type()) throw(IllegalArgumentException
);
761 /** Get the type that this tester tests (the datatype type) */
762 DatatypeType
getDomain() const;
765 * Get the range type for this tester (included for sake of
766 * interface completeness), but doesn't give useful information).
768 BooleanType
getRangeType() const;
770 };/* class TesterType */
772 }/* CVC4 namespace */
774 #endif /* __CVC4__TYPE_H */