diff --git a/auxil/bifcl b/auxil/bifcl index 6c07de1324..001e1c30f9 160000 --- a/auxil/bifcl +++ b/auxil/bifcl @@ -1 +1 @@ -Subproject commit 6c07de13247f16490c25a2066c77db1678ccd128 +Subproject commit 001e1c30f9646ea1198da6f8d24dc2235dbcd390 diff --git a/src/Attr.h b/src/Attr.h index a1ff47dcc7..b8263f0239 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -10,20 +10,19 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); -namespace zeek { -class Type; -using TypePtr = IntrusivePtr; - -namespace detail { -using ExprPtr = zeek::IntrusivePtr; -} -} - // Note that there are two kinds of attributes: the kind (here) which // modify expressions or supply metadata on types, and the kind that // are extra metadata on every variable instance. -namespace zeek::detail { + +namespace zeek { + +class Type; +using TypePtr = IntrusivePtr; + +namespace detail { + +using ExprPtr = zeek::IntrusivePtr; enum AttrTag { ATTR_OPTIONAL, @@ -145,7 +144,8 @@ protected: bool global_var; }; -} +} // namespace detail +} // namespace zeek using Attr [[deprecated("Remove in v4.1. Use zeek::detail::Attr instead.")]] = zeek::detail::Attr; using Attributes [[deprecated("Remove in v4.1. Use zeek::detail::Attr instead.")]] = zeek::detail::Attributes; diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index 872a9dd5f5..15f9f4e048 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -141,7 +141,7 @@ bool DbgBreakpoint::SetLocation(ParseLocationRec plr, std::string_view loc_str) at_stmt = plr.stmt; snprintf(description, sizeof(description), "%s:%d", - source_filename, source_line); + source_filename, source_line); debug_msg("Breakpoint %d set at %s\n", GetID(), Description()); } @@ -150,12 +150,12 @@ bool DbgBreakpoint::SetLocation(ParseLocationRec plr, std::string_view loc_str) { std::string loc_s(loc_str); kind = BP_FUNC; - function_name = make_full_var_name(current_module.c_str(), - loc_s.c_str()); + function_name = make_full_var_name(zeek::detail::current_module.c_str(), + loc_s.c_str()); at_stmt = plr.stmt; const Location* loc = at_stmt->GetLocationInfo(); snprintf(description, sizeof(description), "%s at %s:%d", - function_name.c_str(), loc->filename, loc->last_line); + function_name.c_str(), loc->filename, loc->last_line); debug_msg("Breakpoint %d set at %s\n", GetID(), Description()); } @@ -350,7 +350,7 @@ void DbgBreakpoint::PrintHitMsg() case BP_LINE: { ODesc d; - Frame* f = g_frame_stack.back(); + zeek::detail::Frame* f = g_frame_stack.back(); const BroFunc* func = f->GetFunction(); if ( func ) diff --git a/src/Debug.cc b/src/Debug.cc index b3b4523da1..504c8e6a66 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -44,7 +44,7 @@ std::map g_dbgfilemaps; // current context; you don't want to do it after a step or next // command unless you've exited a function. static bool step_or_next_pending = false; -static Frame* last_frame; +static zeek::detail::Frame* last_frame; DebuggerState::DebuggerState() { @@ -55,7 +55,7 @@ DebuggerState::DebuggerState() BreakFromSignal(false); // ### Don't choose this arbitrary size! Extend Frame. - dbg_locals = new Frame(1024, /* func = */ nullptr, /* fn_args = */ nullptr); + dbg_locals = new zeek::detail::Frame(1024, /* func = */ nullptr, /* fn_args = */ nullptr); } DebuggerState::~DebuggerState() @@ -197,11 +197,11 @@ void get_first_statement(zeek::detail::Stmt* list, zeek::detail::Stmt*& first, L static void parse_function_name(vector& result, ParseLocationRec& plr, const string& s) { // function name - const auto& id = lookup_ID(s.c_str(), current_module.c_str()); + const auto& id = zeek::detail::lookup_ID(s.c_str(), zeek::detail::current_module.c_str()); if ( ! id ) { - string fullname = make_full_var_name(current_module.c_str(), s.c_str()); + string fullname = make_full_var_name(zeek::detail::current_module.c_str(), s.c_str()); debug_msg("Function %s not defined.\n", fullname.c_str()); plr.type = plrUnknown; return; @@ -728,7 +728,7 @@ static char* get_prompt(bool reset_counter = false) return prompt; } -string get_context_description(const zeek::detail::Stmt* stmt, const Frame* frame) +string get_context_description(const zeek::detail::Stmt* stmt, const zeek::detail::Frame* frame) { ODesc d; const BroFunc* func = frame ? frame->GetFunction() : nullptr; @@ -769,12 +769,12 @@ int dbg_handle_debug_input() g_debugger_state.BreakFromSignal(false); } - Frame* curr_frame = g_frame_stack.back(); + zeek::detail::Frame* curr_frame = g_frame_stack.back(); const BroFunc* func = curr_frame->GetFunction(); if ( func ) - current_module = extract_module_name(func->Name()); + zeek::detail::current_module = extract_module_name(func->Name()); else - current_module = GLOBAL_MODULE_NAME; + zeek::detail::current_module = GLOBAL_MODULE_NAME; const zeek::detail::Stmt* stmt = curr_frame->GetNextStmt(); if ( ! stmt ) @@ -840,7 +840,7 @@ int dbg_handle_debug_input() // Return true to continue execution, false to abort. -bool pre_execute_stmt(zeek::detail::Stmt* stmt, Frame* f) +bool pre_execute_stmt(zeek::detail::Stmt* stmt, zeek::detail::Frame* f) { if ( ! g_policy_debug || stmt->Tag() == STMT_LIST || stmt->Tag() == STMT_NULL ) @@ -905,7 +905,7 @@ bool pre_execute_stmt(zeek::detail::Stmt* stmt, Frame* f) return true; } -bool post_execute_stmt(zeek::detail::Stmt* stmt, Frame* f, zeek::Val* result, stmt_flow_type* flow) +bool post_execute_stmt(zeek::detail::Stmt* stmt, zeek::detail::Frame* f, zeek::Val* result, stmt_flow_type* flow) { // Handle the case where someone issues a "next" debugger command, // but we're at a return statement, so the next statement is in @@ -959,7 +959,7 @@ zeek::ValPtr dbg_eval_expr(const char* expr) if ( ! (frame_idx >= 0 && (unsigned) frame_idx < g_frame_stack.size()) ) reporter->InternalError("Assertion failed: frame_idx >= 0 && (unsigned) frame_idx < g_frame_stack.size()"); - Frame* frame = g_frame_stack[frame_idx]; + zeek::detail::Frame* frame = g_frame_stack[frame_idx]; if ( ! (frame) ) reporter->InternalError("Assertion failed: frame"); @@ -967,7 +967,7 @@ zeek::ValPtr dbg_eval_expr(const char* expr) if ( func ) { Ref(func->GetScope()); - push_existing_scope(func->GetScope()); + zeek::detail::push_existing_scope(func->GetScope()); } // ### Possibly push a debugger-local scope? @@ -1001,7 +1001,7 @@ zeek::ValPtr dbg_eval_expr(const char* expr) result = g_curr_debug_expr->Eval(frame); if ( func ) - pop_scope(); + zeek::detail::pop_scope(); delete g_curr_debug_expr; g_curr_debug_expr = nullptr; diff --git a/src/Debug.h b/src/Debug.h index 9fb016d9c0..32fc329723 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -11,8 +11,10 @@ #include #include +ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek); + namespace zeek { template class IntrusivePtr; using ValPtr = zeek::IntrusivePtr; @@ -30,7 +32,6 @@ struct ParseLocationRec { class StmtLocMapping; typedef PQueue Filemap; // mapping for a single file -class Frame; class DbgBreakpoint; class DbgWatch; class DbgDisplay; @@ -39,7 +40,9 @@ class StmtHashFn; typedef std::map BPIDMapType; typedef std::multimap BPMapType; +namespace zeek { extern std::string current_module; +} class TraceState { public: @@ -100,7 +103,7 @@ protected: int next_bp_id, next_watch_id, next_display_id; private: - Frame* dbg_locals; // unused + zeek::detail::Frame* dbg_locals; // unused }; // Source line -> statement mapping. @@ -147,8 +150,8 @@ std::vector parse_location_string(const std::string& s); // Debugging hooks. // Return true to continue execution, false to abort. -bool pre_execute_stmt(zeek::detail::Stmt* stmt, Frame* f); -bool post_execute_stmt(zeek::detail::Stmt* stmt, Frame* f, zeek::Val* result, stmt_flow_type* flow); +bool pre_execute_stmt(zeek::detail::Stmt* stmt, zeek::detail::Frame* f); +bool post_execute_stmt(zeek::detail::Stmt* stmt, zeek::detail::Frame* f, zeek::Val* result, stmt_flow_type* flow); // Returns 1 if successful, 0 otherwise. // If cmdfile is non-nil, it contains the location of a file of commands @@ -172,9 +175,9 @@ zeek::ValPtr dbg_eval_expr(const char* expr); int dbg_read_internal_state(); // Get line that looks like "In FnFoo(arg = val) at File:Line". -std::string get_context_description(const zeek::detail::Stmt* stmt, const Frame* frame); +std::string get_context_description(const zeek::detail::Stmt* stmt, const zeek::detail::Frame* frame); -extern Frame* g_dbg_locals; // variables created within debugger context +extern zeek::detail::Frame* g_dbg_locals; // variables created within debugger context extern std::map g_dbgfilemaps; // filename => filemap diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index abdba92675..550a0c6f7f 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -57,7 +57,7 @@ static void lookup_global_symbols_regex(const string& orig_regex, vectorVars(); zeek::detail::ID* nextid; @@ -214,7 +214,7 @@ static int dbg_backtrace_internal(int start, int end) for ( int i = start; i >= end; --i ) { - const Frame* f = g_frame_stack[i]; + const zeek::detail::Frame* f = g_frame_stack[i]; const zeek::detail::Stmt* stmt = f ? f->GetNextStmt() : nullptr; string context = get_context_description(stmt, f); diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 12038c58df..e3860f0b1d 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -31,8 +31,8 @@ const zeek::FuncTypePtr& EventHandler::GetType(bool check_export) if ( type ) return type; - const auto& id = lookup_ID(name.data(), current_module.c_str(), false, false, - check_export); + const auto& id = zeek::detail::lookup_ID(name.data(), zeek::detail::current_module.c_str(), + false, false, check_export); if ( ! id ) return zeek::FuncType::nil; diff --git a/src/Expr.h b/src/Expr.h index dc6642de6b..ed73e252ca 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -17,15 +17,14 @@ #include "Val.h" #include "ZeekArgs.h" -class Frame; -class Scope; +ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Scope, zeek::detail); struct function_ingredients; namespace zeek { template class IntrusivePtr; -} -namespace zeek::detail { +namespace detail { using IDPtr = zeek::IntrusivePtr; @@ -965,7 +964,8 @@ extern bool expr_greater(const Expr* e1, const Expr* e2); inline bool is_vector(Expr* e) { return e->GetType()->Tag() == TYPE_VECTOR; } inline bool is_vector(const ExprPtr& e) { return is_vector(e.get()); } -} +} // namespace detail +} // namespace zeek using Expr [[deprecated("Remove in v4.1. Use zeek::detail::Expr instead.")]] = zeek::detail::Expr; using NameExpr [[deprecated("Remove in v4.1. Use zeek::detail::NameExpr instead.")]] = zeek::detail::NameExpr; diff --git a/src/Frame.cc b/src/Frame.cc index a31e4a7f6c..fa5a11bc32 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -11,7 +11,9 @@ #include "Val.h" #include "ID.h" -std::vector g_frame_stack; +std::vector g_frame_stack; + +namespace zeek::detail { Frame::Frame(int arg_size, const BroFunc* func, const zeek::Args* fn_args) { @@ -616,3 +618,5 @@ Frame::UnserializeOffsetMap(const broker::vector& data) return std::make_pair(true, std::move(rval)); } + +} diff --git a/src/Frame.h b/src/Frame.h index 6449236e11..b4e74fbccb 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -21,16 +21,14 @@ class BroFunc; ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Trigger, zeek::detail::trigger); -namespace zeek::detail { +namespace zeek { +using ValPtr = zeek::IntrusivePtr; + +namespace detail { using IDPtr = zeek::IntrusivePtr; namespace trigger { - using TriggerPtr = zeek::IntrusivePtr; -} -} - -namespace zeek { -using ValPtr = zeek::IntrusivePtr; +using TriggerPtr = zeek::IntrusivePtr; } class Frame; @@ -343,6 +341,11 @@ private: std::unique_ptr> functions_with_closure_frame_reference; }; +} // namespace detail +} // namespace zeek + +using Frame [[deprecated("Remove in v4.1. Use zeek::detail::Frame instead.")]] = zeek::detail::Frame; + /** * If we stopped using this and instead just made a struct of the information * that the debugger actually uses we could make the Frame a class a template. @@ -353,4 +356,4 @@ private: * DebugFrame which provides the information that the debugger uses. See: * https://stackoverflow.com/a/16211097 */ -extern std::vector g_frame_stack; +extern std::vector g_frame_stack; diff --git a/src/Func.cc b/src/Func.cc index d778d880c5..cbec5b12d6 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -129,7 +129,7 @@ void Func::AddBody(zeek::detail::StmtPtr /* new_body */, Internal("Func::AddBody called"); } -void Func::SetScope(ScopePtr newscope) +void Func::SetScope(zeek::detail::ScopePtr newscope) { scope = std::move(newscope); } @@ -179,7 +179,7 @@ void Func::DescribeDebug(ODesc* d, const zeek::Args* args) const TraversalCode Func::Traverse(TraversalCallback* cb) const { // FIXME: Make a fake scope for builtins? - Scope* old_scope = cb->current_scope; + zeek::detail::Scope* old_scope = cb->current_scope; cb->current_scope = scope.get(); TraversalCode tc = cb->PreFunction(this); @@ -299,13 +299,13 @@ bool BroFunc::IsPure() const [](const Body& b) { return b.stmts->IsPure(); }); } -zeek::Val* Func::Call(val_list* args, Frame* parent) const +zeek::Val* Func::Call(val_list* args, zeek::detail::Frame* parent) const { auto zargs = zeek::val_list_to_args(*args); return Invoke(&zargs, parent).release(); }; -zeek::ValPtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const +zeek::ValPtr BroFunc::Invoke(zeek::Args* args, zeek::detail::Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -331,7 +331,7 @@ zeek::ValPtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const return Flavor() == zeek::FUNC_FLAVOR_HOOK ? val_mgr->True() : nullptr; } - auto f = zeek::make_intrusive(frame_size, this, args); + auto f = zeek::make_intrusive(frame_size, this, args); if ( closure ) f->CaptureClosure(closure, outer_ids); @@ -479,7 +479,7 @@ void BroFunc::AddBody(zeek::detail::StmtPtr new_body, sort(bodies.begin(), bodies.end()); } -void BroFunc::AddClosure(id_list ids, Frame* f) +void BroFunc::AddClosure(id_list ids, zeek::detail::Frame* f) { if ( ! f ) return; @@ -488,7 +488,7 @@ void BroFunc::AddClosure(id_list ids, Frame* f) SetClosureFrame(f); } -bool BroFunc::StrengthenClosureReference(Frame* f) +bool BroFunc::StrengthenClosureReference(zeek::detail::Frame* f) { if ( closure != f ) return false; @@ -501,7 +501,7 @@ bool BroFunc::StrengthenClosureReference(Frame* f) return true; } -void BroFunc::SetClosureFrame(Frame* f) +void BroFunc::SetClosureFrame(zeek::detail::Frame* f) { if ( closure ) reporter->InternalError("Tried to override closure for BroFunc %s.", @@ -521,7 +521,7 @@ void BroFunc::SetClosureFrame(Frame* f) bool BroFunc::UpdateClosure(const broker::vector& data) { - auto result = Frame::Unserialize(data); + auto result = zeek::detail::Frame::Unserialize(data); if ( ! result.first ) return false; @@ -559,7 +559,7 @@ FuncPtr BroFunc::DoClone() broker::expected BroFunc::SerializeClosure() const { - return Frame::Serialize(closure, outer_ids); + return zeek::detail::Frame::Serialize(closure, outer_ids); } void BroFunc::Describe(ODesc* d) const @@ -597,7 +597,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, name = make_full_var_name(GLOBAL_MODULE_NAME, arg_name); is_pure = arg_is_pure; - const auto& id = lookup_ID(Name(), GLOBAL_MODULE_NAME, false); + const auto& id = zeek::detail::lookup_ID(Name(), GLOBAL_MODULE_NAME, false); if ( ! id ) reporter->InternalError("built-in function %s missing", Name()); if ( id->HasVal() ) @@ -616,7 +616,7 @@ bool BuiltinFunc::IsPure() const return is_pure; } -zeek::ValPtr BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const +zeek::ValPtr BuiltinFunc::Invoke(zeek::Args* args, zeek::detail::Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -881,7 +881,7 @@ static int get_func_priority(const std::vector& attrs) return priority; } -function_ingredients::function_ingredients(ScopePtr scope, zeek::detail::StmtPtr body) +function_ingredients::function_ingredients(zeek::detail::ScopePtr scope, zeek::detail::StmtPtr body) { frame_size = scope->Length(); inits = scope->GetInits(); diff --git a/src/Func.h b/src/Func.h index 6081344a93..21cf6d4f16 100644 --- a/src/Func.h +++ b/src/Func.h @@ -17,20 +17,13 @@ #include "ZeekArgs.h" #include "BifReturnVal.h" -class Frame; -class Scope; -using ScopePtr = zeek::IntrusivePtr; - +ZEEK_FORWARD_DECLARE_NAMESPACED(Scope, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek); - -namespace zeek::detail { -using IDPtr = zeek::IntrusivePtr; -using StmtPtr = zeek::IntrusivePtr; -} +ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); namespace caf { template class expected; @@ -42,6 +35,15 @@ using vector = std::vector; using caf::expected; } +namespace zeek { + +namespace detail { +using ScopePtr = zeek::IntrusivePtr; +using IDPtr = zeek::IntrusivePtr; +using StmtPtr = zeek::IntrusivePtr; +} +} + class Func; using FuncPtr = zeek::IntrusivePtr; @@ -69,7 +71,7 @@ public: bool HasBodies() const { return bodies.size(); } [[deprecated("Remove in v4.1. Use Invoke() instead.")]] - zeek::Val* Call(val_list* args, Frame* parent = nullptr) const; + zeek::Val* Call(val_list* args, zeek::detail::Frame* parent = nullptr) const; /** * Calls a Zeek function. @@ -78,7 +80,7 @@ public: * @return the return value of the function call. */ virtual zeek::ValPtr Invoke( - zeek::Args* args, Frame* parent = nullptr) const = 0; + zeek::Args* args, zeek::detail::Frame* parent = nullptr) const = 0; /** * A version of Invoke() taking a variable number of individual arguments. @@ -98,8 +100,8 @@ public: const std::vector& new_inits, size_t new_frame_size, int priority = 0); - virtual void SetScope(ScopePtr newscope); - virtual Scope* GetScope() const { return scope.get(); } + virtual void SetScope(zeek::detail::ScopePtr newscope); + virtual zeek::detail::Scope* GetScope() const { return scope.get(); } [[deprecated("Remove in v4.1. Use GetType().")]] virtual zeek::FuncType* FType() const { return type.get(); } @@ -134,7 +136,7 @@ protected: zeek::FunctionFlavor flavor) const; std::vector bodies; - ScopePtr scope; + zeek::detail::ScopePtr scope; Kind kind; uint32_t unique_id; zeek::FuncTypePtr type; @@ -152,7 +154,7 @@ public: ~BroFunc() override; bool IsPure() const override; - zeek::ValPtr Invoke(zeek::Args* args, Frame* parent) const override; + zeek::ValPtr Invoke(zeek::Args* args, zeek::detail::Frame* parent) const override; /** * Adds adds a closure to the function. Closures are cloned and @@ -161,7 +163,7 @@ public: * @param ids IDs that are captured by the closure. * @param f the closure to be captured. */ - void AddClosure(id_list ids, Frame* f); + void AddClosure(id_list ids, zeek::detail::Frame* f); /** * Replaces the current closure with one built from *data* @@ -174,7 +176,7 @@ public: * If the function's closure is a weak reference to the given frame, * upgrade to a strong reference of a shallow clone of that frame. */ - bool StrengthenClosureReference(Frame* f); + bool StrengthenClosureReference(zeek::detail::Frame* f); /** * Serializes this function's closure. @@ -210,7 +212,7 @@ protected: * * @param f the frame to be cloned. */ - void SetClosureFrame(Frame* f); + void SetClosureFrame(zeek::detail::Frame* f); private: size_t frame_size; @@ -218,11 +220,11 @@ private: // List of the outer IDs used in the function. id_list outer_ids; // The frame the BroFunc was initialized in. - Frame* closure = nullptr; + zeek::detail::Frame* closure = nullptr; bool weak_closure_ref = false; }; -using built_in_func = BifReturnVal (*)(Frame* frame, const zeek::Args* args); +using built_in_func = BifReturnVal (*)(zeek::detail::Frame* frame, const zeek::Args* args); class BuiltinFunc final : public Func { public: @@ -230,7 +232,7 @@ public: ~BuiltinFunc() override; bool IsPure() const override; - zeek::ValPtr Invoke(zeek::Args* args, Frame* parent) const override; + zeek::ValPtr Invoke(zeek::Args* args, zeek::detail::Frame* parent) const override; built_in_func TheFunc() const { return func; } void Describe(ODesc* d) const override; @@ -263,14 +265,14 @@ struct function_ingredients { // Gathers all of the information from a scope and a function body needed // to build a function. - function_ingredients(ScopePtr scope, zeek::detail::StmtPtr body); + function_ingredients(zeek::detail::ScopePtr scope, zeek::detail::StmtPtr body); zeek::detail::IDPtr id; zeek::detail::StmtPtr body; std::vector inits; int frame_size; int priority; - ScopePtr scope; + zeek::detail::ScopePtr scope; }; extern std::vector call_stack; diff --git a/src/Hash.h b/src/Hash.h index dbb6802943..af15097173 100644 --- a/src/Hash.h +++ b/src/Hash.h @@ -23,16 +23,15 @@ #include - // to allow bro_md5_hmac access to the hmac seed #include "ZeekArgs.h" -//ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek); +ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); + class BroString; -class Frame; class BifReturnVal; namespace zeek::BifFunc { - extern BifReturnVal md5_hmac_bif(::Frame* frame, const zeek::Args*); + extern BifReturnVal md5_hmac_bif(zeek::detail::Frame* frame, const zeek::Args*); } typedef uint64_t hash_t; @@ -197,7 +196,7 @@ private: inline static bool seeds_initialized = false; friend void hmac_md5(size_t size, const unsigned char* bytes, unsigned char digest[16]); - friend BifReturnVal zeek::BifFunc::md5_hmac_bif(Frame* frame, const zeek::Args*); + friend BifReturnVal zeek::BifFunc::md5_hmac_bif(zeek::detail::Frame* frame, const zeek::Args*); }; typedef enum { diff --git a/src/ID.cc b/src/ID.cc index c0c8c2f094..f8cac63526 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -34,12 +34,12 @@ zeek::VectorTypePtr zeek::id::index_vec; const zeek::detail::IDPtr& zeek::id::find(std::string_view name) { - return global_scope()->Find(name); + return zeek::detail::global_scope()->Find(name); } const zeek::TypePtr& zeek::id::find_type(std::string_view name) { - auto id = global_scope()->Find(name); + auto id = zeek::detail::global_scope()->Find(name); if ( ! id ) reporter->InternalError("Failed to find type named: %s", @@ -50,7 +50,7 @@ const zeek::TypePtr& zeek::id::find_type(std::string_view name) const zeek::ValPtr& zeek::id::find_val(std::string_view name) { - auto id = global_scope()->Find(name); + auto id = zeek::detail::global_scope()->Find(name); if ( ! id ) reporter->InternalError("Failed to find variable named: %s", @@ -61,7 +61,7 @@ const zeek::ValPtr& zeek::id::find_val(std::string_view name) const zeek::ValPtr& zeek::id::find_const(std::string_view name) { - auto id = global_scope()->Find(name); + auto id = zeek::detail::global_scope()->Find(name); if ( ! id ) reporter->InternalError("Failed to find variable named: %s", @@ -366,7 +366,7 @@ TraversalCode ID::Traverse(TraversalCallback* cb) const // FIXME: Perhaps we should be checking at other than global scope. else if ( val && IsFunc(val->GetType()->Tag()) && - cb->current_scope == global_scope() ) + cb->current_scope == zeek::detail::global_scope() ) { tc = val->AsFunc()->Traverse(cb); HANDLE_TC_STMT_PRE(tc); diff --git a/src/Net.cc b/src/Net.cc index d419ba485e..97940a792d 100644 --- a/src/Net.cc +++ b/src/Net.cc @@ -193,7 +193,7 @@ void net_init(const std::optional& interface, reporter->FatalError("problem opening dump file %s (%s)", writefile, pkt_dumper->ErrorMsg()); - if ( const auto& id = global_scope()->Find("trace_output_file") ) + if ( const auto& id = zeek::detail::global_scope()->Find("trace_output_file") ) id->SetVal(zeek::make_intrusive(writefile)); else reporter->Error("trace_output_file not defined in bro.init"); diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 5f29ce39a8..2d91e27dde 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -130,7 +130,7 @@ zeek::TypePtr OpaqueVal::UnserializeType(const broker::data& data) if ( ! name ) return nullptr; - const auto& id = global_scope()->Find(*name); + const auto& id = zeek::detail::global_scope()->Find(*name); if ( ! id ) return nullptr; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index f961620deb..073c6201ef 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -129,7 +129,7 @@ bool RuleConditionPayloadSize::DoMatch(Rule* rule, RuleEndpointState* state, RuleConditionEval::RuleConditionEval(const char* func) { - id = global_scope()->Find(func).get(); + id = zeek::detail::global_scope()->Find(func).get(); if ( ! id ) { rules_error("unknown identifier", func); diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index eec90eb769..8e68d4b4d6 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -1274,7 +1274,7 @@ void RuleMatcher::DumpStateStats(BroFile* f, RuleHdrTest* hdr_test) static zeek::Val* get_bro_val(const char* label) { - auto id = lookup_ID(label, GLOBAL_MODULE_NAME, false); + auto id = zeek::detail::lookup_ID(label, GLOBAL_MODULE_NAME, false); if ( ! id ) { rules_error("unknown script-level identifier", label); diff --git a/src/Scope.cc b/src/Scope.cc index 2aee17b8be..d9f9d4bd48 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -10,7 +10,9 @@ #include "Reporter.h" #include "module_util.h" -typedef PList scope_list; +namespace zeek::detail { + +using scope_list = PList; static scope_list scopes; static Scope* top_scope; @@ -119,10 +121,9 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const } -const zeek::detail::IDPtr& lookup_ID( - const char* name, const char* curr_module, - bool no_global, bool same_module_only, - bool check_export) +const zeek::detail::IDPtr& lookup_ID(const char* name, const char* curr_module, + bool no_global, bool same_module_only, + bool check_export) { std::string fullname = make_full_var_name(curr_module, name); @@ -138,14 +139,14 @@ const zeek::detail::IDPtr& lookup_ID( { if ( need_export && ! id->IsExport() && ! in_debug ) reporter->Error("identifier is not exported: %s", - fullname.c_str()); + fullname.c_str()); return id; } } if ( ! no_global && (strcmp(GLOBAL_MODULE_NAME, curr_module) == 0 || - ! same_module_only) ) + ! same_module_only) ) { std::string globalname = make_full_var_name(GLOBAL_MODULE_NAME, name); return global_scope()->Find(globalname); @@ -154,9 +155,8 @@ const zeek::detail::IDPtr& lookup_ID( return zeek::detail::ID::nil; } -zeek::detail::IDPtr install_ID( - const char* name, const char* module_name, - bool is_global, bool is_export) +zeek::detail::IDPtr install_ID(const char* name, const char* module_name, + bool is_global, bool is_export) { if ( scopes.empty() && ! is_global ) reporter->InternalError("local identifier in global scope"); @@ -220,3 +220,14 @@ Scope* global_scope() { return scopes.empty() ? 0 : scopes.front(); } + +} + +const zeek::detail::IDPtr& lookup_ID( + const char* name, const char* module, + bool no_global, + bool same_module_only, + bool check_export) +{ + return zeek::detail::lookup_ID(name, module, no_global, same_module_only, check_export); +} diff --git a/src/Scope.h b/src/Scope.h index cdd7175aa1..2a227055a0 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -12,21 +12,21 @@ #include "IntrusivePtr.h" #include "TraverseTypes.h" +ZEEK_FORWARD_DECLARE_NAMESPACED(Type, zeek); +using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; + +ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Attr, zeek::detail); namespace zeek { - template class IntrusivePtr; - class Type; - using TypePtr = zeek::IntrusivePtr; -} -using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; -ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); +template class IntrusivePtr; +using TypePtr = zeek::IntrusivePtr; -namespace zeek::detail { - class Attr; - using AttrPtr = zeek::IntrusivePtr; - using IDPtr = zeek::IntrusivePtr; -} +namespace detail { + +using AttrPtr = zeek::IntrusivePtr; +using IDPtr = zeek::IntrusivePtr; class Scope; using ScopePtr = zeek::IntrusivePtr; @@ -88,9 +88,6 @@ protected: std::vector inits; }; - -extern bool in_debug; - // If no_global is true, don't search in the default "global" namespace. extern const zeek::detail::IDPtr& lookup_ID( const char* name, const char* module, @@ -113,3 +110,26 @@ extern Scope* global_scope(); // Current module (identified by its name). extern std::string current_module; + +} // namespace detail +} // namespace zeek + +extern bool in_debug; + +using Scope [[deprecated("Remove in v4.1. Use zeek::detail::Scope instead.")]] = zeek::detail::Scope; +extern std::string& current_module [[deprecated("Remove in v4.1. Use zeek::detail::current_module.")]]; + +constexpr auto install_ID [[deprecated("Remove in v4.1 Use zeek::detail::install_ID instead.")]] = zeek::detail::install_ID; +constexpr auto push_scope [[deprecated("Remove in v4.1 Use zeek::detail::push_scope instead.")]] = zeek::detail::push_scope; +constexpr auto push_existing_scope[[deprecated("Remove in v4.1 Use zeek::detail::push_existing_scope instead.")]] = zeek::detail::push_existing_scope; +constexpr auto pop_scope [[deprecated("Remove in v4.1 Use zeek::detail::pop_scope instead.")]] = zeek::detail::pop_scope; +constexpr auto current_scope [[deprecated("Remove in v4.1 Use zeek::detail::current_scope instead.")]] = zeek::detail::current_scope; +constexpr auto global_scope [[deprecated("Remove in v4.1 Use zeek::detail::global_scope instead.")]] = zeek::detail::global_scope; + +// Because of the use of default arguments, this function can't be aliased like the rest. +[[deprecated("Remove in v4.1 Use zeek::detail::lookup_ID instead.")]] +extern const zeek::detail::IDPtr& lookup_ID( + const char* name, const char* module, + bool no_global = false, + bool same_module_only = false, + bool check_export = true); diff --git a/src/Stats.cc b/src/Stats.cc index 599f3bc4d9..fcb7249801 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -240,7 +240,7 @@ void ProfileLogger::Log() // Script-level state. unsigned int size, mem = 0; - const auto& globals = global_scope()->Vars(); + const auto& globals = zeek::detail::global_scope()->Vars(); if ( expensive ) { diff --git a/src/Stmt.h b/src/Stmt.h index b85f0ab7d2..0858c1022c 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -14,7 +14,8 @@ #include "TraverseTypes.h" class CompositeHash; -class Frame; + +ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); namespace zeek::detail { diff --git a/src/Traverse.cc b/src/Traverse.cc index b9aa28b42d..71562dfee5 100644 --- a/src/Traverse.cc +++ b/src/Traverse.cc @@ -7,16 +7,16 @@ TraversalCode traverse_all(TraversalCallback* cb) { - if ( ! global_scope() ) + if ( ! zeek::detail::global_scope() ) return TC_CONTINUE; if ( ! stmts ) // May be null when parsing fails. return TC_CONTINUE; - cb->current_scope = global_scope(); + cb->current_scope = zeek::detail::global_scope(); - TraversalCode tc = global_scope()->Traverse(cb); + TraversalCode tc = zeek::detail::global_scope()->Traverse(cb); HANDLE_TC_STMT_PRE(tc); tc = stmts->Traverse(cb); diff --git a/src/Traverse.h b/src/Traverse.h index 2d3e13bfee..97598a7a15 100644 --- a/src/Traverse.h +++ b/src/Traverse.h @@ -5,8 +5,8 @@ #include "TraverseTypes.h" class Func; -class Scope; +ZEEK_FORWARD_DECLARE_NAMESPACED(Scope, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); @@ -34,7 +34,7 @@ public: virtual TraversalCode PreDecl(const zeek::detail::ID*) { return TC_CONTINUE; } virtual TraversalCode PostDecl(const zeek::detail::ID*) { return TC_CONTINUE; } - Scope* current_scope; + zeek::detail::Scope* current_scope; }; TraversalCode traverse_all(TraversalCallback* cb); diff --git a/src/Trigger.h b/src/Trigger.h index a904832e83..fe99890214 100644 --- a/src/Trigger.h +++ b/src/Trigger.h @@ -10,10 +10,10 @@ #include "util.h" #include "IntrusivePtr.h" -class Frame; class ODesc; ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek); +ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); diff --git a/src/Type.cc b/src/Type.cc index ad8a9186e4..91409aeeb5 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1131,11 +1131,11 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, return; } - auto id = lookup_ID(name, module_name.c_str()); + auto id = zeek::detail::lookup_ID(name, module_name.c_str()); if ( ! id ) { - id = install_ID(name, module_name.c_str(), true, is_export); + id = zeek::detail::install_ID(name, module_name.c_str(), true, is_export); id->SetType({zeek::NewRef{}, this}); id->SetEnumConst(); @@ -1733,7 +1733,7 @@ TypePtr merge_types(const TypePtr& arg_t1, // Doing a lookup here as a roundabout way of ref-ing t1, without // changing the function params which has t1 as const and also // (potentially) avoiding a pitfall mentioned earlier about clones. - const auto& id = global_scope()->Find(t1->GetName()); + const auto& id = zeek::detail::global_scope()->Find(t1->GetName()); if ( id && id->IsType() && id->GetType()->Tag() == TYPE_ENUM ) // It should make most sense to return the real type here rather diff --git a/src/Val.cc b/src/Val.cc index 8dce7fd022..c9802d469e 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -383,7 +383,7 @@ void Val::ValDescribeReST(ODesc* d) const #ifdef DEBUG detail::ID* Val::GetID() const { - return bound_id ? global_scope()->Find(bound_id).get() : nullptr; + return bound_id ? zeek::detail::global_scope()->Find(bound_id).get() : nullptr; } void Val::SetID(detail::ID* id) @@ -2331,7 +2331,7 @@ bool TableVal::CheckAndAssign(ValPtr index, ValPtr new_val) return Assign(std::move(index), std::move(new_val)); } -void TableVal::InitDefaultFunc(Frame* f) +void TableVal::InitDefaultFunc(zeek::detail::Frame* f) { // Value aready initialized. if ( def_val ) diff --git a/src/Val.h b/src/Val.h index fb6428b093..f87b53d2f8 100644 --- a/src/Val.h +++ b/src/Val.h @@ -41,7 +41,8 @@ class RE_Matcher; class CompositeHash; class HashKey; -class Frame; + +ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); extern double bro_start_network_time; @@ -980,7 +981,7 @@ public: // If the &default attribute is not a function, or the functon has // already been initialized, this does nothing. Otherwise, evaluates // the function in the frame allowing it to capture its closure. - void InitDefaultFunc(Frame* f); + void InitDefaultFunc(zeek::detail::Frame* f); unsigned int MemoryAllocation() const override; diff --git a/src/Var.cc b/src/Var.cc index 1c0daa6757..e577355769 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -350,7 +350,7 @@ zeek::detail::StmtPtr add_local( else { - current_scope()->AddInit(std::move(id)); + zeek::detail::current_scope()->AddInit(std::move(id)); return zeek::make_intrusive(); } } @@ -568,7 +568,7 @@ void begin_func(zeek::detail::IDPtr id, const char* module_name, else id->SetType(t); - push_scope(std::move(id), std::move(attrs)); + zeek::detail::push_scope(std::move(id), std::move(attrs)); const auto& args = t->Params(); int num_args = args->NumFields(); @@ -576,26 +576,26 @@ void begin_func(zeek::detail::IDPtr id, const char* module_name, for ( int i = 0; i < num_args; ++i ) { zeek::TypeDecl* arg_i = args->FieldDecl(i); - auto arg_id = lookup_ID(arg_i->id, module_name); + auto arg_id = zeek::detail::lookup_ID(arg_i->id, module_name); if ( arg_id && ! arg_id->IsGlobal() ) arg_id->Error("argument name used twice"); - arg_id = install_ID(arg_i->id, module_name, false, false); + arg_id = zeek::detail::install_ID(arg_i->id, module_name, false, false); arg_id->SetType(arg_i->type); if ( prototype ) arg_id->SetOffset(prototype->offsets[i]); } - if ( zeek::detail::Attr* depr_attr = find_attr(current_scope()->Attrs().get(), + if ( zeek::detail::Attr* depr_attr = find_attr(zeek::detail::current_scope()->Attrs().get(), zeek::detail::ATTR_DEPRECATED) ) - current_scope()->GetID()->MakeDeprecated(depr_attr->GetExpr()); + zeek::detail::current_scope()->GetID()->MakeDeprecated(depr_attr->GetExpr()); } class OuterIDBindingFinder : public TraversalCallback { public: - OuterIDBindingFinder(Scope* s) + OuterIDBindingFinder(zeek::detail::Scope* s) { scopes.emplace_back(s); } @@ -603,7 +603,7 @@ public: TraversalCode PreExpr(const zeek::detail::Expr*) override; TraversalCode PostExpr(const zeek::detail::Expr*) override; - std::vector scopes; + std::vector scopes; std::vector outer_id_references; }; @@ -644,7 +644,8 @@ TraversalCode OuterIDBindingFinder::PostExpr(const zeek::detail::Expr* expr) void end_func(zeek::detail::StmtPtr body) { - auto ingredients = std::make_unique(pop_scope(), std::move(body)); + auto ingredients = std::make_unique(zeek::detail::pop_scope(), + std::move(body)); if ( ingredients->id->HasVal() ) ingredients->id->GetVal()->AsFunc()->AddBody( @@ -677,7 +678,7 @@ zeek::Val* internal_val(const char* name) return zeek::id::find_val(name).get(); } -id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body) +id_list gather_outer_ids(zeek::detail::Scope* scope, zeek::detail::Stmt* body) { OuterIDBindingFinder cb(scope); body->Traverse(&cb); @@ -704,13 +705,13 @@ zeek::Val* internal_const_val(const char* name) zeek::Val* opt_internal_val(const char* name) { - const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = zeek::detail::lookup_ID(name, GLOBAL_MODULE_NAME); return id ? id->GetVal().get() : nullptr; } double opt_internal_double(const char* name) { - const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = zeek::detail::lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return 0.0; const auto& v = id->GetVal(); return v ? v->InternalDouble() : 0.0; @@ -718,7 +719,7 @@ double opt_internal_double(const char* name) bro_int_t opt_internal_int(const char* name) { - const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = zeek::detail::lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return 0; const auto& v = id->GetVal(); return v ? v->InternalInt() : 0; @@ -726,7 +727,7 @@ bro_int_t opt_internal_int(const char* name) bro_uint_t opt_internal_unsigned(const char* name) { - const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = zeek::detail::lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return 0; const auto& v = id->GetVal(); return v ? v->InternalUnsigned() : 0; @@ -734,7 +735,7 @@ bro_uint_t opt_internal_unsigned(const char* name) zeek::StringVal* opt_internal_string(const char* name) { - const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = zeek::detail::lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return nullptr; const auto& v = id->GetVal(); return v ? v->AsStringVal() : nullptr; @@ -742,7 +743,7 @@ zeek::StringVal* opt_internal_string(const char* name) zeek::TableVal* opt_internal_table(const char* name) { - const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = zeek::detail::lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return nullptr; const auto& v = id->GetVal(); return v ? v->AsTableVal() : nullptr; @@ -750,7 +751,7 @@ zeek::TableVal* opt_internal_table(const char* name) zeek::ListVal* internal_list_val(const char* name) { - const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = zeek::detail::lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return nullptr; diff --git a/src/Var.h b/src/Var.h index e2b6ae9bae..f1c054a2b7 100644 --- a/src/Var.h +++ b/src/Var.h @@ -6,7 +6,6 @@ #include "ID.h" #include "Type.h" -class Scope; class EventHandlerPtr; ZEEK_FORWARD_DECLARE_NAMESPACED(StringVal, zeek); @@ -15,6 +14,7 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(ListVal, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Scope, zeek::detail); namespace zeek::detail { using StmtPtr = zeek::IntrusivePtr; @@ -53,7 +53,7 @@ extern void begin_func(zeek::detail::IDPtr id, const char* module_name, extern void end_func(zeek::detail::StmtPtr body); // Gather all IDs referenced inside a body that aren't part of a given scope. -extern id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body); +extern id_list gather_outer_ids(zeek::detail::Scope* scope, zeek::detail::Stmt* body); [[deprecated("Remove in v4.1. Use zeek::id::find_val().")]] extern zeek::Val* internal_val(const char* name); diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index c3ab9101e8..5956bb6cc7 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -90,7 +90,7 @@ void Manager::InitPreScript() void Manager::InitPostScript() { - const auto& id = global_scope()->Find("Tunnel::vxlan_ports"); + const auto& id = zeek::detail::global_scope()->Find("Tunnel::vxlan_ports"); if ( ! (id && id->GetVal()) ) reporter->FatalError("Tunnel::vxlan_ports not defined"); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 4157da2e00..bcaae8a091 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -349,7 +349,7 @@ struct val_converter { if ( ! name ) return nullptr; - const auto& id = global_scope()->Find(*name); + const auto& id = zeek::detail::global_scope()->Find(*name); if ( ! id ) return nullptr; @@ -693,7 +693,7 @@ struct type_checker { if ( ! name ) return false; - const auto& id = global_scope()->Find(*name); + const auto& id = zeek::detail::global_scope()->Find(*name); if ( ! id ) return false; @@ -1112,12 +1112,12 @@ struct data_type_getter { } }; -zeek::EnumValPtr bro_broker::get_data_type(zeek::RecordVal* v, Frame* frame) +zeek::EnumValPtr bro_broker::get_data_type(zeek::RecordVal* v, zeek::detail::Frame* frame) { return caf::visit(data_type_getter{}, opaque_field_to_data(v, frame)); } -broker::data& bro_broker::opaque_field_to_data(zeek::RecordVal* v, Frame* f) +broker::data& bro_broker::opaque_field_to_data(zeek::RecordVal* v, zeek::detail::Frame* f) { const auto& d = v->GetField(0); diff --git a/src/broker/Data.h b/src/broker/Data.h index 0085ed2844..b97217878f 100644 --- a/src/broker/Data.h +++ b/src/broker/Data.h @@ -46,7 +46,7 @@ zeek::RecordValPtr make_data_val(broker::data d); * @param frame used to get location info upon error. * @return a Broker::DataType value. */ -zeek::EnumValPtr get_data_type(zeek::RecordVal* v, Frame* frame); +zeek::EnumValPtr get_data_type(zeek::RecordVal* v, zeek::detail::Frame* frame); /** * Convert a Bro value to a Broker data value. @@ -188,7 +188,7 @@ struct type_name_getter { * @return a reference to the wrapped Broker data value. A runtime interpreter * exception is thrown if the the optional opaque value of \a v is not set. */ -broker::data& opaque_field_to_data(zeek::RecordVal* v, Frame* f); +broker::data& opaque_field_to_data(zeek::RecordVal* v, zeek::detail::Frame* f); /** * Retrieve variant data from a Broker data value. @@ -201,7 +201,7 @@ broker::data& opaque_field_to_data(zeek::RecordVal* v, Frame* f); * is not currently stored in the Broker data. */ template -T& require_data_type(broker::data& d, zeek::TypeTag tag, Frame* f) +T& require_data_type(broker::data& d, zeek::TypeTag tag, zeek::detail::Frame* f) { auto ptr = caf::get_if(&d); if ( ! ptr ) @@ -217,7 +217,7 @@ T& require_data_type(broker::data& d, zeek::TypeTag tag, Frame* f) * @see require_data_type() and opaque_field_to_data(). */ template -inline T& require_data_type(zeek::RecordVal* v, zeek::TypeTag tag, Frame* f) +inline T& require_data_type(zeek::RecordVal* v, zeek::TypeTag tag, zeek::detail::Frame* f) { return require_data_type(opaque_field_to_data(v, f), tag, f); } @@ -227,7 +227,7 @@ inline T& require_data_type(zeek::RecordVal* v, zeek::TypeTag tag, Frame* f) class SetIterator : public zeek::OpaqueVal { public: - SetIterator(zeek::RecordVal* v, zeek::TypeTag tag, Frame* f) + SetIterator(zeek::RecordVal* v, zeek::TypeTag tag, zeek::detail::Frame* f) : zeek::OpaqueVal(bro_broker::opaque_of_set_iterator), dat(require_data_type(v, zeek::TYPE_TABLE, f)), it(dat.begin()) @@ -247,7 +247,7 @@ protected: class TableIterator : public zeek::OpaqueVal { public: - TableIterator(zeek::RecordVal* v, zeek::TypeTag tag, Frame* f) + TableIterator(zeek::RecordVal* v, zeek::TypeTag tag, zeek::detail::Frame* f) : zeek::OpaqueVal(bro_broker::opaque_of_table_iterator), dat(require_data_type(v, zeek::TYPE_TABLE, f)), it(dat.begin()) @@ -267,7 +267,7 @@ protected: class VectorIterator : public zeek::OpaqueVal { public: - VectorIterator(zeek::RecordVal* v, zeek::TypeTag tag, Frame* f) + VectorIterator(zeek::RecordVal* v, zeek::TypeTag tag, zeek::detail::Frame* f) : zeek::OpaqueVal(bro_broker::opaque_of_vector_iterator), dat(require_data_type(v, zeek::TYPE_VECTOR, f)), it(dat.begin()) @@ -287,7 +287,7 @@ protected: class RecordIterator : public zeek::OpaqueVal { public: - RecordIterator(zeek::RecordVal* v, zeek::TypeTag tag, Frame* f) + RecordIterator(zeek::RecordVal* v, zeek::TypeTag tag, zeek::detail::Frame* f) : zeek::OpaqueVal(bro_broker::opaque_of_record_iterator), dat(require_data_type(v, zeek::TYPE_RECORD, f)), it(dat.begin()) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 3b0b334206..718ebbe9c7 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -30,7 +30,7 @@ namespace bro_broker { static inline zeek::Val* get_option(const char* option) { - const auto& id = global_scope()->Find(option); + const auto& id = zeek::detail::global_scope()->Find(option); if ( ! (id && id->GetVal()) ) reporter->FatalError("Unknown Broker option %s", option); @@ -70,7 +70,7 @@ const broker::endpoint_info Manager::NoPeer{{}, {}}; int Manager::script_scope = 0; struct scoped_reporter_location { - scoped_reporter_location(Frame* frame) + scoped_reporter_location(zeek::detail::Frame* frame) { reporter->PushLocation(frame->GetCall()->GetLocationInfo()); } @@ -413,7 +413,7 @@ bool Manager::PublishIdentifier(std::string topic, std::string id) if ( peer_count == 0 ) return true; - const auto& i = global_scope()->Find(id); + const auto& i = zeek::detail::global_scope()->Find(id); if ( ! i ) return false; @@ -699,7 +699,7 @@ bool Manager::AutoUnpublishEvent(const string& topic, zeek::Val* event) return true; } -zeek::RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) +zeek::RecordVal* Manager::MakeEvent(val_list* args, zeek::detail::Frame* frame) { auto rval = new zeek::RecordVal(zeek::BifType::Record::Broker::Event); auto arg_vec = zeek::make_intrusive(vector_of_data_type); @@ -1188,7 +1188,7 @@ bool Manager::ProcessIdentifierUpdate(broker::zeek::IdentifierUpdate iu) ++statistics.num_ids_incoming; auto id_name = std::move(iu.id_name()); auto id_value = std::move(iu.id_value()); - const auto& id = global_scope()->Find(id_name); + const auto& id = zeek::detail::global_scope()->Find(id_name); if ( ! id ) { diff --git a/src/broker/Manager.h b/src/broker/Manager.h index cbc370b7f6..a274d5f3cc 100644 --- a/src/broker/Manager.h +++ b/src/broker/Manager.h @@ -21,9 +21,9 @@ #include "iosource/IOSource.h" #include "logging/WriterBackend.h" -class Frame; class Func; +ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(VectorType, zeek); namespace zeek { using VectorTypePtr = zeek::IntrusivePtr; @@ -231,7 +231,7 @@ public: * @return an `Event` record value. If an invalid event or arguments * were supplied the optional "name" field will not be set. */ - zeek::RecordVal* MakeEvent(val_list* args, Frame* frame); + zeek::RecordVal* MakeEvent(val_list* args, zeek::detail::Frame* frame); /** * Register interest in peer event messages that use a certain topic prefix. diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index 43610ae63d..1197be3422 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -48,7 +48,7 @@ std::set val_to_topic_set(zeek::Val* val) } static bool publish_event_args(val_list& args, const BroString* topic, - Frame* frame) + zeek::detail::Frame* frame) { bro_broker::Manager::ScriptScopeGuard ssg; auto rval = false; @@ -185,7 +185,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool static Func* topic_func = 0; if ( ! topic_func ) - topic_func = global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc(); + topic_func = zeek::detail::global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc(); zeek::Args vl{{zeek::NewRef{}, pool}, {zeek::NewRef{}, key}}; auto topic = topic_func->Invoke(&vl); @@ -222,7 +222,7 @@ function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool static Func* topic_func = 0; if ( ! topic_func ) - topic_func = global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc(); + topic_func = zeek::detail::global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc(); zeek::Args vl{{zeek::NewRef{}, pool}, {zeek::NewRef{}, key}}; auto topic = topic_func->Invoke(&vl); diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 56d93fcfb0..ec5c731b2b 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -27,7 +27,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) fail_on_file_problem = false; // find all option names and their types. - const auto& globals = global_scope()->Vars(); + const auto& globals = zeek::detail::global_scope()->Vars(); for ( const auto& entry : globals ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index a90e73081a..63bff0ee24 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1177,7 +1177,7 @@ WriterFrontend* Manager::CreateWriter(zeek::EnumVal* id, zeek::EnumVal* writer, if ( ! found_filter_match ) { - const auto& id = global_scope()->Find("Log::default_rotation_interval"); + const auto& id = zeek::detail::global_scope()->Find("Log::default_rotation_interval"); assert(id); winfo->interval = id->GetVal()->AsInterval(); } @@ -1520,7 +1520,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con Func* func = winfo->postprocessor; if ( ! func ) { - const auto& id = global_scope()->Find("Log::__default_rotation_postprocessor"); + const auto& id = zeek::detail::global_scope()->Find("Log::__default_rotation_postprocessor"); assert(id); func = id->GetVal()->AsFunc(); } diff --git a/src/option.bif b/src/option.bif index 03944a802c..21826e63d7 100644 --- a/src/option.bif +++ b/src/option.bif @@ -58,7 +58,7 @@ static bool call_option_handlers_and_set_value(zeek::StringVal* name, const zeek ## lower-level function. function Option::set%(ID: string, val: any, location: string &default=""%): bool %{ - const auto& i = global_scope()->Find(ID->CheckString()); + const auto& i = zeek::detail::global_scope()->Find(ID->CheckString()); if ( ! i ) { builtin_error(fmt("Could not find ID named '%s'", ID->CheckString())); @@ -143,7 +143,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool ## .. zeek:see:: Option::set function Option::set_change_handler%(ID: string, on_change: any, priority: int &default=0%): bool %{ - const auto& i = global_scope()->Find(ID->CheckString()); + const auto& i = zeek::detail::global_scope()->Find(ID->CheckString()); if ( ! i ) { builtin_error(fmt("Could not find ID named '%s'", ID->CheckString())); diff --git a/src/parse.y b/src/parse.y index 760d7de9be..50622976ed 100644 --- a/src/parse.y +++ b/src/parse.y @@ -113,7 +113,9 @@ extern int brolex(); * Part of the module facility: while parsing, keep track of which * module to put things in. */ -std::string current_module = GLOBAL_MODULE_NAME; +std::string zeek::detail::current_module = GLOBAL_MODULE_NAME; +std::string& current_module = zeek::detail::current_module; + bool is_export = false; // true if in an export {} block /* @@ -494,9 +496,9 @@ expr: | '$' TOK_ID func_params '=' { func_hdr_location = @1; - auto func_id = current_scope()->GenerateTemporary("anonymous-function"); + auto func_id = zeek::detail::current_scope()->GenerateTemporary("anonymous-function"); func_id->SetInferReturnType(true); - begin_func(std::move(func_id), current_module.c_str(), + begin_func(std::move(func_id), zeek::detail::current_module.c_str(), zeek::FUNC_FLAVOR_FUNCTION, false, {zeek::AdoptRef{}, $3}); } @@ -657,15 +659,15 @@ expr: | TOK_ID { set_location(@1); - auto id = lookup_ID($1, current_module.c_str()); + auto id = zeek::detail::lookup_ID($1, zeek::detail::current_module.c_str()); if ( ! id ) { if ( ! in_debug ) { /* // CHECK THAT THIS IS NOT GLOBAL. - id = install_ID($1, current_module.c_str(), - false, is_export); + id = install_ID($1, zeek::detail::current_module.c_str(), + false, is_export); */ yyerror(fmt("unknown identifier %s", $1)); @@ -803,7 +805,7 @@ enum_body_elem: if ( $3->GetType()->Tag() != zeek::TYPE_COUNT ) reporter->Error("enumerator is not a count constant"); else - cur_enum_type->AddName(current_module, $1, + cur_enum_type->AddName(zeek::detail::current_module, $1, $3->InternalUnsigned(), is_export, $4); } @@ -820,7 +822,7 @@ enum_body_elem: { set_location(@1); assert(cur_enum_type); - cur_enum_type->AddName(current_module, $1, is_export, $2); + cur_enum_type->AddName(zeek::detail::current_module, $1, is_export, $2); } ; @@ -1071,8 +1073,8 @@ formal_args_decl: decl: TOK_MODULE TOK_ID ';' { - current_module = $2; - zeekygen_mgr->ModuleUsage(::filename, current_module); + zeek::detail::current_module = $2; + zeekygen_mgr->ModuleUsage(::filename, zeek::detail::current_module); } | TOK_EXPORT '{' { is_export = true; } decl_list '}' @@ -1178,7 +1180,7 @@ func_hdr: TOK_FUNCTION def_global_id func_params opt_attr { zeek::IntrusivePtr id{zeek::AdoptRef{}, $2}; - begin_func(id, current_module.c_str(), + begin_func(id, zeek::detail::current_module.c_str(), zeek::FUNC_FLAVOR_FUNCTION, 0, {zeek::NewRef{}, $3}, std::unique_ptr>{$4}); $$ = $3; @@ -1193,7 +1195,7 @@ func_hdr: reporter->Error("event %s() is no longer available, use zeek_%s() instead", name, base.c_str()); } - begin_func({zeek::NewRef{}, $2}, current_module.c_str(), + begin_func({zeek::NewRef{}, $2}, zeek::detail::current_module.c_str(), zeek::FUNC_FLAVOR_EVENT, 0, {zeek::NewRef{}, $3}, std::unique_ptr>{$4}); $$ = $3; @@ -1202,14 +1204,14 @@ func_hdr: { $3->ClearYieldType(zeek::FUNC_FLAVOR_HOOK); $3->SetYieldType(zeek::base_type(zeek::TYPE_BOOL)); - begin_func({zeek::NewRef{}, $2}, current_module.c_str(), + begin_func({zeek::NewRef{}, $2}, zeek::detail::current_module.c_str(), zeek::FUNC_FLAVOR_HOOK, 0, {zeek::NewRef{}, $3}, std::unique_ptr>{$4}); $$ = $3; } | TOK_REDEF TOK_EVENT event_id func_params opt_attr { - begin_func({zeek::NewRef{}, $3}, current_module.c_str(), + begin_func({zeek::NewRef{}, $3}, zeek::detail::current_module.c_str(), zeek::FUNC_FLAVOR_EVENT, 1, {zeek::NewRef{}, $4}, std::unique_ptr>{$5}); $$ = $4; @@ -1258,8 +1260,8 @@ lambda_body: // a lambda expression. // Gather the ingredients for a BroFunc from the current scope - auto ingredients = std::make_unique(zeek::IntrusivePtr{zeek::NewRef{}, current_scope()}, zeek::IntrusivePtr{zeek::AdoptRef{}, $3}); - id_list outer_ids = gather_outer_ids(pop_scope().get(), ingredients->body.get()); + auto ingredients = std::make_unique(zeek::IntrusivePtr{zeek::NewRef{}, zeek::detail::current_scope()}, zeek::IntrusivePtr{zeek::AdoptRef{}, $3}); + id_list outer_ids = gather_outer_ids(zeek::detail::pop_scope().get(), ingredients->body.get()); $$ = new zeek::detail::LambdaExpr(std::move(ingredients), std::move(outer_ids)); } @@ -1273,8 +1275,8 @@ anonymous_function: begin_func: func_params { - auto id = current_scope()->GenerateTemporary("anonymous-function"); - begin_func(id, current_module.c_str(), zeek::FUNC_FLAVOR_FUNCTION, 0, {zeek::AdoptRef{}, $1}); + auto id = zeek::detail::current_scope()->GenerateTemporary("anonymous-function"); + begin_func(id, zeek::detail::current_module.c_str(), zeek::FUNC_FLAVOR_FUNCTION, 0, {zeek::AdoptRef{}, $1}); $$ = id.release(); } ; @@ -1609,7 +1611,7 @@ event: TOK_ID '(' opt_expr_list ')' { set_location(@1, @4); - const auto& id = lookup_ID($1, current_module.c_str()); + const auto& id = zeek::detail::lookup_ID($1, zeek::detail::current_module.c_str()); if ( id ) { @@ -1667,12 +1669,12 @@ case_type: { const char* name = $4; zeek::TypePtr type{zeek::AdoptRef{}, $2}; - auto case_var = lookup_ID(name, current_module.c_str()); + auto case_var = zeek::detail::lookup_ID(name, zeek::detail::current_module.c_str()); if ( case_var && case_var->IsGlobal() ) case_var->Error("already a global identifier"); else - case_var = install_ID(name, current_module.c_str(), false, false); + case_var = zeek::detail::install_ID(name, zeek::detail::current_module.c_str(), false, false); add_local(case_var, std::move(type), zeek::detail::INIT_NONE, nullptr, nullptr, VAR_REGULAR); @@ -1688,7 +1690,7 @@ for_head: // body so that we execute these actions - defining // the local variable - prior to parsing the body, // which might refer to the variable. - auto loop_var = lookup_ID($3, current_module.c_str()); + auto loop_var = zeek::detail::lookup_ID($3, zeek::detail::current_module.c_str()); if ( loop_var ) { @@ -1698,8 +1700,8 @@ for_head: else { - loop_var = install_ID($3, current_module.c_str(), - false, false); + loop_var = zeek::detail::install_ID($3, zeek::detail::current_module.c_str(), + false, false); } id_list* loop_vars = new id_list; @@ -1716,12 +1718,12 @@ for_head: TOK_FOR '(' TOK_ID ',' TOK_ID TOK_IN expr ')' { set_location(@1, @8); - const char* module = current_module.c_str(); + const char* module = zeek::detail::current_module.c_str(); // Check for previous definitions of key and // value variables. - auto key_var = lookup_ID($3, module); - auto val_var = lookup_ID($5, module); + auto key_var = zeek::detail::lookup_ID($3, module); + auto val_var = zeek::detail::lookup_ID($5, module); // Validate previous definitions as needed. if ( key_var ) @@ -1730,7 +1732,7 @@ for_head: key_var->Error("global variable used in for loop"); } else - key_var = install_ID($3, module, false, false); + key_var = zeek::detail::install_ID($3, module, false, false); if ( val_var ) { @@ -1738,7 +1740,7 @@ for_head: val_var->Error("global variable used in for loop"); } else - val_var = install_ID($5, module, false, false); + val_var = zeek::detail::install_ID($5, module, false, false); id_list* loop_vars = new id_list; loop_vars->push_back(key_var.release()); @@ -1749,10 +1751,10 @@ for_head: TOK_FOR '(' '[' local_id_list ']' ',' TOK_ID TOK_IN expr ')' { set_location(@1, @10); - const char* module = current_module.c_str(); + const char* module = zeek::detail::current_module.c_str(); // Validate value variable - auto val_var = lookup_ID($7, module); + auto val_var = zeek::detail::lookup_ID($7, module); if ( val_var ) { @@ -1760,7 +1762,7 @@ for_head: val_var->Error("global variable used in for loop"); } else - val_var = install_ID($7, module, false, false); + val_var = zeek::detail::install_ID($7, module, false, false); $$ = new zeek::detail::ForStmt($4, {zeek::AdoptRef{}, $9}, std::move(val_var)); } @@ -1780,7 +1782,7 @@ local_id: TOK_ID { set_location(@1); - auto id = lookup_ID($1, current_module.c_str()); + auto id = zeek::detail::lookup_ID($1, zeek::detail::current_module.c_str()); $$ = id.release(); if ( $$ ) @@ -1792,8 +1794,8 @@ local_id: else { - $$ = install_ID($1, current_module.c_str(), - false, is_export).release(); + $$ = zeek::detail::install_ID($1, zeek::detail::current_module.c_str(), + false, is_export).release(); } } ; @@ -1817,7 +1819,7 @@ global_or_event_id: TOK_ID { set_location(@1); - auto id = lookup_ID($1, current_module.c_str(), false, + auto id = zeek::detail::lookup_ID($1, zeek::detail::current_module.c_str(), false, defining_global_ID); $$ = id.release(); @@ -1842,10 +1844,10 @@ global_or_event_id: { const char* module_name = resolving_global_ID ? - current_module.c_str() : 0; + zeek::detail::current_module.c_str() : 0; - $$ = install_ID($1, module_name, - true, is_export).release(); + $$ = zeek::detail::install_ID($1, module_name, + true, is_export).release(); } } ; @@ -1855,7 +1857,7 @@ resolve_id: TOK_ID { set_location(@1); - auto id = lookup_ID($1, current_module.c_str()); + auto id = zeek::detail::lookup_ID($1, zeek::detail::current_module.c_str()); $$ = id.release(); if ( ! $$ ) diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index a47e557e24..7d4d43533d 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -138,7 +138,7 @@ ComponentManager::ComponentManager(const std::string& arg_module, const st : module(arg_module), tag_enum_type(zeek::make_intrusive(module + "::" + local_id)) { - auto id = install_ID(local_id.c_str(), module.c_str(), true, true); + auto id = zeek::detail::install_ID(local_id.c_str(), module.c_str(), true, true); add_type(id.get(), tag_enum_type, nullptr); zeekygen_mgr->Identifier(std::move(id)); } diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 5d91efe4de..bf8d4d1c46 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -617,7 +617,7 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const } std::pair -Manager::HookCallFunction(const Func* func, Frame* parent, +Manager::HookCallFunction(const Func* func, zeek::detail::Frame* parent, zeek::Args* vecargs) const { HookArgumentList args; diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index 9e74e911ac..cf700d5e14 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -256,7 +256,7 @@ public: * the method returns null. */ std::pair - HookCallFunction(const Func* func, Frame* parent, zeek::Args* args) const; + HookCallFunction(const Func* func, zeek::detail::Frame* parent, zeek::Args* args) const; /** * Hook that filters the queuing of an event. diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index 179d2c7bbc..3af8a94688 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -376,7 +376,7 @@ int Plugin::HookLoadFile(const LoadType type, const std::string& file, const std } std::pair -Plugin::HookFunctionCall(const Func* func, Frame* parent, +Plugin::HookFunctionCall(const Func* func, zeek::detail::Frame* parent, zeek::Args* args) { val_list vlargs(args->size()); @@ -395,7 +395,8 @@ Plugin::HookFunctionCall(const Func* func, Frame* parent, return {handled, {zeek::AdoptRef{}, result}}; } -std::pair Plugin::HookCallFunction(const Func* func, Frame *parent, val_list* args) +std::pair Plugin::HookCallFunction( + const Func* func, zeek::detail::Frame *parent, val_list* args) { std::pair result(false, NULL); return result; diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index e2f687e254..9dc25fa483 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -17,10 +17,11 @@ #define BRO_PLUGIN_BRO_VERSION BRO_VERSION_FUNCTION class ODesc; -class Frame; class Func; class Event; +ZEEK_FORWARD_DECLARE_NAMESPACED(Frame, zeek::detail); + namespace zeek { template class IntrusivePtr; using ValPtr = zeek::IntrusivePtr; @@ -235,7 +236,7 @@ public: /** * Constructor with a Frame argument. */ - explicit HookArgument(Frame* f) { type = FRAME; arg.frame = f; } + explicit HookArgument(zeek::detail::Frame* f) { type = FRAME; arg.frame = f; } /** * Constructor with a WriterInfo argument. @@ -315,7 +316,7 @@ public: * Returns the value for a Bro frame argument. The argument's type must * match accordingly. */ - const Frame* AsFrame() const { assert(type == FRAME); return arg.frame; } + const zeek::detail::Frame* AsFrame() const { assert(type == FRAME); return arg.frame; } /** * Returns the value for a logging WriterInfo argument. The argument's type must @@ -366,7 +367,7 @@ private: const Event* event; const Connection* conn; const Func* func; - const Frame* frame; + const zeek::detail::Frame* frame; int int_; const Val* val; const val_list* vals; @@ -673,10 +674,10 @@ protected: * pair with the first member set to 'false' and null result value. */ virtual std::pair - HookFunctionCall(const Func* func, Frame* parent, zeek::Args* args); + HookFunctionCall(const Func* func, zeek::detail::Frame* parent, zeek::Args* args); [[deprecated("Remove in v4.1. Use HookFunctionCall()")]] - virtual std::pair HookCallFunction(const Func* func, Frame *parent, val_list* args); + virtual std::pair HookCallFunction(const Func* func, zeek::detail::Frame *parent, val_list* args); /** * Hook into raising events. Whenever the script interpreter is about diff --git a/src/scan.l b/src/scan.l index 63a2c2bfb5..2aa9e16090 100644 --- a/src/scan.l +++ b/src/scan.l @@ -179,7 +179,7 @@ ESCSEQ (\\([^\n]|[0-7]+|x[[:xdigit:]]+)) ##<.* { std::string hint(cur_enum_type && last_id_tok ? - make_full_var_name(current_module.c_str(), last_id_tok) : ""); + make_full_var_name(zeek::detail::current_module.c_str(), last_id_tok) : ""); zeekygen_mgr->PostComment(yytext + 3, hint); } @@ -693,7 +693,7 @@ static int load_files(const char* orig_file) // was done when we're finished processing it. if ( ! did_module_restore ) { - file_stack.push_back(new FileInfo(current_module)); + file_stack.push_back(new FileInfo(zeek::detail::current_module)); did_module_restore = true; } else @@ -776,7 +776,7 @@ void do_atifdef(const char* id) { ++current_depth; - const auto& i = lookup_ID(id, current_module.c_str()); + const auto& i = zeek::detail::lookup_ID(id, zeek::detail::current_module.c_str()); if ( ! i ) { @@ -789,7 +789,7 @@ void do_atifndef(const char *id) { ++current_depth; - const auto& i = lookup_ID(id, current_module.c_str()); + const auto& i = zeek::detail::lookup_ID(id, zeek::detail::current_module.c_str()); if ( i ) { @@ -1077,5 +1077,5 @@ FileInfo::~FileInfo() yylloc.first_line = yylloc.last_line = line_number = line; if ( restore_module != "" ) - current_module = restore_module; + zeek::detail::current_module = restore_module; } diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index 1c2cb36b3e..eee61b5312 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -542,7 +542,7 @@ zeek::Val* Value::ValueToVal(const std::string& source, const Value* val, bool& // Enums are not a base-type, so need to look it up. const auto& sv = val->val.set_val.vals[0]->val.string_val; std::string enum_name(sv.data, sv.length); - const auto& enum_id = global_scope()->Find(enum_name); + const auto& enum_id = zeek::detail::global_scope()->Find(enum_name); if ( ! enum_id ) { @@ -607,7 +607,7 @@ zeek::Val* Value::ValueToVal(const std::string& source, const Value* val, bool& std::string enum_string(val->val.string_val.data, val->val.string_val.length); // let's try looking it up by global ID. - const auto& id = lookup_ID(enum_string.c_str(), GLOBAL_MODULE_NAME); + const auto& id = zeek::detail::lookup_ID(enum_string.c_str(), GLOBAL_MODULE_NAME); if ( ! id || ! id->IsEnumConst() ) { diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 36120688bb..3eb5f7b122 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -311,7 +311,7 @@ void terminate_bro() delete val_mgr; // free the global scope - pop_scope(); + zeek::detail::pop_scope(); reporter = nullptr; } diff --git a/src/zeek.bif b/src/zeek.bif index f1e3dadb0f..78784c66f6 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1914,7 +1914,7 @@ function packet_source%(%): PacketSource function global_sizes%(%): var_sizes %{ auto sizes = zeek::make_intrusive(IntrusivePtr{zeek::NewRef{}, var_sizes}); - const auto& globals = global_scope()->Vars(); + const auto& globals = zeek::detail::global_scope()->Vars(); for ( const auto& global : globals ) { @@ -1942,7 +1942,7 @@ function global_ids%(%): id_table %{ static auto id_table = zeek::id::find_type("id_table"); auto ids = zeek::make_intrusive(id_table); - const auto& globals = global_scope()->Vars(); + const auto& globals = zeek::detail::global_scope()->Vars(); for ( const auto& global : globals ) { @@ -1974,7 +1974,7 @@ function global_ids%(%): id_table ## the string ``""`` or ``""`` is returned. function lookup_ID%(id: string%) : any %{ - const auto& i = global_scope()->Find(id->CheckString()); + const auto& i = zeek::detail::global_scope()->Find(id->CheckString()); if ( ! i ) return zeek::make_intrusive(""); @@ -1997,7 +1997,7 @@ function record_fields%(rec: any%): record_field_table if ( rec->GetType()->Tag() == zeek::TYPE_STRING ) { - const auto& id = global_scope()->Find(rec->AsStringVal()->ToStdString()); + const auto& id = zeek::detail::global_scope()->Find(rec->AsStringVal()->ToStdString()); if ( ! id || ! id->IsType() || id->GetType()->Tag() != zeek::TYPE_RECORD ) { @@ -3905,7 +3905,7 @@ static zeek::ValPtr mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, static bool mmdb_try_open_loc () { // City database is always preferred over Country database. - const auto& mmdb_dir_val = global_scope()->Find("mmdb_dir")->GetVal(); + const auto& mmdb_dir_val = zeek::detail::global_scope()->Find("mmdb_dir")->GetVal(); std::string mmdb_dir = mmdb_dir_val->AsString()->CheckString(); if ( ! mmdb_dir.empty() ) @@ -3933,7 +3933,7 @@ static bool mmdb_try_open_loc () static bool mmdb_try_open_asn () { - const auto& mmdb_dir_val = global_scope()->Find("mmdb_dir")->GetVal(); + const auto& mmdb_dir_val = zeek::detail::global_scope()->Find("mmdb_dir")->GetVal(); std::string mmdb_dir = mmdb_dir_val->AsString()->CheckString(); if ( ! mmdb_dir.empty() ) diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index 0bbd64ad66..9f16010fbc 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -258,12 +258,12 @@ void ScriptInfo::DoInitPostScript() // so just manually associating them with scripts for now. if ( name == "base/frameworks/input/main.zeek" ) { - const auto& id = global_scope()->Find("Input::Reader"); + const auto& id = zeek::detail::global_scope()->Find("Input::Reader"); types.push_back(new IdentifierInfo(id, this)); } else if ( name == "base/frameworks/logging/main.zeek" ) { - const auto& id = global_scope()->Find("Log::Writer"); + const auto& id = zeek::detail::global_scope()->Find("Log::Writer"); types.push_back(new IdentifierInfo(id, this)); } }