diff options
author | Morgan Deters <mdeters@cs.nyu.edu> | 2013-03-20 13:09:18 -0400 |
---|---|---|
committer | Morgan Deters <mdeters@cs.nyu.edu> | 2013-03-20 15:36:53 -0400 |
commit | 0c661d41f7594ee3c761b173c1e709ce428ce89d (patch) | |
tree | 8eac3152accfdf7f7f1af92106725a9351e21f56 /src/printer/smt2 | |
parent | bf46697e4b5fe231621763d56a236e367e817c37 (diff) |
Properly |quote| symbols in SMT-LIBv2 output.
Diffstat (limited to 'src/printer/smt2')
-rw-r--r-- | src/printer/smt2/smt2_printer.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/printer/smt2/smt2_printer.cpp b/src/printer/smt2/smt2_printer.cpp index 8541ca6ae..ef4fd5fea 100644 --- a/src/printer/smt2/smt2_printer.cpp +++ b/src/printer/smt2/smt2_printer.cpp @@ -74,6 +74,17 @@ void Smt2Printer::toStream(std::ostream& out, TNode n, } } +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 @@ -86,7 +97,7 @@ void Smt2Printer::toStream(std::ostream& out, TNode n, if(n.isVar()) { string s; if(n.getAttribute(expr::VarNameAttr(), s)) { - out << s; + out << maybeQuoteSymbol(s); } else { if(n.getKind() == kind::VARIABLE) { out << "var_"; @@ -175,7 +186,7 @@ void Smt2Printer::toStream(std::ostream& out, TNode n, break; case kind::DATATYPE_TYPE: - out << n.getConst<Datatype>().getName(); + out << maybeQuoteSymbol(n.getConst<Datatype>().getName()); break; case kind::UNINTERPRETED_CONSTANT: { @@ -196,7 +207,7 @@ void Smt2Printer::toStream(std::ostream& out, TNode n, if(n.getKind() == kind::SORT_TYPE) { string name; if(n.getAttribute(expr::VarNameAttr(), name)) { - out << name; + out << maybeQuoteSymbol(name); return; } } |