diff options
author | Gereon Kremer <nafur42@gmail.com> | 2021-05-20 04:08:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-20 02:08:56 +0000 |
commit | a95980ecd80b971086c328c3e1bb731852890a07 (patch) | |
tree | 8b9be61587f4c29e24c9f15edb9f31f955c4aef9 /src/api/python | |
parent | 8bb85b0f1664f6d03bcbf3997533140204c29251 (diff) |
Add more getters for api::Term (#6496)
This PR adds more getter functions for api::Term to retrieve values from constant terms (and terms that the average API use might consider constant).
It also introduces std::wstring as regular representation for string constants instead of std::vector<uint32> for the SMT-LIB parser and the String class.
Diffstat (limited to 'src/api/python')
-rw-r--r-- | src/api/python/cvc5.pxd | 8 | ||||
-rw-r--r-- | src/api/python/cvc5.pxi | 29 |
2 files changed, 18 insertions, 19 deletions
diff --git a/src/api/python/cvc5.pxd b/src/api/python/cvc5.pxd index a044c79f5..24f8ac0a0 100644 --- a/src/api/python/cvc5.pxd +++ b/src/api/python/cvc5.pxd @@ -1,6 +1,7 @@ # import dereference and increment operators from cython.operator cimport dereference as deref, preincrement as inc from libc.stdint cimport int32_t, int64_t, uint32_t, uint64_t +from libc.stddef cimport wchar_t from libcpp.set cimport set from libcpp.string cimport string from libcpp.vector cimport vector @@ -19,6 +20,9 @@ cdef extern from "<functional>" namespace "std" nogil: hash() size_t operator()(T t) +cdef extern from "<string>" namespace "std": + cdef cppclass wstring: + wstring(const wchar_t*, size_t) except + cdef extern from "api/cpp/cvc5.h" namespace "cvc5": cdef cppclass Options: @@ -191,7 +195,7 @@ cdef extern from "api/cpp/cvc5.h" namespace "cvc5::api": Term mkEmptySet(Sort s) except + Term mkSepNil(Sort sort) except + Term mkString(const string& s) except + - Term mkString(const vector[unsigned]& s) except + + Term mkString(const wstring& s) except + Term mkEmptySequence(Sort sort) except + Term mkUniverseSet(Sort sort) except + Term mkBitVector(uint32_t size) except + @@ -372,7 +376,7 @@ cdef extern from "api/cpp/cvc5.h" namespace "cvc5::api": Term operator*() except + const_iterator begin() except + const_iterator end() except + - bint isInteger() except + + bint isIntegerValue() except + cdef cppclass TermHashFunction: TermHashFunction() except + diff --git a/src/api/python/cvc5.pxi b/src/api/python/cvc5.pxi index a512a17a8..6d197168d 100644 --- a/src/api/python/cvc5.pxi +++ b/src/api/python/cvc5.pxi @@ -3,6 +3,7 @@ from fractions import Fraction import sys from libc.stdint cimport int32_t, int64_t, uint32_t, uint64_t +from libc.stddef cimport wchar_t from libcpp.pair cimport pair from libcpp.set cimport set @@ -26,9 +27,14 @@ from cvc5 cimport ROUND_TOWARD_NEGATIVE, ROUND_TOWARD_ZERO from cvc5 cimport ROUND_NEAREST_TIES_TO_AWAY from cvc5 cimport Term as c_Term from cvc5 cimport hash as c_hash +from cvc5 cimport wstring as c_wstring from cvc5kinds cimport Kind as c_Kind +cdef extern from "Python.h": + wchar_t* PyUnicode_AsWideCharString(object, Py_ssize_t *) + void PyMem_Free(void*) + ################################## DECORATORS ################################# def expand_list_arg(num_req_args=0): ''' @@ -735,23 +741,12 @@ cdef class Solver: term.cterm = self.csolver.mkSepNil(sort.csort) return term - def mkString(self, str_or_vec): + def mkString(self, str s): cdef Term term = Term(self) - cdef vector[unsigned] v - if isinstance(str_or_vec, str): - for u in str_or_vec: - v.push_back(<unsigned> ord(u)) - term.cterm = self.csolver.mkString(<const vector[unsigned]&> v) - elif isinstance(str_or_vec, list): - for u in str_or_vec: - if not isinstance(u, int): - raise ValueError("List should contain ints but got: {}" - .format(str_or_vec)) - v.push_back(<unsigned> u) - term.cterm = self.csolver.mkString(<const vector[unsigned]&> v) - else: - raise ValueError("Expected string or vector of ASCII codes" - " but got: {}".format(str_or_vec)) + cdef Py_ssize_t size + cdef wchar_t* tmp = PyUnicode_AsWideCharString(s, &size) + term.cterm = self.csolver.mkString(c_wstring(tmp, size)) + PyMem_Free(tmp) return term def mkEmptySequence(self, Sort sort): @@ -1599,7 +1594,7 @@ cdef class Term: return term def isInteger(self): - return self.cterm.isInteger() + return self.cterm.isIntegerValue() def toPythonObj(self): ''' |