diff options
author | 2019-02-06 10:24:34 +0100 | |
---|---|---|
committer | 2019-02-07 21:54:11 +0100 | |
commit | 3b899b86e67e3a5cc093d2dd9c0dcaeed197c806 (patch) | |
tree | 5efe135d75b1fd837549719bfa6572802870be1b /src/lib/netlist/plib | |
parent | c8d0db0c83d4b72e86f6255b95ff45ccc475d85d (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.
Diffstat (limited to 'src/lib/netlist/plib')
35 files changed, 322 insertions, 422 deletions
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 |