// See the file "COPYING" in the main distribution directory for copyright. #pragma once #include #include #include #include #include "zeek/IntrusivePtr.h" #include "zeek/Obj.h" #include "zeek/TraverseTypes.h" #include "zeek/ZeekList.h" namespace zeek { class Type; template class IntrusivePtr; using TypePtr = IntrusivePtr; namespace detail { class Attr; class ID; using AttrPtr = IntrusivePtr; using IDPtr = IntrusivePtr; class Scope; using ScopePtr = IntrusivePtr; class Scope : public Obj { public: explicit Scope(IDPtr id, std::unique_ptr> al); const IDPtr& Find(std::string_view name) const; template void Insert(N&& name, I&& id) { local[std::forward(name)] = id; ordered_vars.push_back(std::forward(id)); } const IDPtr& GetID() const { return scope_id; } const std::unique_ptr>& Attrs() const { return attrs; } const TypePtr& GetReturnType() const { return return_type; } size_t Length() const { return local.size(); } const auto& Vars() const { return local; } const auto& OrderedVars() const { return ordered_vars; } 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(IDPtr id) { inits.emplace_back(std::move(id)); } void Describe(ODesc* d) const override; TraversalCode Traverse(TraversalCallback* cb) const; protected: IDPtr scope_id; std::unique_ptr> attrs; TypePtr return_type; std::map> local; std::vector inits; // We keep track of identifiers in the order that they're added. // This is necessary for script optimization to be able to find // event/hook parameters for instances where the declaration of // an additional handler uses different names for the parameters // than the original declaration. std::vector> ordered_vars; }; // If no_global is true, don't search in the default "global" namespace. extern const IDPtr& lookup_ID(const char* name, const char* module, bool no_global = false, bool same_module_only = false, bool check_export = true); extern IDPtr install_ID(const char* name, const char* module_name, bool is_global, bool is_export); extern void push_scope(IDPtr id, std::unique_ptr> attrs); extern void push_existing_scope(ScopePtr scope); // Returns the one popped off. extern ScopePtr pop_scope(); extern ScopePtr current_scope(); extern ScopePtr global_scope(); // Current module (identified by its name). extern std::string current_module; } // namespace detail } // namespace zeek extern bool in_debug;