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, 2010, 2011 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
14 ** \brief Interface for expression types.
16 ** Interface for expression types
19 #include "cvc4_public.h"
21 #ifndef __CVC4__TYPE_H
22 #define __CVC4__TYPE_H
29 #include "util/Assert.h"
30 #include "util/cardinality.h"
43 template <bool ref_count
>
49 class PseudobooleanType
;
53 class ConstructorType
;
60 class SortConstructorType
;
63 /** Strategy for hashing Types */
64 struct CVC4_PUBLIC TypeHashFunction
{
65 /** Return a hash code for type t */
66 size_t operator()(const CVC4::Type
& t
) const;
67 };/* struct TypeHashFunction */
70 * Output operator for types
71 * @param out the stream to output to
72 * @param t the type to output
75 std::ostream
& operator<<(std::ostream
& out
, const Type
& t
) CVC4_PUBLIC
;
78 * Class encapsulating CVC4 expression types.
80 class CVC4_PUBLIC Type
{
82 friend class SmtEngine
;
83 friend class ExprManager
;
84 friend class NodeManager
;
85 friend class TypeNode
;
86 friend struct TypeHashStrategy
;
87 friend std::ostream
& CVC4::operator<<(std::ostream
& out
, const Type
& t
);
91 /** The internal expression representation */
94 /** The responsible expression manager */
95 NodeManager
* d_nodeManager
;
98 * Construct a new type given the typeNode, for internal use only.
99 * @param typeNode the TypeNode to use
100 * @return the Type corresponding to the TypeNode
102 Type
makeType(const TypeNode
& typeNode
) const;
105 * Constructor for internal purposes.
106 * @param em the expression manager that handles this expression
107 * @param typeNode the actual TypeNode pointer for this type
109 Type(NodeManager
* em
, TypeNode
* typeNode
);
111 /** Accessor for derived classes */
112 static TypeNode
* getTypeNode(const Type
& t
) throw() { return t
.d_typeNode
; }
116 /** Force a virtual destructor for safety. */
119 /** Default constructor */
124 * @param t the type to make a copy of
129 * Check whether this is a null type
130 * @return true if type is null
135 * Return the cardinality of this type.
137 Cardinality
getCardinality() const;
140 * Is this a well-founded type? (I.e., do there exist ground
143 bool isWellFounded() const;
146 * Construct and return a ground term for this Type. Throws an
147 * exception if this type is not well-founded.
149 Expr
mkGroundTerm() const;
152 * Substitution of Types.
154 Type
substitute(const Type
& type
, const Type
& replacement
) const;
157 * Simultaneous substitution of Types.
159 Type
substitute(const std::vector
<Type
>& types
,
160 const std::vector
<Type
>& replacements
) const;
163 * Get this type's ExprManager.
165 ExprManager
* getExprManager() const;
168 * Assignment operator.
169 * @param t the type to assign to this type
170 * @return this type after assignment.
172 Type
& operator=(const Type
& t
);
175 * Comparison for structural equality.
176 * @param t the type to compare to
177 * @returns true if the types are equal
179 bool operator==(const Type
& t
) const;
182 * Comparison for structural disequality.
183 * @param t the type to compare to
184 * @returns true if the types are not equal
186 bool operator!=(const Type
& t
) const;
189 * An ordering on Types so they can be stored in maps, etc.
191 bool operator<(const Type
& t
) const;
194 * An ordering on Types so they can be stored in maps, etc.
196 bool operator<=(const Type
& t
) const;
199 * An ordering on Types so they can be stored in maps, etc.
201 bool operator>(const Type
& t
) const;
204 * An ordering on Types so they can be stored in maps, etc.
206 bool operator>=(const Type
& t
) const;
209 * Is this the Boolean type?
210 * @return true if the type is a Boolean type
212 bool isBoolean() const;
215 * Cast this type to a Boolean type
216 * @return the BooleanType
218 operator BooleanType() const throw(AssertionException
);
221 * Is this the integer type?
222 * @return true if the type is a integer type
224 bool isInteger() const;
227 * Cast this type to a integer type
228 * @return the IntegerType
230 operator IntegerType() const throw(AssertionException
);
233 * Is this the real type?
234 * @return true if the type is a real type
239 * Cast this type to a real type
240 * @return the RealType
242 operator RealType() const throw(AssertionException
);
245 * Is this the pseudoboolean type?
246 * @return true if the type is the pseudoboolean type
248 bool isPseudoboolean() const;
251 * Cast this type to a pseudoboolean type
252 * @return the PseudobooleanType
254 operator PseudobooleanType() const throw(AssertionException
);
257 * Is this the bit-vector type?
258 * @return true if the type is a bit-vector type
260 bool isBitVector() const;
263 * Cast this type to a bit-vector type
264 * @return the BitVectorType
266 operator BitVectorType() const throw(AssertionException
);
269 * Is this a function type?
270 * @return true if the type is a function type
272 bool isFunction() const;
275 * Is this a predicate type, i.e. if it's a function type mapping to Boolean.
276 * All predicate types are also function types.
277 * @return true if the type is a predicate type
279 bool isPredicate() const;
282 * Cast this type to a function type
283 * @return the FunctionType
285 operator FunctionType() const throw(AssertionException
);
288 * Is this a tuple type?
289 * @return true if the type is a tuple type
291 bool isTuple() const;
294 * Cast this type to a tuple type
295 * @return the TupleType
297 operator TupleType() const throw(AssertionException
);
300 * Is this an array type?
301 * @return true if the type is a array type
303 bool isArray() const;
306 * Cast this type to an array type
307 * @return the ArrayType
309 operator ArrayType() const throw(AssertionException
);
312 * Is this a datatype type?
313 * @return true if the type is a datatype type
315 bool isDatatype() const;
318 * Cast this type to a datatype type
319 * @return the DatatypeType
321 operator DatatypeType() const throw(AssertionException
);
324 * Is this a constructor type?
325 * @return true if the type is a constructor type
327 bool isConstructor() const;
330 * Cast this type to a constructor type
331 * @return the ConstructorType
333 operator ConstructorType() const throw(AssertionException
);
336 * Is this a selector type?
337 * @return true if the type is a selector type
339 bool isSelector() const;
342 * Cast this type to a selector type
343 * @return the SelectorType
345 operator SelectorType() const throw(AssertionException
);
348 * Is this a tester type?
349 * @return true if the type is a tester type
351 bool isTester() const;
354 * Cast this type to a tester type
355 * @return the TesterType
357 operator TesterType() const throw(AssertionException
);
360 * Is this a sort kind?
361 * @return true if this is a sort kind
366 * Cast this type to a sort type
367 * @return the sort type
369 operator SortType() const throw(AssertionException
);
372 * Is this a sort constructor kind?
373 * @return true if this is a sort constructor kind
375 bool isSortConstructor() const;
378 * Cast this type to a sort constructor type
379 * @return the sort constructor type
381 operator SortConstructorType() const throw(AssertionException
);
384 * Is this a kind type (i.e., the type of a type)?
385 * @return true if this is a kind type
390 * Cast to a kind type
391 * @return the kind type
393 operator KindType() const throw(AssertionException
);
396 * Outputs a string representation of this type to the stream.
397 * @param out the stream to output to
399 void toStream(std::ostream
& out
) const;
402 * Constructs a string representation of this type.
404 std::string
toString() const;
408 * Singleton class encapsulating the Boolean type.
410 class CVC4_PUBLIC BooleanType
: public Type
{
414 /** Construct from the base type */
415 BooleanType(const Type
& type
= Type()) throw(AssertionException
);
416 };/* class BooleanType */
419 * Singleton class encapsulating the integer type.
421 class CVC4_PUBLIC IntegerType
: public Type
{
425 /** Construct from the base type */
426 IntegerType(const Type
& type
= Type()) throw(AssertionException
);
427 };/* class IntegerType */
430 * Singleton class encapsulating the real type.
432 class CVC4_PUBLIC RealType
: public Type
{
436 /** Construct from the base type */
437 RealType(const Type
& type
= Type()) throw(AssertionException
);
438 };/* class RealType */
441 * Singleton class encapsulating the pseudoboolean type.
443 class CVC4_PUBLIC PseudobooleanType
: public Type
{
447 /** Construct from the base type */
448 PseudobooleanType(const Type
& type
) throw(AssertionException
);
449 };/* class PseudobooleanType */
452 * Class encapsulating a function type.
454 class CVC4_PUBLIC FunctionType
: public Type
{
458 /** Construct from the base type */
459 FunctionType(const Type
& type
= Type()) throw(AssertionException
);
461 /** Get the argument types */
462 std::vector
<Type
> getArgTypes() const;
464 /** Get the range type (i.e., the type of the result). */
465 Type
getRangeType() const;
466 };/* class FunctionType */
469 * Class encapsulating a tuple type.
471 class CVC4_PUBLIC TupleType
: public Type
{
475 /** Construct from the base type */
476 TupleType(const Type
& type
= Type()) throw(AssertionException
);
478 /** Get the constituent types */
479 std::vector
<Type
> getTypes() const;
480 };/* class TupleType */
483 * Class encapsulating an array type.
485 class CVC4_PUBLIC ArrayType
: public Type
{
489 /** Construct from the base type */
490 ArrayType(const Type
& type
= Type()) throw(AssertionException
);
492 /** Get the index type */
493 Type
getIndexType() const;
495 /** Get the constituent type */
496 Type
getConstituentType() const;
497 };/* class ArrayType */
500 * Class encapsulating a user-defined sort.
502 class CVC4_PUBLIC SortType
: public Type
{
506 /** Construct from the base type */
507 SortType(const Type
& type
= Type()) throw(AssertionException
);
509 /** Get the name of the sort */
510 std::string
getName() const;
512 /** Is this type parameterized? */
513 bool isParameterized() const;
515 /** Get the parameter types */
516 std::vector
<Type
> getParamTypes() const;
518 };/* class SortType */
521 * Class encapsulating a user-defined sort constructor.
523 class CVC4_PUBLIC SortConstructorType
: public Type
{
527 /** Construct from the base type */
528 SortConstructorType(const Type
& type
= Type()) throw(AssertionException
);
530 /** Get the name of the sort constructor */
531 std::string
getName() const;
533 /** Get the arity of the sort constructor */
534 size_t getArity() const;
536 /** Instantiate a sort using this sort constructor */
537 SortType
instantiate(const std::vector
<Type
>& params
) const;
539 };/* class SortConstructorType */
542 * Class encapsulating the kind type (the type of types).
544 class CVC4_PUBLIC KindType
: public Type
{
548 /** Construct from the base type */
549 KindType(const Type
& type
= Type()) throw(AssertionException
);
550 };/* class KindType */
553 * Class encapsulating the bit-vector type.
555 class CVC4_PUBLIC BitVectorType
: public Type
{
559 /** Construct from the base type */
560 BitVectorType(const Type
& type
= Type()) throw(AssertionException
);
563 * Returns the size of the bit-vector type.
564 * @return the width of the bit-vector type (> 0)
566 unsigned getSize() const;
568 };/* class BitVectorType */
572 * Class encapsulating the datatype type
574 class CVC4_PUBLIC DatatypeType
: public Type
{
578 /** Construct from the base type */
579 DatatypeType(const Type
& type
= Type()) throw(AssertionException
);
581 /** Get the underlying datatype */
582 const Datatype
& getDatatype() const;
584 /** Is this datatype parametric? */
585 bool isParametric() const;
588 * Get the constructor operator associated to the given constructor
589 * name in this datatype.
591 Expr
getConstructor(std::string name
) const;
594 * Has this datatype been fully instantiated ?
596 * @return true if this datatype is not parametric or, if it is, it
597 * has been fully instantiated
599 bool isInstantiated() const;
602 * Has this datatype been instantiated for parameter N ?
604 bool isParameterInstantiated(unsigned n
) const;
606 /** Get the parameter types */
607 std::vector
<Type
> getParamTypes() const;
609 /** Get the arity of the datatype constructor */
610 size_t getArity() const;
612 /** Instantiate a datatype using this datatype constructor */
613 DatatypeType
instantiate(const std::vector
<Type
>& params
) const;
615 };/* class DatatypeType */
618 * Class encapsulating the constructor type
620 class CVC4_PUBLIC ConstructorType
: public Type
{
624 /** Construct from the base type */
625 ConstructorType(const Type
& type
= Type()) throw(AssertionException
);
627 /** Get the range type */
628 DatatypeType
getRangeType() const;
630 /** Get the argument types */
631 std::vector
<Type
> getArgTypes() const;
633 /** Get the number of constructor arguments */
634 size_t getArity() const;
636 };/* class ConstructorType */
640 * Class encapsulating the Selector type
642 class CVC4_PUBLIC SelectorType
: public Type
{
646 /** Construct from the base type */
647 SelectorType(const Type
& type
= Type()) throw(AssertionException
);
649 /** Get the domain type for this selector (the datatype type) */
650 DatatypeType
getDomain() const;
652 /** Get the range type for this selector (the field type) */
653 Type
getRangeType() const;
655 };/* class SelectorType */
658 * Class encapsulating the Tester type
660 class CVC4_PUBLIC TesterType
: public Type
{
664 /** Construct from the base type */
665 TesterType(const Type
& type
= Type()) throw(AssertionException
);
667 /** Get the type that this tester tests (the datatype type) */
668 DatatypeType
getDomain() const;
671 * Get the range type for this tester (included for sake of
672 * interface completeness), but doesn't give useful information).
674 BooleanType
getRangeType() const;
676 };/* class TesterType */
678 }/* CVC4 namespace */
680 #endif /* __CVC4__TYPE_H */