Extend Printer infrastructure also to the "Result" class, meaning that different...
authorMorgan Deters <mdeters@gmail.com>
Fri, 8 Jun 2012 21:21:42 +0000 (21:21 +0000)
committerMorgan Deters <mdeters@gmail.com>
Fri, 8 Jun 2012 21:21:42 +0000 (21:21 +0000)
src/expr/command.cpp
src/printer/printer.cpp
src/printer/printer.h
src/util/result.cpp
src/util/result.h

index 7dd9df69abd1cb2fcd9f1cc60050ae4c09a4255c..78d04f000510ea707392a9a5964c7820ce177f62 100644 (file)
@@ -1100,7 +1100,7 @@ std::ostream& operator<<(std::ostream& out,
     return out << "unknown";
 
   default:
-    return out << "SetBenchmarkStatusCommand::[UNKNOWNSTATUS!]";
+    return out << "BenchmarkStatus::[UNKNOWNSTATUS!]";
   }
 }
 
index e3b2ed79686a916cb898d85f767ddfa23cd00fd2..cde0635845a92e96d5561a36578b3a2a175f264f 100644 (file)
@@ -48,7 +48,40 @@ Printer* Printer::makePrinter(OutputLanguage lang) throw() {
   default:
     Unhandled(lang);
   }
-
 }/* Printer::makePrinter() */
 
+void Printer::toStream(std::ostream& out, const Result& r) const throw() {
+  if(r.getType() == Result::TYPE_SAT) {
+    switch(r.isSat()) {
+    case Result::UNSAT:
+      out << "unsat";
+      break;
+    case Result::SAT:
+      out << "sat";
+      break;
+    case Result::SAT_UNKNOWN:
+      out << "unknown";
+      if(r.whyUnknown() != Result::UNKNOWN_REASON) {
+        out << " (" << r.whyUnknown() << ")";
+      }
+      break;
+    }
+  } else {
+    switch(r.isValid()) {
+    case Result::INVALID:
+      out << "invalid";
+      break;
+    case Result::VALID:
+      out << "valid";
+      break;
+    case Result::VALIDITY_UNKNOWN:
+      out << "unknown";
+      if(r.whyUnknown() != Result::UNKNOWN_REASON) {
+        out << " (" << r.whyUnknown() << ")";
+      }
+      break;
+    }
+  }
+}/* Printer::toStream() */
+
 }/* CVC4 namespace */
index 9bcbba3b0e03156dabe497b7c4f5f3a5bdabab6e..04b4350602aaa88004e224157bae3b89a97bcbfc 100644 (file)
@@ -62,6 +62,16 @@ public:
   /** Write a CommandStatus out to a stream with this Printer. */
   virtual void toStream(std::ostream& out, const CommandStatus* s) const throw() = 0;
 
+  /**
+   * Write a Result out to a stream with this Printer.
+   *
+   * The default implementation writes a reasonable string in lowercase
+   * for sat, unsat, valid, invalid, or unknown results.  This behavior
+   * is overridable by each Printer, since sometimes an output language
+   * has a particular preference for how results should appear.
+   */
+  virtual void toStream(std::ostream& out, const Result& r) const throw();
+
 };/* class Printer */
 
 }/* CVC4 namespace */
index bdb17f54c5ee2191879aed0be0fe2f000fed6599..84e422c1915d3485cddf7c8719d7ba81b2b1c71b 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "util/result.h"
 #include "util/Assert.h"
+#include "printer/printer.h"
 
 using namespace std;
 
@@ -190,38 +191,7 @@ ostream& operator<<(ostream& out,
 }
 
 ostream& operator<<(ostream& out, const Result& r) {
-  if(r.d_which == Result::TYPE_SAT) {
-    switch(r.d_sat) {
-    case Result::UNSAT:
-      out << "unsat";
-      break;
-    case Result::SAT:
-      out << "sat";
-      break;
-    case Result::SAT_UNKNOWN:
-      out << "unknown";
-      if(r.whyUnknown() != Result::UNKNOWN_REASON) {
-        out << " (" << r.whyUnknown() << ")";
-      }
-      break;
-    }
-  } else {
-    switch(r.d_validity) {
-    case Result::INVALID:
-      out << "invalid";
-      break;
-    case Result::VALID:
-      out << "valid";
-      break;
-    case Result::VALIDITY_UNKNOWN:
-      out << "unknown";
-      if(r.whyUnknown() != Result::UNKNOWN_REASON) {
-        out << " (" << r.whyUnknown() << ")";
-      }
-      break;
-    }
-  }
-
+  Printer::getPrinter(Node::setlanguage::getLanguage(out))->toStream(out, r);
   return out;
 }/* operator<<(ostream&, const Result&) */
 
index ac52ee382eda19c987cb8e9974a81e8bb73aadec..f0cf3f20eec060c3897c694be1c3a96e2c95458e 100644 (file)
@@ -55,6 +55,12 @@ public:
     VALIDITY_UNKNOWN = 2
   };
 
+  enum Type {
+    TYPE_SAT,
+    TYPE_VALIDITY,
+    TYPE_NONE
+  };
+
   enum UnknownExplanation {
     REQUIRES_FULL_CHECK,
     INCOMPLETE,
@@ -71,11 +77,9 @@ public:
 private:
   enum Sat d_sat;
   enum Validity d_validity;
-  enum { TYPE_SAT, TYPE_VALIDITY, TYPE_NONE } d_which;
+  enum Type d_which;
   enum UnknownExplanation d_unknownExplanation;
 
-  friend std::ostream& CVC4::operator<<(std::ostream& out, const Result& r);
-
 public:
   Result() :
     d_sat(SAT_UNKNOWN),
@@ -126,6 +130,9 @@ public:
   bool isUnknown() const {
     return isSat() == SAT_UNKNOWN && isValid() == VALIDITY_UNKNOWN;
   }
+  Type getType() const {
+    return d_which;
+  }
   bool isNull() const {
     return d_which == TYPE_NONE;
   }