return out;
}
+std::ostream& operator<<(std::ostream& out,
+ const std::vector<DatatypeConstructorDecl>& vector)
+{
+ container_to_stream(out, vector);
+ return out;
+}
+
/* DatatypeDecl ------------------------------------------------------------- */
DatatypeDecl::DatatypeDecl(const std::string& name, bool isCoDatatype)
*/
Term Solver::declareConst(const std::string& symbol, Sort sort) const
{
- return d_exprMgr->mkVar(symbol, *sort.d_type);
+ try
+ {
+ CVC4_API_ARG_CHECK_EXPECTED(!sort.isNull(), sort) << "non-null sort";
+ Term res = d_exprMgr->mkVar(symbol, *sort.d_type);
+ (void)res.d_expr->getType(true); /* kick off type checking */
+ return res;
+ }
+ catch (const CVC4::TypeCheckingException& e)
+ {
+ throw CVC4ApiException(e.getMessage());
+ }
}
/**
const std::string& symbol,
const std::vector<DatatypeConstructorDecl>& ctors) const
{
+ CVC4_API_ARG_CHECK_EXPECTED(ctors.size() > 0, ctors)
+ << "a datatype declaration with at least one constructor";
DatatypeDecl dtdecl(symbol);
for (const DatatypeConstructorDecl& ctor : ctors)
{
dtdecl.addConstructor(ctor);
}
- return mkDatatypeSort(dtdecl);
+ return d_exprMgr->mkDatatypeType(*dtdecl.d_dtype);
}
/**
std::ostream& operator<<(std::ostream& out,
const DatatypeConstructorDecl& ctordecl) CVC4_PUBLIC;
+/**
+ * Serialize a vector of datatype constructor declarations to given stream.
+ * @param out the output stream
+ * @param vector the vector of datatype constructor declarations to be
+ * serialized to the given stream
+ * @return the output stream
+ */
+std::ostream& operator<<(std::ostream& out,
+ const std::vector<DatatypeConstructorDecl>& vector);
+
/**
* Serialize a datatype selector declaration to given stream.
* @param out the output stream
void testMkUniverseSet();
void testMkVar();
+ void testDeclareConst();
+ void testDeclareDatatype();
void testDeclareFun();
+ void testDeclareSort();
+
void testDefineFun();
void testDefineFunRec();
void testDefineFunsRec();
TS_ASSERT_THROWS_NOTHING(d_solver->mkVar("", funSort));
}
+void SolverBlack::testDeclareConst()
+{
+ Sort boolSort = d_solver->getBooleanSort();
+ Sort intSort = d_solver->getIntegerSort();
+ Sort funSort = d_solver->mkFunctionSort(intSort, boolSort);
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareConst(std::string("b"), boolSort));
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareConst(std::string("i"), intSort));
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareConst("f", funSort));
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareConst("", funSort));
+ TS_ASSERT_THROWS(d_solver->declareConst("a", Sort()), CVC4ApiException&);
+}
+
+void SolverBlack::testDeclareDatatype()
+{
+ DatatypeConstructorDecl cons("cons");
+ DatatypeConstructorDecl nil("nil");
+ std::vector<DatatypeConstructorDecl> ctors1 = {nil};
+ std::vector<DatatypeConstructorDecl> ctors2 = {cons, nil};
+ std::vector<DatatypeConstructorDecl> ctors3;
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareDatatype(std::string("a"), ctors1));
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareDatatype(std::string("b"), ctors2));
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareDatatype(std::string(""), ctors2));
+ TS_ASSERT_THROWS(d_solver->declareDatatype(std::string("c"), ctors3),
+ CVC4ApiException&);
+ TS_ASSERT_THROWS(d_solver->declareDatatype(std::string(""), ctors3),
+ CVC4ApiException&);
+}
+
void SolverBlack::testDeclareFun()
{
Sort bvSort = d_solver->mkBitVectorSort(32);
CVC4ApiException&);
}
+void SolverBlack::testDeclareSort()
+{
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareSort("s", 0));
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareSort("s", 2));
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareSort("", 2));
+}
+
void SolverBlack::testDefineFun()
{
Sort bvSort = d_solver->mkBitVectorSort(32);