first batch of cppcheck disables and a few more stl-ifications,

involving use of accumulate() .
This commit is contained in:
G.E 2024-05-16 23:01:17 +03:00
parent 6e306a508e
commit da4f563a24
29 changed files with 81 additions and 12 deletions

View File

@ -251,6 +251,7 @@ void checkForMultilineStart(ReportManager &rm, NGHolder &g,
static
bool hasAssertVertices(const NGHolder &g) {
// cppcheck-suppress useStlAlgorithm
for (auto v : vertices_range(g)) {
int flags = g[v].assert_flags;
if (flags & WORDBOUNDARY_FLAGS) {

View File

@ -136,6 +136,7 @@ void FDRCompiler::createInitialState(FDR *fdr) {
const vector<LiteralIndex> &bucket_lits = bucketToLits[b];
u32 min_len = ~0U;
for (const LiteralIndex &lit_idx : bucket_lits) {
// cppcheck-suppress useStlAlgorithm
min_len = min(min_len, verify_u32(lits[lit_idx].s.length()));
}

View File

@ -303,6 +303,7 @@ setupFullConfs(const vector<hwlmLiteral> &lits,
if (contains(bucketToLits, b)) {
vector<hwlmLiteral> vl;
for (const LiteralIndex &lit_idx : bucketToLits.at(b)) {
// cppcheck-suppress useStlAlgorithm
vl.emplace_back(lits[lit_idx]);
}

View File

@ -71,6 +71,7 @@ void getTeddyDescriptions(vector<TeddyEngineDescription> *out) {
};
out->clear();
for (const auto &def : defns) {
// cppcheck-suppress useStlAlgorithm
out->emplace_back(def);
}
}
@ -123,6 +124,7 @@ bool isAllowed(const vector<hwlmLiteral> &vl, const TeddyEngineDescription &eng,
u32 n_small_lits = 0;
for (const auto &lit : vl) {
if (lit.s.length() < eng.numMasks) {
// cppcheck-suppress useStlAlgorithm
n_small_lits++;
}
}
@ -204,6 +206,7 @@ unique_ptr<TeddyEngineDescription> getTeddyDescription(u32 engineID) {
getTeddyDescriptions(&descs);
for (const auto &desc : descs) {
// cppcheck-suppress useStlAlgorithm
if (desc.getID() == engineID) {
return std::make_unique<TeddyEngineDescription>(desc);
}

View File

@ -182,6 +182,7 @@ vector<vector<CharReach>> generate_paths(const raw_dfa &rdfa,
vector<vector<CharReach>> rv;
rv.reserve(paths.size());
for (auto &p : paths) {
// cppcheck-suppress useStlAlgorithm
rv.emplace_back(vector<CharReach>(std::make_move_iterator(p.reach.begin()),
std::make_move_iterator(p.reach.end())));
}

View File

@ -672,6 +672,7 @@ set<ReportID> all_reports(const CastleProto &proto) {
depth findMinWidth(const CastleProto &proto) {
depth min_width(depth::infinity());
for (const PureRepeat &pr : proto.repeats | map_values) {
// cppcheck-suppress useStlAlgorithm
min_width = min(min_width, pr.bounds.min);
}
return min_width;
@ -680,6 +681,7 @@ depth findMinWidth(const CastleProto &proto) {
depth findMaxWidth(const CastleProto &proto) {
depth max_width(0);
for (const PureRepeat &pr : proto.repeats | map_values) {
// cppcheck-suppress useStlAlgorithm
max_width = max(max_width, pr.bounds.max);
}
return max_width;
@ -746,6 +748,7 @@ u32 CastleProto::merge(const PureRepeat &pr) {
// First, see if this repeat is already in this castle.
for (const auto &m : repeats) {
// cppcheck-suppress useStlAlgorithm
if (m.second == pr) {
DEBUG_PRINTF("repeat already present, with top %u\n", m.first);
return m.first;
@ -970,6 +973,7 @@ void addToHolder(NGHolder &g, u32 top, const PureRepeat &pr) {
static
bool hasZeroMinBound(const CastleProto &proto) {
const depth zero(0);
// cppcheck-suppress useStlAlgorithm
for (const PureRepeat &pr : proto.repeats | map_values) {
if (pr.bounds.min == zero) {
return true;

View File

@ -263,6 +263,7 @@ void mapping_new_states(const HopcroftInfo &info,
new_states.reserve(num_partitions);
for (const auto &m : ordering) {
// cppcheck-suppress useStlAlgorithm
new_states.emplace_back(rdfa.states[m.first]);
}
rdfa.states = std::move(new_states);

View File

@ -650,6 +650,7 @@ void GoughSSAVarJoin::generate(UNUSED vector<gough_ins> *out) const {
GoughSSAVar *GoughSSAVarJoin::get_input(const GoughEdge &prev) const {
for (const auto &var_edge : input_map) {
// cppcheck-suppress useStlAlgorithm
if (contains(var_edge.second, prev)) {
return var_edge.first;
}
@ -992,6 +993,7 @@ void copy_in_blocks(raw_som_dfa &raw, u8 alphaShift, const GoughGraph &cfg,
}
bool find_normal_self_loop(GoughVertex v, const GoughGraph &g, GoughEdge *out) {
// cppcheck-suppress useStlAlgorithm
for (const auto &e : out_edges_range(v, g)) {
if (target(e, g) != v) {
continue;

View File

@ -146,6 +146,7 @@ bool verify_neighbour(const GoughGraph &g, GoughVertex u,
const map<gough_edge_id, vector<gough_ins> > &blocks,
const set<GoughVertex> &succs,
const vector<gough_ins> &block_sl) {
// cppcheck-suppress useStlAlgorithm
for (const auto &e : out_edges_range(u, g)) {
if (!g[e].reach.any()) { /* ignore top edges */
continue;
@ -172,6 +173,7 @@ static
bool verify_neighbour_no_block(const GoughGraph &g, GoughVertex u,
const map<gough_edge_id, vector<gough_ins> > &blocks,
const set<GoughVertex> &succs) {
// cppcheck-suppress useStlAlgorithm
for (const auto &e : out_edges_range(u, g)) {
if (!g[e].reach.any()) { /* ignore top edges */
continue;
@ -229,6 +231,7 @@ bool allow_two_byte_accel(const GoughGraph &g,
succs.insert(target(e, g));
}
// cppcheck-suppress useStlAlgorithm
for (auto w : adjacent_vertices_range(v, g)) {
if (w != v && !verify_neighbour(g, w, blocks, succs, block_sl)) {
return false;
@ -249,6 +252,7 @@ bool allow_two_byte_accel(const GoughGraph &g,
}
succs.insert(target(e, g));
// cppcheck-suppress useStlAlgorithm
for (auto w : adjacent_vertices_range(v, g)) {
if (w != v && !verify_neighbour_no_block(g, w, blocks, succs)) {
return false;

View File

@ -50,6 +50,7 @@ namespace ue2 {
template<typename VarP, typename VarQ>
void emplace_back_all_raw(vector<VarP> *out, const vector<VarQ> &in) {
// cppcheck-suppress useStlAlgorithm
for (const auto &var : in) {
out->emplace_back(var.get());
}
@ -380,6 +381,7 @@ template<typename VarP>
void add_to_dom_ordering(const vector<VarP> &vars,
vector<GoughSSAVar *> *out) {
for (const auto &var : vars) {
// cppcheck-suppress useStlAlgorithm
out->emplace_back(var.get());
}
}

View File

@ -482,6 +482,7 @@ bool allow_wide_accel(NFAVertex v, const NGHolder &g, NFAVertex sds_or_proxy) {
static
bool allow_wide_accel(const vector<NFAVertex> &vv, const NGHolder &g,
NFAVertex sds_or_proxy) {
// cppcheck-suppress useStlAlgorithm
for (auto v : vv) {
if (allow_wide_accel(v, g, sds_or_proxy)) {
return true;
@ -623,6 +624,7 @@ void fillAccelInfo(build_info &bi) {
vector<NFAVertex> astates;
for (const auto &m : accel_map) {
// cppcheck-suppress useStlAlgorithm
astates.emplace_back(m.first);
}
@ -799,12 +801,14 @@ u32 getEffectiveAccelStates(const build_info &args,
continue;
}
for (const auto &s_mask : args.squashMap | map_values) {
// cppcheck-suppress useStlAlgorithm
if (!s_mask.test(state_id)) {
may_turn_off |= 1U << accel_id;
break;
}
}
for (const auto &s_mask : args.reportSquashMap | map_values) {
// cppcheck-suppress useStlAlgorithm
if (!s_mask.test(state_id)) {
may_turn_off |= 1U << accel_id;
break;

View File

@ -55,6 +55,7 @@
#include <cstring>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
@ -529,10 +530,15 @@ size_t calcWideRegionSize(const dfa_info &info) {
size_t rv = info.wide_symbol_chain.size() * sizeof(u32) + 4;
// wide info body
for (const auto &chain : info.wide_symbol_chain) {
rv += ROUNDUP_N(chain.size(), 2) +
(info.impl_alpha_size + 1) * sizeof(u16) + 2;
}
auto chainz = [info=info](size_t z, const vector<symbol_t> &chain) {
return z + (size_t)(ROUNDUP_N(chain.size(), 2) +
(info.impl_alpha_size + 1) * sizeof(u16) + 2);
};
rv += std::accumulate(info.wide_symbol_chain.begin(), info.wide_symbol_chain.end(), 0, chainz);
// for (const auto &chain : info.wide_symbol_chain) {
// rv += ROUNDUP_N(chain.size(), 2) +
// (info.impl_alpha_size + 1) * sizeof(u16) + 2;
// }
return ROUNDUP_16(rv);
}

View File

@ -265,6 +265,7 @@ bool can_die_early(const raw_dfa &raw, dstate_id_t s,
}
for (const auto &next : raw.states[s].next) {
// cppcheck-suppress useStlAlgorithm
if (can_die_early(raw, next, visited, age_limit - 1)) {
return true;
}

View File

@ -182,6 +182,7 @@ bool shuftiBuildDoubleMasks(const CharReach &onechar,
}
nibble_masks.clear();
for (const auto &e : new_masks) {
// cppcheck-suppress useStlAlgorithm
nibble_masks.emplace_back(e.second);
}
}

View File

@ -42,6 +42,8 @@
#include "util/container.h"
#include "util/verify_types.h"
#include <numeric>
using namespace std;
namespace ue2 {
@ -127,9 +129,14 @@ buildTamarama(const TamaInfo &tamaInfo, const u32 queue,
sizeof(u32) * subSize + 64; // offsets to subengines in bytecode and
// padding for subengines
for (const auto &sub : tamaInfo.subengines) {
total_size += ROUNDUP_CL(sub->length);
}
auto subl = [](size_t z, NFA *sub) {
return z + (size_t)(ROUNDUP_CL(sub->length));
};
total_size += std::accumulate(tamaInfo.subengines.begin(), tamaInfo.subengines.end(), 0, subl);
// for (const auto &sub : tamaInfo.subengines) {
// total_size += ROUNDUP_CL(sub->length);
// }
// use subSize as a sentinel value for no active subengines,
// so add one to subSize here

View File

@ -137,6 +137,7 @@ NFAVertex findReformable(const NGHolder &g, const set<NFAVertex> &starts,
static
bool isStartNode(NFAVertex v, NFAVertex start, const NGHolder &g,
bool selfLoopIsAcceptable) {
// cppcheck-suppress useStlAlgorithm
for (auto u : inv_adjacent_vertices_range(v, g)) {
if (selfLoopIsAcceptable && u == v) {
continue;
@ -307,6 +308,7 @@ void reformUnanchoredRepeatsComponent(NGHolder &g,
}
for (auto v : otherV) {
// cppcheck-suppress useStlAlgorithm
if (!edge(dotV, v, g).second) {
return;
}
@ -441,6 +443,7 @@ bool gatherParticipants(const NGHolder &g,
/* All the non chained v connected to start must be in succ as well
* TODO: remember why (and document). */
// cppcheck-suppress useStlAlgorithm
for (auto u : adjacent_vertices_range(start, g)) {
if (is_special(u, g)) {
continue;

View File

@ -77,17 +77,20 @@ static constexpr u32 MAX_TAIL_SHELL_DEPTH = 3;
* classes.
*/
bool isAlternationOfClasses(const NGHolder &g) {
// cppcheck-suppress useStlAlgorithm
for (auto v : vertices_range(g)) {
if (is_special(v, g)) {
continue;
}
// Vertex must have in edges from starts only.
// cppcheck-suppress useStlAlgorithm
for (auto u : inv_adjacent_vertices_range(v, g)) {
if (!is_any_start(u, g)) {
return false;
}
}
// Vertex must have out edges to accepts only.
// cppcheck-suppress useStlAlgorithm
for (auto w : adjacent_vertices_range(v, g)) {
if (!is_any_accept(w, g)) {
return false;

View File

@ -157,6 +157,7 @@ vector<bool> findLoopReachable(const Graph &g,
for (auto v : reverse(topoOrder)) {
for (const auto &e : in_edges_range(v, g)) {
// cppcheck-suppress useStlAlgorithm
if (deadNodes[g[source(e, g)].index]) {
deadNodes[g[v].index] = true;
break;

View File

@ -63,6 +63,7 @@ bool checkVerticesFwd(const NGHolder &g, const set<NFAVertex> &sad,
for (auto u : sad) {
bool ok = false;
for (auto v : adjacent_vertices_range(u, g)) {
// cppcheck-suppress useStlAlgorithm
if (contains(happy, v)) {
ok = true;
break;
@ -85,6 +86,7 @@ bool checkVerticesRev(const NGHolder &g, const set<NFAVertex> &sad,
for (auto v : sad) {
bool ok = false;
for (auto u : inv_adjacent_vertices_range(v, g)) {
// cppcheck-suppress useStlAlgorithm
if (contains(happy, u)) {
ok = true;
break;

View File

@ -197,6 +197,7 @@ bool outIsIrreducible(NFAVertex &v, const NGHolder &g) {
unsigned nonSpecialVertices = 0;
for (auto w : adjacent_vertices_range(v, g)) {
if (!is_special(w, g) && w != v) {
// cppcheck-suppress useStlAlgorithm
nonSpecialVertices++;
}
}
@ -208,6 +209,7 @@ bool inIsIrreducible(NFAVertex &v, const NGHolder &g) {
unsigned nonSpecialVertices = 0;
for (auto u : inv_adjacent_vertices_range(v, g)) {
if (!is_special(u, g) && u != v) {
// cppcheck-suppress useStlAlgorithm
nonSpecialVertices++;
}
}

View File

@ -131,6 +131,7 @@ void checkVertex(const ReportManager &rm, const NGHolder &g, NFAVertex v,
static
bool hasOffsetAdjust(const ReportManager &rm, const NGHolder &g) {
// cppcheck-suppress useStlAlgorithm
for (const auto &report_id : all_reports(g)) {
if (rm.getReport(report_id).offsetAdjust) {
return true;

View File

@ -75,6 +75,7 @@ bool hasSameBounds(const Container &reports, const ReportManager &rm) {
assert(!reports.empty());
const auto &first = rm.getReport(*reports.begin());
// cppcheck-suppress useStlAlgorithm
for (auto id : reports) {
const auto &report = rm.getReport(id);
if (report.minOffset != first.minOffset ||
@ -225,6 +226,7 @@ void updateReportBounds(ReportManager &rm, NGHolder &g,
static
bool hasVirtualStarts(const NGHolder &g) {
// cppcheck-suppress useStlAlgorithm
for (auto v : adjacent_vertices_range(g.start, g)) {
if (g[v].assert_flags & POS_FLAG_VIRTUAL_START) {
return true;
@ -439,6 +441,7 @@ bool hasOffsetAdjust(const ReportManager &rm, NGHolder &g,
}
int offsetAdjust = rm.getReport(*reports.begin()).offsetAdjust;
// cppcheck-suppress useStlAlgorithm
for (auto report : reports) {
const Report &ir = rm.getReport(report);
if (ir.offsetAdjust != offsetAdjust) {

View File

@ -673,6 +673,7 @@ void validate_fuzzy_compile(const NGHolder &g, u32 edit_distance, bool hamming,
}
// graph isn't fuzzable if there are edge assertions anywhere in the graph
for (auto e : edges_range(g)) {
// cppcheck-suppress useStlAlgorithm
if (g[e].assert_flags) {
throw CompileError("Zero-width assertions are disallowed for "
"approximate matching.");

View File

@ -453,6 +453,7 @@ void haig_do_preds(const NGHolder &g, const stateset &nfa_states,
DEBUG_PRINTF("d vertex %zu\n", g[v].index);
vector<u32> &out_map = preds[slot_id];
for (auto u : inv_adjacent_vertices_range(v, g)) {
// cppcheck-suppress useStlAlgorithm
out_map.emplace_back(g[u].index);
}

View File

@ -172,9 +172,11 @@ bool is_equal_i(const NGHolder &a, const NGHolder &b,
vector<pair<u32, flat_set<u32>>> top_b;
for (const auto &e : out_edges_range(a.start, a)) {
// cppcheck-suppress useStlAlgorithm
top_a.emplace_back(a[target(e, a)].index, a[e].tops);
}
for (const auto &e : out_edges_range(b.start, b)) {
// cppcheck-suppress useStlAlgorithm
top_b.emplace_back(b[target(e, b)].index, b[e].tops);
}

View File

@ -46,6 +46,7 @@
#include <algorithm>
#include <fstream>
#include <numeric>
#include <queue>
#include <boost/graph/boykov_kolmogorov_max_flow.hpp>
@ -359,6 +360,7 @@ u64a litUniqueness(const string &s) {
static
u64a litCountBits(const ue2_literal &lit) {
u64a n = 0;
// cppcheck-suppress useStlAlgorithm
for (const auto &c : lit) {
n += c.nocase ? 7 : 8;
}
@ -670,10 +672,11 @@ u64a scoreSet(const set<ue2_literal> &s) {
}
u64a score = 1ULL;
for (const auto &lit : s) {
score += calculateScore(lit);
}
auto cscore = [](u64a z, const ue2_literal &lit) { return z + calculateScore(lit); };
score += std::accumulate(s.begin(), s.end(), 0, cscore);
// for (const auto &lit : s) {
// score += calculateScore(lit);
// }
return score;
}

View File

@ -141,12 +141,14 @@ bool isRegionExit(const Graph &g, NFAVertex v,
template <class Graph>
bool isSingletonRegion(const Graph &g, NFAVertex v,
const std::unordered_map<NFAVertex, u32> &region_map) {
// cppcheck-suppress useStlAlgorithm
for (const auto &e : in_edges_range(v, g)) {
auto u = source(e, g);
if (u != v && inSameRegion(g, v, u, region_map)) {
return false;
}
// cppcheck-suppress useStlAlgorithm
for (auto w : ue2::adjacent_vertices_range(u, g)) {
if (w != v && inSameRegion(g, v, w, region_map)) {
return false;
@ -154,11 +156,13 @@ bool isSingletonRegion(const Graph &g, NFAVertex v,
}
}
// cppcheck-suppress useStlAlgorithm
for (auto w : adjacent_vertices_range(v, g)) {
if (w != v && inSameRegion(g, v, w, region_map)) {
return false;
}
// cppcheck-suppress useStlAlgorithm
for (const auto &e : in_edges_range(w, g)) {
auto u = source(e, g);
if (u != v && inSameRegion(g, v, u, region_map)) {
@ -201,7 +205,7 @@ bool isOptionalRegion(const Graph &g, NFAVertex v,
DEBUG_PRINTF(" searching from u=%zu\n", g[u].index);
assert(inEarlierRegion(g, v, u, region_map));
// cppcheck-suppress useStlAlgorithm
for (auto w : adjacent_vertices_range(u, g)) {
DEBUG_PRINTF(" searching to w=%zu\n", g[w].index);
if (inLaterRegion(g, v, w, region_map)) {

View File

@ -200,6 +200,8 @@ public:
/// Are no bits set?
bool none() const {
// cppcheck-suppress useStlAlgorithm
// XXX maybe do this one..
for (const auto &e : bits) {
if (e != 0) {
return false;

View File

@ -616,12 +616,14 @@ public:
vertex_descriptor v) const {
if (in_degree_impl(v) < out_degree_impl(u)) {
for (const edge_descriptor &e : in_edges_range(v, *this)) {
// cppcheck-suppress useStlAlgorithm
if (source_impl(e) == u) {
return {e, true};
}
}
} else {
for (const edge_descriptor &e : out_edges_range(u, *this)) {
// cppcheck-suppress useStlAlgorithm
if (target_impl(e) == v) {
return {e, true};
}