Merge remote-tracking branch 'origin/master' into topic/johanna/gh-859

This commit is contained in:
Johanna Amann 2021-06-29 15:09:56 +01:00
commit e4b2fa50a9
571 changed files with 40145 additions and 11997 deletions

View file

@ -45,6 +45,8 @@ class PrefixTable;
class CompositeHash;
class HashKey;
class ZBody;
} // namespace detail
namespace run_state {
@ -110,6 +112,7 @@ public:
virtual ValPtr SizeVal() const;
// Bytes in total value object.
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
virtual unsigned int MemoryAllocation() const;
// Add this value to the given value (if appropriate).
@ -186,6 +189,9 @@ UNDERLYING_ACCESSOR_DECL(TypeVal, zeek::Type*, AsType)
OpaqueVal* AsOpaqueVal();
const OpaqueVal* AsOpaqueVal() const;
TypeVal* AsTypeVal();
const TypeVal* AsTypeVal() const;
void Describe(ODesc* d) const override;
virtual void DescribeReST(ODesc* d) const;
@ -450,10 +456,11 @@ public:
// Returns a masked port number
static uint32_t Mask(uint32_t port_num, TransportProto port_type);
protected:
friend class ValManager;
// Only meant for use by ValManager and compiled-to-C++ script
// functions.
PortVal(uint32_t p);
protected:
void ValDescribe(ODesc* d) const override;
ValPtr DoClone(CloneState* state) override;
@ -480,6 +487,7 @@ public:
const IPAddr& Get() const { return *addr_val; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override;
protected:
@ -509,6 +517,7 @@ public:
const IPPrefix& Get() const { return *subnet_val; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override;
protected:
@ -544,6 +553,7 @@ public:
const String* Get() const { return string_val; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override;
StringValPtr Replace(RE_Matcher* re, const String& repl,
@ -605,6 +615,7 @@ public:
const RE_Matcher* Get() const { return re_val; }
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override;
protected:
@ -654,6 +665,7 @@ public:
void Describe(ODesc* d) const override;
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override;
protected:
@ -927,6 +939,7 @@ public:
// the function in the frame allowing it to capture its closure.
void InitDefaultFunc(detail::Frame* f);
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override;
void ClearTimer(detail::Timer* t)
@ -1173,13 +1186,15 @@ public:
/**
* Appends a value to the record's fields. The caller is responsible
* for ensuring that fields are appended in the correct order and
* with the correct type.
* with the correct type. The type needs to be passed in because
* it's unsafe to take it from v when the field's type is "any" while
* v is a concrete type.
* @param v The value to append.
*/
void AppendField(ValPtr v)
void AppendField(ValPtr v, const TypePtr& t)
{
if ( v )
record_val->emplace_back(ZVal(v, v->GetType()));
record_val->emplace_back(ZVal(v, t));
else
record_val->emplace_back(std::nullopt);
}
@ -1202,6 +1217,18 @@ public:
return (*record_val)[field] ? true : false;
}
/**
* Returns true if the given field is in the record, false if
* it's missing.
* @param field The field name to retrieve.
* @return Whether there's a value for the given field name.
*/
bool HasField(const char *field) const
{
int idx = GetType()->AsRecordType()->FieldOffset(field);
return (idx != -1) && HasField(idx);
}
/**
* Returns the value of a given field index.
* @param field The field index to retrieve.
@ -1380,6 +1407,7 @@ public:
RecordValPtr CoerceTo(RecordTypePtr other,
bool allow_orphaning = false);
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See GHI-572.")]]
unsigned int MemoryAllocation() const override;
void DescribeReST(ODesc* d) const override;
@ -1393,6 +1421,23 @@ public:
static void DoneParsing();
protected:
friend class zeek::detail::ZBody;
// For use by low-level ZAM instructions. Caller assumes
// responsibility for memory management. The first version
// allows manipulation of whether the field is present at all.
// The second version ensures that the optional value is present.
std::optional<ZVal>& RawOptField(int field)
{ return (*record_val)[field]; }
ZVal& RawField(int field)
{
auto& f = RawOptField(field);
if ( ! f )
f = ZVal();
return *f;
}
ValPtr DoClone(CloneState* state) override;
void AddedField(int field)
@ -1436,6 +1481,8 @@ protected:
friend class Val;
friend class EnumType;
friend EnumValPtr make_enum__CPP(TypePtr t, int i);
template<class T, class... Ts>
friend IntrusivePtr<T> make_intrusive(Ts&&... args);
@ -1468,6 +1515,8 @@ protected:
class VectorVal final : public Val, public notifier::detail::Modifiable {
public:
explicit VectorVal(VectorTypePtr t);
VectorVal(VectorTypePtr t, std::vector<std::optional<ZVal>>* vals);
~VectorVal() override;
ValPtr SizeVal() const override;
@ -1548,8 +1597,29 @@ public:
*/
VectorValPtr Order(Func* cmp_func = nullptr);
/**
* Ensures that the vector can be used as a "vector of t". In
* general, this is only relevant for objects that are typed as
* "vector of any", making sure that each element is in fact
* of type "t", and is internally represented as such so that
* this object can be used directly without any special-casing.
*
* Returns true if the object is compatible with "vector of t"
* (including if it's not a vector-of-any but instead already a
* vector-of-t), false if not compatible.
* @param t The yield type to concretize to.
* @return True if the object is compatible with vector-of-t, false
* if not.
*/
bool Concretize(const TypePtr& t);
ValPtr ValAt(unsigned int index) const { return At(index); }
bool Has(unsigned int index) const
// Version to use once std::optional implementation is merged.
// { return index < vector_val->size() && vector_val[index]; }
{ return At(index) != nullptr; }
/**
* Returns the given element in a given underlying representation.
* Enables efficient vector access. Caller must ensure that the
@ -1558,8 +1628,12 @@ public:
* @param index The position in the vector of the element to return.
* @return The element's underlying value.
*/
bro_int_t IntAt(unsigned int index) const
{ return (*vector_val)[index]->int_val; }
bro_uint_t CountAt(unsigned int index) const
{ return (*vector_val)[index]->uint_val; }
double DoubleAt(unsigned int index) const
{ return (*vector_val)[index]->double_val; }
const RecordVal* RecordValAt(unsigned int index) const
{ return (*vector_val)[index]->record_val; }
bool BoolAt(unsigned int index) const
@ -1569,6 +1643,10 @@ public:
const String* StringAt(unsigned int index) const
{ return StringValAt(index)->AsString(); }
// Only intended for low-level access by compiled code.
const auto& RawVec() const { return vector_val; }
auto& RawVec() { return vector_val; }
protected:
/**
* Returns the element at a given index or nullptr if it does not exist.