Rewrote for loops to use auto : semantics. (nw)

This commit is contained in:
couriersud 2016-06-05 03:07:56 +02:00
parent 20be9611af
commit 07ec6f4378
10 changed files with 60 additions and 68 deletions

View File

@ -163,13 +163,13 @@ public:
plib::pstring_vector_t out(io[1], ","); plib::pstring_vector_t out(io[1], ",");
nl_assert_always(out.size() == m_NO, "output count wrong"); 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(); //new (&m_I[i]) logic_input_t();
inout[i] = inout[i].trim(); inout[i] = inout[i].trim();
m_I.emplace(i, *this, inout[i]); 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(); //new (&m_Q[i]) logic_output_t();
out[i] = out[i].trim(); out[i] = out[i].trim();
@ -179,7 +179,7 @@ public:
// Connect output "Q" to input "_Q" if this exists // Connect output "Q" to input "_Q" if this exists
// This enables timed state without having explicit state .... // This enables timed state without having explicit state ....
UINT32 disabled_ignore = 0; 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]; pstring tmp = "_" + out[i];
const int idx = inout.indexof(tmp); const int idx = inout.indexof(tmp);
@ -213,9 +213,9 @@ public:
{ {
m_active = 0; m_active = 0;
m_ign = 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(); m_I[i].activate();
for (unsigned i=0; i<m_NO;i++) for (std::size_t i=0; i<m_NO;i++)
if (this->m_Q[i].net().num_cons()>0) if (this->m_Q[i].net().num_cons()>0)
m_active++; m_active++;
m_last_state = 0; m_last_state = 0;
@ -249,7 +249,7 @@ public:
if (m_NI > 1 && has_state == 0) if (m_NI > 1 && has_state == 0)
if (--m_active == 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_I[i].inactivate();
m_ign = (1<<m_NI)-1; m_ign = (1<<m_NI)-1;
} }
@ -271,20 +271,20 @@ private:
UINT32 state = 0; UINT32 state = 0;
if (m_NI > 1 && !has_state) 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 (!doOUT || (m_ign & (1<<i))) if (!doOUT || (m_ign & (1<<i)))
m_I[i].activate(); m_I[i].activate();
} }
if (!doOUT) if (!doOUT)
for (unsigned i = 0; i < m_NI; i++) for (std::size_t i = 0; i < m_NI; i++)
{ {
state |= (INPLOGIC(m_I[i]) << i); state |= (INPLOGIC(m_I[i]) << i);
mt = std::max(this->m_I[i].net().time(), mt); mt = std::max(this->m_I[i].net().time(), mt);
} }
else 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); state |= (INPLOGIC(m_I[i]) << i);
const UINT32 nstate = state | (has_state ? (m_last_state << m_NI) : 0); const UINT32 nstate = state | (has_state ? (m_last_state << m_NI) : 0);
@ -297,16 +297,16 @@ private:
const UINT32 timebase = nstate * m_NO; const UINT32 timebase = nstate * m_NO;
if (doOUT) 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]]); OUTLOGIC(m_Q[i], (out >> i) & 1, m_ttp->m_timing_nt[m_ttp->m_timing[timebase + i]]);
} }
else 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]]); 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) 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)) if (m_ign & (1 << i))
m_I[i].inactivate(); m_I[i].inactivate();
} }

View File

@ -311,7 +311,7 @@ namespace netlist
, m_Q(*this, "Q") , 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)); m_I.emplace(i, *this, plib::pfmt("A{1}")(i));
plib::pstring_vector_t cmds(m_func.Value(), " "); plib::pstring_vector_t cmds(m_func.Value(), " ");

View File

@ -299,8 +299,8 @@ void netlist_t::reset()
// m_solver->do_reset(); // m_solver->do_reset();
// Reset all nets once ! // Reset all nets once !
for (std::size_t i = 0; i < m_nets.size(); i++) for (auto & n : m_nets)
m_nets[i]->reset(); n->reset();
// Reset all devices once ! // Reset all devices once !
for (auto & dev : m_devices) for (auto & dev : m_devices)
@ -384,9 +384,8 @@ void netlist_t::print_stats() const
{ {
#if (NL_KEEP_STATISTICS) #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("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); printf("Queue Pushes %15d\n", queue().m_prof_call);
@ -642,7 +641,7 @@ void net_t::rebuild_list()
unsigned cnt = 0; unsigned cnt = 0;
m_list_active.clear(); 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) if (term->state() != logic_t::STATE_INP_PASSIVE)
{ {
m_list_active.add(*term); m_list_active.add(*term);

View File

@ -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 */ /* 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 ... p->clear_net(); // de-link from all nets ...
if (!connect(new_proxy->proxy_term(), *p)) 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()); ret = connect(t2, t1.net().railterminal());
if (!ret) 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)) if (t->is_type(core_terminal_t::TERMINAL))
ret = connect(t2, *t); 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()); ret = connect(t1, t2.net().railterminal());
if (!ret) 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)) if (t->is_type(core_terminal_t::TERMINAL))
ret = connect(t1, *t); ret = connect(t1, *t);
@ -723,8 +723,8 @@ void setup_t::resolve_inputs()
} }
if (tries == 0) if (tries == 0)
{ {
for (std::size_t i = 0; i < m_links.size(); i++ ) for (auto & link : m_links)
log().warning("Error connecting {1} to {2}\n", m_links[i].first, m_links[i].second); log().warning("Error connecting {1} to {2}\n", link.first, link.second);
log().fatal("Error connecting -- bailing out\n"); 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"); 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)>())
{ {
devices::NETLIB_NAME(twoterm) *t = dynamic_cast<devices::NETLIB_NAME(twoterm) *>(netlist().m_devices[i].get()); has_twoterms = true;
if (t != nullptr) if (t->m_N.net().isRailNet() && t->m_P.net().isRailNet())
{ log().warning("Found device {1} connected only to railterminals {2}/{3}\n",
has_twoterms = true; t->name(), t->m_N.net().name(), t->m_P.net().name());
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"); log().verbose("initialize solver ...\n");

View File

@ -103,7 +103,7 @@ public:
int indexof(const LC &elem) const 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) if (this->at(i) == elem)
return i; return i;

View File

@ -182,9 +182,8 @@ public:
{ {
pstring ret; pstring ret;
for (std::size_t i=0; i<m_opts.size(); i++ ) for (auto & opt : m_opts )
{ {
option *opt = m_opts[i];
pstring line = ""; pstring line = "";
if (opt->m_short != "") if (opt->m_short != "")
line += " -" + opt->m_short; line += " -" + opt->m_short;
@ -207,19 +206,19 @@ private:
option *getopt_short(pstring arg) 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) if (opt->m_short == arg)
return m_opts[i]; return opt;
} }
return nullptr; return nullptr;
} }
option *getopt_long(pstring arg) 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) if (opt->m_long == arg)
return m_opts[i]; return opt;
} }
return nullptr; return nullptr;
} }

View File

@ -360,13 +360,13 @@ pstring ppreprocessor::replace_macros(const pstring &line)
{ {
pstring_vector_t elems(line, m_expr_sep); pstring_vector_t elems(line, m_expr_sep);
pstringbuffer ret = ""; pstringbuffer ret = "";
for (std::size_t i=0; i<elems.size(); i++) for (auto & elem : elems)
{ {
define_t *def = get_define(elems[i]); define_t *def = get_define(elem);
if (def != nullptr) if (def != nullptr)
ret.cat(def->m_replace); ret.cat(def->m_replace);
else else
ret.cat(elems[i]); ret.cat(elem);
} }
return ret; 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) static pstring catremainder(const pstring_vector_t &elems, std::size_t start, pstring sep)
{ {
pstringbuffer ret = ""; pstringbuffer ret = "";
for (std::size_t i=start; i<elems.size(); i++) for (auto & elem : elems)
{ {
ret.cat(elems[i]); ret.cat(elem);
ret.cat(sep); ret.cat(sep);
} }
return ret; return ret;

View File

@ -56,16 +56,16 @@ void pstate_manager_t::remove_save_items(const void *owner)
void pstate_manager_t::pre_save() void pstate_manager_t::pre_save()
{ {
for (std::size_t i=0; i < m_save.size(); i++) for (auto & s : m_save)
if (m_save[i]->m_dt == DT_CUSTOM) if (s->m_dt == DT_CUSTOM)
m_save[i]->m_callback->on_pre_save(); s->m_callback->on_pre_save();
} }
void pstate_manager_t::post_load() void pstate_manager_t::post_load()
{ {
for (std::size_t i=0; i < m_save.size(); i++) for (auto & s : m_save)
if (m_save[i]->m_dt == DT_CUSTOM) if (s->m_dt == DT_CUSTOM)
m_save[i]->m_callback->on_post_load(); s->m_callback->on_post_load();
} }
template<> void pstate_manager_t::save_item(const void *owner, pstate_callback_t &state, const pstring &stname) template<> void pstate_manager_t::save_item(const void *owner, pstate_callback_t &state, const pstring &stname)

View File

@ -147,7 +147,7 @@ const pstring_t<F> pstring_t<F>::ucase() const
{ {
pstring_t ret = *this; pstring_t ret = *this;
ret.pcopy(cstr(), blen()); ret.pcopy(cstr(), blen());
for (unsigned i=0; i<ret.len(); i++) for (std::size_t i=0; i<ret.len(); i++)
ret.m_ptr->str()[i] = toupper((unsigned) ret.m_ptr->str()[i]); ret.m_ptr->str()[i] = toupper((unsigned) ret.m_ptr->str()[i]);
return ret; return ret;
} }
@ -158,11 +158,11 @@ int pstring_t<F>::find_first_not_of(const pstring_t &no) const
char *t = m_ptr->str(); char *t = m_ptr->str();
unsigned nolen = no.len(); unsigned nolen = no.len();
unsigned tlen = 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(); char *n = no.m_ptr->str();
bool f = true; 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)) if (F::code(t) == F::code(n))
f = false; f = false;
@ -182,11 +182,11 @@ int pstring_t<F>::find_last_not_of(const pstring_t &no) const
unsigned nolen = no.len(); unsigned nolen = no.len();
unsigned tlen = len(); unsigned tlen = len();
int last_found = -1; 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(); char *n = no.m_ptr->str();
bool f = true; 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)) if (F::code(t) == F::code(n))
f = false; f = false;
@ -392,7 +392,7 @@ void pstring_t<F>::resetmem()
{ {
if (stk != nullptr) if (stk != nullptr)
{ {
for (unsigned i=0; i<=16; i++) for (std::size_t i=0; i<=16; i++)
{ {
for (; stk[i].size() > 0; ) for (; stk[i].size() > 0; )
{ {
@ -448,7 +448,7 @@ int pstring_t<F>::find(const pstring_t &search, unsigned start) const
const char *s = search.cstr(); const char *s = search.cstr();
const unsigned startt = std::min(start, tlen); const unsigned startt = std::min(start, tlen);
const char *t = cstr(); const char *t = cstr();
for (unsigned i=0; i<startt; i++) for (std::size_t i=0; i<startt; i++)
t += F::codelen(t); t += F::codelen(t);
for (int i=0; i <= (int) tlen - (int) startt - (int) slen; i++) for (int i=0; i <= (int) tlen - (int) startt - (int) slen; i++)
{ {
@ -477,7 +477,7 @@ int pstring_t<F>::find(const mem_t *search, unsigned start) const
const char *s = search; const char *s = search;
const unsigned startt = std::min(start, tlen); const unsigned startt = std::min(start, tlen);
const char *t = cstr(); const char *t = cstr();
for (unsigned i=0; i<startt; i++) for (std::size_t i=0; i<startt; i++)
t += F::codelen(t); t += F::codelen(t);
for (int i=0; i <= (int) tlen - (int) startt - (int) slen; i++) for (int i=0; i <= (int) tlen - (int) startt - (int) slen; i++)
{ {

View File

@ -112,11 +112,11 @@ public:
{ {
log().debug("Creating dynamic logs ...\n"); log().debug("Creating dynamic logs ...\n");
plib::pstring_vector_t ll(m_opts ? m_opts->opt_logs() : "" , ":"); plib::pstring_vector_t ll(m_opts ? m_opts->opt_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); /*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().start_devices();
nt.setup().resolve_inputs(); 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}(<id>")(f->classname(),"-20")(f->name()); pstring out = plib::pfmt("{1} {2}(<id>")(f->classname(),"-20")(f->name());
pstring terms(""); 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 ... // 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() + ".")) if (inp.startsWith(d->name() + "."))
inp = inp.substr(d->name().len() + 1); inp = inp.substr(d->name().len() + 1);
terms += "," + inp; terms += "," + inp;