Skip to content

Commit a1fe6d4

Browse files
author
Daniel Kroening
committed
smt2_solver: implement (echo "string")
1 parent f0c59b5 commit a1fe6d4

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/solvers/smt2/smt2_solver.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ class smt2_solvert:public smt2_parsert
4747
} status;
4848
};
4949

50+
static std::string smt2_string_literal(const std::string &s)
51+
{
52+
// " is the only escape sequence
53+
std::string result;
54+
result += '"';
55+
56+
for(const auto &c : s)
57+
if(c == '"')
58+
result += "\"\"";
59+
else
60+
result += c;
61+
62+
result += '"';
63+
return result;
64+
}
65+
5066
void smt2_solvert::define_constants(const exprt &expr)
5167
{
5268
for(const auto &op : expr.operands())
@@ -228,6 +244,13 @@ void smt2_solvert::command(const std::string &c)
228244

229245
std::cout << ")\n";
230246
}
247+
else if(c == "echo")
248+
{
249+
if(next_token() != STRING_LITERAL)
250+
std::cout << "expected string literal" << '\n';
251+
else
252+
std::cout << smt2_string_literal(buffer) << '\n';
253+
}
231254
else if(c=="simplify")
232255
{
233256
// this is a command that Z3 appears to implement
@@ -251,8 +274,6 @@ void smt2_solvert::command(const std::string &c)
251274
| ( define-fun-rec hfunction_def i )
252275
| ( define-funs-rec ( hfunction_deci n+1 ) ( htermi n+1 ) )
253276
| ( define-sort hsymboli ( hsymboli ??? ) hsorti )
254-
| ( echo hstringi )
255-
| ( exit )
256277
| ( get-assertions )
257278
| ( get-assignment )
258279
| ( get-info hinfo_flag i )

0 commit comments

Comments
 (0)