mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
track the current body with more rigor
This commit is contained in:
parent
9281ffaa98
commit
16c46a3462
2 changed files with 11 additions and 22 deletions
21
src/Func.cc
21
src/Func.cc
|
@ -295,10 +295,8 @@ ScriptFunc::ScriptFunc(std::string _name, FuncTypePtr ft, std::vector<StmtPtr> b
|
||||||
|
|
||||||
std::ranges::stable_sort(bodies, std::ranges::greater(), &Body::priority);
|
std::ranges::stable_sort(bodies, std::ranges::greater(), &Body::priority);
|
||||||
|
|
||||||
if ( ! bodies.empty() ) {
|
if ( ! bodies.empty() )
|
||||||
current_body = bodies[0].stmts;
|
current_body = bodies[0];
|
||||||
current_priority = bodies[0].priority;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFunc::~ScriptFunc() {
|
ScriptFunc::~ScriptFunc() {
|
||||||
|
@ -562,13 +560,9 @@ void ScriptFunc::AddBody(StmtPtr new_body, const std::vector<IDPtr>& new_inits,
|
||||||
bodies.clear();
|
bodies.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Body b;
|
current_body = Body{.stmts = new_body, .groups = {groups.begin(), groups.end()}, .priority = priority};
|
||||||
b.stmts = new_body;
|
|
||||||
b.groups = {groups.begin(), groups.end()};
|
|
||||||
current_body = new_body;
|
|
||||||
current_priority = b.priority = priority;
|
|
||||||
|
|
||||||
bodies.push_back(std::move(b));
|
bodies.push_back(current_body);
|
||||||
std::ranges::stable_sort(bodies, std::ranges::greater(), &Body::priority);
|
std::ranges::stable_sort(bodies, std::ranges::greater(), &Body::priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,18 +571,15 @@ void ScriptFunc::ReplaceBody(const StmtPtr& old_body, StmtPtr new_body) {
|
||||||
|
|
||||||
for ( auto body = bodies.begin(); body != bodies.end(); ++body )
|
for ( auto body = bodies.begin(); body != bodies.end(); ++body )
|
||||||
if ( body->stmts.get() == old_body.get() ) {
|
if ( body->stmts.get() == old_body.get() ) {
|
||||||
if ( new_body ) {
|
if ( new_body )
|
||||||
body->stmts = new_body;
|
body->stmts = new_body;
|
||||||
current_priority = body->priority;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
bodies.erase(body);
|
bodies.erase(body);
|
||||||
|
|
||||||
found_it = true;
|
found_it = true;
|
||||||
|
current_body = *body;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_body = new_body;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptFunc::DeserializeCaptures(BrokerListView data) {
|
bool ScriptFunc::DeserializeCaptures(BrokerListView data) {
|
||||||
|
|
12
src/Func.h
12
src/Func.h
|
@ -265,8 +265,9 @@ public:
|
||||||
*/
|
*/
|
||||||
void ReplaceBody(const detail::StmtPtr& old_body, detail::StmtPtr new_body);
|
void ReplaceBody(const detail::StmtPtr& old_body, detail::StmtPtr new_body);
|
||||||
|
|
||||||
StmtPtr CurrentBody() const { return current_body; }
|
StmtPtr CurrentBody() const { return current_body.stmts; }
|
||||||
int CurrentPriority() const { return current_priority; }
|
int CurrentPriority() const { return current_body.priority; }
|
||||||
|
auto CurrentEventGroups() const { return current_body.groups; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the function's frame size.
|
* Returns the function's frame size.
|
||||||
|
@ -322,11 +323,8 @@ private:
|
||||||
|
|
||||||
OffsetMap* captures_offset_mapping = nullptr;
|
OffsetMap* captures_offset_mapping = nullptr;
|
||||||
|
|
||||||
// The most recently added/updated body ...
|
// A copy of the most recently added/updated Body.
|
||||||
StmtPtr current_body;
|
Body current_body;
|
||||||
|
|
||||||
// ... and its priority.
|
|
||||||
int current_priority = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using built_in_func = ValPtr (*)(Frame* frame, const Args* args);
|
using built_in_func = ValPtr (*)(Frame* frame, const Args* args);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue