Improve use of &deprecated on functions.

- Don't report warnings on function definition if declaration is marked
  deprecated.
- Allow &deprecated to apply to a standalone function definition.
This commit is contained in:
Jon Siwek 2015-01-21 12:27:09 -06:00
parent 87962a48dd
commit 011e2cdd32
7 changed files with 53 additions and 6 deletions

View file

@ -248,6 +248,16 @@ void ID::UpdateValAttrs()
}
}
void ID::MakeDeprecated()
{
if ( IsDeprecated() )
return;
attr_list* attr = new attr_list;
attr->append(new Attr(ATTR_DEPRECATED));
AddAttrs(new Attributes(attr, Type(), false));
}
void ID::AddAttrs(Attributes* a)
{
if ( attrs )

View file

@ -83,6 +83,8 @@ public:
bool IsDeprecated() const
{ return FindAttr(ATTR_DEPRECATED) != 0; }
void MakeDeprecated();
void Error(const char* msg, const BroObj* o2 = 0);
void Describe(ODesc* d) const;

View file

@ -1479,11 +1479,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
id->SetEnumConst();
if ( deprecated )
{
attr_list* attr = new attr_list;
attr->append(new Attr(ATTR_DEPRECATED));
id->AddAttrs(new Attributes(attr, id->Type(), false));
}
id->MakeDeprecated();
broxygen_mgr->Identifier(id);
}

View file

@ -435,6 +435,10 @@ void end_func(Stmt* body, attr_list* attrs)
loop_over_list(*attrs, i)
{
Attr* a = (*attrs)[i];
if ( a->Tag() == ATTR_DEPRECATED )
continue;
if ( a->Tag() != ATTR_PRIORITY )
{
a->Error("illegal attribute for function body");

View file

@ -227,6 +227,18 @@ static bool expr_is_table_type_name(const Expr* expr)
return false;
}
static bool has_attr(const attr_list* al, attr_tag tag)
{
if ( ! al )
return false;
for ( int i = 0; i < al->length(); ++i )
if ( (*al)[i]->Tag() == tag )
return true;
return false;
}
%}
%union {
@ -1147,6 +1159,9 @@ func_body:
{
saved_in_init.push_back(in_init);
in_init = 0;
if ( has_attr($1, ATTR_DEPRECATED) )
current_scope()->ScopeID()->MakeDeprecated();
}
stmt_list
@ -1571,7 +1586,13 @@ global_or_event_id:
$$->Error("already a local identifier");
if ( $$->IsDeprecated() )
reporter->Warning("deprecated (%s)", $$->Name());
{
BroType* t = $$->Type();
if ( t->Tag() != TYPE_FUNC ||
t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION )
reporter->Warning("deprecated (%s)", $$->Name());
}
delete [] $1;
}

View file

@ -15,6 +15,8 @@ warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated
warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 55: deprecated (my_event)
warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 60: deprecated (my_hook)
warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 65: deprecated (blah)
warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 74: deprecated (dont_use_me)
warning in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.deprecated/deprecated.bro, line 79: deprecated (dont_use_me_either)
ZERO
ONE
TWO

View file

@ -66,3 +66,15 @@ function hmm(b: blah)
{
print b;
}
global dont_use_me: function() &deprecated;
function dont_use_me()
{
dont_use_me();
}
function dont_use_me_either() &deprecated
{
dont_use_me_either();
}