#include "expr/node_algorithm.h"
#include "expr/node_builder.h"
#include "expr/node_manager.h"
+#include "expr/node_manager_attributes.h"
#include "expr/sequence.h"
#include "expr/type_node.h"
#include "expr/uninterpreted_constant.h"
CVC5_API_TRY_CATCH_END;
}
+bool Term::hasSymbol() const
+{
+ CVC5_API_TRY_CATCH_BEGIN;
+ CVC5_API_CHECK_NOT_NULL;
+ //////// all checks before this line
+ return d_node->hasAttribute(expr::VarNameAttr());
+ ////////
+ CVC5_API_TRY_CATCH_END;
+}
+
+std::string Term::getSymbol() const
+{
+ CVC5_API_TRY_CATCH_BEGIN;
+ CVC5_API_CHECK_NOT_NULL;
+ CVC5_API_CHECK(d_node->hasAttribute(expr::VarNameAttr()))
+ << "Invalid call to '" << __PRETTY_FUNCTION__
+ << "', expected the term to have a symbol.";
+ //////// all checks before this line
+ return d_node->getAttribute(expr::VarNameAttr());
+ ////////
+ CVC5_API_TRY_CATCH_END;
+}
+
bool Term::isNull() const
{
CVC5_API_TRY_CATCH_BEGIN;
*/
Op getOp() const;
+ /**
+ * @return true if the term has a symbol.
+ */
+ bool hasSymbol() const;
+
+ /**
+ * Asserts hasSymbol().
+ * @return the raw symbol of the term.
+ */
+ std::string getSymbol() const;
+
/**
* @return true if this Term is a null term
*/
private native long getOp(long pointer);
+ /**
+ * @return true if the term has a symbol.
+ */
+ public boolean hasSymbol()
+ {
+ return hasSymbol(pointer);
+ }
+
+ private native boolean hasSymbol(long pointer);
+
+ /**
+ * Asserts hasSymbol().
+ * @return the raw symbol of the term.
+ */
+ public String getSymbol()
+ {
+ return getSymbol(pointer);
+ }
+
+ private native String getSymbol(long pointer);
+
/**
* @return true if this Term is a null term
*/
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
}
+/*
+ * Class: io_github_cvc5_api_Term
+ * Method: hasSymbol
+ * Signature: (J)Z
+ */
+JNIEXPORT jboolean JNICALL Java_io_github_cvc5_api_Term_hasSymbol(JNIEnv* env,
+ jobject,
+ jlong pointer)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Term* current = reinterpret_cast<Term*>(pointer);
+ return static_cast<jboolean>(current->hasSymbol());
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, static_cast<jboolean>(false));
+}
+
+/*
+ * Class: io_github_cvc5_api_Term
+ * Method: getSymbol
+ * Signature: (J)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_io_github_cvc5_api_Term_getSymbol(JNIEnv* env,
+ jobject,
+ jlong pointer)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Term* current = reinterpret_cast<Term*>(pointer);
+ return env->NewStringUTF(current->getSymbol().c_str());
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, nullptr);
+}
+
/*
* Class: io_github_cvc5_api_Term
* Method: isNull
Term substitute(const vector[Term] & es, const vector[Term] & reps) except +
bint hasOp() except +
Op getOp() except +
+ bint hasSymbol() except +
+ string getSymbol() except +
bint isNull() except +
Term getConstArrayBase() except +
Term notTerm() except +
op.cop = self.cterm.getOp()
return op
+ def hasSymbol(self):
+ return self.cterm.hasSymbol()
+
+ def getSymbol(self):
+ return self.cterm.getSymbol().decode()
+
def isNull(self):
return self.cterm.isNull()
#include <string>
+#include "expr/node_manager_attributes.h"
#include "options/base_options.h"
#include "options/language.h"
#include "printer/ast/ast_printer.h"
void Printer::toStreamCmdDeclareFunction(std::ostream& out, const Node& v) const
{
- std::stringstream vs;
- vs << v;
- toStreamCmdDeclareFunction(out, vs.str(), v.getType());
+ std::string vs = v.getAttribute(expr::VarNameAttr());
+ toStreamCmdDeclareFunction(out, vs, v.getType());
}
void Printer::toStreamCmdDeclarePool(std::ostream& out,
ASSERT_EQ(headTerm, d_solver.mkTerm(headTerm.getOp(), children));
}
+TEST_F(TestApiBlackTerm, hasGetSymbol)
+{
+ Term n;
+ Term t = d_solver.mkBoolean(true);
+ Term c = d_solver.mkConst(d_solver.getBooleanSort(), "|\\|");
+
+ ASSERT_THROW(n.hasSymbol(), CVC5ApiException);
+ ASSERT_FALSE(t.hasSymbol());
+ ASSERT_TRUE(c.hasSymbol());
+
+ ASSERT_THROW(n.getSymbol(), CVC5ApiException);
+ ASSERT_THROW(t.getSymbol(), CVC5ApiException);
+ ASSERT_EQ(c.getSymbol(), "|\\|");
+}
+
TEST_F(TestApiBlackTerm, isNull)
{
Term x;
Term nilOpTerm = list.getConstructorTerm("nil");
}
+ @Test void hasGetSymbol() throws CVC5ApiException
+ {
+ Term n = d_solver.getNullTerm();
+ Term t = d_solver.mkBoolean(true);
+ Term c = d_solver.mkConst(d_solver.getBooleanSort(), "|\\|");
+
+ assertThrows(CVC5ApiException.class, () -> n.hasSymbol());
+ assertFalse(t.hasSymbol());
+ assertTrue(c.hasSymbol());
+
+ assertThrows(CVC5ApiException.class, () -> n.getSymbol());
+ assertThrows(CVC5ApiException.class, () -> t.getSymbol());
+ assertEquals(c.getSymbol(), "|\\|");
+ }
+
@Test void isNull() throws CVC5ApiException
{
Term x = d_solver.getNullTerm();
assert headTerm == solver.mkTerm(headTerm.getOp(), children)
+def test_has_get_symbol(solver):
+ n = Term(solver)
+ t = solver.mkBoolean(True)
+ c = solver.mkConst(solver.getBooleanSort(), "|\\|")
+
+ with pytest.raises(RuntimeError):
+ n.hasSymbol()
+ assert not t.hasSymbol()
+ assert c.hasSymbol()
+
+ with pytest.raises(RuntimeError):
+ n.getSymbol()
+ with pytest.raises(RuntimeError):
+ t.getSymbol()
+ assert c.getSymbol() == "|\\|"
+
+
def test_is_null(solver):
x = Term(solver)
assert x.isNull()