Code maintenance and fix for "pure virtual call" error. (nw)

This commit is contained in:
couriersud 2019-01-06 20:04:39 +01:00
parent fc59d08474
commit 3c6d9ac9a0
8 changed files with 35 additions and 28 deletions

View File

@ -837,6 +837,8 @@ void netlist_mame_device::device_start()
m_netlist = global_alloc(netlist_mame_t(*this, "netlist"));
m_netlist->load_base_libraries();
// register additional devices
nl_register_devices();

View File

@ -253,8 +253,6 @@ netlist_t::netlist_t(const pstring &aname)
state().save_item(this, static_cast<plib::state_manager_t::callback_t &>(m_queue), "m_queue");
state().save_item(this, m_time, "m_time");
m_setup = plib::make_unique<setup_t>(*this);
/* FIXME: doesn't really belong here */
NETLIST_NAME(base)(*m_setup);
}
netlist_t::~netlist_t()
@ -263,6 +261,11 @@ netlist_t::~netlist_t()
m_devices.clear();
}
void netlist_t::load_base_libraries()
{
NETLIST_NAME(base)(*m_setup);
}
nl_double netlist_t::gmin() const NL_NOEXCEPT
{
return solver()->gmin();

View File

@ -1222,6 +1222,14 @@ namespace netlist
explicit netlist_t(const pstring &aname);
virtual ~netlist_t();
/**
* @brief Load base libraries for diodes, transistors ...
*
* This must be called after netlist_t is created.
*
*/
void load_base_libraries();
/* run functions */
const netlist_time &time() const NL_NOEXCEPT { return m_time; }

View File

@ -58,7 +58,8 @@
//#define MF_1_CLASS_1_NOT_FOUND "Class {1} not found!"
#define MF_1_UNABLE_TO_PARSE_MODEL_1 "Unable to parse model: {1}"
#define MF_1_MODEL_ALREADY_EXISTS_1 "Model already exists: {1}"
#define MF_1_ADDING_ALI1_TO_ALIAS_LIST "Error adding alias {1} to alias list"
#define MF_1_DEVICE_ALREADY_EXISTS_1 "Device already exists: {1}"
#define MF_1_ADDING_ALI1_TO_ALIAS_LIST "Error adding alias {1} to alias list"
#define MF_1_DIP_PINS_MUST_BE_AN_EQUAL_NUMBER_OF_PINS_1 "You must pass an equal number of pins to DIPPINS {1}"
#define MF_1_UNKNOWN_OBJECT_TYPE_1 "Unknown object type {1}"
#define MF_2_INVALID_NUMBER_CONVERSION_1_2 "Invalid number conversion {1} : {2}"

View File

@ -78,17 +78,15 @@ void setup_t::register_dev(const pstring &classname, const pstring &name)
log().fatal(MF_1_CLASS_1_NOT_FOUND, classname);
/* make sure we parse macro library entries */
f->macro_actions(netlist(), name);
m_device_factory.push_back(std::pair<pstring, factory::element_t *>(build_fqn(name), f));
pstring key = build_fqn(name);
if (device_exists(key))
log().fatal(MF_1_DEVICE_ALREADY_EXISTS_1, name);
m_device_factory[key] = f;
}
bool setup_t::device_exists(const pstring &name) const
{
for (auto e : m_device_factory)
{
if (e.first == name)
return true;
}
return false;
return (m_device_factory.find(name) != m_device_factory.end());
}
@ -160,7 +158,7 @@ double setup_t::get_initial_param_val(const pstring &name, const double def)
if (i != m_param_values.end())
{
double vald = 0;
if (sscanf(i->second.c_str(), "%lf", &vald) != 1)
if (!plib::pstod_ne(i->second, vald))
log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second);
return vald;
}
@ -173,9 +171,12 @@ int setup_t::get_initial_param_val(const pstring &name, const int def)
auto i = m_param_values.find(name);
if (i != m_param_values.end())
{
double vald = 0;
if (sscanf(i->second.c_str(), "%lf", &vald) != 1)
long vald = 0;
if (!plib::pstod_ne(i->second, vald))
log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second);
if (vald - std::floor(vald) != 0.0)
log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, i->second);
return static_cast<int>(vald);
}
else

View File

@ -291,7 +291,8 @@ namespace netlist
plib::plog_base<netlist_t, NL_DEBUG> &log();
const plib::plog_base<netlist_t, NL_DEBUG> &log() const;
std::vector<std::pair<pstring, factory::element_t *>> m_device_factory;
//std::vector<std::pair<pstring, factory::element_t *>> m_device_factory;
std::unordered_map<pstring, factory::element_t *> m_device_factory;
std::unordered_map<pstring, pstring> m_alias;
std::unordered_map<pstring, pstring> m_param_values;

View File

@ -375,10 +375,7 @@ double ppreprocessor::expr(const std::vector<pstring> &sexpr, std::size_t &start
ppreprocessor::define_t *ppreprocessor::get_define(const pstring &name)
{
auto idx = m_defines.find(name);
if (idx != m_defines.end())
return &idx->second;
else
return nullptr;
return (idx != m_defines.end()) ? &idx->second : nullptr;
}
pstring ppreprocessor::replace_macros(const pstring &line)
@ -388,10 +385,7 @@ pstring ppreprocessor::replace_macros(const pstring &line)
for (auto & elem : elems)
{
define_t *def = get_define(elem);
if (def != nullptr)
ret += def->m_replace;
else
ret += elem;
ret += (def != nullptr) ? def->m_replace : elem;
}
return ret;
}
@ -409,11 +403,8 @@ static pstring catremainder(const std::vector<pstring> &elems, std::size_t start
pstring ppreprocessor::process_line(const pstring &line)
{
//pstring lt = plib::trim(plib::replace_all(line, pstring("\t"), pstring(" ")));
pstring a = plib::replace_all(line, pstring("\t"), pstring(" "));
pstring lt = plib::trim(a);
pstring lt = plib::trim(plib::replace_all(line, pstring("\t"), pstring(" ")));
pstring ret;
m_lineno++;
// FIXME ... revise and extend macro handling
if (plib::startsWith(lt, "#"))
{
@ -477,9 +468,7 @@ pstring ppreprocessor::process_line(const pstring &line)
{
lt = replace_macros(lt);
if (m_ifflag == 0)
{
ret += lt;
}
}
return ret;
}
@ -490,6 +479,7 @@ void ppreprocessor::process(putf8_reader &istrm, putf8_writer &ostrm)
pstring line;
while (istrm.readline(line))
{
m_lineno++;
line = process_line(line);
ostrm.writeline(line);
}

View File

@ -147,6 +147,7 @@ public:
void init()
{
load_base_libraries();
}
void read_netlist(const pstring &filename, const pstring &name,