Internals: Favor const_iterators. No functional change intended.

This commit is contained in:
Wilson Snyder 2024-02-25 17:12:13 -05:00
parent 42041f2403
commit e320b0b581
8 changed files with 46 additions and 48 deletions

View File

@ -814,7 +814,7 @@ void _vl_vsformat(std::string& output, const std::string& format, va_list ap) VL
bool widthSet = false;
bool left = false;
size_t width = 0;
for (std::string::const_iterator pos = format.begin(); pos != format.end(); ++pos) {
for (std::string::const_iterator pos = format.cbegin(); pos != format.cend(); ++pos) {
if (!inPct && pos[0] == '%') {
pctit = pos;
inPct = true;
@ -1212,8 +1212,8 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
IData got = 0;
bool inPct = false;
bool inIgnore = false;
std::string::const_iterator pos = format.begin();
for (; pos != format.end() && !_vl_vsss_eof(fp, floc); ++pos) {
std::string::const_iterator pos = format.cbegin();
for (; pos != format.cend() && !_vl_vsss_eof(fp, floc); ++pos) {
// VL_DBG_MSGF("_vlscan fmt='"<<pos[0]<<"' floc="<<floc<<" file='"<<_vl_vsss_peek(fp, floc,
// fromp, fstr)<<"'\n");
if (!inPct && pos[0] == '%') {
@ -2786,7 +2786,7 @@ bool VerilatedContextImp::commandArgVlUint64(const std::string& arg, const std::
VL_FATAL_MT("COMMAND_LINE", 0, "", msg.c_str());
};
if (std::any_of(str.begin(), str.end(), [](int c) { return !std::isdigit(c); })) fail();
if (std::any_of(str.cbegin(), str.cend(), [](int c) { return !std::isdigit(c); })) fail();
char* end;
valuer = std::strtoull(str.c_str(), &end, 10);
if (errno == ERANGE) fail("Value out of range of uint64_t");

View File

@ -59,7 +59,7 @@ void VlDelayScheduler::resume() {
#endif
bool resumed = false;
while (!m_queue.empty() && (m_queue.begin()->first == m_context.time())) {
while (!m_queue.empty() && (m_queue.cbegin()->first == m_context.time())) {
VlCoroutineHandle handle = std::move(m_queue.begin()->second);
m_queue.erase(m_queue.begin());
handle.resume();
@ -80,7 +80,7 @@ void VlDelayScheduler::resume() {
}
uint64_t VlDelayScheduler::nextTimeSlot() const {
if (!m_queue.empty()) return m_queue.begin()->first;
if (!m_queue.empty()) return m_queue.cbegin()->first;
if (m_zeroDelayed.empty())
VL_FATAL_MT(__FILE__, __LINE__, "", "%Error: There is no next time slot scheduled");
return m_context.time();

View File

@ -180,7 +180,7 @@ public:
bool empty() const { return m_queue.empty() && m_zeroDelayed.empty(); }
// Are there coroutines to resume at the current simulation time?
bool awaitingCurrentTime() const {
return (!m_queue.empty() && (m_queue.begin()->first <= m_context.time()))
return (!m_queue.empty() && (m_queue.cbegin()->first <= m_context.time()))
|| !m_zeroDelayed.empty();
}
#ifdef VL_DEBUG

View File

@ -615,7 +615,7 @@ public:
// inside (set membership operator)
bool inside(const T_Value& value) const {
return std::find(m_deque.begin(), m_deque.end(), value) != m_deque.end();
return std::find(m_deque.cbegin(), m_deque.cend(), value) != m_deque.cend();
}
// Return slice q[lsb:msb]
@ -776,13 +776,13 @@ public:
// Reduction operators
VlQueue min() const {
if (m_deque.empty()) return VlQueue{};
const auto it = std::min_element(m_deque.begin(), m_deque.end());
const auto it = std::min_element(m_deque.cbegin(), m_deque.cend());
return VlQueue::cons(*it);
}
template <typename Func>
VlQueue min(Func with_func) const {
if (m_deque.empty()) return VlQueue{};
const auto it = std::min_element(m_deque.begin(), m_deque.end(),
const auto it = std::min_element(m_deque.cbegin(), m_deque.cend(),
[&with_func](const IData& a, const IData& b) {
return with_func(0, a) < with_func(0, b);
});
@ -790,13 +790,13 @@ public:
}
VlQueue max() const {
if (m_deque.empty()) return VlQueue{};
const auto it = std::max_element(m_deque.begin(), m_deque.end());
const auto it = std::max_element(m_deque.cbegin(), m_deque.cend());
return VlQueue::cons(*it);
}
template <typename Func>
VlQueue max(Func with_func) const {
if (m_deque.empty()) return VlQueue{};
const auto it = std::max_element(m_deque.begin(), m_deque.end(),
const auto it = std::max_element(m_deque.cbegin(), m_deque.cend(),
[&with_func](const IData& a, const IData& b) {
return with_func(0, a) < with_func(0, b);
});
@ -817,40 +817,40 @@ public:
}
T_Value r_product() const {
if (m_deque.empty()) return T_Value(0);
auto it = m_deque.begin();
auto it = m_deque.cbegin();
T_Value out{*it};
++it;
for (; it != m_deque.end(); ++it) out *= *it;
for (; it != m_deque.cend(); ++it) out *= *it;
return out;
}
template <typename Func>
T_Value r_product(Func with_func) const {
if (m_deque.empty()) return T_Value(0);
auto it = m_deque.begin();
auto it = m_deque.cbegin();
IData index = 0;
T_Value out{with_func(index, *it)};
++it;
++index;
for (; it != m_deque.end(); ++it) out *= with_func(index++, *it);
for (; it != m_deque.cend(); ++it) out *= with_func(index++, *it);
return out;
}
T_Value r_and() const {
if (m_deque.empty()) return T_Value(0);
auto it = m_deque.begin();
auto it = m_deque.cbegin();
T_Value out{*it};
++it;
for (; it != m_deque.end(); ++it) out &= *it;
for (; it != m_deque.cend(); ++it) out &= *it;
return out;
}
template <typename Func>
T_Value r_and(Func with_func) const {
if (m_deque.empty()) return T_Value(0);
auto it = m_deque.begin();
auto it = m_deque.cbegin();
IData index = 0;
T_Value out{with_func(index, *it)};
++it;
++index;
for (; it != m_deque.end(); ++it) out &= with_func(index, *it);
for (; it != m_deque.cend(); ++it) out &= with_func(index, *it);
return out;
}
T_Value r_or() const {
@ -948,7 +948,7 @@ public:
// Return last element. Verilog: function int last(ref index)
int last(T_Key& indexr) const {
const auto it = m_map.crbegin();
if (it == m_map.rend()) return 0;
if (it == m_map.crend()) return 0;
indexr = it->first;
return 1;
}
@ -1077,7 +1077,7 @@ public:
template <typename Func>
VlQueue<T_Value> find_first(Func with_func) const {
const auto it
= std::find_if(m_map.begin(), m_map.end(), [=](const std::pair<T_Key, T_Value>& i) {
= std::find_if(m_map.cbegin(), m_map.cend(), [=](const std::pair<T_Key, T_Value>& i) {
return with_func(i.first, i.second);
});
if (it == m_map.end()) return VlQueue<T_Value>{};
@ -1086,7 +1086,7 @@ public:
template <typename Func>
VlQueue<T_Key> find_first_index(Func with_func) const {
const auto it
= std::find_if(m_map.begin(), m_map.end(), [=](const std::pair<T_Key, T_Value>& i) {
= std::find_if(m_map.cbegin(), m_map.cend(), [=](const std::pair<T_Key, T_Value>& i) {
return with_func(i.first, i.second);
});
if (it == m_map.end()) return VlQueue<T_Value>{};
@ -1094,19 +1094,17 @@ public:
}
template <typename Func>
VlQueue<T_Value> find_last(Func with_func) const {
const auto it
= std::find_if(m_map.rbegin(), m_map.rend(), [=](const std::pair<T_Key, T_Value>& i) {
return with_func(i.first, i.second);
});
const auto it = std::find_if(
m_map.crbegin(), m_map.crend(),
[=](const std::pair<T_Key, T_Value>& i) { return with_func(i.first, i.second); });
if (it == m_map.rend()) return VlQueue<T_Value>{};
return VlQueue<T_Value>::cons(it->second);
}
template <typename Func>
VlQueue<T_Key> find_last_index(Func with_func) const {
const auto it
= std::find_if(m_map.rbegin(), m_map.rend(), [=](const std::pair<T_Key, T_Value>& i) {
return with_func(i.first, i.second);
});
const auto it = std::find_if(
m_map.crbegin(), m_map.crend(),
[=](const std::pair<T_Key, T_Value>& i) { return with_func(i.first, i.second); });
if (it == m_map.rend()) return VlQueue<T_Value>{};
return VlQueue<T_Key>::cons(it->first);
}
@ -1115,7 +1113,7 @@ public:
VlQueue<T_Value> min() const {
if (m_map.empty()) return VlQueue<T_Value>();
const auto it = std::min_element(
m_map.begin(), m_map.end(),
m_map.cbegin(), m_map.cend(),
[](const std::pair<T_Key, T_Value>& a, const std::pair<T_Key, T_Value>& b) {
return a.second < b.second;
});
@ -1125,7 +1123,7 @@ public:
VlQueue<T_Value> min(Func with_func) const {
if (m_map.empty()) return VlQueue<T_Value>();
const auto it = std::min_element(
m_map.begin(), m_map.end(),
m_map.cbegin(), m_map.cend(),
[&with_func](const std::pair<T_Key, T_Value>& a, const std::pair<T_Key, T_Value>& b) {
return with_func(a.first, a.second) < with_func(b.first, b.second);
});
@ -1134,7 +1132,7 @@ public:
VlQueue<T_Value> max() const {
if (m_map.empty()) return VlQueue<T_Value>();
const auto it = std::max_element(
m_map.begin(), m_map.end(),
m_map.cbegin(), m_map.cend(),
[](const std::pair<T_Key, T_Value>& a, const std::pair<T_Key, T_Value>& b) {
return a.second < b.second;
});
@ -1144,7 +1142,7 @@ public:
VlQueue<T_Value> max(Func with_func) const {
if (m_map.empty()) return VlQueue<T_Value>();
const auto it = std::max_element(
m_map.begin(), m_map.end(),
m_map.cbegin(), m_map.cend(),
[&with_func](const std::pair<T_Key, T_Value>& a, const std::pair<T_Key, T_Value>& b) {
return with_func(a.first, a.second) < with_func(b.first, b.second);
});
@ -1164,36 +1162,36 @@ public:
}
T_Value r_product() const {
if (m_map.empty()) return T_Value(0);
auto it = m_map.begin();
auto it = m_map.cbegin();
T_Value out{it->second};
++it;
for (; it != m_map.end(); ++it) out *= it->second;
for (; it != m_map.cend(); ++it) out *= it->second;
return out;
}
template <typename Func>
T_Value r_product(Func with_func) const {
if (m_map.empty()) return T_Value(0);
auto it = m_map.begin();
auto it = m_map.cbegin();
T_Value out{with_func(it->first, it->second)};
++it;
for (; it != m_map.end(); ++it) out *= with_func(it->first, it->second);
for (; it != m_map.cend(); ++it) out *= with_func(it->first, it->second);
return out;
}
T_Value r_and() const {
if (m_map.empty()) return T_Value(0);
auto it = m_map.begin();
auto it = m_map.cbegin();
T_Value out{it->second};
++it;
for (; it != m_map.end(); ++it) out &= it->second;
for (; it != m_map.cend(); ++it) out &= it->second;
return out;
}
template <typename Func>
T_Value r_and(Func with_func) const {
if (m_map.empty()) return T_Value(0);
auto it = m_map.begin();
auto it = m_map.cbegin();
T_Value out{with_func(it->first, it->second)};
++it;
for (; it != m_map.end(); ++it) out &= with_func(it->first, it->second);
for (; it != m_map.cend(); ++it) out &= with_func(it->first, it->second);
return out;
}
T_Value r_or() const {

View File

@ -339,7 +339,7 @@ class EmitMkHierVerilation final {
const V3HierBlockPlan::HierVector blocks
= m_planp->hierBlocksSorted(); // leaf comes first
// List in order of leaf-last order so that linker can resolve dependency
for (auto& block : vlstd::reverse_view(blocks)) {
for (const auto& block : vlstd::reverse_view(blocks)) {
of.puts("\t" + block->hierLib(true) + " \\\n");
}
of.puts("\n");

View File

@ -394,7 +394,7 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const {
}
// Print ranks
for (auto dotRank : ranks) {
for (const auto& dotRank : ranks) {
*logp << "\t{ rank=";
if (dotRank != "sink" && dotRank != "source" && dotRank != "min" && dotRank != "max") {
*logp << "same";

View File

@ -1253,7 +1253,7 @@ public:
}
~SimulateVisitor() override {
for (const auto& pair : m_constps) {
for (AstConst* const constp : pair.second) { delete constp; }
for (AstConst* const constp : pair.second) delete constp;
}
m_constps.clear();
for (AstNode* ip : m_reclaimValuesp) delete ip;

View File

@ -107,7 +107,7 @@ class VariableOrder final {
void tspSortVars(std::vector<AstVar*>& varps) {
// Map from "MTask affinity" -> "variable list"
std::map<const MTaskIdSet, std::vector<AstVar*>> m2v;
for (AstVar* const varp : varps) { m2v[varp->mtaskIds()].push_back(varp); }
for (AstVar* const varp : varps) m2v[varp->mtaskIds()].push_back(varp);
// Create a TSP sort state for each unique MTaskIdSet, except for the empty set
V3TSP::StateVec states;
@ -125,7 +125,7 @@ class VariableOrder final {
// Helper function to sort given vector, then append to 'varps'
const auto sortAndAppend = [this, &varps](std::vector<AstVar*>& subVarps) {
simpleSortVars(subVarps);
for (AstVar* const varp : subVarps) { varps.push_back(varp); }
for (AstVar* const varp : subVarps) varps.push_back(varp);
};
// Enumerate by sorted MTaskIdSet, sort within the set separately