netlist: more cpp core guidelines work. (nw)

This commit is contained in:
couriersud 2019-02-08 08:04:40 +01:00
parent a44729fdfa
commit f4c0f8c74b
20 changed files with 69 additions and 58 deletions

View File

@ -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

View File

@ -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;
};

View File

@ -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),

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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;
};
// -----------------------------------------------------------------------------

View File

@ -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);

View File

@ -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)

View File

@ -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++)

View File

@ -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)

View File

@ -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;

View File

@ -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];
};

View File

@ -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;

View File

@ -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

View File

@ -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];
}

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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)

View File

@ -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));
}