CVC5_API_TRY_CATCH_END;
}
+bool Sort::hasSymbol() const
+{
+ CVC5_API_TRY_CATCH_BEGIN;
+ CVC5_API_CHECK_NOT_NULL;
+ //////// all checks before this line
+ return d_type->hasAttribute(expr::VarNameAttr());
+ ////////
+ CVC5_API_TRY_CATCH_END;
+}
+
+std::string Sort::getSymbol() const
+{
+ CVC5_API_TRY_CATCH_BEGIN;
+ CVC5_API_CHECK_NOT_NULL;
+ CVC5_API_CHECK(d_type->hasAttribute(expr::VarNameAttr()))
+ << "Invalid call to '" << __PRETTY_FUNCTION__
+ << "', expected the sort to have a symbol.";
+ //////// all checks before this line
+ return d_type->getAttribute(expr::VarNameAttr());
+ ////////
+ CVC5_API_TRY_CATCH_END;
+}
+
bool Sort::isNull() const
{
CVC5_API_TRY_CATCH_BEGIN;
*/
bool operator>=(const Sort& s) const;
+ /**
+ * @return true if the sort has a symbol.
+ */
+ bool hasSymbol() const;
+
+ /**
+ * Asserts hasSymbol().
+ * @return the raw symbol of the sort.
+ */
+ std::string getSymbol() const;
+
/**
* @return true if this Sort is a null sort.
*/
private native int compareTo(long pointer1, long pointer2);
+ /**
+ * @return true if the sort has a symbol.
+ */
+ public boolean hasSymbol()
+ {
+ return hasSymbol(pointer);
+ }
+
+ private native boolean hasSymbol(long pointer);
+
+ /**
+ * Asserts hasSymbol().
+ * @return the raw symbol of the symbol.
+ */
+ public String getSymbol()
+ {
+ return getSymbol(pointer);
+ }
+
+ private native String getSymbol(long pointer);
+
/**
* @return true if this Sort is a null sort.
*/
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
}
+/*
+ * Class: io_github_cvc5_api_Sort
+ * Method: hasSymbol
+ * Signature: (J)Z
+ */
+JNIEXPORT jboolean JNICALL Java_io_github_cvc5_api_Sort_hasSymbol(JNIEnv* env,
+ jobject,
+ jlong pointer)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Sort* current = reinterpret_cast<Sort*>(pointer);
+ return static_cast<jboolean>(current->hasSymbol());
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, static_cast<jboolean>(false));
+}
+
+/*
+ * Class: io_github_cvc5_api_Sort
+ * Method: getSymbol
+ * Signature: (J)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_io_github_cvc5_api_Sort_getSymbol(JNIEnv* env,
+ jobject,
+ jlong pointer)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Sort* current = reinterpret_cast<Sort*>(pointer);
+ return env->NewStringUTF(current->getSymbol().c_str());
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, nullptr);
+}
+
/*
* Class: io_github_cvc5_api_Sort
* Method: isNull
bint operator>(const Sort&) except +
bint operator<=(const Sort&) except +
bint operator>=(const Sort&) except +
+ bint hasSymbol() except +
+ string getSymbol() except +
bint isNull() except +
bint isBoolean() except +
bint isInteger() except +
def __hash__(self):
return csorthash(self.csort)
+ def hasSymbol(self):
+ """:return: True iff this sort has a symbol."""
+ return self.csort.hasSymbol()
+
+ def getSymbol(self):
+ """
+ Asserts :py:meth:`hasSymbol()`.
+
+ :return: the raw symbol of the sort.
+ """
+ return self.csort.getSymbol().decode()
+
def isNull(self):
""":return: True if this Sort is a null sort."""
return self.csort.isNull()
def getSymbol(self):
"""
- Asserts :py:meth:`hasSymbol()`.
+ Asserts :py:meth:`hasSymbol()`.
- :return: the raw symbol of the term.
- """
+ :return: the raw symbol of the term.
+ """
return self.cterm.getSymbol().decode()
def isNull(self):
ASSERT_NO_THROW(d_solver.getIntegerSort() >= Sort());
}
+TEST_F(TestApiBlackSort, hasGetSymbol)
+{
+ Sort n;
+ Sort b = d_solver.getBooleanSort();
+ Sort s0 = d_solver.mkParamSort("s0");
+ Sort s1 = d_solver.mkParamSort("|s1\\|");
+
+ ASSERT_THROW(n.hasSymbol(), CVC5ApiException);
+ ASSERT_FALSE(b.hasSymbol());
+ ASSERT_TRUE(s0.hasSymbol());
+ ASSERT_TRUE(s1.hasSymbol());
+
+ ASSERT_THROW(n.getSymbol(), CVC5ApiException);
+ ASSERT_THROW(b.getSymbol(), CVC5ApiException);
+ ASSERT_EQ(s0.getSymbol(), "s0");
+ ASSERT_EQ(s1.getSymbol(), "|s1\\|");
+}
+
TEST_F(TestApiBlackSort, isNull)
{
Sort x;
assertDoesNotThrow(() -> d_solver.getIntegerSort().compareTo(d_solver.getNullSort()));
}
+ @Test void hasGetSymbol() throws CVC5ApiException
+ {
+ Sort n = d_solver.getNullSort();
+ Sort b = d_solver.getBooleanSort();
+ Sort s0 = d_solver.mkParamSort("s0");
+ Sort s1 = d_solver.mkParamSort("|s1\\|");
+
+ assertThrows(CVC5ApiException.class, () -> n.hasSymbol());
+ assertFalse(b.hasSymbol());
+ assertTrue(s0.hasSymbol());
+ assertTrue(s1.hasSymbol());
+
+ assertThrows(CVC5ApiException.class, () -> n.getSymbol());
+ assertThrows(CVC5ApiException.class, () -> b.getSymbol());
+ assertEquals(s0.getSymbol(), "s0");
+ assertEquals(s1.getSymbol(), "|s1\\|");
+ }
+
@Test void isBoolean()
{
assertTrue(d_solver.getBooleanSort().isBoolean());
solver.getIntegerSort() > Sort(solver)
solver.getIntegerSort() >= Sort(solver)
+def test_has_get_symbol(solver):
+ n = Sort(solver)
+ b = solver.getBooleanSort()
+ s0 = solver.mkParamSort("s0")
+ s1 = solver.mkParamSort("|s1\\|")
+
+ with pytest.raises(RuntimeError):
+ n.hasSymbol()
+ assert not b.hasSymbol()
+ assert s0.hasSymbol()
+ assert s1.hasSymbol()
+
+ with pytest.raises(RuntimeError):
+ n.getSymbol()
+ with pytest.raises(RuntimeError):
+ b.getSymbol()
+ assert s0.getSymbol() == "s0"
+ assert s1.getSymbol() == "|s1\\|"
+
+
def test_is_null(solver):
x = Sort(solver)
assert x.isNull()