case kind::APPLY_CONSTRUCTOR:
{
typeChildren = true;
- const Datatype& dt = Datatype::datatypeOf(n.getOperator().toExpr());
+ const DType& dt = DType::datatypeOf(n.getOperator());
if (dt.isTuple())
{
stillNeedToPrintParams = false;
if(toDepth != 0) {
if (n.getKind() == kind::APPLY_TESTER)
{
- unsigned cindex = Datatype::indexOf(n.getOperator().toExpr());
- const Datatype& dt = Datatype::datatypeOf(n.getOperator().toExpr());
+ unsigned cindex = DType::indexOf(n.getOperator().toExpr());
+ const DType& dt = DType::datatypeOf(n.getOperator().toExpr());
if (isVariant_2_6(d_variant))
{
out << "(_ is ";
- toStream(out, Node::fromExpr(dt[cindex].getConstructor()), toDepth < 0 ? toDepth : toDepth - 1, types, TypeNode::null());
+ toStream(out,
+ dt[cindex].getConstructor(),
+ toDepth < 0 ? toDepth : toDepth - 1,
+ types,
+ TypeNode::null());
out << ")";
}else{
out << "is-";
- toStream(out, Node::fromExpr(dt[cindex].getConstructor()), toDepth < 0 ? toDepth : toDepth - 1, types, TypeNode::null());
+ toStream(out,
+ dt[cindex].getConstructor(),
+ toDepth < 0 ? toDepth : toDepth - 1,
+ types,
+ TypeNode::null());
}
}else{
toStream(out, n.getOperator(), toDepth < 0 ? toDepth : toDepth - 1, types, TypeNode::null());
TypeNode opt = n.getOperator().getType();
if (n.getKind() == kind::APPLY_CONSTRUCTOR)
{
- Type tn = n.getType().toType();
+ TypeNode tn = n.getType();
// may be parametric, in which case the constructor type must be
// specialized
- const Datatype& dt = static_cast<DatatypeType>(tn).getDatatype();
+ const DType& dt = tn.getDType();
if (dt.isParametric())
{
- unsigned ci = Datatype::indexOf(n.getOperator().toExpr());
- opt = TypeNode::fromType(dt[ci].getSpecializedConstructorType(tn));
+ unsigned ci = DType::indexOf(n.getOperator().toExpr());
+ opt = dt[ci].getSpecializedConstructorType(tn);
}
}
Assert(opt.getNumChildren() == n.getNumChildren() + 1);
out << "(get-option :" << c->getFlag() << ")";
}
-static void toStream(std::ostream& out, const Datatype & d) {
- for(Datatype::const_iterator ctor = d.begin(), ctor_end = d.end();
- ctor != ctor_end; ++ctor){
- if( ctor!=d.begin() ) out << " ";
- out << "(" << CVC4::quoteSymbol(ctor->getName());
-
- for(DatatypeConstructor::const_iterator arg = ctor->begin(), arg_end = ctor->end();
- arg != arg_end; ++arg){
- out << " (" << arg->getSelector() << " "
- << static_cast<SelectorType>(arg->getType()).getRangeType() << ")";
+static void toStream(std::ostream& out, const DType& dt)
+{
+ for (size_t i = 0, ncons = dt.getNumConstructors(); i < ncons; i++)
+ {
+ const DTypeConstructor& cons = dt[i];
+ if (i != 0)
+ {
+ out << " ";
+ }
+ out << "(" << CVC4::quoteSymbol(cons.getName());
+ for (size_t j = 0, nargs = cons.getNumArgs(); j < nargs; j++)
+ {
+ const DTypeSelector& arg = cons[j];
+ out << " (" << arg.getSelector() << " " << arg.getRangeType() << ")";
}
out << ")";
}
const std::vector<Type>& datatypes = c->getDatatypes();
Assert(!datatypes.empty());
Assert(datatypes[0].isDatatype());
- DatatypeType dt0 = DatatypeType(datatypes[0]);
- const Datatype& d0 = dt0.getDatatype();
+ const DType& d0 = TypeNode::fromType(datatypes[0]).getDType();
if (d0.isTuple())
{
// not necessary to print tuples
for (const Type& t : datatypes)
{
Assert(t.isDatatype());
- const Datatype& d = DatatypeType(t).getDatatype();
+ const DType& d = TypeNode::fromType(t).getDType();
out << "(" << CVC4::quoteSymbol(d.getName());
out << " " << d.getNumParameters() << ")";
}
for (const Type& t : datatypes)
{
Assert(t.isDatatype());
- const Datatype& d = DatatypeType(t).getDatatype();
+ const DType& d = TypeNode::fromType(t).getDType();
if (d.isParametric())
{
out << "(par (";
for (unsigned j = 1, ndt = datatypes.size(); j < ndt; j++)
{
Assert(datatypes[j].isDatatype());
- const Datatype& dj = DatatypeType(datatypes[j]).getDatatype();
+ const DType& dj = TypeNode::fromType(datatypes[j]).getDType();
if (dj.getNumParameters() != nparam)
{
success = false;
for (const Type& t : datatypes)
{
Assert(t.isDatatype());
- const Datatype& dt = DatatypeType(t).getDatatype();
+ const DType& dt = TypeNode::fromType(t).getDType();
out << "(" << CVC4::quoteSymbol(dt.getName()) << " ";
toStream(out, dt);
out << ")";
static void toStreamSygusGrammar(std::ostream& out, const Type& t)
{
if (!t.isNull() && t.isDatatype()
- && static_cast<DatatypeType>(t).getDatatype().isSygus())
+ && TypeNode::fromType(t).getDType().isSygus())
{
std::stringstream types_predecl, types_list;
- std::set<Type> grammarTypes;
- std::list<Type> typesToPrint;
- grammarTypes.insert(t);
- typesToPrint.push_back(t);
+ std::set<TypeNode> grammarTypes;
+ std::list<TypeNode> typesToPrint;
+ grammarTypes.insert(TypeNode::fromType(t));
+ typesToPrint.push_back(TypeNode::fromType(t));
NodeManager* nm = NodeManager::currentNM();
// for each datatype in grammar
// name
// constructors in order
do
{
- Type curr = typesToPrint.front();
+ TypeNode curr = typesToPrint.front();
typesToPrint.pop_front();
- Assert(curr.isDatatype()
- && static_cast<DatatypeType>(curr).getDatatype().isSygus());
- const Datatype& dt = static_cast<DatatypeType>(curr).getDatatype();
+ Assert(curr.isDatatype() && curr.getDType().isSygus());
+ const DType& dt = curr.getDType();
types_list << '(' << dt.getName() << ' ' << dt.getSygusType() << " (";
types_predecl << '(' << dt.getName() << ' ' << dt.getSygusType() << ") ";
if (dt.getSygusAllowConst())
{
types_list << "(Constant " << dt.getSygusType() << ") ";
}
- for (const DatatypeConstructor& cons : dt)
+ for (size_t i = 0, ncons = dt.getNumConstructors(); i < ncons; i++)
{
+ const DTypeConstructor& cons = dt[i];
// make a sygus term
std::vector<Node> cchildren;
- cchildren.push_back(Node::fromExpr(cons.getConstructor()));
- for (const DatatypeConstructorArg& i : cons)
+ cchildren.push_back(cons.getConstructor());
+ for (size_t j = 0, nargs = cons.getNumArgs(); j < nargs; j++)
{
- Type argType = i.getRangeType();
+ TypeNode argType = cons[j].getRangeType();
std::stringstream ss;
ss << argType;
- Node bv = nm->mkBoundVar(ss.str(), TypeNode::fromType(argType));
+ Node bv = nm->mkBoundVar(ss.str(), argType);
cchildren.push_back(bv);
// if fresh type, store it for later processing
if (grammarTypes.insert(argType).second)
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**
- ** \brief Black box testing of CVC4::Datatype
+ ** \brief Black box testing of CVC4::DType
**
- ** Black box testing of CVC4::Datatype.
+ ** Black box testing of CVC4::DType.
**/
#include <cxxtest/TestSuite.h>
#include <sstream>
#include "api/cvc4cpp.h"
-#include "expr/datatype.h"
+#include "expr/dtype.h"
#include "expr/expr.h"
#include "expr/expr_manager.h"
#include "expr/expr_manager_scope.h"
void setUp() override
{
d_slv = new api::Solver();
- d_em = d_slv->getExprManager();
- d_scope = new ExprManagerScope(*d_em);
+ d_nm = d_slv->getNodeManager();
+ d_scope = new NodeManagerScope(d_nm);
Debug.on("datatypes");
Debug.on("groundterms");
}
}
void testEnumeration() {
- Datatype colors(d_em, "colors");
+ DType colors("colors");
- DatatypeConstructor yellow("yellow");
- DatatypeConstructor blue("blue");
- DatatypeConstructor green("green");
- DatatypeConstructor red("red");
+ std::shared_ptr<DTypeConstructor> yellow =
+ std::make_shared<DTypeConstructor>("yellow");
+ std::shared_ptr<DTypeConstructor> blue =
+ std::make_shared<DTypeConstructor>("blue");
+ std::shared_ptr<DTypeConstructor> green =
+ std::make_shared<DTypeConstructor>("green");
+ std::shared_ptr<DTypeConstructor> red =
+ std::make_shared<DTypeConstructor>("red");
colors.addConstructor(yellow);
colors.addConstructor(blue);
colors.addConstructor(red);
Debug("datatypes") << colors << std::endl;
- DatatypeType colorsType = d_em->mkDatatypeType(colors);
+ TypeNode colorsType = d_nm->mkDatatypeType(colors);
Debug("datatypes") << colorsType << std::endl;
- Expr ctor = colorsType.getDatatype()[1].getConstructor();
- Expr apply = d_em->mkExpr(kind::APPLY_CONSTRUCTOR, ctor);
+ Node ctor = colorsType.getDType()[1].getConstructor();
+ Node apply = d_nm->mkNode(kind::APPLY_CONSTRUCTOR, ctor);
Debug("datatypes") << apply << std::endl;
- const Datatype& colorsDT = colorsType.getDatatype();
- TS_ASSERT(colorsDT.getConstructor("blue") == ctor);
- TS_ASSERT(colorsDT["blue"].getConstructor() == ctor);
- TS_ASSERT_THROWS(colorsDT["blue"].getSelector("foo"),
- IllegalArgumentException&);
- TS_ASSERT_THROWS(colorsDT["blue"]["foo"], IllegalArgumentException&);
-
- TS_ASSERT(! colorsType.getDatatype().isParametric());
- TS_ASSERT(colorsType.getDatatype().isFinite());
- TS_ASSERT(colorsType.getDatatype().getCardinality().compare(4) == Cardinality::EQUAL);
+ TS_ASSERT(!colorsType.getDType().isParametric());
+ TS_ASSERT(colorsType.getDType().isFinite());
+ TS_ASSERT(colorsType.getDType().getCardinality().compare(4)
+ == Cardinality::EQUAL);
TS_ASSERT(ctor.getType().getCardinality().compare(1) == Cardinality::EQUAL);
- TS_ASSERT(colorsType.getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << colorsType.getDatatype().getName() << endl
+ TS_ASSERT(colorsType.getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << colorsType.getDType().getName()
+ << endl
<< " is " << colorsType.mkGroundTerm() << endl;
TS_ASSERT(colorsType.mkGroundTerm().getType() == colorsType);
}
void testNat() {
- Datatype nat(d_em, "nat");
+ DType nat("nat");
- DatatypeConstructor succ("succ");
- succ.addArg("pred", DatatypeSelfType());
+ std::shared_ptr<DTypeConstructor> succ =
+ std::make_shared<DTypeConstructor>("succ");
+ succ->addArgSelf("pred");
nat.addConstructor(succ);
- DatatypeConstructor zero("zero");
+ std::shared_ptr<DTypeConstructor> zero =
+ std::make_shared<DTypeConstructor>("zero");
nat.addConstructor(zero);
Debug("datatypes") << nat << std::endl;
- DatatypeType natType = d_em->mkDatatypeType(nat);
+ TypeNode natType = d_nm->mkDatatypeType(nat);
Debug("datatypes") << natType << std::endl;
- Expr ctor = natType.getDatatype()[1].getConstructor();
- Expr apply = d_em->mkExpr(kind::APPLY_CONSTRUCTOR, ctor);
+ Node ctor = natType.getDType()[1].getConstructor();
+ Node apply = d_nm->mkNode(kind::APPLY_CONSTRUCTOR, ctor);
Debug("datatypes") << apply << std::endl;
- TS_ASSERT(! natType.getDatatype().isParametric());
- TS_ASSERT(! natType.getDatatype().isFinite());
- TS_ASSERT(natType.getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
- TS_ASSERT(natType.getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << natType.getDatatype().getName() << endl
+ TS_ASSERT(!natType.getDType().isParametric());
+ TS_ASSERT(!natType.getDType().isFinite());
+ TS_ASSERT(natType.getDType().getCardinality().compare(Cardinality::INTEGERS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(natType.getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << natType.getDType().getName()
+ << endl
<< " is " << natType.mkGroundTerm() << endl;
TS_ASSERT(natType.mkGroundTerm().getType() == natType);
}
void testTree() {
- Datatype tree(d_em, "tree");
- Type integerType = d_em->integerType();
+ DType tree("tree");
+ TypeNode integerType = d_nm->integerType();
- DatatypeConstructor node("node");
- node.addArg("left", DatatypeSelfType());
- node.addArg("right", DatatypeSelfType());
+ std::shared_ptr<DTypeConstructor> node =
+ std::make_shared<DTypeConstructor>("node");
+ node->addArgSelf("left");
+ node->addArgSelf("right");
tree.addConstructor(node);
- DatatypeConstructor leaf("leaf");
- leaf.addArg("leaf", integerType);
+ std::shared_ptr<DTypeConstructor> leaf =
+ std::make_shared<DTypeConstructor>("leaf");
+ leaf->addArg("leaf", integerType);
tree.addConstructor(leaf);
Debug("datatypes") << tree << std::endl;
- DatatypeType treeType = d_em->mkDatatypeType(tree);
+ TypeNode treeType = d_nm->mkDatatypeType(tree);
Debug("datatypes") << treeType << std::endl;
- Expr ctor = treeType.getDatatype()[1].getConstructor();
- TS_ASSERT(treeType.getConstructor("leaf") == ctor);
- TS_ASSERT(treeType.getConstructor("leaf") == ctor);
- TS_ASSERT_THROWS(treeType.getConstructor("leff"),
- IllegalArgumentException&);
-
- TS_ASSERT(! treeType.getDatatype().isParametric());
- TS_ASSERT(! treeType.getDatatype().isFinite());
- TS_ASSERT(treeType.getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
- TS_ASSERT(treeType.getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << treeType.getDatatype().getName() << endl
+ TS_ASSERT(!treeType.getDType().isParametric());
+ TS_ASSERT(!treeType.getDType().isFinite());
+ TS_ASSERT(
+ treeType.getDType().getCardinality().compare(Cardinality::INTEGERS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(treeType.getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << treeType.getDType().getName()
+ << endl
<< " is " << treeType.mkGroundTerm() << endl;
TS_ASSERT(treeType.mkGroundTerm().getType() == treeType);
}
void testListInt() {
- Datatype list(d_em, "list");
- Type integerType = d_em->integerType();
+ DType list("list");
+ TypeNode integerType = d_nm->integerType();
- DatatypeConstructor cons("cons");
- cons.addArg("car", integerType);
- cons.addArg("cdr", DatatypeSelfType());
+ std::shared_ptr<DTypeConstructor> cons =
+ std::make_shared<DTypeConstructor>("cons");
+ cons->addArg("car", integerType);
+ cons->addArgSelf("cdr");
list.addConstructor(cons);
- DatatypeConstructor nil("nil");
+ std::shared_ptr<DTypeConstructor> nil =
+ std::make_shared<DTypeConstructor>("nil");
list.addConstructor(nil);
Debug("datatypes") << list << std::endl;
- DatatypeType listType = d_em->mkDatatypeType(list);
+ TypeNode listType = d_nm->mkDatatypeType(list);
Debug("datatypes") << listType << std::endl;
- TS_ASSERT(! listType.getDatatype().isParametric());
- TS_ASSERT(! listType.getDatatype().isFinite());
- TS_ASSERT(listType.getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
- TS_ASSERT(listType.getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << listType.getDatatype().getName() << endl
+ TS_ASSERT(!listType.getDType().isParametric());
+ TS_ASSERT(!listType.getDType().isFinite());
+ TS_ASSERT(
+ listType.getDType().getCardinality().compare(Cardinality::INTEGERS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(listType.getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << listType.getDType().getName()
+ << endl
<< " is " << listType.mkGroundTerm() << endl;
TS_ASSERT(listType.mkGroundTerm().getType() == listType);
}
void testListReal() {
- Datatype list(d_em, "list");
- Type realType = d_em->realType();
+ DType list("list");
+ TypeNode realType = d_nm->realType();
- DatatypeConstructor cons("cons");
- cons.addArg("car", realType);
- cons.addArg("cdr", DatatypeSelfType());
+ std::shared_ptr<DTypeConstructor> cons =
+ std::make_shared<DTypeConstructor>("cons");
+ cons->addArg("car", realType);
+ cons->addArgSelf("cdr");
list.addConstructor(cons);
- DatatypeConstructor nil("nil");
+ std::shared_ptr<DTypeConstructor> nil =
+ std::make_shared<DTypeConstructor>("nil");
list.addConstructor(nil);
Debug("datatypes") << list << std::endl;
- DatatypeType listType = d_em->mkDatatypeType(list);
+ TypeNode listType = d_nm->mkDatatypeType(list);
Debug("datatypes") << listType << std::endl;
- TS_ASSERT(! listType.getDatatype().isParametric());
- TS_ASSERT(! listType.getDatatype().isFinite());
- TS_ASSERT(listType.getDatatype().getCardinality().compare(Cardinality::REALS) == Cardinality::EQUAL);
- TS_ASSERT(listType.getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << listType.getDatatype().getName() << endl
+ TS_ASSERT(!listType.getDType().isParametric());
+ TS_ASSERT(!listType.getDType().isFinite());
+ TS_ASSERT(listType.getDType().getCardinality().compare(Cardinality::REALS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(listType.getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << listType.getDType().getName()
+ << endl
<< " is " << listType.mkGroundTerm() << endl;
TS_ASSERT(listType.mkGroundTerm().getType() == listType);
}
void testListBoolean() {
- Datatype list(d_em, "list");
- Type booleanType = d_em->booleanType();
+ DType list("list");
+ TypeNode booleanType = d_nm->booleanType();
- DatatypeConstructor cons("cons");
- cons.addArg("car", booleanType);
- cons.addArg("cdr", DatatypeSelfType());
+ std::shared_ptr<DTypeConstructor> cons =
+ std::make_shared<DTypeConstructor>("cons");
+ cons->addArg("car", booleanType);
+ cons->addArgSelf("cdr");
list.addConstructor(cons);
- DatatypeConstructor nil("nil");
+ std::shared_ptr<DTypeConstructor> nil =
+ std::make_shared<DTypeConstructor>("nil");
list.addConstructor(nil);
Debug("datatypes") << list << std::endl;
- DatatypeType listType = d_em->mkDatatypeType(list);
+ TypeNode listType = d_nm->mkDatatypeType(list);
Debug("datatypes") << listType << std::endl;
- TS_ASSERT(! listType.getDatatype().isFinite());
- TS_ASSERT(listType.getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
- TS_ASSERT(listType.getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << listType.getDatatype().getName() << endl
+ TS_ASSERT(!listType.getDType().isFinite());
+ TS_ASSERT(
+ listType.getDType().getCardinality().compare(Cardinality::INTEGERS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(listType.getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << listType.getDType().getName()
+ << endl
<< " is " << listType.mkGroundTerm() << endl;
TS_ASSERT(listType.mkGroundTerm().getType() == listType);
}
* list = cons(car: tree, cdr: list) | nil
* END;
*/
- Datatype tree(d_em, "tree");
- DatatypeConstructor node("node");
- node.addArg("left", DatatypeSelfType());
- node.addArg("right", DatatypeSelfType());
+ std::set<TypeNode> unresolvedTypes;
+ TypeNode unresList =
+ d_nm->mkSort("list", ExprManager::SORT_FLAG_PLACEHOLDER);
+ unresolvedTypes.insert(unresList);
+ TypeNode unresTree =
+ d_nm->mkSort("tree", ExprManager::SORT_FLAG_PLACEHOLDER);
+ unresolvedTypes.insert(unresTree);
+
+ DType tree("tree");
+ std::shared_ptr<DTypeConstructor> node =
+ std::make_shared<DTypeConstructor>("node");
+ node->addArgSelf("left");
+ node->addArgSelf("right");
tree.addConstructor(node);
- DatatypeConstructor leaf("leaf");
- leaf.addArg("leaf", DatatypeUnresolvedType("list"));
+ std::shared_ptr<DTypeConstructor> leaf =
+ std::make_shared<DTypeConstructor>("leaf");
+ leaf->addArg("leaf", unresList);
tree.addConstructor(leaf);
Debug("datatypes") << tree << std::endl;
- Datatype list(d_em, "list");
- DatatypeConstructor cons("cons");
- cons.addArg("car", DatatypeUnresolvedType("tree"));
- cons.addArg("cdr", DatatypeSelfType());
+ DType list("list");
+ std::shared_ptr<DTypeConstructor> cons =
+ std::make_shared<DTypeConstructor>("cons");
+ cons->addArg("car", unresTree);
+ cons->addArgSelf("cdr");
list.addConstructor(cons);
- DatatypeConstructor nil("nil");
+ std::shared_ptr<DTypeConstructor> nil =
+ std::make_shared<DTypeConstructor>("nil");
list.addConstructor(nil);
Debug("datatypes") << list << std::endl;
TS_ASSERT(! tree.isResolved());
- TS_ASSERT(! node.isResolved());
- TS_ASSERT(! leaf.isResolved());
TS_ASSERT(! list.isResolved());
- TS_ASSERT(! cons.isResolved());
- TS_ASSERT(! nil.isResolved());
- vector<Datatype> dts;
+ vector<DType> dts;
dts.push_back(tree);
dts.push_back(list);
- vector<DatatypeType> dtts = d_em->mkMutualDatatypeTypes(dts);
+ vector<TypeNode> dtts = d_nm->mkMutualDatatypeTypes(dts, unresolvedTypes);
- TS_ASSERT(dtts[0].getDatatype().isResolved());
- TS_ASSERT(dtts[1].getDatatype().isResolved());
+ TS_ASSERT(dtts[0].getDType().isResolved());
+ TS_ASSERT(dtts[1].getDType().isResolved());
- TS_ASSERT(! dtts[0].getDatatype().isFinite());
- TS_ASSERT(dtts[0].getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
- TS_ASSERT(dtts[0].getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << dtts[0].getDatatype().getName() << endl
+ TS_ASSERT(!dtts[0].getDType().isFinite());
+ TS_ASSERT(dtts[0].getDType().getCardinality().compare(Cardinality::INTEGERS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(dtts[0].getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << dtts[0].getDType().getName()
+ << endl
<< " is " << dtts[0].mkGroundTerm() << endl;
TS_ASSERT(dtts[0].mkGroundTerm().getType() == dtts[0]);
- TS_ASSERT(! dtts[1].getDatatype().isFinite());
- TS_ASSERT(dtts[1].getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
- TS_ASSERT(dtts[1].getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << dtts[1].getDatatype().getName() << endl
+ TS_ASSERT(!dtts[1].getDType().isFinite());
+ TS_ASSERT(dtts[1].getDType().getCardinality().compare(Cardinality::INTEGERS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(dtts[1].getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << dtts[1].getDType().getName()
+ << endl
<< " is " << dtts[1].mkGroundTerm() << endl;
TS_ASSERT(dtts[1].mkGroundTerm().getType() == dtts[1]);
}
void testMutualListTrees2()
{
- Datatype tree(d_em, "tree");
- DatatypeConstructor node("node");
- node.addArg("left", DatatypeSelfType());
- node.addArg("right", DatatypeSelfType());
+ std::set<TypeNode> unresolvedTypes;
+ TypeNode unresList =
+ d_nm->mkSort("list", ExprManager::SORT_FLAG_PLACEHOLDER);
+ unresolvedTypes.insert(unresList);
+ TypeNode unresTree =
+ d_nm->mkSort("tree", ExprManager::SORT_FLAG_PLACEHOLDER);
+ unresolvedTypes.insert(unresTree);
+
+ DType tree("tree");
+ std::shared_ptr<DTypeConstructor> node =
+ std::make_shared<DTypeConstructor>("node");
+ node->addArgSelf("left");
+ node->addArgSelf("right");
tree.addConstructor(node);
- DatatypeConstructor leaf("leaf");
- leaf.addArg("leaf", DatatypeUnresolvedType("list"));
+ std::shared_ptr<DTypeConstructor> leaf =
+ std::make_shared<DTypeConstructor>("leaf");
+ leaf->addArg("leaf", unresList);
tree.addConstructor(leaf);
- Datatype list(d_em, "list");
- DatatypeConstructor cons("cons");
- cons.addArg("car", DatatypeUnresolvedType("tree"));
- cons.addArg("cdr", DatatypeSelfType());
+ DType list("list");
+ std::shared_ptr<DTypeConstructor> cons =
+ std::make_shared<DTypeConstructor>("cons");
+ cons->addArg("car", unresTree);
+ cons->addArgSelf("cdr");
list.addConstructor(cons);
- DatatypeConstructor nil("nil");
+ std::shared_ptr<DTypeConstructor> nil =
+ std::make_shared<DTypeConstructor>("nil");
list.addConstructor(nil);
// add another constructor to list datatype resulting in an
// "otherNil-list"
- DatatypeConstructor otherNil("otherNil");
+ std::shared_ptr<DTypeConstructor> otherNil =
+ std::make_shared<DTypeConstructor>("otherNil");
list.addConstructor(otherNil);
- vector<Datatype> dts;
+ vector<DType> dts;
dts.push_back(tree);
dts.push_back(list);
// remake the types
- vector<DatatypeType> dtts2 = d_em->mkMutualDatatypeTypes(dts);
-
- TS_ASSERT(! dtts2[0].getDatatype().isFinite());
- TS_ASSERT(dtts2[0].getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
- TS_ASSERT(dtts2[0].getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << dtts2[0].getDatatype().getName() << endl
+ vector<TypeNode> dtts2 = d_nm->mkMutualDatatypeTypes(dts, unresolvedTypes);
+
+ TS_ASSERT(!dtts2[0].getDType().isFinite());
+ TS_ASSERT(
+ dtts2[0].getDType().getCardinality().compare(Cardinality::INTEGERS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(dtts2[0].getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << dtts2[0].getDType().getName()
+ << endl
<< " is " << dtts2[0].mkGroundTerm() << endl;
TS_ASSERT(dtts2[0].mkGroundTerm().getType() == dtts2[0]);
- TS_ASSERT(! dtts2[1].getDatatype().isParametric());
- TS_ASSERT(! dtts2[1].getDatatype().isFinite());
- TS_ASSERT(dtts2[1].getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
- TS_ASSERT(dtts2[1].getDatatype().isWellFounded());
- Debug("groundterms") << "ground term of " << dtts2[1].getDatatype().getName() << endl
+ TS_ASSERT(!dtts2[1].getDType().isParametric());
+ TS_ASSERT(!dtts2[1].getDType().isFinite());
+ TS_ASSERT(
+ dtts2[1].getDType().getCardinality().compare(Cardinality::INTEGERS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(dtts2[1].getDType().isWellFounded());
+ Debug("groundterms") << "ground term of " << dtts2[1].getDType().getName()
+ << endl
<< " is " << dtts2[1].mkGroundTerm() << endl;
TS_ASSERT(dtts2[1].mkGroundTerm().getType() == dtts2[1]);
}
void testNotSoWellFounded() {
- Datatype tree(d_em, "tree");
+ DType tree("tree");
- DatatypeConstructor node("node");
- node.addArg("left", DatatypeSelfType());
- node.addArg("right", DatatypeSelfType());
+ std::shared_ptr<DTypeConstructor> node =
+ std::make_shared<DTypeConstructor>("node");
+ node->addArgSelf("left");
+ node->addArgSelf("right");
tree.addConstructor(node);
Debug("datatypes") << tree << std::endl;
- DatatypeType treeType = d_em->mkDatatypeType(tree);
+ TypeNode treeType = d_nm->mkDatatypeType(tree);
Debug("datatypes") << treeType << std::endl;
- TS_ASSERT(! treeType.getDatatype().isParametric());
- TS_ASSERT(! treeType.getDatatype().isFinite());
- TS_ASSERT(treeType.getDatatype().getCardinality().compare(Cardinality::INTEGERS) == Cardinality::EQUAL);
- TS_ASSERT(! treeType.getDatatype().isWellFounded());
- TS_ASSERT_THROWS_ANYTHING( treeType.mkGroundTerm() );
- TS_ASSERT_THROWS_ANYTHING( treeType.getDatatype().mkGroundTerm( treeType ) );
+ TS_ASSERT(!treeType.getDType().isParametric());
+ TS_ASSERT(!treeType.getDType().isFinite());
+ TS_ASSERT(
+ treeType.getDType().getCardinality().compare(Cardinality::INTEGERS)
+ == Cardinality::EQUAL);
+ TS_ASSERT(!treeType.getDType().isWellFounded());
+ TS_ASSERT(treeType.mkGroundTerm().isNull());
+ TS_ASSERT(treeType.getDType().mkGroundTerm(treeType).isNull());
}
- void testParametricDatatype() {
- vector<Type> v;
- Type t1, t2;
- v.push_back(t1 = d_em->mkSort("T1"));
- v.push_back(t2 = d_em->mkSort("T2"));
- Datatype pair(d_em, "pair", v);
-
- DatatypeConstructor mkpair("mk-pair");
- mkpair.addArg("first", t1);
- mkpair.addArg("second", t2);
+ void testParametricDType()
+ {
+ vector<TypeNode> v;
+ TypeNode t1, t2;
+ v.push_back(t1 = d_nm->mkSort("T1"));
+ v.push_back(t2 = d_nm->mkSort("T2"));
+ DType pair("pair", v);
+
+ std::shared_ptr<DTypeConstructor> mkpair =
+ std::make_shared<DTypeConstructor>("mk-pair");
+ mkpair->addArg("first", t1);
+ mkpair->addArg("second", t2);
pair.addConstructor(mkpair);
- DatatypeType pairType = d_em->mkDatatypeType(pair);
+ TypeNode pairType = d_nm->mkDatatypeType(pair);
- TS_ASSERT(pairType.getDatatype().isParametric());
+ TS_ASSERT(pairType.getDType().isParametric());
v.clear();
- v.push_back(d_em->integerType());
- v.push_back(d_em->integerType());
- DatatypeType pairIntInt = pairType.getDatatype().getDatatypeType(v);
+ v.push_back(d_nm->integerType());
+ v.push_back(d_nm->integerType());
+ TypeNode pairIntInt = pairType.getDType().getTypeNode(v);
v.clear();
- v.push_back(d_em->realType());
- v.push_back(d_em->realType());
- DatatypeType pairRealReal = pairType.getDatatype().getDatatypeType(v);
+ v.push_back(d_nm->realType());
+ v.push_back(d_nm->realType());
+ TypeNode pairRealReal = pairType.getDType().getTypeNode(v);
v.clear();
- v.push_back(d_em->realType());
- v.push_back(d_em->integerType());
- DatatypeType pairRealInt = pairType.getDatatype().getDatatypeType(v);
+ v.push_back(d_nm->realType());
+ v.push_back(d_nm->integerType());
+ TypeNode pairRealInt = pairType.getDType().getTypeNode(v);
v.clear();
- v.push_back(d_em->integerType());
- v.push_back(d_em->realType());
- DatatypeType pairIntReal = pairType.getDatatype().getDatatypeType(v);
+ v.push_back(d_nm->integerType());
+ v.push_back(d_nm->realType());
+ TypeNode pairIntReal = pairType.getDType().getTypeNode(v);
TS_ASSERT_DIFFERS(pairIntInt, pairRealReal);
TS_ASSERT_DIFFERS(pairIntReal, pairRealReal);
TS_ASSERT(!pairRealInt.isSubtypeOf(pairIntInt));
TS_ASSERT(pairIntInt.isSubtypeOf(pairIntInt));
- TS_ASSERT_EQUALS(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairRealReal), TypeNode::fromType(pairRealReal)).toType(), pairRealReal);
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairIntReal), TypeNode::fromType(pairRealReal)).isNull());
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairRealInt), TypeNode::fromType(pairRealReal)).isNull());
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairIntInt), TypeNode::fromType(pairRealReal)).isNull());
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairRealReal), TypeNode::fromType(pairRealInt)).isNull());
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairIntReal), TypeNode::fromType(pairRealInt)).isNull());
- TS_ASSERT_EQUALS(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairRealInt), TypeNode::fromType(pairRealInt)).toType(), pairRealInt);
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairIntInt), TypeNode::fromType(pairRealInt)).isNull());
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairRealReal), TypeNode::fromType(pairIntReal)).isNull());
- TS_ASSERT_EQUALS(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairIntReal), TypeNode::fromType(pairIntReal)).toType(), pairIntReal);
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairRealInt), TypeNode::fromType(pairIntReal)).isNull());
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairIntInt), TypeNode::fromType(pairIntReal)).isNull());
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairRealReal), TypeNode::fromType(pairIntInt)).isNull());
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairIntReal), TypeNode::fromType(pairIntInt)).isNull());
- TS_ASSERT(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairRealInt), TypeNode::fromType(pairIntInt)).isNull());
- TS_ASSERT_EQUALS(TypeNode::leastCommonTypeNode(TypeNode::fromType(pairIntInt), TypeNode::fromType(pairIntInt)).toType(), pairIntInt);
+ TS_ASSERT_EQUALS(TypeNode::leastCommonTypeNode(pairRealReal, pairRealReal),
+ pairRealReal);
+ TS_ASSERT(
+ TypeNode::leastCommonTypeNode(pairIntReal, pairRealReal).isNull());
+ TS_ASSERT(
+ TypeNode::leastCommonTypeNode(pairRealInt, pairRealReal).isNull());
+ TS_ASSERT(TypeNode::leastCommonTypeNode(pairIntInt, pairRealReal).isNull());
+ TS_ASSERT(
+ TypeNode::leastCommonTypeNode(pairRealReal, pairRealInt).isNull());
+ TS_ASSERT(TypeNode::leastCommonTypeNode(pairIntReal, pairRealInt).isNull());
+ TS_ASSERT_EQUALS(TypeNode::leastCommonTypeNode(pairRealInt, pairRealInt),
+ pairRealInt);
+ TS_ASSERT(TypeNode::leastCommonTypeNode(pairIntInt, pairRealInt).isNull());
+ TS_ASSERT(
+ TypeNode::leastCommonTypeNode(pairRealReal, pairIntReal).isNull());
+ TS_ASSERT_EQUALS(TypeNode::leastCommonTypeNode(pairIntReal, pairIntReal),
+ pairIntReal);
+ TS_ASSERT(TypeNode::leastCommonTypeNode(pairRealInt, pairIntReal).isNull());
+ TS_ASSERT(TypeNode::leastCommonTypeNode(pairIntInt, pairIntReal).isNull());
+ TS_ASSERT(TypeNode::leastCommonTypeNode(pairRealReal, pairIntInt).isNull());
+ TS_ASSERT(TypeNode::leastCommonTypeNode(pairIntReal, pairIntInt).isNull());
+ TS_ASSERT(TypeNode::leastCommonTypeNode(pairRealInt, pairIntInt).isNull());
+ TS_ASSERT_EQUALS(TypeNode::leastCommonTypeNode(pairIntInt, pairIntInt),
+ pairIntInt);
}
private:
api::Solver* d_slv;
- ExprManager* d_em;
- ExprManagerScope* d_scope;
-};/* class DatatypeBlack */
+ NodeManager* d_nm;
+ NodeManagerScope* d_scope;
+}; /* class DTypeBlack */