Emit deprecation warning for use of &deprecated function parameters

Particularly, this is meant for using &deprecated on canonical
event/hook prototype parameters to encourage users to create handlers
to another, non-deprecated prototype.  i.e. for canonical prototypes,
we may not always want to put &deprecated directly on the prototype
itself since that signals deprecation of the ID entirely.
This commit is contained in:
Jon Siwek 2020-07-09 20:27:59 -07:00
parent 39f549ed68
commit 26b3d406b4
3 changed files with 42 additions and 1 deletions

View file

@ -450,7 +450,15 @@ static std::optional<zeek::FuncType::Prototype> func_type_check(const zeek::Func
return {};
}
return decl->FindPrototype(*impl->Params());
auto rval = decl->FindPrototype(*impl->Params());
if ( rval )
for ( auto i = 0; i < rval->args->NumFields(); ++i )
if ( rval->args->FieldDecl(i)->GetAttr(zeek::detail::ATTR_DEPRECATED) )
impl->Warn(fmt("use of deprecated parameter '%s'",
rval->args->FieldName(i)), decl, true);
return rval;
}
static bool canonical_arg_types_match(const zeek::FuncType* decl, const zeek::FuncType* impl)

View file

@ -0,0 +1,5 @@
warning in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.alternate-prototypes-deprecated-args/alternate-prototypes-deprecated-args.zeek, line 9 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.alternate-prototypes-deprecated-args/alternate-prototypes-deprecated-args.zeek, line 5: use of deprecated parameter 'b' (event(a:string; b:string; c:string;))
warning in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.alternate-prototypes-deprecated-args/alternate-prototypes-deprecated-args.zeek, line 19 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.alternate-prototypes-deprecated-args/alternate-prototypes-deprecated-args.zeek, line 5: use of deprecated prototype (event(a:string; b:string;) and myev)
myev (canon), one, two, three
myev (new), one, three
myev (old), one, two

View file

@ -0,0 +1,28 @@
# @TEST-EXEC: zeek -b %INPUT >out 2>&1
#
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
global myev: event(a: string, b: string &deprecated="Don't use 'b'", c: string);
global myev: event(a: string, c: string);
global myev: event(a: string, b: string) &deprecated="Don't use this prototype";
event myev(a: string, b: string, c: string) &priority=11
{
print "myev (canon)", a, b, c;
}
event myev(a: string, c: string) &priority = 7
{
print "myev (new)", a, c;
}
event myev(a: string, b: string) &priority = 5
{
print "myev (old)", a, b;
}
event zeek_init()
{
event myev("one", "two", "three");
}