mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Scope: store IntrusivePtr in local
This commit is contained in:
parent
6e0d331267
commit
785ff57d11
6 changed files with 16 additions and 28 deletions
|
@ -62,7 +62,7 @@ void lookup_global_symbols_regex(const string& orig_regex, vector<ID*>& matches,
|
||||||
ID* nextid;
|
ID* nextid;
|
||||||
for ( const auto& sym : syms )
|
for ( const auto& sym : syms )
|
||||||
{
|
{
|
||||||
ID* nextid = sym.second;
|
ID* nextid = sym.second.get();
|
||||||
if ( ! func_only || nextid->Type()->Tag() == TYPE_FUNC )
|
if ( ! func_only || nextid->Type()->Tag() == TYPE_FUNC )
|
||||||
if ( ! regexec (&re, nextid->Name(), 0, 0, 0) )
|
if ( ! regexec (&re, nextid->Name(), 0, 0, 0) )
|
||||||
matches.push_back(nextid);
|
matches.push_back(nextid);
|
||||||
|
|
11
src/Scope.cc
11
src/Scope.cc
|
@ -40,9 +40,6 @@ Scope::Scope(IntrusivePtr<ID> id, attr_list* al)
|
||||||
|
|
||||||
Scope::~Scope()
|
Scope::~Scope()
|
||||||
{
|
{
|
||||||
for ( const auto& entry : local )
|
|
||||||
Unref(entry.second);
|
|
||||||
|
|
||||||
if ( attrs )
|
if ( attrs )
|
||||||
{
|
{
|
||||||
for ( const auto& attr : *attrs )
|
for ( const auto& attr : *attrs )
|
||||||
|
@ -101,7 +98,7 @@ void Scope::Describe(ODesc* d) const
|
||||||
|
|
||||||
for ( const auto& entry : local )
|
for ( const auto& entry : local )
|
||||||
{
|
{
|
||||||
ID* id = entry.second;
|
ID* id = entry.second.get();
|
||||||
id->Describe(d);
|
id->Describe(d);
|
||||||
d->NL();
|
d->NL();
|
||||||
}
|
}
|
||||||
|
@ -111,7 +108,7 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const
|
||||||
{
|
{
|
||||||
for ( const auto& entry : local )
|
for ( const auto& entry : local )
|
||||||
{
|
{
|
||||||
ID* id = entry.second;
|
ID* id = entry.second.get();
|
||||||
TraversalCode tc = id->Traverse(cb);
|
TraversalCode tc = id->Traverse(cb);
|
||||||
HANDLE_TC_STMT_PRE(tc);
|
HANDLE_TC_STMT_PRE(tc);
|
||||||
}
|
}
|
||||||
|
@ -176,11 +173,11 @@ IntrusivePtr<ID> install_ID(const char* name, const char* module_name,
|
||||||
auto id = make_intrusive<ID>(full_name.data(), scope, is_export);
|
auto id = make_intrusive<ID>(full_name.data(), scope, is_export);
|
||||||
|
|
||||||
if ( SCOPE_FUNCTION != scope )
|
if ( SCOPE_FUNCTION != scope )
|
||||||
global_scope()->Insert(std::move(full_name), IntrusivePtr{id}.release());
|
global_scope()->Insert(std::move(full_name), id);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
id->SetOffset(top_scope->Length());
|
id->SetOffset(top_scope->Length());
|
||||||
top_scope->Insert(std::move(full_name), IntrusivePtr{id}.release());
|
top_scope->Insert(std::move(full_name), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
|
23
src/Scope.h
23
src/Scope.h
|
@ -27,31 +27,22 @@ public:
|
||||||
const auto& entry = local.find(std::forward<N>(name));
|
const auto& entry = local.find(std::forward<N>(name));
|
||||||
|
|
||||||
if ( entry != local.end() )
|
if ( entry != local.end() )
|
||||||
return entry->second;
|
return entry->second.get();
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename N>
|
template<typename N, typename I>
|
||||||
void Insert(N&& name, ID* id)
|
void Insert(N&& name, I&& id) { local[std::forward<N>(name)] = std::forward<I>(id); }
|
||||||
{
|
|
||||||
auto [it, inserted] = local.emplace(std::forward<N>(name), id);
|
|
||||||
|
|
||||||
if ( ! inserted )
|
|
||||||
{
|
|
||||||
Unref(it->second);
|
|
||||||
it->second = id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename N>
|
template<typename N>
|
||||||
ID* Remove(N&& name)
|
IntrusivePtr<ID> Remove(N&& name)
|
||||||
{
|
{
|
||||||
const auto& entry = local.find(std::forward<N>(name));
|
const auto& entry = local.find(std::forward<N>(name));
|
||||||
|
|
||||||
if ( entry != local.end() )
|
if ( entry != local.end() )
|
||||||
{
|
{
|
||||||
ID* id = entry->second;
|
auto id = std::move(entry->second);
|
||||||
local.erase(entry);
|
local.erase(entry);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +55,7 @@ public:
|
||||||
BroType* ReturnType() const { return return_type.get(); }
|
BroType* ReturnType() const { return return_type.get(); }
|
||||||
|
|
||||||
size_t Length() const { return local.size(); }
|
size_t Length() const { return local.size(); }
|
||||||
const std::map<std::string, ID*>& Vars() { return local; }
|
const auto& Vars() { return local; }
|
||||||
|
|
||||||
ID* GenerateTemporary(const char* name);
|
ID* GenerateTemporary(const char* name);
|
||||||
|
|
||||||
|
@ -83,7 +74,7 @@ protected:
|
||||||
IntrusivePtr<ID> scope_id;
|
IntrusivePtr<ID> scope_id;
|
||||||
attr_list* attrs;
|
attr_list* attrs;
|
||||||
IntrusivePtr<BroType> return_type;
|
IntrusivePtr<BroType> return_type;
|
||||||
std::map<std::string, ID*> local;
|
std::map<std::string, IntrusivePtr<ID>> local;
|
||||||
id_list* inits;
|
id_list* inits;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ void ProfileLogger::Log()
|
||||||
|
|
||||||
for ( const auto& global : globals )
|
for ( const auto& global : globals )
|
||||||
{
|
{
|
||||||
ID* id = global.second;
|
ID* id = global.second.get();
|
||||||
|
|
||||||
// We don't show/count internal globals as they are always
|
// We don't show/count internal globals as they are always
|
||||||
// contained in some other global user-visible container.
|
// contained in some other global user-visible container.
|
||||||
|
|
|
@ -31,7 +31,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
|
||||||
|
|
||||||
for ( const auto& entry : globals )
|
for ( const auto& entry : globals )
|
||||||
{
|
{
|
||||||
ID* id = entry.second;
|
ID* id = entry.second.get();
|
||||||
if ( ! id->IsOption() )
|
if ( ! id->IsOption() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -1924,7 +1924,7 @@ function global_sizes%(%): var_sizes
|
||||||
|
|
||||||
for ( const auto& global : globals )
|
for ( const auto& global : globals )
|
||||||
{
|
{
|
||||||
ID* id = global.second;
|
ID* id = global.second.get();
|
||||||
if ( id->HasVal() )
|
if ( id->HasVal() )
|
||||||
{
|
{
|
||||||
Val* id_name = new StringVal(id->Name());
|
Val* id_name = new StringVal(id->Name());
|
||||||
|
@ -1952,7 +1952,7 @@ function global_ids%(%): id_table
|
||||||
|
|
||||||
for ( const auto& global : globals )
|
for ( const auto& global : globals )
|
||||||
{
|
{
|
||||||
ID* id = global.second;
|
ID* id = global.second.get();
|
||||||
auto rec = make_intrusive<RecordVal>(script_id);
|
auto rec = make_intrusive<RecordVal>(script_id);
|
||||||
rec->Assign(0, make_intrusive<StringVal>(type_name(id->Type()->Tag())));
|
rec->Assign(0, make_intrusive<StringVal>(type_name(id->Type()->Tag())));
|
||||||
rec->Assign(1, val_mgr->GetBool(id->IsExport()));
|
rec->Assign(1, val_mgr->GetBool(id->IsExport()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue