mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
allow edge_descriptors to be created from pair<edge_descriptor, bool>
This commit is contained in:
@@ -136,10 +136,7 @@ RoseVertex createVertex(RoseBuildImpl *build, const RoseVertex parent,
|
||||
/* fill in report information */
|
||||
g[v].reports.insert(reports.begin(), reports.end());
|
||||
|
||||
RoseEdge e;
|
||||
bool added;
|
||||
tie(e, added) = add_edge(parent, v, g);
|
||||
assert(added);
|
||||
RoseEdge e = add_edge(parent, v, g);
|
||||
DEBUG_PRINTF("adding edge (%u, %u) to parent\n", minBound, maxBound);
|
||||
|
||||
g[e].minBound = minBound;
|
||||
@@ -169,7 +166,7 @@ RoseVertex createAnchoredVertex(RoseBuildImpl *build, u32 literalId,
|
||||
DEBUG_PRINTF("created anchored vertex %zu with lit id %u\n", g[v].index,
|
||||
literalId);
|
||||
|
||||
RoseEdge e = add_edge(build->anchored_root, v, g).first;
|
||||
RoseEdge e = add_edge(build->anchored_root, v, g);
|
||||
g[e].minBound = min_offset;
|
||||
g[e].maxBound = max_offset;
|
||||
|
||||
@@ -315,10 +312,7 @@ void createVertices(RoseBuildImpl *tbi,
|
||||
|
||||
RoseVertex p = pv.first;
|
||||
|
||||
RoseEdge e;
|
||||
bool added;
|
||||
tie(e, added) = add_edge(p, w, g);
|
||||
assert(added);
|
||||
RoseEdge e = add_edge(p, w, g);
|
||||
DEBUG_PRINTF("adding edge (%u,%u) to parent\n", edge_props.minBound,
|
||||
edge_props.maxBound);
|
||||
g[e].minBound = edge_props.minBound;
|
||||
@@ -356,7 +350,7 @@ void createVertices(RoseBuildImpl *tbi,
|
||||
|
||||
for (const auto &pv : parents) {
|
||||
const RoseInEdgeProps &edge_props = bd.ig[pv.second];
|
||||
RoseEdge e = add_edge(pv.first, g_v, tbi->g).first;
|
||||
RoseEdge e = add_edge(pv.first, g_v, tbi->g);
|
||||
g[e].minBound = edge_props.minBound;
|
||||
g[e].maxBound = edge_props.maxBound;
|
||||
g[e].history = selectHistory(*tbi, bd, pv.second, e);
|
||||
@@ -709,7 +703,7 @@ void makeEodEventLeftfix(RoseBuildImpl &build, RoseVertex u,
|
||||
g[v].left.graph = eod_leftfix;
|
||||
g[v].left.leftfix_report = report_mapping.second;
|
||||
g[v].left.lag = 0;
|
||||
RoseEdge e1 = add_edge(u, v, g).first;
|
||||
RoseEdge e1 = add_edge(u, v, g);
|
||||
g[e1].minBound = 0;
|
||||
g[e1].maxBound = ROSE_BOUND_INF;
|
||||
g[v].min_offset = add_rose_depth(g[u].min_offset,
|
||||
@@ -729,7 +723,7 @@ void makeEodEventLeftfix(RoseBuildImpl &build, RoseVertex u,
|
||||
g[w].reports = report_mapping.first;
|
||||
g[w].min_offset = g[v].min_offset;
|
||||
g[w].max_offset = g[v].max_offset;
|
||||
RoseEdge e = add_edge(v, w, g).first;
|
||||
RoseEdge e = add_edge(v, w, g);
|
||||
g[e].minBound = 0;
|
||||
g[e].maxBound = 0;
|
||||
g[e].history = ROSE_ROLE_HISTORY_LAST_BYTE;
|
||||
@@ -803,7 +797,7 @@ void doRoseAcceptVertex(RoseBuildImpl *tbi,
|
||||
g[w].reports = ig[iv].reports;
|
||||
g[w].min_offset = g[u].min_offset;
|
||||
g[w].max_offset = g[u].max_offset;
|
||||
RoseEdge e = add_edge(u, w, g).first;
|
||||
RoseEdge e = add_edge(u, w, g);
|
||||
g[e].minBound = 0;
|
||||
g[e].maxBound = 0;
|
||||
g[e].history = ROSE_ROLE_HISTORY_LAST_BYTE;
|
||||
|
@@ -532,7 +532,7 @@ void addTransientMask(RoseBuildImpl &build, const vector<CharReach> &mask,
|
||||
g[v].left.leftfix_report = mask_report;
|
||||
} else {
|
||||
// Make sure our edge bounds are correct.
|
||||
auto e = edge(parent, v, g).first;
|
||||
RoseEdge e = edge(parent, v, g);
|
||||
g[e].minBound = 0;
|
||||
g[e].maxBound = anchored ? 0 : ROSE_BOUND_INF;
|
||||
g[e].history = anchored ? ROSE_ROLE_HISTORY_ANCH
|
||||
@@ -544,7 +544,7 @@ void addTransientMask(RoseBuildImpl &build, const vector<CharReach> &mask,
|
||||
g[v].max_offset = v_max_offset;
|
||||
|
||||
if (eod) {
|
||||
auto e = add_edge(v, eod_v, g).first;
|
||||
RoseEdge e = add_edge(v, eod_v, g);
|
||||
g[e].minBound = 0;
|
||||
g[e].maxBound = 0;
|
||||
g[e].history = ROSE_ROLE_HISTORY_LAST_BYTE;
|
||||
@@ -574,7 +574,7 @@ unique_ptr<NGHolder> buildMaskRhs(const ue2::flat_set<ReportID> &reports,
|
||||
succ = u;
|
||||
}
|
||||
|
||||
NFAEdge e = add_edge(h.start, succ, h).first;
|
||||
NFAEdge e = add_edge(h.start, succ, h);
|
||||
h[e].tops.insert(DEFAULT_TOP);
|
||||
|
||||
return rhs;
|
||||
|
@@ -1312,7 +1312,7 @@ void addSmallBlockLiteral(RoseBuildImpl &tbi, const simple_anchored_info &sai,
|
||||
g[v].max_offset = sai.max_bound + sai.literal.length();
|
||||
lit_info.vertices.insert(v);
|
||||
|
||||
RoseEdge e = add_edge(anchored_root, v, g).first;
|
||||
RoseEdge e = add_edge(anchored_root, v, g);
|
||||
g[e].minBound = sai.min_bound;
|
||||
g[e].maxBound = sai.max_bound;
|
||||
}
|
||||
@@ -1336,7 +1336,7 @@ void addSmallBlockLiteral(RoseBuildImpl &tbi, const ue2_literal &lit,
|
||||
g[v].literals.insert(lit_id);
|
||||
g[v].reports = reports;
|
||||
|
||||
RoseEdge e = add_edge(tbi.root, v, g).first;
|
||||
RoseEdge e = add_edge(tbi.root, v, g);
|
||||
g[e].minBound = 0;
|
||||
g[e].maxBound = ROSE_BOUND_INF;
|
||||
g[v].min_offset = 1;
|
||||
|
@@ -394,7 +394,7 @@ unique_ptr<NGHolder> makeFloodProneSuffix(const ue2_literal &s, size_t len,
|
||||
NFAVertex u = h->start;
|
||||
for (auto it = s.begin() + s.length() - len; it != s.end(); ++it) {
|
||||
NFAVertex v = addHolderVertex(*it, *h);
|
||||
NFAEdge e = add_edge(u, v, *h).first;
|
||||
NFAEdge e = add_edge(u, v, *h);
|
||||
if (u == h->start) {
|
||||
(*h)[e].tops.insert(DEFAULT_TOP);
|
||||
}
|
||||
@@ -705,10 +705,7 @@ bool handleStartPrefixCliche(const NGHolder &h, RoseGraph &g, RoseVertex v,
|
||||
assert(g[e_old].maxBound >= bound_max);
|
||||
setEdgeBounds(g, e_old, bound_min, bound_max);
|
||||
} else {
|
||||
RoseEdge e_new;
|
||||
UNUSED bool added;
|
||||
tie(e_new, added) = add_edge(ar, v, g);
|
||||
assert(added);
|
||||
RoseEdge e_new = add_edge(ar, v, g);
|
||||
setEdgeBounds(g, e_new, bound_min, bound_max);
|
||||
to_delete->push_back(e_old);
|
||||
}
|
||||
@@ -900,10 +897,7 @@ bool handleMixedPrefixCliche(const NGHolder &h, RoseGraph &g, RoseVertex v,
|
||||
if (source(e_old, g) == ar) {
|
||||
setEdgeBounds(g, e_old, ri.repeatMin + width, ri.repeatMax + width);
|
||||
} else {
|
||||
RoseEdge e_new;
|
||||
UNUSED bool added;
|
||||
tie(e_new, added) = add_edge(ar, v, g);
|
||||
assert(added);
|
||||
RoseEdge e_new = add_edge(ar, v, g);
|
||||
setEdgeBounds(g, e_new, ri.repeatMin + width, ri.repeatMax + width);
|
||||
to_delete->push_back(e_old);
|
||||
}
|
||||
|
@@ -454,11 +454,9 @@ bool isNoRunsVertex(const RoseBuildImpl &build, RoseVertex u) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RoseEdge e;
|
||||
bool exists;
|
||||
tie(e, exists) = edge(build.root, u, g);
|
||||
RoseEdge e = edge(build.root, u, g);
|
||||
|
||||
if (!exists) {
|
||||
if (!e) {
|
||||
DEBUG_PRINTF("u=%zu is not a root role\n", g[u].index);
|
||||
return false;
|
||||
}
|
||||
|
@@ -235,18 +235,15 @@ void mergeDupeLeaves(RoseBuildImpl &tbi) {
|
||||
for (const auto &e : in_edges_range(v, g)) {
|
||||
RoseVertex u = source(e, g);
|
||||
DEBUG_PRINTF("u index=%zu\n", g[u].index);
|
||||
RoseEdge et;
|
||||
bool exists;
|
||||
tie (et, exists) = edge(u, t, g);
|
||||
if (exists) {
|
||||
if (RoseEdge et = edge(u, t, g)) {
|
||||
if (g[et].minBound <= g[e].minBound
|
||||
&& g[et].maxBound >= g[e].maxBound) {
|
||||
DEBUG_PRINTF("remove more constrained edge\n");
|
||||
deadEdges.push_back(e);
|
||||
}
|
||||
} else {
|
||||
DEBUG_PRINTF("rehome edge: add %zu->%zu\n",
|
||||
g[u].index, g[t].index);
|
||||
DEBUG_PRINTF("rehome edge: add %zu->%zu\n", g[u].index,
|
||||
g[t].index);
|
||||
add_edge(u, t, g[e], g);
|
||||
deadEdges.push_back(e);
|
||||
}
|
||||
|
@@ -254,10 +254,8 @@ bool samePredecessors(RoseVertex a, RoseVertex b, const RoseGraph &g) {
|
||||
}
|
||||
|
||||
for (const auto &e_a : in_edges_range(a, g)) {
|
||||
bool exists;
|
||||
RoseEdge e;
|
||||
tie(e, exists) = edge(source(e_a, g), b, g);
|
||||
if (!exists || g[e].rose_top != g[e_a].rose_top) {
|
||||
RoseEdge e = edge(source(e_a, g), b, g);
|
||||
if (!e || g[e].rose_top != g[e_a].rose_top) {
|
||||
DEBUG_PRINTF("bad tops\n");
|
||||
return false;
|
||||
}
|
||||
@@ -271,10 +269,7 @@ static
|
||||
bool hasCommonSuccWithBadBounds(RoseVertex a, RoseVertex b,
|
||||
const RoseGraph &g) {
|
||||
for (const auto &e_a : out_edges_range(a, g)) {
|
||||
bool exists;
|
||||
RoseEdge e;
|
||||
tie(e, exists) = edge(b, target(e_a, g), g);
|
||||
if (exists) {
|
||||
if (RoseEdge e = edge(b, target(e_a, g), g)) {
|
||||
if (g[e_a].maxBound < g[e].minBound
|
||||
|| g[e].maxBound < g[e_a].minBound) {
|
||||
return true;
|
||||
@@ -293,10 +288,7 @@ static
|
||||
bool hasCommonPredWithBadBounds(RoseVertex a, RoseVertex b,
|
||||
const RoseGraph &g) {
|
||||
for (const auto &e_a : in_edges_range(a, g)) {
|
||||
bool exists;
|
||||
RoseEdge e;
|
||||
tie(e, exists) = edge(source(e_a, g), b, g);
|
||||
if (exists) {
|
||||
if (RoseEdge e = edge(source(e_a, g), b, g)) {
|
||||
if (g[e_a].maxBound < g[e].minBound
|
||||
|| g[e].maxBound < g[e_a].minBound) {
|
||||
return true;
|
||||
@@ -744,10 +736,7 @@ bool hasCommonPredWithDiffRoses(RoseVertex a, RoseVertex b,
|
||||
const bool equal_roses = hasEqualLeftfixes(a, b, g);
|
||||
|
||||
for (const auto &e_a : in_edges_range(a, g)) {
|
||||
bool exists;
|
||||
RoseEdge e;
|
||||
tie(e, exists) = edge(source(e_a, g), b, g);
|
||||
if (exists) {
|
||||
if (RoseEdge e = edge(source(e_a, g), b, g)) {
|
||||
DEBUG_PRINTF("common pred, e_r=%d r_t %u,%u\n",
|
||||
(int)equal_roses, g[e].rose_top, g[e_a].rose_top);
|
||||
if (!equal_roses) {
|
||||
@@ -1122,8 +1111,7 @@ bool attemptRoseCastleMerge(RoseBuildImpl &build, bool preds_same, RoseVertex a,
|
||||
// We should be protected from merging common preds with tops leading
|
||||
// to completely different repeats by earlier checks, but just in
|
||||
// case...
|
||||
if (edge(source(e, g), a, g).second) {
|
||||
RoseEdge a_edge = edge(source(e, g), a, g).first;
|
||||
if (RoseEdge a_edge = edge(source(e, g), a, g)) {
|
||||
u32 a_top = g[a_edge].rose_top;
|
||||
const PureRepeat &a_pr = m_castle->repeats[a_top]; // new report
|
||||
if (pr != a_pr) {
|
||||
|
Reference in New Issue
Block a user