use Ingredients directly for constructing functions

This commit is contained in:
Vern Paxson 2023-06-16 15:39:19 -07:00 committed by Arne Welzel
parent b6464814c9
commit 82588ca311
3 changed files with 17 additions and 10 deletions

View file

@ -123,6 +123,14 @@ std::string render_call_stack()
return rval;
}
void Func::AddBody(const detail::FunctionIngredients& ingr, detail::StmtPtr new_body)
{
if ( ! new_body )
new_body = ingr.Body();
AddBody(new_body, ingr.Inits(), ingr.FrameSize(), ingr.Priority(), ingr.Groups());
}
void Func::AddBody(detail::StmtPtr new_body, const std::vector<detail::IDPtr>& new_inits,
size_t new_frame_size, int priority)
{

View file

@ -44,6 +44,7 @@ using IDPtr = IntrusivePtr<ID>;
using StmtPtr = IntrusivePtr<Stmt>;
class ScriptFunc;
class FunctionIngredients;
} // namespace detail
@ -114,14 +115,15 @@ public:
return Invoke(&zargs);
}
// Add a new event handler to an existing function (event).
// Various ways to add a new event handler to an existing function
// (event).
void AddBody(const detail::FunctionIngredients& ingr, detail::StmtPtr new_body = nullptr);
virtual void AddBody(detail::StmtPtr new_body, const std::vector<detail::IDPtr>& new_inits,
size_t new_frame_size, int priority,
const std::set<EventGroupPtr>& groups);
// Add a new event handler to an existing function (event).
virtual void AddBody(detail::StmtPtr new_body, const std::vector<detail::IDPtr>& new_inits,
void AddBody(detail::StmtPtr new_body, const std::vector<detail::IDPtr>& new_inits,
size_t new_frame_size, int priority = 0);
void AddBody(detail::StmtPtr new_body, size_t new_frame_size);
virtual void SetScope(detail::ScopePtr newscope);
virtual detail::ScopePtr GetScope() const { return scope; }
@ -333,8 +335,7 @@ struct CallInfo
const zeek::Args& args;
};
// Struct that collects all the specifics defining a Func. Used for ScriptFuncs
// with closures.
// Class that collects all the specifics defining a Func.
class FunctionIngredients
{
public:

View file

@ -845,9 +845,7 @@ void end_func(StmtPtr body, const char* module_name, bool free_of_conditionals)
id->SetConst();
}
id->GetVal()->AsFunc()->AddBody(ingredients->Body(), ingredients->Inits(),
ingredients->FrameSize(), ingredients->Priority(),
ingredients->Groups());
id->GetVal()->AsFunc()->AddBody(*ingredients);
script_coverage_mgr.AddFunction(id, ingredients->Body());