mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Remove MutableVal class.
This commit is contained in:
parent
062a1ee6b3
commit
7bd738865c
11 changed files with 39 additions and 55 deletions
4
src/ID.h
4
src/ID.h
|
@ -70,10 +70,6 @@ public:
|
|||
|
||||
bool IsRedefinable() const { return FindAttr(ATTR_REDEF) != 0; }
|
||||
|
||||
// Returns true if ID is one of those internal globally unique IDs
|
||||
// to which MutableVals are bound (there name start with a '#').
|
||||
bool IsInternalGlobal() const { return name && name[0] == '#'; }
|
||||
|
||||
void SetAttrs(Attributes* attr);
|
||||
void AddAttrs(Attributes* attr);
|
||||
void RemoveAttr(attr_tag a);
|
||||
|
|
|
@ -14,8 +14,8 @@ notifier::Registry::~Registry()
|
|||
|
||||
void notifier::Registry::Register(Modifiable* m, notifier::Notifier* notifier)
|
||||
{
|
||||
DBG_LOG(DBG_NOTIFIERS, "registering modifiable %p for notifier %s",
|
||||
m, notifier->Name());
|
||||
DBG_LOG(DBG_NOTIFIERS, "registering modifiable %p for notifier %p",
|
||||
m, notifier);
|
||||
|
||||
registrations.insert({m, notifier});
|
||||
++m->notifiers;
|
||||
|
@ -23,16 +23,16 @@ void notifier::Registry::Register(Modifiable* m, notifier::Notifier* notifier)
|
|||
|
||||
void notifier::Registry::Unregister(Modifiable* m, notifier::Notifier* notifier)
|
||||
{
|
||||
DBG_LOG(DBG_NOTIFIERS, "unregistering modifiable %p from notifier %s",
|
||||
m, notifier->Name());
|
||||
DBG_LOG(DBG_NOTIFIERS, "unregistering modifiable %p from notifier %p",
|
||||
m, notifier);
|
||||
|
||||
auto x = registrations.equal_range(m);
|
||||
for ( auto i = x.first; i != x.second; i++ )
|
||||
{
|
||||
if ( i->second == notifier )
|
||||
{
|
||||
registrations.erase(i);
|
||||
--i->first->notifiers;
|
||||
registrations.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -40,9 +40,14 @@ void notifier::Registry::Unregister(Modifiable* m, notifier::Notifier* notifier)
|
|||
|
||||
void notifier::Registry::Unregister(Modifiable* m)
|
||||
{
|
||||
DBG_LOG(DBG_NOTIFIERS, "unregistering modifiable %p from all notifiers",
|
||||
m);
|
||||
|
||||
auto x = registrations.equal_range(m);
|
||||
for ( auto i = x.first; i != x.second; i++ )
|
||||
Unregister(m, i->second);
|
||||
--i->first->notifiers;
|
||||
|
||||
registrations.erase(x.first, x.second);
|
||||
}
|
||||
|
||||
void notifier::Registry::Modified(Modifiable* m)
|
||||
|
@ -54,8 +59,8 @@ void notifier::Registry::Modified(Modifiable* m)
|
|||
i->second->Modified(m);
|
||||
}
|
||||
|
||||
const char* notifier::Notifier::Name() const
|
||||
notifier::Modifiable::~Modifiable()
|
||||
{
|
||||
return fmt("%p", this);
|
||||
if ( notifiers )
|
||||
registry.Unregister(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "util.h"
|
||||
#include "DebugLogger.h"
|
||||
|
||||
namespace notifier {
|
||||
|
||||
|
@ -25,11 +26,18 @@ class Modifiable;
|
|||
|
||||
class Notifier {
|
||||
public:
|
||||
virtual ~Notifier() { }
|
||||
Notifier()
|
||||
{
|
||||
DBG_LOG(DBG_NOTIFIERS, "creating notifier %p", this);
|
||||
}
|
||||
|
||||
// Called afger a change has been performed.
|
||||
virtual ~Notifier()
|
||||
{
|
||||
DBG_LOG(DBG_NOTIFIERS, "destroying notifier %p", this);
|
||||
}
|
||||
|
||||
// Called after a change has been performed.
|
||||
virtual void Modified(Modifiable* m) = 0;
|
||||
virtual const char* Name() const; // for debugging
|
||||
};
|
||||
|
||||
// Singleton class.
|
||||
|
@ -67,12 +75,7 @@ protected:
|
|||
friend class Registry;
|
||||
|
||||
Modifiable() {}
|
||||
~Modifiable()
|
||||
{
|
||||
if ( notifiers )
|
||||
registry.Unregister(this);
|
||||
|
||||
};
|
||||
virtual ~Modifiable();
|
||||
|
||||
void Modified()
|
||||
{
|
||||
|
|
|
@ -255,7 +255,7 @@ void ProfileLogger::Log()
|
|||
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() && ! id->IsInternalGlobal() )
|
||||
if ( id->HasVal() )
|
||||
{
|
||||
Val* v = id->ID_Val();
|
||||
|
||||
|
|
|
@ -385,7 +385,7 @@ void Trigger::Register(ID* id)
|
|||
notifier::registry.Register(id, this);
|
||||
|
||||
Ref(id);
|
||||
objs.push_back(id);
|
||||
objs.push_back({id, id});
|
||||
}
|
||||
|
||||
void Trigger::Register(Val* val)
|
||||
|
@ -397,13 +397,18 @@ void Trigger::Register(Val* val)
|
|||
notifier::registry.Register(val->Modifiable(), this);
|
||||
|
||||
Ref(val);
|
||||
objs.push_back(val);
|
||||
objs.emplace_back(val, val->Modifiable());
|
||||
}
|
||||
|
||||
void Trigger::UnregisterAll()
|
||||
{
|
||||
DBG_LOG(DBG_NOTIFIERS, "%s: unregistering all", Name());
|
||||
|
||||
for ( auto o : objs )
|
||||
Unref(o); // this will unregister with the registry as well
|
||||
{
|
||||
notifier::registry.Unregister(o.second, this);
|
||||
Unref(o.first);
|
||||
}
|
||||
|
||||
objs.clear();
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
void Modified(notifier::Modifiable* m) override
|
||||
{ QueueTrigger(this); }
|
||||
|
||||
const char* Name() const override;
|
||||
const char* Name() const;
|
||||
|
||||
static void QueueTrigger(Trigger* trigger);
|
||||
|
||||
|
@ -102,7 +102,7 @@ private:
|
|||
bool delayed; // true if a function call is currently being delayed
|
||||
bool disabled;
|
||||
|
||||
std::vector<BroObj *> objs;
|
||||
std::vector<std::pair<BroObj *, notifier::Modifiable*>> objs;
|
||||
|
||||
typedef map<const CallExpr*, Val*> ValCache;
|
||||
ValCache cache;
|
||||
|
|
|
@ -693,10 +693,6 @@ bool is_atomic_type(const BroType* t);
|
|||
// True if the given type tag corresponds to a function type.
|
||||
#define IsFunc(t) (t == TYPE_FUNC)
|
||||
|
||||
// True if the given type tag corresponds to mutable type.
|
||||
#define IsMutable(t) \
|
||||
(t == TYPE_RECORD || t == TYPE_TABLE || t == TYPE_VECTOR)
|
||||
|
||||
// True if the given type type is a vector.
|
||||
#define IsVector(t) (t == TYPE_VECTOR)
|
||||
|
||||
|
|
|
@ -349,10 +349,6 @@ void Val::ValDescribeReST(ODesc* d) const
|
|||
}
|
||||
}
|
||||
|
||||
MutableVal::~MutableVal()
|
||||
{
|
||||
}
|
||||
|
||||
IntervalVal::IntervalVal(double quantity, double units) :
|
||||
Val(quantity * units, TYPE_INTERVAL)
|
||||
{
|
||||
|
|
14
src/Val.h
14
src/Val.h
|
@ -49,7 +49,6 @@ class RecordVal;
|
|||
class ListVal;
|
||||
class StringVal;
|
||||
class EnumVal;
|
||||
class MutableVal;
|
||||
|
||||
class VectorVal;
|
||||
|
||||
|
@ -320,11 +319,6 @@ public:
|
|||
CONST_CONVERTER(TYPE_STRING, StringVal*, AsStringVal)
|
||||
CONST_CONVERTER(TYPE_VECTOR, VectorVal*, AsVectorVal)
|
||||
|
||||
bool IsMutableVal() const
|
||||
{
|
||||
return IsMutable(type->Tag());
|
||||
}
|
||||
|
||||
void Describe(ODesc* d) const override;
|
||||
virtual void DescribeReST(ODesc* d) const;
|
||||
|
||||
|
@ -486,14 +480,6 @@ private:
|
|||
|
||||
extern ValManager* val_mgr;
|
||||
|
||||
class MutableVal : public Val {
|
||||
protected:
|
||||
explicit MutableVal(BroType* t) : Val(t) {}
|
||||
|
||||
MutableVal() {}
|
||||
~MutableVal() override;
|
||||
};
|
||||
|
||||
#define Microseconds 1e-6
|
||||
#define Milliseconds 1e-3
|
||||
#define Seconds 1.0
|
||||
|
|
|
@ -1819,7 +1819,7 @@ function global_sizes%(%): var_sizes
|
|||
|
||||
ID* id;
|
||||
while ( (id = globals->NextEntry(c)) )
|
||||
if ( id->HasVal() && ! id->IsInternalGlobal() )
|
||||
if ( id->HasVal() )
|
||||
{
|
||||
Val* id_name = new StringVal(id->Name());
|
||||
Val* id_size = val_mgr->GetCount(id->ID_Val()->MemoryAllocation());
|
||||
|
@ -1847,9 +1847,6 @@ function global_ids%(%): id_table
|
|||
ID* id;
|
||||
while ( (id = globals->NextEntry(c)) )
|
||||
{
|
||||
if ( id->IsInternalGlobal() )
|
||||
continue;
|
||||
|
||||
RecordVal* rec = new RecordVal(script_id);
|
||||
rec->Assign(0, new StringVal(type_name(id->Type()->Tag())));
|
||||
rec->Assign(1, val_mgr->GetBool(id->IsExport()));
|
||||
|
|
|
@ -33,7 +33,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
|
|||
|
||||
while ( auto id = globals->NextEntry(c) )
|
||||
{
|
||||
if ( id->IsInternalGlobal() || ! id->IsOption() )
|
||||
if ( ! id->IsOption() )
|
||||
continue;
|
||||
|
||||
if ( id->Type()->Tag() == TYPE_RECORD ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue