summaryrefslogtreecommitdiff
path: root/src/api/cvc4cpp.cpp
diff options
context:
space:
mode:
authorAina Niemetz <aina.niemetz@gmail.com>2018-07-13 01:57:24 -0700
committerGitHub <noreply@github.com>2018-07-13 01:57:24 -0700
commit99465e5ed6ee1415c060dc89cc666b562045cf20 (patch)
treee10753c0cc4a8b4bad1f449d593a78f4699faba5 /src/api/cvc4cpp.cpp
parent2b9d4520869bfb1b538f5c7f40bb815217185918 (diff)
New C++ API: Implementation of datatype classes. (#2142)
Diffstat (limited to 'src/api/cvc4cpp.cpp')
-rw-r--r--src/api/cvc4cpp.cpp251
1 files changed, 249 insertions, 2 deletions
diff --git a/src/api/cvc4cpp.cpp b/src/api/cvc4cpp.cpp
index ceed73d5b..958438751 100644
--- a/src/api/cvc4cpp.cpp
+++ b/src/api/cvc4cpp.cpp
@@ -769,7 +769,6 @@ bool Sort::isSortConstructor() const
return d_type->isSortConstructor();
}
-#if 0
Datatype Sort::getDatatype() const
{
// CHECK: is this a datatype sort?
@@ -791,7 +790,6 @@ Sort Sort::instantiate(const std::vector<Sort>& params) const
Assert (d_type->isSortConstructor());
return static_cast<SortConstructorType*>(d_type.get())->instantiate(tparams);
}
-#endif
std::string Sort::toString() const
{
@@ -1209,6 +1207,255 @@ std::ostream& operator<<(std::ostream& out,
return out;
}
+/* DatatypeSelector --------------------------------------------------------- */
+
+DatatypeSelector::DatatypeSelector()
+{
+ d_stor = nullptr;
+}
+
+DatatypeSelector::DatatypeSelector(const CVC4::DatatypeConstructorArg& stor)
+ : d_stor(new CVC4::DatatypeConstructorArg(stor))
+{
+}
+
+DatatypeSelector::~DatatypeSelector()
+{
+}
+
+std::string DatatypeSelector::toString() const
+{
+ std::stringstream ss;
+ ss << *d_stor;
+ return ss.str();
+}
+
+std::ostream& operator<<(std::ostream& out, const DatatypeSelector& stor)
+{
+ out << stor.toString();
+ return out;
+}
+
+/* DatatypeConstructor ------------------------------------------------------ */
+
+DatatypeConstructor::DatatypeConstructor()
+{
+ d_ctor = nullptr;
+}
+
+DatatypeConstructor::DatatypeConstructor(const CVC4::DatatypeConstructor& ctor)
+: d_ctor(new CVC4::DatatypeConstructor(ctor))
+{
+}
+
+DatatypeConstructor::~DatatypeConstructor()
+{
+}
+
+DatatypeSelector DatatypeConstructor::operator[](const std::string& name) const
+{
+ // CHECK: selector with name exists?
+ // CHECK: is resolved?
+ return (*d_ctor)[name];
+}
+
+DatatypeSelector DatatypeConstructor::getSelector(const std::string& name) const
+{
+ // CHECK: cons with name exists?
+ // CHECK: is resolved?
+ return (*d_ctor)[name];
+}
+
+Term DatatypeConstructor::getSelectorTerm(const std::string& name) const
+{
+ // CHECK: cons with name exists?
+ // CHECK: is resolved?
+ return d_ctor->getSelector(name);
+}
+
+DatatypeConstructor::const_iterator DatatypeConstructor::begin() const
+{
+ return DatatypeConstructor::const_iterator(*d_ctor, true);
+}
+
+DatatypeConstructor::const_iterator DatatypeConstructor::end() const
+{
+ return DatatypeConstructor::const_iterator(*d_ctor, false);
+}
+
+DatatypeConstructor::const_iterator::const_iterator(
+ const CVC4::DatatypeConstructor& ctor, bool begin)
+{
+ d_int_stors = ctor.getArgs();
+ const std::vector<CVC4::DatatypeConstructorArg>* sels =
+ static_cast<const std::vector<CVC4::DatatypeConstructorArg>*>(
+ d_int_stors);
+ for (const auto& s : *sels)
+ {
+ /* Can not use emplace_back here since constructor is private. */
+ d_stors.push_back(DatatypeSelector(s));
+ }
+ d_idx = begin ? 0 : sels->size();
+}
+
+DatatypeConstructor::const_iterator& DatatypeConstructor::const_iterator::
+operator=(const DatatypeConstructor::const_iterator& it)
+{
+ d_int_stors = it.d_int_stors;
+ d_stors = it.d_stors;
+ d_idx = it.d_idx;
+ return *this;
+}
+
+const DatatypeSelector& DatatypeConstructor::const_iterator::operator*() const
+{
+ return d_stors[d_idx];
+}
+
+const DatatypeSelector* DatatypeConstructor::const_iterator::operator->() const
+{
+ return &d_stors[d_idx];
+}
+
+DatatypeConstructor::const_iterator& DatatypeConstructor::const_iterator::
+operator++()
+{
+ ++d_idx;
+ return *this;
+}
+
+DatatypeConstructor::const_iterator DatatypeConstructor::const_iterator::
+operator++(int)
+{
+ DatatypeConstructor::const_iterator it(*this);
+ ++d_idx;
+ return it;
+}
+
+bool DatatypeConstructor::const_iterator::operator==(
+ const DatatypeConstructor::const_iterator& other) const
+{
+ return d_int_stors == other.d_int_stors && d_idx == other.d_idx;
+}
+
+bool DatatypeConstructor::const_iterator::operator!=(
+ const DatatypeConstructor::const_iterator& other) const
+{
+ return d_int_stors != other.d_int_stors || d_idx != other.d_idx;
+}
+
+std::string DatatypeConstructor::toString() const
+{
+ std::stringstream ss;
+ ss << *d_ctor;
+ return ss.str();
+}
+
+std::ostream& operator<<(std::ostream& out, const DatatypeConstructor& ctor)
+{
+ out << ctor.toString();
+ return out;
+}
+
+/* Datatype ----------------------------------------------------------------- */
+
+Datatype::Datatype(const CVC4::Datatype& dtype)
+: d_dtype(new CVC4::Datatype(dtype))
+{
+}
+
+Datatype::~Datatype()
+{
+}
+
+DatatypeConstructor Datatype::operator[](const std::string& name) const
+{
+ // CHECK: cons with name exists?
+ // CHECK: is resolved?
+ return (*d_dtype)[name];
+}
+
+DatatypeConstructor Datatype::getConstructor(const std::string& name) const
+{
+ // CHECK: cons with name exists?
+ // CHECK: is resolved?
+ return (*d_dtype)[name];
+}
+
+Term Datatype::getConstructorTerm(const std::string& name) const
+{
+ // CHECK: cons with name exists?
+ // CHECK: is resolved?
+ return d_dtype->getConstructor(name);
+}
+
+Datatype::const_iterator Datatype::begin() const
+{
+ return Datatype::const_iterator(*d_dtype, true);
+}
+
+Datatype::const_iterator Datatype::end() const
+{
+ return Datatype::const_iterator(*d_dtype, false);
+}
+
+Datatype::const_iterator::const_iterator(const CVC4::Datatype& dtype, bool begin)
+{
+ d_int_ctors = dtype.getConstructors();
+ const std::vector<CVC4::DatatypeConstructor>* cons =
+ static_cast<const std::vector<CVC4::DatatypeConstructor>*>(d_int_ctors);
+ for (const auto& c : *cons)
+ {
+ /* Can not use emplace_back here since constructor is private. */
+ d_ctors.push_back(DatatypeConstructor(c));
+ }
+ d_idx = begin ? 0 : cons->size();
+}
+
+Datatype::const_iterator& Datatype::const_iterator::operator=(
+ const Datatype::const_iterator& it)
+{
+ d_int_ctors = it.d_int_ctors;
+ d_ctors = it.d_ctors;
+ d_idx = it.d_idx;
+ return *this;
+}
+
+const DatatypeConstructor& Datatype::const_iterator::operator*() const
+{
+ return d_ctors[d_idx];
+}
+
+const DatatypeConstructor* Datatype::const_iterator::operator->() const
+{
+ return &d_ctors[d_idx];
+}
+
+Datatype::const_iterator& Datatype::const_iterator::operator++()
+{
+ ++d_idx;
+ return *this;
+}
+
+Datatype::const_iterator Datatype::const_iterator::operator++(int)
+{
+ Datatype::const_iterator it(*this);
+ ++d_idx;
+ return it;
+}
+
+bool Datatype::const_iterator::operator==(
+ const Datatype::const_iterator& other) const
+{
+ return d_int_ctors == other.d_int_ctors && d_idx == other.d_idx;
+}
+
+bool Datatype::const_iterator::operator!=(
+ const Datatype::const_iterator& other) const
+{
+ return d_int_ctors != other.d_int_ctors || d_idx != other.d_idx;
+}
+
/* -------------------------------------------------------------------------- */
/* Rounding Mode for Floating Points */
/* -------------------------------------------------------------------------- */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback