mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
castle: add nfa kind to CastleProto
This commit is contained in:
parent
1f41a921f2
commit
ec985a62f8
@ -680,7 +680,7 @@ depth findMaxWidth(const CastleProto &proto, u32 top) {
|
|||||||
return proto.repeats.at(top).bounds.max;
|
return proto.repeats.at(top).bounds.max;
|
||||||
}
|
}
|
||||||
|
|
||||||
CastleProto::CastleProto(const PureRepeat &pr) {
|
CastleProto::CastleProto(nfa_kind k, const PureRepeat &pr) : kind(k) {
|
||||||
assert(pr.reach.any());
|
assert(pr.reach.any());
|
||||||
assert(pr.reports.size() == 1);
|
assert(pr.reports.size() == 1);
|
||||||
u32 top = 0;
|
u32 top = 0;
|
||||||
@ -742,6 +742,7 @@ u32 CastleProto::merge(const PureRepeat &pr) {
|
|||||||
bool mergeCastle(CastleProto &c1, const CastleProto &c2,
|
bool mergeCastle(CastleProto &c1, const CastleProto &c2,
|
||||||
map<u32, u32> &top_map) {
|
map<u32, u32> &top_map) {
|
||||||
assert(&c1 != &c2);
|
assert(&c1 != &c2);
|
||||||
|
assert(c1.kind == c2.kind);
|
||||||
|
|
||||||
DEBUG_PRINTF("c1 has %zu repeats, c2 has %zu repeats\n", c1.repeats.size(),
|
DEBUG_PRINTF("c1 has %zu repeats, c2 has %zu repeats\n", c1.repeats.size(),
|
||||||
c2.repeats.size());
|
c2.repeats.size());
|
||||||
@ -954,7 +955,7 @@ bool hasZeroMinBound(const CastleProto &proto) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<NGHolder> makeHolder(const CastleProto &proto, nfa_kind kind,
|
unique_ptr<NGHolder> makeHolder(const CastleProto &proto,
|
||||||
const CompileContext &cc) {
|
const CompileContext &cc) {
|
||||||
assert(!proto.repeats.empty());
|
assert(!proto.repeats.empty());
|
||||||
|
|
||||||
@ -967,7 +968,7 @@ unique_ptr<NGHolder> makeHolder(const CastleProto &proto, nfa_kind kind,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<NGHolder> g = ue2::make_unique<NGHolder>(kind);
|
auto g = ue2::make_unique<NGHolder>(proto.kind);
|
||||||
|
|
||||||
for (const auto &m : proto.repeats) {
|
for (const auto &m : proto.repeats) {
|
||||||
if (m.first >= NFA_MAX_TOP_MASKS) {
|
if (m.first >= NFA_MAX_TOP_MASKS) {
|
||||||
|
@ -66,7 +66,7 @@ struct CompileContext;
|
|||||||
*/
|
*/
|
||||||
struct CastleProto {
|
struct CastleProto {
|
||||||
static constexpr size_t max_occupancy = 65536; // arbitrary limit
|
static constexpr size_t max_occupancy = 65536; // arbitrary limit
|
||||||
explicit CastleProto(const PureRepeat &pr);
|
CastleProto(nfa_kind k, const PureRepeat &pr);
|
||||||
const CharReach &reach() const;
|
const CharReach &reach() const;
|
||||||
|
|
||||||
/** \brief Add a new repeat. */
|
/** \brief Add a new repeat. */
|
||||||
@ -95,6 +95,9 @@ struct CastleProto {
|
|||||||
* so we track this explicitly instead of using repeats.size().
|
* so we track this explicitly instead of using repeats.size().
|
||||||
*/
|
*/
|
||||||
u32 next_top = 1;
|
u32 next_top = 1;
|
||||||
|
|
||||||
|
/** \brief Kind for this engine. */
|
||||||
|
nfa_kind kind;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::set<ReportID> all_reports(const CastleProto &proto);
|
std::set<ReportID> all_reports(const CastleProto &proto);
|
||||||
@ -156,7 +159,7 @@ bool requiresDedupe(const CastleProto &proto,
|
|||||||
/**
|
/**
|
||||||
* \brief Build an NGHolder from a CastleProto.
|
* \brief Build an NGHolder from a CastleProto.
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<NGHolder> makeHolder(const CastleProto &castle, nfa_kind kind,
|
std::unique_ptr<NGHolder> makeHolder(const CastleProto &castle,
|
||||||
const CompileContext &cc);
|
const CompileContext &cc);
|
||||||
|
|
||||||
void remapReportsToPrograms(CastleProto &castle, const ReportManager &rm);
|
void remapReportsToPrograms(CastleProto &castle, const ReportManager &rm);
|
||||||
|
@ -77,7 +77,7 @@ void makeCastle(LeftEngInfo &left,
|
|||||||
if (isPureRepeat(h, pr) && pr.reports.size() == 1) {
|
if (isPureRepeat(h, pr) && pr.reports.size() == 1) {
|
||||||
DEBUG_PRINTF("vertex preceded by infix repeat %s\n",
|
DEBUG_PRINTF("vertex preceded by infix repeat %s\n",
|
||||||
pr.bounds.str().c_str());
|
pr.bounds.str().c_str());
|
||||||
left.castle = make_shared<CastleProto>(pr);
|
left.castle = make_shared<CastleProto>(h.kind, pr);
|
||||||
cache[&h] = left.castle;
|
cache[&h] = left.castle;
|
||||||
left.graph.reset();
|
left.graph.reset();
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ void makeCastleSuffix(RoseBuildImpl &tbi, RoseVertex v,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
suffix.castle = make_shared<CastleProto>(pr);
|
suffix.castle = make_shared<CastleProto>(h.kind, pr);
|
||||||
cache[&h] = suffix.castle;
|
cache[&h] = suffix.castle;
|
||||||
suffix.graph.reset();
|
suffix.graph.reset();
|
||||||
}
|
}
|
||||||
@ -264,8 +264,7 @@ bool unmakeCastles(RoseBuildImpl &tbi) {
|
|||||||
|
|
||||||
for (const auto &e : left_castles) {
|
for (const auto &e : left_castles) {
|
||||||
assert(e.first.castle());
|
assert(e.first.castle());
|
||||||
shared_ptr<NGHolder> h = makeHolder(*e.first.castle(), NFA_INFIX,
|
shared_ptr<NGHolder> h = makeHolder(*e.first.castle(), tbi.cc);
|
||||||
tbi.cc);
|
|
||||||
if (!h || num_vertices(*h) > MAX_UNMAKE_VERTICES) {
|
if (!h || num_vertices(*h) > MAX_UNMAKE_VERTICES) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -281,8 +280,7 @@ bool unmakeCastles(RoseBuildImpl &tbi) {
|
|||||||
|
|
||||||
for (const auto &e : suffix_castles) {
|
for (const auto &e : suffix_castles) {
|
||||||
assert(e.first.castle());
|
assert(e.first.castle());
|
||||||
shared_ptr<NGHolder> h = makeHolder(*e.first.castle(), NFA_SUFFIX,
|
shared_ptr<NGHolder> h = makeHolder(*e.first.castle(), tbi.cc);
|
||||||
tbi.cc);
|
|
||||||
if (!h || num_vertices(*h) > MAX_UNMAKE_VERTICES) {
|
if (!h || num_vertices(*h) > MAX_UNMAKE_VERTICES) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user