Merge remote-tracking branch 'origin/topic/timw/266-namespaces'

Merge adjustments:

- Preserved original `base_type_no_ref` argument type as ::TypeTag
- Removed superfluous #pragma guard around deprecated TableVal ctor
- Clarify NEWS regarding MetaHook{Pre,Post} deprecations
- Simplify some `::zeek::` qualifications to just `zeek::`
- Prefixed FORWARD_DECLARE_NAMESPACED macro with ZEEK_

* origin/topic/timw/266-namespaces:
  Disable some deprecation diagnostics for GCC
  Rename BroType to Type
  Update NEWS
  Review cleanup
  Move Type types to zeek namespace
  Move Flare/Pipe from the bro namespace to zeek::detail
  Move Attr to the zeek::detail namespace
  Move Trigger into the zeek::detail namespace
  Move ID to the zeek::detail namespace
  Move Anon.h into zeek::detail namespace
  Mark all of the aliased classes in plugin/Plugin.h deprecated, and fix all of the plugins that were using them
  Move all of the base plugin classes into the zeek::plugin namespace
  Expr: move all classes into zeek::detail
  Stmt: move Stmt classes into zeek::detail namespace
  Add utility macro for creating namespaced aliases for classes
This commit is contained in:
Jon Siwek 2020-06-11 23:12:02 -07:00
commit d4f3cad7d1
256 changed files with 4277 additions and 3501 deletions

View file

@ -14,8 +14,59 @@
#include <list>
#include <optional>
// BRO types.
class EnumVal;
class TableVal;
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(ListExpr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail);
enum [[deprecated("Remove in v4.1. Use zeek::TypeTag instead.")]] TypeTag {
TYPE_VOID, // 0
TYPE_BOOL, // 1
TYPE_INT, // 2
TYPE_COUNT, // 3
TYPE_COUNTER, // 4
TYPE_DOUBLE, // 5
TYPE_TIME, // 6
TYPE_INTERVAL, // 7
TYPE_STRING, // 8
TYPE_PATTERN, // 9
TYPE_ENUM, // 10
TYPE_TIMER, // 11
TYPE_PORT, // 12
TYPE_ADDR, // 13
TYPE_SUBNET, // 14
TYPE_ANY, // 15
TYPE_TABLE, // 16
TYPE_UNION, // 17
TYPE_RECORD, // 18
TYPE_LIST, // 19
TYPE_FUNC, // 20
TYPE_FILE, // 21
TYPE_VECTOR, // 22
TYPE_OPAQUE, // 23
TYPE_TYPE, // 24
TYPE_ERROR // 25
#define NUM_TYPES (int(TYPE_ERROR) + 1)
};
enum [[deprecated("Remove in v4.1. Use zeek::FunctionFlavor instead.")]] function_flavor {
FUNC_FLAVOR_FUNCTION,
FUNC_FLAVOR_EVENT,
FUNC_FLAVOR_HOOK
};
enum [[deprecated("Remove in v4.1. Use zeek::InternalTypeTag instead.")]] InternalTypeTag : uint16_t {
TYPE_INTERNAL_VOID,
TYPE_INTERNAL_INT, TYPE_INTERNAL_UNSIGNED, TYPE_INTERNAL_DOUBLE,
TYPE_INTERNAL_STRING, TYPE_INTERNAL_ADDR, TYPE_INTERNAL_SUBNET,
TYPE_INTERNAL_OTHER, TYPE_INTERNAL_ERROR
};
namespace zeek {
// BRO types.
enum TypeTag {
TYPE_VOID, // 0
TYPE_BOOL, // 1
@ -46,12 +97,15 @@ enum TypeTag {
#define NUM_TYPES (int(TYPE_ERROR) + 1)
};
// Returns the name of the type.
extern const char* type_name(TypeTag t);
constexpr bool is_network_order(TypeTag tag) noexcept
{
return tag == TYPE_PORT;
}
enum function_flavor {
enum FunctionFlavor {
FUNC_FLAVOR_FUNCTION,
FUNC_FLAVOR_EVENT,
FUNC_FLAVOR_HOOK
@ -116,34 +170,34 @@ constexpr InternalTypeTag to_internal_type_tag(TypeTag tag) noexcept
return TYPE_INTERNAL_VOID;
}
// Returns the name of the type.
extern const char* type_name(TypeTag t);
class Expr;
class Attributes;
class TypeList;
class TableType;
class SetType;
class RecordType;
class SubNetType;
class FuncType;
class ListExpr;
class EnumType;
class VectorType;
class TypeType;
class OpaqueType;
class EnumVal;
class TableVal;
const int DOES_NOT_MATCH_INDEX = 0;
const int MATCHES_INDEX_SCALAR = 1;
const int MATCHES_INDEX_VECTOR = 2;
constexpr int DOES_NOT_MATCH_INDEX = 0;
constexpr int MATCHES_INDEX_SCALAR = 1;
constexpr int MATCHES_INDEX_VECTOR = 2;
class BroType : public BroObj {
class Type : public BroObj {
public:
static inline const IntrusivePtr<BroType> nil;
static inline const IntrusivePtr<Type> nil;
explicit BroType(TypeTag tag, bool base_type = false);
explicit Type(zeek::TypeTag tag, bool base_type = false);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag instead.")]]
explicit Type(::TypeTag tag, bool base_type = false)
: Type(static_cast<zeek::TypeTag>(tag), base_type)
{}
#pragma GCC diagnostic pop
// Performs a shallow clone operation of the Bro type.
// This especially means that especially for tables the types
@ -153,7 +207,7 @@ public:
// Clone operations will mostly be implemented in the derived classes;
// in addition cloning will be limited to classes that can be reached by
// the script-level.
virtual IntrusivePtr<BroType> ShallowClone();
virtual IntrusivePtr<Type> ShallowClone();
TypeTag Tag() const { return tag; }
InternalTypeTag InternalType() const { return internal_tag; }
@ -168,18 +222,18 @@ public:
// if it matches and produces a vector result; and
// DOES_NOT_MATCH_INDEX = 0 if it can't match (or the type
// is not an indexable type).
virtual int MatchesIndex(ListExpr* index) const;
virtual int MatchesIndex(zeek::detail::ListExpr* index) const;
// Returns the type yielded by this type. For example, if
// this type is a table[string] of port, then returns the "port"
// type. Returns nil if this is not an index type.
virtual const IntrusivePtr<BroType>& Yield() const;
virtual const IntrusivePtr<Type>& Yield() const;
[[deprecated("Remove in v4.1. Use Yield() instead.")]]
virtual BroType* YieldType()
virtual Type* YieldType()
{ return Yield().get(); }
[[deprecated("Remove in v4.1. Use Yield() instead.")]]
virtual const BroType* YieldType() const
virtual const Type* YieldType() const
{ return Yield().get(); }
// Returns true if this type is a record and contains the
@ -189,126 +243,126 @@ public:
// Returns the type of the given field, or nil if no such field.
[[deprecated("Remove in v4.1. Use RecordType::GetFieldType() directly.")]]
virtual BroType* FieldType(const char* field) const;
virtual Type* FieldType(const char* field) const;
#define CHECK_TYPE_TAG(tag_type, func_name) \
CHECK_TAG(tag, tag_type, func_name, type_name)
const TypeList* AsTypeList() const
{
CHECK_TYPE_TAG(TYPE_LIST, "BroType::AsTypeList");
CHECK_TYPE_TAG(TYPE_LIST, "Type::AsTypeList");
return (const TypeList*) this;
}
TypeList* AsTypeList()
{
CHECK_TYPE_TAG(TYPE_LIST, "BroType::AsTypeList");
CHECK_TYPE_TAG(TYPE_LIST, "Type::AsTypeList");
return (TypeList*) this;
}
const TableType* AsTableType() const
{
CHECK_TYPE_TAG(TYPE_TABLE, "BroType::AsTableType");
CHECK_TYPE_TAG(TYPE_TABLE, "Type::AsTableType");
return (const TableType*) this;
}
TableType* AsTableType()
{
CHECK_TYPE_TAG(TYPE_TABLE, "BroType::AsTableType");
CHECK_TYPE_TAG(TYPE_TABLE, "Type::AsTableType");
return (TableType*) this;
}
SetType* AsSetType()
{
if ( ! IsSet() )
BadTag("BroType::AsSetType", type_name(tag));
BadTag("Type::AsSetType", type_name(tag));
return (SetType*) this;
}
const SetType* AsSetType() const
{
if ( ! IsSet() )
BadTag("BroType::AsSetType", type_name(tag));
BadTag("Type::AsSetType", type_name(tag));
return (const SetType*) this;
}
const RecordType* AsRecordType() const
{
CHECK_TYPE_TAG(TYPE_RECORD, "BroType::AsRecordType");
CHECK_TYPE_TAG(TYPE_RECORD, "Type::AsRecordType");
return (const RecordType*) this;
}
RecordType* AsRecordType()
{
CHECK_TYPE_TAG(TYPE_RECORD, "BroType::AsRecordType");
CHECK_TYPE_TAG(TYPE_RECORD, "Type::AsRecordType");
return (RecordType*) this;
}
const SubNetType* AsSubNetType() const
{
CHECK_TYPE_TAG(TYPE_SUBNET, "BroType::AsSubNetType");
CHECK_TYPE_TAG(TYPE_SUBNET, "Type::AsSubNetType");
return (const SubNetType*) this;
}
SubNetType* AsSubNetType()
{
CHECK_TYPE_TAG(TYPE_SUBNET, "BroType::AsSubNetType");
CHECK_TYPE_TAG(TYPE_SUBNET, "Type::AsSubNetType");
return (SubNetType*) this;
}
const FuncType* AsFuncType() const
{
CHECK_TYPE_TAG(TYPE_FUNC, "BroType::AsFuncType");
CHECK_TYPE_TAG(TYPE_FUNC, "Type::AsFuncType");
return (const FuncType*) this;
}
FuncType* AsFuncType()
{
CHECK_TYPE_TAG(TYPE_FUNC, "BroType::AsFuncType");
CHECK_TYPE_TAG(TYPE_FUNC, "Type::AsFuncType");
return (FuncType*) this;
}
const EnumType* AsEnumType() const
{
CHECK_TYPE_TAG(TYPE_ENUM, "BroType::AsEnumType");
CHECK_TYPE_TAG(TYPE_ENUM, "Type::AsEnumType");
return (EnumType*) this;
}
EnumType* AsEnumType()
{
CHECK_TYPE_TAG(TYPE_ENUM, "BroType::AsEnumType");
CHECK_TYPE_TAG(TYPE_ENUM, "Type::AsEnumType");
return (EnumType*) this;
}
const VectorType* AsVectorType() const
{
CHECK_TYPE_TAG(TYPE_VECTOR, "BroType::AsVectorType");
CHECK_TYPE_TAG(TYPE_VECTOR, "Type::AsVectorType");
return (VectorType*) this;
}
OpaqueType* AsOpaqueType()
{
CHECK_TYPE_TAG(TYPE_OPAQUE, "BroType::AsOpaqueType");
CHECK_TYPE_TAG(TYPE_OPAQUE, "Type::AsOpaqueType");
return (OpaqueType*) this;
}
const OpaqueType* AsOpaqueType() const
{
CHECK_TYPE_TAG(TYPE_OPAQUE, "BroType::AsOpaqueType");
CHECK_TYPE_TAG(TYPE_OPAQUE, "Type::AsOpaqueType");
return (OpaqueType*) this;
}
VectorType* AsVectorType()
{
CHECK_TYPE_TAG(TYPE_VECTOR, "BroType::AsVectorType");
CHECK_TYPE_TAG(TYPE_VECTOR, "Type::AsVectorType");
return (VectorType*) this;
}
const TypeType* AsTypeType() const
{
CHECK_TYPE_TAG(TYPE_TYPE, "BroType::AsTypeType");
CHECK_TYPE_TAG(TYPE_TYPE, "Type::AsTypeType");
return (TypeType*) this;
}
TypeType* AsTypeType()
{
CHECK_TYPE_TAG(TYPE_TYPE, "BroType::AsTypeType");
CHECK_TYPE_TAG(TYPE_TYPE, "Type::AsTypeType");
return (TypeType*) this;
}
@ -322,7 +376,7 @@ public:
return tag == TYPE_TABLE && Yield();
}
BroType* Ref() { ::Ref(this); return this; }
Type* Ref() { ::Ref(this); return this; }
void Describe(ODesc* d) const override;
virtual void DescribeReST(ODesc* d, bool roles_only = false) const;
@ -332,16 +386,16 @@ public:
void SetName(const std::string& arg_name) { name = arg_name; }
const std::string& GetName() const { return name; }
typedef std::map<std::string, std::set<BroType*> > TypeAliasMap;
typedef std::map<std::string, std::set<Type*> > TypeAliasMap;
static std::set<BroType*> GetAliases(const std::string& type_name)
{ return BroType::type_aliases[type_name]; }
static std::set<Type*> GetAliases(const std::string& type_name)
{ return Type::type_aliases[type_name]; }
static void AddAlias(const std::string &type_name, BroType* type)
{ BroType::type_aliases[type_name].insert(type); }
static void AddAlias(const std::string &type_name, Type* type)
{ Type::type_aliases[type_name].insert(type); }
protected:
BroType() { }
Type() = default;
void SetError();
@ -355,50 +409,50 @@ private:
static TypeAliasMap type_aliases;
};
class TypeList final : public BroType {
class TypeList final : public Type {
public:
explicit TypeList(IntrusivePtr<BroType> arg_pure_type = nullptr)
: BroType(TYPE_LIST), pure_type(std::move(arg_pure_type))
explicit TypeList(IntrusivePtr<Type> arg_pure_type = nullptr)
: Type(TYPE_LIST), pure_type(std::move(arg_pure_type))
{
}
const std::vector<IntrusivePtr<BroType>>& Types() const
const std::vector<IntrusivePtr<Type>>& Types() const
{ return types; }
bool IsPure() const { return pure_type != nullptr; }
// Returns the underlying pure type, or nil if the list
// is not pure or is empty.
const IntrusivePtr<BroType>& GetPureType() const
const IntrusivePtr<Type>& GetPureType() const
{ return pure_type; }
[[deprecated("Remove in v4.1. Use GetPureType() instead.")]]
BroType* PureType() { return pure_type.get(); }
Type* PureType() { return pure_type.get(); }
[[deprecated("Remove in v4.1. Use GetPureType() instead.")]]
const BroType* PureType() const { return pure_type.get(); }
const Type* PureType() const { return pure_type.get(); }
// True if all of the types match t, false otherwise. If
// is_init is true, then the matching is done in the context
// of an initialization.
bool AllMatch(const BroType* t, bool is_init) const;
bool AllMatch(const IntrusivePtr<BroType>& t, bool is_init) const
bool AllMatch(const Type* t, bool is_init) const;
bool AllMatch(const IntrusivePtr<Type>& t, bool is_init) const
{ return AllMatch(t.get(), is_init); }
void Append(IntrusivePtr<BroType> t);
void AppendEvenIfNotPure(IntrusivePtr<BroType> t);
void Append(IntrusivePtr<Type> t);
void AppendEvenIfNotPure(IntrusivePtr<Type> t);
void Describe(ODesc* d) const override;
unsigned int MemoryAllocation() const override;
protected:
IntrusivePtr<BroType> pure_type;
std::vector<IntrusivePtr<BroType>> types;
IntrusivePtr<Type> pure_type;
std::vector<IntrusivePtr<Type>> types;
};
class IndexType : public BroType {
class IndexType : public Type {
public:
int MatchesIndex(ListExpr* index) const override;
int MatchesIndex(zeek::detail::ListExpr* index) const override;
const IntrusivePtr<TypeList>& GetIndices() const
{ return indices; }
@ -406,10 +460,10 @@ public:
[[deprecated("Remove in v4.1. Use GetIndices().")]]
TypeList* Indices() const { return indices.get(); }
const std::vector<IntrusivePtr<BroType>>& IndexTypes() const
const std::vector<IntrusivePtr<Type>>& IndexTypes() const
{ return indices->Types(); }
const IntrusivePtr<BroType>& Yield() const override
const IntrusivePtr<Type>& Yield() const override
{ return yield_type; }
void Describe(ODesc* d) const override;
@ -420,8 +474,8 @@ public:
protected:
IndexType(TypeTag t, IntrusivePtr<TypeList> arg_indices,
IntrusivePtr<BroType> arg_yield_type)
: BroType(t), indices(std::move(arg_indices)),
IntrusivePtr<Type> arg_yield_type)
: Type(t), indices(std::move(arg_indices)),
yield_type(std::move(arg_yield_type))
{
}
@ -429,14 +483,14 @@ protected:
~IndexType() override;
IntrusivePtr<TypeList> indices;
IntrusivePtr<BroType> yield_type;
IntrusivePtr<Type> yield_type;
};
class TableType : public IndexType {
public:
TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<BroType> yield);
TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<Type> yield);
IntrusivePtr<BroType> ShallowClone() override;
IntrusivePtr<Type> ShallowClone() override;
// Returns true if this table type is "unspecified", which is
// what one gets using an empty "set()" or "table()" constructor.
@ -445,22 +499,22 @@ public:
class SetType final : public TableType {
public:
SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<ListExpr> arg_elements);
SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr> arg_elements);
~SetType() override;
IntrusivePtr<BroType> ShallowClone() override;
IntrusivePtr<Type> ShallowClone() override;
[[deprecated("Remove in v4.1. Use Elements() isntead.")]]
ListExpr* SetElements() const { return elements.get(); }
zeek::detail::ListExpr* SetElements() const { return elements.get(); }
const IntrusivePtr<ListExpr>& Elements() const
const IntrusivePtr<zeek::detail::ListExpr>& Elements() const
{ return elements; }
protected:
IntrusivePtr<ListExpr> elements;
IntrusivePtr<zeek::detail::ListExpr> elements;
};
class FuncType final : public BroType {
class FuncType final : public Type {
public:
static inline const IntrusivePtr<FuncType> nil;
@ -475,9 +529,18 @@ public:
std::map<int, int> offsets;
};
FuncType(IntrusivePtr<RecordType> args, IntrusivePtr<BroType> yield,
function_flavor f);
IntrusivePtr<BroType> ShallowClone() override;
FuncType(IntrusivePtr<RecordType> args, IntrusivePtr<Type> yield,
FunctionFlavor f);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use the version that takes zeek::FunctionFlavor instead.")]]
FuncType(IntrusivePtr<RecordType> args, IntrusivePtr<Type> yield, ::function_flavor f)
: FuncType(args, yield, static_cast<FunctionFlavor>(f))
{}
#pragma GCC diagnostic pop
IntrusivePtr<Type> ShallowClone() override;
~FuncType() override;
@ -487,20 +550,27 @@ public:
const IntrusivePtr<RecordType>& Params() const
{ return args; }
const IntrusivePtr<BroType>& Yield() const override
const IntrusivePtr<Type>& Yield() const override
{ return yield; }
void SetYieldType(IntrusivePtr<BroType> arg_yield) { yield = std::move(arg_yield); }
function_flavor Flavor() const { return flavor; }
void SetYieldType(IntrusivePtr<Type> arg_yield) { yield = std::move(arg_yield); }
FunctionFlavor Flavor() const { return flavor; }
std::string FlavorString() const;
// Used to convert a function type to an event or hook type.
void ClearYieldType(function_flavor arg_flav)
void ClearYieldType(FunctionFlavor arg_flav)
{ yield = nullptr; flavor = arg_flav; }
int MatchesIndex(ListExpr* index) const override;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use the version that takes zeek::FunctionFlavor instead.")]]
void ClearYieldType(::function_flavor arg_flav)
{ yield = nullptr; flavor = static_cast<FunctionFlavor>(arg_flav); }
#pragma GCC diagnostic pop
int MatchesIndex(zeek::detail::ListExpr* index) const override;
bool CheckArgs(const type_list* args, bool is_init = false) const;
bool CheckArgs(const std::vector<IntrusivePtr<BroType>>& args,
bool CheckArgs(const std::vector<IntrusivePtr<Type>>& args,
bool is_init = false) const;
[[deprecated("Remove in v4.1. Use ParamList().")]]
@ -531,20 +601,20 @@ public:
protected:
friend IntrusivePtr<FuncType> make_intrusive<FuncType>();
FuncType() : BroType(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; }
FuncType() : Type(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; }
IntrusivePtr<RecordType> args;
IntrusivePtr<TypeList> arg_types;
IntrusivePtr<BroType> yield;
function_flavor flavor;
IntrusivePtr<Type> yield;
FunctionFlavor flavor;
std::vector<Prototype> prototypes;
};
class TypeType final : public BroType {
class TypeType final : public Type {
public:
explicit TypeType(IntrusivePtr<BroType> t) : BroType(TYPE_TYPE), type(std::move(t)) {}
IntrusivePtr<BroType> ShallowClone() override { return make_intrusive<TypeType>(type); }
explicit TypeType(IntrusivePtr<Type> t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {}
IntrusivePtr<Type> ShallowClone() override { return make_intrusive<TypeType>(type); }
const IntrusivePtr<BroType>& GetType() const
const IntrusivePtr<Type>& GetType() const
{ return type; }
template <class T>
@ -552,62 +622,66 @@ public:
{ return cast_intrusive<T>(type); }
[[deprecated("Remove in v4.1. Use GetType().")]]
BroType* Type() { return type.get(); }
zeek::Type* Type() { return type.get(); }
[[deprecated("Remove in v4.1. Use GetType().")]]
const BroType* Type() const { return type.get(); }
const zeek::Type* Type() const { return type.get(); }
protected:
IntrusivePtr<BroType> type;
IntrusivePtr<zeek::Type> type;
};
class TypeDecl final {
public:
TypeDecl() = default;
TypeDecl(const char* i, IntrusivePtr<BroType> t, IntrusivePtr<Attributes> attrs = nullptr);
TypeDecl(const char* i, IntrusivePtr<Type> t,
IntrusivePtr<zeek::detail::Attributes> attrs = nullptr);
TypeDecl(const TypeDecl& other);
~TypeDecl();
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use GetAttr().")]]
const Attr* FindAttr(attr_tag a) const
{ return attrs ? attrs->Find(a).get() : nullptr; }
const zeek::detail::Attr* FindAttr(::attr_tag a) const
{ return attrs ? attrs->Find(static_cast<zeek::detail::attr_tag>(a)).get() : nullptr; }
#pragma GCC diagnostic pop
const IntrusivePtr<Attr>& GetAttr(attr_tag a) const
{ return attrs ? attrs->Find(a) : Attr::nil; }
const IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::attr_tag a) const
{ return attrs ? attrs->Find(a) : zeek::detail::Attr::nil; }
void DescribeReST(ODesc* d, bool roles_only = false) const;
IntrusivePtr<BroType> type;
IntrusivePtr<Attributes> attrs;
IntrusivePtr<Type> type;
IntrusivePtr<zeek::detail::Attributes> attrs;
const char* id = nullptr;
};
typedef PList<TypeDecl> type_decl_list;
using type_decl_list = PList<TypeDecl>;
class RecordType final : public BroType {
class RecordType final : public Type {
public:
explicit RecordType(type_decl_list* types);
IntrusivePtr<BroType> ShallowClone() override;
IntrusivePtr<Type> ShallowClone() override;
~RecordType() override;
bool HasField(const char* field) const override;
[[deprecated("Remove in v4.1. Use GetFieldType() instead (note it doesn't check for invalid names).")]]
BroType* FieldType(const char* field) const override
Type* FieldType(const char* field) const override
{
auto offset = FieldOffset(field);
return offset >= 0 ? GetFieldType(offset).get() : nullptr;
}
[[deprecated("Remove in v4.1. Use GetFieldType() instead.")]]
BroType* FieldType(int field) const
Type* FieldType(int field) const
{ return GetFieldType(field).get(); }
/**
* Looks up a field by name and returns its type. No check for invalid
* field name is performed.
*/
const IntrusivePtr<BroType>& GetFieldType(const char* field_name) const
const IntrusivePtr<Type>& GetFieldType(const char* field_name) const
{ return GetFieldType(FieldOffset(field_name)); }
/**
@ -622,7 +696,7 @@ public:
* Looks up a field by its index and returns its type. No check for
* invalid field offset is performed.
*/
const IntrusivePtr<BroType>& GetFieldType(int field_index) const
const IntrusivePtr<Type>& GetFieldType(int field_index) const
{ return (*types)[field_index]->type; }
/**
@ -669,15 +743,24 @@ public:
bool IsFieldDeprecated(int field) const
{
const TypeDecl* decl = FieldDecl(field);
return decl && decl->GetAttr(ATTR_DEPRECATED) != nullptr;
return decl && decl->GetAttr(zeek::detail::ATTR_DEPRECATED) != nullptr;
}
bool FieldHasAttr(int field, attr_tag at) const
bool FieldHasAttr(int field, zeek::detail::attr_tag at) const
{
const TypeDecl* decl = FieldDecl(field);
return decl && decl->GetAttr(at) != nullptr;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]]
bool FieldHasAttr(int field, ::attr_tag at) const
{
return FieldHasAttr(field, static_cast<zeek::detail::attr_tag>(at));
}
#pragma GCC diagnostic pop
std::string GetFieldDeprecationWarning(int field, bool has_check) const;
protected:
@ -687,31 +770,31 @@ protected:
type_decl_list* types;
};
class SubNetType final : public BroType {
class SubNetType final : public Type {
public:
SubNetType();
void Describe(ODesc* d) const override;
};
class FileType final : public BroType {
class FileType final : public Type {
public:
explicit FileType(IntrusivePtr<BroType> yield_type);
IntrusivePtr<BroType> ShallowClone() override { return make_intrusive<FileType>(yield); }
explicit FileType(IntrusivePtr<Type> yield_type);
IntrusivePtr<Type> ShallowClone() override { return make_intrusive<FileType>(yield); }
~FileType() override;
const IntrusivePtr<BroType>& Yield() const override
const IntrusivePtr<Type>& Yield() const override
{ return yield; }
void Describe(ODesc* d) const override;
protected:
IntrusivePtr<BroType> yield;
IntrusivePtr<Type> yield;
};
class OpaqueType final : public BroType {
class OpaqueType final : public Type {
public:
explicit OpaqueType(const std::string& name);
IntrusivePtr<BroType> ShallowClone() override { return make_intrusive<OpaqueType>(name); }
IntrusivePtr<Type> ShallowClone() override { return make_intrusive<OpaqueType>(name); }
~OpaqueType() override { };
const std::string& Name() const { return name; }
@ -725,23 +808,23 @@ protected:
std::string name;
};
class EnumType final : public BroType {
class EnumType final : public Type {
public:
typedef std::list<std::pair<std::string, bro_int_t> > enum_name_list;
explicit EnumType(const EnumType* e);
explicit EnumType(const std::string& arg_name);
IntrusivePtr<BroType> ShallowClone() override;
IntrusivePtr<Type> ShallowClone() override;
~EnumType() override;
// The value of this name is next internal counter value, starting
// with zero. The internal counter is incremented.
void AddName(const std::string& module_name, const char* name, bool is_export, Expr* deprecation = nullptr);
void AddName(const std::string& module_name, const char* name, bool is_export, zeek::detail::Expr* deprecation = nullptr);
// The value of this name is set to val. Once a value has been
// explicitly assigned using this method, no further names can be
// added that aren't likewise explicitly initalized.
void AddName(const std::string& module_name, const char* name, bro_int_t val, bool is_export, Expr* deprecation = nullptr);
void AddName(const std::string& module_name, const char* name, bro_int_t val, bool is_export, zeek::detail::Expr* deprecation = nullptr);
// -1 indicates not found.
bro_int_t Lookup(const std::string& module_name, const char* name) const;
@ -761,7 +844,7 @@ protected:
void CheckAndAddName(const std::string& module_name,
const char* name, bro_int_t val, bool is_export,
Expr* deprecation = nullptr);
zeek::detail::Expr* deprecation = nullptr);
typedef std::map<std::string, bro_int_t> NameMap;
NameMap names;
@ -778,15 +861,15 @@ protected:
bro_int_t counter;
};
class VectorType final : public BroType {
class VectorType final : public Type {
public:
explicit VectorType(IntrusivePtr<BroType> t);
IntrusivePtr<BroType> ShallowClone() override;
explicit VectorType(IntrusivePtr<Type> t);
IntrusivePtr<Type> ShallowClone() override;
~VectorType() override;
const IntrusivePtr<BroType>& Yield() const override;
const IntrusivePtr<Type>& Yield() const override;
int MatchesIndex(ListExpr* index) const override;
int MatchesIndex(zeek::detail::ListExpr* index) const override;
// Returns true if this table type is "unspecified", which is what one
// gets using an empty "vector()" constructor.
@ -796,62 +879,39 @@ public:
void DescribeReST(ODesc* d, bool roles_only = false) const override;
protected:
IntrusivePtr<BroType> yield_type;
IntrusivePtr<Type> yield_type;
};
extern IntrusivePtr<OpaqueType> md5_type;
extern IntrusivePtr<OpaqueType> sha1_type;
extern IntrusivePtr<OpaqueType> sha256_type;
extern IntrusivePtr<OpaqueType> entropy_type;
extern IntrusivePtr<OpaqueType> cardinality_type;
extern IntrusivePtr<OpaqueType> topk_type;
extern IntrusivePtr<OpaqueType> bloomfilter_type;
extern IntrusivePtr<OpaqueType> x509_opaque_type;
extern IntrusivePtr<OpaqueType> ocsp_resp_opaque_type;
extern IntrusivePtr<OpaqueType> paraglob_type;
// Returns the basic (non-parameterized) type with the given type.
const IntrusivePtr<BroType>& base_type(TypeTag tag);
// Returns the basic (non-parameterized) type with the given type.
// The reference count of the type is not increased.
[[deprecated("Remove in v4.1. Use ::base_type() instead")]]
inline BroType* base_type_no_ref(TypeTag tag)
{ return base_type(tag).get(); }
// Returns the basic error type.
inline const IntrusivePtr<BroType>& error_type() { return base_type(TYPE_ERROR); }
// True if the two types are equivalent. If is_init is true then the test is
// done in the context of an initialization. If match_record_field_names is
// true then for record types the field names have to match, too.
extern bool same_type(const BroType& t1, const BroType& t2,
extern bool same_type(const Type& t1, const Type& t2,
bool is_init=false, bool match_record_field_names=true);
inline bool same_type(const IntrusivePtr<BroType>& t1, const IntrusivePtr<BroType>& t2,
inline bool same_type(const IntrusivePtr<Type>& t1, const IntrusivePtr<Type>& t2,
bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); }
inline bool same_type(const BroType* t1, const BroType* t2,
inline bool same_type(const Type* t1, const Type* t2,
bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); }
inline bool same_type(const IntrusivePtr<BroType>& t1, const BroType* t2,
inline bool same_type(const IntrusivePtr<Type>& t1, const Type* t2,
bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); }
inline bool same_type(const BroType* t1, const IntrusivePtr<BroType>& t2,
inline bool same_type(const Type* t1, const IntrusivePtr<Type>& t2,
bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); }
// True if the two attribute lists are equivalent.
extern bool same_attrs(const Attributes* a1, const Attributes* a2);
extern bool same_attrs(const zeek::detail::Attributes* a1, const zeek::detail::Attributes* a2);
// Returns true if the record sub_rec can be promoted to the record
// super_rec.
extern bool record_promotion_compatible(const RecordType* super_rec,
const RecordType* sub_rec);
// If the given BroType is a TypeList with just one element, returns
// If the given Type is a TypeList with just one element, returns
// that element, otherwise returns the type.
extern const BroType* flatten_type(const BroType* t);
extern BroType* flatten_type(BroType* t);
extern const Type* flatten_type(const Type* t);
extern Type* flatten_type(Type* t);
// Returns the "maximum" of two type tags, in a type-promotion sense.
extern TypeTag max_type(TypeTag t1, TypeTag t2);
@ -859,28 +919,28 @@ extern TypeTag max_type(TypeTag t1, TypeTag t2);
// Given two types, returns the "merge", in which promotable types
// are promoted to the maximum of the two. Returns nil (and generates
// an error message) if the types are incompatible.
IntrusivePtr<BroType> merge_types(const IntrusivePtr<BroType>& t1,
const IntrusivePtr<BroType>& t2);
IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& t1,
const IntrusivePtr<Type>& t2);
// Given a list of expressions, returns a (ref'd) type reflecting
// a merged type consistent across all of them, or nil if this
// cannot be done.
IntrusivePtr<BroType> merge_type_list(ListExpr* elements);
IntrusivePtr<Type> merge_type_list(zeek::detail::ListExpr* elements);
// Given an expression, infer its type when used for an initialization.
IntrusivePtr<BroType> init_type(Expr* init);
IntrusivePtr<Type> init_type(zeek::detail::Expr* init);
// Returns true if argument is an atomic type.
bool is_atomic_type(const BroType& t);
inline bool is_atomic_type(const BroType* t)
bool is_atomic_type(const Type& t);
inline bool is_atomic_type(const Type* t)
{ return is_atomic_type(*t); }
inline bool is_atomic_type(const IntrusivePtr<BroType>& t)
inline bool is_atomic_type(const IntrusivePtr<Type>& t)
{ return is_atomic_type(*t); }
// True if the given type tag corresponds to type that can be assigned to.
extern bool is_assignable(TypeTag t);
inline bool is_assignable(BroType* t)
{ return ::is_assignable(t->Tag()); }
inline bool is_assignable(Type* t)
{ return zeek::is_assignable(t->Tag()); }
// True if the given type tag corresponds to an integral type.
inline bool IsIntegral(TypeTag t) { return (t == TYPE_INT || t == TYPE_COUNT || t == TYPE_COUNTER); }
@ -929,3 +989,68 @@ inline bool BothString(TypeTag t1, TypeTag t2) { return (IsString(t1) && IsStrin
// True if either tag is the error type.
inline bool EitherError(TypeTag t1, TypeTag t2) { return (IsErrorType(t1) || IsErrorType(t2)); }
// Returns the basic (non-parameterized) type with the given type.
const IntrusivePtr<zeek::Type>& base_type(zeek::TypeTag tag);
// Returns the basic error type.
inline const IntrusivePtr<zeek::Type>& error_type() { return base_type(TYPE_ERROR); }
} // namespace zeek
// Returns the basic (non-parameterized) type with the given type.
// The reference count of the type is not increased.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use zeek::base_type() instead")]]
inline zeek::Type* base_type_no_ref(::TypeTag tag)
{ return zeek::base_type(static_cast<zeek::TypeTag>(tag)).get(); }
#pragma GCC diagnostic pop
extern IntrusivePtr<zeek::OpaqueType> md5_type;
extern IntrusivePtr<zeek::OpaqueType> sha1_type;
extern IntrusivePtr<zeek::OpaqueType> sha256_type;
extern IntrusivePtr<zeek::OpaqueType> entropy_type;
extern IntrusivePtr<zeek::OpaqueType> cardinality_type;
extern IntrusivePtr<zeek::OpaqueType> topk_type;
extern IntrusivePtr<zeek::OpaqueType> bloomfilter_type;
extern IntrusivePtr<zeek::OpaqueType> x509_opaque_type;
extern IntrusivePtr<zeek::OpaqueType> ocsp_resp_opaque_type;
extern IntrusivePtr<zeek::OpaqueType> paraglob_type;
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
using TypeList [[deprecated("Remove in v4.1. Use zeek::TypeList instead.")]] = zeek::TypeList;
using IndexType [[deprecated("Remove in v4.1. Use zeek::IndexType instead.")]] = zeek::IndexType;
using TableType [[deprecated("Remove in v4.1. Use zeek::TableType instead.")]] = zeek::TableType;
using SetType [[deprecated("Remove in v4.1. Use zeek::SetType instead.")]] = zeek::SetType;
using FuncType [[deprecated("Remove in v4.1. Use zeek::FuncType instead.")]] = zeek::FuncType;
using TypeType [[deprecated("Remove in v4.1. Use zeek::TypeType instead.")]] = zeek::TypeType;
using TypeDecl [[deprecated("Remove in v4.1. Use zeek::TypeDecl instead.")]] = zeek::TypeDecl;
using RecordType [[deprecated("Remove in v4.1. Use zeek::RecordType instead.")]] = zeek::RecordType;
using SubNetType [[deprecated("Remove in v4.1. Use zeek::SubNetType instead.")]] = zeek::SubNetType;
using FileType [[deprecated("Remove in v4.1. Use zeek::FileType instead.")]] = zeek::FileType;
using OpaqueType [[deprecated("Remove in v4.1. Use zeek::OpaqueType instead.")]] = zeek::OpaqueType;
using EnumType [[deprecated("Remove in v4.1. Use zeek::EnumType instead.")]] = zeek::EnumType;
using VectorType [[deprecated("Remove in v4.1. Use zeek::VectorType instead.")]] = zeek::VectorType;
using type_decl_list [[deprecated("Remove in v4.1. Use zeek::type_decl_list instead.")]] = zeek::type_decl_list;
constexpr auto IsIntegral [[deprecated("Remove in v4.1. Use zeek::IsIntegral instead.")]] = zeek::IsIntegral;
constexpr auto IsArithmetic [[deprecated("Remove in v4.1. Use zeek::IsArithmetic instead.")]] = zeek::IsArithmetic;
constexpr auto IsBool [[deprecated("Remove in v4.1. Use zeek::IsBool instead.")]] = zeek::IsBool;
constexpr auto IsInterval [[deprecated("Remove in v4.1. Use zeek::IsInterval instead.")]] = zeek::IsInterval;
constexpr auto IsRecord [[deprecated("Remove in v4.1. Use zeek::IsRecord instead.")]] = zeek::IsRecord;
constexpr auto IsFunc [[deprecated("Remove in v4.1. Use zeek::IsFunc instead.")]] = zeek::IsFunc;
constexpr auto IsVector [[deprecated("Remove in v4.1. Use zeek::IsVector instead.")]] = zeek::IsVector;
constexpr auto IsString [[deprecated("Remove in v4.1. Use zeek::IsString instead.")]] = zeek::IsString;
constexpr auto IsErrorType [[deprecated("Remove in v4.1. Use zeek::IsErrorType instead.")]] = zeek::IsErrorType;
constexpr auto BothIntegral [[deprecated("Remove in v4.1. Use zeek::BothIntegral instead.")]] = zeek::BothIntegral;
constexpr auto BothArithmetic [[deprecated("Remove in v4.1. Use zeek::BothArithmetic instead.")]] = zeek::BothArithmetic;
constexpr auto EitherArithmetic [[deprecated("Remove in v4.1. Use zeek::EitherArithmetic instead.")]] = zeek::EitherArithmetic;
constexpr auto BothBool [[deprecated("Remove in v4.1. Use zeek::BothBool instead.")]] = zeek::BothBool;
constexpr auto BothInterval [[deprecated("Remove in v4.1. Use zeek::BothInterval instead.")]] = zeek::BothInterval;
constexpr auto BothString [[deprecated("Remove in v4.1. Use zeek::BothString instead.")]] = zeek::BothString;
constexpr auto EitherError [[deprecated("Remove in v4.1. Use zeek::EitherError instead.")]] = zeek::EitherError;
constexpr auto base_type [[deprecated("Remove in v4.1. Use zeek::base_type instead.")]] = zeek::base_type;
constexpr auto error_type [[deprecated("Remove in v4.1. Use zeek::error_type instead.")]] = zeek::error_type;
constexpr auto type_name [[deprecated("Remove in v4.1. Use zeek::type_name instead.")]] = zeek::type_name;
constexpr auto is_network_order [[deprecated("Remove in v4.1. Use zeek::is_network_order instead.")]] = zeek::is_network_order;