mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The one place where we deviate is header include order since Zeek depends on headers being included in a certain order.
This commit is contained in:
parent
7b8e7ed72c
commit
f5a76c1aed
786 changed files with 131714 additions and 153609 deletions
534
src/Func.h
534
src/Func.h
|
@ -18,21 +18,19 @@
|
|||
#include "zeek/ZeekArgs.h"
|
||||
#include "zeek/ZeekList.h"
|
||||
|
||||
namespace broker
|
||||
{
|
||||
namespace broker {
|
||||
class data;
|
||||
using vector = std::vector<data>;
|
||||
template <class> class expected;
|
||||
}
|
||||
template<class>
|
||||
class expected;
|
||||
} // namespace broker
|
||||
|
||||
namespace zeek
|
||||
{
|
||||
namespace zeek {
|
||||
|
||||
class Val;
|
||||
class FuncType;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
|
||||
class Scope;
|
||||
class Stmt;
|
||||
|
@ -46,7 +44,7 @@ using StmtPtr = IntrusivePtr<Stmt>;
|
|||
class ScriptFunc;
|
||||
class FunctionIngredients;
|
||||
|
||||
} // namespace detail
|
||||
} // namespace detail
|
||||
|
||||
class EventGroup;
|
||||
using EventGroupPtr = std::shared_ptr<EventGroup>;
|
||||
|
@ -54,350 +52,329 @@ using EventGroupPtr = std::shared_ptr<EventGroup>;
|
|||
class Func;
|
||||
using FuncPtr = IntrusivePtr<Func>;
|
||||
|
||||
class Func : public Obj
|
||||
{
|
||||
class Func : public Obj {
|
||||
public:
|
||||
static inline const FuncPtr nil;
|
||||
static inline const FuncPtr nil;
|
||||
|
||||
enum Kind
|
||||
{
|
||||
SCRIPT_FUNC,
|
||||
BUILTIN_FUNC
|
||||
};
|
||||
enum Kind { SCRIPT_FUNC, BUILTIN_FUNC };
|
||||
|
||||
explicit Func(Kind arg_kind) : kind(arg_kind) { }
|
||||
explicit Func(Kind arg_kind) : kind(arg_kind) {}
|
||||
|
||||
virtual bool IsPure() const = 0;
|
||||
FunctionFlavor Flavor() const { return GetType()->Flavor(); }
|
||||
virtual bool IsPure() const = 0;
|
||||
FunctionFlavor Flavor() const { return GetType()->Flavor(); }
|
||||
|
||||
struct Body
|
||||
{
|
||||
detail::StmtPtr stmts;
|
||||
int priority;
|
||||
std::set<EventGroupPtr> groups;
|
||||
// If any of the groups are disabled, this body is disabled.
|
||||
// The disabled field is updated from EventGroup instances.
|
||||
bool disabled = false;
|
||||
struct Body {
|
||||
detail::StmtPtr stmts;
|
||||
int priority;
|
||||
std::set<EventGroupPtr> groups;
|
||||
// If any of the groups are disabled, this body is disabled.
|
||||
// The disabled field is updated from EventGroup instances.
|
||||
bool disabled = false;
|
||||
|
||||
bool operator<(const Body& other) const
|
||||
{
|
||||
return priority > other.priority;
|
||||
} // reverse sort
|
||||
};
|
||||
bool operator<(const Body& other) const { return priority > other.priority; } // reverse sort
|
||||
};
|
||||
|
||||
const std::vector<Body>& GetBodies() const { return bodies; }
|
||||
bool HasBodies() const { return ! bodies.empty(); }
|
||||
const std::vector<Body>& GetBodies() const { return bodies; }
|
||||
bool HasBodies() const { return ! bodies.empty(); }
|
||||
|
||||
/**
|
||||
* Are there bodies and is any one of them enabled?
|
||||
*
|
||||
* @return true if bodies exist and at least one is enabled.
|
||||
*/
|
||||
bool HasEnabledBodies() const { return ! bodies.empty() && has_enabled_bodies; };
|
||||
/**
|
||||
* Are there bodies and is any one of them enabled?
|
||||
*
|
||||
* @return true if bodies exist and at least one is enabled.
|
||||
*/
|
||||
bool HasEnabledBodies() const { return ! bodies.empty() && has_enabled_bodies; };
|
||||
|
||||
/**
|
||||
* Calls a Zeek function.
|
||||
* @param args the list of arguments to the function call.
|
||||
* @param parent the frame from which the function is being called.
|
||||
* @return the return value of the function call.
|
||||
*/
|
||||
virtual ValPtr Invoke(zeek::Args* args, detail::Frame* parent = nullptr) const = 0;
|
||||
/**
|
||||
* Calls a Zeek function.
|
||||
* @param args the list of arguments to the function call.
|
||||
* @param parent the frame from which the function is being called.
|
||||
* @return the return value of the function call.
|
||||
*/
|
||||
virtual ValPtr Invoke(zeek::Args* args, detail::Frame* parent = nullptr) const = 0;
|
||||
|
||||
/**
|
||||
* A version of Invoke() taking a variable number of individual arguments.
|
||||
*/
|
||||
template <class... Args>
|
||||
std::enable_if_t<std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>,
|
||||
ValPtr>
|
||||
Invoke(Args&&... args) const
|
||||
{
|
||||
auto zargs = zeek::Args{std::forward<Args>(args)...};
|
||||
return Invoke(&zargs);
|
||||
}
|
||||
/**
|
||||
* A version of Invoke() taking a variable number of individual arguments.
|
||||
*/
|
||||
template<class... Args>
|
||||
std::enable_if_t<std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>, ValPtr> Invoke(
|
||||
Args&&... args) const {
|
||||
auto zargs = zeek::Args{std::forward<Args>(args)...};
|
||||
return Invoke(&zargs);
|
||||
}
|
||||
|
||||
// Various ways to add a new event handler to an existing function
|
||||
// (event). The usual version to use is the first with its default
|
||||
// parameter. All of the others are for use by script optimization,
|
||||
// as is a non-default second parameter to the first method, which
|
||||
// overrides the function body in "ingr".
|
||||
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);
|
||||
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);
|
||||
// Various ways to add a new event handler to an existing function
|
||||
// (event). The usual version to use is the first with its default
|
||||
// parameter. All of the others are for use by script optimization,
|
||||
// as is a non-default second parameter to the first method, which
|
||||
// overrides the function body in "ingr".
|
||||
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);
|
||||
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; }
|
||||
virtual void SetScope(detail::ScopePtr newscope);
|
||||
virtual detail::ScopePtr GetScope() const { return scope; }
|
||||
|
||||
const FuncTypePtr& GetType() const { return type; }
|
||||
const FuncTypePtr& GetType() const { return type; }
|
||||
|
||||
Kind GetKind() const { return kind; }
|
||||
Kind GetKind() const { return kind; }
|
||||
|
||||
const char* Name() const { return name.c_str(); }
|
||||
void SetName(const char* arg_name) { name = arg_name; }
|
||||
const char* Name() const { return name.c_str(); }
|
||||
void SetName(const char* arg_name) { name = arg_name; }
|
||||
|
||||
void Describe(ODesc* d) const override = 0;
|
||||
virtual void DescribeDebug(ODesc* d, const zeek::Args* args) const;
|
||||
void Describe(ODesc* d) const override = 0;
|
||||
virtual void DescribeDebug(ODesc* d, const zeek::Args* args) const;
|
||||
|
||||
virtual FuncPtr DoClone();
|
||||
virtual FuncPtr DoClone();
|
||||
|
||||
virtual detail::TraversalCode Traverse(detail::TraversalCallback* cb) const;
|
||||
virtual detail::TraversalCode Traverse(detail::TraversalCallback* cb) const;
|
||||
|
||||
protected:
|
||||
Func() = default;
|
||||
Func() = default;
|
||||
|
||||
// Copies this function's state into other.
|
||||
void CopyStateInto(Func* other) const;
|
||||
// Copies this function's state into other.
|
||||
void CopyStateInto(Func* other) const;
|
||||
|
||||
// Helper function for checking result of plugin hook.
|
||||
void CheckPluginResult(bool handled, const ValPtr& hook_result, FunctionFlavor flavor) const;
|
||||
// Helper function for checking result of plugin hook.
|
||||
void CheckPluginResult(bool handled, const ValPtr& hook_result, FunctionFlavor flavor) const;
|
||||
|
||||
std::vector<Body> bodies;
|
||||
detail::ScopePtr scope;
|
||||
Kind kind = SCRIPT_FUNC;
|
||||
FuncTypePtr type;
|
||||
std::string name;
|
||||
std::vector<Body> bodies;
|
||||
detail::ScopePtr scope;
|
||||
Kind kind = SCRIPT_FUNC;
|
||||
FuncTypePtr type;
|
||||
std::string name;
|
||||
|
||||
private:
|
||||
// EventGroup updates Func::Body.disabled and has_enabled_bodies.
|
||||
// This is friend/private with EventGroup here so that we do not
|
||||
// expose accessors in the zeek:: public interface.
|
||||
friend class EventGroup;
|
||||
bool has_enabled_bodies = true;
|
||||
};
|
||||
// EventGroup updates Func::Body.disabled and has_enabled_bodies.
|
||||
// This is friend/private with EventGroup here so that we do not
|
||||
// expose accessors in the zeek:: public interface.
|
||||
friend class EventGroup;
|
||||
bool has_enabled_bodies = true;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
|
||||
class ScriptFunc : public Func
|
||||
{
|
||||
class ScriptFunc : public Func {
|
||||
public:
|
||||
ScriptFunc(const IDPtr& id);
|
||||
ScriptFunc(const IDPtr& id);
|
||||
|
||||
// For compiled scripts.
|
||||
ScriptFunc(std::string name, FuncTypePtr ft, std::vector<StmtPtr> bodies,
|
||||
std::vector<int> priorities);
|
||||
// For compiled scripts.
|
||||
ScriptFunc(std::string name, FuncTypePtr ft, std::vector<StmtPtr> bodies, std::vector<int> priorities);
|
||||
|
||||
~ScriptFunc() override;
|
||||
~ScriptFunc() override;
|
||||
|
||||
bool IsPure() const override;
|
||||
ValPtr Invoke(zeek::Args* args, Frame* parent) const override;
|
||||
bool IsPure() const override;
|
||||
ValPtr Invoke(zeek::Args* args, Frame* parent) const override;
|
||||
|
||||
/**
|
||||
* Creates a separate frame for captures and initializes its
|
||||
* elements. The list of captures comes from the ScriptFunc's
|
||||
* type, so doesn't need to be passed in, just the frame to
|
||||
* use in evaluating the identifiers.
|
||||
*
|
||||
* @param f the frame used for evaluating the captured identifiers
|
||||
*/
|
||||
void CreateCaptures(Frame* f);
|
||||
/**
|
||||
* Creates a separate frame for captures and initializes its
|
||||
* elements. The list of captures comes from the ScriptFunc's
|
||||
* type, so doesn't need to be passed in, just the frame to
|
||||
* use in evaluating the identifiers.
|
||||
*
|
||||
* @param f the frame used for evaluating the captured identifiers
|
||||
*/
|
||||
void CreateCaptures(Frame* f);
|
||||
|
||||
/**
|
||||
* Uses the given set of ZVal's for captures. Note that this is
|
||||
* different from the method above, which uses its argument to
|
||||
* compute the captures, rather than here where they are pre-computed.
|
||||
*
|
||||
* Makes deep copies if required.
|
||||
*
|
||||
* @param cvec a vector of ZVal's corresponding to the captures.
|
||||
*/
|
||||
void CreateCaptures(std::unique_ptr<std::vector<ZVal>> cvec);
|
||||
/**
|
||||
* Uses the given set of ZVal's for captures. Note that this is
|
||||
* different from the method above, which uses its argument to
|
||||
* compute the captures, rather than here where they are pre-computed.
|
||||
*
|
||||
* Makes deep copies if required.
|
||||
*
|
||||
* @param cvec a vector of ZVal's corresponding to the captures.
|
||||
*/
|
||||
void CreateCaptures(std::unique_ptr<std::vector<ZVal>> cvec);
|
||||
|
||||
/**
|
||||
* Returns the frame associated with this function for tracking
|
||||
* captures, or nil if there isn't one.
|
||||
*
|
||||
* @return internal frame kept by the function for persisting captures
|
||||
*/
|
||||
Frame* GetCapturesFrame() const { return captures_frame; }
|
||||
/**
|
||||
* Returns the frame associated with this function for tracking
|
||||
* captures, or nil if there isn't one.
|
||||
*
|
||||
* @return internal frame kept by the function for persisting captures
|
||||
*/
|
||||
Frame* GetCapturesFrame() const { return captures_frame; }
|
||||
|
||||
/**
|
||||
* Returns the set of ZVal's used for captures. It's okay to modify
|
||||
* these as long as memory-management is done for managed entries.
|
||||
*
|
||||
* @return internal vector of ZVal's kept for persisting captures
|
||||
*/
|
||||
auto& GetCapturesVec() const
|
||||
{
|
||||
ASSERT(captures_vec);
|
||||
return *captures_vec;
|
||||
}
|
||||
/**
|
||||
* Returns the set of ZVal's used for captures. It's okay to modify
|
||||
* these as long as memory-management is done for managed entries.
|
||||
*
|
||||
* @return internal vector of ZVal's kept for persisting captures
|
||||
*/
|
||||
auto& GetCapturesVec() const {
|
||||
ASSERT(captures_vec);
|
||||
return *captures_vec;
|
||||
}
|
||||
|
||||
// Same definition as in Frame.h.
|
||||
using OffsetMap = std::unordered_map<std::string, int>;
|
||||
// Same definition as in Frame.h.
|
||||
using OffsetMap = std::unordered_map<std::string, int>;
|
||||
|
||||
/**
|
||||
* Returns the mapping of captures to slots in the captures frame.
|
||||
*
|
||||
* @return pointer to mapping of captures to slots
|
||||
*/
|
||||
const OffsetMap* GetCapturesOffsetMap() const { return captures_offset_mapping; }
|
||||
/**
|
||||
* Returns the mapping of captures to slots in the captures frame.
|
||||
*
|
||||
* @return pointer to mapping of captures to slots
|
||||
*/
|
||||
const OffsetMap* GetCapturesOffsetMap() const { return captures_offset_mapping; }
|
||||
|
||||
/**
|
||||
* Serializes this function's capture frame.
|
||||
*
|
||||
* @return a serialized version of the function's capture frame.
|
||||
*/
|
||||
virtual broker::expected<broker::data> SerializeCaptures() const;
|
||||
/**
|
||||
* Serializes this function's capture frame.
|
||||
*
|
||||
* @return a serialized version of the function's capture frame.
|
||||
*/
|
||||
virtual broker::expected<broker::data> SerializeCaptures() const;
|
||||
|
||||
/**
|
||||
* Sets the captures frame to one built from *data*.
|
||||
*
|
||||
* @param data a serialized frame
|
||||
*/
|
||||
bool DeserializeCaptures(const broker::vector& data);
|
||||
/**
|
||||
* Sets the captures frame to one built from *data*.
|
||||
*
|
||||
* @param data a serialized frame
|
||||
*/
|
||||
bool DeserializeCaptures(const broker::vector& data);
|
||||
|
||||
using Func::AddBody;
|
||||
using Func::AddBody;
|
||||
|
||||
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) override;
|
||||
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) override;
|
||||
|
||||
/**
|
||||
* Replaces the given current instance of a function body with
|
||||
* a new one. If new_body is nil then the current instance is
|
||||
* deleted with no replacement.
|
||||
*
|
||||
* @param old_body Body to replace.
|
||||
* @param new_body New body to use; can be nil.
|
||||
*/
|
||||
void ReplaceBody(const detail::StmtPtr& old_body, detail::StmtPtr new_body);
|
||||
/**
|
||||
* Replaces the given current instance of a function body with
|
||||
* a new one. If new_body is nil then the current instance is
|
||||
* deleted with no replacement.
|
||||
*
|
||||
* @param old_body Body to replace.
|
||||
* @param new_body New body to use; can be nil.
|
||||
*/
|
||||
void ReplaceBody(const detail::StmtPtr& old_body, detail::StmtPtr new_body);
|
||||
|
||||
StmtPtr CurrentBody() const { return current_body; }
|
||||
int CurrentPriority() const { return current_priority; }
|
||||
StmtPtr CurrentBody() const { return current_body; }
|
||||
int CurrentPriority() const { return current_priority; }
|
||||
|
||||
/**
|
||||
* Returns the function's frame size.
|
||||
* @return The number of ValPtr slots in the function's frame.
|
||||
*/
|
||||
int FrameSize() const { return frame_size; }
|
||||
/**
|
||||
* Returns the function's frame size.
|
||||
* @return The number of ValPtr slots in the function's frame.
|
||||
*/
|
||||
int FrameSize() const { return frame_size; }
|
||||
|
||||
/**
|
||||
* Changes the function's frame size to a new size - used for
|
||||
* script optimization/compilation.
|
||||
*
|
||||
* @param new_size The frame size the function should use.
|
||||
*/
|
||||
void SetFrameSize(int new_size) { frame_size = new_size; }
|
||||
/**
|
||||
* Changes the function's frame size to a new size - used for
|
||||
* script optimization/compilation.
|
||||
*
|
||||
* @param new_size The frame size the function should use.
|
||||
*/
|
||||
void SetFrameSize(int new_size) { frame_size = new_size; }
|
||||
|
||||
/** Sets this function's outer_id list. */
|
||||
void SetOuterIDs(IDPList ids) { outer_ids = std::move(ids); }
|
||||
/** Sets this function's outer_id list. */
|
||||
void SetOuterIDs(IDPList ids) { outer_ids = std::move(ids); }
|
||||
|
||||
void Describe(ODesc* d) const override;
|
||||
void Describe(ODesc* d) const override;
|
||||
|
||||
protected:
|
||||
ScriptFunc() : Func(SCRIPT_FUNC) { }
|
||||
ScriptFunc() : Func(SCRIPT_FUNC) {}
|
||||
|
||||
StmtPtr AddInits(StmtPtr body, const std::vector<IDPtr>& inits);
|
||||
StmtPtr AddInits(StmtPtr body, const std::vector<IDPtr>& inits);
|
||||
|
||||
/**
|
||||
* Clones this function along with its captures.
|
||||
*/
|
||||
FuncPtr DoClone() override;
|
||||
/**
|
||||
* Clones this function along with its captures.
|
||||
*/
|
||||
FuncPtr DoClone() override;
|
||||
|
||||
/**
|
||||
* Uses the given frame for captures, and generates the
|
||||
* mapping from captured variables to offsets in the frame.
|
||||
* Virtual so it can be modified for script optimization uses.
|
||||
*
|
||||
* @param f the frame holding the values of capture variables
|
||||
*/
|
||||
virtual void SetCaptures(Frame* f);
|
||||
/**
|
||||
* Uses the given frame for captures, and generates the
|
||||
* mapping from captured variables to offsets in the frame.
|
||||
* Virtual so it can be modified for script optimization uses.
|
||||
*
|
||||
* @param f the frame holding the values of capture variables
|
||||
*/
|
||||
virtual void SetCaptures(Frame* f);
|
||||
|
||||
private:
|
||||
size_t frame_size = 0;
|
||||
size_t frame_size = 0;
|
||||
|
||||
// List of the outer IDs used in the function.
|
||||
IDPList outer_ids;
|
||||
// List of the outer IDs used in the function.
|
||||
IDPList outer_ids;
|
||||
|
||||
// Frame for (capture-by-copy) closures. These persist over the
|
||||
// function's lifetime, providing quasi-globals that maintain
|
||||
// state across individual calls to the function.
|
||||
Frame* captures_frame = nullptr;
|
||||
// Frame for (capture-by-copy) closures. These persist over the
|
||||
// function's lifetime, providing quasi-globals that maintain
|
||||
// state across individual calls to the function.
|
||||
Frame* captures_frame = nullptr;
|
||||
|
||||
OffsetMap* captures_offset_mapping = nullptr;
|
||||
OffsetMap* captures_offset_mapping = nullptr;
|
||||
|
||||
// Captures when using ZVal block instead of a Frame.
|
||||
std::unique_ptr<std::vector<ZVal>> captures_vec;
|
||||
// Captures when using ZVal block instead of a Frame.
|
||||
std::unique_ptr<std::vector<ZVal>> captures_vec;
|
||||
|
||||
// The most recently added/updated body ...
|
||||
StmtPtr current_body;
|
||||
// The most recently added/updated body ...
|
||||
StmtPtr current_body;
|
||||
|
||||
// ... and its priority.
|
||||
int current_priority = 0;
|
||||
};
|
||||
// ... and its priority.
|
||||
int current_priority = 0;
|
||||
};
|
||||
|
||||
using built_in_func = BifReturnVal (*)(Frame* frame, const Args* args);
|
||||
|
||||
class BuiltinFunc final : public Func
|
||||
{
|
||||
class BuiltinFunc final : public Func {
|
||||
public:
|
||||
BuiltinFunc(built_in_func func, const char* name, bool is_pure);
|
||||
~BuiltinFunc() override = default;
|
||||
BuiltinFunc(built_in_func func, const char* name, bool is_pure);
|
||||
~BuiltinFunc() override = default;
|
||||
|
||||
bool IsPure() const override;
|
||||
ValPtr Invoke(zeek::Args* args, Frame* parent) const override;
|
||||
built_in_func TheFunc() const { return func; }
|
||||
bool IsPure() const override;
|
||||
ValPtr Invoke(zeek::Args* args, Frame* parent) const override;
|
||||
built_in_func TheFunc() const { return func; }
|
||||
|
||||
void Describe(ODesc* d) const override;
|
||||
void Describe(ODesc* d) const override;
|
||||
|
||||
protected:
|
||||
BuiltinFunc()
|
||||
{
|
||||
func = nullptr;
|
||||
is_pure = 0;
|
||||
}
|
||||
BuiltinFunc() {
|
||||
func = nullptr;
|
||||
is_pure = 0;
|
||||
}
|
||||
|
||||
built_in_func func;
|
||||
bool is_pure;
|
||||
};
|
||||
built_in_func func;
|
||||
bool is_pure;
|
||||
};
|
||||
|
||||
extern bool check_built_in_call(BuiltinFunc* f, CallExpr* call);
|
||||
|
||||
struct CallInfo
|
||||
{
|
||||
const CallExpr* call;
|
||||
const Func* func;
|
||||
const zeek::Args& args;
|
||||
};
|
||||
struct CallInfo {
|
||||
const CallExpr* call;
|
||||
const Func* func;
|
||||
const zeek::Args& args;
|
||||
};
|
||||
|
||||
// Class that collects all the specifics defining a Func.
|
||||
class FunctionIngredients
|
||||
{
|
||||
class FunctionIngredients {
|
||||
public:
|
||||
// Gathers all of the information from a scope and a function body needed
|
||||
// to build a function.
|
||||
FunctionIngredients(ScopePtr scope, StmtPtr body, const std::string& module_name);
|
||||
// Gathers all of the information from a scope and a function body needed
|
||||
// to build a function.
|
||||
FunctionIngredients(ScopePtr scope, StmtPtr body, const std::string& module_name);
|
||||
|
||||
const IDPtr& GetID() const { return id; }
|
||||
const IDPtr& GetID() const { return id; }
|
||||
|
||||
const StmtPtr& Body() const { return body; }
|
||||
void ReplaceBody(StmtPtr new_body) { body = std::move(new_body); }
|
||||
const StmtPtr& Body() const { return body; }
|
||||
void ReplaceBody(StmtPtr new_body) { body = std::move(new_body); }
|
||||
|
||||
const auto& Inits() const { return inits; }
|
||||
void ClearInits() { inits.clear(); }
|
||||
const auto& Inits() const { return inits; }
|
||||
void ClearInits() { inits.clear(); }
|
||||
|
||||
size_t FrameSize() const { return frame_size; }
|
||||
int Priority() const { return priority; }
|
||||
const ScopePtr& Scope() const { return scope; }
|
||||
const auto& Groups() const { return groups; }
|
||||
size_t FrameSize() const { return frame_size; }
|
||||
int Priority() const { return priority; }
|
||||
const ScopePtr& Scope() const { return scope; }
|
||||
const auto& Groups() const { return groups; }
|
||||
|
||||
// Used by script optimization to update lambda ingredients
|
||||
// after compilation.
|
||||
void SetFrameSize(size_t _frame_size) { frame_size = _frame_size; }
|
||||
// Used by script optimization to update lambda ingredients
|
||||
// after compilation.
|
||||
void SetFrameSize(size_t _frame_size) { frame_size = _frame_size; }
|
||||
|
||||
private:
|
||||
IDPtr id;
|
||||
StmtPtr body;
|
||||
std::vector<IDPtr> inits;
|
||||
size_t frame_size = 0;
|
||||
int priority = 0;
|
||||
ScopePtr scope;
|
||||
std::set<EventGroupPtr> groups;
|
||||
};
|
||||
IDPtr id;
|
||||
StmtPtr body;
|
||||
std::vector<IDPtr> inits;
|
||||
size_t frame_size = 0;
|
||||
int priority = 0;
|
||||
ScopePtr scope;
|
||||
std::set<EventGroupPtr> groups;
|
||||
};
|
||||
|
||||
using FunctionIngredientsPtr = std::shared_ptr<FunctionIngredients>;
|
||||
|
||||
|
@ -427,19 +404,18 @@ extern bool did_builtin_init;
|
|||
extern std::vector<void (*)()> bif_initializers;
|
||||
extern void init_primary_bifs();
|
||||
|
||||
inline void run_bif_initializers()
|
||||
{
|
||||
for ( const auto& bi : bif_initializers )
|
||||
bi();
|
||||
inline void run_bif_initializers() {
|
||||
for ( const auto& bi : bif_initializers )
|
||||
bi();
|
||||
|
||||
bif_initializers = {};
|
||||
}
|
||||
bif_initializers = {};
|
||||
}
|
||||
|
||||
extern void emit_builtin_exception(const char* msg);
|
||||
extern void emit_builtin_exception(const char* msg, const ValPtr& arg);
|
||||
extern void emit_builtin_exception(const char* msg, Obj* arg);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace detail
|
||||
|
||||
extern std::string render_call_stack();
|
||||
|
||||
|
@ -448,4 +424,4 @@ extern void emit_builtin_error(const char* msg);
|
|||
extern void emit_builtin_error(const char* msg, const ValPtr&);
|
||||
extern void emit_builtin_error(const char* msg, Obj* arg);
|
||||
|
||||
} // namespace zeek
|
||||
} // namespace zeek
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue