3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-11 19:53:34 +00:00

remove some allocs from exceptions

This commit is contained in:
Nuno Lopes 2018-07-02 17:08:02 +01:00
parent 8791f61aa7
commit cef17c22a1
19 changed files with 36 additions and 40 deletions

View file

@ -59,7 +59,7 @@ public:
if (c == nullptr) {
std::string err_msg("unknown command '");
err_msg = err_msg + s.bare_str() + "'";
throw cmd_exception(err_msg);
throw cmd_exception(std::move(err_msg));
}
m_cmds.push_back(s);
}
@ -384,7 +384,7 @@ class set_option_cmd : public set_get_option_cmd {
std::string msg = "error setting '";
msg += opt_name.str();
msg += "', option value cannot be modified after initialization";
throw cmd_exception(msg);
throw cmd_exception(std::move(msg));
}
}

View file

@ -369,7 +369,7 @@ void stream_ref::set(char const * name) {
std::string msg = "failed to set output stream '";
msg += name;
msg += "'";
throw cmd_exception(msg);
throw cmd_exception(std::move(msg));
}
SASSERT(m_stream);
}

View file

@ -211,7 +211,7 @@ class horn_tactic : public tactic {
default:
msg << "formula is not in Horn fragment: " << mk_pp(g->form(i), m) << "\n";
TRACE("horn", tout << msg.str(););
throw tactic_exception(msg.str().c_str());
throw tactic_exception(msg.str());
}
}

View file

@ -909,7 +909,7 @@ namespace smt2 {
std::string err_msg = "invalid datatype declaration, unknown sort '";
err_msg += missing.str();
err_msg += "'";
throw parser_exception(err_msg, line, pos);
throw parser_exception(std::move(err_msg), line, pos);
}
dts->commit(pm());
m_ctx.insert_aux_pdecl(dts.get());
@ -989,7 +989,7 @@ namespace smt2 {
std::string err_msg = "invalid datatype declaration, unknown sort '";
err_msg += missing.str();
err_msg += "'";
throw parser_exception(err_msg, line, pos);
throw parser_exception(std::move(err_msg), line, pos);
}
}
@ -999,7 +999,7 @@ namespace smt2 {
std::string err_msg = "invalid datatype declaration, repeated accessor identifier '";
err_msg += duplicated.str();
err_msg += "'";
throw parser_exception(err_msg, line, pos);
throw parser_exception(std::move(err_msg), line, pos);
}
}

View file

@ -844,8 +844,7 @@ namespace qe {
break;
case l_undef:
result.push_back(in.get());
std::string s = "search failed";
throw tactic_exception(s.c_str());
throw tactic_exception("search failed");
}
}

View file

@ -1279,7 +1279,7 @@ namespace qe {
if (s == "ok" || s == "unknown") {
s = m_fa.s().reason_unknown();
}
throw tactic_exception(s.c_str());
throw tactic_exception(std::move(s));
}
}
@ -1344,7 +1344,7 @@ namespace qe {
s = m_fa.s().reason_unknown();
}
throw tactic_exception(s.c_str());
throw tactic_exception(std::move(s));
}
return l_true;
}

View file

@ -92,7 +92,7 @@ struct goal2sat::imp {
void throw_op_not_handled(std::string const& s) {
std::string s0 = "operator " + s + " not supported, apply simplifier before invoking translator";
throw tactic_exception(s0.c_str());
throw tactic_exception(std::move(s0));
}
void mk_clause(sat::literal l) {

View file

@ -39,7 +39,6 @@ class smt_tactic : public tactic {
smt_params m_params;
params_ref m_params_ref;
statistics m_stats;
std::string m_failure;
smt::kernel * m_ctx;
symbol m_logic;
progress_callback * m_callback;
@ -259,7 +258,7 @@ public:
if (m_fail_if_inconclusive && !m_candidate_models) {
std::stringstream strm;
strm << "smt tactic failed to show goal to be sat/unsat " << m_ctx->last_failure_as_string();
throw tactic_exception(strm.str().c_str());
throw tactic_exception(strm.str());
}
result.push_back(in.get());
if (m_candidate_models) {
@ -281,8 +280,7 @@ public:
break;
}
}
m_failure = m_ctx->last_failure_as_string();
throw tactic_exception(m_failure.c_str());
throw tactic_exception(m_ctx->last_failure_as_string());
}
}
catch (rewriter_exception & ex) {

View file

@ -635,7 +635,7 @@ private:
t.join();
m_manager.limit().reset_cancel();
if (m_exn_code == -1)
throw default_exception(m_exn_msg);
throw default_exception(std::move(m_exn_msg));
if (m_exn_code != 0)
throw z3_error(m_exn_code);
if (!m_models.empty()) {

View file

@ -968,7 +968,7 @@ private:
void throw_tactic(expr* e) {
std::stringstream strm;
strm << "goal is in a fragment unsupported by pb2bv. Offending expression: " << mk_pp(e, m);
throw tactic_exception(strm.str().c_str());
throw tactic_exception(strm.str());
}
};

View file

@ -206,7 +206,7 @@ void fail_if_proof_generation(char const * tactic_name, goal_ref const & in) {
if (in->proofs_enabled()) {
std::string msg = tactic_name;
msg += " does not support proof production";
throw tactic_exception(msg.c_str());
throw tactic_exception(std::move(msg));
}
}
@ -214,7 +214,7 @@ void fail_if_unsat_core_generation(char const * tactic_name, goal_ref const & in
if (in->unsat_core_enabled()) {
std::string msg = tactic_name;
msg += " does not support unsat core production";
throw tactic_exception(msg.c_str());
throw tactic_exception(std::move(msg));
}
}
@ -222,6 +222,6 @@ void fail_if_model_generation(char const * tactic_name, goal_ref const & in) {
if (in->models_enabled()) {
std::string msg = tactic_name;
msg += " does not generate models";
throw tactic_exception(msg.c_str());
throw tactic_exception(std::move(msg));
}
}

View file

@ -26,7 +26,7 @@ class tactic_exception : public z3_exception {
protected:
std::string m_msg;
public:
tactic_exception(char const * msg):m_msg(msg) {}
tactic_exception(std::string && msg) : m_msg(std::move(msg)) {}
~tactic_exception() override {}
char const * msg() const override { return m_msg.c_str(); }
};

View file

@ -463,9 +463,9 @@ public:
if (finished_id == UINT_MAX) {
switch (ex_kind) {
case ERROR_EX: throw z3_error(error_code);
case TACTIC_EX: throw tactic_exception(ex_msg.c_str());
case TACTIC_EX: throw tactic_exception(std::move(ex_msg));
default:
throw default_exception(ex_msg.c_str());
throw default_exception(std::move(ex_msg));
}
}
}
@ -660,9 +660,9 @@ public:
if (failed) {
switch (ex_kind) {
case ERROR_EX: throw z3_error(error_code);
case TACTIC_EX: throw tactic_exception(ex_msg.c_str());
case TACTIC_EX: throw tactic_exception(std::move(ex_msg));
default:
throw default_exception(ex_msg.c_str());
throw default_exception(std::move(ex_msg));
}
}

View file

@ -55,8 +55,8 @@ class cmd_exception : public default_exception {
}
public:
cmd_exception(char const * msg):default_exception(msg), m_line(-1), m_pos(-1) {}
cmd_exception(std::string const & msg):default_exception(msg), m_line(-1), m_pos(-1) {}
cmd_exception(std::string const & msg, int line, int pos):default_exception(msg), m_line(line), m_pos(pos) {}
cmd_exception(std::string && msg):default_exception(std::move(msg)), m_line(-1), m_pos(-1) {}
cmd_exception(std::string && msg, int line, int pos):default_exception(std::move(msg)), m_line(line), m_pos(pos) {}
cmd_exception(char const * msg, symbol const & s):
default_exception(compose(msg,s)),m_line(-1),m_pos(-1) {}
cmd_exception(char const * msg, symbol const & s, int line, int pos):

View file

@ -356,7 +356,7 @@ public:
}
}
if (error)
throw exception(error_msg);
throw exception(std::move(error_msg));
}
std::string get_value(params_ref const & ps, symbol const & p) {
@ -417,7 +417,7 @@ public:
}
}
if (error)
throw exception(error_msg);
throw exception(std::move(error_msg));
return r;
}
@ -509,7 +509,7 @@ public:
}
}
if (error)
throw exception(error_msg);
throw exception(std::move(error_msg));
}
void display_parameter(std::ostream & out, char const * name) {
@ -550,7 +550,7 @@ public:
}
}
if (error)
throw exception(error_msg);
throw exception(std::move(error_msg));
}
};

View file

@ -36,8 +36,8 @@ bool contains(const std::unordered_map<A, B> & map, const A& key) {
}
namespace lp {
inline void throw_exception(const std::string & str) {
throw default_exception(str);
inline void throw_exception(std::string && str) {
throw default_exception(std::move(str));
}
typedef z3_exception exception;

View file

@ -27,9 +27,10 @@ Revision History:
#include "util/event_handler.h"
#include "util/scoped_timer.h"
scoped_timer * g_timeout = nullptr;
void (* g_on_timeout)() = nullptr;
static scoped_timer * g_timeout = nullptr;
static void (* g_on_timeout)() = nullptr;
namespace {
class g_timeout_eh : public event_handler {
public:
void operator()(event_handler_caller_t caller_id) override {
@ -46,6 +47,7 @@ public:
}
}
};
}
void set_timeout(long ms) {
if (g_timeout)

View file

@ -67,9 +67,6 @@ default_exception::default_exception(fmt, char const* msg, ...) {
m_msg = out.str();
}
default_exception::default_exception(std::string const & msg): m_msg(msg) {
}
char const * default_exception::msg() const {
return m_msg.c_str();
}

View file

@ -41,7 +41,7 @@ class default_exception : public z3_exception {
std::string m_msg;
public:
struct fmt {};
default_exception(std::string const& msg);
default_exception(std::string && msg) : m_msg(std::move(msg)) {}
default_exception(fmt, char const* msg, ...);
~default_exception() override {}
char const * msg() const override;