mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-11-16 17:31:51 +03:00
addressing cppcheck shadowFunction warnings
This commit is contained in:
@@ -485,15 +485,15 @@ void collapseVariableDotRepeat(NGHolder &g, NFAVertex start,
|
||||
|
||||
// Collect all the other optional dot vertices and the successor vertices
|
||||
// by walking down the graph from initialDot
|
||||
set<NFAVertex> dots, succ;
|
||||
if (!gatherParticipants(g, start, initialDot, dots, succ)) {
|
||||
set<NFAVertex> dots, succr;
|
||||
if (!gatherParticipants(g, start, initialDot, dots, succr)) {
|
||||
DEBUG_PRINTF("gatherParticipants failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_PRINTF("optional dot repeat with %zu participants, "
|
||||
"terminating in %zu non-dot nodes\n",
|
||||
dots.size(), succ.size());
|
||||
dots.size(), succr.size());
|
||||
|
||||
// Remove all the participants and set the start offset
|
||||
dead.insert(dots.begin(), dots.end());
|
||||
@@ -509,7 +509,7 @@ void collapseVariableDotRepeat(NGHolder &g, NFAVertex start,
|
||||
assert(startEnd->is_reachable());
|
||||
|
||||
// Connect our successor vertices to both start and startDs.
|
||||
for (auto v : succ) {
|
||||
for (auto v : succr) {
|
||||
add_edge_if_not_present(g.start, v, g);
|
||||
add_edge_if_not_present(g.startDs, v, g);
|
||||
}
|
||||
|
||||
@@ -506,14 +506,14 @@ bool transformMinLengthToRepeat(NGHolder &g, ReportManager &rm) {
|
||||
while (v != cyclic) {
|
||||
DEBUG_PRINTF("vertex %zu\n", g[v].index);
|
||||
width++;
|
||||
auto succ = succs(v, g);
|
||||
if (contains(succ, cyclic)) {
|
||||
if (succ.size() == 1) {
|
||||
auto s = succs(v, g);
|
||||
if (contains(s, cyclic)) {
|
||||
if (s.size() == 1) {
|
||||
v = cyclic;
|
||||
} else if (succ.size() == 2) {
|
||||
} else if (s.size() == 2) {
|
||||
// Cyclic and jump edge.
|
||||
succ.erase(cyclic);
|
||||
NFAVertex v2 = *succ.begin();
|
||||
s.erase(cyclic);
|
||||
NFAVertex v2 = *s.begin();
|
||||
if (!edge(cyclic, v2, g).second) {
|
||||
DEBUG_PRINTF("bad form\n");
|
||||
return false;
|
||||
@@ -524,11 +524,11 @@ bool transformMinLengthToRepeat(NGHolder &g, ReportManager &rm) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (succ.size() != 1) {
|
||||
if (s.size() != 1) {
|
||||
DEBUG_PRINTF("bad form\n");
|
||||
return false;
|
||||
}
|
||||
v = *succ.begin();
|
||||
v = *s.begin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,12 +544,12 @@ bool transformMinLengthToRepeat(NGHolder &g, ReportManager &rm) {
|
||||
while (!is_any_accept(v, g)) {
|
||||
DEBUG_PRINTF("vertex %zu\n", g[v].index);
|
||||
width++;
|
||||
auto succ = succs(v, g);
|
||||
if (succ.size() != 1) {
|
||||
auto s = succs(v, g);
|
||||
if (s.size() != 1) {
|
||||
DEBUG_PRINTF("bad form\n");
|
||||
return false;
|
||||
}
|
||||
v = *succ.begin();
|
||||
v = *s.begin();
|
||||
}
|
||||
|
||||
int offsetAdjust = 0;
|
||||
@@ -569,14 +569,14 @@ bool transformMinLengthToRepeat(NGHolder &g, ReportManager &rm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<NFAVertex> preds;
|
||||
vector<NFAVertex> predcs;
|
||||
vector<NFAEdge> dead;
|
||||
for (auto u : inv_adjacent_vertices_range(cyclic, g)) {
|
||||
DEBUG_PRINTF("pred %zu\n", g[u].index);
|
||||
if (u == cyclic) {
|
||||
continue;
|
||||
}
|
||||
preds.emplace_back(u);
|
||||
predcs.emplace_back(u);
|
||||
|
||||
// We want to delete the out-edges of each predecessor, but need to
|
||||
// make sure we don't delete the startDs self loop.
|
||||
@@ -589,7 +589,7 @@ bool transformMinLengthToRepeat(NGHolder &g, ReportManager &rm) {
|
||||
|
||||
remove_edges(dead, g);
|
||||
|
||||
assert(!preds.empty());
|
||||
assert(!predcs.empty());
|
||||
|
||||
const CharReach &cr = g[cyclic].char_reach;
|
||||
|
||||
@@ -597,14 +597,14 @@ bool transformMinLengthToRepeat(NGHolder &g, ReportManager &rm) {
|
||||
v = add_vertex(g);
|
||||
g[v].char_reach = cr;
|
||||
|
||||
for (auto u : preds) {
|
||||
for (auto u : predcs) {
|
||||
add_edge(u, v, g);
|
||||
}
|
||||
preds.clear();
|
||||
preds.emplace_back(v);
|
||||
predcs.clear();
|
||||
predcs.emplace_back(v);
|
||||
}
|
||||
assert(!preds.empty());
|
||||
for (auto u : preds) {
|
||||
for (auto u : predcs) {
|
||||
add_edge(u, cyclic, g);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,15 +66,15 @@ bool findMask(const NGHolder &g, vector<CharReach> *mask, bool *anchored,
|
||||
return false;
|
||||
}
|
||||
|
||||
set<NFAVertex> &succs = *anchored ? s_succ : sds_succ;
|
||||
succs.erase(g.startDs);
|
||||
if (succs.size() != 1) {
|
||||
set<NFAVertex> &succrs = *anchored ? s_succ : sds_succ;
|
||||
succrs.erase(g.startDs);
|
||||
if (succrs.size() != 1) {
|
||||
DEBUG_PRINTF("branchy root\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
NFAVertex u = *anchored ? g.start : g.startDs;
|
||||
NFAVertex v = *succs.begin();
|
||||
NFAVertex v = *succrs.begin();
|
||||
|
||||
while (true) {
|
||||
DEBUG_PRINTF("validating vertex %zu\n", g[v].index);
|
||||
|
||||
@@ -71,13 +71,13 @@ vector<flat_set<NFAVertex>> gatherSuccessorsByDepth(const NGHolder &g,
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto succ : adjacent_vertices_range(v, g)) {
|
||||
for (auto succr : adjacent_vertices_range(v, g)) {
|
||||
// ignore self-loops
|
||||
if (v == succ) {
|
||||
if (v == succr) {
|
||||
continue;
|
||||
}
|
||||
DEBUG_PRINTF("Node %zu depth %u\n", g[succ].index, d + 1);
|
||||
next.insert(succ);
|
||||
next.insert(succr);
|
||||
}
|
||||
}
|
||||
result[d] = next;
|
||||
@@ -113,13 +113,13 @@ vector<flat_set<NFAVertex>> gatherPredecessorsByDepth(const NGHolder &g,
|
||||
for (unsigned d = 1; d < depth; d++) {
|
||||
// collect all successors for all current level vertices
|
||||
for (auto v : cur) {
|
||||
for (auto pred : inv_adjacent_vertices_range(v, g)) {
|
||||
for (auto predc : inv_adjacent_vertices_range(v, g)) {
|
||||
// ignore self-loops
|
||||
if (v == pred) {
|
||||
if (v == predc) {
|
||||
continue;
|
||||
}
|
||||
DEBUG_PRINTF("Node %zu depth %u\n", g[pred].index, d + 1);
|
||||
next.insert(pred);
|
||||
next.insert(predc);
|
||||
}
|
||||
}
|
||||
result[d] = next;
|
||||
@@ -584,9 +584,9 @@ private:
|
||||
bool clone = false;
|
||||
for (auto &pair : reports_to_vertices) {
|
||||
const auto &reports = pair.first;
|
||||
const auto &vertices = pair.second;
|
||||
const auto &svertices = pair.second;
|
||||
|
||||
for (auto src : vertices) {
|
||||
for (auto src : svertices) {
|
||||
// get all predecessors up to edit distance
|
||||
auto src_vertices_by_depth =
|
||||
gatherPredecessorsByDepth(g, src, edit_distance);
|
||||
@@ -602,8 +602,8 @@ private:
|
||||
assert(targets.size());
|
||||
|
||||
for (unsigned d = 0; d < src_vertices_by_depth.size(); d++) {
|
||||
const auto &preds = src_vertices_by_depth[d];
|
||||
for (auto v : preds) {
|
||||
const auto &predcs = src_vertices_by_depth[d];
|
||||
for (auto v : predcs) {
|
||||
// only clone a node if it already contains reports
|
||||
if (clone && !g[v].reports.empty()) {
|
||||
create_clone(v, reports, edit_distance - d,
|
||||
|
||||
@@ -342,7 +342,7 @@ void attemptToUseAsStart(const NGHolder &g, NFAVertex u,
|
||||
map<NFAVertex, flat_set<u32>> &unhandled_succ_tops,
|
||||
map<u32, set<NFAVertex>> &tops_out) {
|
||||
flat_set<u32> top_inter = unhandled_succ_tops.at(u);
|
||||
flat_set<NFAVertex> succs;
|
||||
flat_set<NFAVertex> f_succs;
|
||||
for (NFAVertex v : adjacent_vertices_range(u, g)) {
|
||||
if (!contains(unhandled_succ_tops, v)) {
|
||||
return;
|
||||
@@ -360,7 +360,7 @@ void attemptToUseAsStart(const NGHolder &g, NFAVertex u,
|
||||
set_intersection(top_inter.begin(), top_inter.end(),
|
||||
v_tops.begin(), v_tops.end(), ni_inserter);
|
||||
top_inter = std::move(new_inter);
|
||||
succs.insert(v);
|
||||
f_succs.insert(v);
|
||||
}
|
||||
|
||||
if (top_inter.empty()) {
|
||||
@@ -373,7 +373,7 @@ void attemptToUseAsStart(const NGHolder &g, NFAVertex u,
|
||||
}
|
||||
|
||||
DEBUG_PRINTF("reusing %zu is a start vertex\n", g[u].index);
|
||||
markTopSuccAsHandled(u, top_inter, succs, tops_out, unhandled_top_succs,
|
||||
markTopSuccAsHandled(u, top_inter, f_succs, tops_out, unhandled_top_succs,
|
||||
unhandled_succ_tops);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,12 +62,12 @@ namespace ue2 {
|
||||
static
|
||||
void findAccelFriendGeneration(const NGHolder &g, const CharReach &cr,
|
||||
const flat_set<NFAVertex> &cands,
|
||||
const flat_set<NFAVertex> &preds,
|
||||
const flat_set<NFAVertex> &f_preds,
|
||||
flat_set<NFAVertex> *next_cands,
|
||||
flat_set<NFAVertex> *next_preds,
|
||||
flat_set<NFAVertex> *friends) {
|
||||
for (auto v : cands) {
|
||||
if (contains(preds, v)) {
|
||||
if (contains(f_preds, v)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ void findAccelFriendGeneration(const NGHolder &g, const CharReach &cr,
|
||||
}
|
||||
|
||||
for (auto u : inv_adjacent_vertices_range(v, g)) {
|
||||
if (!contains(preds, u)) {
|
||||
if (!contains(f_preds, u)) {
|
||||
DEBUG_PRINTF("bad pred\n");
|
||||
goto next_cand;
|
||||
}
|
||||
@@ -116,8 +116,8 @@ void findAccelFriends(const NGHolder &g, NFAVertex v,
|
||||
|
||||
u32 friend_depth = offset + 1;
|
||||
|
||||
flat_set<NFAVertex> preds;
|
||||
insert(&preds, inv_adjacent_vertices(v, g));
|
||||
flat_set<NFAVertex> f_preds;
|
||||
insert(&f_preds, inv_adjacent_vertices(v, g));
|
||||
const CharReach &cr = g[v].char_reach;
|
||||
|
||||
flat_set<NFAVertex> cands;
|
||||
@@ -126,9 +126,9 @@ void findAccelFriends(const NGHolder &g, NFAVertex v,
|
||||
flat_set<NFAVertex> next_preds;
|
||||
flat_set<NFAVertex> next_cands;
|
||||
for (u32 i = 0; i < friend_depth; i++) {
|
||||
findAccelFriendGeneration(g, cr, cands, preds, &next_cands, &next_preds,
|
||||
findAccelFriendGeneration(g, cr, cands, f_preds, &next_cands, &next_preds,
|
||||
friends);
|
||||
preds.insert(next_preds.begin(), next_preds.end());
|
||||
f_preds.insert(next_preds.begin(), next_preds.end());
|
||||
next_preds.clear();
|
||||
cands.swap(next_cands);
|
||||
next_cands.clear();
|
||||
|
||||
@@ -94,7 +94,7 @@ void transition_graph(autom &nfa, const std::vector<NFAVertex> &vByStateId,
|
||||
/* generate top transitions, false -> top = selfloop */
|
||||
bool top_allowed = is_triggered(graph);
|
||||
|
||||
StateSet succ = nfa.dead;
|
||||
StateSet succr = nfa.dead;
|
||||
for (size_t i = in.find_first(); i != in.npos; i = in.find_next(i)) {
|
||||
NFAVertex u = vByStateId[i];
|
||||
|
||||
@@ -102,7 +102,7 @@ void transition_graph(autom &nfa, const std::vector<NFAVertex> &vByStateId,
|
||||
if (contains(unused, v)) {
|
||||
continue;
|
||||
}
|
||||
succ.set(graph[v].index);
|
||||
succr.set(graph[v].index);
|
||||
}
|
||||
|
||||
if (top_allowed && !nfa.toppable.test(i)) {
|
||||
@@ -112,15 +112,15 @@ void transition_graph(autom &nfa, const std::vector<NFAVertex> &vByStateId,
|
||||
}
|
||||
}
|
||||
|
||||
StateSet active_squash = succ & squash;
|
||||
StateSet active_squash = succr & squash;
|
||||
if (active_squash.any()) {
|
||||
for (size_t j = active_squash.find_first(); j != active_squash.npos;
|
||||
j = active_squash.find_next(j)) {
|
||||
succ &= squash_mask.find(j)->second;
|
||||
succr &= squash_mask.find(j)->second;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j = succ.find_first(); j != succ.npos; j = succ.find_next(j)) {
|
||||
for (size_t j = succr.find_first(); j != succr.npos; j = succr.find_next(j)) {
|
||||
const CharReach &cr = cr_by_index[j];
|
||||
for (size_t s = cr.find_first(); s != cr.npos; s = cr.find_next(s)) {
|
||||
next[s].set(j); /* already alpha'ed */
|
||||
|
||||
@@ -398,19 +398,19 @@ CharReach reduced_cr(NFAVertex v, const NGHolder &g,
|
||||
return v_cr;
|
||||
}
|
||||
|
||||
NFAVertex pred = getSoleSourceVertex(g, v);
|
||||
assert(pred);
|
||||
NFAVertex s_pred = getSoleSourceVertex(g, v);
|
||||
assert(s_pred);
|
||||
|
||||
/* require pred to be fed by one vertex OR (start + startDS) */
|
||||
/* require s_pred to be fed by one vertex OR (start + startDS) */
|
||||
NFAVertex predpred;
|
||||
size_t idp = in_degree(pred, g);
|
||||
if (hasSelfLoop(pred, g)) {
|
||||
size_t idp = in_degree(s_pred, g);
|
||||
if (hasSelfLoop(s_pred, g)) {
|
||||
return v_cr; /* not cliche */
|
||||
} else if (idp == 1) {
|
||||
predpred = getSoleSourceVertex(g, pred);
|
||||
predpred = getSoleSourceVertex(g, s_pred);
|
||||
} else if (idp == 2
|
||||
&& edge(g.start, pred, g).second
|
||||
&& edge(g.startDs, pred, g).second) {
|
||||
&& edge(g.start, s_pred, g).second
|
||||
&& edge(g.startDs, s_pred, g).second) {
|
||||
predpred = g.startDs;
|
||||
} else {
|
||||
return v_cr; /* not cliche */
|
||||
@@ -419,7 +419,7 @@ CharReach reduced_cr(NFAVertex v, const NGHolder &g,
|
||||
assert(predpred);
|
||||
|
||||
/* require predpred to be cyclic and its cr to be a superset of
|
||||
pred and v */
|
||||
s_pred and v */
|
||||
if (!hasSelfLoop(predpred, g)) {
|
||||
return v_cr; /* not cliche */
|
||||
}
|
||||
@@ -429,7 +429,7 @@ CharReach reduced_cr(NFAVertex v, const NGHolder &g,
|
||||
return v_cr; /* fake cyclic */
|
||||
}
|
||||
|
||||
const CharReach &p_cr = g[pred].char_reach;
|
||||
const CharReach &p_cr = g[s_pred].char_reach;
|
||||
const CharReach &pp_cr = g[predpred].char_reach;
|
||||
if (!v_cr.isSubsetOf(pp_cr) || !p_cr.isSubsetOf(pp_cr)) {
|
||||
return v_cr; /* not cliche */
|
||||
@@ -440,7 +440,7 @@ CharReach reduced_cr(NFAVertex v, const NGHolder &g,
|
||||
set<NFAVertex> v_succ;
|
||||
insert(&v_succ, adjacent_vertices(v, g));
|
||||
set<NFAVertex> p_succ;
|
||||
insert(&p_succ, adjacent_vertices(pred, g));
|
||||
insert(&p_succ, adjacent_vertices(s_pred, g));
|
||||
|
||||
if (!is_subset_of(v_succ, p_succ)) {
|
||||
DEBUG_PRINTF("fail\n");
|
||||
@@ -450,7 +450,7 @@ CharReach reduced_cr(NFAVertex v, const NGHolder &g,
|
||||
if (contains(v_succ, g.accept) || contains(v_succ, g.acceptEod)) {
|
||||
/* need to check that reports of v are a subset of p's */
|
||||
if (!is_subset_of(g[v].reports,
|
||||
g[pred].reports)) {
|
||||
g[s_pred].reports)) {
|
||||
DEBUG_PRINTF("fail - reports not subset\n");
|
||||
return v_cr; /* not cliche */
|
||||
}
|
||||
|
||||
@@ -391,9 +391,9 @@ void checkReachSubgraphs(const NGHolder &g, vector<ReachSubgraph> &rs,
|
||||
unordered_set<NFAVertex> involved(rsi.vertices.begin(),
|
||||
rsi.vertices.end());
|
||||
unordered_set<NFAVertex> tail(involved); // to look for back-edges.
|
||||
unordered_set<NFAVertex> pred, succ;
|
||||
proper_pred(g, rsi.vertices.front(), pred);
|
||||
proper_succ(g, rsi.vertices.back(), succ);
|
||||
unordered_set<NFAVertex> v_pred, v_succ;
|
||||
proper_pred(g, rsi.vertices.front(), v_pred);
|
||||
proper_succ(g, rsi.vertices.back(), v_succ);
|
||||
|
||||
flat_set<ReportID> reports;
|
||||
findFirstReports(g, rsi, reports);
|
||||
@@ -404,7 +404,7 @@ void checkReachSubgraphs(const NGHolder &g, vector<ReachSubgraph> &rs,
|
||||
for (auto v : rsi.vertices) {
|
||||
tail.erase(v); // now contains all vertices _after_ this one.
|
||||
|
||||
if (vertexIsBad(g, v, involved, tail, pred, succ, reports)) {
|
||||
if (vertexIsBad(g, v, involved, tail, v_pred, v_succ, reports)) {
|
||||
recalc = true;
|
||||
continue;
|
||||
}
|
||||
@@ -788,10 +788,10 @@ void replaceSubgraphWithSpecial(NGHolder &g, ReachSubgraph &rsi,
|
||||
|
||||
const unordered_set<NFAVertex> involved(rsi.vertices.begin(),
|
||||
rsi.vertices.end());
|
||||
vector<NFAVertex> succs;
|
||||
getSuccessors(g, rsi, &succs);
|
||||
vector<NFAVertex> g_succs;
|
||||
getSuccessors(g, rsi, &g_succs);
|
||||
|
||||
unpeelNearEnd(g, rsi, depths, &succs);
|
||||
unpeelNearEnd(g, rsi, depths, &g_succs);
|
||||
|
||||
// Create our replacement cyclic state with the same reachability and
|
||||
// report info as the last vertex in our topo-ordered list.
|
||||
@@ -819,7 +819,7 @@ void replaceSubgraphWithSpecial(NGHolder &g, ReachSubgraph &rsi,
|
||||
|
||||
// Wire cyclic state to tug trigger states built from successors.
|
||||
vector<NFAVertex> tugs;
|
||||
for (auto v : succs) {
|
||||
for (auto v : g_succs) {
|
||||
buildTugTrigger(g, cyclic, v, involved, depths, tugs);
|
||||
}
|
||||
created.insert(tugs.begin(), tugs.end());
|
||||
@@ -857,8 +857,8 @@ void replaceSubgraphWithLazySpecial(NGHolder &g, ReachSubgraph &rsi,
|
||||
|
||||
const unordered_set<NFAVertex> involved(rsi.vertices.begin(),
|
||||
rsi.vertices.end());
|
||||
vector<NFAVertex> succs;
|
||||
getSuccessors(g, rsi, &succs);
|
||||
vector<NFAVertex> g_succs;
|
||||
getSuccessors(g, rsi, &g_succs);
|
||||
|
||||
// Create our replacement cyclic state with the same reachability and
|
||||
// report info as the last vertex in our topo-ordered list.
|
||||
@@ -887,15 +887,15 @@ void replaceSubgraphWithLazySpecial(NGHolder &g, ReachSubgraph &rsi,
|
||||
// In the rose case, our tug is our cyclic, and it's wired to our
|
||||
// successors (which should be just the accept).
|
||||
vector<NFAVertex> tugs;
|
||||
assert(succs.size() == 1);
|
||||
for (auto v : succs) {
|
||||
assert(g_succs.size() == 1);
|
||||
for (auto v : g_succs) {
|
||||
add_edge(cyclic, v, g);
|
||||
}
|
||||
|
||||
// Wire pos trigger to accept if min repeat is one -- this deals with cases
|
||||
// where we can get a pos and tug trigger on the same byte.
|
||||
if (rsi.repeatMin == depth(1)) {
|
||||
for (auto v : succs) {
|
||||
for (auto v : g_succs) {
|
||||
add_edge(pos_trigger, v, g);
|
||||
g[pos_trigger].reports = g[cyclic].reports;
|
||||
}
|
||||
@@ -1456,9 +1456,9 @@ struct StrawWalker {
|
||||
}
|
||||
if (ai != ae) {
|
||||
DEBUG_PRINTF("more than one succ\n");
|
||||
set<NFAVertex> succs;
|
||||
insert(&succs, adjacent_vertices(v, g));
|
||||
succs.erase(v);
|
||||
set<NFAVertex> a_succs;
|
||||
insert(&a_succs, adjacent_vertices(v, g));
|
||||
a_succs.erase(v);
|
||||
for (tie(ai, ae) = adjacent_vertices(v, g); ai != ae; ++ai) {
|
||||
next = *ai;
|
||||
DEBUG_PRINTF("checking %zu\n", g[next].index);
|
||||
@@ -1468,7 +1468,7 @@ struct StrawWalker {
|
||||
set<NFAVertex> lsuccs;
|
||||
insert(&lsuccs, adjacent_vertices(next, g));
|
||||
|
||||
if (lsuccs != succs) {
|
||||
if (lsuccs != a_succs) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1895,9 +1895,9 @@ bool improveLeadingRepeat(NGHolder &g, BoundedRepeatData &rd,
|
||||
}
|
||||
|
||||
vector<NFAVertex> straw;
|
||||
NFAVertex pred =
|
||||
NFAVertex w_pred =
|
||||
walkStrawToCyclicRev(g, rd.pos_trigger, all_repeats, straw);
|
||||
if (pred != g.startDs) {
|
||||
if (w_pred != g.startDs) {
|
||||
DEBUG_PRINTF("straw walk doesn't lead to startDs\n");
|
||||
return false;
|
||||
}
|
||||
@@ -1999,9 +1999,9 @@ bool improveLeadingRepeatOutfix(NGHolder &g, BoundedRepeatData &rd,
|
||||
}
|
||||
|
||||
vector<NFAVertex> straw;
|
||||
NFAVertex pred =
|
||||
NFAVertex w_pred =
|
||||
walkStrawToCyclicRev(g, rd.pos_trigger, all_repeats, straw);
|
||||
if (pred != g.startDs) {
|
||||
if (w_pred != g.startDs) {
|
||||
DEBUG_PRINTF("straw walk doesn't lead to startDs\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -876,18 +876,18 @@ bool beginsWithDotStar(const NGHolder &g) {
|
||||
// We can ignore the successors of start, as matches that begin there will
|
||||
// necessarily have a SOM of 0.
|
||||
|
||||
set<NFAVertex> succ;
|
||||
insert(&succ, adjacent_vertices(g.startDs, g));
|
||||
succ.erase(g.startDs);
|
||||
set<NFAVertex> a_succ;
|
||||
insert(&a_succ, adjacent_vertices(g.startDs, g));
|
||||
a_succ.erase(g.startDs);
|
||||
|
||||
for (auto v : succ) {
|
||||
for (auto v : a_succ) {
|
||||
// We want 'dot' states that aren't virtual starts.
|
||||
if (g[v].char_reach.all() &&
|
||||
!g[v].assert_flags) {
|
||||
hasDot = true;
|
||||
set<NFAVertex> dotsucc;
|
||||
insert(&dotsucc, adjacent_vertices(v, g));
|
||||
if (dotsucc != succ) {
|
||||
if (dotsucc != a_succ) {
|
||||
DEBUG_PRINTF("failed dot-star succ check\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ bool forkVertex(NFAVertex v, NGHolder &g, vector<DepthMinMax> &depths,
|
||||
|
||||
for (auto &group : predGroups) {
|
||||
const depth &predDepth = group.first;
|
||||
const vector<NFAEdge> &preds = group.second;
|
||||
const vector<NFAEdge> &gspreds = group.second;
|
||||
|
||||
// Clone v for this depth with all its associated out-edges.
|
||||
u32 clone_idx = depths.size(); // next index to be used
|
||||
@@ -130,8 +130,8 @@ bool forkVertex(NFAVertex v, NGHolder &g, vector<DepthMinMax> &depths,
|
||||
add_edge(clone, target(e, g), g[e], g);
|
||||
}
|
||||
|
||||
// Add in-edges from preds in this group.
|
||||
for (const auto &e : preds) {
|
||||
// Add in-edges from gspreds in this group.
|
||||
for (const auto &e : gspreds) {
|
||||
add_edge(source(e, g), clone, g[e], g);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,19 +255,19 @@ void buildSquashMask(NFAStateSet &mask, const NGHolder &g, NFAVertex v,
|
||||
}
|
||||
|
||||
static
|
||||
void buildSucc(NFAStateSet &succ, const NGHolder &g, NFAVertex v) {
|
||||
void buildSucc(NFAStateSet &ssucc, const NGHolder &g, NFAVertex v) {
|
||||
for (auto w : adjacent_vertices_range(v, g)) {
|
||||
if (!is_special(w, g)) {
|
||||
succ.set(g[w].index);
|
||||
ssucc.set(g[w].index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void buildPred(NFAStateSet &pred, const NGHolder &g, NFAVertex v) {
|
||||
void buildPred(NFAStateSet &spred, const NGHolder &g, NFAVertex v) {
|
||||
for (auto u : inv_adjacent_vertices_range(v, g)) {
|
||||
if (!is_special(u, g)) {
|
||||
pred.set(g[u].index);
|
||||
spred.set(g[u].index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -408,19 +408,19 @@ unordered_map<NFAVertex, NFAStateSet> findSquashers(const NGHolder &g,
|
||||
|
||||
DEBUG_PRINTF("state %u is cyclic\n", i);
|
||||
|
||||
NFAStateSet mask(numStates), succ(numStates), pred(numStates);
|
||||
NFAStateSet mask(numStates), ssucc(numStates), spred(numStates);
|
||||
buildSquashMask(mask, g, v, cr, initStates, vByIndex, pdom_tree, som,
|
||||
som_depths, region_map, cache);
|
||||
buildSucc(succ, g, v);
|
||||
buildPred(pred, g, v);
|
||||
buildSucc(ssucc, g, v);
|
||||
buildPred(spred, g, v);
|
||||
const auto &reports = g[v].reports;
|
||||
|
||||
for (size_t j = succ.find_first(); j != succ.npos;
|
||||
j = succ.find_next(j)) {
|
||||
for (size_t j = ssucc.find_first(); j != ssucc.npos;
|
||||
j = ssucc.find_next(j)) {
|
||||
NFAVertex vj = vByIndex[j];
|
||||
NFAStateSet pred2(numStates);
|
||||
buildPred(pred2, g, vj);
|
||||
if (pred2 == pred) {
|
||||
if (pred2 == spred) {
|
||||
DEBUG_PRINTF("adding the sm from %zu to %u's sm\n", j, i);
|
||||
NFAStateSet tmp(numStates);
|
||||
buildSquashMask(tmp, g, vj, cr, initStates, vByIndex, pdom_tree,
|
||||
@@ -429,14 +429,14 @@ unordered_map<NFAVertex, NFAStateSet> findSquashers(const NGHolder &g,
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j = pred.find_first(); j != pred.npos;
|
||||
j = pred.find_next(j)) {
|
||||
for (size_t j = spred.find_first(); j != spred.npos;
|
||||
j = spred.find_next(j)) {
|
||||
NFAVertex vj = vByIndex[j];
|
||||
NFAStateSet succ2(numStates);
|
||||
buildSucc(succ2, g, vj);
|
||||
/* we can use j as a basis for squashing if its succs are a subset
|
||||
* of ours */
|
||||
if ((succ2 & ~succ).any()) {
|
||||
if ((succ2 & ~ssucc).any()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -709,15 +709,15 @@ u32 removeTrailingLiteralStates(NGHolder &g, const ue2_literal &lit,
|
||||
assert(delay <= lit.length());
|
||||
DEBUG_PRINTF("managed delay %u (of max %u)\n", delay, max_delay);
|
||||
|
||||
set<NFAVertex> pred;
|
||||
set<NFAVertex> predv;
|
||||
for (auto v : curr) {
|
||||
insert(&pred, inv_adjacent_vertices_range(v, g));
|
||||
insert(&predv, inv_adjacent_vertices_range(v, g));
|
||||
}
|
||||
|
||||
clear_in_edges(g.accept, g);
|
||||
clearReports(g);
|
||||
|
||||
for (auto v : pred) {
|
||||
for (auto v : predv) {
|
||||
NFAEdge e = add_edge(v, g.accept, g);
|
||||
g[v].reports.insert(0);
|
||||
if (is_triggered(g) && v == g.start) {
|
||||
|
||||
@@ -704,13 +704,13 @@ unique_ptr<VertLitInfo> findBestSplit(const NGHolder &g,
|
||||
}
|
||||
}
|
||||
|
||||
auto cmp = LitComparator(g, seeking_anchored, seeking_transient,
|
||||
auto lcmp = LitComparator(g, seeking_anchored, seeking_transient,
|
||||
last_chance);
|
||||
|
||||
unique_ptr<VertLitInfo> best = std::move(lits.back());
|
||||
lits.pop_back();
|
||||
while (!lits.empty()) {
|
||||
if (cmp(best, lits.back())) {
|
||||
if (lcmp(best, lits.back())) {
|
||||
best = std::move(lits.back());
|
||||
}
|
||||
lits.pop_back();
|
||||
@@ -812,7 +812,7 @@ flat_set<NFAEdge> poisonEdges(const NGHolder &h,
|
||||
|
||||
/* poison edges covered by successor literal */
|
||||
|
||||
set<pair<ue2_literal, bool> > succs;
|
||||
set<pair<ue2_literal, bool> > lsuccs;
|
||||
for (const RoseInEdge &ve : ee) {
|
||||
if (vg[target(ve, vg)].type != RIV_LITERAL) {
|
||||
/* nothing to poison in suffixes/outfixes */
|
||||
@@ -820,15 +820,15 @@ flat_set<NFAEdge> poisonEdges(const NGHolder &h,
|
||||
assert(is_any_accept_type(vg[target(ve, vg)].type));
|
||||
continue;
|
||||
}
|
||||
succs.insert({vg[target(ve, vg)].s,
|
||||
lsuccs.insert({vg[target(ve, vg)].s,
|
||||
vg[source(ve, vg)].type == RIV_LITERAL});
|
||||
|
||||
}
|
||||
|
||||
DEBUG_PRINTF("poisoning edges %zu successor literals\n", succs.size());
|
||||
DEBUG_PRINTF("poisoning edges %zu successor literals\n", lsuccs.size());
|
||||
|
||||
flat_set<NFAEdge> bad;
|
||||
for (const auto &p : succs) {
|
||||
for (const auto &p : lsuccs) {
|
||||
poisonFromSuccessor(h, p.first, p.second, bad);
|
||||
}
|
||||
|
||||
@@ -1434,11 +1434,11 @@ bool deanchorIfNeeded(NGHolder &g) {
|
||||
|
||||
if (succ_v == succ_g) {
|
||||
DEBUG_PRINTF("found ^.*\n");
|
||||
for (auto succ : adjacent_vertices_range(g.start, g)) {
|
||||
if (succ == g.startDs) {
|
||||
for (auto asucc : adjacent_vertices_range(g.start, g)) {
|
||||
if (asucc == g.startDs) {
|
||||
continue;
|
||||
}
|
||||
add_edge(g.startDs, succ, g);
|
||||
add_edge(g.startDs, asucc, g);
|
||||
}
|
||||
clear_vertex(v, g);
|
||||
remove_vertex(v, g);
|
||||
@@ -1685,18 +1685,18 @@ void removeRedundantLiteralsFromInfix(const NGHolder &h, RoseInGraph &ig,
|
||||
* successor literal. This would require using distinct report ids and also
|
||||
* taking into account overlap of successor literals. */
|
||||
|
||||
set<ue2_literal> preds;
|
||||
set<ue2_literal> succs;
|
||||
set<ue2_literal> lpreds;
|
||||
set<ue2_literal> lsuccs;
|
||||
for (const RoseInEdge &e : ee) {
|
||||
RoseInVertex u = source(e, ig);
|
||||
assert(ig[u].type == RIV_LITERAL);
|
||||
assert(!ig[u].delay);
|
||||
preds.insert(ig[u].s);
|
||||
lpreds.insert(ig[u].s);
|
||||
|
||||
RoseInVertex v = target(e, ig);
|
||||
assert(ig[v].type == RIV_LITERAL);
|
||||
assert(!ig[v].delay);
|
||||
succs.insert(ig[v].s);
|
||||
lsuccs.insert(ig[v].s);
|
||||
|
||||
if (ig[e].graph_lag) {
|
||||
/* already removed redundant parts of literals */
|
||||
@@ -1708,9 +1708,9 @@ void removeRedundantLiteralsFromInfix(const NGHolder &h, RoseInGraph &ig,
|
||||
|
||||
map<ue2_literal, pair<shared_ptr<NGHolder>, u32> > graphs; /* + delay */
|
||||
|
||||
for (const ue2_literal &right : succs) {
|
||||
for (const ue2_literal &right : lsuccs) {
|
||||
size_t max_overlap = 0;
|
||||
for (const ue2_literal &left : preds) {
|
||||
for (const ue2_literal &left : lpreds) {
|
||||
size_t overlap = maxOverlap(left, right, 0);
|
||||
ENSURE_AT_LEAST(&max_overlap, overlap);
|
||||
}
|
||||
@@ -1747,13 +1747,13 @@ void removeRedundantLiteralsFromInfix(const NGHolder &h, RoseInGraph &ig,
|
||||
|
||||
for (const RoseInEdge &e : ee) {
|
||||
RoseInVertex v = target(e, ig);
|
||||
const ue2_literal &succ = ig[v].s;
|
||||
if (!contains(graphs, succ)) {
|
||||
const ue2_literal &igsucc = ig[v].s;
|
||||
if (!contains(graphs, igsucc)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ig[e].graph = graphs[succ].first;
|
||||
ig[e].graph_lag = graphs[succ].second;
|
||||
ig[e].graph = graphs[igsucc].first;
|
||||
ig[e].graph_lag = graphs[igsucc].second;
|
||||
|
||||
if (isStarCliche(*ig[e].graph)) {
|
||||
DEBUG_PRINTF("is a X star!\n");
|
||||
@@ -1793,8 +1793,8 @@ void removeRedundantLiteralsFromInfixes(RoseInGraph &g,
|
||||
|
||||
for (const auto &m : infixes) {
|
||||
NGHolder *h = m.first;
|
||||
const auto &edges = m.second;
|
||||
removeRedundantLiteralsFromInfix(*h, g, edges, cc);
|
||||
const auto &medges = m.second;
|
||||
removeRedundantLiteralsFromInfix(*h, g, medges, cc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1953,7 +1953,7 @@ bool makeTransientFromLongLiteral(NGHolder &h, RoseInGraph &vg,
|
||||
|
||||
static
|
||||
void restoreTrailingLiteralStates(NGHolder &g, const ue2_literal &lit,
|
||||
u32 delay, const vector<NFAVertex> &preds) {
|
||||
u32 delay, const vector<NFAVertex> &lpreds) {
|
||||
assert(delay <= lit.length());
|
||||
assert(isCorrectlyTopped(g));
|
||||
DEBUG_PRINTF("adding on '%s' %u\n", dumpString(lit).c_str(), delay);
|
||||
@@ -1969,7 +1969,7 @@ void restoreTrailingLiteralStates(NGHolder &g, const ue2_literal &lit,
|
||||
prev = curr;
|
||||
}
|
||||
|
||||
for (auto v : preds) {
|
||||
for (auto v : lpreds) {
|
||||
NFAEdge e = add_edge_if_not_present(v, prev, g);
|
||||
if (v == g.start && is_triggered(g)) {
|
||||
g[e].tops.insert(DEFAULT_TOP);
|
||||
@@ -1988,11 +1988,11 @@ void restoreTrailingLiteralStates(NGHolder &g, const ue2_literal &lit,
|
||||
static
|
||||
void restoreTrailingLiteralStates(NGHolder &g,
|
||||
const vector<pair<ue2_literal, u32>> &lits) {
|
||||
vector<NFAVertex> preds;
|
||||
insert(&preds, preds.end(), inv_adjacent_vertices(g.accept, g));
|
||||
vector<NFAVertex> vpreds;
|
||||
insert(&vpreds, vpreds.end(), inv_adjacent_vertices(g.accept, g));
|
||||
clear_in_edges(g.accept, g);
|
||||
|
||||
for (auto v : preds) {
|
||||
for (auto v : vpreds) {
|
||||
g[v].reports.clear(); /* clear report from old accepts */
|
||||
}
|
||||
|
||||
@@ -2000,7 +2000,7 @@ void restoreTrailingLiteralStates(NGHolder &g,
|
||||
const ue2_literal &lit = p.first;
|
||||
u32 delay = p.second;
|
||||
|
||||
restoreTrailingLiteralStates(g, lit, delay, preds);
|
||||
restoreTrailingLiteralStates(g, lit, delay, vpreds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2134,14 +2134,14 @@ void findBetterPrefixes(RoseInGraph &vg, const CompileContext &cc) {
|
||||
/* look for bad prefixes and try to split */
|
||||
for (const auto &m : prefixes) {
|
||||
NGHolder *h = m.first;
|
||||
const auto &edges = m.second;
|
||||
const auto &medges = m.second;
|
||||
depth max_width = findMaxWidth(*h);
|
||||
if (willBeTransient(max_width, cc)
|
||||
|| willBeAnchoredTable(max_width, cc.grey)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
changed = improvePrefix(*h, vg, edges, cc);
|
||||
changed = improvePrefix(*h, vg, medges, cc);
|
||||
}
|
||||
} while (changed && gen++ < MAX_FIND_BETTER_PREFIX_GEN);
|
||||
}
|
||||
@@ -2198,12 +2198,12 @@ void extractStrongLiterals(RoseInGraph &vg, const CompileContext &cc) {
|
||||
|
||||
for (const auto &m : edges_by_graph) {
|
||||
NGHolder *g = m.first;
|
||||
const auto &edges = m.second;
|
||||
const auto &medges = m.second;
|
||||
if (contains(stuck, g)) {
|
||||
DEBUG_PRINTF("already known to be bad\n");
|
||||
continue;
|
||||
}
|
||||
bool rv = extractStrongLiteral(*g, vg, edges, cc);
|
||||
bool rv = extractStrongLiteral(*g, vg, medges, cc);
|
||||
if (rv) {
|
||||
changed = true;
|
||||
} else {
|
||||
@@ -2281,8 +2281,8 @@ void improveWeakInfixes(RoseInGraph &vg, const CompileContext &cc) {
|
||||
|
||||
for (const auto &m : weak_edges) {
|
||||
NGHolder *h = m.first;
|
||||
const auto &edges = m.second;
|
||||
improveInfix(*h, vg, edges, cc);
|
||||
const auto &medges = m.second;
|
||||
improveInfix(*h, vg, medges, cc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2407,14 +2407,14 @@ bool replaceSuffixWithInfix(const NGHolder &h, RoseInGraph &vg,
|
||||
assert(!by_reports.empty());
|
||||
|
||||
/* TODO: how strong a min len do we want here ? */
|
||||
u32 min_len = cc.grey.minRoseLiteralLength;
|
||||
ENSURE_AT_LEAST(&min_len, MIN_SUFFIX_LEN);
|
||||
u32 rose_min_len = cc.grey.minRoseLiteralLength;
|
||||
ENSURE_AT_LEAST(&rose_min_len, MIN_SUFFIX_LEN);
|
||||
|
||||
for (auto &vli : by_reports | map_values) {
|
||||
u64a score = sanitizeAndCompressAndScore(vli.lit);
|
||||
|
||||
if (vli.lit.empty()
|
||||
|| !validateRoseLiteralSetQuality(vli.lit, score, false, min_len,
|
||||
|| !validateRoseLiteralSetQuality(vli.lit, score, false, rose_min_len,
|
||||
false, false)) {
|
||||
return false;
|
||||
}
|
||||
@@ -2458,8 +2458,8 @@ void avoidSuffixes(RoseInGraph &vg, const CompileContext &cc) {
|
||||
/* look at suffixes and try to split */
|
||||
for (const auto &m : suffixes) {
|
||||
const NGHolder *h = m.first;
|
||||
const auto &edges = m.second;
|
||||
replaceSuffixWithInfix(*h, vg, edges, cc);
|
||||
const auto &medges = m.second;
|
||||
replaceSuffixWithInfix(*h, vg, medges, cc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2553,8 +2553,8 @@ void lookForDoubleCut(RoseInGraph &vg, const CompileContext &cc) {
|
||||
|
||||
for (const auto &m : right_edges) {
|
||||
const NGHolder *h = m.first;
|
||||
const auto &edges = m.second;
|
||||
lookForDoubleCut(*h, edges, vg, cc.grey);
|
||||
const auto &medges = m.second;
|
||||
lookForDoubleCut(*h, medges, vg, cc.grey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2745,8 +2745,8 @@ void lookForCleanEarlySplits(RoseInGraph &vg, const CompileContext &cc) {
|
||||
|
||||
for (const auto &m : rightfixes) {
|
||||
const NGHolder *h = m.first;
|
||||
const auto &edges = m.second;
|
||||
lookForCleanSplit(*h, edges, vg, cc);
|
||||
const auto &medges = m.second;
|
||||
lookForCleanSplit(*h, medges, vg, cc);
|
||||
}
|
||||
|
||||
prev = std::move(curr);
|
||||
@@ -2942,10 +2942,10 @@ bool ensureImplementable(RoseBuild &rose, RoseInGraph &vg, bool allow_changes,
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto &edges = m.second;
|
||||
const auto &medges = m.second;
|
||||
|
||||
if (tryForEarlyDfa(*h, cc) &&
|
||||
doEarlyDfa(rose, vg, *h, edges, final_chance, rm, cc)) {
|
||||
doEarlyDfa(rose, vg, *h, medges, final_chance, rm, cc)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2954,7 +2954,7 @@ bool ensureImplementable(RoseBuild &rose, RoseInGraph &vg, bool allow_changes,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (splitForImplementability(vg, *h, edges, cc)) {
|
||||
if (splitForImplementability(vg, *h, medges, cc)) {
|
||||
added_count++;
|
||||
if (added_count > MAX_IMPLEMENTABLE_SPLITS) {
|
||||
DEBUG_PRINTF("added_count hit limit\n");
|
||||
|
||||
Reference in New Issue
Block a user