summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2019-02-06 10:24:34 +0100
committer couriersud <couriersud@gmx.org>2019-02-07 21:54:11 +0100
commit3b899b86e67e3a5cc093d2dd9c0dcaeed197c806 (patch)
tree5efe135d75b1fd837549719bfa6572802870be1b
parentc8d0db0c83d4b72e86f6255b95ff45ccc475d85d (diff)
netlist: Refactoring after adding clang-tidy support to netlist makefile
- convert macros to c++ code. - order of device creation should not depend on std lib. - some state saving cleanup. - added support for clang-tidy to makefile. - modifications triggered by clang-tidy-9.
-rw-r--r--src/devices/machine/netlist.cpp17
-rw-r--r--src/lib/netlist/analog/nld_bjt.cpp8
-rw-r--r--src/lib/netlist/analog/nld_opamps.cpp4
-rw-r--r--src/lib/netlist/analog/nld_switches.cpp6
-rw-r--r--src/lib/netlist/analog/nlid_fourterm.cpp26
-rw-r--r--src/lib/netlist/analog/nlid_fourterm.h37
-rw-r--r--src/lib/netlist/analog/nlid_twoterm.cpp10
-rw-r--r--src/lib/netlist/analog/nlid_twoterm.h21
-rw-r--r--src/lib/netlist/build/makefile53
-rw-r--r--src/lib/netlist/devices/net_lib.h30
-rw-r--r--src/lib/netlist/devices/nld_4066.cpp14
-rw-r--r--src/lib/netlist/devices/nld_4316.cpp9
-rw-r--r--src/lib/netlist/devices/nld_74165.cpp1
-rw-r--r--src/lib/netlist/devices/nld_7448.cpp2
-rw-r--r--src/lib/netlist/devices/nld_7483.cpp2
-rw-r--r--src/lib/netlist/devices/nld_74ls629.cpp2
-rw-r--r--src/lib/netlist/devices/nld_log.cpp2
-rw-r--r--src/lib/netlist/devices/nld_mm5837.cpp6
-rw-r--r--src/lib/netlist/devices/nld_r2r_dac.cpp4
-rw-r--r--src/lib/netlist/devices/nld_schmitt.cpp10
-rw-r--r--src/lib/netlist/devices/nlid_cmos.h2
-rw-r--r--src/lib/netlist/devices/nlid_proxy.cpp20
-rw-r--r--src/lib/netlist/devices/nlid_proxy.h12
-rw-r--r--src/lib/netlist/devices/nlid_system.h17
-rw-r--r--src/lib/netlist/devices/nlid_truthtable.cpp9
-rw-r--r--src/lib/netlist/devices/nlid_truthtable.h8
-rw-r--r--src/lib/netlist/macro/nlm_cd4xxx.cpp2
-rw-r--r--src/lib/netlist/netlist_types.h13
-rw-r--r--src/lib/netlist/nl_base.cpp153
-rw-r--r--src/lib/netlist/nl_base.h187
-rw-r--r--src/lib/netlist/nl_config.h13
-rw-r--r--src/lib/netlist/nl_factory.cpp11
-rw-r--r--src/lib/netlist/nl_factory.h20
-rw-r--r--src/lib/netlist/nl_lists.h12
-rw-r--r--src/lib/netlist/nl_parser.cpp8
-rw-r--r--src/lib/netlist/nl_parser.h8
-rw-r--r--src/lib/netlist/nl_setup.cpp91
-rw-r--r--src/lib/netlist/nl_setup.h39
-rw-r--r--src/lib/netlist/nl_time.h48
-rw-r--r--src/lib/netlist/plib/gmres.h8
-rw-r--r--src/lib/netlist/plib/mat_cr.h18
-rw-r--r--src/lib/netlist/plib/palloc.cpp8
-rw-r--r--src/lib/netlist/plib/palloc.h4
-rw-r--r--src/lib/netlist/plib/parray.h6
-rw-r--r--src/lib/netlist/plib/pchrono.cpp4
-rw-r--r--src/lib/netlist/plib/pchrono.h17
-rw-r--r--src/lib/netlist/plib/pconfig.h9
-rw-r--r--src/lib/netlist/plib/pdynlib.cpp4
-rw-r--r--src/lib/netlist/plib/pdynlib.h2
-rw-r--r--src/lib/netlist/plib/pexception.cpp28
-rw-r--r--src/lib/netlist/plib/pexception.h26
-rw-r--r--src/lib/netlist/plib/pfmtlog.cpp11
-rw-r--r--src/lib/netlist/plib/pfmtlog.h34
-rw-r--r--src/lib/netlist/plib/pfunction.cpp13
-rw-r--r--src/lib/netlist/plib/pfunction.h4
-rw-r--r--src/lib/netlist/plib/plists.h10
-rw-r--r--src/lib/netlist/plib/pmain.cpp5
-rw-r--r--src/lib/netlist/plib/pmain.h8
-rw-r--r--src/lib/netlist/plib/pomp.h6
-rw-r--r--src/lib/netlist/plib/poptions.cpp24
-rw-r--r--src/lib/netlist/plib/poptions.h19
-rw-r--r--src/lib/netlist/plib/pparser.cpp45
-rw-r--r--src/lib/netlist/plib/pparser.h39
-rw-r--r--src/lib/netlist/plib/ppmf.h14
-rw-r--r--src/lib/netlist/plib/pstate.cpp18
-rw-r--r--src/lib/netlist/plib/pstate.h43
-rw-r--r--src/lib/netlist/plib/pstream.cpp37
-rw-r--r--src/lib/netlist/plib/pstream.h119
-rw-r--r--src/lib/netlist/plib/pstring.cpp2
-rw-r--r--src/lib/netlist/plib/pstring.h81
-rw-r--r--src/lib/netlist/plib/ptypes.h30
-rw-r--r--src/lib/netlist/plib/putil.cpp16
-rw-r--r--src/lib/netlist/plib/putil.h28
-rw-r--r--src/lib/netlist/plib/vector_ops.h4
-rw-r--r--src/lib/netlist/prg/nltool.cpp32
-rw-r--r--src/lib/netlist/prg/nlwav.cpp24
-rw-r--r--src/lib/netlist/solver/nld_matrix_solver.cpp59
-rw-r--r--src/lib/netlist/solver/nld_matrix_solver.h28
-rw-r--r--src/lib/netlist/solver/nld_ms_direct.h32
-rw-r--r--src/lib/netlist/solver/nld_ms_direct1.h2
-rw-r--r--src/lib/netlist/solver/nld_ms_direct2.h2
-rw-r--r--src/lib/netlist/solver/nld_ms_gcr.h20
-rw-r--r--src/lib/netlist/solver/nld_ms_gmres.h14
-rw-r--r--src/lib/netlist/solver/nld_ms_sm.h30
-rw-r--r--src/lib/netlist/solver/nld_ms_sor.h26
-rw-r--r--src/lib/netlist/solver/nld_ms_sor_mat.h12
-rw-r--r--src/lib/netlist/solver/nld_ms_w.h32
-rw-r--r--src/lib/netlist/solver/nld_solver.cpp26
-rw-r--r--src/lib/netlist/solver/nld_solver.h10
-rw-r--r--src/lib/netlist/tools/nl_convert.cpp8
-rw-r--r--src/lib/netlist/tools/nl_convert.h20
91 files changed, 966 insertions, 1092 deletions
diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp
index fc76132a731..957d4575672 100644
--- a/src/devices/machine/netlist.cpp
+++ b/src/devices/machine/netlist.cpp
@@ -581,11 +581,12 @@ void netlist_mame_analog_output_device::custom_netlist_additions(netlist::setup_
{
const pstring pin(m_in);
pstring dname = pstring("OUT_") + pin;
+ pstring dfqn = setup.build_fqn(dname);
m_delegate.bind_relative_to(owner()->machine().root_device());
- plib::owned_ptr<netlist::device_t> dev = plib::owned_ptr<netlist::device_t>::Create<NETLIB_NAME(analog_callback)>(setup.netlist(), setup.build_fqn(dname));
+ plib::owned_ptr<netlist::device_t> dev = plib::owned_ptr<netlist::device_t>::Create<NETLIB_NAME(analog_callback)>(setup.netlist(), dfqn);
static_cast<NETLIB_NAME(analog_callback) *>(dev.get())->register_callback(std::move(m_delegate));
- setup.netlist().add_dev(std::move(dev));
+ setup.netlist().add_dev(dfqn, std::move(dev));
setup.register_link(dname + ".IN", pin);
}
@@ -616,11 +617,13 @@ void netlist_mame_logic_output_device::custom_netlist_additions(netlist::setup_t
{
pstring pin(m_in);
pstring dname = "OUT_" + pin;
+ pstring dfqn = setup.build_fqn(dname);
+
m_delegate.bind_relative_to(owner()->machine().root_device());
- plib::owned_ptr<netlist::device_t> dev = plib::owned_ptr<netlist::device_t>::Create<NETLIB_NAME(logic_callback)>(setup.netlist(), setup.build_fqn(dname));
+ plib::owned_ptr<netlist::device_t> dev = plib::owned_ptr<netlist::device_t>::Create<NETLIB_NAME(logic_callback)>(setup.netlist(), dfqn);
static_cast<NETLIB_NAME(logic_callback) *>(dev.get())->register_callback(std::move(m_delegate));
- setup.netlist().add_dev(std::move(dev));
+ setup.netlist().add_dev(dfqn, std::move(dev));
setup.register_link(dname + ".IN", pin);
}
@@ -882,9 +885,9 @@ void netlist_mame_device::device_start()
setup().prepare_to_run();
- netlist().nlstate().save(*this, m_rem, "m_rem");
- netlist().nlstate().save(*this, m_div, "m_div");
- netlist().nlstate().save(*this, m_old, "m_old");
+ netlist().nlstate().save(*this, m_rem, this->name(), "m_rem");
+ netlist().nlstate().save(*this, m_div, this->name(), "m_div");
+ netlist().nlstate().save(*this, m_old, this->name(), "m_old");
save_state();
diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp
index bd2e55e145f..7f8e57a8511 100644
--- a/src/lib/netlist/analog/nld_bjt.cpp
+++ b/src/lib/netlist/analog/nld_bjt.cpp
@@ -6,8 +6,8 @@
*/
#include "../solver/nld_solver.h"
-#include "nlid_twoterm.h"
#include "../nl_setup.h"
+#include "nlid_twoterm.h"
#include <cmath>
@@ -248,10 +248,6 @@ public:
register_subalias("B", m_D_EB.m_N); // Anode
register_subalias("C", m_D_CB.m_P); // Cathode
- //register_term("_B1", m_D_CB.m_N); // Anode
-
- //register_term("_E1", m_D_EC.m_P);
- //register_term("_C1", m_D_EC.m_N);
connect(m_D_EB.m_P, m_D_EC.m_P);
connect(m_D_EB.m_N, m_D_CB.m_N);
@@ -432,6 +428,6 @@ NETLIB_UPDATE_PARAM(QBJT_EB)
namespace devices {
NETLIB_DEVICE_IMPL_NS(analog, QBJT_EB, "QBJT_EB", "MODEL")
NETLIB_DEVICE_IMPL_NS(analog, QBJT_switch, "QBJT_SW", "MODEL")
- }
+ } // namespace devices
} // namespace netlist
diff --git a/src/lib/netlist/analog/nld_opamps.cpp b/src/lib/netlist/analog/nld_opamps.cpp
index b65ff0a9edd..53ba7b3897d 100644
--- a/src/lib/netlist/analog/nld_opamps.cpp
+++ b/src/lib/netlist/analog/nld_opamps.cpp
@@ -8,8 +8,8 @@
#include "nld_opamps.h"
#include "../nl_base.h"
#include "../nl_errstr.h"
-#include "nlid_twoterm.h"
#include "nlid_fourterm.h"
+#include "nlid_twoterm.h"
#include <cmath>
@@ -240,5 +240,5 @@ namespace netlist
namespace devices {
NETLIB_DEVICE_IMPL_NS(analog, opamp, "OPAMP", "MODEL")
- }
+ } // namespace devices
} // namespace netlist
diff --git a/src/lib/netlist/analog/nld_switches.cpp b/src/lib/netlist/analog/nld_switches.cpp
index 7f650737de8..0e62fe13952 100644
--- a/src/lib/netlist/analog/nld_switches.cpp
+++ b/src/lib/netlist/analog/nld_switches.cpp
@@ -27,7 +27,7 @@ namespace netlist
{
NETLIB_CONSTRUCTOR(switch1)
, m_R(*this, "R")
- , m_POS(*this, "POS", 0)
+ , m_POS(*this, "POS", false)
{
register_subalias("1", m_R.m_P);
register_subalias("2", m_R.m_N);
@@ -75,7 +75,7 @@ namespace netlist
NETLIB_CONSTRUCTOR(switch2)
, m_R1(*this, "R1")
, m_R2(*this, "R2")
- , m_POS(*this, "POS", 0)
+ , m_POS(*this, "POS", false)
{
connect(m_R1.m_N, m_R2.m_N);
@@ -139,5 +139,5 @@ namespace netlist
namespace devices {
NETLIB_DEVICE_IMPL_NS(analog, switch1, "SWITCH", "")
NETLIB_DEVICE_IMPL_NS(analog, switch2, "SWITCH2", "")
- }
+ } // namespace devices
} // namespace netlist
diff --git a/src/lib/netlist/analog/nlid_fourterm.cpp b/src/lib/netlist/analog/nlid_fourterm.cpp
index 7cd9bd83561..f4451c55023 100644
--- a/src/lib/netlist/analog/nlid_fourterm.cpp
+++ b/src/lib/netlist/analog/nlid_fourterm.cpp
@@ -24,16 +24,16 @@ namespace netlist
NETLIB_RESET(VCCS)
{
const nl_double m_mult = m_G() * m_gfac; // 1.0 ==> 1V ==> 1A
- const nl_double GI = NL_FCONST(1.0) / m_RI();
+ const nl_double GI = plib::constants<nl_double>::one / m_RI();
m_IP.set(GI);
m_IN.set(GI);
- m_OP.set(m_mult, NL_FCONST(0.0));
- m_OP1.set(-m_mult, NL_FCONST(0.0));
+ m_OP.set(m_mult, plib::constants<nl_double>::zero);
+ m_OP1.set(-m_mult, plib::constants<nl_double>::zero);
- m_ON.set(-m_mult, NL_FCONST(0.0));
- m_ON1.set(m_mult, NL_FCONST(0.0));
+ m_ON.set(-m_mult, plib::constants<nl_double>::zero);
+ m_ON1.set(m_mult, plib::constants<nl_double>::zero);
}
NETLIB_UPDATE(VCCS)
@@ -79,11 +79,11 @@ NETLIB_UPDATE_TERMINALS(LVCCS)
const nl_double beta = m_mult * (1.0 - X*X);
const nl_double I = m_cur_limit() * X - beta * m_vi;
- m_OP.set(beta, NL_FCONST(0.0), I);
- m_OP1.set(-beta, NL_FCONST(0.0));
+ m_OP.set(beta, plib::constants<nl_double>::zero, I);
+ m_OP1.set(-beta, plib::constants<nl_double>::zero);
- m_ON.set(-beta, NL_FCONST(0.0), -I);
- m_ON1.set(beta, NL_FCONST(0.0));
+ m_ON.set(-beta, plib::constants<nl_double>::zero, -I);
+ m_ON1.set(beta, plib::constants<nl_double>::zero);
}
// ----------------------------------------------------------------------------------------
@@ -106,11 +106,11 @@ NETLIB_UPDATE_PARAM(CCCS)
NETLIB_RESET(VCVS)
{
- m_gfac = NL_FCONST(1.0) / m_RO();
+ m_gfac = plib::constants<nl_double>::one / m_RO();
NETLIB_NAME(VCCS)::reset();
- m_OP2.set(NL_FCONST(1.0) / m_RO());
- m_ON2.set(NL_FCONST(1.0) / m_RO());
+ m_OP2.set(plib::constants<nl_double>::one / m_RO());
+ m_ON2.set(plib::constants<nl_double>::one / m_RO());
}
} //namespace analog
@@ -120,5 +120,5 @@ NETLIB_RESET(VCVS)
NETLIB_DEVICE_IMPL_NS(analog, VCCS, "VCCS", "")
NETLIB_DEVICE_IMPL_NS(analog, CCCS, "CCCS", "")
NETLIB_DEVICE_IMPL_NS(analog, LVCCS, "LVCCS", "")
- }
+ } // namespace devices
} // namespace netlist
diff --git a/src/lib/netlist/analog/nlid_fourterm.h b/src/lib/netlist/analog/nlid_fourterm.h
index a0984221cae..800a9d1cfb8 100644
--- a/src/lib/netlist/analog/nlid_fourterm.h
+++ b/src/lib/netlist/analog/nlid_fourterm.h
@@ -9,6 +9,7 @@
#define NLID_FOURTERM_H_
#include "../nl_base.h"
+#include "../plib/putil.h"
namespace netlist {
namespace analog {
@@ -40,26 +41,17 @@ namespace netlist {
NETLIB_CONSTRUCTOR(VCCS)
, m_G(*this, "G", 1.0)
, m_RI(*this, "RI", 1e9)
- , m_OP(*this, "OP")
- , m_ON(*this, "ON")
- , m_IP(*this, "IP")
- , m_IN(*this, "IN")
- , m_OP1(*this, "_OP1")
- , m_ON1(*this, "_ON1")
+ , m_OP(*this, "OP", &m_IP)
+ , m_ON(*this, "ON", &m_IP)
+ , m_IP(*this, "IP", &m_IN) // <= this should be NULL and terminal be filtered out prior to solving...
+ , m_IN(*this, "IN", &m_IP) // <= this should be NULL and terminal be filtered out prior to solving...
+ , m_OP1(*this, "_OP1", &m_IN)
+ , m_ON1(*this, "_ON1", &m_IN)
, m_gfac(1.0)
{
- m_IP.m_otherterm = &m_IN; // <= this should be NULL and terminal be filtered out prior to solving...
- m_IN.m_otherterm = &m_IP; // <= this should be NULL and terminal be filtered out prior to solving...
-
- m_OP.m_otherterm = &m_IP;
- m_OP1.m_otherterm = &m_IN;
-
- m_ON.m_otherterm = &m_IP;
- m_ON1.m_otherterm = &m_IN;
-
connect(m_OP, m_OP1);
connect(m_ON, m_ON1);
- m_gfac = NL_FCONST(1.0);
+ m_gfac = plib::constants<nl_double>::one;
}
param_double_t m_G;
@@ -137,7 +129,7 @@ namespace netlist {
public:
NETLIB_CONSTRUCTOR_DERIVED(CCCS, VCCS)
{
- m_gfac = NL_FCONST(1.0) / m_RI();
+ m_gfac = plib::constants<nl_double>::one / m_RI();
}
protected:
@@ -180,12 +172,9 @@ namespace netlist {
public:
NETLIB_CONSTRUCTOR_DERIVED(VCVS, VCCS)
, m_RO(*this, "RO", 1.0)
- , m_OP2(*this, "_OP2")
- , m_ON2(*this, "_ON2")
+ , m_OP2(*this, "_OP2", &m_ON2)
+ , m_ON2(*this, "_ON2", &m_OP2)
{
- m_OP2.m_otherterm = &m_ON2;
- m_ON2.m_otherterm = &m_OP2;
-
connect(m_OP2, m_OP1);
connect(m_ON2, m_ON1);
}
@@ -202,7 +191,7 @@ namespace netlist {
};
- }
-}
+ } // namespace analog
+} // namespace netlist
#endif /* NLD_FOURTERM_H_ */
diff --git a/src/lib/netlist/analog/nlid_twoterm.cpp b/src/lib/netlist/analog/nlid_twoterm.cpp
index 51c17b92267..5b4bf064093 100644
--- a/src/lib/netlist/analog/nlid_twoterm.cpp
+++ b/src/lib/netlist/analog/nlid_twoterm.cpp
@@ -7,8 +7,8 @@
#include "../solver/nld_solver.h"
-#include "nlid_twoterm.h"
#include "../nl_factory.h"
+#include "nlid_twoterm.h"
#include <cmath>
@@ -70,7 +70,7 @@ void generic_diode::update_diode(const nl_double nVd)
}
else
{
- const double a = std::max((nVd - m_Vd) * m_VtInv, NL_FCONST(-0.99));
+ const double a = std::max((nVd - m_Vd) * m_VtInv, plib::constants<nl_double>()(-0.99));
m_Vd = m_Vd + std::log1p(a) * m_Vt;
//const double IseVDVt = m_Is * std::exp(m_Vd * m_VtInv);
const double IseVDVt = std::exp(m_logIs + m_Vd * m_VtInv);
@@ -145,7 +145,7 @@ NETLIB_RESET(POT)
v = (std::exp(v) - 1.0) / (std::exp(1.0) - 1.0);
m_R1.set_R(std::max(m_R() * v, exec().gmin()));
- m_R2.set_R(std::max(m_R() * (NL_FCONST(1.0) - v), exec().gmin()));
+ m_R2.set_R(std::max(m_R() * (plib::constants<nl_double>::one - v), exec().gmin()));
}
NETLIB_UPDATE_PARAM(POT)
@@ -158,7 +158,7 @@ NETLIB_UPDATE_PARAM(POT)
v = (std::exp(v) - 1.0) / (std::exp(1.0) - 1.0);
m_R1.set_R(std::max(m_R() * v, exec().gmin()));
- m_R2.set_R(std::max(m_R() * (NL_FCONST(1.0) - v), exec().gmin()));
+ m_R2.set_R(std::max(m_R() * (plib::constants<nl_double>::one - v), exec().gmin()));
}
@@ -288,6 +288,6 @@ NETLIB_UPDATE_TERMINALS(D)
NETLIB_DEVICE_IMPL_NS(analog, D, "DIODE", "MODEL")
NETLIB_DEVICE_IMPL_NS(analog, VS, "VS", "V")
NETLIB_DEVICE_IMPL_NS(analog, CS, "CS", "I")
- }
+ } // namespace devices
} // namespace netlist
diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h
index 5571e17867d..aa165d58a4e 100644
--- a/src/lib/netlist/analog/nlid_twoterm.h
+++ b/src/lib/netlist/analog/nlid_twoterm.h
@@ -33,9 +33,9 @@
#ifndef NLID_TWOTERM_H_
#define NLID_TWOTERM_H_
+#include "../plib/pfunction.h"
#include "netlist/nl_base.h"
#include "netlist/nl_setup.h"
-#include "../plib/pfunction.h"
// -----------------------------------------------------------------------------
// Implementation
@@ -52,12 +52,13 @@ namespace netlist
template <class C>
inline core_device_t &bselect(bool b, C &d1, core_device_t &d2)
{
- core_device_t *h = dynamic_cast<core_device_t *>(&d1);
+ auto *h = dynamic_cast<core_device_t *>(&d1);
return b ? *h : d2;
}
template<>
inline core_device_t &bselect(bool b, netlist_base_t &d1, core_device_t &d2)
{
+ plib::unused_var(d1);
if (b)
throw nl_exception("bselect with netlist and b==true");
return d2;
@@ -66,11 +67,9 @@ namespace netlist
NETLIB_OBJECT(twoterm)
{
NETLIB_CONSTRUCTOR_EX(twoterm, bool terminals_owned = false)
- , m_P(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "1")
- , m_N(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "2")
+ , m_P(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "1", &m_N)
+ , m_N(bselect(terminals_owned, owner, *this), (terminals_owned ? name + "." : "") + "2", &m_P)
{
- m_P.m_otherterm = &m_N;
- m_N.m_otherterm = &m_P;
}
terminal_t m_P;
@@ -124,7 +123,7 @@ NETLIB_OBJECT_DERIVED(R_base, twoterm)
public:
void set_R(const nl_double R)
{
- const nl_double G = NL_FCONST(1.0) / R;
+ const nl_double G = plib::constants<nl_double>::one / R;
set_mat( G, -G, 0.0,
-G, G, 0.0);
}
@@ -166,7 +165,7 @@ NETLIB_OBJECT(POT)
, m_R2(*this, "_R2")
, m_R(*this, "R", 10000)
, m_Dial(*this, "DIAL", 0.5)
- , m_DialIsLog(*this, "DIALLOG", 0)
+ , m_DialIsLog(*this, "DIALLOG", false)
{
register_subalias("1", m_R1.m_P);
register_subalias("2", m_R1.m_N);
@@ -195,8 +194,8 @@ NETLIB_OBJECT(POT2)
, m_R1(*this, "_R1")
, m_R(*this, "R", 10000)
, m_Dial(*this, "DIAL", 0.5)
- , m_DialIsLog(*this, "DIALLOG", 0)
- , m_Reverse(*this, "REVERSE", 0)
+ , m_DialIsLog(*this, "DIALLOG", false)
+ , m_Reverse(*this, "REVERSE", false)
{
register_subalias("1", m_R1.m_P);
register_subalias("2", m_R1.m_N);
@@ -489,7 +488,7 @@ private:
};
- } //namespace devices
+ } // namespace analog
} // namespace netlist
#endif /* NLD_TWOTERM_H_ */
diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile
index 33618e346b5..8996ba242ec 100644
--- a/src/lib/netlist/build/makefile
+++ b/src/lib/netlist/build/makefile
@@ -12,6 +12,28 @@
SRC = ..
VSBUILD = $(SRC)/buildVS
DOC = $(SRC)/documentation
+TIDY_DB = ../compile_commands.json
+
+TIDY_FLAGSX = -checks=*,-google*,-hicpp*,-readability*,-fuchsia*,-llvm-header-guard,
+TIDY_FLAGSX += -modernize-use-using,-cppcoreguidelines-pro-type-reinterpret-cast,
+TIDY_FLAGSX += -cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-owning-memory,
+TIDY_FLAGSX += -modernize-use-default-member-init,-cert-*,-cppcoreguidelines-pro-bounds-constant-array-index,
+TIDY_FLAGSX += -modernize-pass-by-value,-misc-macro-parentheses,-cppcoreguidelines-pro-type-static-cast-downcast,
+TIDY_FLAGSX += -cppcoreguidelines-special-member-functions,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
+TIDY_FLAGSX += -performance-unnecessary-value-param,-android-*,-cppcoreguidelines-avoid-magic-numbers,
+TIDY_FLAGSX += -cppcoreguidelines-macro-usage,-misc-non-private-member-variables-in-classes,
+TIDY_FLAGSX += -cppcoreguidelines-non-private-member-variables-in-classes,
+TIDY_FLAGSX += -cppcoreguidelines-avoid-c-arrays,-modernize-avoid-c-arrays,
+TIDY_FLAGSX += -performance-unnecessary-copy-initialization,
+TIDY_FLAGSX += -bugprone-macro-parentheses
+
+space :=
+space +=
+TIDY_FLAGS = $(subst $(space),,$(TIDY_FLAGSX))
+
+#TIDY_FLAGS = -checks=llvm-include-order -fix
+#TIDY_FLAGS = -checks=llvm-namespace-comment -fix
+#TIDY_FLAGS = -checks=modernize-use-override -fix
ifeq ($(subst Windows_NT,windows,$(OS)),windows)
OBJ = obj/mingw
@@ -32,6 +54,7 @@ LD = @g++
MD = @mkdir
RM = @rm
DOXYGEN = @doxygen
+CLANG_TIDY = clang-tidy-9
TARGETS = nltool nlwav
@@ -154,6 +177,8 @@ DOCS = \
$(DOC)/test1-50r.svg \
ALL_OBJS = $(OBJS) $(PMAIN) $(NLOBJ)/prg/nltool.o $(NLOBJ)/prg/nlwav.o
+
+ALL_TIDY_FILES = $(ALL_OBJS:.o=.json)
SOURCES = $(patsubst $(OBJ)%, $(SRC)%, $(ALL_OBJS:.o=.cpp))
ALLFILES = $(SOURCES) $(VSBUILDS) $(DOCS)
@@ -207,7 +232,7 @@ native:
$(MAKE) CEXTRAFLAGS="-march=native -Wall -Wpedantic -Wsign-compare -Wextra -Wno-unused-parameter"
clang:
- $(MAKE) CC=clang++ LD=clang++ CEXTRAFLAGS="-march=native -Wno-unused-parameter -Weverything -Werror -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wweak-template-vtables -Wno-exit-time-destructors"
+ $(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Wno-unused-parameter -Weverything -Werror -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wweak-template-vtables -Wno-exit-time-destructors"
clang-5:
$(MAKE) CC=clang++-5.0 LD=clang++-5.0 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-inconsistent-missing-destructor-override -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-weak-template-vtables -Wno-exit-time-destructors"
@@ -216,6 +241,8 @@ nvcc:
$(MAKE) CC=/usr/local/cuda-9.0/bin/nvcc LD=/usr/local/cuda-9.2/bin/nvcc \
CEXTRAFLAGS="-x cu -DNVCCBUILD=1 --expt-extended-lambda --expt-relaxed-constexpr --default-stream per-thread --restrict"
+tidy_db: compile_commands_prefix $(ALL_TIDY_FILES) compile_commands_postfix
+
#
# -Wno-c++11-narrowing : seems a bit broken
# Mostly done: -Wno-weak-vtables -Wno-cast-align
@@ -257,6 +284,18 @@ ifeq ($(filter $(MAKECMDGOALS),$(MAKEFILE_TARGETS_WITHOUT_INCLUDE)),)
endif
#-------------------------------------------------
+# clang tidy
+#-------------------------------------------------
+tidy: tidy_db
+ @echo running tidy
+ @for i in $(SOURCES); do \
+ $(CLANG_TIDY) $$i $(TIDY_FLAGS) -header-filter=.*; \
+ done
+
+tidy_db: compile_commands_prefix $(ALL_TIDY_FILES) compile_commands_postfix
+
+
+#-------------------------------------------------
# generic rules
#-------------------------------------------------
@@ -277,3 +316,15 @@ $(OBJ)/%.a:
$(RM) $@
$(AR) $(ARFLAGS) $@ $^
+$(OBJ)/%.json: $(SRC)/%.cpp
+ @echo Building compile database entry for $< ...
+ @echo { \"directory\": \".\", >> $(TIDY_DB)
+ @echo \"command\": \"$(CC) $(CDEFS) $(CFLAGS) -c $< -o dummy.o\", >> $(TIDY_DB)
+ @echo \"file\": \"$(CURDIR)/$<\" } >> $(TIDY_DB)
+ @echo "," >> $(TIDY_DB)
+
+compile_commands_prefix:
+ @echo "[" > $(TIDY_DB)
+
+compile_commands_postfix:
+ @echo "]" >> $(TIDY_DB)
diff --git a/src/lib/netlist/devices/net_lib.h b/src/lib/netlist/devices/net_lib.h
index 4809f330c6b..6cd2b6349f1 100644
--- a/src/lib/netlist/devices/net_lib.h
+++ b/src/lib/netlist/devices/net_lib.h
@@ -35,19 +35,8 @@
#include "nld_2102A.h"
#include "nld_2716.h"
-#include "nld_tms4800.h"
#include "nld_4020.h"
#include "nld_4066.h"
-#include "nld_7448.h"
-#include "nld_7450.h"
-#include "nld_7473.h"
-#include "nld_7474.h"
-#include "nld_7475.h"
-#include "nld_7483.h"
-#include "nld_7485.h"
-#include "nld_7490.h"
-#include "nld_7493.h"
-#include "nld_7497.h"
#include "nld_74107.h"
#include "nld_74123.h"
#include "nld_74153.h"
@@ -61,21 +50,32 @@
#include "nld_74193.h"
#include "nld_74194.h"
#include "nld_74365.h"
+#include "nld_7448.h"
+#include "nld_7450.h"
+#include "nld_7473.h"
+#include "nld_7474.h"
+#include "nld_7475.h"
+#include "nld_7483.h"
+#include "nld_7485.h"
+#include "nld_7490.h"
+#include "nld_7493.h"
+#include "nld_7497.h"
#include "nld_74ls629.h"
-#include "nld_82S16.h"
#include "nld_82S115.h"
#include "nld_82S123.h"
#include "nld_82S126.h"
+#include "nld_82S16.h"
#include "nld_9310.h"
#include "nld_9316.h"
#include "nld_9322.h"
+#include "nld_tms4800.h"
#include "nld_am2847.h"
#include "nld_dm9314.h"
#include "nld_dm9334.h"
-#include "nld_ne555.h"
#include "nld_mm5837.h"
+#include "nld_ne555.h"
#include "nld_r2r_dac.h"
@@ -86,15 +86,15 @@
#include "nld_log.h"
#include "../macro/nlm_cd4xxx.h"
-#include "../macro/nlm_ttl74xx.h"
#include "../macro/nlm_opamp.h"
#include "../macro/nlm_other.h"
+#include "../macro/nlm_ttl74xx.h"
#include "../analog/nld_bjt.h"
#include "../analog/nld_fourterm.h"
+#include "../analog/nld_opamps.h"
#include "../analog/nld_switches.h"
#include "../analog/nld_twoterm.h"
-#include "../analog/nld_opamps.h"
#include "nld_legacy.h"
#endif
diff --git a/src/lib/netlist/devices/nld_4066.cpp b/src/lib/netlist/devices/nld_4066.cpp
index c4598f4fd1a..81a9a07ef0b 100644
--- a/src/lib/netlist/devices/nld_4066.cpp
+++ b/src/lib/netlist/devices/nld_4066.cpp
@@ -7,9 +7,9 @@
#include "nld_4066.h"
-#include "nlid_cmos.h"
#include "netlist/analog/nlid_twoterm.h"
#include "netlist/solver/nld_solver.h"
+#include "nlid_cmos.h"
namespace netlist
{
@@ -41,28 +41,28 @@ namespace netlist
{
// Start in off condition
// FIXME: is ROFF correct?
- m_R.set_R(NL_FCONST(1.0) / exec().gmin());
+ m_R.set_R(plib::constants<nl_double>::one / exec().gmin());
}
NETLIB_UPDATE(CD4066_GATE)
{
nl_double sup = (m_supply.vdd() - m_supply.vss());
- nl_double low = NL_FCONST(0.45) * sup;
- nl_double high = NL_FCONST(0.55) * sup;
+ nl_double low = plib::constants<nl_double>()(0.45) * sup;
+ nl_double high = plib::constants<nl_double>()(0.55) * sup;
nl_double in = m_control() - m_supply.vss();
- nl_double rON = m_base_r() * NL_FCONST(5.0) / sup;
+ nl_double rON = m_base_r() * plib::constants<nl_double>()(5.0) / sup;
nl_double R = -1.0;
if (in < low)
{
- R = NL_FCONST(1.0) / exec().gmin();
+ R = plib::constants<nl_double>::one / exec().gmin();
}
else if (in > high)
{
R = rON;
}
- if (R > NL_FCONST(0.0))
+ if (R > plib::constants<nl_double>::zero)
{
m_R.update();
m_R.set_R(R);
diff --git a/src/lib/netlist/devices/nld_4316.cpp b/src/lib/netlist/devices/nld_4316.cpp
index 6774e1e1408..c34a0602147 100644
--- a/src/lib/netlist/devices/nld_4316.cpp
+++ b/src/lib/netlist/devices/nld_4316.cpp
@@ -6,9 +6,9 @@
*/
#include "nld_4316.h"
-#include "nlid_cmos.h"
#include "netlist/analog/nlid_twoterm.h"
#include "netlist/solver/nld_solver.h"
+#include "nlid_cmos.h"
namespace netlist { namespace devices {
@@ -38,7 +38,7 @@ namespace netlist { namespace devices {
NETLIB_RESET(CD4316_GATE)
{
- m_R.set_R(NL_FCONST(1.0) / exec().gmin());
+ m_R.set_R(plib::constants<nl_double>::one / exec().gmin());
}
NETLIB_UPDATE(CD4316_GATE)
@@ -47,10 +47,11 @@ namespace netlist { namespace devices {
if (m_S() && !m_E())
m_R.set_R(m_base_r());
else
- m_R.set_R(NL_FCONST(1.0) / exec().gmin());
+ m_R.set_R(plib::constants<nl_double>::one / exec().gmin());
m_R.solve_later(NLTIME_FROM_NS(1));
}
NETLIB_DEVICE_IMPL(CD4316_GATE, "CD4316_GATE", "")
-} } // namesapce netlist::devices
+} // namespace devices
+ } // namespace netlist
diff --git a/src/lib/netlist/devices/nld_74165.cpp b/src/lib/netlist/devices/nld_74165.cpp
index 6ad95da091f..a8aef44b623 100644
--- a/src/lib/netlist/devices/nld_74165.cpp
+++ b/src/lib/netlist/devices/nld_74165.cpp
@@ -86,6 +86,7 @@ namespace netlist
}
else if (!m_CLK() || m_CLKINH())
{
+ // FIXME: qh is overwritten below?
qh = old_qh;
}
else if (!m_last_CLK)
diff --git a/src/lib/netlist/devices/nld_7448.cpp b/src/lib/netlist/devices/nld_7448.cpp
index 239d6b50921..f14714de17c 100644
--- a/src/lib/netlist/devices/nld_7448.cpp
+++ b/src/lib/netlist/devices/nld_7448.cpp
@@ -133,7 +133,7 @@ namespace netlist
#else
-#define BITS7(b6,b5,b4,b3,b2,b1,b0) (b6<<6) | (b5<<5) | (b4<<4) | (b3<<3) | (b2<<2) | (b1<<1) | (b0<<0)
+#define BITS7(b6,b5,b4,b3,b2,b1,b0) ((b6)<<6) | ((b5)<<5) | ((b4)<<4) | ((b3)<<3) | ((b2)<<2) | ((b1)<<1) | ((b0)<<0)
static constexpr uint8_t tab7448[16] =
{
diff --git a/src/lib/netlist/devices/nld_7483.cpp b/src/lib/netlist/devices/nld_7483.cpp
index 2fbdeb7e52b..285fbeee19e 100644
--- a/src/lib/netlist/devices/nld_7483.cpp
+++ b/src/lib/netlist/devices/nld_7483.cpp
@@ -107,7 +107,7 @@ namespace netlist
NETLIB_UPDATE(7483)
{
- uint8_t r = static_cast<uint8_t>(m_a + m_b + m_C0());
+ auto r = static_cast<uint8_t>(m_a + m_b + m_C0());
if (r != m_lastr)
{
diff --git a/src/lib/netlist/devices/nld_74ls629.cpp b/src/lib/netlist/devices/nld_74ls629.cpp
index bdebea3a45e..5383501043c 100644
--- a/src/lib/netlist/devices/nld_74ls629.cpp
+++ b/src/lib/netlist/devices/nld_74ls629.cpp
@@ -210,7 +210,7 @@ namespace netlist
freq += k9 * v_rng * v_freq_3;
freq += k10 * v_rng * v_freq_4;
- freq *= NL_FCONST(0.1e-6) / m_CAP();
+ freq *= plib::constants<nl_double>()(0.1e-6) / m_CAP();
// FIXME: we need a possibility to remove entries from queue ...
// or an exact model ...
diff --git a/src/lib/netlist/devices/nld_log.cpp b/src/lib/netlist/devices/nld_log.cpp
index 107cd3863c0..c99fcb5a9bc 100644
--- a/src/lib/netlist/devices/nld_log.cpp
+++ b/src/lib/netlist/devices/nld_log.cpp
@@ -6,8 +6,8 @@
*/
#include "../nl_base.h"
-#include "../plib/pstream.h"
#include "../plib/pfmtlog.h"
+#include "../plib/pstream.h"
#include "nld_log.h"
//#include "sound/wavwrite.h"
diff --git a/src/lib/netlist/devices/nld_mm5837.cpp b/src/lib/netlist/devices/nld_mm5837.cpp
index eb2840d31fa..93ba4683a0a 100644
--- a/src/lib/netlist/devices/nld_mm5837.cpp
+++ b/src/lib/netlist/devices/nld_mm5837.cpp
@@ -6,8 +6,8 @@
*/
#include "nld_mm5837.h"
-#include "../solver/nld_matrix_solver.h"
#include "../analog/nlid_twoterm.h"
+#include "../solver/nld_matrix_solver.h"
#define R_LOW (1000.0)
#define R_HIGH (1000.0)
@@ -69,7 +69,7 @@ namespace netlist
{
//m_V0.initial(0.0);
//m_RV.do_reset();
- m_RV.set(NL_FCONST(1.0) / R_LOW, 0.0, 0.0);
+ m_RV.set(plib::constants<nl_double>::one / R_LOW, 0.0, 0.0);
m_inc = netlist_time::from_double(1.0 / m_FREQ());
if (m_FREQ() < 24000 || m_FREQ() > 56000)
log().warning(MW_1_FREQUENCY_OUTSIDE_OF_SPECS_1, m_FREQ());
@@ -108,7 +108,7 @@ namespace netlist
// We only need to update the net first if this is a time stepping net
if (m_is_timestep)
m_RV.update();
- m_RV.set(NL_FCONST(1.0) / R, V, 0.0);
+ m_RV.set(plib::constants<nl_double>::one / R, V, plib::constants<nl_double>::zero);
m_RV.solve_later(NLTIME_FROM_NS(1));
}
diff --git a/src/lib/netlist/devices/nld_r2r_dac.cpp b/src/lib/netlist/devices/nld_r2r_dac.cpp
index a622ebe52ab..594ee185600 100644
--- a/src/lib/netlist/devices/nld_r2r_dac.cpp
+++ b/src/lib/netlist/devices/nld_r2r_dac.cpp
@@ -6,8 +6,8 @@
*/
#include "../nl_base.h"
-#include "../nl_factory.h"
#include "../analog/nlid_twoterm.h"
+#include "../nl_factory.h"
namespace netlist
{
@@ -50,6 +50,6 @@ namespace netlist
namespace devices {
NETLIB_DEVICE_IMPL_NS(analog, r2r_dac, "R2R_DAC", "VIN,R,N")
- }
+ } // namespace devices
} // namespace netlist
diff --git a/src/lib/netlist/devices/nld_schmitt.cpp b/src/lib/netlist/devices/nld_schmitt.cpp
index a21f50c0681..ed3783535a0 100644
--- a/src/lib/netlist/devices/nld_schmitt.cpp
+++ b/src/lib/netlist/devices/nld_schmitt.cpp
@@ -7,9 +7,9 @@
#include "nld_schmitt.h"
+#include "../analog/nlid_twoterm.h"
#include "../nl_base.h"
#include "../nl_errstr.h"
-#include "../analog/nlid_twoterm.h"
#include "../solver/nld_solver.h"
#include <cmath>
@@ -85,8 +85,8 @@ namespace netlist
m_RVI.reset();
m_RVO.reset();
m_is_timestep = m_RVO.m_P.net().solver()->has_timestep_devices();
- m_RVI.set(NL_FCONST(1.0) / m_model.m_RI, m_model.m_VI, 0.0);
- m_RVO.set(NL_FCONST(1.0) / m_model.m_ROL, m_model.m_VOL, 0.0);
+ m_RVI.set(plib::constants<nl_double>::one / m_model.m_RI, m_model.m_VI, 0.0);
+ m_RVO.set(plib::constants<nl_double>::one / m_model.m_ROL, m_model.m_VOL, 0.0);
}
NETLIB_UPDATEI()
@@ -98,7 +98,7 @@ namespace netlist
m_last_state = 0;
if (m_is_timestep)
m_RVO.update();
- m_RVO.set(NL_FCONST(1.0) / m_model.m_ROH, m_model.m_VOH, 0.0);
+ m_RVO.set(plib::constants<nl_double>::one / m_model.m_ROH, m_model.m_VOH, 0.0);
m_RVO.solve_later();
}
}
@@ -109,7 +109,7 @@ namespace netlist
m_last_state = 1;
if (m_is_timestep)
m_RVO.update();
- m_RVO.set(NL_FCONST(1.0) / m_model.m_ROL, m_model.m_VOL, 0.0);
+ m_RVO.set(plib::constants<nl_double>::one / m_model.m_ROL, m_model.m_VOL, 0.0);
m_RVO.solve_later();
}
}
diff --git a/src/lib/netlist/devices/nlid_cmos.h b/src/lib/netlist/devices/nlid_cmos.h
index f9999aebcc0..053cc9b5b5e 100644
--- a/src/lib/netlist/devices/nlid_cmos.h
+++ b/src/lib/netlist/devices/nlid_cmos.h
@@ -8,8 +8,8 @@
#ifndef NLID_CMOS_H_
#define NLID_CMOS_H_
-#include "../nl_setup.h"
#include "../nl_base.h"
+#include "../nl_setup.h"
namespace netlist
{
diff --git a/src/lib/netlist/devices/nlid_proxy.cpp b/src/lib/netlist/devices/nlid_proxy.cpp
index 741c864246d..44d3d3af9a5 100644
--- a/src/lib/netlist/devices/nlid_proxy.cpp
+++ b/src/lib/netlist/devices/nlid_proxy.cpp
@@ -29,10 +29,6 @@ namespace netlist
m_proxy_term = proxy_inout;
}
- nld_base_proxy::~nld_base_proxy()
- {
- }
-
// ----------------------------------------------------------------------------------------
// nld_a_to_d_proxy
// ----------------------------------------------------------------------------------------
@@ -44,18 +40,12 @@ namespace netlist
{
}
- nld_base_a_to_d_proxy::~nld_base_a_to_d_proxy() {}
-
nld_a_to_d_proxy::nld_a_to_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *in_proxied)
: nld_base_a_to_d_proxy(anetlist, name, in_proxied, &m_I)
, m_I(*this, "I")
{
}
- nld_a_to_d_proxy::~nld_a_to_d_proxy()
- {
- }
-
NETLIB_RESET(a_to_d_proxy)
{
}
@@ -88,10 +78,6 @@ namespace netlist
{
}
- nld_base_d_to_a_proxy::~nld_base_d_to_a_proxy()
- {
- }
-
nld_d_to_a_proxy::nld_d_to_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *out_proxied)
: nld_base_d_to_a_proxy(anetlist, name, out_proxied, m_RV.m_P)
, m_GNDHack(*this, "_Q")
@@ -139,13 +125,13 @@ namespace netlist
m_last_state = -1;
m_RV.reset();
m_is_timestep = m_RV.m_P.net().solver()->has_timestep_devices();
- m_RV.set(NL_FCONST(1.0) / logic_family()->R_low(),
+ m_RV.set(plib::constants<nl_double>::one / logic_family()->R_low(),
logic_family()->low_V(0.0, supply_V), 0.0);
}
NETLIB_UPDATE(d_to_a_proxy)
{
- const int state = static_cast<int>(m_I());
+ const auto state = static_cast<int>(m_I());
if (state != m_last_state)
{
// FIXME: Variable voltage
@@ -160,7 +146,7 @@ namespace netlist
{
m_RV.update();
}
- m_RV.set(NL_FCONST(1.0) / R, V, 0.0);
+ m_RV.set(plib::constants<nl_double>::one / R, V, 0.0);
m_RV.solve_later();
}
}
diff --git a/src/lib/netlist/devices/nlid_proxy.h b/src/lib/netlist/devices/nlid_proxy.h
index eb1f2b3fe87..034f7c3d9ba 100644
--- a/src/lib/netlist/devices/nlid_proxy.h
+++ b/src/lib/netlist/devices/nlid_proxy.h
@@ -11,8 +11,8 @@
#ifndef NLID_PROXY_H_
#define NLID_PROXY_H_
-#include "../nl_setup.h"
#include "../analog/nlid_twoterm.h"
+#include "../nl_setup.h"
namespace netlist
{
@@ -29,7 +29,7 @@ namespace netlist
nld_base_proxy(netlist_base_t &anetlist, const pstring &name,
logic_t *inout_proxied, detail::core_terminal_t *proxy_inout);
- virtual ~nld_base_proxy();
+ ~nld_base_proxy() override = default;
logic_t &term_proxied() const { return *m_term_proxied; }
detail::core_terminal_t &proxy_term() const { return *m_proxy_term; }
@@ -49,7 +49,7 @@ namespace netlist
{
public:
- virtual ~nld_base_a_to_d_proxy();
+ ~nld_base_a_to_d_proxy() override = default;
virtual logic_output_t &out() { return m_Q; }
@@ -69,7 +69,7 @@ namespace netlist
public:
nld_a_to_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *in_proxied);
- virtual ~nld_a_to_d_proxy() override;
+ ~nld_a_to_d_proxy() override = default;
analog_input_t m_I;
@@ -88,7 +88,7 @@ namespace netlist
NETLIB_OBJECT_DERIVED(base_d_to_a_proxy, base_proxy)
{
public:
- virtual ~nld_base_d_to_a_proxy();
+ ~nld_base_d_to_a_proxy() override = default;
virtual logic_input_t &in() { return m_I; }
@@ -105,7 +105,7 @@ namespace netlist
{
public:
nld_d_to_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *out_proxied);
- virtual ~nld_d_to_a_proxy() override {}
+ ~nld_d_to_a_proxy() override = default;
protected:
diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h
index 7271084bbc1..f98a74f043f 100644
--- a/src/lib/netlist/devices/nlid_system.h
+++ b/src/lib/netlist/devices/nlid_system.h
@@ -11,9 +11,9 @@
#ifndef NLID_SYSTEM_H_
#define NLID_SYSTEM_H_
+#include "../analog/nlid_twoterm.h"
#include "../nl_base.h"
#include "../nl_setup.h"
-#include "../analog/nlid_twoterm.h"
#include "../plib/putil.h"
namespace netlist
@@ -27,7 +27,7 @@ namespace netlist
NETLIB_OBJECT(netlistparams)
{
NETLIB_CONSTRUCTOR(netlistparams)
- , m_use_deactivate(*this, "USE_DEACTIVATE", 0)
+ , m_use_deactivate(*this, "USE_DEACTIVATE", false)
{
}
NETLIB_UPDATEI() { }
@@ -125,18 +125,15 @@ namespace netlist
std::vector<pstring> pat(plib::psplit(m_pattern(),","));
m_off = netlist_time::from_double(m_offset());
- unsigned long pati[32];
- for (int pI = 0; pI < 32; pI++)
- {
- pati[pI] = 0;
- }
+ netlist_time::mult_type pati[32] = { 0 };
+
m_size = static_cast<std::uint8_t>(pat.size());
- unsigned long total = 0;
+ netlist_time::mult_type total = 0;
for (unsigned i=0; i<m_size; i++)
{
// FIXME: use pstonum_ne
//pati[i] = plib::pstonum<decltype(pati[i])>(pat[i]);
- pati[i] = plib::pstonum<unsigned long>(pat[i]);
+ pati[i] = plib::pstonum<netlist_time::mult_type>(pat[i]);
total += pati[i];
}
netlist_time ttotal = netlist_time::zero();
@@ -177,7 +174,7 @@ namespace netlist
{
NETLIB_CONSTRUCTOR(logic_input)
, m_Q(*this, "Q")
- , m_IN(*this, "IN", 0)
+ , m_IN(*this, "IN", false)
/* make sure we get the family first */
, m_FAMILY(*this, "FAMILY", "FAMILY(TYPE=TTL)")
{
diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp
index 2377071c4e2..5eda50e0357 100644
--- a/src/lib/netlist/devices/nlid_truthtable.cpp
+++ b/src/lib/netlist/devices/nlid_truthtable.cpp
@@ -6,9 +6,9 @@
*/
#include "nlid_truthtable.h"
-#include "../plib/plists.h"
#include "../nl_setup.h"
#include "../plib/palloc.h"
+#include "../plib/plists.h"
#include <bitset>
@@ -394,7 +394,7 @@ void truthtable_parser::parse(const std::vector<pstring> &truthtable)
else
nl_assert_always(outs == "0", "Unknown value (not 0 or 1");
// FIXME: error handling
- netlist_time t = netlist_time::from_nsec(plib::pstonum<unsigned long>(plib::trim(times[j])));
+ netlist_time t = netlist_time::from_nsec(plib::pstonum<netlist_time::internal_type>(plib::trim(times[j])));
uint_least8_t k=0;
while (m_timing_nt[k] != netlist_time::zero() && m_timing_nt[k] != t)
k++;
@@ -451,11 +451,6 @@ netlist_base_factory_truthtable_t::netlist_base_factory_truthtable_t(const pstri
{
}
-netlist_base_factory_truthtable_t::~netlist_base_factory_truthtable_t()
-{
-}
-
-
#define ENTRYY(n, m, s) case (n * 100 + m): \
{ using xtype = netlist_factory_truthtable_t<n, m>; \
ret = plib::palloc<xtype>(desc.name, desc.classname, desc.def_param, s); } break
diff --git a/src/lib/netlist/devices/nlid_truthtable.h b/src/lib/netlist/devices/nlid_truthtable.h
index 6896c656750..c344feda2d4 100644
--- a/src/lib/netlist/devices/nlid_truthtable.h
+++ b/src/lib/netlist/devices/nlid_truthtable.h
@@ -10,8 +10,8 @@
#ifndef NLID_TRUTHTABLE_H_
#define NLID_TRUTHTABLE_H_
-#include "../nl_setup.h"
#include "../nl_base.h"
+#include "../nl_setup.h"
#include "../plib/putil.h"
#define NETLIB_TRUTHTABLE(cname, nIN, nOUT) \
@@ -90,8 +90,10 @@ namespace devices
struct truthtable_t
{
truthtable_t()
- : m_initialized(false)
+ : m_timing_index{0}
+ , m_initialized(false)
{}
+
type_t m_out_state[m_size];
uint_least8_t m_timing_index[m_size * m_NO];
netlist_time m_timing_nt[16];
@@ -217,7 +219,7 @@ namespace devices
netlist_base_factory_truthtable_t(const pstring &name, const pstring &classname,
const pstring &def_param, const pstring &sourcefile);
- virtual ~netlist_base_factory_truthtable_t();
+ ~netlist_base_factory_truthtable_t() override = default;
std::vector<pstring> m_desc;
const logic_family_desc_t *m_family;
diff --git a/src/lib/netlist/macro/nlm_cd4xxx.cpp b/src/lib/netlist/macro/nlm_cd4xxx.cpp
index 9ce786ca85e..a9d622032fd 100644
--- a/src/lib/netlist/macro/nlm_cd4xxx.cpp
+++ b/src/lib/netlist/macro/nlm_cd4xxx.cpp
@@ -2,10 +2,10 @@
// copyright-holders:Couriersud
#include "nlm_cd4xxx.h"
-#include "../devices/nld_system.h"
#include "../devices/nld_4020.h"
#include "../devices/nld_4066.h"
#include "../devices/nld_4316.h"
+#include "../devices/nld_system.h"
/*
* CD4001BC: Quad 2-Input NOR Buffered B Series Gate
diff --git a/src/lib/netlist/netlist_types.h b/src/lib/netlist/netlist_types.h
index bbca9949e49..9edd19e0ace 100644
--- a/src/lib/netlist/netlist_types.h
+++ b/src/lib/netlist/netlist_types.h
@@ -9,13 +9,14 @@
#ifndef NETLIST_TYPES_H_
#define NETLIST_TYPES_H_
+#include <cstdint>
+#include <unordered_map>
+
#include "nl_config.h"
#include "plib/pchrono.h"
-#include "plib/pstring.h"
#include "plib/pfmtlog.h"
+#include "plib/pstring.h"
-#include <cstdint>
-#include <unordered_map>
namespace netlist
{
@@ -37,7 +38,7 @@ namespace netlist
class callbacks_t
{
public:
- virtual ~callbacks_t() {}
+ virtual ~callbacks_t() = default;
/* logging callback */
virtual void vlog(const plib::plog_level &l, const pstring &ls) const = 0;
@@ -74,7 +75,7 @@ namespace netlist
*/
using model_map_t = std::unordered_map<pstring, pstring>;
- }
-}
+ } // namespace detail
+} // namespace netlist
#endif /* NETLIST_TYPES_H_ */
diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp
index 24cb7cc8890..7447ddb5f02 100644
--- a/src/lib/netlist/nl_base.cpp
+++ b/src/lib/netlist/nl_base.cpp
@@ -8,18 +8,18 @@
#include "solver/nld_matrix_solver.h"
#include "solver/nld_solver.h"
-#include "plib/putil.h"
#include "plib/palloc.h"
+#include "plib/putil.h"
-#include "nl_base.h"
-#include "devices/nlid_system.h"
#include "devices/nlid_proxy.h"
+#include "devices/nlid_system.h"
#include "macro/nlm_base.h"
+#include "nl_base.h"
#include "nl_errstr.h"
-#include <cstring>
#include <cmath>
+#include <cstring>
#include <limits>
namespace netlist
@@ -56,26 +56,18 @@ namespace detail
}
}
-}
-
-nl_exception::~nl_exception()
-{
-}
+} // namespace detail
// ----------------------------------------------------------------------------------------
// logic_family_ttl_t
// ----------------------------------------------------------------------------------------
+// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init, modernize-use-equals-default)
logic_family_desc_t::logic_family_desc_t()
{
}
-logic_family_desc_t::~logic_family_desc_t()
-{
-}
-
-
class logic_family_ttl_t : public logic_family_desc_t
{
public:
@@ -90,8 +82,8 @@ public:
m_R_low = 1.0;
m_R_high = 130.0;
}
- virtual plib::owned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override;
- virtual plib::owned_ptr<devices::nld_base_a_to_d_proxy> create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override;
+ plib::owned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override;
+ plib::owned_ptr<devices::nld_base_a_to_d_proxy> create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override;
};
plib::owned_ptr<devices::nld_base_d_to_a_proxy> logic_family_ttl_t::create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const
@@ -117,8 +109,8 @@ public:
m_R_low = 10.0;
m_R_high = 10.0;
}
- virtual plib::owned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override;
- virtual plib::owned_ptr<devices::nld_base_a_to_d_proxy> create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override;
+ plib::owned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const override;
+ plib::owned_ptr<devices::nld_base_a_to_d_proxy> create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override;
};
plib::owned_ptr<devices::nld_base_d_to_a_proxy> logic_family_cd4xxx_t::create_d_a_proxy(netlist_base_t &anetlist, const pstring &name, logic_output_t *proxied) const
@@ -166,6 +158,7 @@ void detail::queue_t::register_state(plib::state_manager_t &manager, const pstri
void detail::queue_t::on_pre_save(plib::state_manager_t &manager)
{
+ plib::unused_var(manager);
m_qsize = this->size();
for (std::size_t i = 0; i < m_qsize; i++ )
{
@@ -177,6 +170,7 @@ void detail::queue_t::on_pre_save(plib::state_manager_t &manager)
void detail::queue_t::on_post_load(plib::state_manager_t &manager)
{
+ plib::unused_var(manager);
this->clear();
for (std::size_t i = 0; i < m_qsize; i++ )
{
@@ -197,17 +191,15 @@ detail::netlist_ref::netlist_ref(netlist_state_t &nl)
// ----------------------------------------------------------------------------------------
detail::object_t::object_t(const pstring &aname)
- : m_name(plib::make_unique<pstring>(aname))
+// : m_name(aname)
{
+ name_hash().insert({this, aname});
}
-detail::object_t::~object_t()
+pstring detail::object_t::name() const
{
-}
-
-const pstring &detail::object_t::name() const
-{
- return *m_name;
+ return name_hash().find(this)->second;
+ //return m_name;
}
// ----------------------------------------------------------------------------------------
@@ -258,10 +250,6 @@ netlist_t::netlist_t(const pstring &aname, std::unique_ptr<callbacks_t> callback
run_state_manager().save_item(this, m_time, "m_time");
}
-netlist_t::~netlist_t()
-{
-}
-
// ----------------------------------------------------------------------------------------
// netlist_t
// ----------------------------------------------------------------------------------------
@@ -355,7 +343,7 @@ void netlist_state_t::reset()
// Reset all devices once !
log().verbose("Call reset on all devices:");
for (auto & dev : m_devices)
- dev->reset();
+ dev.second->reset();
// Make sure everything depending on parameters is set
// Currently analog input and logic input also
@@ -363,7 +351,7 @@ void netlist_state_t::reset()
log().verbose("Call update_param on all devices:");
for (auto & dev : m_devices)
- dev->update_param();
+ dev.second->update_param();
// Step all devices once !
/*
@@ -389,14 +377,14 @@ void netlist_state_t::reset()
t.push_back(&term->m_delegate);
term->m_delegate();
}
- core_device_t *dev = reinterpret_cast<core_device_t *>(term->m_delegate.object());
+ auto *dev = reinterpret_cast<core_device_t *>(term->m_delegate.object());
if (!plib::container::contains(d, dev))
d.push_back(dev);
}
log().verbose("Devices not yet updated:");
for (auto &dev : m_devices)
- if (!plib::container::contains(d, dev.get()))
- log().verbose("\t ...{1}", dev->name());
+ if (!plib::container::contains(d, dev.second.get()))
+ log().verbose("\t ...{1}", dev.second->name());
//x->update_dev();
}
break;
@@ -409,7 +397,7 @@ void netlist_state_t::reset()
std::size_t i = m_devices.size();
while (i>0)
- m_devices[--i]->update();
+ m_devices[--i].second->update();
for (auto &n : m_nets) // only used if USE_COPY_INSTEAD_OF_REFERENCE == 1
n->update_inputs();
@@ -420,7 +408,7 @@ void netlist_state_t::reset()
{
log().verbose("Using brute force forward startup strategy");
for (auto &d : m_devices)
- d->update();
+ d.second->update();
}
break;
}
@@ -434,11 +422,11 @@ void netlist_state_t::reset()
void netlist_t::process_queue(const netlist_time delta) NL_NOEXCEPT
{
+ auto sm_guard(m_stat_mainloop.guard());
netlist_time stop(m_time + delta);
m_queue.push(detail::queue_t::entry_t(stop, nullptr));
- auto sm_guard(m_stat_mainloop.guard());
if (m_mainclock == nullptr)
{
@@ -491,14 +479,14 @@ void netlist_t::print_stats() const
index.push_back(i);
std::sort(index.begin(), index.end(),
- [&](size_t i1, size_t i2) { return m_state->m_devices[i1]->m_stat_total_time.total() < m_state->m_devices[i2]->m_stat_total_time.total(); });
+ [&](size_t i1, size_t i2) { return m_state->m_devices[i1].second->m_stat_total_time.total() < m_state->m_devices[i2].second->m_stat_total_time.total(); });
nperftime_t<NL_KEEP_STATISTICS>::type total_time(0);
- uint_least64_t total_count(0);
+ netlist_time::mult_type total_count(0);
for (auto & j : index)
{
- auto entry = m_state->m_devices[j].get();
+ auto entry = m_state->m_devices[j].second.get();
log().verbose("Device {1:20} : {2:12} {3:12} {4:15} {5:12}", entry->name(),
entry->m_stat_call_count(), entry->m_stat_total_time.count(),
entry->m_stat_total_time.total(), entry->m_stat_inc_active());
@@ -543,12 +531,13 @@ void netlist_t::print_stats() const
auto trigger = total_count * 200 / 1000000; // 200 ppm
for (auto &entry : m_state->m_devices)
{
+ auto ep = entry.second.get();
// Factor of 3 offers best performace increase
- if (entry->m_stat_inc_active() > 3 * entry->m_stat_total_time.count()
- && entry->m_stat_inc_active() > trigger)
- log().verbose("HINT({}, NO_DEACTIVATE) // {} {} {}", entry->name(),
- static_cast<double>(entry->m_stat_inc_active()) / static_cast<double>(entry->m_stat_total_time.count()),
- entry->m_stat_inc_active(), entry->m_stat_total_time.count());
+ if (ep->m_stat_inc_active() > 3 * ep->m_stat_total_time.count()
+ && ep->m_stat_inc_active() > trigger)
+ log().verbose("HINT({}, NO_DEACTIVATE) // {} {} {}", ep->name(),
+ static_cast<double>(ep->m_stat_inc_active()) / static_cast<double>(ep->m_stat_total_time.count()),
+ ep->m_stat_inc_active(), ep->m_stat_total_time.count());
}
}
}
@@ -558,12 +547,12 @@ core_device_t *netlist_state_t::get_single_device(const pstring &classname, bool
core_device_t *ret = nullptr;
for (auto &d : m_devices)
{
- if (cc(d.get()))
+ if (cc(d.second.get()))
{
if (ret != nullptr)
m_log.fatal(MF_1_MORE_THAN_ONE_1_DEVICE_FOUND, classname);
else
- ret = d.get();
+ ret = d.second.get();
}
}
return ret;
@@ -595,11 +584,7 @@ core_device_t::core_device_t(core_device_t &owner, const pstring &name)
set_logic_family(owner.logic_family());
if (logic_family() == nullptr)
set_logic_family(family_TTL());
- state().add_dev(plib::owned_ptr<core_device_t>(this, false));
-}
-
-core_device_t::~core_device_t()
-{
+ state().add_dev(this->name(), plib::owned_ptr<core_device_t>(this, false));
}
void core_device_t::set_default_delegate(detail::core_terminal_t &term)
@@ -627,11 +612,6 @@ device_t::device_t(core_device_t &owner, const pstring &name)
{
}
-device_t::~device_t()
-{
- //log().debug("~net_device_t\n");
-}
-
setup_t &device_t::setup()
{
return state().setup();
@@ -683,6 +663,11 @@ void device_t::connect_post_start(detail::core_terminal_t &t1, detail::core_term
// family_setter_t
// -----------------------------------------------------------------------------
+// NOLINTNEXTLINE(modernize-use-equals-default)
+detail::family_setter_t::family_setter_t()
+{
+}
+
detail::family_setter_t::family_setter_t(core_device_t &dev, const pstring &desc)
{
dev.set_logic_family(dev.setup().family_from_model(desc));
@@ -776,7 +761,7 @@ void detail::net_t::reset()
m_new_Q = 0;
m_cur_Q = 0;
- analog_net_t *p = dynamic_cast<analog_net_t *>(this);
+ auto *p = dynamic_cast<analog_net_t *>(this);
if (p != nullptr)
p->m_cur_Analog = 0.0;
@@ -833,10 +818,6 @@ logic_net_t::logic_net_t(netlist_base_t &nl, const pstring &aname, detail::core_
{
}
-logic_net_t::~logic_net_t()
-{
-}
-
// ----------------------------------------------------------------------------------------
// analog_net_t
// ----------------------------------------------------------------------------------------
@@ -848,10 +829,6 @@ analog_net_t::analog_net_t(netlist_base_t &nl, const pstring &aname, detail::cor
{
}
-analog_net_t::~analog_net_t()
-{
-}
-
// ----------------------------------------------------------------------------------------
// core_terminal_t
// ----------------------------------------------------------------------------------------
@@ -869,19 +846,11 @@ detail::core_terminal_t::core_terminal_t(core_device_t &dev, const pstring &anam
{
}
-detail::core_terminal_t::~core_terminal_t()
-{
-}
-
analog_t::analog_t(core_device_t &dev, const pstring &aname, const state_e state)
: core_terminal_t(dev, aname, state)
{
}
-analog_t::~analog_t()
-{
-}
-
logic_t::logic_t(core_device_t &dev, const pstring &aname, const state_e state,
nldelegate delegate)
: core_terminal_t(dev, aname, state, delegate)
@@ -890,28 +859,20 @@ logic_t::logic_t(core_device_t &dev, const pstring &aname, const state_e state,
{
}
-logic_t::~logic_t()
-{
-}
-
// ----------------------------------------------------------------------------------------
// terminal_t
// ----------------------------------------------------------------------------------------
-terminal_t::terminal_t(core_device_t &dev, const pstring &aname)
+terminal_t::terminal_t(core_device_t &dev, const pstring &aname, terminal_t *otherterm)
: analog_t(dev, aname, STATE_BIDIR)
-, m_otherterm(nullptr)
, m_Idr1(nullptr)
, m_go1(nullptr)
, m_gt1(nullptr)
+, m_otherterm(otherterm)
{
state().setup().register_term(*this);
}
-terminal_t::~terminal_t()
-{
-}
-
void terminal_t::solve_now()
{
// Nets may belong to railnets which do not have a solver attached
@@ -950,10 +911,6 @@ logic_output_t::logic_output_t(core_device_t &dev, const pstring &aname)
state().setup().register_term(*this);
}
-logic_output_t::~logic_output_t()
-{
-}
-
void logic_output_t::initial(const netlist_sig_t val)
{
if (has_net())
@@ -970,10 +927,6 @@ analog_input_t::analog_input_t(core_device_t &dev, const pstring &aname)
state().setup().register_term(*this);
}
-analog_input_t::~analog_input_t()
-{
-}
-
// ----------------------------------------------------------------------------------------
// analog_output_t
// ----------------------------------------------------------------------------------------
@@ -989,10 +942,6 @@ analog_output_t::analog_output_t(core_device_t &dev, const pstring &aname)
state().setup().register_term(*this);
}
-analog_output_t::~analog_output_t()
-{
-}
-
void analog_output_t::initial(const nl_double val)
{
net().set_Q_Analog(val);
@@ -1010,10 +959,6 @@ logic_input_t::logic_input_t(core_device_t &dev, const pstring &aname,
state().setup().register_term(*this);
}
-logic_input_t::~logic_input_t()
-{
-}
-
// ----------------------------------------------------------------------------------------
// Parameters ...
// ----------------------------------------------------------------------------------------
@@ -1024,10 +969,6 @@ param_t::param_t(device_t &device, const pstring &name)
device.setup().register_param(this->name(), *this);
}
-param_t::~param_t()
-{
-}
-
param_t::param_type_t param_t::param_type() const
{
if (dynamic_cast<const param_str_t *>(this) != nullptr)
@@ -1074,10 +1015,6 @@ param_str_t::param_str_t(device_t &device, const pstring &name, const pstring &v
m_param = device.setup().get_initial_param_val(this->name(),val);
}
-param_str_t::~param_str_t()
-{
-}
-
void param_str_t::changed()
{
}
diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h
index 507eb42d367..58563c91610 100644
--- a/src/lib/netlist/nl_base.h
+++ b/src/lib/netlist/nl_base.h
@@ -13,18 +13,20 @@
#error "nl_base.h included. Please correct."
#endif
-#include "netlist_types.h"
-#include "nl_errstr.h"
-#include "nl_lists.h"
-#include "nl_time.h"
+#include <unordered_map>
+#include <vector>
+
#include "plib/palloc.h" // owned_ptr
#include "plib/pdynlib.h"
-#include "plib/pstate.h"
#include "plib/pfmtlog.h"
-#include "plib/pstream.h"
#include "plib/ppmf.h"
+#include "plib/pstate.h"
+#include "plib/pstream.h"
-#include <unordered_map>
+#include "netlist_types.h"
+#include "nl_errstr.h"
+#include "nl_lists.h"
+#include "nl_time.h"
//============================================================
// MACROS / New Syntax
@@ -186,7 +188,7 @@ namespace netlist
class NETLIB_NAME(base_proxy);
class NETLIB_NAME(base_d_to_a_proxy);
class NETLIB_NAME(base_a_to_d_proxy);
- }
+ } // namespace devices
namespace detail {
class object_t;
@@ -196,13 +198,12 @@ namespace netlist
struct family_setter_t;
class queue_t;
class net_t;
- }
+ } // namespace detail
class logic_output_t;
class logic_input_t;
class analog_net_t;
class logic_net_t;
- class net_t;
class setup_t;
class netlist_t;
class netlist_state_t;
@@ -228,8 +229,7 @@ namespace netlist
)
: plib::pexception(text) { }
/*! Copy constructor. */
- nl_exception(const nl_exception &e) : plib::pexception(e) { }
- virtual ~nl_exception();
+ nl_exception(const nl_exception &e) = default;
};
/*! Logic families descriptors are used to create proxy devices.
@@ -240,7 +240,7 @@ namespace netlist
{
public:
logic_family_desc_t();
- virtual ~logic_family_desc_t();
+ virtual ~logic_family_desc_t() = default;
virtual plib::owned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_base_t &anetlist, const pstring &name,
logic_output_t *proxied) const = 0;
@@ -250,8 +250,8 @@ namespace netlist
double fixed_V() const { return m_fixed_V; }
double low_thresh_V(const double VN, const double VP) const { return VN + (VP - VN) * m_low_thresh_PCNT; }
double high_thresh_V(const double VN, const double VP) const { return VN + (VP - VN) * m_high_thresh_PCNT; }
- double low_V(const double VN, const double VP) const { return VN + m_low_VO; }
- double high_V(const double VN, const double VP) const { return VP - m_high_VO; }
+ double low_V(const double VN, const double VP) const { plib::unused_var(VP); return VN + m_low_VO; }
+ double high_V(const double VN, const double VP) const { plib::unused_var(VN); return VP - m_high_VO; }
double R_low() const { return m_R_low; }
double R_high() const { return m_R_high; }
@@ -285,7 +285,7 @@ namespace netlist
void set_logic_family(const logic_family_desc_t *fam) { m_logic_family = fam; }
protected:
- ~logic_family_t() { } // prohibit polymorphic destruction
+ ~logic_family_t() = default; // prohibit polymorphic destruction
const logic_family_desc_t *m_logic_family;
};
@@ -391,7 +391,7 @@ namespace netlist
* memory allocation to enhance locality. Please refer to \ref USE_MEMPOOL as
* well.
*/
- class detail::object_t
+ class detail::object_t : public plib::nocopyassignmove
{
public:
@@ -405,17 +405,22 @@ namespace netlist
*
* \returns name of the object.
*/
- const pstring &name() const;
+ pstring name() const;
- void * operator new (size_t size, void *ptr) { return ptr; }
- void operator delete (void *ptr, void *) { }
+ void * operator new (size_t size, void *ptr) { plib::unused_var(size); return ptr; }
+ void operator delete (void *ptr, void *) { plib::unused_var(ptr); }
void * operator new (size_t size);
void operator delete (void * mem);
protected:
- ~object_t(); // only childs should be destructible
+ ~object_t() = default; // only childs should be destructible
private:
- std::unique_ptr<pstring> m_name;
+ //pstring m_name;
+ static std::unordered_map<const object_t *, pstring> &name_hash()
+ {
+ static std::unordered_map<const object_t *, pstring> lhash;
+ return lhash;
+ }
};
struct detail::netlist_ref
@@ -508,7 +513,7 @@ namespace netlist
core_terminal_t(core_device_t &dev, const pstring &aname,
const state_e state, nldelegate delegate = nldelegate());
- virtual ~core_terminal_t();
+ virtual ~core_terminal_t() = default;
/*! The object type.
* \returns type of the object
@@ -562,7 +567,6 @@ namespace netlist
public:
analog_t(core_device_t &dev, const pstring &aname, const state_e state);
- virtual ~analog_t();
const analog_net_t & net() const NL_NOEXCEPT;
analog_net_t & net() NL_NOEXCEPT;
@@ -576,8 +580,7 @@ namespace netlist
{
public:
- terminal_t(core_device_t &dev, const pstring &aname);
- virtual ~terminal_t();
+ terminal_t(core_device_t &dev, const pstring &aname, terminal_t *otherterm);
nl_double operator ()() const NL_NOEXCEPT;
@@ -593,36 +596,28 @@ namespace netlist
void set(const nl_double GO, const nl_double GT, const nl_double I) noexcept
{
- set_ptr(m_Idr1, I);
- set_ptr(m_go1, GO);
- set_ptr(m_gt1, GT);
+ if (m_go1 != nullptr)
+ {
+ if (*m_Idr1 != I) *m_Idr1 = I;
+ if (*m_go1 != GO) *m_go1 = GO;
+ if (*m_gt1 != GT) *m_gt1 = GT;
+ }
}
void solve_now();
void schedule_solve_after(const netlist_time after);
- void set_ptrs(nl_double *gt, nl_double *go, nl_double *Idr) noexcept
- {
- m_gt1 = gt;
- m_go1 = go;
- m_Idr1 = Idr;
- }
-
- terminal_t *m_otherterm;
+ void set_ptrs(nl_double *gt, nl_double *go, nl_double *Idr) noexcept;
+ terminal_t *otherterm() const noexcept { return m_otherterm; }
private:
- void set_ptr(nl_double *ptr, const nl_double val) noexcept
- {
- if (ptr != nullptr && *ptr != val)
- {
- *ptr = val;
- }
- }
nl_double *m_Idr1; // drive current
nl_double *m_go1; // conductance for Voltage from other term
nl_double *m_gt1; // conductance for total conductance
+ terminal_t *m_otherterm;
+
};
@@ -635,7 +630,6 @@ namespace netlist
public:
logic_t(core_device_t &dev, const pstring &aname,
const state_e state, nldelegate delegate = nldelegate());
- virtual ~logic_t();
bool has_proxy() const { return (m_proxy != nullptr); }
devices::nld_base_proxy *get_proxy() const { return m_proxy; }
@@ -659,7 +653,6 @@ namespace netlist
public:
logic_input_t(core_device_t &dev, const pstring &aname,
nldelegate delegate = nldelegate());
- virtual ~logic_input_t();
netlist_sig_t operator()() const NL_NOEXCEPT
{
@@ -691,9 +684,6 @@ namespace netlist
const pstring &aname /*!< name of terminal */
);
- /*! Destructor */
- virtual ~analog_input_t();
-
/*! returns voltage at terminal.
* \returns voltage at terminal.
*/
@@ -796,7 +786,6 @@ namespace netlist
public:
logic_net_t(netlist_base_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr);
- virtual ~logic_net_t();
netlist_sig_t Q() const noexcept { return m_cur_Q; }
void initial(const netlist_sig_t val) noexcept
@@ -853,8 +842,6 @@ namespace netlist
analog_net_t(netlist_base_t &nl, const pstring &aname, detail::core_terminal_t *mr = nullptr);
- virtual ~analog_net_t();
-
nl_double Q_Analog() const NL_NOEXCEPT { return m_cur_Analog; }
void set_Q_Analog(const nl_double v) NL_NOEXCEPT { m_cur_Analog = v; }
nl_double *Q_Analog_state_ptr() NL_NOEXCEPT { return m_cur_Analog.ptr(); }
@@ -877,7 +864,6 @@ namespace netlist
public:
logic_output_t(core_device_t &dev, const pstring &aname);
- virtual ~logic_output_t();
void initial(const netlist_sig_t val);
@@ -904,7 +890,6 @@ namespace netlist
{
public:
analog_output_t(core_device_t &dev, const pstring &aname);
- virtual ~analog_output_t();
void push(const nl_double val) NL_NOEXCEPT { set_Q(val); }
void initial(const nl_double val);
@@ -935,7 +920,7 @@ namespace netlist
param_type_t param_type() const;
protected:
- virtual ~param_t(); /* not intended to be destroyed */
+ virtual ~param_t() = default; /* not intended to be destroyed */
void update_param();
@@ -995,10 +980,9 @@ namespace netlist
{
public:
param_str_t(device_t &device, const pstring &name, const pstring &val);
- virtual ~param_str_t();
const pstring &operator()() const NL_NOEXCEPT { return Value(); }
- void setTo(netlist_time time, const pstring &param) NL_NOEXCEPT
+ void setTo(const pstring &param) NL_NOEXCEPT
{
if (m_param != param)
{
@@ -1042,12 +1026,12 @@ namespace netlist
const pstring model_value_str(const pstring &entity) /*const*/;
const pstring model_type() /*const*/;
+ /* hide this */
+ void setTo(const pstring &param) = delete;
protected:
- virtual void changed() override;
+ void changed() override;
nl_double model_value(const pstring &entity) /*const*/;
private:
- /* hide this */
- void setTo(const pstring &param) = delete;
detail::model_map_t m_map;
};
@@ -1065,7 +1049,7 @@ namespace netlist
std::unique_ptr<plib::pistream> stream();
protected:
- virtual void changed() override { }
+ void changed() override { }
};
// -----------------------------------------------------------------------------
@@ -1081,7 +1065,7 @@ namespace netlist
const ST & operator[] (std::size_t n) NL_NOEXCEPT { return m_data[n]; }
protected:
- virtual void changed() override
+ void changed() override
{
stream()->read(reinterpret_cast<plib::pistream::value_type *>(&m_data[0]),1<<AW);
}
@@ -1103,7 +1087,7 @@ namespace netlist
core_device_t(netlist_base_t &owner, const pstring &name);
core_device_t(core_device_t &owner, const pstring &name);
- virtual ~core_device_t();
+ virtual ~core_device_t() = default;
void do_inc_active() NL_NOEXCEPT
{
@@ -1172,7 +1156,7 @@ namespace netlist
device_t(netlist_base_t &owner, const pstring &name);
device_t(core_device_t &owner, const pstring &name);
- virtual ~device_t() override;
+ ~device_t() override = default;
setup_t &setup();
const setup_t &setup() const;
@@ -1203,7 +1187,11 @@ namespace netlist
struct detail::family_setter_t
{
- family_setter_t() { }
+ /* clang will complain about an unused private field if
+ * a defaulted constructor is used
+ */
+ // NOLINTNEXTLINE(modernize-use-equals-default)
+ family_setter_t();
family_setter_t(core_device_t &dev, const pstring &desc);
family_setter_t(core_device_t &dev, const logic_family_desc_t *desc);
};
@@ -1255,7 +1243,9 @@ namespace netlist
{
public:
using nets_collection_type = std::vector<plib::owned_ptr<detail::net_t>>;
- using devices_collection_type = std::vector<plib::owned_ptr<core_device_t>>;
+
+ /* need to preserve order of device creation ... */
+ using devices_collection_type = std::vector<std::pair<pstring, plib::owned_ptr<core_device_t>>>;
netlist_state_t(const pstring &aname,
std::unique_ptr<callbacks_t> &&callbacks,
std::unique_ptr<setup_t> &&setup);
@@ -1289,13 +1279,15 @@ namespace netlist
plib::state_manager_t &run_state_manager() { return m_state; }
- template<typename O, typename C> void save(O &owner, C &state, const pstring &stname)
+ template<typename O, typename C>
+ void save(O &owner, C &state, const pstring &module, const pstring &stname)
{
- this->run_state_manager().save_item(static_cast<void *>(&owner), state, owner.name() + pstring(".") + stname);
+ this->run_state_manager().save_item(static_cast<void *>(&owner), state, module + pstring(".") + stname);
}
- template<typename O, typename C> void save(O &owner, C *state, const pstring &stname, const std::size_t count)
+ template<typename O, typename C>
+ void save(O &owner, C *state, const pstring &module, const pstring &stname, const std::size_t count)
{
- this->run_state_manager().save_state_ptr(static_cast<void *>(&owner), owner.name() + pstring(".") + stname, plib::state_manager_t::datatype_f<C>::f(), count, state);
+ this->run_state_manager().save_state_ptr(static_cast<void *>(&owner), module + pstring(".") + stname, plib::state_manager_t::dtype<C>(), count, state);
}
core_device_t *get_single_device(const pstring &classname, bool (*cc)(core_device_t *)) const;
@@ -1312,33 +1304,31 @@ namespace netlist
std::vector<device_class *> tmp;
for (auto &d : m_devices)
{
- device_class *dev = dynamic_cast<device_class *>(d.get());
+ auto dev = dynamic_cast<device_class *>(d.second.get());
if (dev != nullptr)
tmp.push_back(dev);
}
return tmp;
}
- void add_dev(plib::owned_ptr<core_device_t> dev)
+ template <typename T>
+ void add_dev(const pstring &name, plib::owned_ptr<T> &&dev)
{
for (auto & d : m_devices)
- if (d->name() == dev->name())
- log().fatal(MF_1_DUPLICATE_NAME_DEVICE_LIST, d->name());
- m_devices.push_back(std::move(dev));
+ if (d.first == name)
+ log().fatal(MF_1_DUPLICATE_NAME_DEVICE_LIST, d.first);
+ //m_devices.push_back(std::move(dev));
+ m_devices.insert(m_devices.end(), { name, std::move(dev) });
}
void remove_dev(core_device_t *dev)
{
- m_devices.erase(
- std::remove_if(
- m_devices.begin(),
- m_devices.end(),
- [&] (plib::owned_ptr<core_device_t> const& p)
- {
- return p.get() == dev;
- }),
- m_devices.end()
- );
+ for (auto it = m_devices.begin(); it != m_devices.end(); it++)
+ if (it->second.get() == dev)
+ {
+ m_devices.erase(it);
+ return;
+ }
}
/* sole use is to manage lifetime of family objects */
@@ -1379,7 +1369,7 @@ namespace netlist
public:
explicit netlist_t(const pstring &aname, std::unique_ptr<callbacks_t> callbacks);
- ~netlist_t();
+ ~netlist_t() = default;
/* run functions */
@@ -1407,6 +1397,7 @@ namespace netlist
template <typename X = devices::NETLIB_NAME(solver)>
nl_double gmin(X *solv = nullptr) const NL_NOEXCEPT
{
+ plib::unused_var(solv);
return static_cast<X *>(m_solver)->gmin();
}
@@ -1486,7 +1477,7 @@ namespace netlist
if (found)
{
bool err = false;
- T vald = plib::pstonum_ne<T>(p, err);
+ auto vald = plib::pstonum_ne<T>(p, err);
if (err)
device.state().log().fatal(MF_2_INVALID_NUMBER_CONVERSION_1_2, name, p);
m_param = vald;
@@ -1494,7 +1485,7 @@ namespace netlist
else
m_param = val;
- device.state().save(*this, m_param, "m_param");
+ device.state().save(*this, m_param, this->name(), "m_param");
}
template <typename ST, std::size_t AW, std::size_t DW>
@@ -1613,6 +1604,18 @@ namespace netlist
inline nl_double terminal_t::operator ()() const NL_NOEXCEPT { return net().Q_Analog(); }
+ inline void terminal_t::set_ptrs(nl_double *gt, nl_double *go, nl_double *Idr) noexcept
+ {
+ if (!(gt && go && Idr) && (gt || go || Idr))
+ state().log().fatal("Inconsistent nullptrs for terminal {}", name());
+ else
+ {
+ m_gt1 = gt;
+ m_go1 = go;
+ m_Idr1 = Idr;
+ }
+ }
+
inline logic_net_t & logic_t::net() NL_NOEXCEPT
{
return static_cast<logic_net_t &>(core_terminal_t::net());
@@ -1674,18 +1677,18 @@ namespace netlist
state_var<T>::state_var(O &owner, const pstring &name, const T &value)
: m_value(value)
{
- owner.state().save(owner, m_value, name);
+ owner.state().save(owner, m_value, owner.name(), name);
}
template <typename T, std::size_t N>
template <typename O>
state_var<T[N]>::state_var(O &owner, const pstring &name, const T & value)
{
- owner.state().save(owner, m_value, name);
+ owner.state().save(owner, m_value, owner.name(), name);
for (std::size_t i=0; i<N; i++)
m_value[i] = value;
}
-}
+} // namespace netlist
namespace plib
{
@@ -1693,7 +1696,7 @@ namespace plib
struct ptype_traits<netlist::state_var<X>> : ptype_traits<X>
{
};
-}
+} // namespace plib
diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h
index 69b5fad945c..de9a370db2f 100644
--- a/src/lib/netlist/nl_config.h
+++ b/src/lib/netlist/nl_config.h
@@ -62,8 +62,6 @@
// FIXME: Convert into solver parameter
#define USE_LINEAR_PREDICTION (0)
-#define NETLIST_GMIN_DEFAULT (1e-9)
-
//============================================================
// DEBUGGING
//============================================================
@@ -98,16 +96,17 @@
#endif // !defined(USE_OPENMP)
// Use nano-second resolution - Sufficient for now
-#define NETLIST_INTERNAL_RES (UINT64_C(1000000000))
-#define NETLIST_CLOCK (NETLIST_INTERNAL_RES)
+
+static constexpr const auto NETLIST_INTERNAL_RES = 1000000000;
+static constexpr const auto NETLIST_CLOCK = NETLIST_INTERNAL_RES;
+
+//#define NETLIST_INTERNAL_RES (UINT64_C(1000000000))
+//#define NETLIST_CLOCK (NETLIST_INTERNAL_RES)
//#define NETLIST_INTERNAL_RES (UINT64_C(1000000000000))
//#define NETLIST_CLOCK (UINT64_C(1000000000))
//#define nl_double float
-//#define NL_FCONST(x) (x ## f)
-
-#define NL_FCONST(x) x
using nl_double = double;
//============================================================
diff --git a/src/lib/netlist/nl_factory.cpp b/src/lib/netlist/nl_factory.cpp
index eca8de4d4b2..26ee33853e0 100644
--- a/src/lib/netlist/nl_factory.cpp
+++ b/src/lib/netlist/nl_factory.cpp
@@ -10,9 +10,9 @@
#include "nl_factory.h"
#include "nl_base.h"
+#include "nl_errstr.h"
#include "nl_setup.h"
#include "plib/putil.h"
-#include "nl_errstr.h"
namespace netlist { namespace factory
{
@@ -26,7 +26,7 @@ namespace netlist { namespace factory
}
protected:
NETLIB_RESETI() { }
- NETLIB_UPDATEI() { };
+ NETLIB_UPDATEI() { }
};
element_t::element_t(const pstring &name, const pstring &classname,
@@ -43,10 +43,6 @@ namespace netlist { namespace factory
{
}
- element_t::~element_t()
- {
- }
-
// ----------------------------------------------------------------------------------------
// net_device_t_base_factory
// ----------------------------------------------------------------------------------------
@@ -98,4 +94,5 @@ namespace netlist { namespace factory
}
-} }
+} // namespace factory
+ } // namespace netlist
diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h
index a20ba400234..ca0c266739e 100644
--- a/src/lib/netlist/nl_factory.h
+++ b/src/lib/netlist/nl_factory.h
@@ -49,10 +49,14 @@ namespace factory {
const pstring &def_param);
element_t(const pstring &name, const pstring &classname,
const pstring &def_param, const pstring &sourcefile);
- virtual ~element_t();
+ virtual ~element_t() = default;
virtual plib::owned_ptr<device_t> Create(netlist_state_t &anetlist, const pstring &name) = 0;
- virtual void macro_actions(netlist_state_t &anetlist, const pstring &name) {}
+ virtual void macro_actions(netlist_state_t &anetlist, const pstring &name)
+ {
+ plib::unused_var(anetlist);
+ plib::unused_var(name);
+ }
const pstring &name() const { return m_name; }
const pstring &classname() const { return m_classname; }
@@ -133,7 +137,11 @@ namespace factory {
library_element_t(setup_t &setup, const pstring &name, const pstring &classname,
const pstring &def_param, const pstring &source)
- : element_t(name, classname, def_param, source) { }
+ : element_t(name, classname, def_param, source)
+ {
+ // FIXME: if it is not used, remove it
+ plib::unused_var(setup);
+ }
plib::owned_ptr<device_t> Create(netlist_state_t &anetlist, const pstring &name) override;
@@ -142,11 +150,11 @@ namespace factory {
private:
};
- }
+ } // namespace factory
namespace devices {
void initialize_factory(factory::list_t &factory);
- }
-}
+ } // namespace devices
+} // namespace netlist
#endif /* NLFACTORY_H_ */
diff --git a/src/lib/netlist/nl_lists.h b/src/lib/netlist/nl_lists.h
index 042a823259f..0c5b25c1a1b 100644
--- a/src/lib/netlist/nl_lists.h
+++ b/src/lib/netlist/nl_lists.h
@@ -10,16 +10,16 @@
#ifndef NLLISTS_H_
#define NLLISTS_H_
-#include "nl_config.h"
#include "netlist_types.h"
-#include "plib/plists.h"
+#include "nl_config.h"
#include "plib/pchrono.h"
+#include "plib/plists.h"
#include "plib/ptypes.h"
+#include <algorithm>
#include <atomic>
-#include <thread>
#include <mutex>
-#include <algorithm>
+#include <thread>
#include <utility>
// ----------------------------------------------------------------------------------------
@@ -33,7 +33,7 @@ namespace netlist
class pspin_mutex
{
public:
- pspin_mutex() noexcept { }
+ pspin_mutex() noexcept = default;
void lock() noexcept{ while (m_lock.test_and_set(std::memory_order_acquire)) { } }
void unlock() noexcept { m_lock.clear(std::memory_order_release); }
private:
@@ -309,6 +309,6 @@ namespace netlist
template <class T, bool TS, bool KEEPSTAT, class QueueOp = typename T::QueueOp>
using timed_queue = timed_queue_linear<T, TS, KEEPSTAT, QueueOp>;
-}
+} // namespace netlist
#endif /* NLLISTS_H_ */
diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp
index 460ff3819bf..f28eb822a09 100644
--- a/src/lib/netlist/nl_parser.cpp
+++ b/src/lib/netlist/nl_parser.cpp
@@ -6,9 +6,9 @@
*/
#include "nl_parser.h"
-#include "nl_factory.h"
-#include "nl_errstr.h"
#include "nl_base.h"
+#include "nl_errstr.h"
+#include "nl_factory.h"
namespace netlist
{
@@ -395,7 +395,7 @@ void parser_t::device(const pstring &dev_type)
// ----------------------------------------------------------------------------------------
-nl_double parser_t::eval_param(const token_t tok)
+nl_double parser_t::eval_param(const token_t &tok)
{
static pstring macs[6] = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"};
static nl_double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
@@ -423,4 +423,4 @@ nl_double parser_t::eval_param(const token_t tok)
}
-}
+} // namespace netlist
diff --git a/src/lib/netlist/nl_parser.h b/src/lib/netlist/nl_parser.h
index f14250ea7d1..16075ca4914 100644
--- a/src/lib/netlist/nl_parser.h
+++ b/src/lib/netlist/nl_parser.h
@@ -18,7 +18,7 @@ namespace netlist
public:
template <typename T>
parser_t(T &&strm, setup_t &setup)
- : plib::ptokenizer(std::move(strm))
+ : plib::ptokenizer(std::forward<T>(strm))
, m_setup(setup)
{
}
@@ -45,10 +45,10 @@ namespace netlist
/* for debugging messages */
netlist_state_t &netlist() { return m_setup.netlist(); }
- virtual void verror(const pstring &msg, int line_num, const pstring &line) override;
+ void verror(const pstring &msg, int line_num, const pstring &line) override;
private:
- nl_double eval_param(const token_t tok);
+ nl_double eval_param(const token_t &tok);
token_id_t m_tok_param_left;
token_id_t m_tok_param_right;
@@ -75,6 +75,6 @@ namespace netlist
setup_t &m_setup;
};
-}
+} // namespace netlist
#endif /* NL_PARSER_H_ */
diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp
index cef51f481db..d60074c0e47 100644
--- a/src/lib/netlist/nl_setup.cpp
+++ b/src/lib/netlist/nl_setup.cpp
@@ -6,16 +6,16 @@
*/
#include "plib/palloc.h"
-#include "plib/putil.h"
+#include "analog/nld_twoterm.h"
+#include "devices/nlid_proxy.h"
+#include "devices/nlid_system.h"
+#include "devices/nlid_truthtable.h"
#include "nl_base.h"
-#include "nl_setup.h"
-#include "nl_parser.h"
#include "nl_factory.h"
-#include "devices/nlid_system.h"
-#include "devices/nlid_proxy.h"
-#include "analog/nld_twoterm.h"
+#include "nl_parser.h"
+#include "nl_setup.h"
+#include "plib/putil.h"
#include "solver/nld_solver.h"
-#include "devices/nlid_truthtable.h"
#include <cmath>
@@ -88,17 +88,24 @@ void setup_t::register_dev(const pstring &classname, const pstring &name)
auto f = factory().factory_by_name(classname);
if (f == nullptr)
log().fatal(MF_1_CLASS_1_NOT_FOUND, classname);
- /* make sure we parse macro library entries */
- f->macro_actions(netlist(), name);
- pstring key = build_fqn(name);
- if (device_exists(key))
- log().fatal(MF_1_DEVICE_ALREADY_EXISTS_1, name);
- m_device_factory[key] = f;
+ else
+ {
+ /* make sure we parse macro library entries */
+ f->macro_actions(netlist(), name);
+ pstring key = build_fqn(name);
+ if (device_exists(key))
+ log().fatal(MF_1_DEVICE_ALREADY_EXISTS_1, name);
+ else
+ m_device_factory.insert(m_device_factory.end(), {key, f});
+ }
}
bool setup_t::device_exists(const pstring &name) const
{
- return (m_device_factory.find(name) != m_device_factory.end());
+ for (auto &d : m_device_factory)
+ if (d.first == name)
+ return true;
+ return false;
}
@@ -398,7 +405,7 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(detail::core_terminal_t &out)
{
nl_assert(out.is_logic());
- logic_output_t &out_cast = static_cast<logic_output_t &>(out);
+ auto &out_cast = static_cast<logic_output_t &>(out);
devices::nld_base_proxy *proxy = out_cast.get_proxy();
if (proxy == nullptr)
@@ -424,7 +431,7 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(detail::core_terminal_t &out)
proxy = new_proxy.get();
- m_netlist.nlstate().add_dev(std::move(new_proxy));
+ m_netlist.nlstate().add_dev(new_proxy->name(), std::move(new_proxy));
}
return proxy;
}
@@ -433,7 +440,7 @@ devices::nld_base_proxy *setup_t::get_a_d_proxy(detail::core_terminal_t &inp)
{
nl_assert(inp.is_logic());
- logic_input_t &incast = dynamic_cast<logic_input_t &>(inp);
+ auto &incast = dynamic_cast<logic_input_t &>(inp);
devices::nld_base_proxy *proxy = incast.get_proxy();
if (proxy != nullptr)
@@ -463,7 +470,7 @@ devices::nld_base_proxy *setup_t::get_a_d_proxy(detail::core_terminal_t &inp)
inp.net().m_core_terms.clear(); // clear the list
}
ret->out().net().add_terminal(inp);
- m_netlist.nlstate().add_dev(std::move(new_proxy));
+ m_netlist.nlstate().add_dev(new_proxy->name(), std::move(new_proxy));
return ret;
}
}
@@ -598,7 +605,7 @@ static detail::core_terminal_t &resolve_proxy(detail::core_terminal_t &term)
{
if (term.is_logic())
{
- logic_t &out = dynamic_cast<logic_t &>(term);
+ auto &out = dynamic_cast<logic_t &>(term);
if (out.has_proxy())
return out.get_proxy()->proxy_term();
}
@@ -765,7 +772,7 @@ void setup_t::register_dynamic_log_devices()
auto nc = factory().factory_by_name("LOG")->Create(netlist(), name);
register_link(name + ".I", ll);
log().debug(" dynamic link {1}: <{2}>\n",ll, name);
- m_netlist.nlstate().add_dev(std::move(nc));
+ m_netlist.nlstate().add_dev(nc->name(), std::move(nc));
}
}
}
@@ -858,7 +865,7 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity)
{
pstring tmp = model_value_str(map, entity);
- nl_double factor = NL_FCONST(1.0);
+ nl_double factor = plib::constants<nl_double>::one;
auto p = std::next(tmp.begin(), static_cast<pstring::difference_type>(tmp.size() - 1));
switch (*p)
{
@@ -874,7 +881,7 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity)
if (*p < '0' || *p > '9')
log().fatal(MF_1_UNKNOWN_NUMBER_FACTOR_IN_1, entity);
}
- if (factor != NL_FCONST(1.0))
+ if (factor != plib::constants<nl_double>::one)
tmp = plib::left(tmp, tmp.size() - 1);
// FIXME: check for errors
return plib::pstonum<nl_double>(tmp) * factor;
@@ -883,10 +890,10 @@ nl_double setup_t::model_value(detail::model_map_t &map, const pstring &entity)
class logic_family_std_proxy_t : public logic_family_desc_t
{
public:
- logic_family_std_proxy_t() { }
- virtual plib::owned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_base_t &anetlist,
+ logic_family_std_proxy_t() = default;
+ plib::owned_ptr<devices::nld_base_d_to_a_proxy> create_d_a_proxy(netlist_base_t &anetlist,
const pstring &name, logic_output_t *proxied) const override;
- virtual plib::owned_ptr<devices::nld_base_a_to_d_proxy> create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override;
+ plib::owned_ptr<devices::nld_base_a_to_d_proxy> create_a_d_proxy(netlist_base_t &anetlist, const pstring &name, logic_input_t *proxied) const override;
};
plib::owned_ptr<devices::nld_base_d_to_a_proxy> logic_family_std_proxy_t::create_d_a_proxy(netlist_base_t &anetlist,
@@ -1017,8 +1024,7 @@ void setup_t::prepare_to_run()
if ( factory().is_class<devices::NETLIB_NAME(solver)>(e.second)
|| factory().is_class<devices::NETLIB_NAME(netlistparams)>(e.second))
{
- auto dev = plib::owned_ptr<device_t>(e.second->Create(netlist(), e.first));
- m_netlist.nlstate().add_dev(std::move(dev));
+ m_netlist.nlstate().add_dev(e.first, plib::owned_ptr<device_t>(e.second->Create(netlist(), e.first)));
}
}
@@ -1036,7 +1042,22 @@ void setup_t::prepare_to_run()
&& !factory().is_class<devices::NETLIB_NAME(netlistparams)>(e.second))
{
auto dev = plib::owned_ptr<device_t>(e.second->Create(netlist(), e.first));
- m_netlist.nlstate().add_dev(std::move(dev));
+ m_netlist.nlstate().add_dev(dev->name(), std::move(dev));
+ }
+ }
+
+ log().debug("Looking for unknown parameters ...\n");
+ for (auto &p : m_param_values)
+ {
+ auto f = m_params.find(p.first);
+ if (f == m_params.end())
+ {
+ if (plib::endsWith(p.first, pstring(".HINT_NO_DEACTIVATE")))
+ {
+ // FIXME: get device name, check for device
+ }
+ else
+ log().info("Unknown parameter: {}", p.first);
}
}
@@ -1046,18 +1067,18 @@ void setup_t::prepare_to_run()
{
if (use_deactivate)
{
- auto p = m_param_values.find(d->name() + ".HINT_NO_DEACTIVATE");
+ auto p = m_param_values.find(d.second->name() + ".HINT_NO_DEACTIVATE");
if (p != m_param_values.end())
{
//FIXME: check for errors ...
- double v = plib::pstonum<double>(p->second);
+ auto v = plib::pstonum<double>(p->second);
if (std::abs(v - std::floor(v)) > 1e-6 )
log().fatal(MF_1_HND_VAL_NOT_SUPPORTED, p->second);
- d->set_hint_deactivate(v == 0.0);
+ d.second->set_hint_deactivate(v == 0.0);
}
}
else
- d->set_hint_deactivate(false);
+ d.second->set_hint_deactivate(false);
}
/* resolve inputs */
@@ -1113,16 +1134,19 @@ bool source_t::parse(const pstring &name)
std::unique_ptr<plib::pistream> source_string_t::stream(const pstring &name)
{
+ plib::unused_var(name);
return plib::make_unique_base<plib::pistream, plib::pimemstream>(m_str.c_str(), std::strlen(m_str.c_str()));
}
std::unique_ptr<plib::pistream> source_mem_t::stream(const pstring &name)
{
+ plib::unused_var(name);
return plib::make_unique_base<plib::pistream, plib::pimemstream>(m_str.c_str(), std::strlen(m_str.c_str()));
}
std::unique_ptr<plib::pistream> source_file_t::stream(const pstring &name)
{
+ plib::unused_var(name);
return plib::make_unique_base<plib::pistream, plib::pifilestream>(m_filename);
}
@@ -1139,9 +1163,10 @@ bool source_proc_t::parse(const pstring &name)
std::unique_ptr<plib::pistream> source_proc_t::stream(const pstring &name)
{
+ plib::unused_var(name);
std::unique_ptr<plib::pistream> p(nullptr);
return p;
}
-}
+} // namespace netlist
diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h
index d0a5c002928..971f8d2e91d 100644
--- a/src/lib/netlist/nl_setup.h
+++ b/src/lib/netlist/nl_setup.h
@@ -8,20 +8,20 @@
#ifndef NLSETUP_H_
#define NLSETUP_H_
-#include "plib/pstring.h"
-#include "plib/putil.h"
-#include "plib/pstream.h"
#include "plib/pparser.h"
#include "plib/pstate.h"
+#include "plib/pstream.h"
+#include "plib/pstring.h"
+#include "plib/putil.h"
-#include "nl_factory.h"
-#include "nl_config.h"
#include "netlist_types.h"
+#include "nl_config.h"
#include "nl_errstr.h"
+#include "nl_factory.h"
+#include <memory>
#include <stack>
#include <vector>
-#include <memory>
//============================================================
// MACROS / inline netlist definitions
@@ -100,10 +100,10 @@ void NETLIST_NAME(name)(netlist::setup_t &setup) \
desc.family = "";
#define TT_HEAD(x) \
- desc.desc.push_back(x);
+ desc.desc.emplace_back(x);
#define TT_LINE(x) \
- desc.desc.push_back(x);
+ desc.desc.emplace_back(x);
#define TT_FAMILY(x) \
desc.family = x;
@@ -119,12 +119,12 @@ namespace netlist
namespace detail {
class core_terminal_t;
class net_t;
- }
+ } // namespace detail
namespace devices {
class nld_base_proxy;
class nld_netlistparams;
- }
+ } // namespace devices
class core_device_t;
class param_t;
@@ -187,7 +187,7 @@ namespace netlist
: m_setup(setup), m_type(type)
{}
- virtual ~source_t() { }
+ virtual ~source_t() = default;
virtual bool parse(const pstring &name);
setup_t &setup() { return m_setup; }
@@ -339,8 +339,9 @@ namespace netlist
devices::nld_base_proxy *get_d_a_proxy(detail::core_terminal_t &out);
devices::nld_base_proxy *get_a_d_proxy(detail::core_terminal_t &inp);
- //std::vector<std::pair<pstring, factory::element_t *>> m_device_factory;
- std::unordered_map<pstring, factory::element_t *> m_device_factory;
+ /* need to preserve order of device creation ... */
+ 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;
@@ -376,7 +377,7 @@ namespace netlist
}
protected:
- virtual std::unique_ptr<plib::pistream> stream(const pstring &name) override;
+ std::unique_ptr<plib::pistream> stream(const pstring &name) override;
private:
pstring m_str;
@@ -392,7 +393,7 @@ namespace netlist
}
protected:
- virtual std::unique_ptr<plib::pistream> stream(const pstring &name) override;
+ std::unique_ptr<plib::pistream> stream(const pstring &name) override;
private:
pstring m_filename;
@@ -407,7 +408,7 @@ namespace netlist
}
protected:
- virtual std::unique_ptr<plib::pistream> stream(const pstring &name) override;
+ std::unique_ptr<plib::pistream> stream(const pstring &name) override;
private:
pstring m_str;
@@ -423,10 +424,10 @@ namespace netlist
{
}
- virtual bool parse(const pstring &name) override;
+ bool parse(const pstring &name) override;
protected:
- virtual std::unique_ptr<plib::pistream> stream(const pstring &name) override;
+ std::unique_ptr<plib::pistream> stream(const pstring &name) override;
private:
void (*m_setup_func)(setup_t &);
@@ -437,7 +438,7 @@ namespace netlist
// inline implementations
// -----------------------------------------------------------------------------
-}
+} // namespace netlist
#endif /* NLSETUP_H_ */
diff --git a/src/lib/netlist/nl_time.h b/src/lib/netlist/nl_time.h
index b8ed1bb5a33..76e572a4772 100644
--- a/src/lib/netlist/nl_time.h
+++ b/src/lib/netlist/nl_time.h
@@ -8,33 +8,25 @@
#define NLTIME_H_
#include "nl_config.h"
-#include "plib/ptypes.h"
#include "plib/pstate.h"
+#include "plib/ptypes.h"
#include <cstdint>
-//============================================================
-// MACROS
-//============================================================
-
-#define NLTIME_FROM_NS(t) netlist_time::from_nsec(t)
-#define NLTIME_FROM_US(t) netlist_time::from_usec(t)
-#define NLTIME_FROM_MS(t) netlist_time::from_msec(t)
-#define NLTIME_IMMEDIATE netlist_time::from_nsec(1)
-
// ----------------------------------------------------------------------------------------
// netlist_time
// ----------------------------------------------------------------------------------------
namespace netlist
{
+
template <typename TYPE, TYPE RES>
struct ptime final
{
public:
using internal_type = TYPE;
- using mult_type = std::uint64_t;
+ using mult_type = TYPE;
constexpr ptime() noexcept : m_time(0) {}
@@ -114,8 +106,9 @@ namespace netlist
C14CONSTEXPR internal_type *get_internaltype_ptr() noexcept { return &m_time; }
static constexpr ptime from_nsec(const internal_type ns) noexcept { return ptime(ns, UINT64_C(1000000000)); }
- static constexpr ptime from_usec(const internal_type us) noexcept { return ptime(us, UINT64_C(1000000)); }
- static constexpr ptime from_msec(const internal_type ms) noexcept { return ptime(ms, UINT64_C(1000)); }
+ static constexpr ptime from_usec(const internal_type us) noexcept { return ptime(us, UINT64_C( 1000000)); }
+ static constexpr ptime from_msec(const internal_type ms) noexcept { return ptime(ms, UINT64_C( 1000)); }
+ static constexpr ptime from_sec(const internal_type s) noexcept { return ptime(s, UINT64_C( 1)); }
static constexpr ptime from_hz(const internal_type hz) noexcept { return ptime(1 , hz); }
static constexpr ptime from_raw(const internal_type raw) noexcept { return ptime(raw); }
static constexpr ptime from_double(const double t) noexcept { return ptime(static_cast<internal_type>( t * static_cast<double>(RES)), RES); }
@@ -125,6 +118,11 @@ namespace netlist
static constexpr ptime never() noexcept { return ptime(plib::numeric_limits<internal_type>::max(), RES); }
static constexpr internal_type resolution() noexcept { return RES; }
+ constexpr internal_type in_nsec() const noexcept { return m_time / (RES / UINT64_C(1000000000)); }
+ constexpr internal_type in_usec() const noexcept { return m_time / (RES / UINT64_C( 1000000)); }
+ constexpr internal_type in_msec() const noexcept { return m_time / (RES / UINT64_C( 1000)); }
+ constexpr internal_type in_sec() const noexcept { return m_time / (RES / UINT64_C( 1)); }
+
private:
static constexpr const double inv_res = 1.0 / static_cast<double>(RES);
internal_type m_time;
@@ -133,16 +131,26 @@ namespace netlist
#if (PHAS_INT128)
using netlist_time = ptime<UINT128, NETLIST_INTERNAL_RES>;
#else
- using netlist_time = ptime<std::uint64_t, NETLIST_INTERNAL_RES>;
+ using netlist_time = ptime<std::int64_t, NETLIST_INTERNAL_RES>;
static_assert(noexcept(netlist_time::from_nsec(1)) == true, "Not evaluated as constexpr");
#endif
-}
+
+ //============================================================
+ // MACROS
+ //============================================================
+
+ template <typename T> inline constexpr netlist_time NLTIME_FROM_NS(T &&t) { return netlist_time::from_nsec(t); }
+ template <typename T> inline constexpr netlist_time NLTIME_FROM_US(T &&t) { return netlist_time::from_usec(t); }
+ template <typename T> inline constexpr netlist_time NLTIME_FROM_MS(T &&t) { return netlist_time::from_msec(t); }
+
+} // namespace netlist
namespace plib {
-template<> inline void state_manager_t::save_item(const void *owner, netlist::netlist_time &nlt, const pstring &stname)
-{
- save_state_ptr(owner, stname, datatype_t(sizeof(netlist::netlist_time::internal_type), true, false), 1, nlt.get_internaltype_ptr());
-}
-}
+
+ template<> inline void state_manager_t::save_item(const void *owner, netlist::netlist_time &nlt, const pstring &stname)
+ {
+ save_state_ptr(owner, stname, datatype_t(sizeof(netlist::netlist_time::internal_type), true, false), 1, nlt.get_internaltype_ptr());
+ }
+} // namespace plib
#endif /* NLTIME_H_ */
diff --git a/src/lib/netlist/plib/gmres.h b/src/lib/netlist/plib/gmres.h
index edda011dc19..352ce721722 100644
--- a/src/lib/netlist/plib/gmres.h
+++ b/src/lib/netlist/plib/gmres.h
@@ -8,9 +8,9 @@
#ifndef PLIB_GMRES_H_
#define PLIB_GMRES_H_
-#include "pconfig.h"
#include "mat_cr.h"
#include "parray.h"
+#include "pconfig.h"
#include "vector_ops.h"
#include <algorithm>
@@ -246,13 +246,13 @@ namespace plib
if (rho < rho_delta)
return itr_used + 1;
- vec_set_scalar(RESTART+1, m_g, NL_FCONST(0.0));
+ vec_set_scalar(RESTART+1, m_g, constants<FT>::zero);
m_g[0] = rho;
//for (std::size_t i = 0; i < mr + 1; i++)
// vec_set_scalar(mr, m_ht[i], NL_FCONST(0.0));
- vec_mult_scalar(n, residual, NL_FCONST(1.0) / rho, m_v[0]);
+ vec_mult_scalar(n, residual, constants<FT>::one / rho, m_v[0]);
for (std::size_t k = 0; k < RESTART; k++)
{
@@ -269,7 +269,7 @@ namespace plib
m_ht[kp1][k] = std::sqrt(vec_mult2<FT>(n, m_v[kp1]));
if (m_ht[kp1][k] != 0.0)
- vec_scale(n, m_v[kp1], NL_FCONST(1.0) / m_ht[kp1][k]);
+ vec_scale(n, m_v[kp1], constants<FT>::one / m_ht[kp1][k]);
for (std::size_t j = 0; j < k; j++)
givens_mult(m_c[j], m_s[j], m_ht[j][k], m_ht[j+1][k]);
diff --git a/src/lib/netlist/plib/mat_cr.h b/src/lib/netlist/plib/mat_cr.h
index 9490a07f367..7bb81e3c8e4 100644
--- a/src/lib/netlist/plib/mat_cr.h
+++ b/src/lib/netlist/plib/mat_cr.h
@@ -11,16 +11,18 @@
#define MAT_CR_H_
#include <algorithm>
-#include <type_traits>
#include <array>
-#include <vector>
#include <cmath>
#include <cstdlib>
+#include <type_traits>
+#include <vector>
-#include "pconfig.h"
#include "palloc.h"
-#include "pstate.h"
#include "parray.h"
+#include "pconfig.h"
+#include "pomp.h"
+#include "pstate.h"
+#include "putil.h"
namespace plib
{
@@ -62,9 +64,7 @@ namespace plib
A[i] = 0;
}
- ~matrix_compressed_rows_t()
- {
- }
+ ~matrix_compressed_rows_t() = default;
index_type size() const { return m_size; }
@@ -285,7 +285,7 @@ namespace plib
template <typename VTV, typename VTR>
- void mult_vec(VTR & RESTRICT res, const VTV & RESTRICT x)
+ void mult_vec(VTR & res, const VTV & x)
{
/*
* res = A * x
@@ -513,6 +513,6 @@ namespace plib
index_type m_size;
};
-}
+} // namespace plib
#endif /* MAT_CR_H_ */
diff --git a/src/lib/netlist/plib/palloc.cpp b/src/lib/netlist/plib/palloc.cpp
index 80fd2098a66..ab5b14d0618 100644
--- a/src/lib/netlist/plib/palloc.cpp
+++ b/src/lib/netlist/plib/palloc.cpp
@@ -7,8 +7,8 @@
#include "pconfig.h"
#include "palloc.h"
-#include "pfmtlog.h"
#include "pexception.h"
+#include "pfmtlog.h"
#include <algorithm>
@@ -37,7 +37,7 @@ mempool::~mempool()
mempool::block * mempool::new_block()
{
- block *b = new block();
+ auto *b = new block();
b->data = static_cast<char *>(::operator new(m_min_alloc));
b->cur_ptr = b->data;
b->m_free = m_min_alloc;
@@ -92,7 +92,7 @@ void mempool::free(void *ptr)
auto i = reinterpret_cast<info *>(p - mininfosize());
block *b = i->m_block;
if (b->m_num_alloc == 0)
- plib::pexception("mempool::free - double free was called\n");
+ throw plib::pexception("mempool::free - double free was called\n");
else
{
//b->m_free = m_min_alloc;
@@ -101,4 +101,4 @@ void mempool::free(void *ptr)
b->m_num_alloc--;
}
-}
+} // namespace plib
diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h
index de992b7bc50..e8d82277ed9 100644
--- a/src/lib/netlist/plib/palloc.h
+++ b/src/lib/netlist/plib/palloc.h
@@ -111,7 +111,7 @@ public:
static owned_ptr Create(Args&&... args)
{
owned_ptr a;
- DC *x = new DC(std::forward<Args>(args)...);
+ auto *x = new DC(std::forward<Args>(args)...);
a.m_ptr = static_cast<SC *>(x);
return std::move(a);
}
@@ -176,6 +176,6 @@ public:
};
-}
+} // namespace plib
#endif /* PALLOC_H_ */
diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h
index df3f85ea927..6fc9cc430b2 100644
--- a/src/lib/netlist/plib/parray.h
+++ b/src/lib/netlist/plib/parray.h
@@ -11,11 +11,11 @@
#include "pconfig.h"
#include "pexception.h"
+#include <array>
#include <memory>
+#include <type_traits>
#include <utility>
#include <vector>
-#include <array>
-#include <type_traits>
namespace plib {
@@ -112,6 +112,6 @@ namespace plib {
base_type m_a;
size_type m_size;
};
-}
+} // namespace plib
#endif /* PARRAY_H_ */
diff --git a/src/lib/netlist/plib/pchrono.cpp b/src/lib/netlist/plib/pchrono.cpp
index 971d19b3645..953d948e062 100644
--- a/src/lib/netlist/plib/pchrono.cpp
+++ b/src/lib/netlist/plib/pchrono.cpp
@@ -49,5 +49,5 @@ exact_ticks::type exact_ticks::per_second()
#endif
-}
-}
+} // namespace chrono
+} // namespace plib
diff --git a/src/lib/netlist/plib/pchrono.h b/src/lib/netlist/plib/pchrono.h
index c3ea4ba9535..76f18bf4a83 100644
--- a/src/lib/netlist/plib/pchrono.h
+++ b/src/lib/netlist/plib/pchrono.h
@@ -10,8 +10,8 @@
#include "pconfig.h"
-#include <cstdint>
#include <chrono>
+#include <cstdint>
namespace plib {
namespace chrono {
@@ -174,7 +174,10 @@ namespace chrono {
struct guard_t
{
- guard_t(timer &m) : m_m(m) { m_m.m_time -= T::start();; }
+ guard_t() = delete;
+ guard_t(const guard_t &g) noexcept = default;
+ guard_t(guard_t &&g) noexcept = default;
+ guard_t(timer &m) noexcept : m_m(m) { m_m.m_time -= T::start(); }
~guard_t() { m_m.m_time += T::stop(); ++m_m.m_count; }
private:
timer &m_m;
@@ -208,8 +211,14 @@ namespace chrono {
struct guard_t
{
- guard_t() {}
- ~guard_t() {}
+ guard_t() = default;
+ guard_t(const guard_t &g) noexcept = default;
+ guard_t(guard_t &&g) noexcept = default;
+ /* using default constructor will trigger warning on
+ * unused local variable.
+ */
+ // NOLINTNEXTLINE(modernize-use-equals-default)
+ ~guard_t() { }
};
constexpr type operator()() const { return 0; }
diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h
index 731ae1f18fd..71a5f25e0e8 100644
--- a/src/lib/netlist/plib/pconfig.h
+++ b/src/lib/netlist/plib/pconfig.h
@@ -76,15 +76,6 @@ typedef __uint128_t UINT128;
typedef __int128_t INT128;
#endif
-#if defined(__GNUC__)
-#ifdef RESTRICT
-#undef RESTRICT
-#endif
-#define RESTRICT __restrict__
-#else
-#define RESTRICT
-#endif
-
//============================================================
// Standard defines
//============================================================
diff --git a/src/lib/netlist/plib/pdynlib.cpp b/src/lib/netlist/plib/pdynlib.cpp
index 13827eaf24c..f30ddc5d59a 100644
--- a/src/lib/netlist/plib/pdynlib.cpp
+++ b/src/lib/netlist/plib/pdynlib.cpp
@@ -91,6 +91,8 @@ dynlib::dynlib(const pstring libname)
dynlib::dynlib(const pstring path, const pstring libname)
: m_isLoaded(false), m_lib(nullptr)
{
+ // FIXME: implement path search
+ plib::unused_var(path);
// printf("win: loading <%s>\n", libname.c_str());
#ifdef _WIN32
TCHAR *buffer = tstring_from_utf8(libname.c_str());
@@ -148,4 +150,4 @@ void *dynlib::getsym_p(const pstring name)
#endif
}
-}
+} // namespace plib
diff --git a/src/lib/netlist/plib/pdynlib.h b/src/lib/netlist/plib/pdynlib.h
index 7c9412593c9..0ab498436b3 100644
--- a/src/lib/netlist/plib/pdynlib.h
+++ b/src/lib/netlist/plib/pdynlib.h
@@ -64,6 +64,6 @@ private:
calltype m_sym;
};
-}
+} // namespace plib
#endif /* PSTRING_H_ */
diff --git a/src/lib/netlist/plib/pexception.cpp b/src/lib/netlist/plib/pexception.cpp
index a4ed8f367e0..d26fc8fd12e 100644
--- a/src/lib/netlist/plib/pexception.cpp
+++ b/src/lib/netlist/plib/pexception.cpp
@@ -26,74 +26,48 @@ pexception::pexception(const pstring &text)
{
}
-pexception::~pexception() noexcept
-{
-}
file_e::file_e(const pstring &fmt, const pstring &filename)
: pexception(pfmt(fmt)(filename))
{
}
-file_e::~file_e() noexcept
-{
-}
file_open_e::file_open_e(const pstring &filename)
: file_e("File open failed: {}", filename)
{
}
-file_open_e::~file_open_e() noexcept
-{
-
-}
file_read_e::file_read_e(const pstring &filename)
: file_e("File read failed: {}", filename)
{
}
-file_read_e::~file_read_e() noexcept
-{
-
-}
file_write_e::file_write_e(const pstring &filename)
: file_e("File write failed: {}", filename)
{
}
-file_write_e::~file_write_e() noexcept
-{
-}
null_argument_e::null_argument_e(const pstring &argument)
: pexception(pfmt("Null argument passed: {}")(argument))
{
}
-null_argument_e::~null_argument_e() noexcept
-{
-}
out_of_mem_e::out_of_mem_e(const pstring &location)
: pexception(pfmt("Out of memory: {}")(location))
{
}
-out_of_mem_e::~out_of_mem_e() noexcept
-{
-}
fpexception_e::fpexception_e(const pstring &text)
: pexception(pfmt("Out of memory: {}")(text))
{
}
-fpexception_e::~fpexception_e() noexcept
-{
-}
bool fpsignalenabler::m_enable = false;
@@ -140,4 +114,4 @@ bool fpsignalenabler::global_enable(bool enable)
}
-}
+} // namespace plib
diff --git a/src/lib/netlist/plib/pexception.h b/src/lib/netlist/plib/pexception.h
index 1a5957099fd..7c798112c69 100644
--- a/src/lib/netlist/plib/pexception.h
+++ b/src/lib/netlist/plib/pexception.h
@@ -8,10 +8,11 @@
#ifndef PEXCEPTION_H_
#define PEXCEPTION_H_
-#include "pstring.h"
-
#include <exception>
+#include "pstring.h"
+#include "ptypes.h"
+
namespace plib {
//============================================================
// exception base
@@ -21,9 +22,6 @@ class pexception : public std::exception
{
public:
explicit pexception(const pstring &text);
- pexception(const pexception &e) : std::exception(e), m_text(e.m_text) { }
-
- virtual ~pexception() noexcept override;
const pstring &text() { return m_text; }
const char* what() const noexcept override { return m_text.c_str(); }
@@ -36,48 +34,36 @@ class file_e : public plib::pexception
{
public:
file_e(const pstring &fmt, const pstring &filename);
- file_e(const file_e &e) : pexception(e) { }
- virtual ~file_e() noexcept;
};
class file_open_e : public file_e
{
public:
explicit file_open_e(const pstring &filename);
- file_open_e(const file_open_e &e) : file_e(e) { }
- virtual ~file_open_e() noexcept;
};
class file_read_e : public file_e
{
public:
explicit file_read_e(const pstring &filename);
- file_read_e(const file_read_e &e) : file_e(e) { }
- virtual ~file_read_e() noexcept;
};
class file_write_e : public file_e
{
public:
explicit file_write_e(const pstring &filename);
- file_write_e(const file_write_e &e) : file_e(e) { }
- virtual ~file_write_e() noexcept;
};
class null_argument_e : public plib::pexception
{
public:
explicit null_argument_e(const pstring &argument);
- null_argument_e(const null_argument_e &e) : pexception(e) { }
- virtual ~null_argument_e() noexcept;
};
class out_of_mem_e : public plib::pexception
{
public:
explicit out_of_mem_e(const pstring &location);
- out_of_mem_e(const out_of_mem_e &e) : pexception(e) { }
- virtual ~out_of_mem_e() noexcept;
};
/* FIXME: currently only a stub for later use. More use could be added by
@@ -88,8 +74,6 @@ class fpexception_e : public pexception
{
public:
explicit fpexception_e(const pstring &text);
- fpexception_e(const fpexception_e &e) : pexception(e) { }
- virtual ~fpexception_e() noexcept;
};
static constexpr unsigned FP_INEXACT = 0x0001;
@@ -103,7 +87,7 @@ static constexpr unsigned FP_ALL = 0x0001f;
* Catch SIGFPE on linux for debugging purposes.
*/
-class fpsignalenabler
+class fpsignalenabler : public nocopyassignmove
{
public:
explicit fpsignalenabler(unsigned fpexceptions);
@@ -121,6 +105,6 @@ private:
};
-}
+} // namespace plib
#endif /* PEXCEPTION_H_ */
diff --git a/src/lib/netlist/plib/pfmtlog.cpp b/src/lib/netlist/plib/pfmtlog.cpp
index 2c120f6b7a4..f142a0cd73f 100644
--- a/src/lib/netlist/plib/pfmtlog.cpp
+++ b/src/lib/netlist/plib/pfmtlog.cpp
@@ -8,18 +8,19 @@
#include "pfmtlog.h"
#include "palloc.h"
-#include <cstring>
-#include <cstdlib>
-#include <cstdarg>
#include <algorithm>
-#include <locale>
+#include <cstdarg>
+#include <cstdlib>
+#include <cstring>
#include <iostream>
+#include <locale>
namespace plib {
pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...)
{
va_list ap;
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
va_start(ap, cfmt_spec);
pstring fmt("%");
char buf[2048]; // FIXME
@@ -87,4 +88,4 @@ pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...)
return *this;
}
-}
+} // namespace plib
diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h
index 9b7a85d8d8d..bf9d45fadd2 100644
--- a/src/lib/netlist/plib/pfmtlog.h
+++ b/src/lib/netlist/plib/pfmtlog.h
@@ -136,7 +136,6 @@ struct ptype_traits<double> : ptype_traits_base<double>
static char32_t fmt_spec() { return 'f'; }
};
-
template<>
struct ptype_traits<char *> : ptype_traits_base<char *>
{
@@ -144,6 +143,13 @@ struct ptype_traits<char *> : ptype_traits_base<char *>
static char32_t fmt_spec() { return 's'; }
};
+template<>
+struct ptype_traits<std::string> : ptype_traits_base<char *>
+{
+ static const char *cast(const std::string &x) { return x.c_str(); }
+ static char32_t fmt_spec() { return 's'; }
+};
+
class pfmt
{
public:
@@ -151,44 +157,50 @@ public:
: m_str(fmt), m_arg(0)
{
}
-
- pfmt(const pfmt &rhs) : m_str(rhs.m_str), m_arg(rhs.m_arg) { }
-
- ~pfmt()
- {
- }
+ pfmt(const pfmt &rhs) = default;
+ ~pfmt() = default;
operator pstring() const { return m_str; }
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
pfmt & e(const double &x) {return format_element("", 'e', x); }
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
pfmt & g(const double &x) {return format_element("", 'g', x); }
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
pfmt & e(const float &x) {return format_element("", 'e', static_cast<double>(x)); }
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
pfmt & g(const float &x) {return format_element("", 'g', static_cast<double>(x)); }
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
pfmt &operator ()(const void *x) {return format_element("", 'p', x); }
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
pfmt &operator ()(const pstring &x) {return format_element("", 's', x.c_str() ); }
template<typename T>
pfmt &operator ()(const T &x)
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
return format_element(ptype_traits<T>::size_spec(), ptype_traits<T>::fmt_spec(), ptype_traits<T>::cast(x));
}
template<typename T>
pfmt &operator ()(const T *x)
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
return format_element(ptype_traits<T *>::size_spec(), ptype_traits<T *>::fmt_spec(), ptype_traits<T *>::cast(x));
}
template<typename T>
pfmt &x(const T &x)
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
return format_element(ptype_traits<T>::size_spec(), 'x', x);
}
template<typename T>
pfmt &o(const T &x)
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
return format_element(ptype_traits<T>::size_spec(), 'o', x);
}
@@ -237,7 +249,7 @@ public:
bool is_enabled() const { return m_enabled; }
protected:
- ~pfmt_writer_t() { }
+ ~pfmt_writer_t() = default;
private:
pfmt &xlog(pfmt &fmt) const { return fmt; }
@@ -258,7 +270,7 @@ class plog_channel : public pfmt_writer_t<plog_channel<T, L, build_enabled>, bui
friend class pfmt_writer_t<plog_channel<T, L, build_enabled>, build_enabled>;
public:
explicit plog_channel(T &b) : pfmt_writer_t<plog_channel, build_enabled>(), m_base(b) { }
- ~plog_channel() { }
+ ~plog_channel() = default;
protected:
void vdowrite(const pstring &ls) const
@@ -283,7 +295,7 @@ public:
error(proxy),
fatal(proxy)
{}
- virtual ~plog_base() {}
+ virtual ~plog_base() = default;
plog_channel<T, plog_level::DEBUG, debug_enabled> debug;
plog_channel<T, plog_level::INFO> info;
@@ -293,7 +305,7 @@ public:
plog_channel<T, plog_level::FATAL> fatal;
};
-}
+} // namespace plib
template<typename T>
plib::pfmt& operator<<(plib::pfmt &p, T&& val) { return p(std::forward<T>(val)); }
diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp
index 3a1ef9d841b..fc8f7248470 100644
--- a/src/lib/netlist/plib/pfunction.cpp
+++ b/src/lib/netlist/plib/pfunction.cpp
@@ -6,9 +6,9 @@
*/
#include "pfunction.h"
+#include "pexception.h"
#include "pfmtlog.h"
#include "putil.h"
-#include "pexception.h"
#include <cmath>
#include <stack>
@@ -56,7 +56,7 @@ void pfunction::compile_postfix(const std::vector<pstring> &inputs,
{ rc.m_cmd = RAND; stk += 1; }
else
{
- for (unsigned i = 0; i < inputs.size(); i++)
+ for (std::size_t i = 0; i < inputs.size(); i++)
{
if (inputs[i] == cmd)
{
@@ -117,7 +117,7 @@ void pfunction::compile_infix(const std::vector<pstring> &inputs, const pstring
std::stack<pstring> opstk;
std::vector<pstring> postfix;
- for (unsigned i = 0; i < sexpr.size(); i++)
+ for (std::size_t i = 0; i < sexpr.size(); i++)
{
pstring &s = sexpr[i];
if (s=="(")
@@ -181,14 +181,15 @@ void pfunction::compile_infix(const std::vector<pstring> &inputs, const pstring
#define OP(OP, ADJ, EXPR) \
case OP: \
- ptr-=ADJ; \
- stack[ptr-1] = EXPR; \
+ ptr-= (ADJ); \
+ stack[ptr-1] = (EXPR); \
break;
double pfunction::evaluate(const std::vector<double> &values)
{
double stack[20];
unsigned ptr = 0;
+ stack[0] = 0.0;
for (auto &rc : m_precompiled)
{
switch (rc.m_cmd)
@@ -214,4 +215,4 @@ double pfunction::evaluate(const std::vector<double> &values)
return stack[ptr-1];
}
-}
+} // namespace plib
diff --git a/src/lib/netlist/plib/pfunction.h b/src/lib/netlist/plib/pfunction.h
index 7d5984f9d15..fbb6c508333 100644
--- a/src/lib/netlist/plib/pfunction.h
+++ b/src/lib/netlist/plib/pfunction.h
@@ -8,8 +8,8 @@
#ifndef PFUNCTION_H_
#define PFUNCTION_H_
-#include "pstring.h"
#include "pstate.h"
+#include "pstring.h"
#include <vector>
@@ -112,6 +112,6 @@ namespace plib {
};
-}
+} // namespace plib
#endif /* PEXCEPTION_H_ */
diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h
index 19e65cb7cdc..3ba7dd2fb4f 100644
--- a/src/lib/netlist/plib/plists.h
+++ b/src/lib/netlist/plib/plists.h
@@ -32,9 +32,7 @@ public:
typedef C* iterator;
typedef const C* const_iterator;
- uninitialised_array_t()
- {
- }
+ uninitialised_array_t() = default;
~uninitialised_array_t()
{
@@ -202,8 +200,8 @@ public:
explicit constexpr iter_t(LC* x) noexcept : p(x) { }
explicit constexpr iter_t(iter_t &rhs) noexcept : p(rhs.p) { }
iter_t(iter_t &&rhs) noexcept { std::swap(*this, rhs); }
- iter_t& operator=(iter_t &rhs) { iter_t t(rhs); std::swap(*this, t); return *this; }
- iter_t& operator=(iter_t &&rhs) { std::swap(*this, rhs); return *this; }
+ iter_t& operator=(const iter_t &rhs) { iter_t t(rhs); std::swap(*this, t); return *this; }
+ iter_t& operator=(iter_t &&rhs) noexcept { std::swap(*this, rhs); return *this; }
iter_t& operator++() noexcept {p = p->next();return *this;}
iter_t operator++(int) noexcept {iter_t tmp(*this); operator++(); return tmp;}
constexpr bool operator==(const iter_t& rhs) const noexcept {return p == rhs.p;}
@@ -265,6 +263,6 @@ private:
LC *m_head;
};
#endif
-}
+} // namespace plib
#endif /* PLISTS_H_ */
diff --git a/src/lib/netlist/plib/pmain.cpp b/src/lib/netlist/plib/pmain.cpp
index 30b4a1948bd..25022ed9734 100644
--- a/src/lib/netlist/plib/pmain.cpp
+++ b/src/lib/netlist/plib/pmain.cpp
@@ -43,11 +43,6 @@ namespace plib {
}
- app::~app()
- {
-
- }
-
int app::main_utfX(int argc, char *argv[])
{
auto r = this->parse(argc, argv);
diff --git a/src/lib/netlist/plib/pmain.h b/src/lib/netlist/plib/pmain.h
index e2f84b90de6..78e5213713f 100644
--- a/src/lib/netlist/plib/pmain.h
+++ b/src/lib/netlist/plib/pmain.h
@@ -11,12 +11,12 @@
#define PMAIN_H_
#include "poptions.h"
+#include "pstream.h"
#include "pstring.h"
#include "putil.h"
-#include "pstream.h"
-#include <memory>
#include <cwchar>
+#include <memory>
#ifdef _WIN32
#define PMAIN(appclass) \
@@ -36,7 +36,7 @@ namespace plib {
{
public:
app();
- virtual ~app();
+ virtual ~app() = default;
virtual pstring usage() = 0;
virtual int execute() = 0;
@@ -62,7 +62,7 @@ namespace plib {
};
-}
+} // namespace plib
diff --git a/src/lib/netlist/plib/pomp.h b/src/lib/netlist/plib/pomp.h
index 19b39466025..d86326f4594 100644
--- a/src/lib/netlist/plib/pomp.h
+++ b/src/lib/netlist/plib/pomp.h
@@ -47,6 +47,8 @@ inline void set_num_threads(const std::size_t threads)
{
#if HAS_OPENMP && USE_OPENMP
omp_set_num_threads(threads);
+#else
+ plib::unused_var(threads);
#endif
}
@@ -64,7 +66,7 @@ inline std::size_t get_max_threads()
// pdynlib: dynamic loading of libraries ...
// ----------------------------------------------------------------------------------------
-}
-}
+} // namespace omp
+} // namespace plib
#endif /* PSTRING_H_ */
diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp
index dcb8e3931f3..84e08715ec3 100644
--- a/src/lib/netlist/plib/poptions.cpp
+++ b/src/lib/netlist/plib/poptions.cpp
@@ -6,8 +6,8 @@
*/
#include "poptions.h"
-#include "ptypes.h"
#include "pexception.h"
+#include "ptypes.h"
namespace plib {
/***************************************************************************
@@ -20,28 +20,12 @@ namespace plib {
parent.register_option(this);
}
- option_base::~option_base()
- {
- }
-
- option_group::~option_group()
- {
- }
-
- option_example::~option_example()
- {
- }
-
option::option(options &parent, pstring ashort, pstring along, pstring help, bool has_argument)
: option_base(parent, help), m_short(ashort), m_long(along),
m_has_argument(has_argument), m_specified(false)
{
}
- option::~option()
- {
- }
-
int option_str::parse(const pstring &argument)
{
m_val = argument;
@@ -92,12 +76,12 @@ namespace plib {
{
for (auto &opt : m_opts)
{
- option *o = dynamic_cast<option *>(opt);
+ auto *o = dynamic_cast<option *>(opt);
if (o != nullptr)
{
if (o->short_opt() == "" && o->long_opt() == "")
{
- option_args *ov = dynamic_cast<option_args *>(o);
+ auto *ov = dynamic_cast<option_args *>(o);
if (ov != nullptr)
{
if (m_other_args != nullptr)
@@ -247,7 +231,7 @@ namespace plib {
if (opt->has_argument())
{
line += "=";
- option_str_limit_base *ol = dynamic_cast<option_str_limit_base *>(opt);
+ auto *ol = dynamic_cast<option_str_limit_base *>(opt);
if (ol)
{
for (auto &v : ol->limit())
diff --git a/src/lib/netlist/plib/poptions.h b/src/lib/netlist/plib/poptions.h
index 925329e80d4..d34dc4935ba 100644
--- a/src/lib/netlist/plib/poptions.h
+++ b/src/lib/netlist/plib/poptions.h
@@ -10,8 +10,8 @@
#ifndef POPTIONS_H_
#define POPTIONS_H_
-#include "pstring.h"
#include "plists.h"
+#include "pstring.h"
#include "putil.h"
namespace plib {
@@ -25,7 +25,7 @@ class option_base
{
public:
option_base(options &parent, pstring help);
- virtual ~option_base();
+ virtual ~option_base() = default;
pstring help() const { return m_help; }
private:
@@ -37,7 +37,6 @@ class option_group : public option_base
public:
option_group(options &parent, pstring group, pstring help)
: option_base(parent, help), m_group(group) { }
- ~option_group();
pstring group() const { return m_group; }
private:
@@ -49,7 +48,6 @@ class option_example : public option_base
public:
option_example(options &parent, pstring group, pstring help)
: option_base(parent, help), m_example(group) { }
- ~option_example();
pstring example() const { return m_example; }
private:
@@ -61,7 +59,6 @@ class option : public option_base
{
public:
option(options &parent, pstring ashort, pstring along, pstring help, bool has_argument);
- ~option();
/* no_argument options will be called with "" argument */
@@ -96,7 +93,7 @@ public:
pstring operator ()() const { return m_val; }
protected:
- virtual int parse(const pstring &argument) override;
+ int parse(const pstring &argument) override;
private:
pstring m_val;
@@ -133,7 +130,7 @@ public:
pstring as_string() const { return limit()[m_val]; }
protected:
- virtual int parse(const pstring &argument) override
+ int parse(const pstring &argument) override
{
auto raw = plib::container::indexof(limit(), argument);
@@ -160,7 +157,7 @@ public:
bool operator ()() const { return m_val; }
protected:
- virtual int parse(const pstring &argument) override;
+ int parse(const pstring &argument) override;
private:
bool m_val;
@@ -183,7 +180,7 @@ public:
T operator ()() const { return m_val; }
protected:
- virtual int parse(const pstring &argument) override
+ int parse(const pstring &argument) override
{
bool err;
m_val = pstonum_ne<T>(argument, err);
@@ -206,7 +203,7 @@ public:
const std::vector<pstring> &operator ()() const { return m_val; }
protected:
- virtual int parse(const pstring &argument) override;
+ int parse(const pstring &argument) override;
private:
std::vector<pstring> m_val;
@@ -262,6 +259,6 @@ private:
option_args * m_other_args;
};
-}
+} // namespace plib
#endif /* POPTIONS_H_ */
diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp
index d666ad11054..d0c7ea5d960 100644
--- a/src/lib/netlist/plib/pparser.cpp
+++ b/src/lib/netlist/plib/pparser.cpp
@@ -16,11 +16,6 @@ namespace plib {
// A simple tokenizer
// ----------------------------------------------------------------------------------------
-ptokenizer::~ptokenizer()
-{
-}
-
-
pstring ptokenizer::currentline_str()
{
return m_cur_line;
@@ -126,7 +121,7 @@ double ptokenizer::get_number_double()
error(pfmt("Expected a number, got <{1}>")(tok.str()) );
}
bool err;
- double ret = plib::pstonum_ne<double>(tok.str(), err);
+ auto ret = plib::pstonum_ne<double>(tok.str(), err);
if (err)
error(pfmt("Expected a number, got <{1}>")(tok.str()) );
return ret;
@@ -140,7 +135,7 @@ long ptokenizer::get_number_long()
error(pfmt("Expected a long int, got <{1}>")(tok.str()) );
}
bool err;
- long ret = plib::pstonum_ne<long>(tok.str(), err);
+ auto ret = plib::pstonum_ne<long>(tok.str(), err);
if (err)
error(pfmt("Expected a long int, got <{1}>")(tok.str()) );
return ret;
@@ -277,18 +272,18 @@ ppreprocessor::ppreprocessor(defines_map_type *defines)
, m_state(PROCESS)
, m_comment(false)
{
- m_expr_sep.push_back("!");
- m_expr_sep.push_back("(");
- m_expr_sep.push_back(")");
- m_expr_sep.push_back("+");
- m_expr_sep.push_back("-");
- m_expr_sep.push_back("*");
- m_expr_sep.push_back("/");
- m_expr_sep.push_back("&&");
- m_expr_sep.push_back("||");
- m_expr_sep.push_back("==");
- m_expr_sep.push_back(" ");
- m_expr_sep.push_back("\t");
+ m_expr_sep.emplace_back("!");
+ m_expr_sep.emplace_back("(");
+ m_expr_sep.emplace_back(")");
+ m_expr_sep.emplace_back("+");
+ m_expr_sep.emplace_back("-");
+ m_expr_sep.emplace_back("*");
+ m_expr_sep.emplace_back("/");
+ m_expr_sep.emplace_back("&&");
+ m_expr_sep.emplace_back("||");
+ m_expr_sep.emplace_back("==");
+ m_expr_sep.emplace_back(" ");
+ m_expr_sep.emplace_back("\t");
m_defines.insert({"__PLIB_PREPROCESSOR__", define_t("__PLIB_PREPROCESSOR__", "1")});
if (defines != nullptr)
@@ -315,10 +310,10 @@ pstream::size_type ppreprocessor::vread(value_type *buf, const pstream::size_typ
#define CHECKTOK2(p_op, p_prio) \
else if (tok == # p_op) \
{ \
- if (prio < p_prio) \
+ if (prio < (p_prio)) \
return val; \
start++; \
- const auto v2 = expr(sexpr, start, p_prio); \
+ const auto v2 = expr(sexpr, start, (p_prio)); \
val = (val p_op v2); \
} \
@@ -389,9 +384,9 @@ pstring ppreprocessor::replace_macros(const pstring &line)
static pstring catremainder(const std::vector<pstring> &elems, std::size_t start, pstring sep)
{
pstring ret("");
- for (auto & elem : elems)
+ for (std::size_t i = start; i < elems.size(); i++)
{
- ret += elem;
+ ret += elems[i];
ret += sep;
}
return ret;
@@ -472,7 +467,7 @@ pstring ppreprocessor::process_line(pstring line)
std::size_t start = 0;
lt = replace_macros(lt);
std::vector<pstring> t(psplit(replace_all(lt.substr(3), pstring(" "), pstring("")), m_expr_sep));
- int val = static_cast<int>(expr(t, start, 255));
+ auto val = static_cast<int>(expr(t, start, 255));
if (val == 0)
m_ifflag |= (1 << m_level);
}
@@ -535,4 +530,4 @@ pstring ppreprocessor::process_line(pstring line)
-}
+} // namespace plib
diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h
index 3829e8cdcc8..9b68a5524f1 100644
--- a/src/lib/netlist/plib/pparser.h
+++ b/src/lib/netlist/plib/pparser.h
@@ -8,24 +8,25 @@
#ifndef PPARSER_H_
#define PPARSER_H_
-#include "pstring.h"
+#include <cstdint>
+#include <unordered_map>
+
#include "plists.h"
#include "pstream.h"
+#include "pstring.h"
-#include <unordered_map>
-#include <cstdint>
namespace plib {
-class ptokenizer : nocopyassignmove
+class ptokenizer : public nocopyassignmove
{
public:
template <typename T>
- ptokenizer(T &&strm)
- : m_strm(std::move(strm)), m_lineno(0), m_cur_line(""), m_px(m_cur_line.begin()), m_unget(0), m_string('"')
+ ptokenizer(T &&strm) // NOLINT(misc-forwarding-reference-overload, bugprone-forwarding-reference-overload)
+ : m_strm(std::forward<T>(strm)), m_lineno(0), m_cur_line(""), m_px(m_cur_line.begin()), m_unget(0), m_string('"')
{
}
- virtual ~ptokenizer();
+ virtual ~ptokenizer() = default;
enum token_type
{
@@ -166,12 +167,12 @@ public:
using defines_map_type = std::unordered_map<pstring, define_t>;
explicit ppreprocessor(defines_map_type *defines = nullptr);
- virtual ~ppreprocessor() override {}
+ ~ppreprocessor() override = default;
template <typename T>
ppreprocessor & process(T &&istrm)
{
- putf8_reader reader(std::move(istrm));
+ putf8_reader reader(std::forward<T>(istrm));
pstring line;
while (reader.readline(line))
{
@@ -182,13 +183,13 @@ public:
return *this;
}
- ppreprocessor(ppreprocessor &&s)
- : m_defines(s.m_defines)
- , m_expr_sep(s.m_expr_sep)
+ ppreprocessor(ppreprocessor &&s) noexcept
+ : m_defines(std::move(s.m_defines))
+ , m_expr_sep(std::move(s.m_expr_sep))
, m_ifflag(s.m_ifflag)
, m_level(s.m_level)
, m_lineno(s.m_lineno)
- , m_buf(s.m_buf)
+ , m_buf(std::move(s.m_buf))
, m_pos(s.m_pos)
, m_state(s.m_state)
, m_comment(s.m_comment)
@@ -197,9 +198,13 @@ public:
protected:
- virtual size_type vread(value_type *buf, const size_type n) override;
- virtual void vseek(const pos_type n) override { }
- virtual pos_type vtell() const override { return m_pos; }
+ size_type vread(value_type *buf, const size_type n) override;
+ void vseek(const pos_type n) override
+ {
+ plib::unused_var(n);
+ /* FIXME throw exception - should be done in base unless implemented */
+ }
+ pos_type vtell() const override { return m_pos; }
int expr(const std::vector<pstring> &sexpr, std::size_t &start, int prio);
define_t *get_define(const pstring &name);
@@ -229,6 +234,6 @@ private:
bool m_comment;
};
-}
+} // namespace plib
#endif /* PPARSER_H_ */
diff --git a/src/lib/netlist/plib/ppmf.h b/src/lib/netlist/plib/ppmf.h
index 4f0e8b7ba07..4dcceee454f 100644
--- a/src/lib/netlist/plib/ppmf.h
+++ b/src/lib/netlist/plib/ppmf.h
@@ -8,11 +8,10 @@
#ifndef PPMF_H_
#define PPMF_H_
-#include "pconfig.h"
-
-#include <utility>
#include <cstdint>
+#include <utility>
+#include "pconfig.h"
/*
*
@@ -70,7 +69,8 @@ namespace plib {
using generic_function = void (*)();
template<typename MemberFunctionType>
- mfp(MemberFunctionType mftp)
+ mfp(MemberFunctionType mftp) // NOLINT(cppcoreguidelines-pro-type-member-init)
+
: m_function(0), m_this_delta(0), m_size(sizeof(mfp))
{
*reinterpret_cast<MemberFunctionType *>(this) = mftp;
@@ -82,7 +82,7 @@ namespace plib {
mfp mfpo(mftp);
//return mfpo.update_after_bind<FunctionType>(object);
generic_function rfunc(nullptr);
- generic_class *robject = reinterpret_cast<generic_class *>(object);
+ auto robject = reinterpret_cast<generic_class *>(object);
mfpo.convert_to_generic(rfunc, robject);
func = reinterpret_cast<FunctionType>(rfunc);
object = reinterpret_cast<ObjectType *>(robject);
@@ -95,7 +95,7 @@ namespace plib {
if (PHAS_PMF_INTERNAL == 1)
{
// apply the "this" delta to the object first
- generic_class * o_p_delta = reinterpret_cast<generic_class *>(reinterpret_cast<std::uint8_t *>(object) + m_this_delta);
+ auto o_p_delta = reinterpret_cast<generic_class *>(reinterpret_cast<std::uint8_t *>(object) + m_this_delta);
// if the low bit of the vtable index is clear, then it is just a raw function pointer
if (!(m_function & 1))
@@ -274,6 +274,6 @@ namespace plib {
};
-}
+} // namespace plib
#endif /* PPMF_H_ */
diff --git a/src/lib/netlist/plib/pstate.cpp b/src/lib/netlist/plib/pstate.cpp
index a5465bfed46..14d0da3d374 100644
--- a/src/lib/netlist/plib/pstate.cpp
+++ b/src/lib/netlist/plib/pstate.cpp
@@ -9,17 +9,6 @@
#include "palloc.h"
namespace plib {
-state_manager_t::state_manager_t()
-{
-}
-
-state_manager_t::~state_manager_t()
-{
- m_save.clear();
- m_custom.clear();
-}
-
-
void state_manager_t::save_state_ptr(const void *owner, const pstring &stname, const datatype_t &dt, const std::size_t count, void *ptr)
{
@@ -65,9 +54,4 @@ template<> void state_manager_t::save_item(const void *owner, callback_t &state,
state.register_state(*this, stname);
}
-state_manager_t::callback_t::~callback_t()
-{
-}
-
-
-}
+} // namespace plib
diff --git a/src/lib/netlist/plib/pstate.h b/src/lib/netlist/plib/pstate.h
index 3a908cba2d2..19dbc03bc46 100644
--- a/src/lib/netlist/plib/pstate.h
+++ b/src/lib/netlist/plib/pstate.h
@@ -11,8 +11,8 @@
#include "pstring.h"
#include "ptypes.h"
-#include <vector>
#include <memory>
+#include <vector>
// ----------------------------------------------------------------------------------------
// state saving ...
@@ -38,22 +38,20 @@ public:
const bool is_custom;
};
- template<typename T> struct datatype_f
+ template<typename T>
+ static datatype_t dtype()
{
- static const datatype_t f()
- {
- return datatype_t(sizeof(T),
- plib::is_integral<T>::value || std::is_enum<T>::value,
- std::is_floating_point<T>::value);
- }
- };
+ return datatype_t(sizeof(T),
+ plib::is_integral<T>::value || std::is_enum<T>::value,
+ std::is_floating_point<T>::value);
+ }
class callback_t
{
public:
using list_t = std::vector<callback_t *>;
- virtual ~callback_t();
+ virtual ~callback_t() = default;
virtual void register_state(state_manager_t &manager, const pstring &module) = 0;
virtual void on_pre_save(state_manager_t &manager) = 0;
@@ -72,7 +70,7 @@ public:
entry_t(const pstring &stname, const void *owner, callback_t *callback)
: m_name(stname), m_dt(datatype_t(true)), m_owner(owner), m_callback(callback), m_count(0), m_ptr(nullptr) { }
- ~entry_t() { }
+ ~entry_t() = default;
pstring m_name;
const datatype_t m_dt;
@@ -82,28 +80,31 @@ public:
void * m_ptr;
};
- state_manager_t();
- ~state_manager_t();
+ state_manager_t() = default;
+ ~state_manager_t() = default;
- template<typename C> void save_item(const void *owner, C &state, const pstring &stname)
+ template<typename C>
+ void save_item(const void *owner, C &state, const pstring &stname)
{
- save_state_ptr( owner, stname, datatype_f<C>::f(), 1, &state);
+ save_state_ptr( owner, stname, dtype<C>(), 1, &state);
}
- template<typename C, std::size_t N> void save_item(const void *owner, C (&state)[N], const pstring &stname)
+ template<typename C, std::size_t N>
+ void save_item(const void *owner, C (&state)[N], const pstring &stname)
{
- save_state_ptr(owner, stname, datatype_f<C>::f(), N, &(state[0]));
+ save_state_ptr(owner, stname, dtype<C>(), N, &(state[0]));
}
- template<typename C> void save_item(const void *owner, C *state, const pstring &stname, const std::size_t count)
+ template<typename C>
+ void save_item(const void *owner, C *state, const pstring &stname, const std::size_t count)
{
- save_state_ptr(owner, stname, datatype_f<C>::f(), count, state);
+ save_state_ptr(owner, stname, dtype<C>(), count, state);
}
template<typename C>
void save_item(const void *owner, std::vector<C> &v, const pstring &stname)
{
- save_state_ptr(owner, stname, datatype_f<C>::f(), v.size(), v.data());
+ save_state_ptr(owner, stname, dtype<C>(), v.size(), v.data());
}
void pre_save();
@@ -124,6 +125,6 @@ private:
template<> void state_manager_t::save_item(const void *owner, callback_t &state, const pstring &stname);
-}
+} // namespace plib
#endif /* PSTATE_H_ */
diff --git a/src/lib/netlist/plib/pstream.cpp b/src/lib/netlist/plib/pstream.cpp
index a204bdcfe33..f9dd224e92f 100644
--- a/src/lib/netlist/plib/pstream.cpp
+++ b/src/lib/netlist/plib/pstream.cpp
@@ -8,9 +8,9 @@
#include "pstream.h"
#include "palloc.h"
+#include <algorithm>
#include <cstdio>
#include <cstdlib>
-#include <algorithm>
// VS2015 prefers _dup
#ifdef _WIN32
@@ -21,10 +21,6 @@
namespace plib {
-pstream::~pstream()
-{
-}
-
// -----------------------------------------------------------------------------
// pistream: input stream
// -----------------------------------------------------------------------------
@@ -124,10 +120,6 @@ pstdin::pstdin()
/* nothing to do */
}
-pstdin::~pstdin()
-{
-}
-
// -----------------------------------------------------------------------------
// Output file stream
// -----------------------------------------------------------------------------
@@ -198,11 +190,6 @@ pstream::pos_type pofilestream::vtell() const
return static_cast<pos_type>(ret);
}
-postringstream::~postringstream()
-{
-}
-
-
// -----------------------------------------------------------------------------
// pstderr: write to stderr
// -----------------------------------------------------------------------------
@@ -216,10 +203,6 @@ pstderr::pstderr()
{
}
-pstderr::~pstderr()
-{
-}
-
// -----------------------------------------------------------------------------
// pstdout: write to stdout
// -----------------------------------------------------------------------------
@@ -233,10 +216,6 @@ pstdout::pstdout()
{
}
-pstdout::~pstdout()
-{
-}
-
// -----------------------------------------------------------------------------
// Memory stream
// -----------------------------------------------------------------------------
@@ -256,10 +235,6 @@ pimemstream::pimemstream(const pomemstream &ostrm)
{
}
-pimemstream::~pimemstream()
-{
-}
-
pimemstream::pos_type pimemstream::vread(value_type *buf, const pos_type n)
{
pos_type ret = (m_pos + n <= m_len) ? n : m_len - m_pos;
@@ -288,10 +263,6 @@ pimemstream::pos_type pimemstream::vtell() const
return m_pos;
}
-pistringstream::~pistringstream()
-{
-}
-
// -----------------------------------------------------------------------------
// Output memory stream
// -----------------------------------------------------------------------------
@@ -376,10 +347,6 @@ bool putf8_reader::readline(pstring &line)
}
-putf8_fmt_writer::~putf8_fmt_writer()
-{
-}
-
void putf8_fmt_writer::vdowrite(const pstring &ls) const
{
write(ls);
@@ -387,4 +354,4 @@ void putf8_fmt_writer::vdowrite(const pstring &ls) const
-}
+} // namespace plib
diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h
index ad461bb3e20..a74295ba369 100644
--- a/src/lib/netlist/plib/pstream.h
+++ b/src/lib/netlist/plib/pstream.h
@@ -7,16 +7,17 @@
#ifndef PSTREAM_H_
#define PSTREAM_H_
+#include <type_traits>
+#include <vector>
+
+#include "palloc.h"
#include "pconfig.h"
-#include "pstring.h"
-#include "pfmtlog.h"
#include "pexception.h"
-#include "palloc.h"
+#include "pfmtlog.h"
+#include "pstring.h"
#define USE_CSTREAM (0)
-#include <vector>
-#include <type_traits>
#if USE_CSTREAM
#include <fstream>
@@ -39,7 +40,7 @@ typedef std::ostringstream pomemstream;
// pstream: things common to all streams
// -----------------------------------------------------------------------------
-class pstream : nocopyassign
+class pstream : public nocopyassign
{
public:
@@ -67,10 +68,10 @@ protected:
explicit pstream(const unsigned flags) : m_flags(flags)
{
}
- pstream(pstream &&src) : m_flags(src.m_flags)
+ pstream(pstream &&src) noexcept : m_flags(src.m_flags)
{
}
- ~pstream();
+ virtual ~pstream() = default;
virtual void vseek(const pos_type n) = 0;
virtual pos_type vtell() const = 0;
@@ -103,8 +104,6 @@ public:
typedef T value_type;
- virtual ~pistream_base() { }
-
bool eof() const { return ((flags() & FLAG_EOF) != 0); }
pos_type read(T *buf, const pos_type n)
@@ -115,7 +114,7 @@ public:
protected:
pistream_base() : pstream(0) {}
explicit pistream_base(const unsigned flags) : pstream(flags) {}
- explicit pistream_base(pistream_base &&src) : pstream(std::move(src)) {}
+ pistream_base(pistream_base &&src) noexcept : pstream(std::move(src)) {}
/* read up to n bytes from stream */
virtual size_type vread(T *buf, const size_type n) = 0;
};
@@ -134,8 +133,6 @@ public:
typedef T value_type;
- virtual ~postream_base() { }
-
void write(const T *buf, const size_type n)
{
vwrite(buf, n);
@@ -143,7 +140,7 @@ public:
protected:
explicit postream_base(unsigned flags) : pstream(flags) {}
- explicit postream_base(postream_base &&src) : pstream(std::move(src)) {}
+ postream_base(postream_base &&src) noexcept : pstream(std::move(src)) {}
/* write n bytes to stream */
virtual void vwrite(const T *buf, const size_type n) = 0;
@@ -162,7 +159,7 @@ public:
pomemstream();
- pomemstream(pomemstream &&src)
+ pomemstream(pomemstream &&src) noexcept
: postream(std::move(src))
, m_pos(src.m_pos)
, m_capacity(src.m_capacity)
@@ -172,16 +169,16 @@ public:
src.m_mem = nullptr;
}
- virtual ~pomemstream() override;
+ ~pomemstream() override;
char *memory() const { return m_mem; }
pos_type size() const { return m_size; }
protected:
/* write n bytes to stream */
- virtual void vwrite(const value_type *buf, const pos_type) override;
- virtual void vseek(const pos_type n) override;
- virtual pos_type vtell() const override;
+ void vwrite(const value_type *buf, const pos_type) override;
+ void vseek(const pos_type n) override;
+ pos_type vtell() const override;
private:
pos_type m_pos;
@@ -195,23 +192,23 @@ class postringstream : public postream
public:
postringstream() : postream(0) { }
- postringstream(postringstream &&src)
+ postringstream(postringstream &&src) noexcept
: postream(std::move(src))
- , m_buf(src.m_buf)
+ , m_buf(std::move(src.m_buf))
{ src.m_buf = ""; }
- virtual ~postringstream() override;
+ ~postringstream() override = default;
const pstring &str() { return m_buf; }
protected:
/* write n bytes to stream */
- virtual void vwrite(const value_type *buf, const pos_type n) override
+ void vwrite(const value_type *buf, const pos_type n) override
{
m_buf += pstring(reinterpret_cast<const pstring::mem_t *>(buf), n);
}
- virtual void vseek(const pos_type n) override { }
- virtual pos_type vtell() const override { return m_buf.size(); }
+ void vseek(const pos_type n) override { unused_var(n); }
+ pos_type vtell() const override { return m_buf.size(); }
private:
pstring m_buf;
@@ -226,25 +223,25 @@ class pofilestream : public postream
public:
pofilestream(const pstring &fname);
- pofilestream(pofilestream &&src)
+ pofilestream(pofilestream &&src) noexcept
: postream(std::move(src))
, m_file(src.m_file)
, m_pos(src.m_pos)
, m_actually_close(src.m_actually_close)
- , m_filename(src.m_filename)
+ , m_filename(std::move(src.m_filename))
{
src.m_file = nullptr;
src.m_actually_close = false;
}
- virtual ~pofilestream() override;
+ ~pofilestream() override;
protected:
pofilestream(void *file, const pstring &name, const bool do_close);
/* write n bytes to stream */
- virtual void vwrite(const value_type *buf, const pos_type n) override;
- virtual void vseek(const pos_type n) override;
- virtual pos_type vtell() const override;
+ void vwrite(const value_type *buf, const pos_type n) override;
+ void vseek(const pos_type n) override;
+ pos_type vtell() const override;
private:
void *m_file;
@@ -264,7 +261,6 @@ class pstderr : public pofilestream
{
public:
pstderr();
- virtual ~pstderr();
};
// -----------------------------------------------------------------------------
@@ -275,7 +271,6 @@ class pstdout : public pofilestream
{
public:
pstdout();
- virtual ~pstdout();
};
// -----------------------------------------------------------------------------
@@ -287,14 +282,14 @@ class pifilestream : public pistream
public:
pifilestream(const pstring &fname);
- virtual ~pifilestream() override;
+ ~pifilestream() override;
- pifilestream(pifilestream &&src)
+ pifilestream(pifilestream &&src) noexcept
: pistream(std::move(src))
, m_file(src.m_file)
, m_pos(src.m_pos)
, m_actually_close(src.m_actually_close)
- , m_filename(src.m_filename)
+ , m_filename(std::move(src.m_filename))
{
src.m_actually_close = false;
src.m_file = nullptr;
@@ -304,9 +299,9 @@ protected:
pifilestream(void *file, const pstring &name, const bool do_close);
/* read up to n bytes from stream */
- virtual pos_type vread(value_type *buf, const pos_type n) override;
- virtual void vseek(const pos_type n) override;
- virtual pos_type vtell() const override;
+ pos_type vread(value_type *buf, const pos_type n) override;
+ void vseek(const pos_type n) override;
+ pos_type vtell() const override;
private:
void *m_file;
@@ -326,7 +321,7 @@ class pstdin : public pifilestream
public:
pstdin();
- virtual ~pstdin() override;
+ ~pstdin() override = default;
};
// -----------------------------------------------------------------------------
@@ -340,7 +335,7 @@ public:
pimemstream(const void *mem, const pos_type len);
pimemstream();
- pimemstream(pimemstream &&src)
+ pimemstream(pimemstream &&src) noexcept
: pistream(std::move(src))
, m_pos(src.m_pos)
, m_len(src.m_len)
@@ -351,7 +346,7 @@ public:
explicit pimemstream(const pomemstream &ostrm);
- virtual ~pimemstream() override;
+ ~pimemstream() override = default;
pos_type size() const { return m_len; }
protected:
@@ -363,9 +358,9 @@ protected:
}
/* read up to n bytes from stream */
- virtual pos_type vread(value_type *buf, const pos_type n) override;
- virtual void vseek(const pos_type n) override;
- virtual pos_type vtell() const override;
+ pos_type vread(value_type *buf, const pos_type n) override;
+ void vseek(const pos_type n) override;
+ pos_type vtell() const override;
private:
pos_type m_pos;
@@ -386,12 +381,12 @@ public:
{
set_mem(m_str.c_str(), std::strlen(m_str.c_str()));
}
- pistringstream(pistringstream &&src)
+ pistringstream(pistringstream &&src) noexcept
: pimemstream(std::move(src)), m_str(src.m_str)
{
set_mem(m_str.c_str(), std::strlen(m_str.c_str()));
}
- virtual ~pistringstream() override;
+ ~pistringstream() override = default;
private:
/* only needed for a reference till destruction */
@@ -415,15 +410,13 @@ class putf8_reader : plib::nocopyassign
{
public:
- virtual ~putf8_reader()
- {
- }
+ virtual ~putf8_reader() = default;
template <typename T>
friend struct constructor_helper;
template <typename T>
- putf8_reader(T &&strm)
+ putf8_reader(T &&strm) // NOLINT(misc-forwarding-reference-overload,bugprone-move-forwarding-reference,bugprone-forwarding-reference-overload)
: m_strm(std::move(constructor_helper<T>()(std::move(strm))))
{}
@@ -475,8 +468,8 @@ class putf8_writer : plib::nocopyassign
public:
explicit putf8_writer(postream *strm) : m_strm(strm) {}
- putf8_writer(putf8_writer &&src) : m_strm(src.m_strm) {}
- virtual ~putf8_writer() {}
+ putf8_writer(putf8_writer &&src) noexcept : m_strm(src.m_strm) {}
+ virtual ~putf8_writer() = default;
void writeline(const pstring &line) const
{
@@ -510,7 +503,7 @@ public:
{
}
- virtual ~putf8_fmt_writer() override;
+ ~putf8_fmt_writer() override = default;
//protected:
void vdowrite(const pstring &ls) const;
@@ -522,12 +515,12 @@ private:
// pbinary_writer_t: writer on top of ostream
// -----------------------------------------------------------------------------
-class pbinary_writer : plib::nocopyassign
+class pbinary_writer : public plib::nocopyassign
{
public:
explicit pbinary_writer(postream &strm) : m_strm(strm) {}
- pbinary_writer(pbinary_writer &&src) : m_strm(src.m_strm) {}
- virtual ~pbinary_writer() {}
+ pbinary_writer(pbinary_writer &&src) noexcept : m_strm(src.m_strm) {}
+ virtual ~pbinary_writer() = default;
template <typename T>
void write(const T &val)
@@ -537,7 +530,7 @@ public:
void write(const pstring &s)
{
- const postream::value_type *sm = reinterpret_cast<const postream::value_type *>(s.c_str());
+ const auto sm = reinterpret_cast<const postream::value_type *>(s.c_str());
const std::size_t sl = std::strlen(s.c_str());
write(sl);
m_strm.write(sm, sl);
@@ -555,12 +548,12 @@ private:
postream &m_strm;
};
-class pbinary_reader : plib::nocopyassign
+class pbinary_reader : public plib::nocopyassign
{
public:
explicit pbinary_reader(pistream &strm) : m_strm(strm) {}
- pbinary_reader(pbinary_reader &&src) : m_strm(src.m_strm) { }
- virtual ~pbinary_reader() {}
+ pbinary_reader(pbinary_reader &&src) noexcept : m_strm(src.m_strm) { }
+ virtual ~pbinary_reader() = default;
template <typename T>
void read(T &val)
@@ -572,7 +565,7 @@ public:
{
std::size_t sz = 0;
read(sz);
- plib::string_info<pstring>::mem_t *buf = new plib::string_info<pstring>::mem_t[sz+1];
+ auto buf = new plib::string_info<pstring>::mem_t[sz+1];
m_strm.read(reinterpret_cast<pistream::value_type *>(buf), sz);
buf[sz] = 0;
s = pstring(buf);
@@ -601,6 +594,6 @@ inline void copystream(postream &dest, pistream &src)
}
-}
+} // namespace plib
#endif /* PSTREAM_H_ */
diff --git a/src/lib/netlist/plib/pstring.cpp b/src/lib/netlist/plib/pstring.cpp
index 9db4a77efe3..089244c8232 100644
--- a/src/lib/netlist/plib/pstring.cpp
+++ b/src/lib/netlist/plib/pstring.cpp
@@ -10,8 +10,8 @@
#include "plists.h"
#include <algorithm>
-#include <stack>
#include <atomic>
+#include <stack>
template <typename T>
std::size_t strlen_mem(const T *s)
diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h
index 6d7301ee003..4ecfd145c95 100644
--- a/src/lib/netlist/plib/pstring.h
+++ b/src/lib/netlist/plib/pstring.h
@@ -9,12 +9,14 @@
#include <cstring>
#include <exception>
-#include <stdexcept>
#include <iterator>
-#include <string>
#include <limits>
+#include <stdexcept>
+#include <string>
#include <type_traits>
+#include "ptypes.h"
+
// ----------------------------------------------------------------------------------------
// pstring: semi-immutable strings ...
//
@@ -31,26 +33,20 @@ class pstring_const_iterator final
{
public:
- typedef typename T::ref_value_type value_type;
+ using value_type = typename T::ref_value_type;
- typedef value_type const *pointer;
- typedef value_type const &reference;
- typedef std::ptrdiff_t difference_type;
- typedef std::forward_iterator_tag iterator_category;
- typedef typename T::string_type string_type;
- typedef typename T::traits_type traits_type;
+ using pointer = value_type const *;
+ using reference = value_type const &;
+ using difference_type = std::ptrdiff_t;
+ using iterator_category = std::forward_iterator_tag;
+ using string_type = typename T::string_type;
+ using traits_type = typename T::traits_type;
pstring_const_iterator() noexcept : p() { }
explicit constexpr pstring_const_iterator(const typename string_type::const_iterator &x) noexcept : p(x) { }
-#if !defined(_MSC_VER) || !defined(_ITERATOR_DEBUG_LEVEL) || (0 == _ITERATOR_DEBUG_LEVEL) // debug iterators are broken
- pstring_const_iterator(const pstring_const_iterator &rhs) noexcept = default;
- pstring_const_iterator(pstring_const_iterator &&rhs) noexcept = default;
- pstring_const_iterator &operator=(const pstring_const_iterator &rhs) noexcept = default;
- pstring_const_iterator &operator=(pstring_const_iterator &&rhs) noexcept = default;
-#endif
pstring_const_iterator& operator++() noexcept { p += static_cast<difference_type>(traits_type::codelen(&(*p))); return *this; }
- pstring_const_iterator operator++(int) noexcept { pstring_const_iterator tmp(*this); operator++(); return tmp; }
+ const pstring_const_iterator operator++(int) noexcept { pstring_const_iterator tmp(*this); operator++(); return tmp; }
bool operator==(const pstring_const_iterator& rhs) const noexcept { return p == rhs.p; }
bool operator!=(const pstring_const_iterator& rhs) const noexcept { return p != rhs.p; }
@@ -68,7 +64,7 @@ template <typename F>
struct pstring_t
{
public:
- typedef F traits_type;
+ using traits_type = F;
typedef typename traits_type::mem_t mem_t;
typedef typename traits_type::code_t code_t;
@@ -77,10 +73,12 @@ public:
typedef std::ptrdiff_t difference_type;
typedef typename traits_type::string_type string_type;
+ // FIXME: this is ugly
class ref_value_type final
{
public:
ref_value_type() = delete;
+ ~ref_value_type() = delete;
ref_value_type(const ref_value_type &) = delete;
ref_value_type(ref_value_type &&) = delete;
ref_value_type &operator=(const ref_value_type &) = delete;
@@ -93,12 +91,8 @@ public:
typedef const_reference reference;
// simple construction/destruction
- pstring_t()
- {
- }
- ~pstring_t()
- {
- }
+ pstring_t() = default;
+ ~pstring_t() = default;
// FIXME: Do something with encoding
pstring_t(const mem_t *string)
@@ -121,17 +115,13 @@ public:
m_str.assign(string, N - 1);
}
- pstring_t(const pstring_t &string)
- : m_str(string.m_str)
- { }
+ pstring_t(const pstring_t &string) = default;
explicit pstring_t(const string_type &string)
: m_str(string)
{ }
- pstring_t(pstring_t &&string)
- : m_str(string.m_str)
- { }
+ pstring_t(pstring_t &&string) noexcept = default;
explicit pstring_t(code_t code)
{
@@ -149,7 +139,8 @@ public:
operator string_type () const { return m_str; }
- pstring_t &operator=(const pstring_t &string) { m_str = string.m_str; return *this; }
+ pstring_t &operator=(const pstring_t &string) = default;
+ pstring_t &operator=(pstring_t &&string) noexcept = default;
template <typename T,
class = typename std::enable_if<!std::is_same<T, pstring_t::traits_type>::value>::type>
@@ -228,8 +219,8 @@ struct pu8_traits
typedef char code_t;
typedef std::string string_type;
static std::size_t len(const string_type &p) { return p.size(); }
- static std::size_t codelen(const mem_t *p) { return 1; }
- static std::size_t codelen(const code_t c) { return 1; }
+ static std::size_t codelen(const mem_t *p) { plib::unused_var(p); return 1; }
+ static std::size_t codelen(const code_t c) { plib::unused_var(c); return 1; }
static code_t code(const mem_t *p) { return *p; }
static void encode(const code_t c, string_type &s) { s += static_cast<mem_t>(c); }
static const mem_t *nthcode(const mem_t *p, const std::size_t n) { return &(p[n]); }
@@ -253,7 +244,7 @@ struct putf8_traits
}
static std::size_t codelen(const mem_t *p)
{
- const unsigned char *p1 = reinterpret_cast<const unsigned char *>(p);
+ const auto p1 = reinterpret_cast<const unsigned char *>(p);
if ((*p1 & 0x80) == 0x00)
return 1;
else if ((*p1 & 0xE0) == 0xC0)
@@ -280,7 +271,7 @@ struct putf8_traits
}
static code_t code(const mem_t *p)
{
- const unsigned char *p1 = reinterpret_cast<const unsigned char *>(p);
+ const auto p1 = reinterpret_cast<const unsigned char *>(p);
if ((*p1 & 0x80) == 0x00)
return *p1;
else if ((*p1 & 0xE0) == 0xC0)
@@ -339,7 +330,7 @@ struct putf16_traits
while (i != p.end())
{
// FIXME: check that size is equal
- uint16_t c = static_cast<uint16_t>(*i++);
+ auto c = static_cast<uint16_t>(*i++);
if (!((c & 0xd800) == 0xd800))
ret++;
}
@@ -347,7 +338,7 @@ struct putf16_traits
}
static std::size_t codelen(const mem_t *p)
{
- uint16_t c = static_cast<uint16_t>(*p);
+ auto c = static_cast<uint16_t>(*p);
return ((c & 0xd800) == 0xd800) ? 2 : 1;
}
static std::size_t codelen(const code_t c)
@@ -359,7 +350,7 @@ struct putf16_traits
}
static code_t code(const mem_t *p)
{
- uint32_t c = static_cast<uint32_t>(*p++);
+ auto c = static_cast<uint32_t>(*p++);
if ((c & 0xd800) == 0xd800)
{
c = (c - 0xd800) << 10;
@@ -369,7 +360,7 @@ struct putf16_traits
}
static void encode(code_t c, string_type &s)
{
- uint32_t cu = static_cast<uint32_t>(c);
+ auto cu = static_cast<uint32_t>(c);
if (c > 0xffff)
{ //make a surrogate pair
uint32_t t = ((cu - 0x10000) >> 10) + 0xd800;
@@ -405,7 +396,7 @@ struct pwchar_traits
while (i != p.end())
{
// FIXME: check that size is equal
- uint32_t c = static_cast<uint32_t>(*i++);
+ auto c = static_cast<uint32_t>(*i++);
if (!((c & 0xd800) == 0xd800))
ret++;
}
@@ -419,7 +410,7 @@ struct pwchar_traits
{
if (sizeof(wchar_t) == 2)
{
- uint16_t c = static_cast<uint16_t>(*p);
+ auto c = static_cast<uint16_t>(*p);
return ((c & 0xd800) == 0xd800) ? 2 : 1;
}
else
@@ -438,7 +429,7 @@ struct pwchar_traits
{
if (sizeof(wchar_t) == 2)
{
- uint32_t c = static_cast<uint32_t>(*p++);
+ auto c = static_cast<uint32_t>(*p++);
if ((c & 0xd800) == 0xd800)
{
c = (c - 0xd800) << 10;
@@ -454,7 +445,7 @@ struct pwchar_traits
{
if (sizeof(wchar_t) == 2)
{
- uint32_t cu = static_cast<uint32_t>(c);
+ auto cu = static_cast<uint32_t>(c);
if (c > 0xffff)
{ //make a surrogate pair
uint32_t t = ((cu - 0x10000) >> 10) + 0xd800;
@@ -739,10 +730,10 @@ namespace plib
template<typename T, typename T1, typename T2>
T replace_all(const T &str, const T1 &search, const T2 &replace)
{
- return replace_all(str, T(search), T(replace));
+ return replace_all(str, static_cast<T>(search), static_cast<T>(replace));
}
-}
+} // namespace plib
// custom specialization of std::hash can be injected in namespace std
namespace std
@@ -761,6 +752,6 @@ namespace std
return result;
}
};
-}
+} // namespace std
#endif /* PSTRING_H_ */
diff --git a/src/lib/netlist/plib/ptypes.h b/src/lib/netlist/plib/ptypes.h
index 8b6b7ff7914..07a48b03b93 100644
--- a/src/lib/netlist/plib/ptypes.h
+++ b/src/lib/netlist/plib/ptypes.h
@@ -8,11 +8,11 @@
#ifndef PTYPES_H_
#define PTYPES_H_
-#include "pconfig.h"
-#include "pstring.h"
-
-#include <type_traits>
#include <limits>
+#include <string>
+#include <type_traits>
+
+#include "pconfig.h"
namespace plib
{
@@ -45,24 +45,24 @@ namespace plib
struct nocopyassignmove
{
- protected:
- nocopyassignmove() = default;
- ~nocopyassignmove() = default;
- private:
nocopyassignmove(const nocopyassignmove &) = delete;
nocopyassignmove(nocopyassignmove &&) = delete;
nocopyassignmove &operator=(const nocopyassignmove &) = delete;
nocopyassignmove &operator=(nocopyassignmove &&) = delete;
+ protected:
+ nocopyassignmove() = default;
+ ~nocopyassignmove() = default;
};
struct nocopyassign
{
+ nocopyassign(const nocopyassign &) = delete;
+ nocopyassign &operator=(const nocopyassign &) = delete;
protected:
nocopyassign() = default;
~nocopyassign() = default;
- private:
- nocopyassign(const nocopyassign &) = delete;
- nocopyassign &operator=(const nocopyassign &) = delete;
+ nocopyassign(nocopyassign &&) = default;
+ nocopyassign &operator=(nocopyassign &&) = default;
};
//============================================================
@@ -81,16 +81,16 @@ namespace plib
{
protected:
static int from_string_int(const char *str, const char *x);
- static pstring nthstr(int n, const char *str);
+ static std::string nthstr(int n, const char *str);
};
-}
+} // namespace plib
#define P_ENUM(ename, ...) \
struct ename : public plib::penum_base { \
enum E { __VA_ARGS__ }; \
ename (E v) : m_v(v) { } \
- bool set_from_string (const pstring &s) { \
+ bool set_from_string (const std::string &s) { \
static char const *const strings = # __VA_ARGS__; \
int f = from_string_int(strings, s.c_str()); \
if (f>=0) { m_v = static_cast<E>(f); return true; } else { return false; } \
@@ -98,7 +98,7 @@ namespace plib
operator E() const {return m_v;} \
bool operator==(const ename &rhs) const {return m_v == rhs.m_v;} \
bool operator==(const E &rhs) const {return m_v == rhs;} \
- const pstring name() const { \
+ const std::string name() const { \
static char const *const strings = # __VA_ARGS__; \
return nthstr(static_cast<int>(m_v), strings); \
} \
diff --git a/src/lib/netlist/plib/putil.cpp b/src/lib/netlist/plib/putil.cpp
index 19f66ba6cbb..03f730f6ba2 100644
--- a/src/lib/netlist/plib/putil.cpp
+++ b/src/lib/netlist/plib/putil.cpp
@@ -2,13 +2,13 @@
// copyright-holders:Couriersud
#include "putil.h"
-#include "ptypes.h"
#include "plists.h"
+#include "ptypes.h"
-#include <cstdlib>
#include <algorithm>
-#include <initializer_list>
+#include <cstdlib>
#include <cstring>
+#include <initializer_list>
namespace plib
{
@@ -17,7 +17,7 @@ namespace plib
const pstring buildpath(std::initializer_list<pstring> list )
{
pstring ret = "";
- for( auto elem : list )
+ for( const auto &elem : list )
{
if (ret == "")
ret = elem;
@@ -38,7 +38,7 @@ namespace plib
else
return pstring(std::getenv(var.c_str()));
}
- }
+ } // namespace util
std::vector<pstring> psplit(const pstring &str, const pstring &onstr, bool ignore_empty)
{
@@ -102,7 +102,7 @@ namespace plib
auto i = str.begin();
while (i != str.end())
{
- std::size_t p = static_cast<std::size_t>(-1);
+ auto p = static_cast<std::size_t>(-1);
for (std::size_t j=0; j < onstrl.size(); j++)
{
if (std::equal(onstrl[j].begin(), onstrl[j].end(), i))
@@ -161,7 +161,7 @@ namespace plib
return cnt;
return -1;
}
- pstring penum_base::nthstr(int n, const char *str)
+ std::string penum_base::nthstr(int n, const char *str)
{
char buf[64];
char *bufp = buf;
@@ -186,6 +186,6 @@ namespace plib
str++;
}
*bufp = 0;
- return pstring(buf);
+ return std::string(buf);
}
} // namespace plib
diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h
index 023a0271ce2..71a7146e6c0 100644
--- a/src/lib/netlist/plib/putil.h
+++ b/src/lib/netlist/plib/putil.h
@@ -5,13 +5,13 @@
*
*/
-#ifndef P_UTIL_H_
-#define P_UTIL_H_
+#ifndef PUTIL_H_
+#define PUTIL_H_
#include "pstring.h"
-#include <initializer_list>
#include <algorithm>
+#include <initializer_list>
#include <vector> // <<= needed by windows build
#define PSTRINGIFY_HELP(y) # y
@@ -25,7 +25,7 @@ namespace plib
{
const pstring buildpath(std::initializer_list<pstring> list );
const pstring environment(const pstring &var, const pstring &default_val);
- }
+ } // namespace util
namespace container
{
@@ -56,7 +56,21 @@ namespace plib
{
con.erase(std::remove(con.begin(), con.end(), elem), con.end());
}
- }
+ } // namespace container
+
+ /* May be further specialized .... This is the generic version */
+ template <typename T>
+ struct constants
+ {
+ static constexpr T zero = static_cast<T>(0);
+ static constexpr T one = static_cast<T>(1);
+ static constexpr T two = static_cast<T>(2);
+
+ template <typename V>
+ constexpr T operator()(V &&v) const noexcept { return static_cast<T>(v); }
+ };
+
+
template <class C>
struct indexed_compare
@@ -78,6 +92,6 @@ namespace plib
const std::string &token,
const std::size_t maxsplit);
-}
+} // namespace plib
-#endif /* P_UTIL_H_ */
+#endif /* PUTIL_H_ */
diff --git a/src/lib/netlist/plib/vector_ops.h b/src/lib/netlist/plib/vector_ops.h
index 9bcdb6ee8c1..406e69a2a91 100644
--- a/src/lib/netlist/plib/vector_ops.h
+++ b/src/lib/netlist/plib/vector_ops.h
@@ -70,7 +70,7 @@ namespace plib
}
template<typename T>
- void vec_add_mult_scalar_p(const std::size_t & n, const T * RESTRICT v, const T scalar, T * RESTRICT result)
+ void vec_add_mult_scalar_p(const std::size_t & n, const T * v, const T scalar, T * result)
{
for ( std::size_t i = 0; i < n; i++ )
result[i] += scalar * v[i];
@@ -106,7 +106,7 @@ namespace plib
return ret;
}
-}
+} // namespace plib
#if !defined(__clang__) && !defined(_MSC_VER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))
#pragma GCC diagnostic pop
diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp
index 814538e688e..cba5cd60500 100644
--- a/src/lib/netlist/prg/nltool.cpp
+++ b/src/lib/netlist/prg/nltool.cpp
@@ -9,11 +9,11 @@
****************************************************************************/
#include "netlist/plib/pmain.h"
-#include "netlist/nl_setup.h"
-#include "netlist/nl_parser.h"
#include "netlist/devices/net_lib.h"
-#include "netlist/tools/nl_convert.h"
+#include "netlist/nl_parser.h"
+#include "netlist/nl_setup.h"
#include "netlist/solver/nld_solver.h"
+#include "netlist/tools/nl_convert.h"
#include <cstring>
@@ -85,8 +85,8 @@ public:
plib::option_example opt_ex2;
plib::option_example opt_ex3;
- int execute();
- pstring usage();
+ int execute() override;
+ pstring usage() override;
private:
void run();
@@ -127,7 +127,7 @@ public:
{
}
- virtual std::unique_ptr<plib::pistream> stream(const pstring &file) override;
+ std::unique_ptr<plib::pistream> stream(const pstring &file) override;
private:
pstring m_folder;
@@ -172,9 +172,7 @@ public:
{
}
- ~netlist_tool_t()
- {
- }
+ ~netlist_tool_t() = default;
void init()
{
@@ -281,9 +279,11 @@ void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls
struct input_t
{
input_t(const netlist::setup_t &setup, const pstring &line)
+ : m_value(0.0)
{
char buf[400];
double t;
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
int e = sscanf(line.c_str(), "%lf,%[^,],%lf", &t, buf, &m_value);
if (e != 3)
throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
@@ -478,12 +478,12 @@ void tool_app_t::cmac(const netlist::factory::element_t *e)
{
auto v = plib::psplit(e->param_desc(), ",");
pstring vs;
- for (auto s : v)
+ for (const auto &s : v)
vs += ", p" + plib::replace_all(plib::replace_all(s, "+", ""), ".", "_");
mac_out("#define " + e->name() + "(name" + vs + ")");
mac_out("\tNET_REGISTER_DEV(" + e->name() +", name)");
- for (auto s : v)
+ for (const auto &s : v)
{
pstring r(plib::replace_all(plib::replace_all(s, "+", ""), ".", "_"));
if (plib::startsWith(s, "+"))
@@ -498,7 +498,7 @@ void tool_app_t::mac(const netlist::factory::element_t *e)
{
auto v = plib::psplit(e->param_desc(), ",");
pstring vs;
- for (auto s : v)
+ for (const auto &s : v)
{
vs += ", " + plib::replace_all(plib::replace_all(s, "+", ""), ".", "_");
}
@@ -506,7 +506,7 @@ void tool_app_t::mac(const netlist::factory::element_t *e)
if (v.size() > 0)
{
pout("/*\n");
- for (auto s : v)
+ for (const auto &s : v)
{
pstring r(plib::replace_all(plib::replace_all(s, "+", ""), ".", "_"));
if (plib::startsWith(s, "+"))
@@ -645,7 +645,7 @@ void tool_app_t::listdevices()
std::vector<pstring> terms(nt.setup().get_terminals_for_device_name(d->name()));
out += "," + f->param_desc();
- for (auto p : plib::psplit(f->param_desc(),",") )
+ for (const auto &p : plib::psplit(f->param_desc(),",") )
{
if (plib::startsWith(p, "+"))
{
@@ -661,7 +661,7 @@ void tool_app_t::listdevices()
t += "," + j;
printf("\tTerminals: %s\n", t.substr(1).c_str());
}
- devs.push_back(std::move(d));
+ devs.emplace_back(std::move(d));
}
}
@@ -715,7 +715,7 @@ int tool_app_t::execute()
}
m_options = opt_defines();
- m_options.push_back("NLTOOL_VERSION=" PSTRINGIFY(NLTOOL_VERSION));
+ m_options.emplace_back("NLTOOL_VERSION=" PSTRINGIFY(NLTOOL_VERSION));
try
{
diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp
index c25330627b6..29c6d62d9c5 100644
--- a/src/lib/netlist/prg/nlwav.cpp
+++ b/src/lib/netlist/prg/nlwav.cpp
@@ -1,12 +1,12 @@
// license:GPL-2.0+
// copyright-holders:Couriersud
-#include <cstring>
#include "../plib/pstring.h"
+#include "../nl_setup.h"
#include "../plib/plists.h"
-#include "../plib/pstream.h"
#include "../plib/pmain.h"
#include "../plib/ppmf.h"
-#include "../nl_setup.h"
+#include "../plib/pstream.h"
+#include <cstring>
@@ -24,6 +24,8 @@
class wav_t
{
public:
+ // FIXME: Initialized in intialize, need better c++ compliance
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
wav_t(plib::postream &strm, std::size_t sr, std::size_t channels)
: m_f(strm)
{
@@ -60,7 +62,7 @@ public:
m_data.len += m_fmt.block_align;
for (std::size_t i = 0; i < channels(); i++)
{
- int16_t ps = static_cast<int16_t>(sample[i]); /* 16 bit sample, FIXME: Endianess? */
+ auto ps = static_cast<int16_t>(sample[i]); /* 16 bit sample, FIXME: Endianess? */
write(ps);
}
}
@@ -150,6 +152,8 @@ public:
m_e[i].eof = !r[i].readline(line);
if (!m_e[i].eof)
{
+ // sscanf is very fast ...
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
sscanf(line.c_str(), "%lf %lf", &m_e[i].t, &m_e[i].v);
m_e[i].need_more = false;
}
@@ -162,9 +166,9 @@ public:
void process(std::vector<std::unique_ptr<plib::pistream>> &is)
{
std::vector<plib::putf8_reader> readers;
- for (std::size_t i = 0; i < is.size(); i++)
+ for (auto &i : is)
{
- plib::putf8_reader r(std::move(is[i]));
+ plib::putf8_reader r(std::move(i));
readers.push_back(std::move(r));
}
@@ -308,7 +312,7 @@ public:
, m_format(format)
{
for (pstring::value_type c = 64; c < 64+26; c++)
- m_ids.push_back(pstring(c));
+ m_ids.emplace_back(pstring(c));
write("$date Sat Jan 19 14:14:17 2019\n");
write("$end\n");
write("$version Netlist nlwav 0.1\n");
@@ -316,7 +320,7 @@ public:
write("$timescale 1 ns\n");
write("$end\n");
std::size_t i = 0;
- for (auto ch : channels)
+ for (const auto &ch : channels)
{
// $var real 64 N1X1 N1X1 $end
if (format == ANALOG)
@@ -417,8 +421,8 @@ public:
plib::option_example opt_ex1;
plib::option_example opt_ex2;
- int execute();
- pstring usage();
+ int execute() override;
+ pstring usage() override;
plib::pstdin pin_strm;
private:
diff --git a/src/lib/netlist/solver/nld_matrix_solver.cpp b/src/lib/netlist/solver/nld_matrix_solver.cpp
index 30e47c9ba72..b678f7f8d8c 100644
--- a/src/lib/netlist/solver/nld_matrix_solver.cpp
+++ b/src/lib/netlist/solver/nld_matrix_solver.cpp
@@ -15,10 +15,6 @@ namespace netlist
namespace devices
{
-proxied_analog_output_t::~proxied_analog_output_t()
-{
-}
-
terms_for_net_t::terms_for_net_t()
: m_railstart(0)
, m_last_V(0.0)
@@ -66,7 +62,7 @@ void terms_for_net_t::set_pointers()
for (std::size_t i = 0; i < count(); i++)
{
m_terms[i]->set_ptrs(&m_gt[i], &m_go[i], &m_Idr[i]);
- m_connected_net_V[i] = m_terms[i]->m_otherterm->net().Q_Analog_state_ptr();
+ m_connected_net_V[i] = m_terms[i]->otherterm()->net().Q_Analog_state_ptr();
}
}
@@ -92,10 +88,6 @@ matrix_solver_t::matrix_solver_t(netlist_base_t &anetlist, const pstring &name,
connect_post_start(m_fb_sync, m_Q_sync);
}
-matrix_solver_t::~matrix_solver_t()
-{
-}
-
void matrix_solver_t::setup_base(analog_net_t::list_t &nets)
{
@@ -132,7 +124,7 @@ void matrix_solver_t::setup_base(analog_net_t::list_t &nets)
if (!plib::container::contains(m_dynamic_devices, &p->device()))
m_dynamic_devices.push_back(&p->device());
{
- terminal_t *pterm = dynamic_cast<terminal_t *>(p);
+ auto *pterm = dynamic_cast<terminal_t *>(p);
add_term(k, pterm);
}
log().debug("Added terminal {1}\n", p->name());
@@ -262,7 +254,7 @@ void matrix_solver_t::sort_terms(eSortType sort)
for (std::size_t i = 0; i < term->count(); i++)
//FIXME: this is weird
if (other[i] != -1)
- other[i] = get_net_idx(&term->terms()[i]->m_otherterm->net());
+ other[i] = get_net_idx(&term->terms()[i]->otherterm()->net());
}
}
@@ -344,7 +336,7 @@ void matrix_solver_t::setup_matrix()
* This should reduce cache misses ...
*/
- bool **touched = plib::palloc_array<bool *>(iN);
+ auto **touched = plib::palloc_array<bool *>(iN);
for (std::size_t k=0; k<iN; k++)
touched[k] = plib::palloc_array<bool>(iN);
@@ -378,7 +370,7 @@ void matrix_solver_t::setup_matrix()
}
log().verbose("Number of mults/adds for {1}: {2}", name(), m_ops);
- if ((0))
+ if ((false))
for (std::size_t k = 0; k < iN; k++)
{
pstring line = plib::pfmt("{1:3}")(k);
@@ -394,13 +386,14 @@ void matrix_solver_t::setup_matrix()
{
pstring num = plib::pfmt("{1}")(k);
- state().save(*this, m_terms[k]->m_last_V, "lastV." + num);
- state().save(*this, m_terms[k]->m_DD_n_m_1, "m_DD_n_m_1." + num);
- state().save(*this, m_terms[k]->m_h_n_m_1, "m_h_n_m_1." + num);
+ state().save(*this, m_terms[k]->m_last_V, this->name(), "lastV." + num);
+ state().save(*this, m_terms[k]->m_DD_n_m_1, this->name(), "m_DD_n_m_1." + num);
+ state().save(*this, m_terms[k]->m_h_n_m_1, this->name(), "m_h_n_m_1." + num);
- state().save(*this, m_terms[k]->go(),"GO" + num, m_terms[k]->count());
- state().save(*this, m_terms[k]->gt(),"GT" + num, m_terms[k]->count());
- state().save(*this, m_terms[k]->Idr(),"IDR" + num , m_terms[k]->count());
+ // FIXME: This shouldn't be necessary, recalculate on each entry ...
+ state().save(*this, m_terms[k]->go(),"GO" + num, this->name(), m_terms[k]->count());
+ state().save(*this, m_terms[k]->gt(),"GT" + num, this->name(), m_terms[k]->count());
+ state().save(*this, m_terms[k]->Idr(),"IDR" + num, this->name(), m_terms[k]->count());
}
for (std::size_t k=0; k<iN; k++)
@@ -460,11 +453,11 @@ void matrix_solver_t::update_forced()
void matrix_solver_t::step(const netlist_time &delta)
{
const nl_double dd = delta.as_double();
- for (std::size_t k=0; k < m_step_devices.size(); k++)
- m_step_devices[k]->timestep(dd);
+ for (auto &d : m_step_devices)
+ d->timestep(dd);
}
-void matrix_solver_t::solve_base(netlist_time time)
+void matrix_solver_t::solve_base()
{
++m_stat_vsolver_calls;
if (has_dynamic_devices())
@@ -505,7 +498,7 @@ const netlist_time matrix_solver_t::solve(netlist_time now)
/* update all terminals for new time step */
m_last_step = now;
step(delta);
- solve_base(now);
+ solve_base();
const netlist_time next_time_step = compute_next_timestep(delta.as_double());
return next_time_step;
@@ -526,8 +519,8 @@ std::pair<int, int> matrix_solver_t::get_left_right_of_diag(std::size_t irow, st
* return the minimum column right of the diagonal (999999 if no cols found)
*/
- const int row = static_cast<int>(irow);
- const int diag = static_cast<int>(idiag);
+ const auto row = static_cast<int>(irow);
+ const auto diag = static_cast<int>(idiag);
int colmax = -1;
int colmin = 999999;
@@ -536,7 +529,7 @@ std::pair<int, int> matrix_solver_t::get_left_right_of_diag(std::size_t irow, st
for (std::size_t i = 0; i < term->count(); i++)
{
- auto col = get_net_idx(&term->terms()[i]->m_otherterm->net());
+ auto col = get_net_idx(&term->terms()[i]->otherterm()->net());
if (col != -1)
{
if (col==row) col = diag;
@@ -548,7 +541,7 @@ std::pair<int, int> matrix_solver_t::get_left_right_of_diag(std::size_t irow, st
colmax = col;
}
}
- return std::pair<int, int>(colmax, colmin);
+ return {colmax, colmin};
}
double matrix_solver_t::get_weight_around_diag(std::size_t row, std::size_t diag)
@@ -564,10 +557,10 @@ double matrix_solver_t::get_weight_around_diag(std::size_t row, std::size_t diag
auto &term = m_terms[row];
for (std::size_t i = 0; i < term->count(); i++)
{
- auto col = get_net_idx(&term->terms()[i]->m_otherterm->net());
+ auto col = get_net_idx(&term->terms()[i]->otherterm()->net());
if (col >= 0)
{
- std::size_t colu = static_cast<std::size_t>(col);
+ auto colu = static_cast<std::size_t>(col);
if (!touched[colu])
{
if (colu==row) colu = static_cast<unsigned>(diag);
@@ -585,13 +578,13 @@ double matrix_solver_t::get_weight_around_diag(std::size_t row, std::size_t diag
void matrix_solver_t::add_term(std::size_t k, terminal_t *term)
{
- if (term->m_otherterm->net().isRailNet())
+ if (term->otherterm()->net().isRailNet())
{
m_rails_temp[k]->add(term, -1, false);
}
else
{
- int ot = get_net_idx(&term->m_otherterm->net());
+ int ot = get_net_idx(&term->otherterm()->net());
if (ot>=0)
{
m_terms[k]->add(term, ot, true);
@@ -624,8 +617,8 @@ netlist_time matrix_solver_t::compute_next_timestep(const double cur_ts)
t->m_h_n_m_1 = hn;
t->m_DD_n_m_1 = DD_n;
- if (std::fabs(DD2) > NL_FCONST(1e-60)) // avoid div-by-zero
- new_net_timestep = std::sqrt(m_params.m_dynamic_lte / std::fabs(NL_FCONST(0.5)*DD2));
+ if (std::fabs(DD2) > plib::constants<nl_double>()(1e-60)) // avoid div-by-zero
+ new_net_timestep = std::sqrt(m_params.m_dynamic_lte / std::fabs(plib::constants<nl_double>()(0.5)*DD2));
else
new_net_timestep = m_params.m_max_timestep;
diff --git a/src/lib/netlist/solver/nld_matrix_solver.h b/src/lib/netlist/solver/nld_matrix_solver.h
index 2f4e692ed6f..f28f855fa3b 100644
--- a/src/lib/netlist/solver/nld_matrix_solver.h
+++ b/src/lib/netlist/solver/nld_matrix_solver.h
@@ -62,7 +62,7 @@ public:
const std::size_t term_count = this->count();
const std::size_t railstart = this->m_railstart;
- const FT * const * RESTRICT other_cur_analog = this->connected_net_V();
+ const FT * const * other_cur_analog = this->connected_net_V();
for (std::size_t i = 0; i < railstart; i++)
{
@@ -114,7 +114,7 @@ public:
: analog_output_t(dev, aname)
, m_proxied_net(pnet)
{ }
- virtual ~proxied_analog_output_t();
+ ~proxied_analog_output_t() override = default;
analog_net_t *proxied_net() const { return m_proxied_net;}
private:
@@ -136,14 +136,14 @@ public:
PREFER_BAND_MATRIX
};
- virtual ~matrix_solver_t() override;
+ ~matrix_solver_t() override = default;
void setup(analog_net_t::list_t &nets)
{
vsetup(nets);
}
- void solve_base(netlist_time time);
+ void solve_base();
/* after every call to solve, update inputs must be called.
* this can be done as well as a batch to ease parallel processing.
@@ -196,10 +196,10 @@ protected:
/* virtual */ void add_term(std::size_t net_idx, terminal_t *term);
template <typename T>
- void store(const T & RESTRICT V);
+ void store(const T & V);
template <typename T>
- auto delta(const T & RESTRICT V) -> typename std::decay<decltype(V[0])>::type;
+ auto delta(const T & V) -> typename std::decay<decltype(V[0])>::type;
template <typename T>
void build_LE_A(T &child);
@@ -239,7 +239,7 @@ private:
};
template <typename T>
-auto matrix_solver_t::delta(const T & RESTRICT V) -> typename std::decay<decltype(V[0])>::type
+auto matrix_solver_t::delta(const T & V) -> typename std::decay<decltype(V[0])>::type
{
/* NOTE: Ideally we should also include currents (RHS) here. This would
* need a reevaluation of the right hand side after voltages have been updated
@@ -254,7 +254,7 @@ auto matrix_solver_t::delta(const T & RESTRICT V) -> typename std::decay<decltyp
}
template <typename T>
-void matrix_solver_t::store(const T & RESTRICT V)
+void matrix_solver_t::store(const T & V)
{
const std::size_t iN = this->m_terms.size();
for (std::size_t i = 0; i < iN; i++)
@@ -278,7 +278,7 @@ void matrix_solver_t::build_LE_A(T &child)
const std::size_t terms_count = terms->count();
const std::size_t railstart = terms->m_railstart;
- const float_type * const RESTRICT gt = terms->gt();
+ const float_type * const gt = terms->gt();
{
float_type akk = 0.0;
@@ -288,8 +288,8 @@ void matrix_solver_t::build_LE_A(T &child)
Ak[k] = akk;
}
- const float_type * const RESTRICT go = terms->go();
- int * RESTRICT net_other = terms->connected_net_idx();
+ const float_type * const go = terms->go();
+ int * net_other = terms->connected_net_idx();
for (std::size_t i = 0; i < railstart; i++)
Ak[net_other[i]] -= go[i];
@@ -309,9 +309,9 @@ void matrix_solver_t::build_LE_RHS(T &child)
float_type rhsk_b = 0.0;
const std::size_t terms_count = m_terms[k]->count();
- const float_type * const RESTRICT go = m_terms[k]->go();
- const float_type * const RESTRICT Idr = m_terms[k]->Idr();
- const float_type * const * RESTRICT other_cur_analog = m_terms[k]->connected_net_V();
+ const float_type * const go = m_terms[k]->go();
+ const float_type * const Idr = m_terms[k]->Idr();
+ const float_type * const * other_cur_analog = m_terms[k]->connected_net_V();
for (std::size_t i = 0; i < terms_count; i++)
rhsk_a = rhsk_a + Idr[i];
diff --git a/src/lib/netlist/solver/nld_ms_direct.h b/src/lib/netlist/solver/nld_ms_direct.h
index e1583d27be6..9a73cacaa10 100644
--- a/src/lib/netlist/solver/nld_ms_direct.h
+++ b/src/lib/netlist/solver/nld_ms_direct.h
@@ -8,13 +8,13 @@
#ifndef NLD_MS_DIRECT_H_
#define NLD_MS_DIRECT_H_
-#include <netlist/plib/mat_cr.h>
-#include <netlist/plib/vector_ops.h>
#include <algorithm>
#include <cmath>
+#include <netlist/plib/mat_cr.h>
+#include <netlist/plib/vector_ops.h>
-#include "nld_solver.h"
#include "nld_matrix_solver.h"
+#include "nld_solver.h"
namespace netlist
{
@@ -32,13 +32,13 @@ public:
matrix_solver_direct_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size);
matrix_solver_direct_t(netlist_base_t &anetlist, const pstring &name, const eSortType sort, const solver_parameters_t *params, const std::size_t size);
- virtual ~matrix_solver_direct_t() override;
+ ~matrix_solver_direct_t() override = default;
- virtual void vsetup(analog_net_t::list_t &nets) override;
- virtual void reset() override { matrix_solver_t::reset(); }
+ void vsetup(analog_net_t::list_t &nets) override;
+ void reset() override { matrix_solver_t::reset(); }
protected:
- virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override;
+ unsigned vsolve_non_dynamic(const bool newton_raphson) override;
unsigned solve_non_dynamic(const bool newton_raphson);
constexpr std::size_t size() const { return (SIZE > 0) ? static_cast<std::size_t>(SIZE) : m_dim; }
@@ -46,7 +46,7 @@ protected:
void LE_solve();
template <typename T>
- void LE_back_subst(T & RESTRICT x);
+ void LE_back_subst(T & x);
FT &A(std::size_t r, std::size_t c) { return m_A[r * m_pitch + c]; }
FT &RHS(std::size_t r) { return m_A[r * m_pitch + size()]; }
@@ -67,11 +67,6 @@ private:
// ----------------------------------------------------------------------------------------
template <typename FT, int SIZE>
-matrix_solver_direct_t<FT, SIZE>::~matrix_solver_direct_t()
-{
-}
-
-template <typename FT, int SIZE>
void matrix_solver_direct_t<FT, SIZE>::vsetup(analog_net_t::list_t &nets)
{
matrix_solver_t::setup_base(nets);
@@ -85,8 +80,9 @@ void matrix_solver_direct_t<FT, SIZE>::vsetup(analog_net_t::list_t &nets)
t->m_nzrd.push_back(static_cast<unsigned>(size()));
}
+ // FIXME: This shouldn't be necessary ...
for (std::size_t k = 0; k < size(); k++)
- state().save(*this, RHS(k), plib::pfmt("RHS.{1}")(k));
+ state().save(*this, RHS(k), this->name(), plib::pfmt("RHS.{1}")(k));
}
@@ -141,10 +137,10 @@ void matrix_solver_direct_t<FT, SIZE>::LE_solve()
for (std::size_t j = i + 1; j < kN; j++)
{
const FT f1 = - A(j,i) * f;
- if (f1 != NL_FCONST(0.0))
+ if (f1 != plib::constants<FT>::zero)
{
- const FT * RESTRICT pi = &A(i,i+1);
- FT * RESTRICT pj = &A(j,i+1);
+ const FT * pi = &A(i,i+1);
+ FT * pj = &A(j,i+1);
#if 1
plib::vec_add_mult_scalar_p(kN-i,pi,f1,pj);
#else
@@ -164,7 +160,7 @@ void matrix_solver_direct_t<FT, SIZE>::LE_solve()
template <typename FT, int SIZE>
template <typename T>
void matrix_solver_direct_t<FT, SIZE>::LE_back_subst(
- T & RESTRICT x)
+ T & x)
{
const std::size_t kN = size();
diff --git a/src/lib/netlist/solver/nld_ms_direct1.h b/src/lib/netlist/solver/nld_ms_direct1.h
index 4016b8826b0..6a7ba9540da 100644
--- a/src/lib/netlist/solver/nld_ms_direct1.h
+++ b/src/lib/netlist/solver/nld_ms_direct1.h
@@ -30,7 +30,7 @@ namespace devices
// ----------------------------------------------------------------------------------------
// matrix_solver - Direct1
// ----------------------------------------------------------------------------------------
- virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override
+ unsigned vsolve_non_dynamic(const bool newton_raphson) override
{
this->build_LE_A(*this);
this->build_LE_RHS(*this);
diff --git a/src/lib/netlist/solver/nld_ms_direct2.h b/src/lib/netlist/solver/nld_ms_direct2.h
index 07ead72a353..563292c235f 100644
--- a/src/lib/netlist/solver/nld_ms_direct2.h
+++ b/src/lib/netlist/solver/nld_ms_direct2.h
@@ -26,7 +26,7 @@ namespace devices
matrix_solver_direct2_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params)
: matrix_solver_direct_t<double, 2>(anetlist, name, params, 2)
{}
- virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override;
+ unsigned vsolve_non_dynamic(const bool newton_raphson) override;
};
diff --git a/src/lib/netlist/solver/nld_ms_gcr.h b/src/lib/netlist/solver/nld_ms_gcr.h
index 31476b7e2a5..b392a6f30da 100644
--- a/src/lib/netlist/solver/nld_ms_gcr.h
+++ b/src/lib/netlist/solver/nld_ms_gcr.h
@@ -10,14 +10,14 @@
#ifndef NLD_MS_GCR_H_
#define NLD_MS_GCR_H_
-#include <netlist/plib/mat_cr.h>
#include <algorithm>
+#include <netlist/plib/mat_cr.h>
#include "../plib/pdynlib.h"
+#include "../plib/pstream.h"
+#include "../plib/vector_ops.h"
#include "nld_ms_direct.h"
#include "nld_solver.h"
-#include "../plib/vector_ops.h"
-#include "../plib/pstream.h"
namespace netlist
{
@@ -44,16 +44,14 @@ public:
{
}
- virtual ~matrix_solver_GCR_t() override
- {
- }
+ ~matrix_solver_GCR_t() override = default;
constexpr std::size_t N() const { return m_dim; }
- virtual void vsetup(analog_net_t::list_t &nets) override;
- virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override;
+ void vsetup(analog_net_t::list_t &nets) override;
+ unsigned vsolve_non_dynamic(const bool newton_raphson) override;
- virtual std::pair<pstring, pstring> create_solver_code() override;
+ std::pair<pstring, pstring> create_solver_code() override;
private:
@@ -62,7 +60,7 @@ private:
void csc_private(plib::putf8_fmt_writer &strm);
- using extsolver = void (*)(double * RESTRICT m_A, double * RESTRICT RHS, double * RESTRICT V);
+ using extsolver = void (*)(double * m_A, double * RHS, double * V);
pstring static_compile_name();
@@ -75,7 +73,7 @@ private:
mat_type mat;
//extsolver m_proc;
- plib::dynproc<void, double * RESTRICT, double * RESTRICT, double * RESTRICT> m_proc;
+ plib::dynproc<void, double * , double * , double * > m_proc;
};
diff --git a/src/lib/netlist/solver/nld_ms_gmres.h b/src/lib/netlist/solver/nld_ms_gmres.h
index 735b6d76334..2ffc98756cf 100644
--- a/src/lib/netlist/solver/nld_ms_gmres.h
+++ b/src/lib/netlist/solver/nld_ms_gmres.h
@@ -8,12 +8,12 @@
#ifndef NLD_MS_GMRES_H_
#define NLD_MS_GMRES_H_
+#include "../plib/gmres.h"
#include "../plib/mat_cr.h"
#include "../plib/parray.h"
+#include "../plib/vector_ops.h"
#include "nld_ms_direct.h"
#include "nld_solver.h"
-#include "../plib/vector_ops.h"
-#include "../plib/gmres.h"
#include <algorithm>
#include <cmath>
@@ -44,12 +44,10 @@ namespace devices
{
}
- virtual ~matrix_solver_GMRES_t() override
- {
- }
+ ~matrix_solver_GMRES_t() override = default;
- virtual void vsetup(analog_net_t::list_t &nets) override;
- virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override;
+ void vsetup(analog_net_t::list_t &nets) override;
+ unsigned vsolve_non_dynamic(const bool newton_raphson) override;
private:
@@ -77,7 +75,7 @@ namespace devices
for (std::size_t k=0; k<iN; k++)
{
fill[k].resize(iN, decltype(m_ops.m_mat)::FILL_INFINITY);
- terms_for_net_t * RESTRICT row = this->m_terms[k].get();
+ terms_for_net_t * row = this->m_terms[k].get();
for (std::size_t j=0; j < row->m_nz.size(); j++)
{
fill[k][static_cast<mattype>(row->m_nz[j])] = 0;
diff --git a/src/lib/netlist/solver/nld_ms_sm.h b/src/lib/netlist/solver/nld_ms_sm.h
index c48d85bd2b7..59409ab8269 100644
--- a/src/lib/netlist/solver/nld_ms_sm.h
+++ b/src/lib/netlist/solver/nld_ms_sm.h
@@ -35,9 +35,9 @@
#include <algorithm>
-#include "nld_solver.h"
-#include "nld_matrix_solver.h"
#include "../plib/vector_ops.h"
+#include "nld_matrix_solver.h"
+#include "nld_solver.h"
namespace netlist
{
@@ -59,13 +59,13 @@ public:
matrix_solver_sm_t(netlist_base_t &anetlist, const pstring &name,
const solver_parameters_t *params, const std::size_t size);
- virtual ~matrix_solver_sm_t() override;
+ ~matrix_solver_sm_t() override = default;
- virtual void vsetup(analog_net_t::list_t &nets) override;
- virtual void reset() override { matrix_solver_t::reset(); }
+ void vsetup(analog_net_t::list_t &nets) override;
+ void reset() override { matrix_solver_t::reset(); }
protected:
- virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override;
+ unsigned vsolve_non_dynamic(const bool newton_raphson) override;
unsigned solve_non_dynamic(const bool newton_raphson);
constexpr std::size_t size() const { return m_dim; }
@@ -73,7 +73,7 @@ protected:
void LE_invert();
template <typename T>
- void LE_compute_x(T * RESTRICT x);
+ void LE_compute_x(T * x);
template <typename T1, typename T2>
@@ -113,17 +113,13 @@ private:
// ----------------------------------------------------------------------------------------
template <typename FT, int SIZE>
-matrix_solver_sm_t<FT, SIZE>::~matrix_solver_sm_t()
-{
-}
-
-template <typename FT, int SIZE>
void matrix_solver_sm_t<FT, SIZE>::vsetup(analog_net_t::list_t &nets)
{
matrix_solver_t::setup_base(nets);
- for (unsigned k = 0; k < size(); k++)
- state().save(*this, RHS(k), plib::pfmt("RHS.{1}")(k));
+ /* FIXME: Shouldn't be necessary */
+ for (std::size_t k = 0; k < size(); k++)
+ state().save(*this, RHS(k), this->name(), plib::pfmt("RHS.{1}")(k));
}
@@ -147,12 +143,12 @@ void matrix_solver_sm_t<FT, SIZE>::LE_invert()
{
/* FIXME: Singular matrix? */
const float_type f = 1.0 / W(i,i);
- const auto * RESTRICT const p = m_terms[i]->m_nzrd.data();
+ const auto * const p = m_terms[i]->m_nzrd.data();
const std::size_t e = m_terms[i]->m_nzrd.size();
/* Eliminate column i from row j */
- const auto * RESTRICT const pb = m_terms[i]->m_nzbd.data();
+ const auto * const pb = m_terms[i]->m_nzbd.data();
const std::size_t eb = m_terms[i]->m_nzbd.size();
for (std::size_t jb = 0; jb < eb; jb++)
{
@@ -194,7 +190,7 @@ void matrix_solver_sm_t<FT, SIZE>::LE_invert()
template <typename FT, int SIZE>
template <typename T>
void matrix_solver_sm_t<FT, SIZE>::LE_compute_x(
- T * RESTRICT x)
+ T * x)
{
const std::size_t kN = size();
diff --git a/src/lib/netlist/solver/nld_ms_sor.h b/src/lib/netlist/solver/nld_ms_sor.h
index 9629bbcc1dc..bb9192a0c01 100644
--- a/src/lib/netlist/solver/nld_ms_sor.h
+++ b/src/lib/netlist/solver/nld_ms_sor.h
@@ -39,10 +39,10 @@ public:
{
}
- virtual ~matrix_solver_SOR_t() override {}
+ ~matrix_solver_SOR_t() override = default;
- virtual void vsetup(analog_net_t::list_t &nets) override;
- virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override;
+ void vsetup(analog_net_t::list_t &nets) override;
+ unsigned vsolve_non_dynamic(const bool newton_raphson) override;
private:
state_var<float_type> m_lp_fact;
@@ -87,9 +87,9 @@ unsigned matrix_solver_SOR_t<FT, SIZE>::vsolve_non_dynamic(const bool newton_rap
float_type RHS_t = 0.0;
const std::size_t term_count = this->m_terms[k]->count();
- const float_type * const RESTRICT gt = this->m_terms[k]->gt();
- const float_type * const RESTRICT go = this->m_terms[k]->go();
- const float_type * const RESTRICT Idr = this->m_terms[k]->Idr();
+ const float_type * const gt = this->m_terms[k]->gt();
+ const float_type * const go = this->m_terms[k]->go();
+ const float_type * const Idr = this->m_terms[k]->Idr();
const float_type * const *other_cur_analog = this->m_terms[k]->connected_net_V();
this->m_new_V[k] = this->m_nets[k]->Q_Analog();
@@ -110,22 +110,22 @@ unsigned matrix_solver_SOR_t<FT, SIZE>::vsolve_non_dynamic(const bool newton_rap
for (std::size_t i = 0; i < term_count; i++)
gabs_t = gabs_t + std::abs(go[i]);
- gabs_t *= NL_FCONST(0.5); // derived by try and error
+ gabs_t *= plib::constants<nl_double>()(0.5); // derived by try and error
if (gabs_t <= gtot_t)
{
w[k] = ws / gtot_t;
- one_m_w[k] = NL_FCONST(1.0) - ws;
+ one_m_w[k] = plib::constants<FT>::one - ws;
}
else
{
- w[k] = NL_FCONST(1.0) / (gtot_t + gabs_t);
- one_m_w[k] = NL_FCONST(1.0) - NL_FCONST(1.0) * gtot_t / (gtot_t + gabs_t);
+ w[k] = plib::constants<FT>::one / (gtot_t + gabs_t);
+ one_m_w[k] = plib::constants<FT>::one - plib::constants<FT>::one * gtot_t / (gtot_t + gabs_t);
}
}
else
{
w[k] = ws / gtot_t;
- one_m_w[k] = NL_FCONST(1.0) - ws;
+ one_m_w[k] = plib::constants<FT>::one - ws;
}
}
@@ -136,9 +136,9 @@ unsigned matrix_solver_SOR_t<FT, SIZE>::vsolve_non_dynamic(const bool newton_rap
float_type err = 0;
for (std::size_t k = 0; k < iN; k++)
{
- const int * RESTRICT net_other = this->m_terms[k]->connected_net_idx();
+ const int * net_other = this->m_terms[k]->connected_net_idx();
const std::size_t railstart = this->m_terms[k]->m_railstart;
- const float_type * RESTRICT go = this->m_terms[k]->go();
+ const float_type * go = this->m_terms[k]->go();
float_type Idrive = 0.0;
for (std::size_t i = 0; i < railstart; i++)
diff --git a/src/lib/netlist/solver/nld_ms_sor_mat.h b/src/lib/netlist/solver/nld_ms_sor_mat.h
index a64d6a9659a..e5f2e736708 100644
--- a/src/lib/netlist/solver/nld_ms_sor_mat.h
+++ b/src/lib/netlist/solver/nld_ms_sor_mat.h
@@ -14,8 +14,8 @@
#include <algorithm>
-#include "nld_ms_direct.h"
#include "nld_matrix_solver.h"
+#include "nld_ms_direct.h"
#include "nld_solver.h"
namespace netlist
@@ -40,11 +40,11 @@ public:
{
}
- virtual ~matrix_solver_SOR_mat_t() override {}
+ ~matrix_solver_SOR_mat_t() override = default;
- virtual void vsetup(analog_net_t::list_t &nets) override;
+ void vsetup(analog_net_t::list_t &nets) override;
- virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override;
+ unsigned vsolve_non_dynamic(const bool newton_raphson) override;
private:
//state_var<float_type[storage_N]> m_Vdelta;
@@ -192,10 +192,10 @@ unsigned matrix_solver_SOR_mat_t<FT, SIZE>::vsolve_non_dynamic(const bool newton
if (p[i] != k)
gabs_t = gabs_t + std::abs(this->A(k,p[i]));
- gabs_t *= NL_FCONST(1.0); // derived by try and error
+ gabs_t *= plib::constants<FT>::one; // derived by try and error
if (gabs_t > this->A(k,k))
{
- w = NL_FCONST(1.0) / (this->A(k,k) + gabs_t);
+ w = plib::constants<FT>::one / (this->A(k,k) + gabs_t);
}
}
diff --git a/src/lib/netlist/solver/nld_ms_w.h b/src/lib/netlist/solver/nld_ms_w.h
index d448facd5d0..7be3a81c365 100644
--- a/src/lib/netlist/solver/nld_ms_w.h
+++ b/src/lib/netlist/solver/nld_ms_w.h
@@ -42,9 +42,9 @@
#include <algorithm>
-#include "nld_solver.h"
-#include "nld_matrix_solver.h"
#include "../plib/vector_ops.h"
+#include "nld_matrix_solver.h"
+#include "nld_solver.h"
namespace netlist
{
@@ -65,13 +65,13 @@ public:
matrix_solver_w_t(netlist_base_t &anetlist, const pstring &name, const solver_parameters_t *params, const std::size_t size);
- virtual ~matrix_solver_w_t() override;
+ ~matrix_solver_w_t() override = default;
- virtual void vsetup(analog_net_t::list_t &nets) override;
- virtual void reset() override { matrix_solver_t::reset(); }
+ void vsetup(analog_net_t::list_t &nets) override;
+ void reset() override { matrix_solver_t::reset(); }
protected:
- virtual unsigned vsolve_non_dynamic(const bool newton_raphson) override;
+ unsigned vsolve_non_dynamic(const bool newton_raphson) override;
unsigned solve_non_dynamic(const bool newton_raphson);
constexpr std::size_t size() const { return m_dim; }
@@ -79,7 +79,7 @@ protected:
void LE_invert();
template <typename T>
- void LE_compute_x(T * RESTRICT x);
+ void LE_compute_x(T * x);
template <typename T1, typename T2>
@@ -126,17 +126,13 @@ private:
// ----------------------------------------------------------------------------------------
template <typename FT, int SIZE>
-matrix_solver_w_t<FT, SIZE>::~matrix_solver_w_t()
-{
-}
-
-template <typename FT, int SIZE>
void matrix_solver_w_t<FT, SIZE>::vsetup(analog_net_t::list_t &nets)
{
matrix_solver_t::setup_base(nets);
- for (unsigned k = 0; k < size(); k++)
- state().save(*this, RHS(k), plib::pfmt("RHS.{1}")(k));
+ // FIXME: This shouldn't be necessary, recalculate on each entry ...
+ for (std::size_t k = 0; k < size(); k++)
+ state().save(*this, RHS(k), this->name(), plib::pfmt("RHS.{1}")(k));
}
@@ -160,12 +156,12 @@ void matrix_solver_w_t<FT, SIZE>::LE_invert()
{
/* FIXME: Singular matrix? */
const float_type f = 1.0 / W(i,i);
- const auto * RESTRICT const p = m_terms[i]->m_nzrd.data();
+ const auto * const p = m_terms[i]->m_nzrd.data();
const size_t e = m_terms[i]->m_nzrd.size();
/* Eliminate column i from row j */
- const auto * RESTRICT const pb = m_terms[i]->m_nzbd.data();
+ const auto * const pb = m_terms[i]->m_nzbd.data();
const size_t eb = m_terms[i]->m_nzbd.size();
for (std::size_t jb = 0; jb < eb; jb++)
{
@@ -206,7 +202,7 @@ void matrix_solver_w_t<FT, SIZE>::LE_invert()
template <typename FT, int SIZE>
template <typename T>
void matrix_solver_w_t<FT, SIZE>::LE_compute_x(
- T * RESTRICT x)
+ T * x)
{
const std::size_t kN = size();
@@ -343,7 +339,7 @@ unsigned matrix_solver_w_t<FT, SIZE>::solve_non_dynamic(const bool newton_raphso
}
m_cnt++;
- if (0)
+ if (false)
for (unsigned i=0; i<iN; i++)
{
float_type tmp = 0.0;
diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp
index 6779e50088b..6b2f3f675b6 100644
--- a/src/lib/netlist/solver/nld_solver.cpp
+++ b/src/lib/netlist/solver/nld_solver.cpp
@@ -40,8 +40,8 @@
#include "../nl_factory.h"
-#include "nld_solver.h"
#include "nld_matrix_solver.h"
+#include "nld_solver.h"
#if 1
#include "nld_ms_direct.h"
@@ -49,13 +49,13 @@
#else
#include "nld_ms_direct_lu.h"
#endif
-#include "nld_ms_w.h"
-#include "nld_ms_sm.h"
#include "nld_ms_direct1.h"
#include "nld_ms_direct2.h"
+#include "nld_ms_gmres.h"
+#include "nld_ms_sm.h"
#include "nld_ms_sor.h"
#include "nld_ms_sor_mat.h"
-#include "nld_ms_gmres.h"
+#include "nld_ms_w.h"
namespace netlist
{
@@ -70,14 +70,14 @@ namespace netlist
NETLIB_RESET(solver)
{
- for (std::size_t i = 0; i < m_mat_solvers.size(); i++)
- m_mat_solvers[i]->reset();
+ for (auto &s : m_mat_solvers)
+ s->reset();
}
void NETLIB_NAME(solver)::stop()
{
- for (std::size_t i = 0; i < m_mat_solvers.size(); i++)
- m_mat_solvers[i]->log_stats();
+ for (auto &s : m_mat_solvers)
+ s->log_stats();
}
NETLIB_NAME(solver)::~NETLIB_NAME(solver)()
@@ -206,8 +206,8 @@ struct net_splitter
{
if (p->is_type(detail::terminal_type::TERMINAL))
{
- terminal_t *pt = static_cast<terminal_t *>(p);
- analog_net_t *other_net = &pt->m_otherterm->net();
+ auto *pt = static_cast<terminal_t *>(p);
+ analog_net_t *other_net = &pt->otherterm()->net();
if (!already_processed(other_net))
process_net(other_net);
}
@@ -223,10 +223,10 @@ struct net_splitter
{
netlist.log().debug(" ==> not a rail net\n");
/* Must be an analog net */
- analog_net_t *n = static_cast<analog_net_t *>(net.get());
+ auto *n = static_cast<analog_net_t *>(net.get());
if (!already_processed(n))
{
- groups.push_back(analog_net_t::list_t());
+ groups.emplace_back(analog_net_t::list_t());
process_net(n);
}
}
@@ -382,7 +382,7 @@ void NETLIB_NAME(solver)::post_start()
else
{
log().fatal(MF_1_NETGROUP_SIZE_EXCEEDED_1, 128);
- ms = nullptr; /* tease compilers */
+ return; /* tease compilers */
}
break;
}
diff --git a/src/lib/netlist/solver/nld_solver.h b/src/lib/netlist/solver/nld_solver.h
index 19eca289264..f9156c4441f 100644
--- a/src/lib/netlist/solver/nld_solver.h
+++ b/src/lib/netlist/solver/nld_solver.h
@@ -44,18 +44,18 @@ NETLIB_OBJECT(solver)
, m_gs_loops(*this, "GS_LOOPS", 9) // Gauss-Seidel loops
/* general parameters */
- , m_gmin(*this, "GMIN", NETLIST_GMIN_DEFAULT)
- , m_pivot(*this, "PIVOT", 0) // use pivoting - on supported solvers
+ , m_gmin(*this, "GMIN", 1e-9)
+ , m_pivot(*this, "PIVOT", false) // use pivoting - on supported solvers
, m_nr_loops(*this, "NR_LOOPS", 250) // Newton-Raphson loops
, m_nr_recalc_delay(*this, "NR_RECALC_DELAY", NLTIME_FROM_NS(10).as_double()) // Delay to next solve attempt if nr loops exceeded
, m_parallel(*this, "PARALLEL", 0)
/* automatic time step */
- , m_dynamic_ts(*this, "DYNAMIC_TS", 0)
+ , m_dynamic_ts(*this, "DYNAMIC_TS", false)
, m_dynamic_lte(*this, "DYNAMIC_LTE", 1e-5) // diff/timestep
, m_dynamic_min_ts(*this, "DYNAMIC_MIN_TIMESTEP", 1e-6) // nl_double timestep resolution
- , m_log_stats(*this, "LOG_STATS", 1) // log statistics on shutdown
+ , m_log_stats(*this, "LOG_STATS", true) // log statistics on shutdown
, m_params()
{
// internal staff
@@ -63,7 +63,7 @@ NETLIB_OBJECT(solver)
connect(m_fb_step, m_Q_step);
}
- virtual ~NETLIB_NAME(solver)() override;
+ ~NETLIB_NAME(solver)() override;
void post_start();
void stop();
diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp
index da9325d70d9..da2fd681572 100644
--- a/src/lib/netlist/tools/nl_convert.cpp
+++ b/src/lib/netlist/tools/nl_convert.cpp
@@ -5,12 +5,12 @@
*
*/
+#include "../plib/palloc.h"
+#include "../plib/putil.h"
+#include "nl_convert.h"
#include <algorithm>
#include <cmath>
#include <unordered_map>
-#include "nl_convert.h"
-#include "../plib/palloc.h"
-#include "../plib/putil.h"
/* FIXME: temporarily defined here - should be in a file */
/* FIXME: family logic in netlist is convoluted, create
@@ -305,7 +305,7 @@ void nl_convert_spice_t::process_line(const pstring &line)
pstring model;
pstring pins ="CBE";
bool err;
- long nval = plib::pstonum_ne<long>(tt[4], err);
+ auto nval = plib::pstonum_ne<long>(tt[4], err);
plib::unused_var(nval);
if ((err || plib::startsWith(tt[4], "N")) && tt.size() > 5)
diff --git a/src/lib/netlist/tools/nl_convert.h b/src/lib/netlist/tools/nl_convert.h
index 1433f75664c..366249343c9 100644
--- a/src/lib/netlist/tools/nl_convert.h
+++ b/src/lib/netlist/tools/nl_convert.h
@@ -10,10 +10,10 @@
#ifndef NL_CONVERT_H_
#define NL_CONVERT_H_
-#include <memory>
-#include "../plib/pstring.h"
#include "../plib/plists.h"
#include "../plib/pparser.h"
+#include "../plib/pstring.h"
+#include <memory>
/*-------------------------------------------------
convert - convert a spice netlist
@@ -140,9 +140,7 @@ class nl_convert_spice_t : public nl_convert_base_t
public:
nl_convert_spice_t() : nl_convert_base_t() {}
- virtual ~nl_convert_spice_t() override
- {
- }
+ ~nl_convert_spice_t() override = default;
void convert(const pstring &contents) override;
@@ -159,9 +157,7 @@ class nl_convert_eagle_t : public nl_convert_base_t
public:
nl_convert_eagle_t() : nl_convert_base_t() {}
- virtual ~nl_convert_eagle_t() override
- {
- }
+ ~nl_convert_eagle_t() override = default;
class tokenizer : public plib::ptokenizer
{
@@ -175,7 +171,7 @@ public:
protected:
- virtual void verror(const pstring &msg, int line_num, const pstring &line) override;
+ void verror(const pstring &msg, int line_num, const pstring &line) override;
private:
nl_convert_eagle_t &m_convert;
@@ -195,9 +191,7 @@ class nl_convert_rinf_t : public nl_convert_base_t
public:
nl_convert_rinf_t() : nl_convert_base_t() {}
- virtual ~nl_convert_rinf_t() override
- {
- }
+ ~nl_convert_rinf_t() override = default;
class tokenizer : public plib::ptokenizer
{
@@ -216,7 +210,7 @@ public:
protected:
- virtual void verror(const pstring &msg, int line_num, const pstring &line) override;
+ void verror(const pstring &msg, int line_num, const pstring &line) override;
private:
nl_convert_rinf_t &m_convert;