Skip to content

Commit 0fdf8ee

Browse files
author
Daniel Kroening
committed
smt2_solver: implement (echo "string")
1 parent f5f870b commit 0fdf8ee

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
@@ -41,6 +41,22 @@ class smt2_solvert:public smt2_parsert
4141
std::set<irep_idt> constants_done;
4242
};
4343

44+
static std::string smt2_string_literal(const std::string &s)
45+
{
46+
// " is the only escape sequence
47+
std::string result;
48+
result += '"';
49+
50+
for(const auto &c : s)
51+
if(c == '"')
52+
result += "\"\"";
53+
else
54+
result += c;
55+
56+
result += '"';
57+
return result;
58+
}
59+
4460
void smt2_solvert::define_constants(const exprt &expr)
4561
{
4662
for(const auto &op : expr.operands())
@@ -162,6 +178,13 @@ void smt2_solvert::command(const std::string &c)
162178
std::cout << e.pretty() << '\n'; // need to do an 'smt2_format'
163179
}
164180
}
181+
else if(c == "echo")
182+
{
183+
if(next_token() != STRING_LITERAL)
184+
std::cout << "expected string literal" << '\n';
185+
else
186+
std::cout << smt2_string_literal(buffer) << '\n';
187+
}
165188
else if(c=="simplify")
166189
{
167190
// this is a command that Z3 appears to implement
@@ -185,8 +208,6 @@ void smt2_solvert::command(const std::string &c)
185208
| ( define-fun-rec hfunction_def i )
186209
| ( define-funs-rec ( hfunction_deci n+1 ) ( htermi n+1 ) )
187210
| ( define-sort hsymboli ( hsymboli ??? ) hsorti )
188-
| ( echo hstringi )
189-
| ( exit )
190211
| ( get-assertions )
191212
| ( get-assignment )
192213
| ( get-info hinfo_flag i )

0 commit comments

Comments
 (0)