mirror of
https://github.com/Z3Prover/z3
synced 2025-04-12 12:08:18 +00:00
minor code simplification
This commit is contained in:
parent
68e4ed3c9c
commit
cb75326686
|
@ -326,38 +326,25 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void set(char const * name, char const * value) {
|
void set(char const * name, char const * value) {
|
||||||
bool error = false;
|
lock_guard lock(*gparams_mux);
|
||||||
std::string error_msg;
|
symbol m, p;
|
||||||
{
|
normalize(name, m, p);
|
||||||
lock_guard lock(*gparams_mux);
|
if (m == symbol::null) {
|
||||||
try {
|
validate_type(p, value, get_param_descrs());
|
||||||
symbol m, p;
|
set(get_param_descrs(), p, value, m);
|
||||||
normalize(name, m, p);
|
}
|
||||||
if (m == symbol::null) {
|
else {
|
||||||
validate_type(p, value, get_param_descrs());
|
param_descrs * d;
|
||||||
set(get_param_descrs(), p, value, m);
|
if (get_module_param_descrs().find(m, d)) {
|
||||||
}
|
validate_type(p, value, *d);
|
||||||
else {
|
set(*d, p, value, m);
|
||||||
param_descrs * d;
|
|
||||||
if (get_module_param_descrs().find(m, d)) {
|
|
||||||
validate_type(p, value, *d);
|
|
||||||
set(*d, p, value, m);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::stringstream strm;
|
|
||||||
strm << "invalid parameter, unknown module '" << m << "'";
|
|
||||||
throw exception(strm.str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (z3_exception & ex) {
|
else {
|
||||||
// Exception cannot cross critical section boundaries.
|
std::stringstream strm;
|
||||||
error = true;
|
strm << "invalid parameter, unknown module '" << m << "'";
|
||||||
error_msg = ex.msg();
|
throw exception(strm.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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) {
|
||||||
|
@ -377,49 +364,32 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_value(char const * name) {
|
std::string get_value(char const * name) {
|
||||||
std::string r;
|
lock_guard lock(*gparams_mux);
|
||||||
bool error = false;
|
symbol m, p;
|
||||||
std::string error_msg;
|
normalize(name, m, p);
|
||||||
{
|
if (m == symbol::null) {
|
||||||
lock_guard lock(*gparams_mux);
|
if (m_params.contains(p)) {
|
||||||
try {
|
return get_value(m_params, p);
|
||||||
symbol m, p;
|
|
||||||
normalize(name, m, p);
|
|
||||||
if (m == symbol::null) {
|
|
||||||
if (m_params.contains(p)) {
|
|
||||||
r = get_value(m_params, p);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
r = get_default(get_param_descrs(), p, m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
params_ref * ps = nullptr;
|
|
||||||
if (m_module_params.find(m, ps) && ps->contains(p)) {
|
|
||||||
r = get_value(*ps, p);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
param_descrs * d;
|
|
||||||
if (get_module_param_descrs().find(m, d)) {
|
|
||||||
r = get_default(*d, p, m);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::stringstream strm;
|
|
||||||
strm << "unknown module '" << m << "'";
|
|
||||||
throw exception(strm.str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (z3_exception & ex) {
|
else {
|
||||||
// Exception cannot cross critical section boundaries.
|
return get_default(get_param_descrs(), p, m);
|
||||||
error = true;
|
|
||||||
error_msg = ex.msg();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (error)
|
else {
|
||||||
throw exception(std::move(error_msg));
|
params_ref * ps = nullptr;
|
||||||
return r;
|
if (m_module_params.find(m, ps) && ps->contains(p)) {
|
||||||
|
return get_value(*ps, p);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
param_descrs * d;
|
||||||
|
if (get_module_param_descrs().find(m, d)) {
|
||||||
|
return get_default(*d, p, m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::stringstream strm;
|
||||||
|
strm << "unknown module '" << m << "'";
|
||||||
|
throw exception(strm.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// unfortunately, params_ref is not thread safe
|
// unfortunately, params_ref is not thread safe
|
||||||
|
@ -480,72 +450,48 @@ 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;
|
strm << "unknown module '" << module_name << "'";
|
||||||
strm << "unknown module '" << module_name << "'";
|
throw exception(strm.str());
|
||||||
throw exception(strm.str());
|
|
||||||
}
|
|
||||||
out << "[module] " << module_name;
|
|
||||||
char const * descr = nullptr;
|
|
||||||
if (get_module_descrs().find(module_name, descr)) {
|
|
||||||
out << ", description: " << descr;
|
|
||||||
}
|
|
||||||
out << "\n";
|
|
||||||
d->display(out, 4, false);
|
|
||||||
}
|
}
|
||||||
catch (z3_exception & ex) {
|
out << "[module] " << module_name;
|
||||||
// Exception cannot cross critical section boundaries.
|
char const * descr = nullptr;
|
||||||
error = true;
|
if (get_module_descrs().find(module_name, descr)) {
|
||||||
error_msg = ex.msg();
|
out << ", description: " << descr;
|
||||||
}
|
}
|
||||||
if (error)
|
out << "\n";
|
||||||
throw exception(std::move(error_msg));
|
d->display(out, 4, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_parameter(std::ostream & out, char const * name) {
|
void display_parameter(std::ostream & out, char const * name) {
|
||||||
bool error = false;
|
lock_guard lock(*gparams_mux);
|
||||||
std::string error_msg;
|
symbol m, p;
|
||||||
{
|
normalize(name, m, p);
|
||||||
lock_guard lock(*gparams_mux);
|
out << name << " " << m << " " << p << "\n";
|
||||||
try {
|
param_descrs * d;
|
||||||
symbol m, p;
|
if (m == symbol::null) {
|
||||||
normalize(name, m, p);
|
d = &get_param_descrs();
|
||||||
out << name << " " << m << " " << p << "\n";
|
}
|
||||||
param_descrs * d;
|
else {
|
||||||
if (m == symbol::null) {
|
if (!get_module_param_descrs().find(m, d)) {
|
||||||
d = &get_param_descrs();
|
std::stringstream strm;
|
||||||
}
|
strm << "unknown module '" << m << "'";
|
||||||
else {
|
throw exception(strm.str());
|
||||||
if (!get_module_param_descrs().find(m, d)) {
|
|
||||||
std::stringstream strm;
|
|
||||||
strm << "unknown module '" << m << "'";
|
|
||||||
throw exception(strm.str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!d->contains(p))
|
|
||||||
throw_unknown_parameter(p, *d, m);
|
|
||||||
out << " name: " << p << "\n";
|
|
||||||
if (m != symbol::null) {
|
|
||||||
out << " module: " << m << "\n";
|
|
||||||
out << " qualified name: " << m << "." << p << "\n";
|
|
||||||
}
|
|
||||||
out << " type: " << d->get_kind(p) << "\n";
|
|
||||||
out << " description: " << d->get_descr(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)
|
if (!d->contains(p))
|
||||||
throw exception(std::move(error_msg));
|
throw_unknown_parameter(p, *d, m);
|
||||||
|
out << " name: " << p << "\n";
|
||||||
|
if (m != symbol::null) {
|
||||||
|
out << " module: " << m << "\n";
|
||||||
|
out << " qualified name: " << m << "." << p << "\n";
|
||||||
|
}
|
||||||
|
out << " type: " << d->get_kind(p) << "\n";
|
||||||
|
out << " description: " << d->get_descr(p) << "\n";
|
||||||
|
out << " default value: " << d->get_default(p) << "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -637,5 +583,3 @@ void gparams::finalize() {
|
||||||
dealloc(g_imp);
|
dealloc(g_imp);
|
||||||
delete gparams_mux;
|
delete gparams_mux;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue