3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-14 21:08:46 +00:00

enforce stringstream formatting to avoid default format routine. fixes issue #149

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2015-07-06 09:11:52 -07:00
parent 3fd5d0eaba
commit 940fed16e1
6 changed files with 71 additions and 44 deletions

View file

@ -45,7 +45,9 @@ void context_params::set_bool(bool & opt, char const * param, char const * value
opt = false; opt = false;
} }
else { else {
throw default_exception("invalid value '%s' for Boolean parameter '%s'", value, param); std::stringstream strm;
strm << "invalid value '" << value << "' for Boolean parameter '" << param;
throw default_exception(strm.str());
} }
} }

View file

@ -665,7 +665,7 @@ protected:
dtoken unexpected(dtoken tok, char const* msg) { dtoken unexpected(dtoken tok, char const* msg) {
#if 1 #if 1
throw default_exception("%s at line %u '%s' found '%s'\n", msg, throw default_exception(default_exception::fmt(), "%s at line %u '%s' found '%s'\n", msg,
m_lexer->get_line(), m_lexer->get_token_data(), dtoken_strings[tok]); m_lexer->get_line(), m_lexer->get_token_data(), dtoken_strings[tok]);
SASSERT(false); SASSERT(false);
@ -958,7 +958,7 @@ protected:
m_vars.insert(data.bare_str(), v); m_vars.insert(data.bare_str(), v);
} }
else if (s != m_manager.get_sort(v)) { else if (s != m_manager.get_sort(v)) {
throw default_exception("sort: %s expected, but got: %s\n", throw default_exception(default_exception::fmt(), "sort: %s expected, but got: %s\n",
s->get_name().bare_str(), m_manager.get_sort(v)->get_name().bare_str()); s->get_name().bare_str(), m_manager.get_sort(v)->get_name().bare_str());
} }
args.push_back(v); args.push_back(v);
@ -1074,7 +1074,7 @@ protected:
sort * register_finite_sort(symbol name, uint64 domain_size, context::sort_kind k) { sort * register_finite_sort(symbol name, uint64 domain_size, context::sort_kind k) {
if(m_sort_dict.contains(name.bare_str())) { if(m_sort_dict.contains(name.bare_str())) {
throw default_exception("sort %s already declared", name.bare_str()); throw default_exception(default_exception::fmt(), "sort %s already declared", name.bare_str());
} }
sort * s = m_decl_util.mk_sort(name, domain_size); sort * s = m_decl_util.mk_sort(name, domain_size);
m_context.register_finite_sort(s, k); m_context.register_finite_sort(s, k);
@ -1084,7 +1084,7 @@ protected:
sort * register_int_sort(symbol name) { sort * register_int_sort(symbol name) {
if(m_sort_dict.contains(name.bare_str())) { if(m_sort_dict.contains(name.bare_str())) {
throw default_exception("sort %s already declared", name.bare_str()); throw default_exception(default_exception::fmt(), "sort %s already declared", name.bare_str());
} }
sort * s = m_arith.mk_int(); sort * s = m_arith.mk_int();
m_sort_dict.insert(name.bare_str(), s); m_sort_dict.insert(name.bare_str(), s);
@ -1094,7 +1094,7 @@ protected:
sort * get_sort(const char* str) { sort * get_sort(const char* str) {
sort * res; sort * res;
if(!m_sort_dict.find(str, res)) { if(!m_sort_dict.find(str, res)) {
throw default_exception("unknown sort \"%s\"", str); throw default_exception(default_exception::fmt(), "unknown sort \"%s\"", str);
} }
return res; return res;
} }
@ -1104,7 +1104,7 @@ protected:
if(m_arith.is_int(s)) { if(m_arith.is_int(s)) {
uint64 val; uint64 val;
if(!string_to_uint64(name.bare_str(), val)) { if(!string_to_uint64(name.bare_str(), val)) {
throw default_exception("Invalid integer: \"&s\"", name.bare_str()); throw default_exception(default_exception::fmt(), "Invalid integer: \"%s\"", name.bare_str());
} }
res = m_arith.mk_numeral(rational(val, rational::ui64()), s); res = m_arith.mk_numeral(rational(val, rational::ui64()), s);
} }
@ -1295,7 +1295,7 @@ private:
if(num==0) { if(num==0) {
const_name = symbol("<zero element>"); const_name = symbol("<zero element>");
} else if(!m_number_names.find(num, const_name)) { } else if(!m_number_names.find(num, const_name)) {
throw default_exception("unknown symbol number %I64u on line %d in file %s", throw default_exception(default_exception::fmt(), "unknown symbol number %I64u on line %d in file %s",
num, m_current_line, m_current_file.c_str()); num, m_current_line, m_current_file.c_str());
} }
res = mk_table_const(const_name, s); res = mk_table_const(const_name, s);
@ -1334,12 +1334,13 @@ private:
} }
uint64 num; uint64 num;
if(!read_uint64(ptr, num)) { if(!read_uint64(ptr, num)) {
throw default_exception("number expected on line %d in file %s", throw default_exception(default_exception::fmt(), "number expected on line %d in file %s",
m_current_line, m_current_file.c_str()); m_current_line, m_current_file.c_str());
} }
if(*ptr!=' ' && *ptr!=0) { if(*ptr!=' ' && *ptr!=0) {
throw default_exception("' ' expected to separate numbers on line %d in file %s, got '%s'", throw default_exception(default_exception::fmt(),
m_current_line, m_current_file.c_str(), ptr); "' ' expected to separate numbers on line %d in file %s, got '%s'",
m_current_line, m_current_file.c_str(), ptr);
} }
args.push_back(num); args.push_back(num);
} while(!last); } while(!last);
@ -1359,7 +1360,7 @@ private:
func_decl * pred = m_context.try_get_predicate_decl(predicate_name); func_decl * pred = m_context.try_get_predicate_decl(predicate_name);
if(!pred) { if(!pred) {
throw default_exception("tuple file %s for undeclared predicate %s", throw default_exception(default_exception::fmt(), "tuple file %s for undeclared predicate %s",
m_current_file.c_str(), predicate_name.bare_str()); m_current_file.c_str(), predicate_name.bare_str());
} }
unsigned pred_arity = pred->get_arity(); unsigned pred_arity = pred->get_arity();
@ -1381,7 +1382,7 @@ private:
continue; continue;
} }
if(args.size()!=pred_arity) { if(args.size()!=pred_arity) {
throw default_exception("invalid number of arguments on line %d in file %s", throw default_exception(default_exception::fmt(), "invalid number of arguments on line %d in file %s",
m_current_line, m_current_file.c_str()); m_current_line, m_current_file.c_str());
} }
@ -1450,10 +1451,12 @@ private:
const char * ptr = full_line; const char * ptr = full_line;
if(!read_uint64(ptr, num)) { if(!read_uint64(ptr, num)) {
throw default_exception("number expected at line %d in file %s", m_current_line, m_current_file.c_str()); throw default_exception(default_exception::fmt(),
"number expected at line %d in file %s", m_current_line, m_current_file.c_str());
} }
if(*ptr!=' ') { if(*ptr!=' ') {
throw default_exception("' ' expected after the number at line %d in file %s", m_current_line, m_current_file.c_str()); throw default_exception(default_exception::fmt(),
"' ' expected after the number at line %d in file %s", m_current_line, m_current_file.c_str());
} }
ptr++; ptr++;

View file

@ -385,8 +385,9 @@ namespace datalog {
if (!find_fn(r1, r2, fn)) { if (!find_fn(r1, r2, fn)) {
fn = r1.get_manager().mk_join_fn(r1, r2, m_cols1, m_cols2); fn = r1.get_manager().mk_join_fn(r1, r2, m_cols1, m_cols2);
if (!fn) { if (!fn) {
throw default_exception("trying to perform unsupported join operation on relations of kinds %s and %s", throw default_exception(default_exception::fmt(),
r1.get_plugin().get_name().bare_str(), r2.get_plugin().get_name().bare_str()); "trying to perform unsupported join operation on relations of kinds %s and %s",
r1.get_plugin().get_name().bare_str(), r2.get_plugin().get_name().bare_str());
} }
store_fn(r1, r2, fn); store_fn(r1, r2, fn);
} }
@ -447,7 +448,7 @@ namespace datalog {
if (!find_fn(r, fn)) { if (!find_fn(r, fn)) {
fn = r.get_manager().mk_filter_equal_fn(r, m_value, m_col); fn = r.get_manager().mk_filter_equal_fn(r, m_value, m_col);
if (!fn) { if (!fn) {
throw default_exception( throw default_exception(default_exception::fmt(),
"trying to perform unsupported filter_equal operation on a relation of kind %s", "trying to perform unsupported filter_equal operation on a relation of kind %s",
r.get_plugin().get_name().bare_str()); r.get_plugin().get_name().bare_str());
} }
@ -496,7 +497,7 @@ namespace datalog {
if (!find_fn(r, fn)) { if (!find_fn(r, fn)) {
fn = r.get_manager().mk_filter_identical_fn(r, m_cols.size(), m_cols.c_ptr()); fn = r.get_manager().mk_filter_identical_fn(r, m_cols.size(), m_cols.c_ptr());
if (!fn) { if (!fn) {
throw default_exception( throw default_exception(default_exception::fmt(),
"trying to perform unsupported filter_identical operation on a relation of kind %s", "trying to perform unsupported filter_identical operation on a relation of kind %s",
r.get_plugin().get_name().bare_str()); r.get_plugin().get_name().bare_str());
} }
@ -542,7 +543,7 @@ namespace datalog {
if (!find_fn(r, fn)) { if (!find_fn(r, fn)) {
fn = r.get_manager().mk_filter_interpreted_fn(r, m_cond); fn = r.get_manager().mk_filter_interpreted_fn(r, m_cond);
if (!fn) { if (!fn) {
throw default_exception( throw default_exception(default_exception::fmt(),
"trying to perform unsupported filter_interpreted operation on a relation of kind %s", "trying to perform unsupported filter_interpreted operation on a relation of kind %s",
r.get_plugin().get_name().bare_str()); r.get_plugin().get_name().bare_str());
} }
@ -598,7 +599,7 @@ namespace datalog {
if (!find_fn(reg, fn)) { if (!find_fn(reg, fn)) {
fn = reg.get_manager().mk_filter_interpreted_and_project_fn(reg, m_cond, m_cols.size(), m_cols.c_ptr()); fn = reg.get_manager().mk_filter_interpreted_and_project_fn(reg, m_cond, m_cols.size(), m_cols.c_ptr());
if (!fn) { if (!fn) {
throw default_exception( throw default_exception(default_exception::fmt(),
"trying to perform unsupported filter_interpreted_and_project operation on a relation of kind %s", "trying to perform unsupported filter_interpreted_and_project operation on a relation of kind %s",
reg.get_plugin().get_name().bare_str()); reg.get_plugin().get_name().bare_str());
} }
@ -838,7 +839,8 @@ namespace datalog {
if (!find_fn(r1, r2, fn)) { if (!find_fn(r1, r2, fn)) {
fn = r1.get_manager().mk_join_project_fn(r1, r2, m_cols1, m_cols2, m_removed_cols); fn = r1.get_manager().mk_join_project_fn(r1, r2, m_cols1, m_cols2, m_removed_cols);
if (!fn) { if (!fn) {
throw default_exception("trying to perform unsupported join-project operation on relations of kinds %s and %s", throw default_exception(default_exception::fmt(),
"trying to perform unsupported join-project operation on relations of kinds %s and %s",
r1.get_plugin().get_name().bare_str(), r2.get_plugin().get_name().bare_str()); r1.get_plugin().get_name().bare_str(), r2.get_plugin().get_name().bare_str());
} }
store_fn(r1, r2, fn); store_fn(r1, r2, fn);
@ -905,7 +907,7 @@ namespace datalog {
const relation_base & s = *ctx.reg(m_source_reg); const relation_base & s = *ctx.reg(m_source_reg);
if (!s.from_table()) { if (!s.from_table()) {
throw default_exception("relation is not a table %s", throw default_exception(default_exception::fmt(), "relation is not a table %s",
s.get_plugin().get_name().bare_str()); s.get_plugin().get_name().bare_str());
} }
++ctx.m_stats.m_min; ++ctx.m_stats.m_min;
@ -963,7 +965,7 @@ namespace datalog {
if (!find_fn(r, fn)) { if (!find_fn(r, fn)) {
fn = r.get_manager().mk_select_equal_and_project_fn(r, m_value, m_col); fn = r.get_manager().mk_select_equal_and_project_fn(r, m_value, m_col);
if (!fn) { if (!fn) {
throw default_exception( throw default_exception(default_exception::fmt(),
"trying to perform unsupported select_equal_and_project operation on a relation of kind %s", "trying to perform unsupported select_equal_and_project operation on a relation of kind %s",
r.get_plugin().get_name().bare_str()); r.get_plugin().get_name().bare_str());
} }

View file

@ -205,12 +205,17 @@ public:
if (mod_name == symbol::null) { if (mod_name == symbol::null) {
char const * new_name = get_new_param_name(param_name); char const * new_name = get_new_param_name(param_name);
if (new_name) { if (new_name) {
throw exception("the parameter '%s' was renamed to '%s', invoke 'z3 -p' to obtain the new parameter list, and 'z3 -pp:%s' for the full description of the parameter", std::stringstream strm;
param_name.bare_str(), new_name, new_name); strm << "the parameter '" << param_name
<< "', invoke 'z3 -p' to obtain the new parameter list, and 'z3 -pp:" << new_name
<< "' for the full description of the parameter";
throw exception(strm.str());
} }
else if (is_old_param_name(param_name)) { else if (is_old_param_name(param_name)) {
throw exception("unknown parameter '%s', this is an old parameter name, invoke 'z3 -p' to obtain the new parameter list", std::stringstream strm;
param_name.bare_str()); strm << "unknown parameter '" << param_name
<< "', this is an old parameter name, invoke 'z3 -p' to obtain the new parameter list";
throw default_exception(strm.str());
} }
else { else {
std::stringstream strm; std::stringstream strm;
@ -290,10 +295,12 @@ public:
ps.set_bool(param_name, false); ps.set_bool(param_name, false);
} }
else { else {
if (mod_name == symbol::null) std::stringstream strm;
throw exception("invalid value '%s' for Boolean parameter '%s'", value, param_name.bare_str()); strm << "invalid value '" << value << "' for Boolean parameter '" << param_name << "'";
else if (mod_name == symbol::null) {
throw exception("invalid value '%s' for Boolean parameter '%s' at module '%s'", value, param_name.bare_str(), mod_name.bare_str()); strm << " at module '" << mod_name << "'";
}
throw default_exception(strm.str());
} }
} }
else if (k == CPK_SYMBOL) { else if (k == CPK_SYMBOL) {
@ -312,10 +319,12 @@ public:
ps.set_str(param_name, symbol(value).bare_str()); ps.set_str(param_name, symbol(value).bare_str());
} }
else { else {
if (mod_name == symbol::null) std::stringstream strm;
throw exception("unsupported parameter type '%s'", param_name.bare_str()); strm << "unsupported parameter type '" << param_name << "'";
else if (mod_name == symbol::null) {
throw exception("unsupported parameter type '%s' at module '%s'", param_name.bare_str(), mod_name.bare_str()); strm << " at module '" << mod_name << "'";
}
throw exception(strm.str());
} }
} }
@ -338,7 +347,9 @@ public:
set(*d, p, value, m); set(*d, p, value, m);
} }
else { else {
throw exception("invalid parameter, unknown module '%s'", m.bare_str()); std::stringstream strm;
strm << "invalid parameter, unknown module '" << m << "'";
throw exception(strm.str());
} }
} }
} }
@ -396,7 +407,9 @@ public:
r = get_default(*d, p, m); r = get_default(*d, p, m);
} }
else { else {
throw exception("unknown module '%s'", m.bare_str()); std::stringstream strm;
strm << "unknown module '" << m << "'";
throw exception(strm.str());
} }
} }
} }
@ -488,8 +501,11 @@ public:
{ {
try { try {
param_descrs * d = 0; param_descrs * d = 0;
if (!get_module_param_descrs().find(module_name, d)) if (!get_module_param_descrs().find(module_name, d)) {
throw exception("unknown module '%s'", module_name.bare_str()); std::stringstream strm;
strm << "unknown module '" << module_name << "'";
throw exception(strm.str());
}
out << "[module] " << module_name; out << "[module] " << module_name;
char const * descr = 0; char const * descr = 0;
if (get_module_descrs().find(module_name, descr)) { if (get_module_descrs().find(module_name, descr)) {
@ -522,8 +538,11 @@ public:
d = &get_param_descrs(); d = &get_param_descrs();
} }
else { else {
if (!get_module_param_descrs().find(m, d)) if (!get_module_param_descrs().find(m, d)) {
throw exception("unknown module '%s'", m.bare_str()); std::stringstream strm;
strm << "unknown module '" << m << "'";
throw exception(strm.str());
}
} }
if (!d->contains(p)) if (!d->contains(p))
throw_unknown_parameter(p, *d, m); throw_unknown_parameter(p, *d, m);

View file

@ -58,7 +58,7 @@ unsigned z3_error::error_code() const {
return m_error_code; return m_error_code;
} }
default_exception::default_exception(char const* msg, ...) { default_exception::default_exception(fmt, char const* msg, ...) {
std::stringstream out; std::stringstream out;
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);

View file

@ -40,8 +40,9 @@ public:
class default_exception : public z3_exception { class default_exception : public z3_exception {
std::string m_msg; std::string m_msg;
public: public:
struct fmt {};
default_exception(std::string const& msg); default_exception(std::string const& msg);
default_exception(char const* msg, ...); default_exception(fmt, char const* msg, ...);
virtual ~default_exception() {} virtual ~default_exception() {}
virtual char const * msg() const; virtual char const * msg() const;
}; };