Skip to content

add begin() and end() to dstring containers #3479

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 2 commits 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")

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

for(const auto &c : value)
{
// " 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 )
| ( get-assertions )
| ( get-assignment )
| ( get-info hinfo_flag i )
Expand Down
11 changes: 11 additions & 0 deletions src/util/dstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ class dstringt final
return no;
}

// iterators for the underlying string
std::string::const_iterator begin() const
{
return as_string().begin();
}

std::string::const_iterator end() const
{
return as_string().end();
}

private:
#ifdef __GNUC__
constexpr
Expand Down