mirror of
https://github.com/holub/mame
synced 2025-10-04 00:23:43 +03:00
netlist: more consistent exception handling. (nw)
Still not optimal, but better than what we had previously. No exception logging comes closer.
This commit is contained in:
parent
f315e47b89
commit
22e07506cc
@ -69,7 +69,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void vlog(const plib::plog_level &l, const pstring &ls) const override
|
||||
void vlog(const plib::plog_level &l, const pstring &ls) const noexcept override
|
||||
{
|
||||
switch (l)
|
||||
{
|
||||
@ -89,7 +89,9 @@ protected:
|
||||
m_parent.logerror("netlist ERROR: %s\n", ls.c_str());
|
||||
break;
|
||||
case plib::plog_level::FATAL:
|
||||
throw emu_fatalerror(1, "netlist FATAL: %s\n", ls.c_str());
|
||||
//throw emu_fatalerror(1, "netlist FATAL: %s\n", ls.c_str());
|
||||
m_parent.logerror("netlist FATAL: %s\n", ls.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +109,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void vlog(const plib::plog_level &l, const pstring &ls) const override
|
||||
void vlog(const plib::plog_level &l, const pstring &ls) const noexcept override
|
||||
{
|
||||
switch (l)
|
||||
{
|
||||
@ -125,7 +127,9 @@ protected:
|
||||
osd_printf_error("netlist ERROR: %s\n", ls);
|
||||
break;
|
||||
case plib::plog_level::FATAL:
|
||||
throw emu_fatalerror(1, "netlist FATAL: %s\n", ls.c_str());
|
||||
osd_printf_error("netlist FATAL: %s\n", ls);
|
||||
break;
|
||||
//throw emu_fatalerror(1, "netlist FATAL: %s\n", ls.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ namespace analog
|
||||
{
|
||||
plib::unused_var(d1);
|
||||
if (b)
|
||||
throw nl_exception("bselect with netlist and b==true");
|
||||
plib::pthrow<nl_exception>("bselect with netlist and b==true");
|
||||
return d2;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace netlist
|
||||
, m_writer(&m_strm)
|
||||
{
|
||||
if (m_strm.fail())
|
||||
throw plib::file_open_e(plib::pfmt("{1}.log")(this->name()));
|
||||
plib::pthrow<plib::file_open_e>(plib::pfmt("{1}.log")(this->name()));
|
||||
|
||||
m_strm.imbue(std::locale::classic());
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ namespace netlist
|
||||
m_family_desc = anetlist.setup().family_from_model(m_family_name);
|
||||
|
||||
if (m_family_desc == nullptr)
|
||||
throw nl_exception("family description not found for {1}", m_family_name);
|
||||
plib::pthrow<nl_exception>("family description not found for {1}", m_family_name);
|
||||
|
||||
return pool().make_unique<tt_type>(anetlist, name, m_family_desc, *m_ttbl, m_desc);
|
||||
}
|
||||
@ -353,7 +353,7 @@ void truthtable_parser::parseline(unsigned cur, std::vector<pstring> list,
|
||||
{
|
||||
// cutoff previous inputs and outputs for ignore
|
||||
if (m_out_state[nstate] != m_out_state.mask() && m_out_state[nstate] != val)
|
||||
throw nl_exception(plib::pfmt("Error in truthtable: State {1:04} already set, {2} != {3}\n")
|
||||
plib::pthrow<nl_exception>(plib::pfmt("Error in truthtable: State {1:04} already set, {2} != {3}\n")
|
||||
.x(nstate.as_uint())(m_out_state[nstate])(val) );
|
||||
m_out_state.set(nstate, val);
|
||||
for (std::size_t j=0; j<m_NO; j++)
|
||||
@ -449,7 +449,7 @@ void truthtable_parser::parse(const std::vector<pstring> &truthtable)
|
||||
for (size_t i=0; i<m_size; i++)
|
||||
{
|
||||
if (m_out_state[i] == m_out_state.mask())
|
||||
throw nl_exception(plib::pfmt("truthtable: found element not set {1}\n").x(i) );
|
||||
plib::pthrow<nl_exception>(plib::pfmt("truthtable: found element not set {1}\n").x(i) );
|
||||
m_out_state.set(i, m_out_state[i] | (ign[i] << m_NO));
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ class NETLIB_NAME(name) : public device_t
|
||||
//============================================================
|
||||
|
||||
#if defined(MAME_DEBUG) || (NL_DEBUG == true)
|
||||
#define nl_assert(x) do { if (1) if (!(x)) throw nl_exception(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0)
|
||||
#define nl_assert(x) do { if (1) if (!(x)) plib::pthrow<nl_exception>(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); } while (0)
|
||||
#define NL_NOEXCEPT
|
||||
#else
|
||||
#define nl_assert(x) do { if (0) if (!(x)) { /*throw nl_exception(plib::pfmt("assert: {1}:{2}: {3}")(__FILE__)(__LINE__)(#x) ); */} } while (0)
|
||||
|
@ -20,7 +20,6 @@ void parser_t::verror(const pstring &msg)
|
||||
{
|
||||
m_setup.log().fatal("{1}", msg);
|
||||
plib::pthrow<nl_exception>(plib::pfmt("{1}")(msg));
|
||||
//throw error;
|
||||
}
|
||||
|
||||
bool parser_t::parse(const pstring &nlname)
|
||||
|
@ -902,11 +902,11 @@ void models_t::register_model(const pstring &model_in)
|
||||
{
|
||||
auto pos = model_in.find(' ');
|
||||
if (pos == pstring::npos)
|
||||
throw nl_exception(MF_UNABLE_TO_PARSE_MODEL_1(model_in));
|
||||
plib::pthrow<nl_exception>(MF_UNABLE_TO_PARSE_MODEL_1(model_in));
|
||||
pstring model = plib::ucase(plib::trim(plib::left(model_in, pos)));
|
||||
pstring def = plib::trim(model_in.substr(pos + 1));
|
||||
if (!m_models.insert({model, def}).second)
|
||||
throw nl_exception(MF_MODEL_ALREADY_EXISTS_1(model_in));
|
||||
plib::pthrow<nl_exception>(MF_MODEL_ALREADY_EXISTS_1(model_in));
|
||||
}
|
||||
|
||||
void models_t::model_parse(const pstring &model_in, model_map_t &map)
|
||||
@ -923,7 +923,7 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map)
|
||||
key = plib::ucase(model);
|
||||
auto i = m_models.find(key);
|
||||
if (i == m_models.end())
|
||||
throw nl_exception(MF_MODEL_NOT_FOUND(model));
|
||||
plib::pthrow<nl_exception>(MF_MODEL_NOT_FOUND(model));
|
||||
model = i->second;
|
||||
}
|
||||
pstring xmodel = plib::left(model, pos);
|
||||
@ -936,12 +936,12 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map)
|
||||
if (i != m_models.end())
|
||||
model_parse(xmodel, map);
|
||||
else
|
||||
throw nl_exception(MF_MODEL_NOT_FOUND(model_in));
|
||||
plib::pthrow<nl_exception>(MF_MODEL_NOT_FOUND(model_in));
|
||||
}
|
||||
|
||||
pstring remainder = plib::trim(model.substr(pos + 1));
|
||||
if (!plib::endsWith(remainder, ")"))
|
||||
throw nl_exception(MF_MODEL_ERROR_1(model));
|
||||
plib::pthrow<nl_exception>(MF_MODEL_ERROR_1(model));
|
||||
// FIMXE: Not optimal
|
||||
remainder = plib::left(remainder, remainder.size() - 1);
|
||||
|
||||
@ -950,7 +950,7 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map)
|
||||
{
|
||||
auto pose = pe.find('=');
|
||||
if (pose == pstring::npos)
|
||||
throw nl_exception(MF_MODEL_ERROR_ON_PAIR_1(model));
|
||||
plib::pthrow<nl_exception>(MF_MODEL_ERROR_ON_PAIR_1(model));
|
||||
map[plib::ucase(plib::left(pe, pose))] = pe.substr(pose + 1);
|
||||
}
|
||||
}
|
||||
@ -975,9 +975,9 @@ pstring models_t::value_str(const pstring &model, const pstring &entity)
|
||||
pstring ret;
|
||||
|
||||
if (entity != plib::ucase(entity))
|
||||
throw nl_exception(MF_MODEL_PARAMETERS_NOT_UPPERCASE_1_2(entity, model_string(map)));
|
||||
plib::pthrow<nl_exception>(MF_MODEL_PARAMETERS_NOT_UPPERCASE_1_2(entity, model_string(map)));
|
||||
if (map.find(entity) == map.end())
|
||||
throw nl_exception(MF_ENTITY_1_NOT_FOUND_IN_MODEL_2(entity, model_string(map)));
|
||||
plib::pthrow<nl_exception>(MF_ENTITY_1_NOT_FOUND_IN_MODEL_2(entity, model_string(map)));
|
||||
else
|
||||
ret = map[entity];
|
||||
|
||||
@ -1008,7 +1008,7 @@ nl_fptype models_t::value(const pstring &model, const pstring &entity)
|
||||
case 'a': factor = nlconst::magic(1e-18); break;
|
||||
default:
|
||||
if (*p < '0' || *p > '9')
|
||||
throw nl_exception(MF_UNKNOWN_NUMBER_FACTOR_IN_1(entity));
|
||||
plib::pthrow<nl_exception>(MF_UNKNOWN_NUMBER_FACTOR_IN_1(entity));
|
||||
}
|
||||
if (factor != nlconst::one())
|
||||
tmp = plib::left(tmp, tmp.size() - 1);
|
||||
@ -1017,7 +1017,7 @@ nl_fptype models_t::value(const pstring &model, const pstring &entity)
|
||||
bool err(false);
|
||||
auto val = plib::pstonum_ne<nl_fptype>(tmp, err);
|
||||
if (err)
|
||||
throw nl_exception(MF_MODEL_NUMBER_CONVERSION_ERROR(entity, tmp, "double", model));
|
||||
plib::pthrow<nl_exception>(MF_MODEL_NUMBER_CONVERSION_ERROR(entity, tmp, "double", model));
|
||||
return val * factor;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace netlist
|
||||
COPYASSIGNMOVE(callbacks_t, default)
|
||||
|
||||
/* logging callback */
|
||||
virtual void vlog(const plib::plog_level &l, const pstring &ls) const = 0;
|
||||
virtual void vlog(const plib::plog_level &l, const pstring &ls) const noexcept = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -114,7 +114,7 @@ namespace plib
|
||||
{
|
||||
C nz = 0;
|
||||
if (nz_num != 0)
|
||||
throw pexception("build_from_mat only allowed on empty CR matrix");
|
||||
pthrow<pexception>("build_from_mat only allowed on empty CR matrix");
|
||||
for (std::size_t k=0; k < size(); k++)
|
||||
{
|
||||
row_idx[k] = nz;
|
||||
@ -189,7 +189,7 @@ namespace plib
|
||||
while (col_idx[dp] < src.col_idx[sp])
|
||||
A[dp++] = 0;
|
||||
if (row_idx[r+1] <= dp || col_idx[dp] != src.col_idx[sp])
|
||||
throw plib::pexception("slim_copy_from error");
|
||||
pthrow<pexception>("slim_copy_from error");
|
||||
A[dp++] = src.A[sp];
|
||||
}
|
||||
/* fill remaining elements in row */
|
||||
|
@ -82,7 +82,7 @@ namespace plib {
|
||||
{
|
||||
if ((SIZE < 0 && size > SIZEABS())
|
||||
|| (SIZE > 0 && size != SIZEABS()))
|
||||
throw plib::pexception("parray: size error " + plib::to_string(size) + ">" + plib::to_string(SIZE));
|
||||
pthrow<pexception>("parray: size error " + plib::to_string(size) + ">" + plib::to_string(SIZE));
|
||||
}
|
||||
|
||||
template <int X = SIZE >
|
||||
@ -91,7 +91,7 @@ namespace plib {
|
||||
{
|
||||
if ((SIZE < 0 && size > SIZEABS())
|
||||
|| (SIZE > 0 && size != SIZEABS()))
|
||||
throw plib::pexception("parray: size error " + plib::to_string(size) + ">" + plib::to_string(SIZE));
|
||||
pthrow<plib::pexception>("parray: size error " + plib::to_string(size) + ">" + plib::to_string(SIZE));
|
||||
m_a.fill(val);
|
||||
}
|
||||
|
||||
|
@ -79,16 +79,16 @@ namespace plib {
|
||||
bool err(false);
|
||||
rc.m_param = plib::pstonum_ne<decltype(rc.m_param)>(cmd, err);
|
||||
if (err)
|
||||
throw plib::pexception(plib::pfmt("pfunction: unknown/misformatted token <{1}> in <{2}>")(cmd)(expr));
|
||||
pthrow<pexception>(plib::pfmt("pfunction: unknown/misformatted token <{1}> in <{2}>")(cmd)(expr));
|
||||
stk += 1;
|
||||
}
|
||||
}
|
||||
if (stk < 1)
|
||||
throw plib::pexception(plib::pfmt("pfunction: stack underflow on token <{1}> in <{2}>")(cmd)(expr));
|
||||
pthrow<pexception>(plib::pfmt("pfunction: stack underflow on token <{1}> in <{2}>")(cmd)(expr));
|
||||
m_precompiled.push_back(rc);
|
||||
}
|
||||
if (stk != 1)
|
||||
throw plib::pexception(plib::pfmt("pfunction: stack count different to one on <{2}>")(expr));
|
||||
pthrow<pexception>(plib::pfmt("pfunction: stack count different to one on <{2}>")(expr));
|
||||
}
|
||||
|
||||
static int get_prio(const pstring &v)
|
||||
@ -110,7 +110,7 @@ namespace plib {
|
||||
static pstring pop_check(std::stack<pstring> &stk, const pstring &expr)
|
||||
{
|
||||
if (stk.size() == 0)
|
||||
throw plib::pexception(plib::pfmt("pfunction: stack underflow during infix parsing of: <{1}>")(expr));
|
||||
pthrow<pexception>(plib::pfmt("pfunction: stack underflow during infix parsing of: <{1}>")(expr));
|
||||
pstring res = stk.top();
|
||||
stk.pop();
|
||||
return res;
|
||||
|
@ -82,7 +82,7 @@ namespace plib {
|
||||
{
|
||||
if (m_other_args != nullptr)
|
||||
{
|
||||
throw pexception("other args can only be specified once!");
|
||||
pthrow<pexception>("other args can only be specified once!");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -90,7 +90,7 @@ namespace plib {
|
||||
}
|
||||
}
|
||||
else
|
||||
throw pexception("found option with neither short or long tag!" );
|
||||
pthrow<pexception>("found option with neither short or long tag!" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ namespace plib {
|
||||
s = trail + plib::pfmt("{1}:{2}:0\n")(m_stack.back().m_name, m_stack.back().m_lineno) + s;
|
||||
m_stack.pop_back();
|
||||
}
|
||||
throw pexception("\n" + s + e + " " + m_line + "\n");
|
||||
pthrow<pexception>("\n" + s + e + " " + m_line + "\n");
|
||||
}
|
||||
|
||||
template <typename PP, typename L = ppreprocessor::string_list>
|
||||
|
@ -106,11 +106,11 @@ namespace plib
|
||||
//&& (ret == T(0) || plib::abs(ret) >= std::numeric_limits<T>::min() ))
|
||||
{
|
||||
if (cstr[idx] != 0)
|
||||
throw pexception(pstring("Continuation after numeric value ends: ") + pstring(cstr));
|
||||
pthrow<pexception>(pstring("Continuation after numeric value ends: ") + pstring(cstr));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw pexception(pstring("Out of range: ") + pstring(cstr));
|
||||
pthrow<pexception>(pstring("Out of range: ") + pstring(cstr));
|
||||
}
|
||||
return static_cast<T>(ret);
|
||||
}
|
||||
|
@ -113,6 +113,7 @@ public:
|
||||
pstring_t(C (&string)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
|
||||
{
|
||||
static_assert(N > 0,"pstring from array of length 0");
|
||||
// need std::exception since pexception depends on pstring
|
||||
if (string[N-1] != 0)
|
||||
throw std::exception();
|
||||
m_str.assign(string, N - 1);
|
||||
|
@ -181,7 +181,7 @@ public:
|
||||
, m_app(app)
|
||||
{ }
|
||||
|
||||
void vlog(const plib::plog_level &l, const pstring &ls) const override;
|
||||
void vlog(const plib::plog_level &l, const pstring &ls) const noexcept override;
|
||||
|
||||
private:
|
||||
tool_app_t &m_app;
|
||||
@ -266,7 +266,7 @@ public:
|
||||
size += s->m_dt.size * s->m_count;
|
||||
|
||||
if (buf.size() != size)
|
||||
throw netlist::nl_exception("Size different during load state.");
|
||||
plib::pthrow<netlist::nl_exception>("Size different during load state.");
|
||||
|
||||
char *p = buf.data();
|
||||
|
||||
@ -288,7 +288,7 @@ protected:
|
||||
private:
|
||||
};
|
||||
|
||||
void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls) const
|
||||
void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls) const noexcept
|
||||
{
|
||||
pstring err = plib::pfmt("{}: {}\n")(l.name())(ls.c_str());
|
||||
if (l == plib::plog_level::WARNING)
|
||||
@ -296,12 +296,8 @@ void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls
|
||||
if (l == plib::plog_level::ERROR)
|
||||
m_app.m_errors++;
|
||||
if (l == plib::plog_level::FATAL)
|
||||
{
|
||||
m_app.m_errors++;
|
||||
throw netlist::nl_exception(err);
|
||||
}
|
||||
else
|
||||
m_app.pout("{}", err);
|
||||
m_app.pout("{}", err);
|
||||
}
|
||||
|
||||
struct input_t
|
||||
@ -316,7 +312,7 @@ struct input_t
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
int e = std::sscanf(line.c_str(), "%lf,%[^,],%lf", &t, buf.data(), &val);
|
||||
if (e != 3)
|
||||
throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
|
||||
plib::pthrow<netlist::nl_exception>(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
|
||||
m_value = static_cast<nl_fptype>(val);
|
||||
m_time = netlist::netlist_time::from_fp(t);
|
||||
m_param = setup.find_param(pstring(buf.data()), true);
|
||||
@ -328,7 +324,7 @@ struct input_t
|
||||
{
|
||||
case netlist::param_t::STRING:
|
||||
case netlist::param_t::POINTER:
|
||||
throw netlist::nl_exception(plib::pfmt("param {1} is not numeric\n")(m_param->name()));
|
||||
plib::pthrow<netlist::nl_exception>(plib::pfmt("param {1} is not numeric\n")(m_param->name()));
|
||||
case netlist::param_t::DOUBLE:
|
||||
static_cast<netlist::param_fp_t*>(m_param)->setTo(m_value);
|
||||
break;
|
||||
@ -353,7 +349,7 @@ static std::vector<input_t> read_input(const netlist::setup_t &setup, const pstr
|
||||
{
|
||||
plib::putf8_reader r = plib::putf8_reader(std::ifstream(plib::filesystem::u8path(fname)));
|
||||
if (r.stream().fail())
|
||||
throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(fname));
|
||||
plib::pthrow<netlist::nl_exception>(netlist::MF_FILE_OPEN_ERROR(fname));
|
||||
r.stream().imbue(std::locale::classic());
|
||||
pstring l;
|
||||
while (r.readline(l))
|
||||
@ -410,7 +406,7 @@ void tool_app_t::run()
|
||||
{
|
||||
std::ifstream strm(plib::filesystem::u8path(opt_loadstate()));
|
||||
if (strm.fail())
|
||||
throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(opt_loadstate()));
|
||||
plib::pthrow<netlist::nl_exception>(netlist::MF_FILE_OPEN_ERROR(opt_loadstate()));
|
||||
strm.imbue(std::locale::classic());
|
||||
plib::pbinary_reader reader(strm);
|
||||
std::vector<char> loadstate;
|
||||
@ -448,7 +444,7 @@ void tool_app_t::run()
|
||||
auto savestate = nt.save_state();
|
||||
std::ofstream strm(plib::filesystem::u8path(opt_savestate()), std::ios_base::binary);
|
||||
if (strm.fail())
|
||||
throw plib::file_open_e(opt_savestate());
|
||||
plib::pthrow<plib::file_open_e>(opt_savestate());
|
||||
strm.imbue(std::locale::classic());
|
||||
|
||||
plib::pbinary_writer writer(strm);
|
||||
@ -496,14 +492,14 @@ void tool_app_t::validate()
|
||||
//pout("Validation errors: {}\n", m_errors);
|
||||
|
||||
if (m_warnings + m_errors > 0)
|
||||
throw netlist::nl_exception("validation: {1} errors {2} warnings", m_errors, m_warnings);
|
||||
plib::pthrow<netlist::nl_exception>("validation: {1} errors {2} warnings", m_errors, m_warnings);
|
||||
|
||||
}
|
||||
|
||||
void tool_app_t::static_compile()
|
||||
{
|
||||
if (!opt_dir.was_specified())
|
||||
throw netlist::nl_exception("--dir option needs to be specified");
|
||||
plib::pthrow<netlist::nl_exception>("--dir option needs to be specified");
|
||||
|
||||
netlist_tool_t nt(*this, "netlist");
|
||||
|
||||
@ -763,7 +759,7 @@ void tool_app_t::convert()
|
||||
{
|
||||
std::ifstream strm(plib::filesystem::u8path(opt_file()));
|
||||
if (strm.fail())
|
||||
throw netlist::nl_exception(netlist::MF_FILE_OPEN_ERROR(opt_file()));
|
||||
plib::pthrow<netlist::nl_exception>(netlist::MF_FILE_OPEN_ERROR(opt_file()));
|
||||
strm.imbue(std::locale::classic());
|
||||
plib::copystream(ostrm, strm);
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ int nlwav_app::execute()
|
||||
{
|
||||
auto outstrm(std::ofstream(plib::filesystem::u8path(opt_out())));
|
||||
if (outstrm.fail())
|
||||
throw plib::file_open_e(opt_out());
|
||||
plib::pthrow<plib::file_open_e>(opt_out());
|
||||
outstrm.imbue(std::locale::classic());
|
||||
convert(outstrm);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user