mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 01:28:20 +00:00
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:
parent
87962a48dd
commit
011e2cdd32
7 changed files with 53 additions and 6 deletions
10
src/ID.cc
10
src/ID.cc
|
@ -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)
|
void ID::AddAttrs(Attributes* a)
|
||||||
{
|
{
|
||||||
if ( attrs )
|
if ( attrs )
|
||||||
|
|
2
src/ID.h
2
src/ID.h
|
@ -83,6 +83,8 @@ public:
|
||||||
bool IsDeprecated() const
|
bool IsDeprecated() const
|
||||||
{ return FindAttr(ATTR_DEPRECATED) != 0; }
|
{ return FindAttr(ATTR_DEPRECATED) != 0; }
|
||||||
|
|
||||||
|
void MakeDeprecated();
|
||||||
|
|
||||||
void Error(const char* msg, const BroObj* o2 = 0);
|
void Error(const char* msg, const BroObj* o2 = 0);
|
||||||
|
|
||||||
void Describe(ODesc* d) const;
|
void Describe(ODesc* d) const;
|
||||||
|
|
|
@ -1479,11 +1479,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
|
||||||
id->SetEnumConst();
|
id->SetEnumConst();
|
||||||
|
|
||||||
if ( deprecated )
|
if ( deprecated )
|
||||||
{
|
id->MakeDeprecated();
|
||||||
attr_list* attr = new attr_list;
|
|
||||||
attr->append(new Attr(ATTR_DEPRECATED));
|
|
||||||
id->AddAttrs(new Attributes(attr, id->Type(), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
broxygen_mgr->Identifier(id);
|
broxygen_mgr->Identifier(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -435,6 +435,10 @@ void end_func(Stmt* body, attr_list* attrs)
|
||||||
loop_over_list(*attrs, i)
|
loop_over_list(*attrs, i)
|
||||||
{
|
{
|
||||||
Attr* a = (*attrs)[i];
|
Attr* a = (*attrs)[i];
|
||||||
|
|
||||||
|
if ( a->Tag() == ATTR_DEPRECATED )
|
||||||
|
continue;
|
||||||
|
|
||||||
if ( a->Tag() != ATTR_PRIORITY )
|
if ( a->Tag() != ATTR_PRIORITY )
|
||||||
{
|
{
|
||||||
a->Error("illegal attribute for function body");
|
a->Error("illegal attribute for function body");
|
||||||
|
|
23
src/parse.y
23
src/parse.y
|
@ -227,6 +227,18 @@ static bool expr_is_table_type_name(const Expr* expr)
|
||||||
|
|
||||||
return false;
|
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 {
|
%union {
|
||||||
|
@ -1147,6 +1159,9 @@ func_body:
|
||||||
{
|
{
|
||||||
saved_in_init.push_back(in_init);
|
saved_in_init.push_back(in_init);
|
||||||
in_init = 0;
|
in_init = 0;
|
||||||
|
|
||||||
|
if ( has_attr($1, ATTR_DEPRECATED) )
|
||||||
|
current_scope()->ScopeID()->MakeDeprecated();
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt_list
|
stmt_list
|
||||||
|
@ -1571,7 +1586,13 @@ global_or_event_id:
|
||||||
$$->Error("already a local identifier");
|
$$->Error("already a local identifier");
|
||||||
|
|
||||||
if ( $$->IsDeprecated() )
|
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;
|
delete [] $1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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 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 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
|
ZERO
|
||||||
ONE
|
ONE
|
||||||
TWO
|
TWO
|
||||||
|
|
|
@ -66,3 +66,15 @@ function hmm(b: blah)
|
||||||
{
|
{
|
||||||
print b;
|
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();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue