diff --git a/src/BroList.h b/src/BroList.h index 57b1fba2af..fa30fa663f 100644 --- a/src/BroList.h +++ b/src/BroList.h @@ -7,8 +7,8 @@ FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); typedef PList expr_list; -class ID; -typedef PList id_list; +FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); +typedef PList id_list; class Val; typedef PList val_list; diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index 93e1ef9f0e..3cc5baa7f8 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -30,13 +30,13 @@ using namespace std; // // Helper routines // -bool string_is_regex(const string& s) +static bool string_is_regex(const string& s) { return strpbrk(s.data(), "?*\\+"); } -void lookup_global_symbols_regex(const string& orig_regex, vector& matches, - bool func_only = false) +static void lookup_global_symbols_regex(const string& orig_regex, vector& matches, + bool func_only = false) { if ( streq(orig_regex.c_str(), "") ) return; @@ -61,18 +61,18 @@ void lookup_global_symbols_regex(const string& orig_regex, vector& matches, Scope* global = global_scope(); const auto& syms = global->Vars(); - ID* nextid; + zeek::detail::ID* nextid; for ( const auto& sym : syms ) { - ID* nextid = sym.second.get(); + zeek::detail::ID* nextid = sym.second.get(); if ( ! func_only || nextid->GetType()->Tag() == TYPE_FUNC ) if ( ! regexec (&re, nextid->Name(), 0, 0, 0) ) matches.push_back(nextid); } } -void choose_global_symbols_regex(const string& regex, vector& choices, - bool func_only = false) +static void choose_global_symbols_regex(const string& regex, vector& choices, + bool func_only = false) { lookup_global_symbols_regex(regex, choices, func_only); @@ -111,7 +111,7 @@ void choose_global_symbols_regex(const string& regex, vector& choices, int option = atoi(input.c_str()); if ( option > 0 && option <= (int) choices.size() ) { - ID* choice = choices[option - 1]; + zeek::detail::ID* choice = choices[option - 1]; choices.clear(); choices.push_back(choice); return; @@ -398,7 +398,7 @@ int dbg_cmd_break(DebugCmd cmd, const vector& args) vector locstrings; if ( string_is_regex(args[0]) ) { - vector choices; + vector choices; choose_global_symbols_regex(args[0], choices, true); for ( unsigned int i = 0; i < choices.size(); ++i ) locstrings.push_back(choices[i]->Name()); diff --git a/src/Frame.cc b/src/Frame.cc index 7c1470d2dc..628bfc5715 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -77,7 +77,7 @@ void Frame::SetElementWeak(int n, Val* v) frame[n] = {{AdoptRef{}, v}, true}; } -void Frame::SetElement(const ID* id, IntrusivePtr v) +void Frame::SetElement(const zeek::detail::ID* id, IntrusivePtr v) { if ( closure ) { @@ -106,7 +106,7 @@ void Frame::SetElement(const ID* id, IntrusivePtr v) SetElement(id->Offset(), std::move(v)); } -const IntrusivePtr& Frame::GetElementByID(const ID* id) const +const IntrusivePtr& Frame::GetElementByID(const zeek::detail::ID* id) const { if ( closure ) { @@ -478,7 +478,7 @@ void Frame::AddKnownOffsets(const id_list& ids) offset_map = std::make_unique(); std::transform(ids.begin(), ids.end(), std::inserter(*offset_map, offset_map->end()), - [] (const ID* id) -> std::pair + [] (const zeek::detail::ID* id) -> std::pair { return std::make_pair(std::string(id->Name()), id->Offset()); }); @@ -523,10 +523,10 @@ void Frame::ClearElement(int n) frame[n] = {nullptr, false}; } -bool Frame::IsOuterID(const ID* in) const +bool Frame::IsOuterID(const zeek::detail::ID* in) const { return std::any_of(outer_ids.begin(), outer_ids.end(), - [&in](ID* id)-> bool { return strcmp(id->Name(), in->Name()) == 0; }); + [&in](zeek::detail::ID* id)-> bool { return strcmp(id->Name(), in->Name()) == 0; }); } broker::expected Frame::SerializeIDList(const id_list& in) @@ -588,7 +588,7 @@ Frame::UnserializeIDList(const broker::vector& data) return std::make_pair(false, std::move(rval)); } - ID* id = new ID(has_name->c_str(), SCOPE_FUNCTION, false); + auto* id = new zeek::detail::ID(has_name->c_str(), zeek::detail::SCOPE_FUNCTION, false); id->SetOffset(*has_offset); rval.push_back(id); std::advance(where, 1); diff --git a/src/Frame.h b/src/Frame.h index d7a1a26a28..65dff91eb8 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -66,8 +66,8 @@ public: * @param id the ID to associate * @param v the value to associate it with */ - void SetElement(const ID* id, IntrusivePtr v); - void SetElement(const IntrusivePtr& id, IntrusivePtr v) + void SetElement(const zeek::detail::ID* id, IntrusivePtr v); + void SetElement(const IntrusivePtr& id, IntrusivePtr v) { SetElement(id.get(), std::move(v)); } /** @@ -77,11 +77,11 @@ public: * @param id the id who's value to retreive * @return the value associated with *id* */ - const IntrusivePtr& GetElementByID(const IntrusivePtr& id) const + const IntrusivePtr& GetElementByID(const IntrusivePtr& id) const { return GetElementByID(id.get()); } [[deprecated("Remove in v4.1. Use GetElementByID().")]] - Val* GetElement(const ID* id) const + Val* GetElement(const zeek::detail::ID* id) const { return GetElementByID(id).get(); } /** @@ -247,7 +247,7 @@ private: bool weak_ref; }; - const IntrusivePtr& GetElementByID(const ID* id) const; + const IntrusivePtr& GetElementByID(const zeek::detail::ID* id) const; /** * Sets the element at index *n* of the underlying array to *v*, but does @@ -273,7 +273,7 @@ private: void ClearElement(int n); /** Have we captured this id? */ - bool IsOuterID(const ID* in) const; + bool IsOuterID(const zeek::detail::ID* in) const; /** Serializes an offset_map */ static broker::expected diff --git a/src/Func.cc b/src/Func.cc index ad1c7b03b9..c2a498ceb5 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -122,7 +122,7 @@ Func::Func(Kind arg_kind) : kind(arg_kind) Func::~Func() = default; void Func::AddBody(IntrusivePtr /* new_body */, - const std::vector>& /* new_inits */, + const std::vector>& /* new_inits */, size_t /* new_frame_size */, int /* priority */) { Internal("Func::AddBody called"); @@ -268,8 +268,8 @@ void Func::CheckPluginResult(bool handled, const IntrusivePtr& hook_result, } } -BroFunc::BroFunc(const IntrusivePtr& arg_id, IntrusivePtr arg_body, - const std::vector>& aggr_inits, +BroFunc::BroFunc(const IntrusivePtr& arg_id, IntrusivePtr arg_body, + const std::vector>& aggr_inits, size_t arg_frame_size, int priority) : Func(BRO_FUNC) { @@ -450,7 +450,7 @@ IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const } void BroFunc::AddBody(IntrusivePtr new_body, - const std::vector>& new_inits, + const std::vector>& new_inits, size_t new_frame_size, int priority) { if ( new_frame_size > frame_size ) @@ -575,7 +575,7 @@ void BroFunc::Describe(ODesc* d) const } IntrusivePtr BroFunc::AddInits(IntrusivePtr body, - const std::vector>& inits) + const std::vector>& inits) { if ( inits.empty() ) return body; diff --git a/src/Func.h b/src/Func.h index 6dbe12edac..b1b653ddc4 100644 --- a/src/Func.h +++ b/src/Func.h @@ -22,11 +22,11 @@ class Val; class FuncType; class Frame; -class ID; class Scope; FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); +FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); class Func : public BroObj { public: @@ -79,7 +79,7 @@ public: // Add a new event handler to an existing function (event). virtual void AddBody(IntrusivePtr new_body, - const std::vector>& new_inits, + const std::vector>& new_inits, size_t new_frame_size, int priority = 0); virtual void SetScope(IntrusivePtr newscope); @@ -129,8 +129,8 @@ protected: class BroFunc final : public Func { public: - BroFunc(const IntrusivePtr& id, IntrusivePtr body, - const std::vector>& inits, + BroFunc(const IntrusivePtr& id, IntrusivePtr body, + const std::vector>& inits, size_t frame_size, int priority); ~BroFunc() override; @@ -168,7 +168,7 @@ public: broker::expected SerializeClosure() const; void AddBody(IntrusivePtr new_body, - const std::vector>& new_inits, + const std::vector>& new_inits, size_t new_frame_size, int priority) override; /** Sets this function's outer_id list. */ @@ -179,8 +179,9 @@ public: protected: BroFunc() : Func(BRO_FUNC) {} - IntrusivePtr AddInits(IntrusivePtr body, - const std::vector>& inits); + IntrusivePtr AddInits( + IntrusivePtr body, + const std::vector>& inits); /** * Clones this function along with its closures. @@ -269,9 +270,9 @@ struct function_ingredients { // to build a function. function_ingredients(IntrusivePtr scope, IntrusivePtr body); - IntrusivePtr id; + IntrusivePtr id; IntrusivePtr body; - std::vector> inits; + std::vector> inits; int frame_size; int priority; IntrusivePtr scope; diff --git a/src/ID.cc b/src/ID.cc index b21200155d..73bd2b50cb 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -31,7 +31,7 @@ IntrusivePtr zeek::id::count_set; IntrusivePtr zeek::id::string_vec; IntrusivePtr zeek::id::index_vec; -const IntrusivePtr& zeek::id::find(std::string_view name) +const IntrusivePtr& zeek::id::find(std::string_view name) { return global_scope()->Find(name); } @@ -102,6 +102,8 @@ void zeek::id::detail::init() index_vec = zeek::id::find_type("index_vec"); } +namespace zeek::detail { + ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) { name = copy_string(arg_name); @@ -118,6 +120,9 @@ ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) SetLocationInfo(&start_location, &end_location); } +ID::ID(const char* arg_name, ::IDScope arg_scope, bool arg_is_export) : + ID(arg_name, static_cast(arg_scope), arg_is_export) {} + ID::~ID() { delete [] name; @@ -205,7 +210,7 @@ void ID::SetVal(IntrusivePtr v, init_class c) } } -void ID::SetVal(IntrusivePtr ev, init_class c) +void ID::SetVal(IntrusivePtr ev, init_class c) { const auto& a = attrs->Find(c == INIT_EXTRA ? ATTR_ADD_FUNC : ATTR_DEL_FUNC); @@ -215,6 +220,16 @@ void ID::SetVal(IntrusivePtr ev, init_class c) EvalFunc(a->GetExpr(), std::move(ev)); } +void ID::SetVal(IntrusivePtr v, ::init_class c) + { + SetVal(v, static_cast(c)); + } + +void ID::SetVal(IntrusivePtr ev, ::init_class c) + { + SetVal(ev, static_cast(c)); + } + bool ID::IsRedefinable() const { return GetAttr(ATTR_REDEF) != nullptr; @@ -276,7 +291,7 @@ bool ID::IsDeprecated() const return GetAttr(ATTR_DEPRECATED) != nullptr; } -void ID::MakeDeprecated(IntrusivePtr deprecation) +void ID::MakeDeprecated(IntrusivePtr deprecation) { if ( IsDeprecated() ) return; @@ -337,13 +352,13 @@ void ID::SetOption() } } -void ID::EvalFunc(IntrusivePtr ef, IntrusivePtr ev) +void ID::EvalFunc(IntrusivePtr ef, IntrusivePtr ev) { auto arg1 = make_intrusive(val); auto args = make_intrusive(); args->Append(std::move(arg1)); args->Append(std::move(ev)); - auto ce = make_intrusive(std::move(ef), std::move(args)); + auto ce = make_intrusive(std::move(ef), std::move(args)); SetVal(ce->Eval(nullptr)); } @@ -655,3 +670,5 @@ std::vector ID::GetOptionHandlers() const v.push_back(element.second.get()); return v; } + +} diff --git a/src/ID.h b/src/ID.h index ad11c5bf9b..5da63d9a29 100644 --- a/src/ID.h +++ b/src/ID.h @@ -22,16 +22,25 @@ class VectorType; class EnumType; class Attributes; -FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +enum [[deprecated("Remove in v4.1. Use zeek::detail::init_class instead.")]] init_class { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, }; +enum [[deprecated("Remove in v4.1. Use zeek::detail::IDScope instead.")]] IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL }; -typedef enum { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, } init_class; -typedef enum { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL } IDScope; +namespace zeek::detail { + +class Expr; + +enum init_class { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, }; +enum IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL }; class ID final : public BroObj, public notifier::Modifiable { public: static inline const IntrusivePtr nil; ID(const char* name, IDScope arg_scope, bool arg_is_export); + + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::IDScope")]] + ID(const char* name, ::IDScope arg_scope, bool arg_is_export); + ~ID() override; const char* Name() const { return name; } @@ -71,7 +80,12 @@ public: void SetVal(IntrusivePtr v); void SetVal(IntrusivePtr v, init_class c); - void SetVal(IntrusivePtr ev, init_class c); + void SetVal(IntrusivePtr ev, init_class c); + + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::init_class")]] + void SetVal(IntrusivePtr v, ::init_class c); + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::init_class")]] + void SetVal(IntrusivePtr ev, ::init_class c); bool HasVal() const { return val != nullptr; } @@ -118,7 +132,7 @@ public: bool IsDeprecated() const; - void MakeDeprecated(IntrusivePtr deprecation); + void MakeDeprecated(IntrusivePtr deprecation); std::string GetDeprecationWarning() const; @@ -145,7 +159,7 @@ public: std::vector GetOptionHandlers() const; protected: - void EvalFunc(IntrusivePtr ef, IntrusivePtr ev); + void EvalFunc(IntrusivePtr ef, IntrusivePtr ev); #ifdef DEBUG void UpdateValID(); @@ -165,6 +179,10 @@ protected: }; +} + +using ID [[deprecated("Remove in v4.1. Use zeek::detail::ID instead.")]] = zeek::detail::ID; + namespace zeek::id { /** @@ -173,7 +191,7 @@ namespace zeek::id { * @return The identifier, which may reference a nil object if no such * name exists. */ -const IntrusivePtr& find(std::string_view name); +const IntrusivePtr& find(std::string_view name); /** * Lookup an ID by its name and return its type. A fatal occurs if the ID diff --git a/src/RuleCondition.h b/src/RuleCondition.h index d8f0b684b2..33fa4d6ccc 100644 --- a/src/RuleCondition.h +++ b/src/RuleCondition.h @@ -2,11 +2,13 @@ #include // for u_char #include // for u_char +#include "util.h" -class ID; class Rule; class RuleEndpointState; +FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); + // Base class for all rule conditions except patterns and "header". class RuleCondition { public: @@ -111,7 +113,5 @@ public: void PrintDebug() override; private: - ID* id; + zeek::detail::ID* id; }; - - diff --git a/src/Scope.cc b/src/Scope.cc index 657a27170e..008c43ff54 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -15,7 +15,7 @@ typedef PList scope_list; static scope_list scopes; static Scope* top_scope; -Scope::Scope(IntrusivePtr id, +Scope::Scope(IntrusivePtr id, std::unique_ptr>> al) : scope_id(std::move(id)), attrs(std::move(al)) { @@ -35,17 +35,17 @@ Scope::Scope(IntrusivePtr id, } } -const IntrusivePtr& Scope::Find(std::string_view name) const +const IntrusivePtr& Scope::Find(std::string_view name) const { auto entry = local.find(name); if ( entry != local.end() ) return entry->second; - return ID::nil; + return zeek::detail::ID::nil; } -IntrusivePtr Scope::Remove(std::string_view name) +IntrusivePtr Scope::Remove(std::string_view name) { auto entry = local.find(name); @@ -59,12 +59,12 @@ IntrusivePtr Scope::Remove(std::string_view name) return nullptr; } -IntrusivePtr Scope::GenerateTemporary(const char* name) +IntrusivePtr Scope::GenerateTemporary(const char* name) { - return make_intrusive(name, SCOPE_FUNCTION, false); + return make_intrusive(name, zeek::detail::SCOPE_FUNCTION, false); } -std::vector> Scope::GetInits() +std::vector> Scope::GetInits() { auto rval = std::move(inits); inits = {}; @@ -100,7 +100,7 @@ void Scope::Describe(ODesc* d) const for ( const auto& entry : local ) { - ID* id = entry.second.get(); + zeek::detail::ID* id = entry.second.get(); id->Describe(d); d->NL(); } @@ -110,7 +110,7 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const { for ( const auto& entry : local ) { - ID* id = entry.second.get(); + zeek::detail::ID* id = entry.second.get(); TraversalCode tc = id->Traverse(cb); HANDLE_TC_STMT_PRE(tc); } @@ -119,9 +119,9 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const } -const IntrusivePtr& lookup_ID(const char* name, const char* curr_module, - bool no_global, bool same_module_only, - bool check_export) +const IntrusivePtr& 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); @@ -150,30 +150,30 @@ const IntrusivePtr& lookup_ID(const char* name, const char* curr_module, return global_scope()->Find(globalname); } - return ID::nil; + return zeek::detail::ID::nil; } -IntrusivePtr install_ID(const char* name, const char* module_name, +IntrusivePtr 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"); - IDScope scope; + zeek::detail::IDScope scope; if ( is_export || ! module_name || (is_global && normalized_module_name(module_name) == GLOBAL_MODULE_NAME) ) - scope = SCOPE_GLOBAL; + scope = zeek::detail::SCOPE_GLOBAL; else if ( is_global ) - scope = SCOPE_MODULE; + scope = zeek::detail::SCOPE_MODULE; else - scope = SCOPE_FUNCTION; + scope = zeek::detail::SCOPE_FUNCTION; std::string full_name = make_full_var_name(module_name, name); - auto id = make_intrusive(full_name.data(), scope, is_export); + auto id = make_intrusive(full_name.data(), scope, is_export); - if ( SCOPE_FUNCTION != scope ) + if ( zeek::detail::SCOPE_FUNCTION != scope ) global_scope()->Insert(std::move(full_name), id); else { @@ -189,7 +189,7 @@ void push_existing_scope(Scope* scope) scopes.push_back(scope); } -void push_scope(IntrusivePtr id, +void push_scope(IntrusivePtr id, std::unique_ptr>> attrs) { top_scope = new Scope(std::move(id), std::move(attrs)); diff --git a/src/Scope.h b/src/Scope.h index 146c5c051e..9ae4d5d976 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -13,31 +13,32 @@ #include "TraverseTypes.h" template class IntrusivePtr; -class ID; class BroType; class ListVal; +FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); + class Scope : public BroObj { public: - explicit Scope(IntrusivePtr id, + explicit Scope(IntrusivePtr id, std::unique_ptr>> al); - const IntrusivePtr& Find(std::string_view name) const; + const IntrusivePtr& Find(std::string_view name) const; template [[deprecated("Remove in v4.1. Use Find().")]] - ID* Lookup(N&& name) const + zeek::detail::ID* Lookup(N&& name) const { return Find(name).get(); } template void Insert(N&& name, I&& id) { local[std::forward(name)] = std::forward(id); } - IntrusivePtr Remove(std::string_view name); + IntrusivePtr Remove(std::string_view name); [[deprecated("Remove in v4.1. Use GetID().")]] - ID* ScopeID() const { return scope_id.get(); } + zeek::detail::ID* ScopeID() const { return scope_id.get(); } - const IntrusivePtr& GetID() const + const IntrusivePtr& GetID() const { return scope_id; } const std::unique_ptr>>& Attrs() const @@ -52,14 +53,14 @@ public: size_t Length() const { return local.size(); } const auto& Vars() { return local; } - IntrusivePtr GenerateTemporary(const char* name); + IntrusivePtr GenerateTemporary(const char* name); // Returns the list of variables needing initialization, and // removes it from this Scope. - std::vector> GetInits(); + std::vector> GetInits(); // Adds a variable to the list. - void AddInit(IntrusivePtr id) + void AddInit(IntrusivePtr id) { inits.emplace_back(std::move(id)); } void Describe(ODesc* d) const override; @@ -67,26 +68,26 @@ public: TraversalCode Traverse(TraversalCallback* cb) const; protected: - IntrusivePtr scope_id; + IntrusivePtr scope_id; std::unique_ptr>> attrs; IntrusivePtr return_type; - std::map, std::less<>> local; - std::vector> inits; + std::map, std::less<>> local; + std::vector> inits; }; extern bool in_debug; // If no_global is true, don't search in the default "global" namespace. -extern const IntrusivePtr& lookup_ID(const char* name, const char* module, - bool no_global = false, - bool same_module_only = false, - bool check_export = true); +extern const IntrusivePtr& lookup_ID(const char* name, const char* module, + bool no_global = false, + bool same_module_only = false, + bool check_export = true); -extern IntrusivePtr install_ID(const char* name, const char* module_name, - bool is_global, bool is_export); +extern IntrusivePtr install_ID(const char* name, const char* module_name, + bool is_global, bool is_export); -extern void push_scope(IntrusivePtr id, +extern void push_scope(IntrusivePtr id, std::unique_ptr>> attrs); extern void push_existing_scope(Scope* scope); diff --git a/src/Stats.cc b/src/Stats.cc index 39f645bf13..18cd383ca6 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -252,7 +252,7 @@ void ProfileLogger::Log() for ( const auto& global : globals ) { - ID* id = global.second.get(); + auto id = global.second; // We don't show/count internal globals as they are always // contained in some other global user-visible container. diff --git a/src/Traverse.h b/src/Traverse.h index 10b37c7385..ae91701fb5 100644 --- a/src/Traverse.h +++ b/src/Traverse.h @@ -6,10 +6,10 @@ class Func; class Scope; -class ID; FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); class TraversalCallback { public: @@ -25,14 +25,14 @@ public: virtual TraversalCode PreExpr(const zeek::detail::Expr*) { return TC_CONTINUE; } virtual TraversalCode PostExpr(const zeek::detail::Expr*) { return TC_CONTINUE; } - virtual TraversalCode PreID(const ID*) { return TC_CONTINUE; } - virtual TraversalCode PostID(const ID*) { return TC_CONTINUE; } + virtual TraversalCode PreID(const zeek::detail::ID*) { return TC_CONTINUE; } + virtual TraversalCode PostID(const zeek::detail::ID*) { return TC_CONTINUE; } - virtual TraversalCode PreTypedef(const ID*) { return TC_CONTINUE; } - virtual TraversalCode PostTypedef(const ID*) { return TC_CONTINUE; } + virtual TraversalCode PreTypedef(const zeek::detail::ID*) { return TC_CONTINUE; } + virtual TraversalCode PostTypedef(const zeek::detail::ID*) { return TC_CONTINUE; } - virtual TraversalCode PreDecl(const ID*) { return TC_CONTINUE; } - virtual TraversalCode PostDecl(const ID*) { return TC_CONTINUE; } + virtual TraversalCode PreDecl(const zeek::detail::ID*) { return TC_CONTINUE; } + virtual TraversalCode PostDecl(const zeek::detail::ID*) { return TC_CONTINUE; } Scope* current_scope; }; diff --git a/src/Trigger.cc b/src/Trigger.cc index 2781270dd0..06c49a6c98 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -391,7 +391,7 @@ void Trigger::Timeout() Unref(this); } -void Trigger::Register(ID* id) +void Trigger::Register(zeek::detail::ID* id) { assert(! disabled); notifier::registry.Register(id, this); diff --git a/src/Trigger.h b/src/Trigger.h index 7a20bf40ee..cf91b25cba 100644 --- a/src/Trigger.h +++ b/src/Trigger.h @@ -11,12 +11,12 @@ class Frame; class Val; -class ID; class ODesc; FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); +FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); namespace trigger { // Triggers are the heart of "when" statements: expressions that when @@ -89,7 +89,7 @@ private: friend class TriggerTimer; void Init(); - void Register(ID* id); + void Register(zeek::detail::ID* id); void Register(Val* val); void UnregisterAll(); diff --git a/src/Val.cc b/src/Val.cc index 31b906d18d..9dc120028e 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -379,12 +379,12 @@ void Val::ValDescribeReST(ODesc* d) const #ifdef DEBUG -ID* Val::GetID() const +zeek::detail::ID* Val::GetID() const { return bound_id ? global_scope()->Find(bound_id).get() : nullptr; } -void Val::SetID(ID* id) +void Val::SetID(zeek::detail::ID* id) { delete [] bound_id; bound_id = id ? copy_string(id->Name()) : nullptr; diff --git a/src/Val.h b/src/Val.h index 36e0114a31..45aa98f626 100644 --- a/src/Val.h +++ b/src/Val.h @@ -324,9 +324,9 @@ public: #ifdef DEBUG // For debugging, we keep a reference to the global ID to which a // value has been bound *last*. - ID* GetID() const; + zeek::detail::ID* GetID() const; - void SetID(ID* id); + void SetID(zeek::detail::ID* id); #endif static bool WouldOverflow(const BroType* from_type, const BroType* to_type, const Val* val); diff --git a/src/Var.cc b/src/Var.cc index e751600096..bb8fda8975 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -30,7 +30,7 @@ static IntrusivePtr init_val(zeek::detail::Expr* init, const BroType* t, } } -static bool add_prototype(const IntrusivePtr& id, BroType* t, +static bool add_prototype(const IntrusivePtr& id, BroType* t, std::vector>* attrs, const IntrusivePtr& init) { @@ -108,7 +108,8 @@ static bool add_prototype(const IntrusivePtr& id, BroType* t, return true; } -static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_class c, +static void make_var(const IntrusivePtr& id, IntrusivePtr t, + zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt, @@ -227,14 +228,14 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c if ( do_init ) { - if ( c == INIT_NONE && dt == VAR_REDEF && t->IsTable() && + if ( c == zeek::detail::INIT_NONE && dt == VAR_REDEF && t->IsTable() && init && init->Tag() == zeek::detail::EXPR_ASSIGN ) // e.g. 'redef foo["x"] = 1' is missing an init class, but the // intention clearly isn't to overwrite entire existing table val. - c = INIT_EXTRA; + c = zeek::detail::INIT_EXTRA; - if ( init && ((c == INIT_EXTRA && id->GetAttr(ATTR_ADD_FUNC)) || - (c == INIT_REMOVE && id->GetAttr(ATTR_DEL_FUNC)) )) + if ( init && ((c == zeek::detail::INIT_EXTRA && id->GetAttr(ATTR_ADD_FUNC)) || + (c == zeek::detail::INIT_REMOVE && id->GetAttr(ATTR_DEL_FUNC)) )) // Just apply the function. id->SetVal(init, c); @@ -301,22 +302,22 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c // For events, add a function value (without any body) here so that // we can later access the ID even if no implementations have been // defined. - std::vector> inits; + std::vector> inits; auto f = make_intrusive(id, nullptr, inits, 0, 0); id->SetVal(make_intrusive(std::move(f))); } } -void add_global(const IntrusivePtr& id, IntrusivePtr t, - init_class c, IntrusivePtr init, +void add_global(const IntrusivePtr& id, IntrusivePtr t, + zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt) { make_var(id, std::move(t), c, std::move(init), std::move(attr), dt, true); } -IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, - init_class c, IntrusivePtr init, +IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, + zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt) { @@ -324,7 +325,7 @@ IntrusivePtr add_local(IntrusivePtr id, IntrusivePtrError("can't use += / -= for initializations of local variables"); // copy Location to the stack, because AssignExpr may free "init" @@ -347,17 +348,17 @@ IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr add_and_assign_local(IntrusivePtr id, +extern IntrusivePtr add_and_assign_local(IntrusivePtr id, IntrusivePtr init, IntrusivePtr val) { - make_var(id, nullptr, INIT_FULL, init, nullptr, VAR_REGULAR, false); + make_var(id, nullptr, zeek::detail::INIT_FULL, init, nullptr, VAR_REGULAR, false); auto name_expr = make_intrusive(std::move(id)); return make_intrusive(std::move(name_expr), std::move(init), false, std::move(val)); } -void add_type(ID* id, IntrusivePtr t, +void add_type(zeek::detail::ID* id, IntrusivePtr t, std::unique_ptr>> attr) { std::string new_type_name = id->Name(); @@ -458,7 +459,7 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl return true; } -void begin_func(IntrusivePtr id, const char* module_name, +void begin_func(IntrusivePtr id, const char* module_name, function_flavor flavor, bool is_redef, IntrusivePtr t, std::unique_ptr>> attrs) diff --git a/src/Var.h b/src/Var.h index 92805676b1..696fdb7a29 100644 --- a/src/Var.h +++ b/src/Var.h @@ -18,28 +18,28 @@ FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); typedef enum { VAR_REGULAR, VAR_CONST, VAR_REDEF, VAR_OPTION, } decl_type; -extern void add_global(const IntrusivePtr& id, +extern void add_global(const IntrusivePtr& id, IntrusivePtr t, - init_class c, + zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt); -extern IntrusivePtr add_local(IntrusivePtr id, +extern IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, - init_class c, + zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt); -extern IntrusivePtr add_and_assign_local(IntrusivePtr id, +extern IntrusivePtr add_and_assign_local(IntrusivePtr id, IntrusivePtr init, IntrusivePtr val = nullptr); -extern void add_type(ID* id, IntrusivePtr t, +extern void add_type(zeek::detail::ID* id, IntrusivePtr t, std::unique_ptr>> attr); -extern void begin_func(IntrusivePtr id, const char* module_name, +extern void begin_func(IntrusivePtr id, const char* module_name, function_flavor flavor, bool is_redef, IntrusivePtr t, std::unique_ptr>> attrs = nullptr); diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 2416ff7af0..a5f11f3fc5 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -31,7 +31,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) for ( const auto& entry : globals ) { - ID* id = entry.second.get(); + auto id = entry.second; if ( ! id->IsOption() ) continue; diff --git a/src/option.bif b/src/option.bif index f2024062c4..771095567a 100644 --- a/src/option.bif +++ b/src/option.bif @@ -7,7 +7,7 @@ module Option; #include "NetVar.h" #include "broker/Data.h" -static bool call_option_handlers_and_set_value(StringVal* name, const IntrusivePtr& i, +static bool call_option_handlers_and_set_value(StringVal* name, const IntrusivePtr& i, IntrusivePtr val, StringVal* location) { diff --git a/src/parse.y b/src/parse.y index d6e03551a8..91361fe6db 100644 --- a/src/parse.y +++ b/src/parse.y @@ -136,7 +136,7 @@ std::vector saved_in_init; static Location func_hdr_location; EnumType *cur_enum_type = 0; -static ID* cur_decl_type_id = 0; +static zeek::detail::ID* cur_decl_type_id = 0; static void parser_new_enum (void) { @@ -149,7 +149,7 @@ static void parser_new_enum (void) reporter->FatalError("incorrect syntax for enum type declaration"); } -static void parser_redef_enum (ID *id) +static void parser_redef_enum (zeek::detail::ID *id) { /* Redef an enum. id points to the enum to be redefined. Let cur_enum_type point to it. */ @@ -166,7 +166,7 @@ static void parser_redef_enum (ID *id) } } -static void extend_record(ID* id, std::unique_ptr fields, +static void extend_record(zeek::detail::ID* id, std::unique_ptr fields, std::unique_ptr>> attrs) { std::set types = BroType::GetAliases(id->Name()); @@ -232,9 +232,9 @@ static bool expr_is_table_type_name(const zeek::detail::Expr* expr) %union { bool b; char* str; - ID* id; + zeek::detail::ID* id; id_list* id_l; - init_class ic; + zeek::detail::init_class ic; Val* val; RE_Matcher* re; zeek::detail::Expr* expr; @@ -1295,10 +1295,10 @@ opt_type: ; init_class: - { $$ = INIT_NONE; } - | '=' { $$ = INIT_FULL; } - | TOK_ADD_TO { $$ = INIT_EXTRA; } - | TOK_REMOVE_FROM { $$ = INIT_REMOVE; } + { $$ = zeek::detail::INIT_NONE; } + | '=' { $$ = zeek::detail::INIT_FULL; } + | TOK_ADD_TO { $$ = zeek::detail::INIT_EXTRA; } + | TOK_REMOVE_FROM { $$ = zeek::detail::INIT_REMOVE; } ; opt_init: @@ -1658,7 +1658,7 @@ case_type_list: case_type: TOK_TYPE type { - $$ = new ID(0, SCOPE_FUNCTION, 0); + $$ = new zeek::detail::ID(0, zeek::detail::SCOPE_FUNCTION, 0); $$->SetType({AdoptRef{}, $2}); } @@ -1673,7 +1673,7 @@ case_type: else case_var = install_ID(name, current_module.c_str(), false, false); - add_local(case_var, std::move(type), INIT_NONE, nullptr, nullptr, + add_local(case_var, std::move(type), zeek::detail::INIT_NONE, nullptr, nullptr, VAR_REGULAR); $$ = case_var.release(); } diff --git a/src/zeek.bif b/src/zeek.bif index d5083323ca..1b1f645701 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1918,7 +1918,7 @@ function global_sizes%(%): var_sizes for ( const auto& global : globals ) { - ID* id = global.second.get(); + auto id = global.second; if ( id->HasVal() ) { auto id_name = make_intrusive(id->Name()); @@ -1946,7 +1946,7 @@ function global_ids%(%): id_table for ( const auto& global : globals ) { - ID* id = global.second.get(); + zeek::detail::ID* id = global.second.get(); static auto script_id = zeek::id::find_type("script_id"); auto rec = make_intrusive(script_id); rec->Assign(0, make_intrusive(type_name(id->GetType()->Tag()))); diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index e31651f39e..ba8edbdd9f 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -11,7 +11,7 @@ using namespace std; using namespace zeekygen; -IdentifierInfo::IdentifierInfo(IntrusivePtr arg_id, ScriptInfo* script) +IdentifierInfo::IdentifierInfo(IntrusivePtr arg_id, ScriptInfo* script) : Info(), comments(), id(std::move(arg_id)), initial_val(), redefs(), fields(), last_field_seen(), declaring_script(script) @@ -31,7 +31,7 @@ IdentifierInfo::~IdentifierInfo() delete it->second; } -void IdentifierInfo::AddRedef(const string& script, init_class ic, +void IdentifierInfo::AddRedef(const string& script, zeek::detail::init_class ic, IntrusivePtr init_expr, const vector& comments) { Redefinition* redef = new Redefinition(script, ic, std::move(init_expr), comments); @@ -141,7 +141,7 @@ time_t IdentifierInfo::DoGetModificationTime() const IdentifierInfo::Redefinition::Redefinition( std::string arg_script, - init_class arg_ic, + zeek::detail::init_class arg_ic, IntrusivePtr arg_expr, std::vector arg_comments) : from_script(std::move(arg_script)), diff --git a/src/zeekygen/IdentifierInfo.h b/src/zeekygen/IdentifierInfo.h index fc75b3af18..5bb284d23d 100644 --- a/src/zeekygen/IdentifierInfo.h +++ b/src/zeekygen/IdentifierInfo.h @@ -32,7 +32,7 @@ public: * @param script The info object associated with the script in which \a id * is declared. */ - IdentifierInfo(IntrusivePtr id, ScriptInfo* script); + IdentifierInfo(IntrusivePtr id, ScriptInfo* script); /** * Dtor. Releases any references to script-level objects. @@ -70,7 +70,7 @@ public: * @param init_expr The initialization expression used. * @param comments Comments associated with the redef statement. */ - void AddRedef(const std::string& from_script, init_class ic, + void AddRedef(const std::string& from_script, zeek::detail::init_class ic, IntrusivePtr init_expr, const std::vector& comments); @@ -96,7 +96,7 @@ public: /** * @return the script-level ID tracked by this info object. */ - ID* GetID() const + zeek::detail::ID* GetID() const { return id.get(); } /** @@ -127,11 +127,11 @@ public: */ struct Redefinition { std::string from_script; /**< Name of script doing the redef. */ - init_class ic; + zeek::detail::init_class ic; IntrusivePtr init_expr; std::vector comments; /**< Zeekygen comments on redef. */ - Redefinition(std::string arg_script, init_class arg_ic, + Redefinition(std::string arg_script, zeek::detail::init_class arg_ic, IntrusivePtr arg_expr, std::vector arg_comments); @@ -174,7 +174,7 @@ private: typedef std::map record_field_map; std::vector comments; - IntrusivePtr id; + IntrusivePtr id; IntrusivePtr initial_val; redef_list redefs; record_field_map fields; diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index b1a6892b48..eab18fa6e1 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -27,7 +27,7 @@ static void DbgAndWarn(const char* msg) DBG_LOG(DBG_ZEEKYGEN, "%s", msg); } -static void WarnMissingScript(const char* type, const ID* id, +static void WarnMissingScript(const char* type, const zeek::detail::ID* id, const string& script) { if ( script == "" ) @@ -216,7 +216,7 @@ void Manager::ModuleUsage(const string& path, const string& module) module.c_str(), name.c_str()); } -IdentifierInfo* Manager::CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script) +IdentifierInfo* Manager::CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script) { const auto& id_name = id->Name(); auto prev = identifiers.GetInfo(id_name); @@ -247,7 +247,7 @@ IdentifierInfo* Manager::CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* s return rval; } -void Manager::StartType(IntrusivePtr id) +void Manager::StartType(IntrusivePtr id) { if ( disabled ) return; @@ -273,12 +273,12 @@ void Manager::StartType(IntrusivePtr id) incomplete_type = CreateIdentifierInfo(std::move(id), script_info); } -static bool IsEnumType(ID* id) +static bool IsEnumType(zeek::detail::ID* id) { return id->IsType() ? id->GetType()->Tag() == TYPE_ENUM : false; } -void Manager::Identifier(IntrusivePtr id) +void Manager::Identifier(IntrusivePtr id) { if ( disabled ) return; @@ -337,7 +337,7 @@ void Manager::Identifier(IntrusivePtr id) CreateIdentifierInfo(std::move(id), script_info); } -void Manager::RecordField(const ID* id, const TypeDecl* field, +void Manager::RecordField(const zeek::detail::ID* id, const TypeDecl* field, const string& path) { if ( disabled ) @@ -360,8 +360,8 @@ void Manager::RecordField(const ID* id, const TypeDecl* field, field->id, id->Name(), script.c_str()); } -void Manager::Redef(const ID* id, const string& path, - init_class ic, IntrusivePtr init_expr) +void Manager::Redef(const zeek::detail::ID* id, const string& path, + zeek::detail::init_class ic, IntrusivePtr init_expr) { if ( disabled ) return; @@ -397,8 +397,8 @@ void Manager::Redef(const ID* id, const string& path, id->Name(), from_script.c_str()); } -void Manager::Redef(const ID* id, const std::string& path, - init_class ic) +void Manager::Redef(const zeek::detail::ID* id, const std::string& path, + zeek::detail::init_class ic) { Redef(id, path, ic, nullptr); } diff --git a/src/zeekygen/Manager.h b/src/zeekygen/Manager.h index e45784cf51..fcac96204a 100644 --- a/src/zeekygen/Manager.h +++ b/src/zeekygen/Manager.h @@ -110,14 +110,14 @@ public: * Signal that a record or enum type is now being parsed. * @param id The record or enum type identifier. */ - void StartType(IntrusivePtr id); + void StartType(IntrusivePtr id); /** * Register a script-level identifier for which information/documentation * will be gathered. * @param id The script-level identifier. */ - void Identifier(IntrusivePtr id); + void Identifier(IntrusivePtr id); /** * Register a record-field for which information/documentation will be @@ -128,7 +128,7 @@ public: * declared. This can be different from the place where the record type * is declared due to redefs. */ - void RecordField(const ID* id, const TypeDecl* field, + void RecordField(const zeek::detail::ID* id, const TypeDecl* field, const std::string& path); /** @@ -138,10 +138,10 @@ public: * @param ic The initialization class that was used (e.g. =, +=, -=). * @param init_expr The intiialization expression that was used. */ - void Redef(const ID* id, const std::string& path, - init_class ic, IntrusivePtr init_expr); - void Redef(const ID* id, const std::string& path, - init_class ic = INIT_NONE); + void Redef(const zeek::detail::ID* id, const std::string& path, + zeek::detail::init_class ic, IntrusivePtr init_expr); + void Redef(const zeek::detail::ID* id, const std::string& path, + zeek::detail::init_class ic = zeek::detail::INIT_NONE); /** * Register Zeekygen script summary content. @@ -217,7 +217,7 @@ private: typedef std::vector comment_buffer_t; typedef std::map comment_buffer_map_t; - IdentifierInfo* CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script); + IdentifierInfo* CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script); bool disabled; comment_buffer_t comment_buffer; // For whatever next identifier comes in. diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index ddd0d8009c..4b630e6e6a 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -82,7 +82,7 @@ static string make_summary(const string& heading, char underline, char border, for ( id_info_list::const_iterator it = id_list.begin(); it != id_list.end(); ++it ) { - ID* id = (*it)->GetID(); + auto* id = (*it)->GetID(); ODesc d; d.SetQuotes(true); id->DescribeReSTShort(&d); @@ -105,7 +105,7 @@ static string make_redef_summary(const string& heading, char underline, for ( id_info_set::const_iterator it = id_set.begin(); it != id_set.end(); ++it ) { - ID* id = (*it)->GetID(); + auto* id = (*it)->GetID(); ODesc d; d.SetQuotes(true); id->DescribeReSTShort(&d); @@ -179,7 +179,7 @@ void ScriptInfo::DoInitPostScript() it != id_info.end(); ++it ) { IdentifierInfo* info = it->second; - ID* id = info->GetID(); + auto* id = info->GetID(); if ( ! zeekygen::is_public_api(id) ) continue; diff --git a/src/zeekygen/utils.cc b/src/zeekygen/utils.cc index c661b84539..fb016270b4 100644 --- a/src/zeekygen/utils.cc +++ b/src/zeekygen/utils.cc @@ -78,10 +78,10 @@ bool zeekygen::prettify_params(string& s) return false; } -bool zeekygen::is_public_api(const ID* id) +bool zeekygen::is_public_api(const zeek::detail::ID* id) { - return (id->Scope() == SCOPE_GLOBAL) || - (id->Scope() == SCOPE_MODULE && id->IsExport()); + return (id->Scope() == zeek::detail::SCOPE_GLOBAL) || + (id->Scope() == zeek::detail::SCOPE_MODULE && id->IsExport()); } time_t zeekygen::get_mtime(const string& filename) diff --git a/src/zeekygen/utils.h b/src/zeekygen/utils.h index e5ddcc49a4..3bf79101b0 100644 --- a/src/zeekygen/utils.h +++ b/src/zeekygen/utils.h @@ -6,7 +6,8 @@ #include // for time_t -class ID; +namespace zeek::detail { class ID; } +using ID [[deprecated("Remove in v4.1. Use zeek::detail::ID instead")]] = zeek::detail::ID; namespace zeekygen { @@ -25,7 +26,7 @@ bool prettify_params(std::string& s); * @return true if the ID is in the global scope or if it's exported in to * any modules namespace. */ -bool is_public_api(const ID* id); +bool is_public_api(const zeek::detail::ID* id); /** * Get the modification time of a file or abort if there's an error.