return d_typeNode->mkGroundTerm().toExpr();
}
+bool Type::isSubtypeOf(Type t) const {
+ NodeManagerScope nms(d_nodeManager);
+ return d_typeNode->isSubtypeOf(*t.d_typeNode);
+}
+
+bool Type::isComparableTo(Type t) const {
+ NodeManagerScope nms(d_nodeManager);
+ return d_typeNode->isComparableTo(*t.d_typeNode);
+}
+
Type& Type::operator=(const Type& t) {
Assert(d_typeNode != NULL, "Unexpected NULL typenode pointer!");
Assert(t.d_typeNode != NULL, "Unexpected NULL typenode pointer!");
Cardinality getCardinality() const;
/**
- * Is this a well-founded type? (I.e., do there exist ground
- * terms?)
+ * Is this a well-founded type?
*/
bool isWellFounded() const;
*/
Expr mkGroundTerm() const;
+ /**
+ * Is this type a subtype of the given type?
+ */
+ bool isSubtypeOf(Type t) const;
+
+ /**
+ * Is this type comparable to the given type (i.e., do they share
+ * a common ancestor in the subtype tree)?
+ */
+ bool isComparableTo(Type t) const;
+
/**
* Substitution of Types.
*/
Cardinality getCardinality() const;
/**
- * Returns whether this type is well-founded. A type is
- * well-founded if there exist ground terms.
+ * Returns whether this type is well-founded.
*
* @return true iff the type is well-founded
*/
*/
Node mkGroundTerm() const;
- /** Is this type a subtype of the given type? */
+ /**
+ * Is this type a subtype of the given type?
+ */
bool isSubtypeOf(TypeNode t) const;
/**
# store a i e is a[i] <= e
operator STORE 3 "array store"
+# storeall t e is \all i in indexType(t) <= e
+constant STORE_ALL \
+ ::CVC4::ArrayStoreAll \
+ ::CVC4::ArrayStoreAllHashStrategy \
+ "util/array_store_all.h" \
+ "array store-all"
+
# used internally by array theory
operator ARR_TABLE_FUN 4 "array table function"
typerule SELECT ::CVC4::theory::arrays::ArraySelectTypeRule
typerule STORE ::CVC4::theory::arrays::ArrayStoreTypeRule
+typerule STORE_ALL ::CVC4::theory::arrays::ArrayStoreTypeRule
typerule ARR_TABLE_FUN ::CVC4::theory::arrays::ArrayTableFunTypeRule
endtheory
::CVC4::UninterpretedConstantHashStrategy \
"util/uninterpreted_constant.h" \
"The kind of nodes representing uninterpreted constants"
+typerule UNINTERPRETED_CONSTANT ::CVC4::theory::builtin::UninterpretedConstantTypeRule
enumerator SORT_TYPE \
::CVC4::theory::builtin::UninterpretedSortEnumerator \
"theory/builtin/type_enumerator.h"
}
};/* class TupleTypeRule */
+class UninterpretedConstantTypeRule {
+public:
+ inline static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check) {
+ return TypeNode::fromType(n.getConst<UninterpretedConstant>().getType());
+ }
+};/* class UninterpretedConstantTypeRule */
+
class StringConstantTypeRule {
public:
inline static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check) {
namespace CVC4 {
class CVC4_PUBLIC ArrayStoreAll {
- const Type d_type;
+ const ArrayType d_type;
const Expr d_expr;
public:
- ArrayStoreAll(Type type, Expr expr) throw(IllegalArgumentException) :
+ ArrayStoreAll(ArrayType type, Expr expr) throw(IllegalArgumentException) :
d_type(type),
d_expr(expr) {
+
+ // this check is stronger than the assertion check in the expr manager that ArrayTypes are actually array types
+ // because this check is done in production builds too
CheckArgument(type.isArray(), type, "array store-all constants can only be created for array types, not `%s'", type.toString().c_str());
- CheckArgument(expr.getType() == ArrayType(type).getConstituentType(), expr, "expr type `%s' does not match constituent type of array type `%s'", expr.getType().toString().c_str(), type.toString().c_str());
+
+ CheckArgument(expr.getType().isSubtypeOf(type.getConstituentType()), expr, "expr type `%s' does not match constituent type of array type `%s'", expr.getType().toString().c_str(), type.toString().c_str());
}
~ArrayStoreAll() throw() {
}
- Type getType() const throw() {
+ ArrayType getType() const throw() {
return d_type;
}
Expr getExpr() const throw() {
context/cdvector_black \
context/stacking_map_black \
context/stacking_vector_black \
+ util/array_store_all_black \
util/assert_white \
util/bitvector_black \
util/datatype_black \
--- /dev/null
+/********************* */
+/*! \file array_store_all_black.h
+ ** \verbatim
+ ** Original author: mdeters
+ ** Major contributors: none
+ ** Minor contributors (to current version): none
+ ** This file is part of the CVC4 prototype.
+ ** Copyright (c) 2009-2012 The Analysis of Computer Systems Group (ACSys)
+ ** Courant Institute of Mathematical Sciences
+ ** New York University
+ ** See the file COPYING in the top-level source directory for licensing
+ ** information.\endverbatim
+ **
+ ** \brief Black box testing of CVC4::ArrayStoreAll
+ **
+ ** Black box testing of CVC4::ArrayStoreAll.
+ **/
+
+#include <cxxtest/TestSuite.h>
+
+#include "util/array_store_all.h"
+#include "expr/expr_manager.h"
+#include "expr/expr_manager_scope.h"
+#include "expr/type.h"
+#include "expr/expr.h"
+
+using namespace CVC4;
+using namespace std;
+
+class ArrayStoreAllBlack : public CxxTest::TestSuite {
+
+ ExprManager* d_em;
+ ExprManagerScope* d_scope;
+
+public:
+
+ void setUp() {
+ d_em = new ExprManager();
+ d_scope = new ExprManagerScope(*d_em);
+ }
+
+ void tearDown() {
+ delete d_scope;
+ delete d_em;
+ }
+
+ void testStoreAll() {
+ Type usort = d_em->mkSort("U");
+ ArrayStoreAll(d_em->mkArrayType(d_em->integerType(), d_em->realType()), d_em->mkConst(Rational(9, 2)));
+ ArrayStoreAll(d_em->mkArrayType(d_em->mkSort("U"), usort), d_em->mkVar(usort));
+ ArrayStoreAll(d_em->mkArrayType(d_em->mkSort("U"), usort), d_em->mkConst(UninterpretedConstant(usort, 0)));
+ ArrayStoreAll(d_em->mkArrayType(d_em->mkBitVectorType(8), d_em->realType()), d_em->mkConst(Rational(0)));
+ ArrayStoreAll(d_em->mkArrayType(d_em->mkBitVectorType(8), d_em->integerType()), d_em->mkConst(Rational(0)));
+ }
+
+ void testTypeErrors() {
+ // these two throw an AssertionException in assertions-enabled builds, and an IllegalArgumentException in production builds
+ TS_ASSERT_THROWS_ANYTHING( ArrayStoreAll(d_em->integerType(), d_em->mkConst(UninterpretedConstant(d_em->mkSort("U"), 0))) );
+ TS_ASSERT_THROWS_ANYTHING( ArrayStoreAll(d_em->integerType(), d_em->mkConst(Rational(9, 2))) );
+
+ TS_ASSERT_THROWS( ArrayStoreAll(d_em->mkArrayType(d_em->integerType(), d_em->integerType()), d_em->mkConst(Rational(9, 2))), IllegalArgumentException );
+ TS_ASSERT_THROWS( ArrayStoreAll(d_em->mkArrayType(d_em->integerType(), d_em->mkSort("U")), d_em->mkConst(Rational(9, 2))), IllegalArgumentException );
+ TS_ASSERT_THROWS( ArrayStoreAll(d_em->mkArrayType(d_em->realType(), d_em->integerType()), d_em->mkConst(Rational(9, 2))), IllegalArgumentException );
+ }
+
+};/* class ArrayStoreAllBlack */