Fix for bug 555; SMT-LIBv2 symbols now output with proper quoting.
authorMorgan Deters <mdeters@cs.nyu.edu>
Wed, 19 Mar 2014 17:58:59 +0000 (13:58 -0400)
committerMorgan Deters <mdeters@cs.nyu.edu>
Wed, 19 Mar 2014 19:49:50 +0000 (15:49 -0400)
src/printer/smt2/smt2_printer.cpp
src/printer/smt2/smt2_printer.h

index 849d5c0a5fc74e391fee0fb5dd3ac71bbe079053..6485670b5e614a40bb92914182be2006a9230f0f 100644 (file)
@@ -697,6 +697,25 @@ static inline void toStream(std::ostream& out, const SExpr& sexpr) throw() {
   Printer::getPrinter(language::output::LANG_SMTLIB_V2)->toStream(out, sexpr);
 }
 
+void Smt2Printer::toStream(std::ostream& out, const SExpr& sexpr) const throw() {
+  if(sexpr.isKeyword()) {
+    std::string s = sexpr.getValue();
+    if(s.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@%^&*_-+=<>.?/") == std::string::npos) {
+      // simple unquoted symbol
+      out << s;
+    } else {
+      // must quote the symbol, but it cannot contain | or \, we turn those into _
+      size_t p;
+      while((p = s.find_first_of("\\|")) != std::string::npos) {
+        s = s.replace(p, 1, "_");
+      }
+      out << "|" << s << "|";
+    }
+  } else {
+    this->Printer::toStream(out, sexpr);
+  }
+}
+
 template <class T>
 static bool tryToStream(std::ostream& out, const CommandStatus* s) throw();
 
index c70bb78c38c692de8d4a2344464fb7f164763c9c..c3f8deb9c64fc368c8f590c85db7a92a6cf0438a 100644 (file)
@@ -45,6 +45,7 @@ public:
   void toStream(std::ostream& out, const Command* c, int toDepth, bool types, size_t dag) const throw();
   void toStream(std::ostream& out, const CommandStatus* s) const throw();
   void toStream(std::ostream& out, const Result& r) const throw();
+  void toStream(std::ostream& out, const SExpr& sexpr) const throw();
 };/* class Smt2Printer */
 
 }/* CVC4::printer::smt2 namespace */