From: Andrew Reynolds Date: Sun, 16 Feb 2020 21:47:31 +0000 (-0600) Subject: Add temporary global API conversion utilities. (#3759) X-Git-Tag: cvc5-1.0.0~3643 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f5c8fa4f2edf773d1942110b7fee6411894c6961;p=cvc5.git Add temporary global API conversion utilities. (#3759) --- diff --git a/src/api/cvc4cpp.cpp b/src/api/cvc4cpp.cpp index ddc1a61a0..f2c4d3dd3 100644 --- a/src/api/cvc4cpp.cpp +++ b/src/api/cvc4cpp.cpp @@ -562,26 +562,6 @@ bool isDefinedIntKind(CVC4::Kind k) } #endif -Kind intToExtKind(CVC4::Kind k) -{ - auto it = s_kinds_internal.find(k); - if (it == s_kinds_internal.end()) - { - return INTERNAL_KIND; - } - return it->second; -} - -CVC4::Kind extToIntKind(Kind k) -{ - auto it = s_kinds.find(k); - if (it == s_kinds.end()) - { - return CVC4::Kind::UNDEFINED_KIND; - } - return it->second; -} - uint32_t minArity(Kind k) { Assert(isDefinedKind(k)); @@ -796,17 +776,6 @@ Sort::~Sort() {} bool Sort::isNullHelper() const { return d_type->isNull(); } -std::vector Sort::typeVectorToSorts( - const std::vector& types) const -{ - std::vector res; - for (const CVC4::Type& t : types) - { - res.push_back(Sort(t)); - } - return res; -} - bool Sort::operator==(const Sort& s) const { return *d_type == *s.d_type; } bool Sort::operator!=(const Sort& s) const { return *d_type != *s.d_type; } @@ -3984,5 +3953,85 @@ ExprManager* Solver::getExprManager(void) const { return d_exprMgr.get(); } */ SmtEngine* Solver::getSmtEngine(void) const { return d_smtEngine.get(); } + +/* -------------------------------------------------------------------------- */ +/* Conversions */ +/* -------------------------------------------------------------------------- */ + +std::vector termVectorToExprs(const std::vector& terms) +{ + std::vector exprs; + for (size_t i = 0, tsize = terms.size(); i < tsize; i++) + { + exprs.push_back(terms[i].getExpr()); + } + return exprs; +} + +std::vector sortVectorToTypes(const std::vector& sorts) +{ + std::vector types; + for (size_t i = 0, ssize = sorts.size(); i < ssize; i++) + { + types.push_back(sorts[i].getType()); + } + return types; +} + +std::set sortSetToTypes(const std::set& sorts) +{ + std::set types; + for (const Sort& s : sorts) + { + types.insert(s.getType()); + } + return types; +} + +std::vector exprVectorToTerms(const std::vector& exprs) +{ + std::vector terms; + for (size_t i = 0, esize = exprs.size(); i < esize; i++) + { + terms.push_back(Term(exprs[i])); + } + return terms; +} + +std::vector typeVectorToSorts(const std::vector& types) +{ + std::vector sorts; + for (size_t i = 0, tsize = types.size(); i < tsize; i++) + { + sorts.push_back(Sort(types[i])); + } + return sorts; +} + } // namespace api + +/* -------------------------------------------------------------------------- */ +/* Kind Conversions */ +/* -------------------------------------------------------------------------- */ + +CVC4::api::Kind intToExtKind(CVC4::Kind k) +{ + auto it = api::s_kinds_internal.find(k); + if (it == api::s_kinds_internal.end()) + { + return api::INTERNAL_KIND; + } + return it->second; +} + +CVC4::Kind extToIntKind(CVC4::api::Kind k) +{ + auto it = api::s_kinds.find(k); + if (it == api::s_kinds.end()) + { + return CVC4::Kind::UNDEFINED_KIND; + } + return it->second; +} + } // namespace CVC4 diff --git a/src/api/cvc4cpp.h b/src/api/cvc4cpp.h index 396c4eedb..84615afc0 100644 --- a/src/api/cvc4cpp.h +++ b/src/api/cvc4cpp.h @@ -20,6 +20,10 @@ #define CVC4__API__CVC4CPP_H #include "api/cvc4cppkind.h" +// !!! Only temporarily public until the parser is fully migrated to the new +// API. !!! +#include "expr/kind.h" +// !!! #include #include @@ -510,9 +514,6 @@ class CVC4_PUBLIC Sort */ bool isNullHelper() const; - /* Helper to convert a vector of sorts into a vector of internal types. */ - std::vector typeVectorToSorts( - const std::vector& vector) const; /** * The interal type wrapped by this sort. * This is a shared_ptr rather than a unique_ptr to avoid overhead due to @@ -2689,6 +2690,20 @@ class CVC4_PUBLIC Solver std::unique_ptr d_rng; }; +// !!! Only temporarily public until the parser is fully migrated to the +// new API. !!! +std::vector termVectorToExprs(const std::vector& terms); +std::vector sortVectorToTypes(const std::vector& sorts); +std::vector exprVectorToTerms(const std::vector& terms); +std::vector typeVectorToSorts(const std::vector& sorts); +std::set sortSetToTypes(const std::set& sorts); + } // namespace api + +// !!! Only temporarily public until the parser is fully migrated to the +// new API. !!! +CVC4::api::Kind intToExtKind(CVC4::Kind k); +CVC4::Kind extToIntKind(CVC4::api::Kind k); + } // namespace CVC4 #endif