From 07ec6f43782d8c6d421540e906b848e40fb01027 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 5 Jun 2016 03:07:56 +0200 Subject: [PATCH] Rewrote for loops to use auto : semantics. (nw) --- src/lib/netlist/devices/nld_truthtable.h | 24 ++++++++++++------------ src/lib/netlist/devices/nlid_system.h | 2 +- src/lib/netlist/nl_base.cpp | 9 ++++----- src/lib/netlist/nl_setup.cpp | 24 ++++++++++-------------- src/lib/netlist/plib/plists.h | 2 +- src/lib/netlist/plib/poptions.h | 15 +++++++-------- src/lib/netlist/plib/pparser.cpp | 10 +++++----- src/lib/netlist/plib/pstate.cpp | 12 ++++++------ src/lib/netlist/plib/pstring.cpp | 16 ++++++++-------- src/lib/netlist/prg/nltool.cpp | 14 ++++++-------- 10 files changed, 60 insertions(+), 68 deletions(-) diff --git a/src/lib/netlist/devices/nld_truthtable.h b/src/lib/netlist/devices/nld_truthtable.h index c227da33fdc..17b646529bd 100644 --- a/src/lib/netlist/devices/nld_truthtable.h +++ b/src/lib/netlist/devices/nld_truthtable.h @@ -163,13 +163,13 @@ public: plib::pstring_vector_t out(io[1], ","); nl_assert_always(out.size() == m_NO, "output count wrong"); - for (unsigned i=0; i < m_NI; i++) + for (std::size_t i=0; i < m_NI; i++) { //new (&m_I[i]) logic_input_t(); inout[i] = inout[i].trim(); m_I.emplace(i, *this, inout[i]); } - for (unsigned i=0; i < m_NO; i++) + for (std::size_t i=0; i < m_NO; i++) { //new (&m_Q[i]) logic_output_t(); out[i] = out[i].trim(); @@ -179,7 +179,7 @@ public: // Connect output "Q" to input "_Q" if this exists // This enables timed state without having explicit state .... UINT32 disabled_ignore = 0; - for (unsigned i=0; i < m_NO; i++) + for (std::size_t i=0; i < m_NO; i++) { pstring tmp = "_" + out[i]; const int idx = inout.indexof(tmp); @@ -213,9 +213,9 @@ public: { m_active = 0; m_ign = 0; - for (unsigned i = 0; i < m_NI; i++) + for (std::size_t i = 0; i < m_NI; i++) m_I[i].activate(); - for (unsigned i=0; im_Q[i].net().num_cons()>0) m_active++; m_last_state = 0; @@ -249,7 +249,7 @@ public: if (m_NI > 1 && has_state == 0) if (--m_active == 0) { - for (unsigned i = 0; i< m_NI; i++) + for (std::size_t i = 0; i< m_NI; i++) m_I[i].inactivate(); m_ign = (1< 1 && !has_state) - for (unsigned i = 0; i < m_NI; i++) + for (std::size_t i = 0; i < m_NI; i++) { if (!doOUT || (m_ign & (1<m_I[i].net().time(), mt); } else - for (unsigned i = 0; i < m_NI; i++) + for (std::size_t i = 0; i < m_NI; i++) state |= (INPLOGIC(m_I[i]) << i); const UINT32 nstate = state | (has_state ? (m_last_state << m_NI) : 0); @@ -297,16 +297,16 @@ private: const UINT32 timebase = nstate * m_NO; if (doOUT) { - for (unsigned i = 0; i < m_NO; i++) + for (std::size_t i = 0; i < m_NO; i++) OUTLOGIC(m_Q[i], (out >> i) & 1, m_ttp->m_timing_nt[m_ttp->m_timing[timebase + i]]); } else - for (unsigned i = 0; i < m_NO; i++) + for (std::size_t i = 0; i < m_NO; i++) m_Q[i].net().set_Q_time((out >> i) & 1, mt + m_ttp->m_timing_nt[m_ttp->m_timing[timebase + i]]); if (m_NI > 1 && !has_state) { - for (unsigned i = 0; i < m_NI; i++) + for (std::size_t i = 0; i < m_NI; i++) if (m_ign & (1 << i)) m_I[i].inactivate(); } diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index d481c9e9bdd..8547fcfe22f 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -311,7 +311,7 @@ namespace netlist , m_Q(*this, "Q") { - for (int i=0; i < m_N; i++) + for (std::size_t i=0; i < m_N; i++) m_I.emplace(i, *this, plib::pfmt("A{1}")(i)); plib::pstring_vector_t cmds(m_func.Value(), " "); diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index f00736c8b27..1bac7bc5fa2 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -299,8 +299,8 @@ void netlist_t::reset() // m_solver->do_reset(); // Reset all nets once ! - for (std::size_t i = 0; i < m_nets.size(); i++) - m_nets[i]->reset(); + for (auto & n : m_nets) + n->reset(); // Reset all devices once ! for (auto & dev : m_devices) @@ -384,9 +384,8 @@ void netlist_t::print_stats() const { #if (NL_KEEP_STATISTICS) { - for (std::size_t i = 0; i < m_devices.size(); i++) + for (auto & entry : m_devices) { - core_device_t *entry = m_devices[i].get(); printf("Device %20s : %12d %12d %15ld\n", entry->name().cstr(), entry->stat_call_count, entry->stat_update_count, (long int) entry->stat_total_time / (entry->stat_update_count + 1)); } printf("Queue Pushes %15d\n", queue().m_prof_call); @@ -642,7 +641,7 @@ void net_t::rebuild_list() unsigned cnt = 0; m_list_active.clear(); - for (core_terminal_t *term : m_core_terms) + for (auto & term : m_core_terms) if (term->state() != logic_t::STATE_INP_PASSIVE) { m_list_active.add(*term); diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 3e086498439..3a16c4328d0 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -461,7 +461,7 @@ devices::nld_base_proxy *setup_t::get_d_a_proxy(core_terminal_t &out) /* connect all existing terminals to new net */ - for (core_terminal_t *p : out.net().m_core_terms) + for (auto & p : out.net().m_core_terms) { p->clear_net(); // de-link from all nets ... if (!connect(new_proxy->proxy_term(), *p)) @@ -615,7 +615,7 @@ bool setup_t::connect_input_input(core_terminal_t &t1, core_terminal_t &t2) ret = connect(t2, t1.net().railterminal()); if (!ret) { - for (core_terminal_t *t : t1.net().m_core_terms) + for (auto & t : t1.net().m_core_terms) { if (t->is_type(core_terminal_t::TERMINAL)) ret = connect(t2, *t); @@ -630,7 +630,7 @@ bool setup_t::connect_input_input(core_terminal_t &t1, core_terminal_t &t2) ret = connect(t1, t2.net().railterminal()); if (!ret) { - for (core_terminal_t *t : t2.net().m_core_terms) + for (auto & t : t2.net().m_core_terms) { if (t->is_type(core_terminal_t::TERMINAL)) ret = connect(t1, *t); @@ -723,8 +723,8 @@ void setup_t::resolve_inputs() } if (tries == 0) { - for (std::size_t i = 0; i < m_links.size(); i++ ) - log().warning("Error connecting {1} to {2}\n", m_links[i].first, m_links[i].second); + for (auto & link : m_links) + log().warning("Error connecting {1} to {2}\n", link.first, link.second); log().fatal("Error connecting -- bailing out\n"); } @@ -767,16 +767,12 @@ void setup_t::resolve_inputs() log().verbose("looking for two terms connected to rail nets ...\n"); - for (std::size_t i=0; i < netlist().m_devices.size(); i++) + for (auto & t : netlist().get_device_list()) { - devices::NETLIB_NAME(twoterm) *t = dynamic_cast(netlist().m_devices[i].get()); - if (t != nullptr) - { - has_twoterms = true; - if (t->m_N.net().isRailNet() && t->m_P.net().isRailNet()) - log().warning("Found device {1} connected only to railterminals {2}/{3}\n", - t->name(), t->m_N.net().name(), t->m_P.net().name()); - } + has_twoterms = true; + if (t->m_N.net().isRailNet() && t->m_P.net().isRailNet()) + log().warning("Found device {1} connected only to railterminals {2}/{3}\n", + t->name(), t->m_N.net().name(), t->m_P.net().name()); } log().verbose("initialize solver ...\n"); diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index 6448e640ea5..4b5f42541d1 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -103,7 +103,7 @@ public: int indexof(const LC &elem) const { - for (unsigned i = 0; i < this->size(); i++) + for (std::size_t i = 0; i < this->size(); i++) { if (this->at(i) == elem) return i; diff --git a/src/lib/netlist/plib/poptions.h b/src/lib/netlist/plib/poptions.h index ea48598d5f5..dbcf3ba30d4 100644 --- a/src/lib/netlist/plib/poptions.h +++ b/src/lib/netlist/plib/poptions.h @@ -182,9 +182,8 @@ public: { pstring ret; - for (std::size_t i=0; im_short != "") line += " -" + opt->m_short; @@ -207,19 +206,19 @@ private: option *getopt_short(pstring arg) { - for (std::size_t i=0; i < m_opts.size(); i++) + for (auto & opt : m_opts) { - if (m_opts[i]->m_short == arg) - return m_opts[i]; + if (opt->m_short == arg) + return opt; } return nullptr; } option *getopt_long(pstring arg) { - for (std::size_t i=0; i < m_opts.size(); i++) + for (auto & opt : m_opts) { - if (m_opts[i]->m_long == arg) - return m_opts[i]; + if (opt->m_long == arg) + return opt; } return nullptr; } diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index 4daa9ebd1a3..359e4415d72 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -360,13 +360,13 @@ pstring ppreprocessor::replace_macros(const pstring &line) { pstring_vector_t elems(line, m_expr_sep); pstringbuffer ret = ""; - for (std::size_t i=0; im_replace); else - ret.cat(elems[i]); + ret.cat(elem); } return ret; } @@ -374,9 +374,9 @@ pstring ppreprocessor::replace_macros(const pstring &line) static pstring catremainder(const pstring_vector_t &elems, std::size_t start, pstring sep) { pstringbuffer ret = ""; - for (std::size_t i=start; im_dt == DT_CUSTOM) - m_save[i]->m_callback->on_pre_save(); + for (auto & s : m_save) + if (s->m_dt == DT_CUSTOM) + s->m_callback->on_pre_save(); } void pstate_manager_t::post_load() { - for (std::size_t i=0; i < m_save.size(); i++) - if (m_save[i]->m_dt == DT_CUSTOM) - m_save[i]->m_callback->on_post_load(); + for (auto & s : m_save) + if (s->m_dt == DT_CUSTOM) + s->m_callback->on_post_load(); } template<> void pstate_manager_t::save_item(const void *owner, pstate_callback_t &state, const pstring &stname) diff --git a/src/lib/netlist/plib/pstring.cpp b/src/lib/netlist/plib/pstring.cpp index bec765ff73d..9324996ae63 100644 --- a/src/lib/netlist/plib/pstring.cpp +++ b/src/lib/netlist/plib/pstring.cpp @@ -147,7 +147,7 @@ const pstring_t pstring_t::ucase() const { pstring_t ret = *this; ret.pcopy(cstr(), blen()); - for (unsigned i=0; istr()[i] = toupper((unsigned) ret.m_ptr->str()[i]); return ret; } @@ -158,11 +158,11 @@ int pstring_t::find_first_not_of(const pstring_t &no) const char *t = m_ptr->str(); unsigned nolen = no.len(); unsigned tlen = len(); - for (unsigned i=0; i < tlen; i++) + for (std::size_t i=0; i < tlen; i++) { char *n = no.m_ptr->str(); bool f = true; - for (unsigned j=0; j < nolen; j++) + for (std::size_t j=0; j < nolen; j++) { if (F::code(t) == F::code(n)) f = false; @@ -182,11 +182,11 @@ int pstring_t::find_last_not_of(const pstring_t &no) const unsigned nolen = no.len(); unsigned tlen = len(); int last_found = -1; - for (unsigned i=0; i < tlen; i++) + for (std::size_t i=0; i < tlen; i++) { char *n = no.m_ptr->str(); bool f = true; - for (unsigned j=0; j < nolen; j++) + for (std::size_t j=0; j < nolen; j++) { if (F::code(t) == F::code(n)) f = false; @@ -392,7 +392,7 @@ void pstring_t::resetmem() { if (stk != nullptr) { - for (unsigned i=0; i<=16; i++) + for (std::size_t i=0; i<=16; i++) { for (; stk[i].size() > 0; ) { @@ -448,7 +448,7 @@ int pstring_t::find(const pstring_t &search, unsigned start) const const char *s = search.cstr(); const unsigned startt = std::min(start, tlen); const char *t = cstr(); - for (unsigned i=0; i::find(const mem_t *search, unsigned start) const const char *s = search; const unsigned startt = std::min(start, tlen); const char *t = cstr(); - for (unsigned i=0; iopt_logs() : "" , ":"); - for (unsigned i=0; i < ll.size(); i++) + for (auto & log : ll) { - pstring name = "log_" + ll[i]; + pstring name = "log_" + log; /*netlist_device_t *nc = */ m_setup->register_dev("LOG", name); - m_setup->register_link(name + ".I", ll[i]); + m_setup->register_link(name + ".I", log); } } @@ -284,18 +284,16 @@ static void listdevices() nt.setup().start_devices(); nt.setup().resolve_inputs(); - for (unsigned i=0; i < list.size(); i++) + for (auto & f : list) { - auto &f = list[i]; pstring out = plib::pfmt("{1} {2}(")(f->classname(),"-20")(f->name()); pstring terms(""); - auto d = f->Create(nt.setup().netlist(), plib::pfmt("dummy{1}")(i)); + auto d = f->Create(nt.setup().netlist(), "dummy"); // get the list of terminals ... - for (unsigned j=0; j < d->m_terminals.size(); j++) + for (auto & inp : d->m_terminals) { - pstring inp = d->m_terminals[j]; if (inp.startsWith(d->name() + ".")) inp = inp.substr(d->name().len() + 1); terms += "," + inp;