Skip to content

Commit a00eb08

Browse files
committed
Merge branch 'master' of https://github.com/z3prover/z3
2 parents 4317d13 + c4fa719 commit a00eb08

22 files changed

+53
-127
lines changed

src/api/api_ast.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ extern "C" {
146146
ast_manager& m = mk_c(c)->m();
147147
recfun::decl::plugin& p = mk_c(c)->recfun().get_plugin();
148148
if (!p.has_def(d)) {
149-
std::string msg = "function " + mk_pp(d, m) + " needs to be declared using rec_func_decl";
150-
SET_ERROR_CODE(Z3_INVALID_ARG, msg.c_str());
149+
SET_ERROR_CODE(Z3_INVALID_ARG, "function " + mk_pp(d, m) + " needs to be declared using rec_func_decl");
151150
return;
152151
}
153152
expr_ref abs_body(m);
@@ -168,8 +167,7 @@ extern "C" {
168167
return;
169168
}
170169
if (!pd.get_def()->get_cases().empty()) {
171-
std::string msg = "function " + mk_pp(d, m) + " has already been given a definition";
172-
SET_ERROR_CODE(Z3_INVALID_ARG, msg.c_str());
170+
SET_ERROR_CODE(Z3_INVALID_ARG, "function " + mk_pp(d, m) + " has already been given a definition");
173171
return;
174172
}
175173

src/api/api_ast_map.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ extern "C" {
160160
for (; it != end; ++it) {
161161
buffer << "\n (" << mk_ismt2_pp(it->m_key, mng, 3) << "\n " << mk_ismt2_pp(it->m_value, mng, 3) << ")";
162162
}
163-
buffer << ")";
164-
return mk_c(c)->mk_external_string(buffer.str());
163+
buffer << ')';
164+
return mk_c(c)->mk_external_string(std::move(buffer).str());
165165
Z3_CATCH_RETURN(nullptr);
166166
}
167167

src/api/api_context.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ namespace api {
338338
std::ostringstream buffer;
339339
app * a = to_app(n);
340340
buffer << mk_pp(a->get_decl(), m()) << " applied to: ";
341-
if (a->get_num_args() > 1) buffer << "\n";
341+
if (a->get_num_args() > 1) buffer << '\n';
342342
for (unsigned i = 0; i < a->get_num_args(); ++i) {
343343
buffer << mk_bounded_pp(a->get_arg(i), m(), 3) << " of sort ";
344-
buffer << mk_pp(a->get_arg(i)->get_sort(), m()) << "\n";
344+
buffer << mk_pp(a->get_arg(i)->get_sort(), m()) << '\n';
345345
}
346-
auto str = buffer.str();
346+
auto str = std::move(buffer).str();
347347
warning_msg("%s", str.c_str());
348348
break;
349349
}

src/api/api_fpa.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ extern "C" {
10221022
if (mpfm.is_inf(val)) mpqm.set(q, 0);
10231023
std::stringstream ss;
10241024
mpqm.display_decimal(ss, q, sbits);
1025-
return mk_c(c)->mk_external_string(ss.str());
1025+
return mk_c(c)->mk_external_string(std::move(ss).str());
10261026
Z3_CATCH_RETURN("");
10271027
}
10281028

@@ -1100,7 +1100,7 @@ extern "C" {
11001100
}
11011101
std::stringstream ss;
11021102
ss << exp;
1103-
return mk_c(c)->mk_external_string(ss.str());
1103+
return mk_c(c)->mk_external_string(std::move(ss).str());
11041104
Z3_CATCH_RETURN("");
11051105
}
11061106

src/api/api_goal.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ extern "C" {
185185
std::ostringstream buffer;
186186
to_goal_ref(g)->display(buffer);
187187
// Hack for removing the trailing '\n'
188-
std::string result = buffer.str();
188+
std::string result = std::move(buffer).str();
189189
SASSERT(result.size() > 0);
190190
result.resize(result.size()-1);
191191
return mk_c(c)->mk_external_string(std::move(result));
@@ -203,7 +203,7 @@ extern "C" {
203203
}
204204
to_goal_ref(g)->display_dimacs(buffer, include_names);
205205
// Hack for removing the trailing '\n'
206-
std::string result = buffer.str();
206+
std::string result = std::move(buffer).str();
207207
SASSERT(result.size() > 0);
208208
result.resize(result.size()-1);
209209
return mk_c(c)->mk_external_string(std::move(result));

src/api/api_model.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,14 @@ extern "C" {
432432
if (mk_c(c)->get_print_mode() == Z3_PRINT_SMTLIB2_COMPLIANT) {
433433
model_smt2_pp(buffer, mk_c(c)->m(), *(to_model_ref(m)), 0);
434434
// Hack for removing the trailing '\n'
435-
result = buffer.str();
435+
result = std::move(buffer).str();
436436
if (!result.empty())
437437
result.resize(result.size()-1);
438438
}
439439
else {
440440
model_params p;
441441
model_v2_pp(buffer, *(to_model_ref(m)), p.partial());
442-
result = buffer.str();
442+
result = std::move(buffer).str();
443443
}
444444
return mk_c(c)->mk_external_string(std::move(result));
445445
Z3_CATCH_RETURN(nullptr);

src/api/api_numeral.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ extern "C" {
189189
if (ok && r.is_int() && !r.is_neg()) {
190190
std::stringstream strm;
191191
r.display_bin(strm, r.get_num_bits());
192-
return mk_c(c)->mk_external_string(strm.str());
192+
return mk_c(c)->mk_external_string(std::move(strm).str());
193193
}
194194
else {
195195
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
@@ -237,7 +237,7 @@ extern "C" {
237237
else if (mk_c(c)->fpautil().is_numeral(to_expr(a), tmp)) {
238238
std::ostringstream buffer;
239239
fu.fm().display_smt2(buffer, tmp, false);
240-
return mk_c(c)->mk_external_string(buffer.str());
240+
return mk_c(c)->mk_external_string(std::move(buffer).str());
241241
}
242242
else {
243243
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
@@ -288,21 +288,21 @@ extern "C" {
288288
if (u.is_numeral(e, r) && !r.is_int()) {
289289
std::ostringstream buffer;
290290
r.display_decimal(buffer, precision);
291-
return mk_c(c)->mk_external_string(buffer.str());
291+
return mk_c(c)->mk_external_string(std::move(buffer).str());
292292
}
293293
if (u.is_irrational_algebraic_numeral(e)) {
294294
algebraic_numbers::anum const & n = u.to_irrational_algebraic_numeral(e);
295295
algebraic_numbers::manager & am = u.am();
296296
std::ostringstream buffer;
297297
am.display_decimal(buffer, n, precision);
298-
return mk_c(c)->mk_external_string(buffer.str());
298+
return mk_c(c)->mk_external_string(std::move(buffer).str());
299299
}
300300
else if (mk_c(c)->fpautil().is_rm_numeral(to_expr(a), rm))
301301
return Z3_get_numeral_string(c, a);
302302
else if (mk_c(c)->fpautil().is_numeral(to_expr(a), ftmp)) {
303303
std::ostringstream buffer;
304304
fu.fm().display_decimal(buffer, ftmp, 12);
305-
return mk_c(c)->mk_external_string(buffer.str());
305+
return mk_c(c)->mk_external_string(std::move(buffer).str());
306306
}
307307
else if (Z3_get_numeral_rational(c, a, r)) {
308308
return mk_c(c)->mk_external_string(r.to_string());

src/api/api_solver.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ extern "C" {
170170
if (g_is_threaded || g_thread_id != std::this_thread::get_id()) {
171171
g_is_threaded = true;
172172
std::ostringstream strm;
173-
strm << smt2log << "-" << std::this_thread::get_id();
174-
smt2log = symbol(strm.str());
173+
strm << smt2log << '-' << std::this_thread::get_id();
174+
smt2log = symbol(std::move(strm).str());
175175
}
176176
to_solver(s)->m_pp = alloc(solver2smt2_pp, mk_c(c)->m(), smt2log.str());
177177
}
@@ -208,7 +208,7 @@ extern "C" {
208208
if (!smt_logics::supported_logic(to_symbol(logic))) {
209209
std::ostringstream strm;
210210
strm << "logic '" << to_symbol(logic) << "' is not recognized";
211-
SET_ERROR_CODE(Z3_INVALID_ARG, strm.str());
211+
SET_ERROR_CODE(Z3_INVALID_ARG, std::move(strm).str());
212212
RETURN_Z3(nullptr);
213213
}
214214
else {
@@ -306,7 +306,7 @@ extern "C" {
306306

307307
if (!parse_smt2_commands(*ctx.get(), is)) {
308308
ctx = nullptr;
309-
SET_ERROR_CODE(Z3_PARSER_ERROR, errstrm.str());
309+
SET_ERROR_CODE(Z3_PARSER_ERROR, std::move(errstrm).str());
310310
return;
311311
}
312312

@@ -333,7 +333,7 @@ extern "C" {
333333
std::stringstream err;
334334
sat::solver solver(to_solver_ref(s)->get_params(), m.limit());
335335
if (!parse_dimacs(is, err, solver)) {
336-
SET_ERROR_CODE(Z3_PARSER_ERROR, err.str());
336+
SET_ERROR_CODE(Z3_PARSER_ERROR, std::move(err).str());
337337
return;
338338
}
339339
sat2goal s2g;
@@ -400,7 +400,7 @@ extern "C" {
400400
if (!initialized)
401401
to_solver(s)->m_solver = nullptr;
402402
descrs.display(buffer);
403-
return mk_c(c)->mk_external_string(buffer.str());
403+
return mk_c(c)->mk_external_string(std::move(buffer).str());
404404
Z3_CATCH_RETURN("");
405405
}
406406

@@ -799,7 +799,7 @@ extern "C" {
799799
init_solver(c, s);
800800
std::ostringstream buffer;
801801
to_solver_ref(s)->display(buffer);
802-
return mk_c(c)->mk_external_string(buffer.str());
802+
return mk_c(c)->mk_external_string(std::move(buffer).str());
803803
Z3_CATCH_RETURN("");
804804
}
805805

@@ -810,7 +810,7 @@ extern "C" {
810810
init_solver(c, s);
811811
std::ostringstream buffer;
812812
to_solver_ref(s)->display_dimacs(buffer, include_names);
813-
return mk_c(c)->mk_external_string(buffer.str());
813+
return mk_c(c)->mk_external_string(std::move(buffer).str());
814814
Z3_CATCH_RETURN("");
815815
}
816816

src/ast/ast.cpp

+6-27
Original file line numberDiff line numberDiff line change
@@ -319,26 +319,6 @@ func_decl::func_decl(symbol const & name, unsigned arity, sort * const * domain,
319319
//
320320
// -----------------------------------
321321

322-
static app_flags mk_const_flags() {
323-
app_flags r;
324-
r.m_depth = 1;
325-
r.m_ground = true;
326-
r.m_has_quantifiers = false;
327-
r.m_has_labels = false;
328-
return r;
329-
}
330-
331-
static app_flags mk_default_app_flags() {
332-
app_flags r;
333-
r.m_depth = 1;
334-
r.m_ground = true;
335-
r.m_has_quantifiers = false;
336-
r.m_has_labels = false;
337-
return r;
338-
}
339-
340-
app_flags app::g_constant_flags = mk_const_flags();
341-
342322
app::app(func_decl * decl, unsigned num_args, expr * const * args):
343323
expr(AST_APP),
344324
m_decl(decl),
@@ -1762,8 +1742,7 @@ ast * ast_manager::register_node_core(ast * n) {
17621742
inc_ref(t->get_decl());
17631743
unsigned num_args = t->get_num_args();
17641744
if (num_args > 0) {
1765-
app_flags * f = t->flags();
1766-
*f = mk_default_app_flags();
1745+
app_flags * f = &t->m_flags;
17671746
SASSERT(t->is_ground());
17681747
SASSERT(!t->has_quantifiers());
17691748
SASSERT(!t->has_labels());
@@ -1776,13 +1755,13 @@ ast * ast_manager::register_node_core(ast * n) {
17761755
unsigned arg_depth = 0;
17771756
switch (arg->get_kind()) {
17781757
case AST_APP: {
1779-
app_flags * arg_flags = to_app(arg)->flags();
1780-
arg_depth = arg_flags->m_depth;
1781-
if (arg_flags->m_has_quantifiers)
1758+
app *app = to_app(arg);
1759+
arg_depth = app->get_depth();
1760+
if (app->has_quantifiers())
17821761
f->m_has_quantifiers = true;
1783-
if (arg_flags->m_has_labels)
1762+
if (app->has_labels())
17841763
f->m_has_labels = true;
1785-
if (!arg_flags->m_ground)
1764+
if (!app->is_ground())
17861765
f->m_ground = false;
17871766
break;
17881767
}

src/ast/ast.h

+7-10
Original file line numberDiff line numberDiff line change
@@ -704,26 +704,23 @@ struct app_flags {
704704
unsigned m_ground:1; // application does not have free variables or nested quantifiers.
705705
unsigned m_has_quantifiers:1; // application has nested quantifiers.
706706
unsigned m_has_labels:1; // application has nested labels.
707+
app_flags() : m_depth(1), m_ground(1), m_has_quantifiers(0), m_has_labels(0) {}
707708
};
708709

709710
class app : public expr {
710711
friend class ast_manager;
711712

712713
func_decl * m_decl;
713714
unsigned m_num_args;
715+
app_flags m_flags;
714716
expr * m_args[0];
715717

716-
static app_flags g_constant_flags;
717-
718-
// remark: store term depth in the end of the app. the depth is only stored if the num_args > 0
719718
static unsigned get_obj_size(unsigned num_args) {
720-
return num_args == 0 ? sizeof(app) : sizeof(app) + num_args * sizeof(expr *) + sizeof(app_flags);
719+
return sizeof(app) + num_args * sizeof(expr *);
721720
}
722721

723722
friend class tmp_app;
724723

725-
app_flags * flags() const { return m_num_args == 0 ? &g_constant_flags : reinterpret_cast<app_flags*>(const_cast<expr**>(m_args + m_num_args)); }
726-
727724
app(func_decl * decl, unsigned num_args, expr * const * args);
728725
public:
729726
func_decl * get_decl() const { return m_decl; }
@@ -744,10 +741,10 @@ class app : public expr {
744741
expr * const * end() const { return m_args + m_num_args; }
745742
sort * _get_sort() const { return get_decl()->get_range(); }
746743

747-
unsigned get_depth() const { return flags()->m_depth; }
748-
bool is_ground() const { return flags()->m_ground; }
749-
bool has_quantifiers() const { return flags()->m_has_quantifiers; }
750-
bool has_labels() const { return flags()->m_has_labels; }
744+
unsigned get_depth() const { return m_flags.m_depth; }
745+
bool is_ground() const { return m_flags.m_ground; }
746+
bool has_quantifiers() const { return m_flags.m_has_quantifiers; }
747+
bool has_labels() const { return m_flags.m_has_labels; }
751748
};
752749

753750
// -----------------------------------

src/ast/ast_pp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ inline std::ostream& operator<<(std::ostream & out, mk_pp_vec const & pp) {
5858
inline std::string operator+(char const* s, mk_pp const& pp) {
5959
std::ostringstream strm;
6060
strm << s << pp;
61-
return strm.str();
61+
return std::move(strm).str();
6262
}
6363

6464
inline std::string operator+(std::string const& s, mk_pp const& pp) {
6565
std::ostringstream strm;
6666
strm << s << pp;
67-
return strm.str();
67+
return std::move(strm).str();
6868
}
6969

7070
inline std::string& operator+=(std::string& s, mk_pp const& pp) {

src/ast/rewriter/pb_rewriter.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ expr_ref pb_rewriter::mk_validate_rewrite(app_ref& e1, app_ref& e2) {
157157
continue;
158158
}
159159

160-
std::ostringstream strm;
161-
strm << 'x' << i;
162-
name = symbol(strm.str());
160+
name = symbol('x' + std::to_string(i));
163161
trail.push_back(m.mk_const(name, a.mk_int()));
164162
expr* x = trail.back();
165163
m.is_not(e,e);
@@ -188,9 +186,7 @@ void pb_rewriter::validate_rewrite(func_decl* f, unsigned sz, expr*const* args,
188186
}
189187

190188
void pb_rewriter::dump_pb_rewrite(expr* fml) {
191-
std::ostringstream strm;
192-
strm << "pb_rewrite_" << (s_lemma++) << ".smt2";
193-
std::ofstream out(strm.str());
189+
std::ofstream out("pb_rewrite_" + std::to_string(s_lemma++) + ".smt2");
194190
ast_smt_pp pp(m());
195191
pp.display_smt2(out, fml);
196192
out.close();

src/ast/well_sorted.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ struct well_sorted_proc {
7070
strm << "Expected sort: " << mk_pp(expected_sort, m_manager) << '\n';
7171
strm << "Actual sort: " << mk_pp(actual_sort, m_manager) << '\n';
7272
strm << "Function sort: " << mk_pp(decl, m_manager) << '.';
73-
auto str = strm.str();
74-
warning_msg("%s", str.c_str());
73+
warning_msg("%s", std::move(strm).str().c_str());
7574
m_error = true;
7675
return;
7776
}

src/math/lp/numeric_pair.h

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <algorithm>
2525
#ifdef lp_for_z3
2626
#include "util/rational.h"
27-
#include "util/sstream.h"
2827
#include "util/z3_exception.h"
2928
#else
3029
// include "util/numerics/mpq.h"

src/model/model_smt2_pp.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void pp_uninterp_sorts(std::ostream & out, ast_printer_context & ctx, mod
6868
buffer << " ";
6969
}
7070
buffer << "\n-----------";
71-
std::string buffer_str = buffer.str();
71+
std::string buffer_str = std::move(buffer).str();
7272
unsigned len = static_cast<unsigned>(buffer_str.length());
7373
pp_indent(out, indent);
7474
out << ";; ";
@@ -206,9 +206,7 @@ static void pp_funs(std::ostream & out, ast_printer_context & ctx, model_core co
206206
if (f_i->is_partial()) {
207207
body = mk_string(m, "#unspecified");
208208
for (unsigned j = 0; j < f->get_arity(); j++) {
209-
std::stringstream strm;
210-
strm << "x!" << (j+1);
211-
var_names.push_back(symbol(strm.str()));
209+
var_names.push_back(symbol("x!" + std::to_string(j+1)));
212210
}
213211
}
214212
else {

src/sat/sat_cutset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ namespace sat {
273273
std::string cut::table2string(unsigned num_input, uint64_t table) {
274274
std::ostringstream strm;
275275
display_table(strm, num_input, table);
276-
return strm.str();
276+
return std::move(strm).str();
277277
}
278278

279279

0 commit comments

Comments
 (0)