Skip to content

Commit 6293c53

Browse files
author
Daniel Kroening
authored
Merge pull request #3463 from diffblue/smt2_solver_echo
smt2_solver: implement (echo "string")
2 parents 5e68531 + f59fc6e commit 6293c53

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
echo1.smt2
3+
4+
^EXIT=20$
5+
^SIGNAL=0$
6+
\(error "line 2: expected string literal"\)
7+
"whatnot"
8+
"what""not"
9+
--
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; error: must be string literal
2+
(echo 123)
3+
4+
; ok
5+
(echo "whatnot")
6+
7+
; with escaping
8+
(echo "what""not")
9+

src/solvers/smt2/smt2_format.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ std::ostream &smt2_format_rec(std::ostream &out, const exprt &expr)
5757
{
5858
out << value;
5959
}
60+
else if(expr_type.id() == ID_string)
61+
{
62+
const auto &value_string = id2string(value);
63+
64+
out << '"';
65+
66+
for(const auto &c : value_string)
67+
{
68+
// " is the only escape sequence
69+
if(c == '"')
70+
out << '"' << '"';
71+
else
72+
out << c;
73+
}
74+
75+
out << '"';
76+
}
6077
else
6178
DATA_INVARIANT(false, "unhandled constant: " + expr_type.id_string());
6279
}

src/solvers/smt2/smt2_solver.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ void smt2_solvert::command(const std::string &c)
225225

226226
std::cout << ")\n";
227227
}
228+
else if(c == "echo")
229+
{
230+
if(next_token() != STRING_LITERAL)
231+
throw error("expected string literal");
232+
233+
std::cout << smt2_format(constant_exprt(buffer, string_typet())) << '\n';
234+
}
228235
else if(c == "simplify")
229236
{
230237
// this is a command that Z3 appears to implement
@@ -248,8 +255,6 @@ void smt2_solvert::command(const std::string &c)
248255
| ( define-fun-rec hfunction_def i )
249256
| ( define-funs-rec ( hfunction_deci n+1 ) ( htermi n+1 ) )
250257
| ( define-sort hsymboli ( hsymboli ??? ) hsorti )
251-
| ( echo hstringi )
252-
| ( exit )
253258
| ( get-assertions )
254259
| ( get-assignment )
255260
| ( get-info hinfo_flag i )

0 commit comments

Comments
 (0)