mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
zeekygen: use class IntrusivePtr
This commit is contained in:
parent
edde591748
commit
95e2d66fb0
8 changed files with 40 additions and 38 deletions
|
@ -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
|
||||
{
|
||||
|
|
32
src/parse.y
32
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<Expr> 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
|
||||
{
|
||||
|
|
|
@ -135,7 +135,7 @@ ComponentManager<T, C>::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 <class T, class C>
|
||||
|
|
|
@ -11,22 +11,17 @@
|
|||
using namespace std;
|
||||
using namespace zeekygen;
|
||||
|
||||
IdentifierInfo::IdentifierInfo(ID* arg_id, ScriptInfo* script)
|
||||
IdentifierInfo::IdentifierInfo(IntrusivePtr<ID> 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;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Info.h"
|
||||
#include "IntrusivePtr.h"
|
||||
#include "ID.h"
|
||||
|
||||
#include <string>
|
||||
|
@ -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> 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<std::string, RecordField*> record_field_map;
|
||||
|
||||
std::vector<std::string> comments;
|
||||
ID* id;
|
||||
Val* initial_val;
|
||||
IntrusivePtr<ID> id;
|
||||
IntrusivePtr<Val> initial_val;
|
||||
redef_list redefs;
|
||||
record_field_map fields;
|
||||
RecordField* last_field_seen;
|
||||
|
|
|
@ -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> 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> 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> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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> 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> id);
|
||||
|
||||
/**
|
||||
* Register a record-field for which information/documentation will be
|
||||
|
@ -214,7 +214,7 @@ private:
|
|||
typedef std::vector<std::string> comment_buffer_t;
|
||||
typedef std::map<std::string, comment_buffer_t> comment_buffer_map_t;
|
||||
|
||||
IdentifierInfo* CreateIdentifierInfo(ID* id, ScriptInfo* script);
|
||||
IdentifierInfo* CreateIdentifierInfo(IntrusivePtr<ID> id, ScriptInfo* script);
|
||||
|
||||
bool disabled;
|
||||
comment_buffer_t comment_buffer; // For whatever next identifier comes in.
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue