mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 13:38:19 +00:00
Merge remote-tracking branch 'origin/topic/timw/174-duplicate-attributes'
- Replaced "tag" with "attribute" in the error message since the former is not exactly the same concept/meaning and also not user-facing terminology * origin/topic/timw/174-duplicate-attributes: Allow duplicate attributes in full redefs Short-circuit checking of whether attr exists Expanded check for other tag types, fixed btest to cover more tags GH-174: Add warning for duplicate attributes
This commit is contained in:
commit
5e6bb843ab
10 changed files with 65 additions and 18 deletions
37
src/Attr.cc
37
src/Attr.cc
|
@ -193,8 +193,35 @@ Attributes::Attributes(std::vector<AttrPtr> a,
|
|||
AddAttr(std::move(attr));
|
||||
}
|
||||
|
||||
void Attributes::AddAttr(AttrPtr attr)
|
||||
void Attributes::AddAttr(AttrPtr attr, bool is_redef)
|
||||
{
|
||||
auto acceptable_duplicate_attr = [](const AttrPtr& attr, const AttrPtr& existing) -> bool
|
||||
{
|
||||
AttrTag new_tag = attr->Tag();
|
||||
|
||||
if ( new_tag == ATTR_DEPRECATED )
|
||||
{
|
||||
if ( ! attr->DeprecationMessage().empty() ||
|
||||
( existing && ! existing->DeprecationMessage().empty() ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return new_tag == ATTR_LOG || new_tag == ATTR_OPTIONAL || new_tag == ATTR_REDEF ||
|
||||
new_tag == ATTR_BROKER_STORE_ALLOW_COMPLEX || new_tag == ATTR_RAW_OUTPUT ||
|
||||
new_tag == ATTR_ERROR_HANDLER;
|
||||
};
|
||||
|
||||
// A `redef` is allowed to overwrite an existing attribute instead of
|
||||
// flagging it as ambiguous.
|
||||
if ( ! is_redef )
|
||||
{
|
||||
auto existing = Find(attr->Tag());
|
||||
if ( existing && ! acceptable_duplicate_attr(attr, existing) )
|
||||
reporter->Error("Duplicate %s attribute is ambiguous", attr_name(attr->Tag()));
|
||||
}
|
||||
|
||||
// We overwrite old attributes by deleting them first.
|
||||
RemoveAttr(attr->Tag());
|
||||
attrs_list.push_back(attr.get());
|
||||
|
@ -224,16 +251,16 @@ void Attributes::AddAttr(AttrPtr attr)
|
|||
}
|
||||
}
|
||||
|
||||
void Attributes::AddAttrs(const AttributesPtr& a)
|
||||
void Attributes::AddAttrs(const AttributesPtr& a, bool is_redef)
|
||||
{
|
||||
for ( const auto& attr : a->GetAttrs() )
|
||||
AddAttr(attr);
|
||||
AddAttr(attr, is_redef);
|
||||
}
|
||||
|
||||
void Attributes::AddAttrs(Attributes* a)
|
||||
void Attributes::AddAttrs(Attributes* a, bool is_redef)
|
||||
{
|
||||
for ( const auto& attr : a->GetAttrs() )
|
||||
AddAttr(attr);
|
||||
AddAttr(attr, is_redef);
|
||||
|
||||
Unref(a);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue