This further introduces TypeNode::isInstantiatedUninterpretedSort().
CVC5_API_TRY_CATCH_END;
}
+Sort Sort::getUninterpretedSortConstructor() const
+{
+ CVC5_API_TRY_CATCH_BEGIN;
+ CVC5_API_CHECK_NOT_NULL;
+ CVC5_API_CHECK(d_type->isInstantiatedUninterpretedSort())
+ << "Expected instantiated uninterpreted sort.";
+ //////// all checks before this line
+ return Sort(d_solver, d_type->getUninterpretedSortConstructor());
+ ////////
+ CVC5_API_TRY_CATCH_END;
+}
+
Datatype Sort::getDatatype() const
{
CVC5_API_TRY_CATCH_BEGIN;
*/
bool isInstantiated() const;
+ /**
+ * Get the associated uninterpreted sort constructor of an instantiated
+ * uninterpreted sort.
+ *
+ * @return the uninterpreted sort constructor sort
+ */
+ Sort getUninterpretedSortConstructor() const;
+
/**
* @return the underlying datatype of a datatype sort
*/
*/
bool isUninterpretedSortParameterized() const;
- /* Sort constructor sort ----------------------------------------------- */
+ /* Uninterpreted sort constructor sort --------------------------------- */
/**
* @return the arity of an uninterpreted sort constructor sort
private native boolean isInstantiated(long pointer);
+ /**
+ * Get the associated uninterpreted sort constructor of an instantiated
+ * uninterpreted sort.
+ *
+ * @return the uninterpreted sort constructor sort
+ */
+ public Sort getUninterpretedSortConstructor()
+ {
+ long sortPointer = getUninterpretedSortConstructor(pointer);
+ return new Sort(solver, sortPointer);
+ }
+
+ private native long getUninterpretedSortConstructor(long pointer);
+
/**
* @return the underlying datatype of a datatype sort
*/
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, nullptr);
}
+/*
+ * Class: io_github_cvc5_api_Sort
+ * Method: getUninterpretedSortConstructor
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL
+Java_io_github_cvc5_api_Sort_getUninterpretedSortConstructor(JNIEnv* env,
+ jobject,
+ jlong pointer)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Sort* current = reinterpret_cast<Sort*>(pointer);
+ Sort* retPointer = new Sort(current->getUninterpretedSortConstructor());
+ return reinterpret_cast<jlong>(retPointer);
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
+}
+
/*
* Class: io_github_cvc5_api_Sort
* Method: getDatatype
bint isUninterpretedSort() except +
bint isUninterpretedSortConstructor() except +
bint isInstantiated() except +
+ Sort getUninterpretedSortConstructor() except +
Datatype getDatatype() except +
Sort instantiate(const vector[Sort]& params) except +
vector[Sort] getInstantiatedParameters() except +
"""
return self.csort.isInstantiated()
+ def getUninterpretedSortConstructor(self):
+ """
+ Get the associated uninterpreted sort constructor of an
+ instantiated uninterpreted sort.
+
+ :return: the uninterpreted sort constructor sort
+ """
+ cdef Sort sort = Sort(self.solver)
+ sort.csort = self.csort.getUninterpretedSortConstructor()
+ return sort
+
def getDatatype(self):
"""
:return: the underlying datatype of a datatype sort
return true;
}
+bool TypeNode::isInstantiatedUninterpretedSort() const
+{
+ return isUninterpretedSort() && getNumChildren() > 0;
+}
+
bool TypeNode::isInstantiated() const
{
- return isInstantiatedDatatype()
- || (isUninterpretedSort() && getNumChildren() > 0);
+ return isInstantiatedDatatype() || isInstantiatedUninterpretedSort();
}
TypeNode TypeNode::instantiate(const std::vector<TypeNode>& params) const
return getAttribute(expr::VarNameAttr());
}
+TypeNode TypeNode::getUninterpretedSortConstructor() const
+{
+ Assert(isInstantiatedUninterpretedSort());
+ NodeBuilder nb(kind::SORT_TYPE);
+ nb << NodeManager::operatorFromType(*this);
+ return nb.constructTypeNode();
+}
+
bool TypeNode::isParameterInstantiatedDatatype(size_t n) const
{
Assert(getKind() == kind::PARAMETRIC_DATATYPE);
}
/**
- * Very basic pretty printer for Node.
+ * Very basic pretty printer for TypeNode.
*
* @param out output stream to print to.
* @param indent number of spaces to indent the formula by.
/** Is this a fully instantiated datatype type */
bool isInstantiatedDatatype() const;
+ /**
+ * Is this an uninterpreted sort constructed from instantiating an
+ * uninterpreted sort constructor?
+ */
+ bool isInstantiatedUninterpretedSort() const;
+
/**
* Return true if this is an instantiated parametric datatype or
* uninterpreted sort constructor type.
*/
std::string getName() const;
+ /**
+ * Get the uninterpreted sort constructor type this instantiated
+ * uninterpreted sort has been constructed from.
+ *
+ * Asserts that this is an instantiated uninterpreted sort.
+ */
+ TypeNode getUninterpretedSortConstructor() const;
+
/** Get the most general base type of the type */
TypeNode getBaseType() const;
ASSERT_THROW(bvSort.getInstantiatedParameters(), CVC5ApiException);
}
+TEST_F(TestApiBlackSort, getUninterpretedSortConstructor)
+{
+ Sort intSort = d_solver.getIntegerSort();
+ Sort realSort = d_solver.getRealSort();
+ Sort boolSort = d_solver.getBooleanSort();
+ Sort bvSort = d_solver.mkBitVectorSort(8);
+ Sort sortConsSort = d_solver.mkUninterpretedSortConstructorSort("s", 4);
+ ASSERT_THROW(sortConsSort.getUninterpretedSortConstructor(),
+ CVC5ApiException);
+ Sort instSortConsSort =
+ sortConsSort.instantiate({boolSort, intSort, bvSort, realSort});
+ ASSERT_EQ(sortConsSort, instSortConsSort.getUninterpretedSortConstructor());
+}
+
TEST_F(TestApiBlackSort, getFunctionArity)
{
Sort funSort = d_solver.mkFunctionSort(d_solver.mkUninterpretedSort("u"),
assertThrows(CVC5ApiException.class, () -> bvSort.getInstantiatedParameters());
}
+ @Test void getUninterpretedSortConstructor() throws CVC5ApiException
+ {
+ Sort intSort = d_solver.getIntegerSort();
+ Sort realSort = d_solver.getRealSort();
+ Sort boolSort = d_solver.getBooleanSort();
+ Sort bvSort = d_solver.mkBitVectorSort(8);
+ Sort sortConsSort = d_solver.mkUninterpretedSortConstructorSort("s", 4);
+ assertThrows(CVC5ApiException.class, () -> sortConsSort.getUninterpretedSortConstructor());
+ Sort instSortConsSort =
+ sortConsSort.instantiate(new Sort[] {boolSort, intSort, bvSort, realSort});
+ assertEquals(sortConsSort, instSortConsSort.getUninterpretedSortConstructor());
+ }
+
@Test void getFunctionArity() throws CVC5ApiException
{
Sort funSort =
with pytest.raises(RuntimeError):
bvSort.getInstantiatedParameters()
+def test_get_uninterpreted_sort_constructor(solver):
+ intSort = solver.getIntegerSort()
+ realSort = solver.getRealSort()
+ boolSort = solver.getBooleanSort()
+ bvSort = solver.mkBitVectorSort(8)
+ sortConsSort = solver.mkUninterpretedSortConstructorSort("s", 4)
+ with pytest.raises(RuntimeError):
+ sortConsSort.getUninterpretedSortConstructor()
+ instSortConsSort = \
+ sortConsSort.instantiate([boolSort, intSort, bvSort, realSort]);
+ assert sortConsSort == instSortConsSort.getUninterpretedSortConstructor()
+
def test_get_function_arity(solver):
funSort = solver.mkFunctionSort(solver.mkUninterpretedSort("u"),
solver.getIntegerSort())