mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 01:28:20 +00:00
Type: return IntrusivePtr
This commit is contained in:
parent
0a6ddfb6b5
commit
ba35ebec4c
38 changed files with 319 additions and 334 deletions
80
src/Val.h
80
src/Val.h
|
@ -154,7 +154,7 @@ public:
|
|||
~Val() override;
|
||||
|
||||
Val* Ref() { ::Ref(this); return this; }
|
||||
Val* Clone();
|
||||
IntrusivePtr<Val> Clone();
|
||||
|
||||
int IsZero() const;
|
||||
int IsOne() const;
|
||||
|
@ -169,7 +169,7 @@ public:
|
|||
|
||||
// Returns a new Val with the "size" of this Val. What constitutes
|
||||
// size depends on the Val's type.
|
||||
virtual Val* SizeVal() const;
|
||||
virtual IntrusivePtr<Val> SizeVal() const;
|
||||
|
||||
// Bytes in total value object.
|
||||
virtual unsigned int MemoryAllocation() const;
|
||||
|
@ -323,9 +323,9 @@ public:
|
|||
|
||||
static bool WouldOverflow(const BroType* from_type, const BroType* to_type, const Val* val);
|
||||
|
||||
TableVal* GetRecordFields();
|
||||
IntrusivePtr<TableVal> GetRecordFields();
|
||||
|
||||
StringVal* ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr);
|
||||
IntrusivePtr<StringVal> ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -379,17 +379,13 @@ protected:
|
|||
// Caches a cloned value for later reuse during the same
|
||||
// cloning operation. For recursive types, call this *before*
|
||||
// descending down.
|
||||
Val* NewClone(Val *src, Val* dst)
|
||||
{
|
||||
clones.insert(std::make_pair(src, dst));
|
||||
return dst;
|
||||
}
|
||||
IntrusivePtr<Val> NewClone(Val *src, IntrusivePtr<Val> dst);
|
||||
|
||||
std::unordered_map<Val*, Val*> clones;
|
||||
};
|
||||
|
||||
Val* Clone(CloneState* state);
|
||||
virtual Val* DoClone(CloneState* state);
|
||||
IntrusivePtr<Val> Clone(CloneState* state);
|
||||
virtual IntrusivePtr<Val> DoClone(CloneState* state);
|
||||
|
||||
BroValUnion val;
|
||||
BroType* type;
|
||||
|
@ -476,7 +472,7 @@ protected:
|
|||
|
||||
class PortVal : public Val {
|
||||
public:
|
||||
Val* SizeVal() const override { return val_mgr->GetInt(val.uint_val); }
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
// Returns the port number in host order (not including the mask).
|
||||
uint32_t Port() const;
|
||||
|
@ -507,7 +503,7 @@ protected:
|
|||
PortVal(uint32_t p);
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
class AddrVal : public Val {
|
||||
|
@ -516,7 +512,7 @@ public:
|
|||
explicit AddrVal(const std::string& text);
|
||||
~AddrVal() override;
|
||||
|
||||
Val* SizeVal() const override;
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
// Constructor for address already in network order.
|
||||
explicit AddrVal(uint32_t addr); // IPv4.
|
||||
|
@ -526,7 +522,7 @@ public:
|
|||
unsigned int MemoryAllocation() const override;
|
||||
|
||||
protected:
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
class SubNetVal : public Val {
|
||||
|
@ -539,7 +535,7 @@ public:
|
|||
explicit SubNetVal(const IPPrefix& prefix);
|
||||
~SubNetVal() override;
|
||||
|
||||
Val* SizeVal() const override;
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
const IPAddr& Prefix() const;
|
||||
int Width() const;
|
||||
|
@ -551,7 +547,7 @@ public:
|
|||
|
||||
protected:
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
class StringVal : public Val {
|
||||
|
@ -561,7 +557,7 @@ public:
|
|||
explicit StringVal(const string& s);
|
||||
StringVal(int length, const char* s);
|
||||
|
||||
Val* SizeVal() const override;
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
int Len();
|
||||
const u_char* Bytes();
|
||||
|
@ -581,7 +577,7 @@ public:
|
|||
|
||||
protected:
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
class PatternVal : public Val {
|
||||
|
@ -597,7 +593,7 @@ public:
|
|||
|
||||
protected:
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
// ListVals are mainly used to index tables that have more than one
|
||||
|
@ -609,7 +605,7 @@ public:
|
|||
|
||||
TypeTag BaseTag() const { return tag; }
|
||||
|
||||
Val* SizeVal() const override { return val_mgr->GetCount(vals.length()); }
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
int Length() const { return vals.length(); }
|
||||
Val* Index(const int n) { return vals[n]; }
|
||||
|
@ -638,7 +634,7 @@ public:
|
|||
unsigned int MemoryAllocation() const override;
|
||||
|
||||
protected:
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
|
||||
val_list vals;
|
||||
TypeTag tag;
|
||||
|
@ -656,13 +652,7 @@ public:
|
|||
int(network_time - bro_start_network_time);
|
||||
}
|
||||
|
||||
TableEntryVal* Clone(Val::CloneState* state)
|
||||
{
|
||||
auto rval = new TableEntryVal(val ? val->Clone(state) : nullptr);
|
||||
rval->last_access_time = last_access_time;
|
||||
rval->expire_access_time = expire_access_time;
|
||||
return rval;
|
||||
}
|
||||
TableEntryVal* Clone(Val::CloneState* state);
|
||||
|
||||
~TableEntryVal() { }
|
||||
|
||||
|
@ -720,7 +710,7 @@ public:
|
|||
int Assign(Val* index, HashKey* k, IntrusivePtr<Val> new_val);
|
||||
int Assign(Val* index, HashKey* k, Val* new_val);
|
||||
|
||||
Val* SizeVal() const override { return val_mgr->GetCount(Size()); }
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
// Add the entire contents of the table to the given value,
|
||||
// which must also be a TableVal.
|
||||
|
@ -763,17 +753,17 @@ public:
|
|||
// Returns the element's value if it exists in the table,
|
||||
// nil otherwise. Note, "index" is not const because we
|
||||
// need to Ref/Unref it when calling the default function.
|
||||
Val* Lookup(Val* index, bool use_default_val = true);
|
||||
IntrusivePtr<Val> Lookup(Val* index, bool use_default_val = true);
|
||||
|
||||
// For a table[subnet]/set[subnet], return all subnets that cover
|
||||
// the given subnet.
|
||||
// Causes an internal error if called for any other kind of table.
|
||||
VectorVal* LookupSubnets(const SubNetVal* s);
|
||||
IntrusivePtr<VectorVal> LookupSubnets(const SubNetVal* s);
|
||||
|
||||
// For a set[subnet]/table[subnet], return a new table that only contains
|
||||
// entries that cover the given subnet.
|
||||
// Causes an internal error if called for any other kind of table.
|
||||
TableVal* LookupSubnetValues(const SubNetVal* s);
|
||||
IntrusivePtr<TableVal> LookupSubnetValues(const SubNetVal* s);
|
||||
|
||||
// Sets the timestamp for the given index to network time.
|
||||
// Returns false if index does not exist.
|
||||
|
@ -833,7 +823,7 @@ protected:
|
|||
int CheckAndAssign(Val* index, IntrusivePtr<Val> new_val);
|
||||
|
||||
// Calculates default value for index. Returns 0 if none.
|
||||
Val* Default(Val* index);
|
||||
IntrusivePtr<Val> Default(Val* index);
|
||||
|
||||
// Returns true if item expiration is enabled.
|
||||
bool ExpirationEnabled() { return expire_time != 0; }
|
||||
|
@ -853,7 +843,7 @@ protected:
|
|||
// Calls &change_func. Does not take ownership of values. (Refs if needed).
|
||||
void CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe);
|
||||
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
|
||||
TableType* table_type;
|
||||
CompositeHash* table_hash;
|
||||
|
@ -874,8 +864,7 @@ public:
|
|||
explicit RecordVal(RecordType* t, bool init_fields = true);
|
||||
~RecordVal() override;
|
||||
|
||||
Val* SizeVal() const override
|
||||
{ return val_mgr->GetCount(Type()->AsRecordType()->NumFields()); }
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
void Assign(int field, IntrusivePtr<Val> new_val);
|
||||
void Assign(int field, Val* new_val);
|
||||
|
@ -898,7 +887,7 @@ public:
|
|||
/**
|
||||
* Returns a "record_field_table" value for introspection purposes.
|
||||
*/
|
||||
TableVal* GetRecordFieldsVal() const;
|
||||
IntrusivePtr<TableVal> GetRecordFieldsVal() const;
|
||||
|
||||
// This is an experiment to associate a BroObj within the
|
||||
// event engine to a record value in bro script.
|
||||
|
@ -916,8 +905,8 @@ public:
|
|||
//
|
||||
// The *allow_orphaning* parameter allows for a record to be demoted
|
||||
// down to a record type that contains less fields.
|
||||
RecordVal* CoerceTo(const RecordType* other, Val* aggr, bool allow_orphaning = false) const;
|
||||
RecordVal* CoerceTo(RecordType* other, bool allow_orphaning = false);
|
||||
IntrusivePtr<RecordVal> CoerceTo(const RecordType* other, Val* aggr, bool allow_orphaning = false) const;
|
||||
IntrusivePtr<RecordVal> CoerceTo(RecordType* other, bool allow_orphaning = false);
|
||||
|
||||
unsigned int MemoryAllocation() const override;
|
||||
void DescribeReST(ODesc* d) const override;
|
||||
|
@ -930,7 +919,7 @@ public:
|
|||
static void ResizeParseTimeRecords();
|
||||
|
||||
protected:
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
|
||||
BroObj* origin;
|
||||
|
||||
|
@ -939,7 +928,7 @@ protected:
|
|||
|
||||
class EnumVal : public Val {
|
||||
public:
|
||||
Val* SizeVal() const override { return val_mgr->GetInt(val.int_val); }
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
protected:
|
||||
friend class Val;
|
||||
|
@ -950,7 +939,7 @@ protected:
|
|||
}
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -959,8 +948,7 @@ public:
|
|||
explicit VectorVal(VectorType* t);
|
||||
~VectorVal() override;
|
||||
|
||||
Val* SizeVal() const override
|
||||
{ return val_mgr->GetCount(uint32_t(val.vector_val->size())); }
|
||||
IntrusivePtr<Val> SizeVal() const override;
|
||||
|
||||
// Returns false if the type of the argument was wrong.
|
||||
// The vector will automatically grow to accomodate the index.
|
||||
|
@ -1015,7 +1003,7 @@ public:
|
|||
|
||||
protected:
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
Val* DoClone(CloneState* state) override;
|
||||
IntrusivePtr<Val> DoClone(CloneState* state) override;
|
||||
|
||||
VectorType* vector_type;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue