// See the file "COPYING" in the main distribution directory for copyright. #pragma once #include #include #include #include #include "Obj.h" #include "BroList.h" #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; using TypePtr = zeek::IntrusivePtr; namespace detail { using AttrPtr = zeek::IntrusivePtr; using IDPtr = zeek::IntrusivePtr; class Scope; using ScopePtr = zeek::IntrusivePtr; class Scope : public Obj { public: explicit Scope(zeek::detail::IDPtr id, std::unique_ptr> al); const zeek::detail::IDPtr& Find(std::string_view name) const; template [[deprecated("Remove in v4.1. Use Find().")]] 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); } zeek::detail::IDPtr Remove(std::string_view name); [[deprecated("Remove in v4.1. Use GetID().")]] zeek::detail::ID* ScopeID() const { return scope_id.get(); } const zeek::detail::IDPtr& GetID() const { return scope_id; } const std::unique_ptr>& Attrs() const { return attrs; } [[deprecated("Remove in v4.1. Use GetReturnTrype().")]] zeek::Type* ReturnType() const { return return_type.get(); } const zeek::TypePtr& GetReturnType() const { return return_type; } size_t Length() const { return local.size(); } const auto& Vars() { return local; } zeek::detail::IDPtr GenerateTemporary(const char* name); // Returns the list of variables needing initialization, and // removes it from this Scope. std::vector GetInits(); // Adds a variable to the list. void AddInit(zeek::detail::IDPtr id) { inits.emplace_back(std::move(id)); } void Describe(ODesc* d) const override; TraversalCode Traverse(TraversalCallback* cb) const; protected: zeek::detail::IDPtr scope_id; std::unique_ptr> attrs; zeek::TypePtr return_type; std::map> local; std::vector inits; }; // 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, bool no_global = false, bool same_module_only = false, bool check_export = true); extern zeek::detail::IDPtr install_ID( const char* name, const char* module_name, bool is_global, bool is_export); extern void push_scope(zeek::detail::IDPtr id, std::unique_ptr> attrs); extern void push_existing_scope(Scope* scope); // Returns the one popped off. extern ScopePtr pop_scope(); extern Scope* current_scope(); 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 zeek::detail::ID* lookup_ID( const char* name, const char* module, bool no_global = false, bool same_module_only = false, bool check_export = true);