mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Scope: remove uses of PDict
This commit is contained in:
parent
bbf49406c1
commit
a3deb0446c
7 changed files with 51 additions and 41 deletions
|
@ -51,14 +51,16 @@ void lookup_global_symbols_regex(const string& orig_regex, vector<ID*>& matches,
|
|||
}
|
||||
|
||||
Scope* global = global_scope();
|
||||
PDict<ID>* syms = global->Vars();
|
||||
auto syms = global->Vars();
|
||||
|
||||
ID* nextid;
|
||||
IterCookie* cookie = syms->InitForIteration();
|
||||
while ( (nextid = syms->NextEntry( cookie )) )
|
||||
for ( const auto& sym : syms )
|
||||
{
|
||||
ID* nextid = sym.second;
|
||||
if ( ! func_only || nextid->Type()->Tag() == TYPE_FUNC )
|
||||
if ( ! regexec (&re, nextid->Name(), 0, 0, 0) )
|
||||
matches.push_back(nextid);
|
||||
}
|
||||
}
|
||||
|
||||
void choose_global_symbols_regex(const string& regex, vector<ID*>& choices,
|
||||
|
|
20
src/Scope.cc
20
src/Scope.cc
|
@ -19,7 +19,6 @@ Scope::Scope(ID* id, attr_list* al)
|
|||
attrs = al;
|
||||
return_type = 0;
|
||||
|
||||
local = new PDict<ID>(ORDERED);
|
||||
inits = new id_list;
|
||||
|
||||
if ( id )
|
||||
|
@ -42,8 +41,8 @@ Scope::Scope(ID* id, attr_list* al)
|
|||
|
||||
Scope::~Scope()
|
||||
{
|
||||
for ( int i = 0; i < local->Length(); ++i )
|
||||
Unref(local->NthEntry(i));
|
||||
for ( const auto& entry : local )
|
||||
Unref(entry.second);
|
||||
|
||||
if ( attrs )
|
||||
{
|
||||
|
@ -55,7 +54,6 @@ Scope::~Scope()
|
|||
|
||||
Unref(scope_id);
|
||||
Unref(return_type);
|
||||
delete local;
|
||||
delete inits;
|
||||
}
|
||||
|
||||
|
@ -82,7 +80,7 @@ void Scope::Describe(ODesc* d) const
|
|||
d->SP();
|
||||
d->Add(return_type != 0);
|
||||
d->SP();
|
||||
d->Add(local->Length());
|
||||
d->Add(static_cast<uint64_t>(local.size()));
|
||||
d->SP();
|
||||
}
|
||||
|
||||
|
@ -98,9 +96,9 @@ void Scope::Describe(ODesc* d) const
|
|||
d->NL();
|
||||
}
|
||||
|
||||
for ( int i = 0; i < local->Length(); ++i )
|
||||
for ( const auto& entry : local )
|
||||
{
|
||||
ID* id = local->NthEntry(i);
|
||||
ID* id = entry.second;
|
||||
id->Describe(d);
|
||||
d->NL();
|
||||
}
|
||||
|
@ -108,13 +106,9 @@ void Scope::Describe(ODesc* d) const
|
|||
|
||||
TraversalCode Scope::Traverse(TraversalCallback* cb) const
|
||||
{
|
||||
PDict<ID>* ids = GetIDs();
|
||||
IterCookie* iter = ids->InitForIteration();
|
||||
|
||||
HashKey* key;
|
||||
ID* id;
|
||||
while ( (id = ids->NextEntry(key, iter)) )
|
||||
for ( const auto& entry : local )
|
||||
{
|
||||
ID* id = entry.second;
|
||||
TraversalCode tc = id->Traverse(cb);
|
||||
HANDLE_TC_STMT_PRE(tc);
|
||||
}
|
||||
|
|
33
src/Scope.h
33
src/Scope.h
|
@ -4,6 +4,7 @@
|
|||
#define scope_h
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "Dict.h"
|
||||
#include "Obj.h"
|
||||
|
@ -20,25 +21,37 @@ public:
|
|||
explicit Scope(ID* id, attr_list* al);
|
||||
~Scope() override;
|
||||
|
||||
ID* Lookup(const char* name) const { return local->Lookup(name); }
|
||||
void Insert(const char* name, ID* id) { local->Insert(name, id); }
|
||||
ID* Remove(const char* name)
|
||||
ID* Lookup(const std::string& name) const
|
||||
{
|
||||
HashKey key(name);
|
||||
return (ID*) local->Remove(&key);
|
||||
const auto& entry = local.find(name);
|
||||
if ( entry != local.end() )
|
||||
return entry->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
void Insert(const std::string& name, ID* id) { local[name] = id; }
|
||||
ID* Remove(const std::string& name)
|
||||
{
|
||||
const auto& entry = local.find(name);
|
||||
if ( entry != local.end() )
|
||||
{
|
||||
ID* id = entry->second;
|
||||
local.erase(entry);
|
||||
return id;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ID* ScopeID() const { return scope_id; }
|
||||
attr_list* Attrs() const { return attrs; }
|
||||
BroType* ReturnType() const { return return_type; }
|
||||
|
||||
int Length() const { return local->Length(); }
|
||||
PDict<ID>* Vars() const { return local; }
|
||||
size_t Length() const { return local.size(); }
|
||||
std::map<string, ID*>& Vars() { return local; }
|
||||
|
||||
ID* GenerateTemporary(const char* name);
|
||||
|
||||
PDict<ID>* GetIDs() const { return local; }
|
||||
|
||||
// Returns the list of variables needing initialization, and
|
||||
// removes it from this Scope.
|
||||
id_list* GetInits();
|
||||
|
@ -54,7 +67,7 @@ protected:
|
|||
ID* scope_id;
|
||||
attr_list* attrs;
|
||||
BroType* return_type;
|
||||
PDict<ID>* local;
|
||||
std::map<string, ID*> local;
|
||||
id_list* inits;
|
||||
};
|
||||
|
||||
|
|
|
@ -239,7 +239,7 @@ void ProfileLogger::Log()
|
|||
|
||||
// Script-level state.
|
||||
unsigned int size, mem = 0;
|
||||
PDict<ID>* globals = global_scope()->Vars();
|
||||
auto globals = global_scope()->Vars();
|
||||
|
||||
if ( expensive )
|
||||
{
|
||||
|
@ -249,10 +249,10 @@ void ProfileLogger::Log()
|
|||
file->Write(fmt("%.06f Global_sizes > 100k: %dK\n",
|
||||
network_time, mem / 1024));
|
||||
|
||||
ID* id;
|
||||
IterCookie* c = globals->InitForIteration();
|
||||
for ( const auto& global : globals )
|
||||
{
|
||||
ID* id = global.second;
|
||||
|
||||
while ( (id = globals->NextEntry(c)) )
|
||||
// We don't show/count internal globals as they are always
|
||||
// contained in some other global user-visible container.
|
||||
if ( id->HasVal() )
|
||||
|
@ -298,6 +298,7 @@ void ProfileLogger::Log()
|
|||
file->Write("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file->Write(fmt("%.06f Global_sizes total: %dK\n",
|
||||
network_time, mem / 1024));
|
||||
|
|
|
@ -429,7 +429,7 @@ TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr)
|
|||
if ( e->Id()->IsGlobal() )
|
||||
return TC_CONTINUE;
|
||||
|
||||
if ( scope->GetIDs()->Lookup(e->Id()->Name()) )
|
||||
if ( scope->Lookup(e->Id()->Name()) )
|
||||
return TC_CONTINUE;
|
||||
|
||||
outer_id_references.push_back(e);
|
||||
|
|
|
@ -29,10 +29,10 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
|
|||
|
||||
// find all option names and their types.
|
||||
auto globals = global_scope()->Vars();
|
||||
auto c = globals->InitForIteration();
|
||||
|
||||
while ( auto id = globals->NextEntry(c) )
|
||||
for ( const auto& entry : globals )
|
||||
{
|
||||
ID* id = entry.second;
|
||||
if ( ! id->IsOption() )
|
||||
continue;
|
||||
|
||||
|
|
16
src/zeek.bif
16
src/zeek.bif
|
@ -1895,11 +1895,11 @@ function reading_traces%(%): bool
|
|||
function global_sizes%(%): var_sizes
|
||||
%{
|
||||
TableVal* sizes = new TableVal(var_sizes);
|
||||
PDict<ID>* globals = global_scope()->Vars();
|
||||
IterCookie* c = globals->InitForIteration();
|
||||
auto globals = global_scope()->Vars();
|
||||
|
||||
ID* id;
|
||||
while ( (id = globals->NextEntry(c)) )
|
||||
for ( const auto& global : globals )
|
||||
{
|
||||
ID* id = global.second;
|
||||
if ( id->HasVal() )
|
||||
{
|
||||
Val* id_name = new StringVal(id->Name());
|
||||
|
@ -1907,6 +1907,7 @@ function global_sizes%(%): var_sizes
|
|||
sizes->Assign(id_name, id_size);
|
||||
Unref(id_name);
|
||||
}
|
||||
}
|
||||
|
||||
return sizes;
|
||||
%}
|
||||
|
@ -1922,12 +1923,11 @@ function global_sizes%(%): var_sizes
|
|||
function global_ids%(%): id_table
|
||||
%{
|
||||
TableVal* ids = new TableVal(id_table);
|
||||
PDict<ID>* globals = global_scope()->Vars();
|
||||
IterCookie* c = globals->InitForIteration();
|
||||
auto globals = global_scope()->Vars();
|
||||
|
||||
ID* id;
|
||||
while ( (id = globals->NextEntry(c)) )
|
||||
for ( const auto& global : globals )
|
||||
{
|
||||
ID* id = global.second;
|
||||
RecordVal* rec = new RecordVal(script_id);
|
||||
rec->Assign(0, new StringVal(type_name(id->Type()->Tag())));
|
||||
rec->Assign(1, val_mgr->GetBool(id->IsExport()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue