diff options
author | couriersud <couriersud@gmx.org> | 2019-02-08 08:04:40 +0100 |
---|---|---|
committer | couriersud <couriersud@gmx.org> | 2019-02-08 23:18:47 +0100 |
commit | f4c0f8c74bc6433683098946d6c3fc4398a3cb87 (patch) | |
tree | c86bea87812cb8a0fb57d627564f758f49980bde | |
parent | a44729fdfa9161c79eb2d1983bcf9c1ffed51a04 (diff) |
netlist: more cpp core guidelines work. (nw)
-rw-r--r-- | src/lib/netlist/build/makefile | 2 | ||||
-rw-r--r-- | src/lib/netlist/devices/nld_2102A.cpp | 2 | ||||
-rw-r--r-- | src/lib/netlist/devices/nld_4020.cpp | 2 | ||||
-rw-r--r-- | src/lib/netlist/devices/nld_82S16.cpp | 2 | ||||
-rw-r--r-- | src/lib/netlist/devices/nld_am2847.cpp | 2 | ||||
-rw-r--r-- | src/lib/netlist/devices/nlid_system.h | 4 | ||||
-rw-r--r-- | src/lib/netlist/devices/nlid_truthtable.cpp | 4 | ||||
-rw-r--r-- | src/lib/netlist/devices/nlid_truthtable.h | 8 | ||||
-rw-r--r-- | src/lib/netlist/nl_base.h | 22 | ||||
-rw-r--r-- | src/lib/netlist/nl_parser.cpp | 11 | ||||
-rw-r--r-- | src/lib/netlist/plib/gmres.h | 16 | ||||
-rw-r--r-- | src/lib/netlist/plib/plists.h | 1 | ||||
-rw-r--r-- | src/lib/netlist/plib/pmain.cpp | 2 | ||||
-rw-r--r-- | src/lib/netlist/plib/pmain.h | 6 | ||||
-rw-r--r-- | src/lib/netlist/plib/poptions.cpp | 6 | ||||
-rw-r--r-- | src/lib/netlist/plib/poptions.h | 4 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstate.h | 9 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstream.h | 12 | ||||
-rw-r--r-- | src/lib/netlist/plib/pstring.h | 2 | ||||
-rw-r--r-- | src/lib/netlist/prg/nltool.cpp | 10 |
20 files changed, 69 insertions, 58 deletions
diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index 8996ba242ec..495c4ed1316 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -23,7 +23,7 @@ TIDY_FLAGSX += -cppcoreguidelines-special-member-functions,-cppcoreguidelines-pr 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 += -cppcoreguidelines-avoid-c-arrays,-modernize-avoid-c-arrays, TIDY_FLAGSX += -performance-unnecessary-copy-initialization, TIDY_FLAGSX += -bugprone-macro-parentheses diff --git a/src/lib/netlist/devices/nld_2102A.cpp b/src/lib/netlist/devices/nld_2102A.cpp index b364e7ff448..59d9a9b5788 100644 --- a/src/lib/netlist/devices/nld_2102A.cpp +++ b/src/lib/netlist/devices/nld_2102A.cpp @@ -39,7 +39,7 @@ namespace netlist logic_output_t m_DO; - state_var<uint8_t[128]> m_ram; // 1024x1 bits + state_array<uint8_t, 128> m_ram; // 1024x1 bits param_ptr_t m_RAM; }; diff --git a/src/lib/netlist/devices/nld_4020.cpp b/src/lib/netlist/devices/nld_4020.cpp index 35daf46d854..88cc05ada8f 100644 --- a/src/lib/netlist/devices/nld_4020.cpp +++ b/src/lib/netlist/devices/nld_4020.cpp @@ -98,7 +98,7 @@ namespace netlist NETLIB_FUNC_VOID(CD4020_sub, update_outputs, (const unsigned cnt)) { - /* static */ const netlist_time out_delayQn[14] = { + static const std::array<netlist_time, 14> out_delayQn = { NLTIME_FROM_NS(180), NLTIME_FROM_NS(280), NLTIME_FROM_NS(380), NLTIME_FROM_NS(480), NLTIME_FROM_NS(580), NLTIME_FROM_NS(680), diff --git a/src/lib/netlist/devices/nld_82S16.cpp b/src/lib/netlist/devices/nld_82S16.cpp index 1b3362b40cd..fe64334b0c2 100644 --- a/src/lib/netlist/devices/nld_82S16.cpp +++ b/src/lib/netlist/devices/nld_82S16.cpp @@ -74,7 +74,7 @@ namespace netlist logic_input_t m_DIN; logic_output_t m_DOUTQ; - state_var<uint64_t[4]> m_ram; // 256 bits + state_array<uint64_t, 4> m_ram; // 256 bits state_var_u8 m_addr; // 256 bits state_var_sig m_enq; }; diff --git a/src/lib/netlist/devices/nld_am2847.cpp b/src/lib/netlist/devices/nld_am2847.cpp index af7cf1ff2f7..71e46e316f1 100644 --- a/src/lib/netlist/devices/nld_am2847.cpp +++ b/src/lib/netlist/devices/nld_am2847.cpp @@ -30,7 +30,7 @@ namespace netlist logic_input_t m_RC; logic_input_t m_IN; - state_var<uint16_t[5]> m_buffer; + state_array<uint16_t, 5> m_buffer; logic_output_t m_OUT; }; diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index f98a74f043f..3b61bcb3296 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -125,7 +125,7 @@ namespace netlist std::vector<pstring> pat(plib::psplit(m_pattern(),",")); m_off = netlist_time::from_double(m_offset()); - netlist_time::mult_type pati[32] = { 0 }; + std::array<netlist_time::mult_type, 32> pati = { 0 }; m_size = static_cast<std::uint8_t>(pat.size()); netlist_time::mult_type total = 0; @@ -163,7 +163,7 @@ namespace netlist state_var_u8 m_cnt; std::uint8_t m_size; state_var<netlist_time> m_off; - netlist_time m_inc[32]; + std::array<netlist_time, 32> m_inc; }; // ----------------------------------------------------------------------------- diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp index 5eda50e0357..ffac497d482 100644 --- a/src/lib/netlist/devices/nlid_truthtable.cpp +++ b/src/lib/netlist/devices/nlid_truthtable.cpp @@ -228,8 +228,8 @@ namespace netlist { typedef nld_truthtable_t<m_NI, m_NO> tt_type; truthtable_parser desc_s(m_NO, m_NI, &m_ttbl.m_initialized, - packed_int(m_ttbl.m_out_state, sizeof(m_ttbl.m_out_state[0]) * 8), - m_ttbl.m_timing_index, m_ttbl.m_timing_nt); + packed_int(m_ttbl.m_out_state.data(), sizeof(m_ttbl.m_out_state[0]) * 8), + m_ttbl.m_timing_index.data(), m_ttbl.m_timing_nt.data()); desc_s.parse(m_desc); return plib::owned_ptr<device_t>::Create<tt_type>(anetlist, name, m_family, m_ttbl, m_desc); diff --git a/src/lib/netlist/devices/nlid_truthtable.h b/src/lib/netlist/devices/nlid_truthtable.h index c344feda2d4..6067a69113b 100644 --- a/src/lib/netlist/devices/nlid_truthtable.h +++ b/src/lib/netlist/devices/nlid_truthtable.h @@ -94,9 +94,9 @@ namespace devices , 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]; + std::array<type_t, m_size> m_out_state; + std::array<uint_least8_t, m_size * m_NO> m_timing_index; + std::array<netlist_time, 16> m_timing_nt; bool m_initialized; }; @@ -193,7 +193,7 @@ namespace devices const std::size_t timebase(nstate * m_NO); const auto *t(&m_ttp.m_timing_index[timebase]); - const auto *tim = m_ttp.m_timing_nt; + const auto *tim = m_ttp.m_timing_nt.data(); if (doOUT) for (std::size_t i = 0; i < m_NO; out >>= 1, ++i) diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index 58563c91610..b1dbd23d931 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -343,25 +343,25 @@ namespace netlist * Please refer to \ref state_var. */ template <typename T, std::size_t N> - struct state_var<T[N]> + struct state_array { public: //! Constructor. template <typename O> - state_var(O &owner, //!< owner must have a netlist() method. + state_array(O &owner, //!< owner must have a netlist() method. const pstring &name, //!< identifier/name for this state variable const T &value //!< Initial value after construction ); //! Copy Constructor. - state_var(const state_var &rhs) NL_NOEXCEPT = default; + state_array(const state_array &rhs) NL_NOEXCEPT = default; //! Move Constructor. - state_var(state_var &&rhs) NL_NOEXCEPT = default; - state_var &operator=(const state_var &rhs) NL_NOEXCEPT = default; - state_var &operator=(const T &rhs) NL_NOEXCEPT { m_value = rhs; return *this; } + state_array(state_array &&rhs) NL_NOEXCEPT = default; + state_array &operator=(const state_array &rhs) NL_NOEXCEPT = default; + state_array &operator=(const T &rhs) NL_NOEXCEPT { m_value = rhs; return *this; } T & operator[](const std::size_t i) NL_NOEXCEPT { return m_value[i]; } - constexpr T & operator[](const std::size_t i) const NL_NOEXCEPT { return m_value[i]; } + constexpr const T & operator[](const std::size_t i) const NL_NOEXCEPT { return m_value[i]; } private: - T m_value[N]; + std::array<T, N> m_value; }; // ----------------------------------------------------------------------------- @@ -1071,7 +1071,7 @@ namespace netlist } private: - ST m_data[1 << AW]; + std::array<ST, 1 << AW> m_data; }; // ----------------------------------------------------------------------------- @@ -1433,7 +1433,7 @@ namespace netlist public: struct init { - const char *p[N]; + std::array<const char *, N> p; }; template<typename... Args> object_array_t(core_device_t &dev, init names, Args&&... args) @@ -1682,7 +1682,7 @@ namespace netlist template <typename T, std::size_t N> template <typename O> - state_var<T[N]>::state_var(O &owner, const pstring &name, const T & value) + state_array<T,N>::state_array(O &owner, const pstring &name, const T & value) { owner.state().save(owner, m_value, owner.name(), name); for (std::size_t i=0; i<N; i++) diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp index f28eb822a09..cecfbe862bf 100644 --- a/src/lib/netlist/nl_parser.cpp +++ b/src/lib/netlist/nl_parser.cpp @@ -357,7 +357,7 @@ void parser_t::device(const pstring &dev_type) m_setup.register_dev(dev_type, devname); m_setup.log().debug("Parser: IC: {1}\n", devname); - for (pstring tp : paramlist) + for (const pstring &tp : paramlist) { require_token(m_tok_comma); if (plib::startsWith(tp, "+")) @@ -397,13 +397,12 @@ void parser_t::device(const pstring &dev_type) 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}; - int i; - int f=0; + static std::array<pstring, 6> macs = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"}; + static std::array<nl_double, 6> facs = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12}; + std::size_t f=0; nl_double ret; - for (i=1; i<6;i++) + for (std::size_t i=1; i<macs.size();i++) if (tok.str() == macs[i]) f = i; if (f>0) diff --git a/src/lib/netlist/plib/gmres.h b/src/lib/netlist/plib/gmres.h index 2b7f013c6ff..e6012aa02a6 100644 --- a/src/lib/netlist/plib/gmres.h +++ b/src/lib/netlist/plib/gmres.h @@ -246,6 +246,10 @@ namespace plib if (rho < rho_delta) return itr_used + 1; + /* FIXME: The "+" is necessary to avoid link issues + * on some systems / compiler versions. Issue reported by + * AJR, no details known yet. + */ vec_set_scalar(RESTART+1, m_g, +constants<FT>::zero); m_g[0] = rho; @@ -327,14 +331,14 @@ namespace plib plib::parray<float_type, SIZE> residual; plib::parray<float_type, SIZE> Ax; - float_type m_c[RESTART + 1]; /* mr + 1 */ - float_type m_g[RESTART + 1]; /* mr + 1 */ - float_type m_ht[RESTART + 1][RESTART]; /* (mr + 1), mr */ - float_type m_s[RESTART + 1]; /* mr + 1 */ - float_type m_y[RESTART + 1]; /* mr + 1 */ + std::array<float_type, RESTART + 1> m_c; /* mr + 1 */ + std::array<float_type, RESTART + 1> m_g; /* mr + 1 */ + std::array<std::array<float_type, RESTART>, RESTART + 1> m_ht; /* (mr + 1), mr */ + std::array<float_type, RESTART + 1> m_s; /* mr + 1 */ + std::array<float_type, RESTART + 1> m_y; /* mr + 1 */ //plib::parray<float_type, SIZE> m_v[RESTART + 1]; /* mr + 1, n */ - float_type m_v[RESTART + 1][storage_N]; /* mr + 1, n */ + std::array<std::array<float_type, storage_N>, RESTART + 1> m_v; /* mr + 1, n */ std::size_t m_size; diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 3ba7dd2fb4f..ee6a5497dd3 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -73,6 +73,7 @@ protected: private: /* ensure proper alignment */ + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays) typename std::aligned_storage<sizeof(C), alignof(C)>::type m_buf[N]; }; diff --git a/src/lib/netlist/plib/pmain.cpp b/src/lib/netlist/plib/pmain.cpp index 25022ed9734..b381d96dca7 100644 --- a/src/lib/netlist/plib/pmain.cpp +++ b/src/lib/netlist/plib/pmain.cpp @@ -43,7 +43,7 @@ namespace plib { } - int app::main_utfX(int argc, char *argv[]) + int app::main_utfX(int argc, char **argv) { auto r = this->parse(argc, argv); int ret = 0; diff --git a/src/lib/netlist/plib/pmain.h b/src/lib/netlist/plib/pmain.h index 78e5213713f..04a8dd0bc53 100644 --- a/src/lib/netlist/plib/pmain.h +++ b/src/lib/netlist/plib/pmain.h @@ -23,7 +23,7 @@ extern "C" int wmain(int argc, wchar_t *argv[]) { return plib::app::mainrun<appclass, wchar_t>(argc, argv); } #else #define PMAIN(appclass) \ -int main(int argc, char *argv[]) { return plib::app::mainrun<appclass, char>(argc, argv); } +int main(int argc, char **argv) { return plib::app::mainrun<appclass, char>(argc, argv); } #endif @@ -48,14 +48,14 @@ namespace plib { plib::putf8_fmt_writer perr; template <class C, typename T> - static int mainrun(int argc, T *argv[]) + static int mainrun(int argc, T **argv) { auto a = std::unique_ptr<C>(new C); return a->main_utfX(argc, argv); } private: - int main_utfX(int argc, char *argv[]); + int main_utfX(int argc, char **argv); #ifdef _WIN32 int main_utfX(int argc, wchar_t *argv[]); #endif diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp index 84e08715ec3..cd40c5d5492 100644 --- a/src/lib/netlist/plib/poptions.cpp +++ b/src/lib/netlist/plib/poptions.cpp @@ -51,7 +51,7 @@ namespace plib { { } - options::options(option *o[]) + options::options(option **o) : m_other_args(nullptr) { int i=0; @@ -100,7 +100,7 @@ namespace plib { } } - int options::parse(int argc, char *argv[]) + int options::parse(int argc, char **argv) { check_consistency(); m_app = pstring(argv[0]); @@ -122,7 +122,7 @@ namespace plib { has_equal_arg = (v.size() > 1); if (has_equal_arg) { - for (unsigned j = 1; j < v.size() - 1; j++) + for (std::size_t j = 1; j < v.size() - 1; j++) opt_arg = opt_arg + v[j] + "="; opt_arg += v[v.size()-1]; } diff --git a/src/lib/netlist/plib/poptions.h b/src/lib/netlist/plib/poptions.h index d34dc4935ba..091adfb6d8f 100644 --- a/src/lib/netlist/plib/poptions.h +++ b/src/lib/netlist/plib/poptions.h @@ -222,12 +222,12 @@ class options public: options(); - explicit options(option *o[]); + explicit options(option **o); ~options(); void register_option(option_base *opt); - int parse(int argc, char *argv[]); + int parse(int argc, char **argv); pstring help(pstring description, pstring usage, unsigned width = 72, unsigned indent = 20) const; diff --git a/src/lib/netlist/plib/pstate.h b/src/lib/netlist/plib/pstate.h index 19dbc03bc46..9fdd78a4263 100644 --- a/src/lib/netlist/plib/pstate.h +++ b/src/lib/netlist/plib/pstate.h @@ -11,6 +11,7 @@ #include "pstring.h" #include "ptypes.h" +#include <array> #include <memory> #include <vector> @@ -90,7 +91,7 @@ public: } template<typename C, std::size_t N> - void save_item(const void *owner, C (&state)[N], const pstring &stname) + void save_item(const void *owner, C (&state)[N], const pstring &stname) // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays) { save_state_ptr(owner, stname, dtype<C>(), N, &(state[0])); } @@ -107,6 +108,12 @@ public: save_state_ptr(owner, stname, dtype<C>(), v.size(), v.data()); } + template<typename C, std::size_t N> + void save_item(const void *owner, std::array<C, N> &a, const pstring &stname) + { + save_state_ptr(owner, stname, dtype<C>(), N, a.data()); + } + void pre_save(); void post_load(); void remove_save_items(const void *owner); diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index a74295ba369..8e47cc02a6b 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -416,8 +416,8 @@ public: friend struct constructor_helper; template <typename T> - 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)))) + putf8_reader(T &&strm) // NOLINT(misc-forwarding-reference-overload, bugprone-forwarding-reference-overload) + : m_strm(std::move(constructor_helper<T>()(std::move(strm)))) // NOLINT(bugprone-move-forwarding-reference) {} bool eof() const { return m_strm->eof(); } @@ -430,7 +430,7 @@ public: bool readcode(putf8string::traits_type::code_t &c) { - pistream::value_type b[4]; + std::array<pistream::value_type, 4> b{0}; if (m_strm->read(&b[0], 1) != 1) return false; const std::size_t l = putf8string::traits_type::codelen(reinterpret_cast<putf8string::traits_type::mem_t *>(&b)); @@ -587,10 +587,10 @@ private: inline void copystream(postream &dest, pistream &src) { - postream::value_type buf[1024]; + std::array<postream::value_type, 1024> buf; // NOLINT(cppcoreguidelines-pro-type-member-init) pstream::pos_type r; - while ((r=src.read(buf, 1024)) > 0) - dest.write(buf, r); + while ((r=src.read(buf.data(), 1024)) > 0) + dest.write(buf.data(), r); } diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index 4ecfd145c95..a4c4936cffc 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -107,7 +107,7 @@ public: template<typename C, std::size_t N, class = typename std::enable_if<std::is_same<C, const mem_t>::value>::type> - pstring_t(C (&string)[N]) + pstring_t(C (&string)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays) { static_assert(N > 0,"pstring from array of length 0"); if (string[N-1] != 0) diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index cba5cd60500..e9011b698a4 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -281,14 +281,14 @@ struct input_t input_t(const netlist::setup_t &setup, const pstring &line) : m_value(0.0) { - char buf[400]; + std::array<char, 400> buf; // NOLINT(cppcoreguidelines-pro-type-member-init) double t; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - int e = sscanf(line.c_str(), "%lf,%[^,],%lf", &t, buf, &m_value); + int e = sscanf(line.c_str(), "%lf,%[^,],%lf", &t, buf.data(), &m_value); if (e != 3) throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line)); m_time = netlist::netlist_time::from_double(t); - m_param = setup.find_param(pstring(buf), true); + m_param = setup.find_param(pstring(buf.data()), true); } void setparam() @@ -653,13 +653,13 @@ void tool_app_t::listdevices() } } out += ")"; - printf("%s\n", out.c_str()); + pout("{}\n", out); if (terms.size() > 0) { pstring t = ""; for (auto & j : terms) t += "," + j; - printf("\tTerminals: %s\n", t.substr(1).c_str()); + pout("\tTerminals: {}\n", t.substr(1)); } devs.emplace_back(std::move(d)); } |