mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-11-19 10:34:25 +03:00
ng: split NGWrapper into NGHolder, ExpressionInfo
We now use NGHolder for all graph information, while other expression properties (report, flag information, etc) go in new class ExpressionInfo.
This commit is contained in:
committed by
Matthew Barr
parent
fadfab6d8c
commit
5dfae12a62
@@ -27,8 +27,8 @@
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Code for discovering properties of an NGWrapper used by
|
||||
* hs_expression_info.
|
||||
* \brief Code for discovering properties of an NFA graph used by
|
||||
* hs_expression_info().
|
||||
*/
|
||||
#include "ng_expr_info.h"
|
||||
|
||||
@@ -58,42 +58,42 @@ namespace ue2 {
|
||||
|
||||
/* get rid of leading \b and multiline ^ vertices */
|
||||
static
|
||||
void removeLeadingVirtualVerticesFromRoot(NGWrapper &w, NFAVertex root) {
|
||||
void removeLeadingVirtualVerticesFromRoot(NGHolder &g, NFAVertex root) {
|
||||
vector<NFAVertex> victims;
|
||||
|
||||
for (auto v : adjacent_vertices_range(root, w)) {
|
||||
if (w[v].assert_flags & POS_FLAG_VIRTUAL_START) {
|
||||
for (auto v : adjacent_vertices_range(root, g)) {
|
||||
if (g[v].assert_flags & POS_FLAG_VIRTUAL_START) {
|
||||
DEBUG_PRINTF("(?m)^ vertex or leading \\[bB] vertex\n");
|
||||
victims.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto u : victims) {
|
||||
for (auto v : adjacent_vertices_range(u, w)) {
|
||||
add_edge_if_not_present(root, v, w);
|
||||
for (auto v : adjacent_vertices_range(u, g)) {
|
||||
add_edge_if_not_present(root, v, g);
|
||||
}
|
||||
}
|
||||
|
||||
remove_vertices(victims, w);
|
||||
remove_vertices(victims, g);
|
||||
}
|
||||
|
||||
static
|
||||
void checkVertex(const ReportManager &rm, const NGWrapper &w, NFAVertex v,
|
||||
void checkVertex(const ReportManager &rm, const NGHolder &g, NFAVertex v,
|
||||
const vector<DepthMinMax> &depths, DepthMinMax &info) {
|
||||
if (is_any_accept(v, w)) {
|
||||
if (is_any_accept(v, g)) {
|
||||
return;
|
||||
}
|
||||
if (is_any_start(v, w)) {
|
||||
if (is_any_start(v, g)) {
|
||||
info.min = 0;
|
||||
info.max = max(info.max, depth(0));
|
||||
return;
|
||||
}
|
||||
|
||||
u32 idx = w[v].index;
|
||||
u32 idx = g[v].index;
|
||||
assert(idx < depths.size());
|
||||
const DepthMinMax &d = depths.at(idx);
|
||||
|
||||
for (ReportID report_id : w[v].reports) {
|
||||
for (ReportID report_id : g[v].reports) {
|
||||
const Report &report = rm.getReport(report_id);
|
||||
assert(report.type == EXTERNAL_CALLBACK);
|
||||
|
||||
@@ -118,7 +118,7 @@ void checkVertex(const ReportManager &rm, const NGWrapper &w, NFAVertex v,
|
||||
rd.max = min(rd.max, max_offset);
|
||||
}
|
||||
|
||||
DEBUG_PRINTF("vertex %zu report %u: %s\n", w[v].index, report_id,
|
||||
DEBUG_PRINTF("vertex %zu report %u: %s\n", g[v].index, report_id,
|
||||
rd.str().c_str());
|
||||
|
||||
info = unionDepthMinMax(info, rd);
|
||||
@@ -126,8 +126,8 @@ void checkVertex(const ReportManager &rm, const NGWrapper &w, NFAVertex v,
|
||||
}
|
||||
|
||||
static
|
||||
bool hasOffsetAdjust(const ReportManager &rm, const NGWrapper &w) {
|
||||
for (const auto &report_id : all_reports(w)) {
|
||||
bool hasOffsetAdjust(const ReportManager &rm, const NGHolder &g) {
|
||||
for (const auto &report_id : all_reports(g)) {
|
||||
if (rm.getReport(report_id).offsetAdjust) {
|
||||
return true;
|
||||
}
|
||||
@@ -135,28 +135,29 @@ bool hasOffsetAdjust(const ReportManager &rm, const NGWrapper &w) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void fillExpressionInfo(ReportManager &rm, NGWrapper &w, hs_expr_info *info) {
|
||||
void fillExpressionInfo(ReportManager &rm, NGHolder &g,
|
||||
const ExpressionInfo &expr, hs_expr_info *info) {
|
||||
assert(info);
|
||||
|
||||
/* ensure utf8 starts at cp boundary */
|
||||
ensureCodePointStart(rm, w);
|
||||
resolveAsserts(rm, w);
|
||||
optimiseVirtualStarts(w);
|
||||
ensureCodePointStart(rm, g, expr);
|
||||
resolveAsserts(rm, g, expr);
|
||||
optimiseVirtualStarts(g);
|
||||
|
||||
removeLeadingVirtualVerticesFromRoot(w, w.start);
|
||||
removeLeadingVirtualVerticesFromRoot(w, w.startDs);
|
||||
removeLeadingVirtualVerticesFromRoot(g, g.start);
|
||||
removeLeadingVirtualVerticesFromRoot(g, g.startDs);
|
||||
|
||||
vector<DepthMinMax> depths;
|
||||
calcDepthsFrom(w, w.start, depths);
|
||||
calcDepthsFrom(g, g.start, depths);
|
||||
|
||||
DepthMinMax d;
|
||||
|
||||
for (auto u : inv_adjacent_vertices_range(w.accept, w)) {
|
||||
checkVertex(rm, w, u, depths, d);
|
||||
for (auto u : inv_adjacent_vertices_range(g.accept, g)) {
|
||||
checkVertex(rm, g, u, depths, d);
|
||||
}
|
||||
|
||||
for (auto u : inv_adjacent_vertices_range(w.acceptEod, w)) {
|
||||
checkVertex(rm, w, u, depths, d);
|
||||
for (auto u : inv_adjacent_vertices_range(g.acceptEod, g)) {
|
||||
checkVertex(rm, g, u, depths, d);
|
||||
}
|
||||
|
||||
if (d.max.is_finite()) {
|
||||
@@ -170,9 +171,9 @@ void fillExpressionInfo(ReportManager &rm, NGWrapper &w, hs_expr_info *info) {
|
||||
info->min_width = UINT_MAX;
|
||||
}
|
||||
|
||||
info->unordered_matches = hasOffsetAdjust(rm, w);
|
||||
info->matches_at_eod = can_match_at_eod(w);
|
||||
info->matches_only_at_eod = can_only_match_at_eod(w);
|
||||
info->unordered_matches = hasOffsetAdjust(rm, g);
|
||||
info->matches_at_eod = can_match_at_eod(g);
|
||||
info->matches_only_at_eod = can_only_match_at_eod(g);
|
||||
}
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
Reference in New Issue
Block a user