Use type aliases for IntrusivePtr definitions

This commit is contained in:
Tim Wojtulewicz 2020-06-24 16:46:34 -04:00
parent f6a251cdac
commit ec9eff0bd5
180 changed files with 2026 additions and 1893 deletions

View file

@ -18,10 +18,18 @@ class Val;
class EnumVal;
class TableVal;
using ValPtr = zeek::IntrusivePtr<Val>;
using EnumValPtr = zeek::IntrusivePtr<EnumVal>;
using TableValPtr = zeek::IntrusivePtr<TableVal>;
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(ListExpr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail);
namespace zeek::detail {
using ListExprPtr = zeek::IntrusivePtr<ListExpr>;
}
namespace zeek {
// BRO types.
@ -139,6 +147,20 @@ class EnumType;
class VectorType;
class TypeType;
class OpaqueType;
class FileType;
using TypePtr = zeek::IntrusivePtr<Type>;
using TypeListPtr = zeek::IntrusivePtr<TypeList>;
using TableTypePtr = zeek::IntrusivePtr<TableType>;
using SetTypePtr = zeek::IntrusivePtr<SetType>;
using RecordTypePtr = zeek::IntrusivePtr<RecordType>;
using SubNetTypePtr = zeek::IntrusivePtr<SubNetType>;
using FuncTypePtr = zeek::IntrusivePtr<FuncType>;
using EnumTypePtr = zeek::IntrusivePtr<EnumType>;
using VectorTypePtr = zeek::IntrusivePtr<VectorType>;
using TypeTypePtr = zeek::IntrusivePtr<TypeType>;
using OpaqueTypePtr = zeek::IntrusivePtr<OpaqueType>;
using FileTypePtr = zeek::IntrusivePtr<FileType>;
constexpr int DOES_NOT_MATCH_INDEX = 0;
constexpr int MATCHES_INDEX_SCALAR = 1;
@ -146,7 +168,7 @@ constexpr int MATCHES_INDEX_VECTOR = 2;
class Type : public BroObj {
public:
static inline const zeek::IntrusivePtr<Type> nil;
static inline const TypePtr nil;
explicit Type(zeek::TypeTag tag, bool base_type = false);
@ -158,7 +180,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 zeek::IntrusivePtr<Type> ShallowClone();
virtual TypePtr ShallowClone();
TypeTag Tag() const { return tag; }
InternalTypeTag InternalType() const { return internal_tag; }
@ -178,7 +200,7 @@ public:
// 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 zeek::IntrusivePtr<Type>& Yield() const;
virtual const TypePtr& Yield() const;
[[deprecated("Remove in v4.1. Use Yield() instead.")]]
virtual Type* YieldType()
@ -362,7 +384,7 @@ private:
class TypeList final : public Type {
public:
explicit TypeList(zeek::IntrusivePtr<Type> arg_pure_type = nullptr)
explicit TypeList(TypePtr arg_pure_type = nullptr)
: Type(TYPE_LIST), pure_type(std::move(arg_pure_type))
{
}
@ -373,14 +395,14 @@ public:
const type_list* Types() const
{ return &types_list; }
const std::vector<zeek::IntrusivePtr<Type>>& GetTypes() const
const std::vector<TypePtr>& GetTypes() 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 zeek::IntrusivePtr<Type>& GetPureType() const
const TypePtr& GetPureType() const
{ return pure_type; }
[[deprecated("Remove in v4.1. Use GetPureType() instead.")]]
@ -392,19 +414,19 @@ public:
// is_init is true, then the matching is done in the context
// of an initialization.
bool AllMatch(const Type* t, bool is_init) const;
bool AllMatch(const zeek::IntrusivePtr<Type>& t, bool is_init) const
bool AllMatch(const TypePtr& t, bool is_init) const
{ return AllMatch(t.get(), is_init); }
void Append(zeek::IntrusivePtr<Type> t);
void AppendEvenIfNotPure(zeek::IntrusivePtr<Type> t);
void Append(TypePtr t);
void AppendEvenIfNotPure(TypePtr t);
void Describe(ODesc* d) const override;
unsigned int MemoryAllocation() const override;
protected:
zeek::IntrusivePtr<Type> pure_type;
std::vector<zeek::IntrusivePtr<Type>> types;
TypePtr pure_type;
std::vector<TypePtr> types;
// Remove in v4.1. This is used by Types(), which is deprecated.
type_list types_list;
@ -415,7 +437,7 @@ public:
int MatchesIndex(zeek::detail::ListExpr* index) const override;
const zeek::IntrusivePtr<TypeList>& GetIndices() const
const TypeListPtr& GetIndices() const
{ return indices; }
[[deprecated("Remove in v4.1. Use GetIndices().")]]
@ -425,10 +447,10 @@ public:
const type_list* IndexTypes() const
{ return indices->Types(); }
const std::vector<zeek::IntrusivePtr<Type>>& GetIndexTypes() const
const std::vector<TypePtr>& GetIndexTypes() const
{ return indices->GetTypes(); }
const zeek::IntrusivePtr<Type>& Yield() const override
const TypePtr& Yield() const override
{ return yield_type; }
void Describe(ODesc* d) const override;
@ -438,8 +460,8 @@ public:
bool IsSubNetIndex() const;
protected:
IndexType(TypeTag t, zeek::IntrusivePtr<TypeList> arg_indices,
zeek::IntrusivePtr<Type> arg_yield_type)
IndexType(TypeTag t, TypeListPtr arg_indices,
TypePtr arg_yield_type)
: Type(t), indices(std::move(arg_indices)),
yield_type(std::move(arg_yield_type))
{
@ -447,15 +469,15 @@ protected:
~IndexType() override = default;
zeek::IntrusivePtr<TypeList> indices;
zeek::IntrusivePtr<Type> yield_type;
TypeListPtr indices;
TypePtr yield_type;
};
class TableType : public IndexType {
public:
TableType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<Type> yield);
TableType(TypeListPtr ind, TypePtr yield);
zeek::IntrusivePtr<Type> ShallowClone() override;
TypePtr ShallowClone() override;
// Returns true if this table type is "unspecified", which is
// what one gets using an empty "set()" or "table()" constructor.
@ -464,24 +486,24 @@ public:
class SetType final : public TableType {
public:
SetType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<zeek::detail::ListExpr> arg_elements);
SetType(TypeListPtr ind, zeek::detail::ListExprPtr arg_elements);
~SetType() override;
zeek::IntrusivePtr<Type> ShallowClone() override;
TypePtr ShallowClone() override;
[[deprecated("Remove in v4.1. Use Elements() isntead.")]]
zeek::detail::ListExpr* SetElements() const { return elements.get(); }
const zeek::IntrusivePtr<zeek::detail::ListExpr>& Elements() const
const zeek::detail::ListExprPtr& Elements() const
{ return elements; }
protected:
zeek::IntrusivePtr<zeek::detail::ListExpr> elements;
zeek::detail::ListExprPtr elements;
};
class FuncType final : public Type {
public:
static inline const zeek::IntrusivePtr<FuncType> nil;
static inline const FuncTypePtr nil;
/**
* Prototype is only currently used for events and hooks which declare
@ -490,27 +512,27 @@ public:
*/
struct Prototype {
bool deprecated;
zeek::IntrusivePtr<RecordType> args;
RecordTypePtr args;
std::map<int, int> offsets;
};
FuncType(zeek::IntrusivePtr<RecordType> args, zeek::IntrusivePtr<Type> yield,
FuncType(RecordTypePtr args, TypePtr yield,
FunctionFlavor f);
zeek::IntrusivePtr<Type> ShallowClone() override;
TypePtr ShallowClone() override;
~FuncType() override;
[[deprecated("Remove in v4.1. Use Params().")]]
RecordType* Args() const { return args.get(); }
const zeek::IntrusivePtr<RecordType>& Params() const
const RecordTypePtr& Params() const
{ return args; }
const zeek::IntrusivePtr<Type>& Yield() const override
const TypePtr& Yield() const override
{ return yield; }
void SetYieldType(zeek::IntrusivePtr<Type> arg_yield) { yield = std::move(arg_yield); }
void SetYieldType(TypePtr arg_yield) { yield = std::move(arg_yield); }
FunctionFlavor Flavor() const { return flavor; }
std::string FlavorString() const;
@ -520,13 +542,13 @@ public:
int MatchesIndex(zeek::detail::ListExpr* index) const override;
bool CheckArgs(const type_list* args, bool is_init = false) const;
bool CheckArgs(const std::vector<zeek::IntrusivePtr<Type>>& args,
bool CheckArgs(const std::vector<TypePtr>& args,
bool is_init = false) const;
[[deprecated("Remove in v4.1. Use ParamList().")]]
TypeList* ArgTypes() const { return arg_types.get(); }
const zeek::IntrusivePtr<TypeList>& ParamList() const
const TypeListPtr& ParamList() const
{ return arg_types; }
void Describe(ODesc* d) const override;
@ -549,22 +571,22 @@ public:
{ return prototypes; }
protected:
friend zeek::IntrusivePtr<FuncType> zeek::make_intrusive<FuncType>();
friend FuncTypePtr zeek::make_intrusive<FuncType>();
FuncType() : Type(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; }
zeek::IntrusivePtr<RecordType> args;
zeek::IntrusivePtr<TypeList> arg_types;
zeek::IntrusivePtr<Type> yield;
RecordTypePtr args;
TypeListPtr arg_types;
TypePtr yield;
FunctionFlavor flavor;
std::vector<Prototype> prototypes;
};
class TypeType final : public Type {
public:
explicit TypeType(zeek::IntrusivePtr<Type> t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {}
zeek::IntrusivePtr<Type> ShallowClone() override { return zeek::make_intrusive<TypeType>(type); }
explicit TypeType(TypePtr t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {}
TypePtr ShallowClone() override { return zeek::make_intrusive<TypeType>(type); }
const zeek::IntrusivePtr<Type>& GetType() const
const TypePtr& GetType() const
{ return type; }
template <class T>
@ -577,24 +599,23 @@ public:
const zeek::Type* Type() const { return type.get(); }
protected:
zeek::IntrusivePtr<zeek::Type> type;
TypePtr type;
};
class TypeDecl final {
public:
TypeDecl() = default;
TypeDecl(const char* i, zeek::IntrusivePtr<Type> t,
zeek::IntrusivePtr<zeek::detail::Attributes> attrs = nullptr);
TypeDecl(const char* i, TypePtr t, zeek::detail::AttributesPtr attrs = nullptr);
TypeDecl(const TypeDecl& other);
~TypeDecl();
const zeek::IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::AttrTag a) const
const zeek::detail::AttrPtr& GetAttr(zeek::detail::AttrTag a) const
{ return attrs ? attrs->Find(a) : zeek::detail::Attr::nil; }
void DescribeReST(ODesc* d, bool roles_only = false) const;
zeek::IntrusivePtr<Type> type;
zeek::IntrusivePtr<zeek::detail::Attributes> attrs;
TypePtr type;
zeek::detail::AttributesPtr attrs;
const char* id = nullptr;
};
@ -603,7 +624,7 @@ using type_decl_list = PList<TypeDecl>;
class RecordType final : public Type {
public:
explicit RecordType(type_decl_list* types);
zeek::IntrusivePtr<Type> ShallowClone() override;
TypePtr ShallowClone() override;
~RecordType() override;
@ -624,7 +645,7 @@ public:
* Looks up a field by name and returns its type. No check for invalid
* field name is performed.
*/
const zeek::IntrusivePtr<Type>& GetFieldType(const char* field_name) const
const TypePtr& GetFieldType(const char* field_name) const
{ return GetFieldType(FieldOffset(field_name)); }
/**
@ -639,7 +660,7 @@ public:
* Looks up a field by its index and returns its type. No check for
* invalid field offset is performed.
*/
const zeek::IntrusivePtr<Type>& GetFieldType(int field_index) const
const TypePtr& GetFieldType(int field_index) const
{ return (*types)[field_index]->type; }
/**
@ -650,7 +671,7 @@ public:
zeek::IntrusivePtr<T> GetFieldType(int field_index) const
{ return zeek::cast_intrusive<T>((*types)[field_index]->type); }
zeek::IntrusivePtr<Val> FieldDefault(int field) const;
ValPtr FieldDefault(int field) const;
// A field's offset is its position in the type_decl_list,
// starting at 0. Returns negative if the field doesn't exist.
@ -672,7 +693,7 @@ public:
* @param rv an optional record value, if given the values of
* all fields will be provided in the returned table.
*/
zeek::IntrusivePtr<TableVal> GetRecordFieldsVal(const RecordVal* rv = nullptr) const;
TableValPtr GetRecordFieldsVal(const RecordVal* rv = nullptr) const;
// Returns null if all is ok, otherwise a pointer to an error message.
const char* AddFields(const type_decl_list& types,
@ -712,23 +733,23 @@ public:
class FileType final : public Type {
public:
explicit FileType(zeek::IntrusivePtr<Type> yield_type);
zeek::IntrusivePtr<Type> ShallowClone() override { return zeek::make_intrusive<FileType>(yield); }
explicit FileType(TypePtr yield_type);
TypePtr ShallowClone() override { return zeek::make_intrusive<FileType>(yield); }
~FileType() override;
const zeek::IntrusivePtr<Type>& Yield() const override
const TypePtr& Yield() const override
{ return yield; }
void Describe(ODesc* d) const override;
protected:
zeek::IntrusivePtr<Type> yield;
TypePtr yield;
};
class OpaqueType final : public Type {
public:
explicit OpaqueType(const std::string& name);
zeek::IntrusivePtr<Type> ShallowClone() override { return zeek::make_intrusive<OpaqueType>(name); }
TypePtr ShallowClone() override { return zeek::make_intrusive<OpaqueType>(name); }
~OpaqueType() override { };
const std::string& Name() const { return name; }
@ -748,7 +769,7 @@ public:
explicit EnumType(const EnumType* e);
explicit EnumType(const std::string& arg_name);
zeek::IntrusivePtr<Type> ShallowClone() override;
TypePtr ShallowClone() override;
~EnumType() override;
// The value of this name is next internal counter value, starting
@ -770,7 +791,7 @@ public:
void DescribeReST(ODesc* d, bool roles_only = false) const override;
const zeek::IntrusivePtr<EnumVal>& GetVal(bro_int_t i);
const EnumValPtr& GetVal(bro_int_t i);
protected:
void AddNameInternal(const std::string& module_name,
@ -783,7 +804,7 @@ protected:
typedef std::map<std::string, bro_int_t> NameMap;
NameMap names;
using ValMap = std::unordered_map<bro_int_t, zeek::IntrusivePtr<EnumVal>>;
using ValMap = std::unordered_map<bro_int_t, EnumValPtr>;
ValMap vals;
// The counter is initialized to 0 and incremented on every implicit
@ -797,11 +818,11 @@ protected:
class VectorType final : public Type {
public:
explicit VectorType(zeek::IntrusivePtr<Type> t);
zeek::IntrusivePtr<Type> ShallowClone() override;
explicit VectorType(TypePtr t);
TypePtr ShallowClone() override;
~VectorType() override;
const zeek::IntrusivePtr<Type>& Yield() const override;
const TypePtr& Yield() const override;
int MatchesIndex(zeek::detail::ListExpr* index) const override;
@ -813,7 +834,7 @@ public:
void DescribeReST(ODesc* d, bool roles_only = false) const override;
protected:
zeek::IntrusivePtr<Type> yield_type;
TypePtr yield_type;
};
// True if the two types are equivalent. If is_init is true then the test is
@ -821,16 +842,16 @@ protected:
// true then for record types the field names have to match, too.
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 zeek::IntrusivePtr<Type>& t1, const zeek::IntrusivePtr<Type>& t2,
inline bool same_type(const TypePtr& t1, const TypePtr& 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 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 zeek::IntrusivePtr<Type>& t1, const Type* t2,
inline bool same_type(const TypePtr& 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 Type* t1, const zeek::IntrusivePtr<Type>& t2,
inline bool same_type(const Type* t1, const TypePtr& t2,
bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); }
@ -853,22 +874,21 @@ 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.
zeek::IntrusivePtr<Type> merge_types(const zeek::IntrusivePtr<Type>& t1,
const zeek::IntrusivePtr<Type>& t2);
TypePtr merge_types(const TypePtr& t1, const TypePtr& 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.
zeek::IntrusivePtr<Type> merge_type_list(zeek::detail::ListExpr* elements);
TypePtr merge_type_list(zeek::detail::ListExpr* elements);
// Given an expression, infer its type when used for an initialization.
zeek::IntrusivePtr<Type> init_type(zeek::detail::Expr* init);
TypePtr init_type(zeek::detail::Expr* init);
// Returns true if argument is an atomic type.
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 zeek::IntrusivePtr<Type>& t)
inline bool is_atomic_type(const TypePtr& t)
{ return is_atomic_type(*t); }
// True if the given type tag corresponds to type that can be assigned to.
@ -925,10 +945,10 @@ inline bool BothString(TypeTag t1, TypeTag t2) { return (IsString(t1) && IsStrin
inline bool EitherError(TypeTag t1, TypeTag t2) { return (IsErrorType(t1) || IsErrorType(t2)); }
// Returns the basic (non-parameterized) type with the given type.
const zeek::IntrusivePtr<Type>& base_type(zeek::TypeTag tag);
const TypePtr& base_type(zeek::TypeTag tag);
// Returns the basic error type.
inline const zeek::IntrusivePtr<Type>& error_type() { return base_type(TYPE_ERROR); }
inline const TypePtr& error_type() { return base_type(TYPE_ERROR); }
} // namespace zeek
@ -938,16 +958,16 @@ inline const zeek::IntrusivePtr<Type>& error_type() { return base_type(TYP
inline zeek::Type* base_type_no_ref(zeek::TypeTag tag)
{ return zeek::base_type(tag).get(); }
extern zeek::IntrusivePtr<zeek::OpaqueType> md5_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> sha1_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> sha256_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> entropy_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> cardinality_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> topk_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> bloomfilter_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> x509_opaque_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> ocsp_resp_opaque_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> paraglob_type;
extern zeek::OpaqueTypePtr md5_type;
extern zeek::OpaqueTypePtr sha1_type;
extern zeek::OpaqueTypePtr sha256_type;
extern zeek::OpaqueTypePtr entropy_type;
extern zeek::OpaqueTypePtr cardinality_type;
extern zeek::OpaqueTypePtr topk_type;
extern zeek::OpaqueTypePtr bloomfilter_type;
extern zeek::OpaqueTypePtr x509_opaque_type;
extern zeek::OpaqueTypePtr ocsp_resp_opaque_type;
extern zeek::OpaqueTypePtr 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;