New C++ API: Clean up usage of internal Result. (#6043)
authorAina Niemetz <aina.niemetz@gmail.com>
Thu, 4 Mar 2021 01:36:57 +0000 (17:36 -0800)
committerGitHub <noreply@github.com>
Thu, 4 Mar 2021 01:36:57 +0000 (01:36 +0000)
This disables the temporarily available internals of Result.
It further changes the interface for getUnknownExplanation, which now
returns an enum value instead of a string.

src/api/cvc4cpp.cpp
src/api/cvc4cpp.h
src/main/command_executor.cpp
src/smt/command.h
src/util/result.cpp
src/util/result.h
test/unit/api/result_black.cpp

index 41019892000593e28e340666f80e00104b47764f..a426c927018b4ad594361b350e48123bc9e9d310 100644 (file)
@@ -936,25 +936,52 @@ bool Result::operator!=(const Result& r) const
   return *d_result != *r.d_result;
 }
 
-std::string Result::getUnknownExplanation(void) const
+Result::UnknownExplanation Result::getUnknownExplanation(void) const
 {
-  std::stringstream ss;
-  ss << d_result->whyUnknown();
-  return ss.str();
+  CVC4::Result::UnknownExplanation expl = d_result->whyUnknown();
+  switch (expl)
+  {
+    case CVC4::Result::REQUIRES_FULL_CHECK: return REQUIRES_FULL_CHECK;
+    case CVC4::Result::INCOMPLETE: return INCOMPLETE;
+    case CVC4::Result::TIMEOUT: return TIMEOUT;
+    case CVC4::Result::RESOURCEOUT: return RESOURCEOUT;
+    case CVC4::Result::MEMOUT: return MEMOUT;
+    case CVC4::Result::INTERRUPTED: return INTERRUPTED;
+    case CVC4::Result::NO_STATUS: return NO_STATUS;
+    case CVC4::Result::UNSUPPORTED: return UNSUPPORTED;
+    case CVC4::Result::OTHER: return OTHER;
+    default: return UNKNOWN_REASON;
+  }
+  return UNKNOWN_REASON;
 }
 
 std::string Result::toString(void) const { return d_result->toString(); }
 
-// !!! This is only temporarily available until the parser is fully migrated
-// to the new API. !!!
-CVC4::Result Result::getResult(void) const { return *d_result; }
-
 std::ostream& operator<<(std::ostream& out, const Result& r)
 {
   out << r.toString();
   return out;
 }
 
+std::ostream& operator<<(std::ostream& out, enum Result::UnknownExplanation e)
+{
+  switch (e)
+  {
+    case Result::REQUIRES_FULL_CHECK: out << "REQUIRES_FULL_CHECK"; break;
+    case Result::INCOMPLETE: out << "INCOMPLETE"; break;
+    case Result::TIMEOUT: out << "TIMEOUT"; break;
+    case Result::RESOURCEOUT: out << "RESOURCEOUT"; break;
+    case Result::MEMOUT: out << "MEMOUT"; break;
+    case Result::INTERRUPTED: out << "INTERRUPTED"; break;
+    case Result::NO_STATUS: out << "NO_STATUS"; break;
+    case Result::UNSUPPORTED: out << "UNSUPPORTED"; break;
+    case Result::OTHER: out << "OTHER"; break;
+    case Result::UNKNOWN_REASON: out << "UNKNOWN_REASON"; break;
+    default: Unhandled() << e;
+  }
+  return out;
+}
+
 /* -------------------------------------------------------------------------- */
 /* Sort                                                                       */
 /* -------------------------------------------------------------------------- */
index e52fe25242055789d84a65bf37c63f6045b5ce3d..f68fe4c0bba6464598ec4b71c148c18e546f0359 100644 (file)
@@ -97,14 +97,19 @@ class CVC4_PUBLIC Result
   friend class Solver;
 
  public:
-  // !!! This constructor is only temporarily public until the parser is fully
-  // migrated to the new API. !!!
-  /**
-   * Constructor.
-   * @param r the internal result that is to be wrapped by this result
-   * @return the Result
-   */
-  Result(const CVC4::Result& r);
+  enum UnknownExplanation
+  {
+    REQUIRES_FULL_CHECK,
+    INCOMPLETE,
+    TIMEOUT,
+    RESOURCEOUT,
+    MEMOUT,
+    INTERRUPTED,
+    NO_STATUS,
+    UNSUPPORTED,
+    OTHER,
+    UNKNOWN_REASON
+  };
 
   /** Constructor. */
   Result();
@@ -167,18 +172,21 @@ class CVC4_PUBLIC Result
   /**
    * @return an explanation for an unknown query result.
    */
-  std::string getUnknownExplanation() const;
+  UnknownExplanation getUnknownExplanation() const;
 
   /**
    * @return a string representation of this result.
    */
   std::string toString() const;
 
-  // !!! This is only temporarily available until the parser is fully migrated
-  // to the new API. !!!
-  CVC4::Result getResult(void) const;
-
  private:
+  /**
+   * Constructor.
+   * @param r the internal result that is to be wrapped by this result
+   * @return the Result
+   */
+  Result(const CVC4::Result& r);
+
   /**
    * The interal result wrapped by this result.
    * This is a shared_ptr rather than a unique_ptr since CVC4::Result is
@@ -188,13 +196,22 @@ class CVC4_PUBLIC Result
 };
 
 /**
- * Serialize a result to given stream.
+ * Serialize a Result to given stream.
  * @param out the output stream
  * @param r the result to be serialized to the given output stream
  * @return the output stream
  */
 std::ostream& operator<<(std::ostream& out, const Result& r) CVC4_PUBLIC;
 
+/**
+ * Serialize an UnknownExplanation to given stream.
+ * @param out the output stream
+ * @param r the explanation to be serialized to the given output stream
+ * @return the output stream
+ */
+std::ostream& operator<<(std::ostream& out,
+                         enum Result::UnknownExplanation e) CVC4_PUBLIC;
+
 /* -------------------------------------------------------------------------- */
 /* Sort                                                                       */
 /* -------------------------------------------------------------------------- */
index 04ed5147aa8ac2e238b57369b656ad6e9aa2bb9e..8f4b2d4d2a7c148d88bc8d87f35bd6d16bff5be6 100644 (file)
@@ -163,7 +163,7 @@ bool CommandExecutor::doCommandSingleton(Command* cmd)
     if (d_options.getDumpModels()
         && (res.isSat()
             || (res.isSatUnknown()
-                && res.getResult().whyUnknown() == Result::INCOMPLETE)))
+                && res.getUnknownExplanation() == api::Result::INCOMPLETE)))
     {
       getterCommands.emplace_back(new GetModelCommand());
     }
@@ -176,7 +176,8 @@ bool CommandExecutor::doCommandSingleton(Command* cmd)
         && ((d_options.getInstFormatMode() != options::InstFormatMode::SZS
              && (res.isSat()
                  || (res.isSatUnknown()
-                     && res.getResult().whyUnknown() == Result::INCOMPLETE)))
+                     && res.getUnknownExplanation()
+                            == api::Result::INCOMPLETE)))
             || isResultUnsat))
     {
       getterCommands.emplace_back(new GetInstantiationsCommand());
index a2230e12a36446f5e1588646fc08cbb97c0f5cc4..67b8248521d2e7242f53dcc945dd6e42aefa0847 100644 (file)
@@ -28,7 +28,6 @@
 #include <vector>
 
 #include "api/cvc4cpp.h"
-#include "util/result.h"
 #include "util/sexpr.h"
 
 namespace CVC4 {
index 09445fa3bff5c677b72fd5f040e857e5d127246d..bb280b515ccb399ecad1a46276b60e7abe908b81 100644 (file)
@@ -270,38 +270,20 @@ ostream& operator<<(ostream& out, enum Result::Entailment e)
   return out;
 }
 
-ostream& operator<<(ostream& out, enum Result::UnknownExplanation e) {
-  switch (e) {
-    case Result::REQUIRES_FULL_CHECK:
-      out << "REQUIRES_FULL_CHECK";
-      break;
-    case Result::INCOMPLETE:
-      out << "INCOMPLETE";
-      break;
-    case Result::TIMEOUT:
-      out << "TIMEOUT";
-      break;
-    case Result::RESOURCEOUT:
-      out << "RESOURCEOUT";
-      break;
-    case Result::MEMOUT:
-      out << "MEMOUT";
-      break;
-    case Result::INTERRUPTED:
-      out << "INTERRUPTED";
-      break;
-    case Result::NO_STATUS:
-      out << "NO_STATUS";
-      break;
-    case Result::UNSUPPORTED:
-      out << "UNSUPPORTED";
-      break;
-    case Result::OTHER:
-      out << "OTHER";
-      break;
-    case Result::UNKNOWN_REASON:
-      out << "UNKNOWN_REASON";
-      break;
+ostream& operator<<(ostream& out, enum Result::UnknownExplanation e)
+{
+  switch (e)
+  {
+    case Result::REQUIRES_FULL_CHECK: out << "REQUIRES_FULL_CHECK"; break;
+    case Result::INCOMPLETE: out << "INCOMPLETE"; break;
+    case Result::TIMEOUT: out << "TIMEOUT"; break;
+    case Result::RESOURCEOUT: out << "RESOURCEOUT"; break;
+    case Result::MEMOUT: out << "MEMOUT"; break;
+    case Result::INTERRUPTED: out << "INTERRUPTED"; break;
+    case Result::NO_STATUS: out << "NO_STATUS"; break;
+    case Result::UNSUPPORTED: out << "UNSUPPORTED"; break;
+    case Result::OTHER: out << "OTHER"; break;
+    case Result::UNKNOWN_REASON: out << "UNKNOWN_REASON"; break;
     default: Unhandled() << e;
   }
   return out;
index d0b0896bc27a82754f04e3a62f78743ea102f56f..8ded88e1520a4f88820f98b3c4c098b4a115d742 100644 (file)
@@ -51,7 +51,8 @@ class CVC4_PUBLIC Result {
     TYPE_NONE
   };
 
-  enum UnknownExplanation {
+  enum UnknownExplanation
+  {
     REQUIRES_FULL_CHECK,
     INCOMPLETE,
     TIMEOUT,
index 887be8fe0e3ad30c5be536b964b388ce08bbea08..a3e693b27ccbbd2b768093cda2cac6aa6ef4352c 100644 (file)
@@ -115,7 +115,7 @@ TEST_F(TestApiBlackResult, isEntailmentUnknown)
   CVC4::api::Result res = d_solver.checkEntailed(x.eqTerm(x));
   ASSERT_FALSE(res.isEntailed());
   ASSERT_TRUE(res.isEntailmentUnknown());
-  ASSERT_EQ(res.getUnknownExplanation(), "UNKNOWN_REASON");
+  ASSERT_EQ(res.getUnknownExplanation(), api::Result::UNKNOWN_REASON);
 }
 }  // namespace test
 }  // namespace CVC4