}
}
+static std::string maybeQuoteSymbol(const std::string& s) {
+ // this is the set of SMT-LIBv2 permitted characters in "simple" (non-quoted) symbols
+ if(s.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~!@$%^&*_-+=<>.?/") != string::npos) {
+ // need to quote it
+ stringstream ss;
+ ss << '|' << s << '|';
+ return ss.str();
+ }
+ return s;
+}
+
void Smt2Printer::toStream(std::ostream& out, TNode n,
int toDepth, bool types) const throw() {
// null
if(n.isVar()) {
string s;
if(n.getAttribute(expr::VarNameAttr(), s)) {
- out << s;
+ out << maybeQuoteSymbol(s);
} else {
if(n.getKind() == kind::VARIABLE) {
out << "var_";
break;
case kind::DATATYPE_TYPE:
- out << n.getConst<Datatype>().getName();
+ out << maybeQuoteSymbol(n.getConst<Datatype>().getName());
break;
case kind::UNINTERPRETED_CONSTANT: {
if(n.getKind() == kind::SORT_TYPE) {
string name;
if(n.getAttribute(expr::VarNameAttr(), name)) {
- out << name;
+ out << maybeQuoteSymbol(name);
return;
}
}
--- /dev/null
+; This test checks the correct output behavior of SMT-LIBv2 symbols
+; (sometimes they have to be |quoted| with pipes).
+;
+; COMMAND-LINE: -qm
+; EXIT: 10
+(declare-fun |toto| () Bool)
+(declare-fun |to to| () Bool)
+(assert (and toto |to to|))
+(check-sat)
+; EXPECT: sat
+(get-model)
+; EXPECT: (model
+; EXPECT: (define-fun toto () Bool true)
+; EXPECT: (define-fun |to to| () Bool true)
+; EXPECT: )