// the complete spec for the datatype from the DatatypeSort, and
// this Datatype object has constructor symbols (and others) filled in.
- Datatype consList = consListSort.getDatatype();
+ const Datatype& consList = consListSort.getDatatype();
// t = cons 0 nil
//
Sort paramConsIntListSort =
paramConsListSort.instantiate(std::vector<Sort>{slv.getIntegerSort()});
- Datatype paramConsList = paramConsListSort.getDatatype();
+ const Datatype& paramConsList = paramConsListSort.getDatatype();
std::cout << "parameterized datatype sort is " << std::endl;
for (const DatatypeConstructor& ctor : paramConsList)
<< ">>> Alternatively, use declareDatatype" << std::endl;
std::cout << std::endl;
- std::vector<DatatypeConstructorDecl> ctors = {cons, nil};
+ DatatypeConstructorDecl cons2("cons");
+ DatatypeSelectorDecl head2("head", slv.getIntegerSort());
+ DatatypeSelectorDecl tail2("tail", DatatypeDeclSelfSort());
+ cons2.addSelector(head2);
+ cons2.addSelector(tail2);
+ DatatypeConstructorDecl nil2("nil");
+ std::vector<DatatypeConstructorDecl> ctors = {cons2, nil2};
Sort consListSort2 = slv.declareDatatype("list2", ctors);
test(slv, consListSort2);
DatatypeType paramConsListType = em.mkDatatypeType(paramConsListSpec);
Type paramConsIntListType = paramConsListType.instantiate(std::vector<Type>{em.integerType()});
- Datatype paramConsList = paramConsListType.getDatatype();
+ const Datatype& paramConsList = paramConsListType.getDatatype();
std::cout << "parameterized datatype sort is " << std::endl;
for (const DatatypeConstructor& ctor : paramConsList)
// !!! This is only temporarily available until the parser is fully migrated
// to the new API. !!!
-CVC4::DatatypeConstructor DatatypeConstructorDecl::getDatatypeConstructor(
- void) const
+const CVC4::DatatypeConstructor&
+DatatypeConstructorDecl::getDatatypeConstructor(void) const
{
return *d_ctor;
}
// !!! This is only temporarily available until the parser is fully migrated
// to the new API. !!!
-CVC4::Datatype DatatypeDecl::getDatatype(void) const { return *d_dtype; }
+const CVC4::Datatype& DatatypeDecl::getDatatype(void) const { return *d_dtype; }
std::ostream& operator<<(std::ostream& out,
const DatatypeSelectorDecl& stordecl)
// !!! This is only temporarily available until the parser is fully migrated
// to the new API. !!!
-CVC4::DatatypeConstructor DatatypeConstructor::getDatatypeConstructor(
+const CVC4::DatatypeConstructor& DatatypeConstructor::getDatatypeConstructor(
void) const
{
return *d_ctor;
// !!! This is only temporarily available until the parser is fully migrated
// to the new API. !!!
-CVC4::Datatype Datatype::getDatatype(void) const { return *d_dtype; }
+const CVC4::Datatype& Datatype::getDatatype(void) const { return *d_dtype; }
Datatype::const_iterator::const_iterator(const CVC4::Datatype& dtype,
bool begin)
// !!! This is only temporarily available until the parser is fully migrated
// to the new API. !!!
- CVC4::DatatypeConstructor getDatatypeConstructor(void) const;
+ const CVC4::DatatypeConstructor& getDatatypeConstructor(void) const;
private:
/**
// !!! This is only temporarily available until the parser is fully migrated
// to the new API. !!!
- CVC4::Datatype getDatatype(void) const;
+ const CVC4::Datatype& getDatatype(void) const;
private:
/* The internal (intermediate) datatype wrapped by this datatype
// !!! This is only temporarily available until the parser is fully migrated
// to the new API. !!!
- CVC4::DatatypeConstructor getDatatypeConstructor(void) const;
+ const CVC4::DatatypeConstructor& getDatatypeConstructor(void) const;
private:
/**
// !!! This is only temporarily available until the parser is fully migrated
// to the new API. !!!
- CVC4::Datatype getDatatype(void) const;
+ const CVC4::Datatype& getDatatype(void) const;
private:
/**
OpTerm opterm2 = d_solver->mkOpTerm(DIVISIBLE_OP, 1);
OpTerm opterm3 = d_solver->mkOpTerm(CHAIN_OP, EQUAL);
// list datatype
+
Sort sort = d_solver->mkParamSort("T");
DatatypeDecl listDecl("paramlist", sort);
DatatypeConstructorDecl cons("cons");
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));
+ DatatypeConstructorDecl cons("cons");
+ DatatypeConstructorDecl nil2("nil");
+ std::vector<DatatypeConstructorDecl> ctors2 = {cons, nil2};
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),
+ DatatypeConstructorDecl cons2("cons");
+ DatatypeConstructorDecl nil3("nil");
+ std::vector<DatatypeConstructorDecl> ctors3 = {cons2, nil3};
+ TS_ASSERT_THROWS_NOTHING(d_solver->declareDatatype(std::string(""), ctors3));
+ std::vector<DatatypeConstructorDecl> ctors4;
+ TS_ASSERT_THROWS(d_solver->declareDatatype(std::string("c"), ctors4),
CVC4ApiException&);
- TS_ASSERT_THROWS(d_solver->declareDatatype(std::string(""), ctors3),
+ TS_ASSERT_THROWS(d_solver->declareDatatype(std::string(""), ctors4),
CVC4ApiException&);
}
Sort uSort = d_solver->mkUninterpretedSort("u");
Sort funSort1 = d_solver->mkFunctionSort({bvSort, bvSort}, bvSort);
Sort funSort2 = d_solver->mkFunctionSort(uSort, d_solver->getIntegerSort());
-
DatatypeDecl consListSpec("list");
DatatypeConstructorDecl cons("cons");
DatatypeSelectorDecl head("head", d_solver->getIntegerSort());
Debug("groundterms") << "ground term of " << dtts[1].getDatatype().getName() << endl
<< " is " << dtts[1].mkGroundTerm() << endl;
TS_ASSERT(dtts[1].mkGroundTerm().getType() == dtts[1]);
+ }
+ void testMutualListTrees2()
+ {
+ Datatype tree("tree");
+ DatatypeConstructor node("node", "is_node");
+ node.addArg("left", DatatypeSelfType());
+ node.addArg("right", DatatypeSelfType());
+ tree.addConstructor(node);
+
+ DatatypeConstructor leaf("leaf", "is_leaf");
+ leaf.addArg("leaf", DatatypeUnresolvedType("list"));
+ tree.addConstructor(leaf);
+
+ Datatype list("list");
+ DatatypeConstructor cons("cons", "is_cons");
+ cons.addArg("car", DatatypeUnresolvedType("tree"));
+ cons.addArg("cdr", DatatypeSelfType());
+ list.addConstructor(cons);
+
+ DatatypeConstructor nil("nil", "is_nil");
+ list.addConstructor(nil);
// add another constructor to list datatype resulting in an
// "otherNil-list"
DatatypeConstructor otherNil("otherNil", "is_otherNil");
- dts[1].addConstructor(otherNil);
+ list.addConstructor(otherNil);
+ vector<Datatype> dts;
+ dts.push_back(tree);
+ dts.push_back(list);
// remake the types
vector<DatatypeType> dtts2 = d_em->mkMutualDatatypeTypes(dts);
- TS_ASSERT_DIFFERS(dtts, dtts2);
- TS_ASSERT_DIFFERS(dtts[1], dtts2[1]);
-
- // tree is also different because it's a tree of otherNil-lists
- TS_ASSERT_DIFFERS(dtts[0], dtts2[0]);
-
TS_ASSERT(! dtts2[0].getDatatype().isFinite());
TS_ASSERT(dtts2[0].getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
TS_ASSERT(dtts2[0].getDatatype().isWellFounded());