3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-12 20:18:18 +00:00

minor code simplification

This commit is contained in:
Nuno Lopes 2019-09-03 15:51:51 +01:00
parent 68e4ed3c9c
commit cb75326686

View file

@ -326,11 +326,7 @@ public:
} }
void set(char const * name, char const * value) { void set(char const * name, char const * value) {
bool error = false;
std::string error_msg;
{
lock_guard lock(*gparams_mux); lock_guard lock(*gparams_mux);
try {
symbol m, p; symbol m, p;
normalize(name, m, p); normalize(name, m, p);
if (m == symbol::null) { if (m == symbol::null) {
@ -350,15 +346,6 @@ public:
} }
} }
} }
catch (z3_exception & ex) {
// Exception cannot cross critical section boundaries.
error = true;
error_msg = ex.msg();
}
}
if (error)
throw exception(std::move(error_msg));
}
std::string get_value(params_ref const & ps, symbol const & p) { std::string get_value(params_ref const & ps, symbol const & p) {
std::ostringstream buffer; std::ostringstream buffer;
@ -377,50 +364,33 @@ public:
} }
std::string get_value(char const * name) { std::string get_value(char const * name) {
std::string r;
bool error = false;
std::string error_msg;
{
lock_guard lock(*gparams_mux); lock_guard lock(*gparams_mux);
try {
symbol m, p; symbol m, p;
normalize(name, m, p); normalize(name, m, p);
if (m == symbol::null) { if (m == symbol::null) {
if (m_params.contains(p)) { if (m_params.contains(p)) {
r = get_value(m_params, p); return get_value(m_params, p);
} }
else { else {
r = get_default(get_param_descrs(), p, m); return get_default(get_param_descrs(), p, m);
} }
} }
else { else {
params_ref * ps = nullptr; params_ref * ps = nullptr;
if (m_module_params.find(m, ps) && ps->contains(p)) { if (m_module_params.find(m, ps) && ps->contains(p)) {
r = get_value(*ps, p); return get_value(*ps, p);
} }
else { else {
param_descrs * d; param_descrs * d;
if (get_module_param_descrs().find(m, d)) { if (get_module_param_descrs().find(m, d)) {
r = get_default(*d, p, m); return get_default(*d, p, m);
}
}
} }
else {
std::stringstream strm; std::stringstream strm;
strm << "unknown module '" << m << "'"; strm << "unknown module '" << m << "'";
throw exception(strm.str()); throw exception(strm.str());
} }
}
}
}
catch (z3_exception & ex) {
// Exception cannot cross critical section boundaries.
error = true;
error_msg = ex.msg();
}
}
if (error)
throw exception(std::move(error_msg));
return r;
}
// unfortunately, params_ref is not thread safe // unfortunately, params_ref is not thread safe
// so better create a local copy of the parameters. // so better create a local copy of the parameters.
@ -480,10 +450,7 @@ public:
} }
void display_module(std::ostream & out, symbol const & module_name) { void display_module(std::ostream & out, symbol const & module_name) {
bool error = false;
std::string error_msg;
lock_guard lock(*gparams_mux); lock_guard lock(*gparams_mux);
try {
param_descrs * d = nullptr; param_descrs * d = nullptr;
if (!get_module_param_descrs().find(module_name, d)) { if (!get_module_param_descrs().find(module_name, d)) {
std::stringstream strm; std::stringstream strm;
@ -498,21 +465,9 @@ public:
out << "\n"; out << "\n";
d->display(out, 4, false); d->display(out, 4, false);
} }
catch (z3_exception & ex) {
// Exception cannot cross critical section boundaries.
error = true;
error_msg = ex.msg();
}
if (error)
throw exception(std::move(error_msg));
}
void display_parameter(std::ostream & out, char const * name) { void display_parameter(std::ostream & out, char const * name) {
bool error = false;
std::string error_msg;
{
lock_guard lock(*gparams_mux); lock_guard lock(*gparams_mux);
try {
symbol m, p; symbol m, p;
normalize(name, m, p); normalize(name, m, p);
out << name << " " << m << " " << p << "\n"; out << name << " " << m << " " << p << "\n";
@ -538,15 +493,6 @@ public:
out << " description: " << d->get_descr(p) << "\n"; out << " description: " << d->get_descr(p) << "\n";
out << " default value: " << d->get_default(p) << "\n"; out << " default value: " << d->get_default(p) << "\n";
} }
catch (z3_exception & ex) {
// Exception cannot cross critical section boundaries.
error = true;
error_msg = ex.msg();
}
}
if (error)
throw exception(std::move(error_msg));
}
}; };
gparams::imp * gparams::g_imp = nullptr; gparams::imp * gparams::g_imp = nullptr;
@ -637,5 +583,3 @@ void gparams::finalize() {
dealloc(g_imp); dealloc(g_imp);
delete gparams_mux; delete gparams_mux;
} }