Remove MutableVal class.

This commit is contained in:
Robin Sommer 2019-06-06 23:48:31 +00:00
parent 062a1ee6b3
commit 7bd738865c
11 changed files with 39 additions and 55 deletions

View file

@ -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);

View file

@ -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);
}

View file

@ -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()
{

View file

@ -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();

View file

@ -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();
}

View file

@ -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;

View file

@ -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)

View file

@ -349,10 +349,6 @@ void Val::ValDescribeReST(ODesc* d) const
}
}
MutableVal::~MutableVal()
{
}
IntervalVal::IntervalVal(double quantity, double units) :
Val(quantity * units, TYPE_INTERVAL)
{

View file

@ -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

View file

@ -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()));

View file

@ -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 ||