mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Add Attributes ctor that takes IntrusivePtrs
This commit is contained in:
parent
102e58b80b
commit
ccd1cbbc54
6 changed files with 87 additions and 14 deletions
26
src/Attr.cc
26
src/Attr.cc
|
@ -137,7 +137,6 @@ void Attr::AddTag(ODesc* d) const
|
||||||
}
|
}
|
||||||
|
|
||||||
Attributes::Attributes(attr_list* a, IntrusivePtr<BroType> t, bool arg_in_record, bool is_global)
|
Attributes::Attributes(attr_list* a, IntrusivePtr<BroType> t, bool arg_in_record, bool is_global)
|
||||||
: type(std::move(t))
|
|
||||||
{
|
{
|
||||||
attrs.reserve(a->length());
|
attrs.reserve(a->length());
|
||||||
in_record = arg_in_record;
|
in_record = arg_in_record;
|
||||||
|
@ -155,6 +154,31 @@ Attributes::Attributes(attr_list* a, IntrusivePtr<BroType> t, bool arg_in_record
|
||||||
delete a;
|
delete a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Attributes::Attributes(IntrusivePtr<BroType> t,
|
||||||
|
bool arg_in_record, bool is_global)
|
||||||
|
: Attributes(std::vector<IntrusivePtr<Attr>>{}, std::move(t),
|
||||||
|
arg_in_record, is_global)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Attributes::Attributes(std::vector<IntrusivePtr<Attr>> a,
|
||||||
|
IntrusivePtr<BroType> t,
|
||||||
|
bool arg_in_record, bool is_global)
|
||||||
|
: type(std::move(t))
|
||||||
|
{
|
||||||
|
attrs.reserve(a.size());
|
||||||
|
in_record = arg_in_record;
|
||||||
|
global_var = is_global;
|
||||||
|
|
||||||
|
SetLocationInfo(&start_location, &end_location);
|
||||||
|
|
||||||
|
// We loop through 'a' and add each attribute individually,
|
||||||
|
// rather than just taking over 'a' for ourselves, so that
|
||||||
|
// the necessary checking gets done.
|
||||||
|
|
||||||
|
for ( auto& attr : a )
|
||||||
|
AddAttr(std::move(attr));
|
||||||
|
}
|
||||||
|
|
||||||
void Attributes::AddAttr(IntrusivePtr<Attr> attr)
|
void Attributes::AddAttr(IntrusivePtr<Attr> attr)
|
||||||
{
|
{
|
||||||
// We overwrite old attributes by deleting them first.
|
// We overwrite old attributes by deleting them first.
|
||||||
|
|
|
@ -79,8 +79,13 @@ protected:
|
||||||
// Manages a collection of attributes.
|
// Manages a collection of attributes.
|
||||||
class Attributes final : public BroObj {
|
class Attributes final : public BroObj {
|
||||||
public:
|
public:
|
||||||
|
[[deprecated("Remove in v4.1. Construct using IntrusivePtrs instead.")]]
|
||||||
Attributes(attr_list* a, IntrusivePtr<BroType> t, bool in_record, bool is_global);
|
Attributes(attr_list* a, IntrusivePtr<BroType> t, bool in_record, bool is_global);
|
||||||
|
|
||||||
|
Attributes(std::vector<IntrusivePtr<Attr>> a, IntrusivePtr<BroType> t,
|
||||||
|
bool in_record, bool is_global);
|
||||||
|
Attributes(IntrusivePtr<BroType> t, bool in_record, bool is_global);
|
||||||
|
|
||||||
void AddAttr(IntrusivePtr<Attr> a);
|
void AddAttr(IntrusivePtr<Attr> a);
|
||||||
void AddAttrs(Attributes* a); // Unref's 'a' when done
|
void AddAttrs(Attributes* a); // Unref's 'a' when done
|
||||||
|
|
||||||
|
|
22
src/Expr.cc
22
src/Expr.cc
|
@ -3087,7 +3087,16 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr<ListExpr> constructor_li
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr;
|
if ( arg_attrs )
|
||||||
|
{
|
||||||
|
std::vector<IntrusivePtr<Attr>> attrv;
|
||||||
|
|
||||||
|
for ( auto& a : *arg_attrs )
|
||||||
|
attrv.emplace_back(AdoptRef{}, a);
|
||||||
|
|
||||||
|
attrs = new Attributes(std::move(attrv), type, false, false);
|
||||||
|
delete arg_attrs;
|
||||||
|
}
|
||||||
|
|
||||||
const auto& indices = type->AsTableType()->GetIndices()->Types();
|
const auto& indices = type->AsTableType()->GetIndices()->Types();
|
||||||
const expr_list& cle = op->AsListExpr()->Exprs();
|
const expr_list& cle = op->AsListExpr()->Exprs();
|
||||||
|
@ -3206,7 +3215,16 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr<ListExpr> constructor_list,
|
||||||
else if ( type->Tag() != TYPE_TABLE || ! type->AsTableType()->IsSet() )
|
else if ( type->Tag() != TYPE_TABLE || ! type->AsTableType()->IsSet() )
|
||||||
SetError("values in set(...) constructor do not specify a set");
|
SetError("values in set(...) constructor do not specify a set");
|
||||||
|
|
||||||
attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr;
|
if ( arg_attrs )
|
||||||
|
{
|
||||||
|
std::vector<IntrusivePtr<Attr>> attrv;
|
||||||
|
|
||||||
|
for ( auto& a : *arg_attrs )
|
||||||
|
attrv.emplace_back(AdoptRef{}, a);
|
||||||
|
|
||||||
|
attrs = new Attributes(std::move(attrv), type, false, false);
|
||||||
|
delete arg_attrs;
|
||||||
|
}
|
||||||
|
|
||||||
const auto& indices = type->AsTableType()->GetIndices()->Types();
|
const auto& indices = type->AsTableType()->GetIndices()->Types();
|
||||||
expr_list& cle = op->AsListExpr()->Exprs();
|
expr_list& cle = op->AsListExpr()->Exprs();
|
||||||
|
|
10
src/ID.cc
10
src/ID.cc
|
@ -258,7 +258,7 @@ void ID::UpdateValAttrs()
|
||||||
TypeDecl* fd = rt->FieldDecl(i);
|
TypeDecl* fd = rt->FieldDecl(i);
|
||||||
|
|
||||||
if ( ! fd->attrs )
|
if ( ! fd->attrs )
|
||||||
fd->attrs = make_intrusive<Attributes>(new attr_list, rt->GetFieldType(i), true, IsGlobal());
|
fd->attrs = make_intrusive<Attributes>(rt->GetFieldType(i), true, IsGlobal());
|
||||||
|
|
||||||
fd->attrs->AddAttr(make_intrusive<Attr>(ATTR_LOG));
|
fd->attrs->AddAttr(make_intrusive<Attr>(ATTR_LOG));
|
||||||
}
|
}
|
||||||
|
@ -281,8 +281,8 @@ void ID::MakeDeprecated(IntrusivePtr<Expr> deprecation)
|
||||||
if ( IsDeprecated() )
|
if ( IsDeprecated() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
attr_list* attr = new attr_list{new Attr(ATTR_DEPRECATED, std::move(deprecation))};
|
std::vector<IntrusivePtr<Attr>> attrv{make_intrusive<Attr>(ATTR_DEPRECATED, std::move(deprecation))};
|
||||||
AddAttrs(make_intrusive<Attributes>(attr, GetType(), false, IsGlobal()));
|
AddAttrs(make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ID::GetDeprecationWarning() const
|
std::string ID::GetDeprecationWarning() const
|
||||||
|
@ -331,8 +331,8 @@ void ID::SetOption()
|
||||||
// option implied redefinable
|
// option implied redefinable
|
||||||
if ( ! IsRedefinable() )
|
if ( ! IsRedefinable() )
|
||||||
{
|
{
|
||||||
attr_list* attr = new attr_list{new Attr(ATTR_REDEF)};
|
std::vector<IntrusivePtr<Attr>> attrv{make_intrusive<Attr>(ATTR_REDEF)};
|
||||||
AddAttrs(make_intrusive<Attributes>(attr, GetType(), false, IsGlobal()));
|
AddAttrs(make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
src/Type.cc
13
src/Type.cc
|
@ -609,9 +609,18 @@ std::optional<FuncType::Prototype> FuncType::FindPrototype(const RecordType& arg
|
||||||
|
|
||||||
TypeDecl::TypeDecl(IntrusivePtr<BroType> t, const char* i, attr_list* arg_attrs, bool in_record)
|
TypeDecl::TypeDecl(IntrusivePtr<BroType> t, const char* i, attr_list* arg_attrs, bool in_record)
|
||||||
: type(std::move(t)),
|
: type(std::move(t)),
|
||||||
attrs(arg_attrs ? make_intrusive<Attributes>(arg_attrs, type, in_record, false) : nullptr),
|
|
||||||
id(i)
|
id(i)
|
||||||
{
|
{
|
||||||
|
if ( arg_attrs )
|
||||||
|
{
|
||||||
|
std::vector<IntrusivePtr<Attr>> attrv;
|
||||||
|
|
||||||
|
for ( auto& a : *arg_attrs )
|
||||||
|
attrv.emplace_back(AdoptRef{}, a);
|
||||||
|
|
||||||
|
attrs = make_intrusive<Attributes>(std::move(attrv), type, in_record, false);
|
||||||
|
delete arg_attrs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeDecl::TypeDecl(const TypeDecl& other)
|
TypeDecl::TypeDecl(const TypeDecl& other)
|
||||||
|
@ -856,7 +865,7 @@ const char* RecordType::AddFields(type_decl_list* others, attr_list* attr)
|
||||||
if ( log )
|
if ( log )
|
||||||
{
|
{
|
||||||
if ( ! td->attrs )
|
if ( ! td->attrs )
|
||||||
td->attrs = make_intrusive<Attributes>(new attr_list, td->type, true, false);
|
td->attrs = make_intrusive<Attributes>(td->type, true, false);
|
||||||
|
|
||||||
td->attrs->AddAttr(make_intrusive<Attr>(ATTR_LOG));
|
td->attrs->AddAttr(make_intrusive<Attr>(ATTR_LOG));
|
||||||
}
|
}
|
||||||
|
|
25
src/Var.cc
25
src/Var.cc
|
@ -196,7 +196,14 @@ static void make_var(ID* id, IntrusivePtr<BroType> t, init_class c,
|
||||||
id->SetType(t);
|
id->SetType(t);
|
||||||
|
|
||||||
if ( attr )
|
if ( attr )
|
||||||
id->AddAttrs(make_intrusive<Attributes>(attr, t, false, id->IsGlobal()));
|
{
|
||||||
|
std::vector<IntrusivePtr<Attr>> attrv;
|
||||||
|
|
||||||
|
for ( auto& a : *attr)
|
||||||
|
attrv.emplace_back(AdoptRef{}, a);
|
||||||
|
|
||||||
|
id->AddAttrs(make_intrusive<Attributes>(std::move(attrv), t, false, id->IsGlobal()));
|
||||||
|
}
|
||||||
|
|
||||||
if ( init )
|
if ( init )
|
||||||
{
|
{
|
||||||
|
@ -387,7 +394,15 @@ void add_type(ID* id, IntrusivePtr<BroType> t, attr_list* attr)
|
||||||
id->MakeType();
|
id->MakeType();
|
||||||
|
|
||||||
if ( attr )
|
if ( attr )
|
||||||
id->SetAttrs(make_intrusive<Attributes>(attr, tnew, false, false));
|
{
|
||||||
|
std::vector<IntrusivePtr<Attr>> attrv;
|
||||||
|
|
||||||
|
for ( auto& a : *attr )
|
||||||
|
attrv.emplace_back(AdoptRef{}, a);
|
||||||
|
|
||||||
|
id->SetAttrs(make_intrusive<Attributes>(std::move(attrv), tnew, false, false));
|
||||||
|
delete attr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transfer_arg_defaults(RecordType* args, RecordType* recv)
|
static void transfer_arg_defaults(RecordType* args, RecordType* recv)
|
||||||
|
@ -404,8 +419,10 @@ static void transfer_arg_defaults(RecordType* args, RecordType* recv)
|
||||||
|
|
||||||
if ( ! recv_i->attrs )
|
if ( ! recv_i->attrs )
|
||||||
{
|
{
|
||||||
attr_list* a = new attr_list{def};
|
std::vector<IntrusivePtr<Attr>> a{{NewRef{}, def}};
|
||||||
recv_i->attrs = make_intrusive<Attributes>(a, recv_i->type, true, false);
|
recv_i->attrs = make_intrusive<Attributes>(std::move(a),
|
||||||
|
recv_i->type,
|
||||||
|
true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ( ! recv_i->attrs->FindAttr(ATTR_DEFAULT) )
|
else if ( ! recv_i->attrs->FindAttr(ATTR_DEFAULT) )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue