return d_typeNode->isParametricDatatype();
}
+Expr DatatypeType::getConstructor(std::string name) const {
+ return getDatatype().getConstructor(name);
+}
+
bool DatatypeType::isInstantiated() const {
return d_typeNode->isInstantiatedDatatype();
}
/** Instantiate a sort using this sort constructor */
SortType instantiate(const std::vector<Type>& params) const;
+
};/* class SortConstructorType */
/**
* @return the width of the bit-vector type (> 0)
*/
unsigned getSize() const;
+
};/* class BitVectorType */
/** Is this datatype parametric? */
bool isParametric() const;
+ /**
+ * Get the constructor operator associated to the given constructor
+ * name in this datatype.
+ */
+ Expr getConstructor(std::string name) const;
+
/**
* Has this datatype been fully instantiated ?
*
return d_constructors[index];
}
+const Datatype::Constructor& Datatype::operator[](std::string name) const {
+ for(const_iterator i = begin(); i != end(); ++i) {
+ if((*i).getName() == name) {
+ return *i;
+ }
+ }
+ CheckArgument(false, name, "No such constructor `%s' of datatype `%s'", name.c_str(), d_name.c_str());
+}
+
+Expr Datatype::getConstructor(std::string name) const {
+ return (*this)[name].getConstructor();
+}
+
void Datatype::Constructor::resolve(ExprManager* em, DatatypeType self,
const std::map<std::string, DatatypeType>& resolutions,
const std::vector<Type>& placeholders,
return d_args[index];
}
+const Datatype::Constructor::Arg& Datatype::Constructor::operator[](std::string name) const {
+ for(const_iterator i = begin(); i != end(); ++i) {
+ if((*i).getName() == name) {
+ return *i;
+ }
+ }
+ CheckArgument(false, name, "No such arg `%s' of constructor `%s'", name.c_str(), d_name.c_str());
+}
+
+Expr Datatype::Constructor::getSelector(std::string name) const {
+ return (*this)[name].getSelector();
+}
+
Datatype::Constructor::Arg::Arg(std::string name, Expr selector) :
d_name(name),
d_selector(selector),
const std::vector< SortConstructorType >& paramTypes,
const std::vector< DatatypeType >& paramReplacements);
public:
+ /**
+ * Create a new Datatype constructor with the given name for the
+ * constructor and the same name (prefixed with "is_") for the
+ * tester. The actual constructor and tester aren't created until
+ * resolution time.
+ */
+ explicit Constructor(std::string name);
+
/**
* Create a new Datatype constructor with the given name for the
* constructor and the given name for the tester. The actual
/** Get the name of this Datatype constructor. */
std::string getName() const throw();
+
/**
* Get the constructor operator of this Datatype constructor. The
* Datatype must be resolved.
*/
Expr getConstructor() const;
+
/**
* Get the tester operator of this Datatype constructor. The
* Datatype must be resolved.
*/
Expr getTester() const;
+
/**
* Get the number of arguments (so far) of this Datatype constructor.
*/
/** Get the ith Constructor arg. */
const Arg& operator[](size_t index) const;
+ /**
+ * Get the Constructor arg named. This is a linear search
+ * through the arguments, so in the case of multiple,
+ * similarly-named arguments, the first is returned.
+ */
+ const Arg& operator[](std::string name) const;
+
+ /**
+ * Get the selector named. This is a linear search
+ * through the arguments, so in the case of multiple,
+ * similarly-named arguments, the selector for the first
+ * is returned.
+ */
+ Expr getSelector(std::string name) const;
+
};/* class Datatype::Constructor */
/** The type for iterators over constructors. */
/** Get the ith Constructor. */
const Constructor& operator[](size_t index) const;
+ /**
+ * Get the Constructor named. This is a linear search
+ * through the constructors, so in the case of multiple,
+ * similarly-named constructors, the first is returned.
+ */
+ const Constructor& operator[](std::string name) const;
+
+ /**
+ * Get the constructor operator for the named constructor.
+ * This Datatype must be resolved.
+ */
+ Expr getConstructor(std::string name) const;
+
};/* class Datatype */
Expr apply = d_em->mkExpr(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().isFinite());
TS_ASSERT(colorsType.getDatatype().getCardinality() == 4);
TS_ASSERT(ctor.getType().getCardinality() == 1);
DatatypeType treeType = d_em->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().isFinite());
TS_ASSERT(treeType.getDatatype().getCardinality() == Cardinality::INTEGERS);
TS_ASSERT(treeType.getDatatype().isWellFounded());