CVC4_API_SOLVER_CHECK_SORT(sort);
return mkValHelper<CVC4::UninterpretedConstant>(
- CVC4::UninterpretedConstant(*sort.d_type, index));
+ CVC4::UninterpretedConstant(TypeNode::fromType(*sort.d_type), index));
CVC4_API_SOLVER_TRY_CATCH_END;
}
#include <string>
#include "base/check.h"
+#include "expr/type_node.h"
using namespace std;
namespace CVC4 {
-UninterpretedConstant::UninterpretedConstant(Type type, Integer index)
- : d_type(type), d_index(index)
+UninterpretedConstant::UninterpretedConstant(const TypeNode& type,
+ Integer index)
+ : d_type(new TypeNode(type)), d_index(index)
{
//PrettyCheckArgument(type.isSort(), type, "uninterpreted constants can only be created for uninterpreted sorts, not `%s'", type.toString().c_str());
PrettyCheckArgument(index >= 0, index, "index >= 0 required for uninterpreted constant index, not `%s'", index.toString().c_str());
}
+UninterpretedConstant::~UninterpretedConstant() {}
+
+UninterpretedConstant::UninterpretedConstant(const UninterpretedConstant& other)
+ : d_type(new TypeNode(other.getType())), d_index(other.getIndex())
+{
+}
+
+const TypeNode& UninterpretedConstant::getType() const { return *d_type; }
+const Integer& UninterpretedConstant::getIndex() const { return d_index; }
+bool UninterpretedConstant::operator==(const UninterpretedConstant& uc) const
+{
+ return getType() == uc.getType() && d_index == uc.d_index;
+}
+bool UninterpretedConstant::operator!=(const UninterpretedConstant& uc) const
+{
+ return !(*this == uc);
+}
+
+bool UninterpretedConstant::operator<(const UninterpretedConstant& uc) const
+{
+ return getType() < uc.getType()
+ || (getType() == uc.getType() && d_index < uc.d_index);
+}
+bool UninterpretedConstant::operator<=(const UninterpretedConstant& uc) const
+{
+ return getType() < uc.getType()
+ || (getType() == uc.getType() && d_index <= uc.d_index);
+}
+bool UninterpretedConstant::operator>(const UninterpretedConstant& uc) const
+{
+ return !(*this <= uc);
+}
+bool UninterpretedConstant::operator>=(const UninterpretedConstant& uc) const
+{
+ return !(*this < uc);
+}
+
std::ostream& operator<<(std::ostream& out, const UninterpretedConstant& uc) {
std::stringstream ss;
ss << uc.getType();
return out << "uc_" << st.c_str() << "_" << uc.getIndex();
}
+size_t UninterpretedConstantHashFunction::operator()(
+ const UninterpretedConstant& uc) const
+{
+ return TypeNodeHashFunction()(uc.getType())
+ * IntegerHashFunction()(uc.getIndex());
+}
+
}/* CVC4 namespace */
#include "cvc4_public.h"
-#pragma once
+#ifndef CVC4__UNINTERPRETED_CONSTANT_H
+#define CVC4__UNINTERPRETED_CONSTANT_H
#include <iosfwd>
+#include <memory>
-#include "expr/type.h"
+#include "util/integer.h"
namespace CVC4 {
-class CVC4_PUBLIC UninterpretedConstant {
+class TypeNode;
+
+class UninterpretedConstant
+{
public:
- UninterpretedConstant(Type type, Integer index);
+ UninterpretedConstant(const TypeNode& type, Integer index);
+ ~UninterpretedConstant();
- Type getType() const { return d_type; }
- const Integer& getIndex() const { return d_index; }
- bool operator==(const UninterpretedConstant& uc) const
- {
- return d_type == uc.d_type && d_index == uc.d_index;
- }
- bool operator!=(const UninterpretedConstant& uc) const
- {
- return !(*this == uc);
- }
+ UninterpretedConstant(const UninterpretedConstant& other);
- bool operator<(const UninterpretedConstant& uc) const
- {
- return d_type < uc.d_type ||
- (d_type == uc.d_type && d_index < uc.d_index);
- }
- bool operator<=(const UninterpretedConstant& uc) const
- {
- return d_type < uc.d_type ||
- (d_type == uc.d_type && d_index <= uc.d_index);
- }
- bool operator>(const UninterpretedConstant& uc) const
- {
- return !(*this <= uc);
- }
- bool operator>=(const UninterpretedConstant& uc) const
- {
- return !(*this < uc);
- }
+ const TypeNode& getType() const;
+ const Integer& getIndex() const;
+ bool operator==(const UninterpretedConstant& uc) const;
+ bool operator!=(const UninterpretedConstant& uc) const;
+ bool operator<(const UninterpretedConstant& uc) const;
+ bool operator<=(const UninterpretedConstant& uc) const;
+ bool operator>(const UninterpretedConstant& uc) const;
+ bool operator>=(const UninterpretedConstant& uc) const;
private:
- const Type d_type;
+ std::unique_ptr<TypeNode> d_type;
const Integer d_index;
-};/* class UninterpretedConstant */
+}; /* class UninterpretedConstant */
-std::ostream& operator<<(std::ostream& out, const UninterpretedConstant& uc) CVC4_PUBLIC;
+std::ostream& operator<<(std::ostream& out, const UninterpretedConstant& uc);
/**
* Hash function for the BitVector constants.
*/
-struct CVC4_PUBLIC UninterpretedConstantHashFunction {
- inline size_t operator()(const UninterpretedConstant& uc) const {
- return TypeHashFunction()(uc.getType()) * IntegerHashFunction()(uc.getIndex());
- }
-};/* struct UninterpretedConstantHashFunction */
+struct CVC4_PUBLIC UninterpretedConstantHashFunction
+{
+ size_t operator()(const UninterpretedConstant& uc) const;
+}; /* struct UninterpretedConstantHashFunction */
+
+} // namespace CVC4
-}/* CVC4 namespace */
+#endif /* CVC4__UNINTERPRETED_CONSTANT_H */
class UninterpretedConstantTypeRule {
public:
inline static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check) {
- return TypeNode::fromType(n.getConst<UninterpretedConstant>().getType());
+ return n.getConst<UninterpretedConstant>().getType();
}
};/* class UninterpretedConstantTypeRule */
if(isFinished()) {
throw NoMoreValuesException(getType());
}
- return NodeManager::currentNM()->mkConst(UninterpretedConstant(getType().toType(), d_count));
+ return NodeManager::currentNM()->mkConst(
+ UninterpretedConstant(getType(), d_count));
}
UninterpretedSortEnumerator& operator++() override
{
int debruijn = depth - it->second - 1;
return NodeManager::currentNM()->mkConst(
- UninterpretedConstant(n.getType().toType(), debruijn));
+ UninterpretedConstant(n.getType(), debruijn));
}
std::vector<Node> children;
bool childChanged = false;
std::map< Node, int >::iterator itv = vmap.find( n );
if( itv!=vmap.end() ){
int debruijn = depth - 1 - itv->second;
- return NodeManager::currentNM()->mkConst(UninterpretedConstant(n.getType().toType(), debruijn));
+ return NodeManager::currentNM()->mkConst(
+ UninterpretedConstant(n.getType(), debruijn));
}else if( n.getType().isDatatype() ){
Node nc = eqc_cons[n];
if( !nc.isNull() ){
if (d_child_enum)
{
ret = NodeManager::currentNM()->mkConst(
- UninterpretedConstant(d_type.toType(), d_size_limit));
+ UninterpretedConstant(d_type, d_size_limit));
}
else
{
#ifdef CVC4_ASSERTIONS
RewriteResponse r2 =
d_theoryRewriters[newTheoryId]->postRewrite(response.d_node);
- Assert(r2.d_node == response.d_node);
+ Assert(r2.d_node == response.d_node)
+ << r2.d_node << " != " << response.d_node;
#endif
rewriteStackTop.d_node = response.d_node;
break;
void testSetOfUF()
{
- TypeNode typeNode = d_nm->mkSort("Atom");
- Type sort = typeNode.toType();
- SetEnumerator setEnumerator(d_nm->mkSetType(typeNode));
+ TypeNode sort = d_nm->mkSort("Atom");
+ SetEnumerator setEnumerator(d_nm->mkSetType(sort));
Node actual0 = *setEnumerator;
- Node expected0 =
- d_nm->mkConst(EmptySet(d_nm->mkSetType(typeNode)));
+ Node expected0 = d_nm->mkConst(EmptySet(d_nm->mkSetType(sort)));
TS_ASSERT_EQUALS(expected0, actual0);
TS_ASSERT(!setEnumerator.isFinished());
}
void testUF() {
- TypeNode sortn = d_nm->mkSort("T");
- Type sort = sortn.toType();
- TypeNode sortn2 = d_nm->mkSort("U");
- Type sort2 = sortn2.toType();
- TypeEnumerator te(sortn);
+ TypeNode sort = d_nm->mkSort("T");
+ TypeNode sort2 = d_nm->mkSort("U");
+ TypeEnumerator te(sort);
TS_ASSERT_EQUALS(*te, d_nm->mkConst(UninterpretedConstant(sort, 0)));
for(size_t i = 1; i < 100; ++i) {
TS_ASSERT_DIFFERS(*te, d_nm->mkConst(UninterpretedConstant(sort, i)));
ArrayStoreAll(d_nm->mkArrayType(d_nm->integerType(), d_nm->realType()),
d_nm->mkConst(Rational(9, 2)));
ArrayStoreAll(d_nm->mkArrayType(d_nm->mkSort("U"), usort),
- d_nm->mkConst(UninterpretedConstant(usort.toType(), 0)));
+ d_nm->mkConst(UninterpretedConstant(usort, 0)));
ArrayStoreAll(d_nm->mkArrayType(d_nm->mkBitVectorType(8), d_nm->realType()),
d_nm->mkConst(Rational(0)));
ArrayStoreAll(
{
TS_ASSERT_THROWS(ArrayStoreAll(d_nm->integerType(),
d_nm->mkConst(UninterpretedConstant(
- d_nm->mkSort("U").toType(), 0))),
+ d_nm->mkSort("U"), 0))),
IllegalArgumentException&);
TS_ASSERT_THROWS(
ArrayStoreAll(d_nm->integerType(), d_nm->mkConst(Rational(9, 2))),