diff --git a/src/parse.y b/src/parse.y index 3f79e4331c..f2337ec653 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1119,7 +1119,7 @@ decl: IntrusivePtr id{AdoptRef{}, $2}; IntrusivePtr init{AdoptRef{}, $5}; add_global(id.get(), {AdoptRef{}, $3}, $4, init, $6, VAR_REDEF); - zeekygen_mgr->Redef(id.get(), ::filename, $4, init.release()); + zeekygen_mgr->Redef(id.get(), ::filename, $4, std::move(init)); } | TOK_REDEF TOK_ENUM global_id TOK_ADD_TO '{' diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index 49ae1ad856..5727e3860c 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -32,9 +32,9 @@ IdentifierInfo::~IdentifierInfo() } void IdentifierInfo::AddRedef(const string& script, init_class ic, - Expr* init_expr, const vector& comments) + IntrusivePtr init_expr, const vector& comments) { - Redefinition* redef = new Redefinition(script, ic, init_expr, comments); + Redefinition* redef = new Redefinition(script, ic, std::move(init_expr), comments); redefs.push_back(redef); } @@ -142,49 +142,16 @@ time_t IdentifierInfo::DoGetModificationTime() const IdentifierInfo::Redefinition::Redefinition( std::string arg_script, init_class arg_ic, - Expr* arg_expr, + IntrusivePtr arg_expr, std::vector arg_comments) : from_script(std::move(arg_script)), ic(arg_ic), - init_expr(arg_expr ? arg_expr->Ref() : nullptr), + init_expr(std::move(arg_expr)), comments(std::move(arg_comments)) { } -IdentifierInfo::Redefinition::Redefinition(const IdentifierInfo::Redefinition& other) - { - from_script = other.from_script; - ic = other.ic; - init_expr = other.init_expr; - comments = other.comments; - - if ( init_expr ) - init_expr->Ref(); - } - -IdentifierInfo::Redefinition& -IdentifierInfo::Redefinition::operator=(const IdentifierInfo::Redefinition& other) - { - if ( &other == this ) - return *this; - - Unref(init_expr); - - from_script = other.from_script; - ic = other.ic; - init_expr = other.init_expr; - comments = other.comments; - - if ( init_expr ) - init_expr->Ref(); - - return *this; - } - -IdentifierInfo::Redefinition::~Redefinition() - { - Unref(init_expr); - } +IdentifierInfo::Redefinition::~Redefinition() = default; IdentifierInfo::RecordField::~RecordField() { diff --git a/src/zeekygen/IdentifierInfo.h b/src/zeekygen/IdentifierInfo.h index 947378d1f0..949a503664 100644 --- a/src/zeekygen/IdentifierInfo.h +++ b/src/zeekygen/IdentifierInfo.h @@ -71,7 +71,7 @@ public: * @param comments Comments associated with the redef statement. */ void AddRedef(const std::string& from_script, init_class ic, - Expr* init_expr, + IntrusivePtr init_expr, const std::vector& comments); /** @@ -128,17 +128,13 @@ public: struct Redefinition { std::string from_script; /**< Name of script doing the redef. */ init_class ic; - Expr* init_expr; + IntrusivePtr init_expr; std::vector comments; /**< Zeekygen comments on redef. */ Redefinition(std::string arg_script, init_class arg_ic, - Expr* arg_expr, + IntrusivePtr arg_expr, std::vector arg_comments); - Redefinition(const Redefinition& other); - - Redefinition& operator=(const Redefinition& other); - ~Redefinition(); }; diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index f9e4e48585..b61cb15404 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -7,6 +7,7 @@ #include "PackageInfo.h" #include "ScriptInfo.h" #include "IdentifierInfo.h" +#include "Expr.h" #include #include @@ -359,7 +360,7 @@ void Manager::RecordField(const ID* id, const TypeDecl* field, } void Manager::Redef(const ID* id, const string& path, - init_class ic, Expr* init_expr) + init_class ic, IntrusivePtr init_expr) { if ( disabled ) return; @@ -387,7 +388,7 @@ void Manager::Redef(const ID* id, const string& path, return; } - id_info->AddRedef(from_script, ic, init_expr, comment_buffer); + id_info->AddRedef(from_script, ic, std::move(init_expr), comment_buffer); script_info->AddRedef(id_info); comment_buffer.clear(); last_identifier_seen = id_info; @@ -395,6 +396,12 @@ 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) + { + Redef(id, path, ic, nullptr); + } + void Manager::SummaryComment(const string& script, const string& comment) { if ( disabled ) diff --git a/src/zeekygen/Manager.h b/src/zeekygen/Manager.h index a22dada278..aca2f07c5c 100644 --- a/src/zeekygen/Manager.h +++ b/src/zeekygen/Manager.h @@ -14,6 +14,7 @@ #include #include +template class IntrusivePtr; class TypeDecl; namespace zeekygen { @@ -138,7 +139,9 @@ public: * @param init_expr The intiialization expression that was used. */ void Redef(const ID* id, const std::string& path, - init_class ic = INIT_NONE, Expr* init_expr = nullptr); + init_class ic, IntrusivePtr init_expr); + void Redef(const ID* id, const std::string& path, + init_class ic = INIT_NONE); /** * Register Zeekygen script summary content.