mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 05:28:20 +00:00
zeekygen/IdentifierInfo: use class IntrusivePtr more
With this in place, we can eliminate the manually imeplemented copy constructor/operator.
This commit is contained in:
parent
a0c831a1bd
commit
78712d009f
5 changed files with 22 additions and 49 deletions
|
@ -1119,7 +1119,7 @@ decl:
|
||||||
IntrusivePtr id{AdoptRef{}, $2};
|
IntrusivePtr id{AdoptRef{}, $2};
|
||||||
IntrusivePtr<Expr> init{AdoptRef{}, $5};
|
IntrusivePtr<Expr> init{AdoptRef{}, $5};
|
||||||
add_global(id.get(), {AdoptRef{}, $3}, $4, init, $6, VAR_REDEF);
|
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 '{'
|
| TOK_REDEF TOK_ENUM global_id TOK_ADD_TO '{'
|
||||||
|
|
|
@ -32,9 +32,9 @@ IdentifierInfo::~IdentifierInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
void IdentifierInfo::AddRedef(const string& script, init_class ic,
|
void IdentifierInfo::AddRedef(const string& script, init_class ic,
|
||||||
Expr* init_expr, const vector<string>& comments)
|
IntrusivePtr<Expr> init_expr, const vector<string>& 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);
|
redefs.push_back(redef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,49 +142,16 @@ time_t IdentifierInfo::DoGetModificationTime() const
|
||||||
IdentifierInfo::Redefinition::Redefinition(
|
IdentifierInfo::Redefinition::Redefinition(
|
||||||
std::string arg_script,
|
std::string arg_script,
|
||||||
init_class arg_ic,
|
init_class arg_ic,
|
||||||
Expr* arg_expr,
|
IntrusivePtr<Expr> arg_expr,
|
||||||
std::vector<std::string> arg_comments)
|
std::vector<std::string> arg_comments)
|
||||||
: from_script(std::move(arg_script)),
|
: from_script(std::move(arg_script)),
|
||||||
ic(arg_ic),
|
ic(arg_ic),
|
||||||
init_expr(arg_expr ? arg_expr->Ref() : nullptr),
|
init_expr(std::move(arg_expr)),
|
||||||
comments(std::move(arg_comments))
|
comments(std::move(arg_comments))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentifierInfo::Redefinition::Redefinition(const IdentifierInfo::Redefinition& other)
|
IdentifierInfo::Redefinition::~Redefinition() = default;
|
||||||
{
|
|
||||||
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::RecordField::~RecordField()
|
IdentifierInfo::RecordField::~RecordField()
|
||||||
{
|
{
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
* @param comments Comments associated with the redef statement.
|
* @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, init_class ic,
|
||||||
Expr* init_expr,
|
IntrusivePtr<Expr> init_expr,
|
||||||
const std::vector<std::string>& comments);
|
const std::vector<std::string>& comments);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,17 +128,13 @@ public:
|
||||||
struct Redefinition {
|
struct Redefinition {
|
||||||
std::string from_script; /**< Name of script doing the redef. */
|
std::string from_script; /**< Name of script doing the redef. */
|
||||||
init_class ic;
|
init_class ic;
|
||||||
Expr* init_expr;
|
IntrusivePtr<Expr> init_expr;
|
||||||
std::vector<std::string> comments; /**< Zeekygen comments on redef. */
|
std::vector<std::string> comments; /**< Zeekygen comments on redef. */
|
||||||
|
|
||||||
Redefinition(std::string arg_script, init_class arg_ic,
|
Redefinition(std::string arg_script, init_class arg_ic,
|
||||||
Expr* arg_expr,
|
IntrusivePtr<Expr> arg_expr,
|
||||||
std::vector<std::string> arg_comments);
|
std::vector<std::string> arg_comments);
|
||||||
|
|
||||||
Redefinition(const Redefinition& other);
|
|
||||||
|
|
||||||
Redefinition& operator=(const Redefinition& other);
|
|
||||||
|
|
||||||
~Redefinition();
|
~Redefinition();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "PackageInfo.h"
|
#include "PackageInfo.h"
|
||||||
#include "ScriptInfo.h"
|
#include "ScriptInfo.h"
|
||||||
#include "IdentifierInfo.h"
|
#include "IdentifierInfo.h"
|
||||||
|
#include "Expr.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -359,7 +360,7 @@ void Manager::RecordField(const ID* id, const TypeDecl* field,
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::Redef(const ID* id, const string& path,
|
void Manager::Redef(const ID* id, const string& path,
|
||||||
init_class ic, Expr* init_expr)
|
init_class ic, IntrusivePtr<Expr> init_expr)
|
||||||
{
|
{
|
||||||
if ( disabled )
|
if ( disabled )
|
||||||
return;
|
return;
|
||||||
|
@ -387,7 +388,7 @@ void Manager::Redef(const ID* id, const string& path,
|
||||||
return;
|
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);
|
script_info->AddRedef(id_info);
|
||||||
comment_buffer.clear();
|
comment_buffer.clear();
|
||||||
last_identifier_seen = id_info;
|
last_identifier_seen = id_info;
|
||||||
|
@ -395,6 +396,12 @@ void Manager::Redef(const ID* id, const string& path,
|
||||||
id->Name(), from_script.c_str());
|
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)
|
void Manager::SummaryComment(const string& script, const string& comment)
|
||||||
{
|
{
|
||||||
if ( disabled )
|
if ( disabled )
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
template <class T> class IntrusivePtr;
|
||||||
class TypeDecl;
|
class TypeDecl;
|
||||||
|
|
||||||
namespace zeekygen {
|
namespace zeekygen {
|
||||||
|
@ -138,7 +139,9 @@ public:
|
||||||
* @param init_expr The intiialization expression that was used.
|
* @param init_expr The intiialization expression that was used.
|
||||||
*/
|
*/
|
||||||
void Redef(const ID* id, const std::string& path,
|
void Redef(const ID* id, const std::string& path,
|
||||||
init_class ic = INIT_NONE, Expr* init_expr = nullptr);
|
init_class ic, IntrusivePtr<Expr> init_expr);
|
||||||
|
void Redef(const ID* id, const std::string& path,
|
||||||
|
init_class ic = INIT_NONE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register Zeekygen script summary content.
|
* Register Zeekygen script summary content.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue