mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
changes to ScriptFunc's to track captures, and LambdaExpr's to check/manage them
This commit is contained in:
parent
955384291d
commit
627fb8616e
4 changed files with 177 additions and 3 deletions
53
src/Func.cc
53
src/Func.cc
|
@ -319,6 +319,9 @@ ScriptFunc::~ScriptFunc()
|
|||
{
|
||||
if ( ! weak_closure_ref )
|
||||
Unref(closure);
|
||||
|
||||
delete captures_frame;
|
||||
delete captures_offset_mapping;
|
||||
}
|
||||
|
||||
bool ScriptFunc::IsPure() const
|
||||
|
@ -472,6 +475,56 @@ ValPtr ScriptFunc::Invoke(zeek::Args* args, Frame* parent) const
|
|||
return result;
|
||||
}
|
||||
|
||||
void ScriptFunc::CreateCaptures(Frame* f)
|
||||
{
|
||||
auto captures = type->GetCaptures();
|
||||
|
||||
if ( ! captures )
|
||||
return;
|
||||
|
||||
// Create a private Frame to hold the values of captured variables,
|
||||
// and a mapping from those variables to their offsets in the Frame.
|
||||
captures_frame = new Frame(captures->size(), this, nullptr);
|
||||
captures_offset_mapping = new OffsetMap;
|
||||
|
||||
int offset = 0;
|
||||
for ( auto c : *captures )
|
||||
{
|
||||
auto cid = c->id;
|
||||
auto v = f->GetElementByID(cid);
|
||||
|
||||
if ( v )
|
||||
{
|
||||
if ( c->deep_copy || ! v->Modifiable() )
|
||||
v = v->Clone();
|
||||
else
|
||||
v->Ref();
|
||||
|
||||
captures_frame->SetElement(offset, v);
|
||||
}
|
||||
|
||||
(*captures_offset_mapping)[cid->Name()] = offset;
|
||||
++offset;
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptFunc::SetCaptures(Frame* f)
|
||||
{
|
||||
auto captures = type->GetCaptures();
|
||||
ASSERT(captures);
|
||||
|
||||
captures_frame = f;
|
||||
captures_offset_mapping = new OffsetMap;
|
||||
|
||||
int offset = 0;
|
||||
for ( auto c : *captures )
|
||||
{
|
||||
auto cid = c->id;
|
||||
(*captures_offset_mapping)[cid->Name()] = offset;
|
||||
++offset;
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptFunc::AddBody(StmtPtr new_body,
|
||||
const std::vector<IDPtr>& new_inits,
|
||||
size_t new_frame_size, int priority)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue