Skip to content

smt2_solver: implement (echo "string") #3463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions regression/smt2_solver/echo/echo1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
echo1.smt2

^EXIT=20$
^SIGNAL=0$
\(error "line 2: expected string literal"\)
"whatnot"
"what""not"
--
9 changes: 9 additions & 0 deletions regression/smt2_solver/echo/echo1.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; error: must be string literal
(echo 123)

; ok
(echo "whatnot")

; with escaping
(echo "what""not")

17 changes: 17 additions & 0 deletions src/solvers/smt2/smt2_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ std::ostream &smt2_format_rec(std::ostream &out, const exprt &expr)
{
out << value;
}
else if(expr_type.id() == ID_string)
{
const auto &value_string = id2string(value);

out << '"';

for(const auto &c : value_string)
{
// " is the only escape sequence
if(c == '"')
out << '"' << '"';
else
out << c;
}

out << '"';
}
else
DATA_INVARIANT(false, "unhandled constant: " + expr_type.id_string());
}
Expand Down
9 changes: 7 additions & 2 deletions src/solvers/smt2/smt2_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ void smt2_solvert::command(const std::string &c)

std::cout << ")\n";
}
else if(c == "echo")
{
if(next_token() != STRING_LITERAL)
throw error("expected string literal");

std::cout << smt2_format(constant_exprt(buffer, string_typet())) << '\n';
}
else if(c == "simplify")
{
// this is a command that Z3 appears to implement
Expand All @@ -248,8 +255,6 @@ void smt2_solvert::command(const std::string &c)
| ( define-fun-rec hfunction_def i )
| ( define-funs-rec ( hfunction_deci n+1 ) ( htermi n+1 ) )
| ( define-sort hsymboli ( hsymboli ??? ) hsorti )
| ( echo hstringi )
| ( exit )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is exit deleted here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated cleanup

| ( get-assertions )
| ( get-assignment )
| ( get-info hinfo_flag i )
Expand Down