mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Merge remote-tracking branch 'origin/topic/timw/171-deprecation-warnings'
* origin/topic/timw/171-deprecation-warnings: GH-171: support warning messages alongside deprecated attributes Made a minor tweak to give a better error message when using &deprecated= with something other than a string literal expression.
This commit is contained in:
commit
16785a2d70
13 changed files with 269 additions and 74 deletions
24
src/ID.cc
24
src/ID.cc
|
@ -189,15 +189,35 @@ void ID::UpdateValAttrs()
|
|||
}
|
||||
}
|
||||
|
||||
void ID::MakeDeprecated()
|
||||
void ID::MakeDeprecated(Expr* deprecation)
|
||||
{
|
||||
if ( IsDeprecated() )
|
||||
return;
|
||||
|
||||
attr_list* attr = new attr_list{new Attr(ATTR_DEPRECATED)};
|
||||
attr_list* attr = new attr_list{new Attr(ATTR_DEPRECATED, deprecation)};
|
||||
AddAttrs(new Attributes(attr, Type(), false));
|
||||
}
|
||||
|
||||
string ID::GetDeprecationWarning() const
|
||||
{
|
||||
string result;
|
||||
Attr* depr_attr = FindAttr(ATTR_DEPRECATED);
|
||||
if ( depr_attr )
|
||||
{
|
||||
ConstExpr* expr = static_cast<ConstExpr*>(depr_attr->AttrExpr());
|
||||
if ( expr )
|
||||
{
|
||||
StringVal* text = expr->Value()->AsStringVal();
|
||||
result = text->CheckString();
|
||||
}
|
||||
}
|
||||
|
||||
if ( result.empty() )
|
||||
return fmt("deprecated (%s)", Name());
|
||||
else
|
||||
return fmt("deprecated (%s): %s", Name(), result.c_str());
|
||||
}
|
||||
|
||||
void ID::AddAttrs(Attributes* a)
|
||||
{
|
||||
if ( attrs )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue