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:
Jon Siwek 2019-06-21 12:26:08 -07:00
commit 16785a2d70
13 changed files with 269 additions and 74 deletions

View file

@ -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 )