CVC5_API_TRY_CATCH_END;
}
-Term DatatypeConstructor::getSpecializedConstructorTerm(
+Term DatatypeConstructor::getInstantiatedConstructorTerm(
const Sort& retSort) const
{
CVC5_API_TRY_CATCH_BEGIN;
CVC5_API_TRY_CATCH_END;
}
+std::vector<Sort> Datatype::getParameters() const
+{
+ CVC5_API_TRY_CATCH_BEGIN;
+ CVC5_API_CHECK_NOT_NULL;
+ CVC5_API_CHECK(isParametric()) << "Expected parametric datatype";
+ //////// all checks before this line
+ std::vector<cvc5::TypeNode> params = d_dtype->getParameters();
+ return Sort::typeNodeVectorToSorts(d_solver, params);
+ ////////
+ CVC5_API_TRY_CATCH_END;
+}
+
bool Datatype::isParametric() const
{
CVC5_API_TRY_CATCH_BEGIN;
friend class DatatypeConstructorDecl;
friend class DatatypeSelector;
friend class DatatypeDecl;
+ friend class Datatype;
friend class Op;
friend class Solver;
friend class Grammar;
bool isDatatype() const;
/**
- * Is this a parametric datatype sort?
+ * Is this a parametric datatype sort? A parametric datatype sort is either
+ * one that is returned by a call to Solver::mkDatatypeSort() or Solver::mkDatatypeSorts() for a
+ * parametric datatype, or an instantiated datatype sort returned by
+ * Sort::instantiate() for parametric datatype sort `s`.
* @return true if the sort is a parametric datatype sort
*/
bool isParametricDatatype() const;
* @param retSort the desired return sort of the constructor
* @return the constructor term
*/
- Term getSpecializedConstructorTerm(const Sort& retSort) const;
+ Term getInstantiatedConstructorTerm(const Sort& retSort) const;
/**
* Get the tester operator of this datatype constructor.
/** @return the number of constructors for this Datatype. */
size_t getNumConstructors() const;
+ /**
+ * @return the parameters of this datatype, if it is parametric. An exception
+ * is thrown if this datatype is not parametric.
+ */
+ std::vector<Sort> getParameters() const;
+
/** @return true if this datatype is parametric */
bool isParametric() const;
private native int getNumConstructors(long pointer);
+ /**
+ * @return the parameters of this datatype, if it is parametric. An exception
+ * is thrown if this datatype is not parametric.
+ */
+ public Sort[] getParameters() {
+ long[] sortPointers = getParameters(pointer);
+ Sort[] sorts = Utils.getSorts(solver, sortPointers);
+ return sorts;
+ }
+
+ private native long[] getParameters(long pointer);
+
/** @return true if this datatype is parametric */
public boolean isParametric()
{
* @param retSort the desired return sort of the constructor
* @return the constructor term
*/
- public Term getSpecializedConstructorTerm(Sort retSort)
- {
- long termPointer = getSpecializedConstructorTerm(pointer, retSort.getPointer());
+ public Term getInstantiatedConstructorTerm(Sort retSort) {
+ long termPointer =
+ getInstantiatedConstructorTerm(pointer, retSort.getPointer());
return new Term(solver, termPointer);
}
- private native long getSpecializedConstructorTerm(long pointer, long retSortPointer);
+ private native long getInstantiatedConstructorTerm(
+ long pointer, long retSortPointer);
/**
* Get the tester operator of this datatype constructor.
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
}
+/*
+ * Class: io_github_cvc5_api_Datatype
+ * Method: getParameters
+ * Signature: (J)[J
+ */
+JNIEXPORT jlongArray JNICALL Java_io_github_cvc5_api_Datatype_getParameters(
+ JNIEnv* env, jobject, jlong pointer)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Datatype* current = (Datatype*)pointer;
+ std::vector<Sort> sorts = current->getParameters();
+ std::vector<jlong> sortPointers(sorts.size());
+ for (size_t i = 0; i < sorts.size(); i++)
+ {
+ sortPointers[i] = reinterpret_cast<jlong>(new Sort(sorts[i]));
+ }
+ jlongArray ret = env->NewLongArray(sorts.size());
+ env->SetLongArrayRegion(ret, 0, sorts.size(), sortPointers.data());
+ return ret;
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, nullptr);
+}
+
/*
* Class: io_github_cvc5_api_Datatype
* Method: isParametric
/*
* Class: io_github_cvc5_api_DatatypeConstructor
- * Method: getSpecializedConstructorTerm
+ * Method: getInstantiatedConstructorTerm
* Signature: (JJ)J
*/
JNIEXPORT jlong JNICALL
-Java_io_github_cvc5_api_DatatypeConstructor_getSpecializedConstructorTerm(
+Java_io_github_cvc5_api_DatatypeConstructor_getInstantiatedConstructorTerm(
JNIEnv* env, jobject, jlong pointer, jlong retSortPointer)
{
CVC5_JAVA_API_TRY_CATCH_BEGIN;
DatatypeConstructor* current = (DatatypeConstructor*)pointer;
Sort* sort = (Sort*)retSortPointer;
- Term* retPointer = new Term(current->getSpecializedConstructorTerm(*sort));
+ Term* retPointer = new Term(current->getInstantiatedConstructorTerm(*sort));
return (jlong)retPointer;
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
}
DatatypeSelector getSelector(const string& name) except +
string getName() except +
size_t getNumConstructors() except +
+ vector[Sort] getParameters() except +
bint isParametric() except +
bint isCodatatype() except +
bint isTuple() except +
DatatypeSelector operator[](const string& name) except +
string getName() except +
Term getConstructorTerm() except +
- Term getSpecializedConstructorTerm(const Sort& retSort) except +
+ Term getInstantiatedConstructorTerm(const Sort& retSort) except +
Term getTesterTerm() except +
size_t getNumSelectors() except +
DatatypeSelector getSelector(const string& name) except +
"""
return self.cd.getNumConstructors()
+ def getParameters(self):
+ """
+ :return: the parameters of this datatype, if it is parametric. An
+ exception is thrown if this datatype is not parametric.
+ """
+ param_sorts = []
+ for s in self.cd.getParameters():
+ sort = Sort(self.solver)
+ sort.csort = s
+ param_sorts.append(sort)
+ return param_sorts
+
def isParametric(self):
""":return: True if this datatype is parametric."""
return self.cd.isParametric()
term.cterm = self.cdc.getConstructorTerm()
return term
- def getSpecializedConstructorTerm(self, Sort retSort):
+ def getInstantiatedConstructorTerm(self, Sort retSort):
"""
- Specialized method for parametric datatypes (see :cpp:func:`DatatypeConstructor::getSpecializedConstructorTerm() <cvc5::api::DatatypeConstructor::getSpecializedConstructorTerm>`).
+ Specialized method for parametric datatypes (see
+ :cpp:func:`DatatypeConstructor::getInstantiatedConstructorTerm()
+ <cvc5::api::DatatypeConstructor::getInstantiatedConstructorTerm>`).
:param retSort: the desired return sort of the constructor
:return: the constructor operator as a term.
"""
cdef Term term = Term(self.solver)
- term.cterm = self.cdc.getSpecializedConstructorTerm(retSort.csort)
+ term.cterm = self.cdc.getInstantiatedConstructorTerm(retSort.csort)
return term
def getTesterTerm(self):
// lookup by name
api::DatatypeConstructor dc = d.getConstructor(t.toString());
// ask the constructor for the specialized constructor term
- t = dc.getSpecializedConstructorTerm(s);
+ t = dc.getInstantiatedConstructorTerm(s);
}
// the type of t does not match the sort s by design (constructor type
// vs datatype type), thus we use an alternative check here.
{
// lookup constructor by name
api::DatatypeConstructor dc = dt.getConstructor(f.toString());
- api::Term scons = dc.getSpecializedConstructorTerm(expr.getSort());
+ api::Term scons = dc.getInstantiatedConstructorTerm(expr.getSort());
// take the type of the specialized constructor instead
type = scons.getSort();
}
bitIAnd = d_iandUtils.createBitwiseIAndNode(x, y, high_bit, j);
// enforce bitwise equality
lem = nm->mkNode(
- AND, lem, rewrite(d_iandUtils.iextract(high_bit, j, i)).eqNode(bitIAnd));
+ AND,
+ lem,
+ rewrite(d_iandUtils.iextract(high_bit, j, i)).eqNode(bitIAnd));
}
}
return lem;
dtypeSpec.addConstructor(nil);
Sort dtypeSort = d_solver.mkDatatypeSort(dtypeSpec);
Datatype dt = dtypeSort.getDatatype();
+ ASSERT_THROW(dt.getParameters(), CVC5ApiException);
ASSERT_EQ(dt.getName(), std::string("list"));
ASSERT_NO_THROW(dt.getConstructor("nil"));
ASSERT_NO_THROW(dt["cons"]);
Sort pairType = d_solver.mkDatatypeSort(pairSpec);
ASSERT_TRUE(pairType.getDatatype().isParametric());
+ std::vector<Sort> dparams = pairType.getDatatype().getParameters();
+ ASSERT_TRUE(dparams[0] == t1 && dparams[1] == t2);
v.clear();
v.push_back(d_solver.getIntegerSort());
iargs.push_back(isort);
Sort listInt = dtsorts[0].instantiate(iargs);
+ std::vector<Sort> liparams = listInt.getDatatype().getParameters();
+ // the parameter of the datatype is not instantiated
+ ASSERT_TRUE(liparams.size() == 1 && liparams[0] == x);
+
Term testConsTerm;
// get the specialized constructor term for list[Int]
- ASSERT_NO_THROW(testConsTerm = nilc.getSpecializedConstructorTerm(listInt));
+ ASSERT_NO_THROW(testConsTerm = nilc.getInstantiatedConstructorTerm(listInt));
ASSERT_NE(testConsTerm, nilc.getConstructorTerm());
// error to get the specialized constructor term for Int
- ASSERT_THROW(nilc.getSpecializedConstructorTerm(isort), CVC5ApiException);
+ ASSERT_THROW(nilc.getInstantiatedConstructorTerm(isort), CVC5ApiException);
}
} // namespace test
} // namespace cvc5
Sort pairType = d_solver.mkDatatypeSort(pairSpec);
assertTrue(pairType.getDatatype().isParametric());
+ Sort[] dparams = pairType.getDatatype().getParameters();
+ assertTrue(dparams[0].equals(t1) && dparams[1].equals(t2));
v.clear();
v.add(d_solver.getIntegerSort());
AtomicReference<Term> atomicTerm = new AtomicReference<>();
// get the specialized constructor term for list[Int]
- assertDoesNotThrow(() -> atomicTerm.set(nilc.getSpecializedConstructorTerm(listInt)));
+ assertDoesNotThrow(
+ () -> atomicTerm.set(nilc.getInstantiatedConstructorTerm(listInt)));
Term testConsTerm = atomicTerm.get();
assertNotEquals(testConsTerm, nilc.getConstructorTerm());
// error to get the specialized constructor term for Int
- assertThrows(CVC5ApiException.class, () -> nilc.getSpecializedConstructorTerm(isort));
+ assertThrows(CVC5ApiException.class,
+ () -> nilc.getInstantiatedConstructorTerm(isort));
}
}
dtypeSpec.addConstructor(nil)
dtypeSort = solver.mkDatatypeSort(dtypeSpec)
dt = dtypeSort.getDatatype()
+ # not parametric datatype
+ with pytest.raises(RuntimeError): dt.getParameters()
assert not dt.isCodatatype()
assert not dt.isTuple()
assert not dt.isRecord()
v.append(t1)
v.append(t2)
pairSpec = solver.mkDatatypeDecl("pair", v)
-
+
mkpair = solver.mkDatatypeConstructorDecl("mk-pair")
mkpair.addSelector("first", t1)
mkpair.addSelector("second", t2)
pairType = solver.mkDatatypeSort(pairSpec)
assert pairType.getDatatype().isParametric()
+ dparams = pairType.getDatatype().getParameters()
+ assert dparams[0]==t1 and dparams[1]==t2
v.clear()
v.append(solver.getIntegerSort())
testConsTerm = Term(solver)
# get the specialized constructor term for list[Int]
- testConsTerm = nilc.getSpecializedConstructorTerm(listInt)
+ testConsTerm = nilc.getInstantiatedConstructorTerm(listInt)
assert testConsTerm != nilc.getConstructorTerm()
# error to get the specialized constructor term for Int
with pytest.raises(RuntimeError):
- nilc.getSpecializedConstructorTerm(isort)
+ nilc.getInstantiatedConstructorTerm(isort)