diff --git a/src/Type.cc b/src/Type.cc index cb9bd60bb0..ab422f2ba0 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1183,7 +1183,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, if ( deprecation ) id->MakeDeprecated(deprecation); - zeekygen_mgr->Identifier(id.get()); + zeekygen_mgr->Identifier(std::move(id)); } else { diff --git a/src/parse.y b/src/parse.y index c11242e7ec..4daa1562ff 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1086,27 +1086,31 @@ decl: | TOK_GLOBAL def_global_id opt_type init_class opt_init opt_attr ';' { - add_global($2, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, $6, VAR_REGULAR); - zeekygen_mgr->Identifier($2); + IntrusivePtr id{AdoptRef{}, $2}; + add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, $6, VAR_REGULAR); + zeekygen_mgr->Identifier(std::move(id)); } | TOK_OPTION def_global_id opt_type init_class opt_init opt_attr ';' { - add_global($2, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, $6, VAR_OPTION); - zeekygen_mgr->Identifier($2); + IntrusivePtr id{AdoptRef{}, $2}; + add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, $6, VAR_OPTION); + zeekygen_mgr->Identifier(std::move(id)); } | TOK_CONST def_global_id opt_type init_class opt_init opt_attr ';' { - add_global($2, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, $6, VAR_CONST); - zeekygen_mgr->Identifier($2); + IntrusivePtr id{AdoptRef{}, $2}; + add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, $6, VAR_CONST); + zeekygen_mgr->Identifier(std::move(id)); } | TOK_REDEF global_id opt_type init_class opt_init opt_attr ';' { + IntrusivePtr id{AdoptRef{}, $2}; IntrusivePtr init{AdoptRef{}, $5}; - add_global($2, {AdoptRef{}, $3}, $4, init, $6, VAR_REDEF); - zeekygen_mgr->Redef($2, ::filename, $4, init.release()); + add_global(id.get(), {AdoptRef{}, $3}, $4, init, $6, VAR_REDEF); + zeekygen_mgr->Redef(id.get(), ::filename, $4, init.release()); } | TOK_REDEF TOK_ENUM global_id TOK_ADD_TO '{' @@ -1133,12 +1137,13 @@ decl: } | TOK_TYPE global_id ':' - { cur_decl_type_id = $2; zeekygen_mgr->StartType($2); } + { cur_decl_type_id = $2; zeekygen_mgr->StartType({NewRef{}, $2}); } type opt_attr ';' { cur_decl_type_id = 0; - add_type($2, {AdoptRef{}, $5}, $6); - zeekygen_mgr->Identifier($2); + IntrusivePtr id{AdoptRef{}, $2}; + add_type(id.get(), {AdoptRef{}, $5}, $6); + zeekygen_mgr->Identifier(std::move(id)); } | func_hdr { func_hdr_location = @1; } func_body @@ -1168,10 +1173,11 @@ conditional: func_hdr: TOK_FUNCTION def_global_id func_params opt_attr { - begin_func($2, current_module.c_str(), + IntrusivePtr id{AdoptRef{}, $2}; + begin_func(id.get(), current_module.c_str(), FUNC_FLAVOR_FUNCTION, 0, {NewRef{}, $3}, $4); $$ = $3; - zeekygen_mgr->Identifier($2); + zeekygen_mgr->Identifier(std::move(id)); } | TOK_EVENT event_id func_params opt_attr { diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index 8740e376b3..87d22fc189 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -135,7 +135,7 @@ ComponentManager::ComponentManager(const string& arg_module, const string& { auto id = install_ID(local_id.c_str(), module.c_str(), true, true); add_type(id.get(), tag_enum_type, 0); - zeekygen_mgr->Identifier(id.get()); + zeekygen_mgr->Identifier(std::move(id)); } template diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index c94dd7fb99..291e39981f 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -11,22 +11,17 @@ using namespace std; using namespace zeekygen; -IdentifierInfo::IdentifierInfo(ID* arg_id, ScriptInfo* script) +IdentifierInfo::IdentifierInfo(IntrusivePtr arg_id, ScriptInfo* script) : Info(), - comments(), id(arg_id), initial_val(), redefs(), fields(), + comments(), id(std::move(arg_id)), initial_val(), redefs(), fields(), last_field_seen(), declaring_script(script) { - Ref(id); - if ( id->ID_Val() && (id->IsOption() || id->IsRedefinable()) ) - initial_val = id->ID_Val()->Clone(); + initial_val = {AdoptRef{}, id->ID_Val()->Clone()}; } IdentifierInfo::~IdentifierInfo() { - Unref(id); - Unref(initial_val); - for ( redef_list::const_iterator it = redefs.begin(); it != redefs.end(); ++it ) delete *it; diff --git a/src/zeekygen/IdentifierInfo.h b/src/zeekygen/IdentifierInfo.h index 56ae00f0b8..947378d1f0 100644 --- a/src/zeekygen/IdentifierInfo.h +++ b/src/zeekygen/IdentifierInfo.h @@ -3,6 +3,7 @@ #pragma once #include "Info.h" +#include "IntrusivePtr.h" #include "ID.h" #include @@ -31,7 +32,7 @@ public: * @param script The info object associated with the script in which \a id * is declared. */ - IdentifierInfo(ID* id, ScriptInfo* script); + IdentifierInfo(IntrusivePtr id, ScriptInfo* script); /** * Dtor. Releases any references to script-level objects. @@ -42,7 +43,7 @@ public: * Returns the initial value of the identifier. */ Val* InitialVal() const - { return initial_val; } + { return initial_val.get(); } /** * Add a comment associated with the identifier. If the identifier is a @@ -96,7 +97,7 @@ public: * @return the script-level ID tracked by this info object. */ ID* GetID() const - { return id; } + { return id.get(); } /** * @return The script which declared the script-level identifier. @@ -177,8 +178,8 @@ private: typedef std::map record_field_map; std::vector comments; - ID* id; - Val* initial_val; + IntrusivePtr id; + IntrusivePtr initial_val; redef_list redefs; record_field_map fields; RecordField* last_field_seen; diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index 3029d1640f..f9e4e48585 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -215,7 +215,7 @@ void Manager::ModuleUsage(const string& path, const string& module) module.c_str(), name.c_str()); } -IdentifierInfo* Manager::CreateIdentifierInfo(ID* id, ScriptInfo* script) +IdentifierInfo* Manager::CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script) { auto prev = identifiers.GetInfo(id->Name()); IdentifierInfo* rval = prev ? prev : new IdentifierInfo(id, script); @@ -245,7 +245,7 @@ IdentifierInfo* Manager::CreateIdentifierInfo(ID* id, ScriptInfo* script) return rval; } -void Manager::StartType(ID* id) +void Manager::StartType(IntrusivePtr id) { if ( disabled ) return; @@ -262,7 +262,7 @@ void Manager::StartType(ID* id) if ( ! script_info ) { - WarnMissingScript("identifier", id, script); + WarnMissingScript("identifier", id.get(), script); return; } @@ -276,7 +276,7 @@ static bool IsEnumType(ID* id) return id->AsType() ? id->AsType()->Tag() == TYPE_ENUM : false; } -void Manager::Identifier(ID* id) +void Manager::Identifier(IntrusivePtr id) { if ( disabled ) return; @@ -326,7 +326,7 @@ void Manager::Identifier(ID* id) if ( ! script_info ) { - WarnMissingScript("identifier", id, script); + WarnMissingScript("identifier", id.get(), script); return; } diff --git a/src/zeekygen/Manager.h b/src/zeekygen/Manager.h index 988d641370..a22dada278 100644 --- a/src/zeekygen/Manager.h +++ b/src/zeekygen/Manager.h @@ -109,14 +109,14 @@ public: * Signal that a record or enum type is now being parsed. * @param id The record or enum type identifier. */ - void StartType(ID* 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(ID* id); + void Identifier(IntrusivePtr id); /** * Register a record-field for which information/documentation will be @@ -214,7 +214,7 @@ private: typedef std::vector comment_buffer_t; typedef std::map comment_buffer_map_t; - IdentifierInfo* CreateIdentifierInfo(ID* 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 6e8afda0ef..a2c41bb300 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -258,12 +258,12 @@ void ScriptInfo::DoInitPostScript() if ( name == "base/frameworks/input/main.zeek" ) { auto id = global_scope()->Lookup("Input::Reader"); - types.push_back(new IdentifierInfo(id, this)); + types.push_back(new IdentifierInfo({NewRef{}, id}, this)); } else if ( name == "base/frameworks/logging/main.zeek" ) { auto id = global_scope()->Lookup("Log::Writer"); - types.push_back(new IdentifierInfo(id, this)); + types.push_back(new IdentifierInfo({NewRef{}, id}, this)); } }