mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Switch deprecations to reporter->Deprecation()
Removes a bit of reliance around the magic DoLog() rendering at the cost of needing to open-code some of it. The new obj_desc_short() helper makes that acceptable, though.
This commit is contained in:
parent
2f93592c6f
commit
384b4de764
5 changed files with 42 additions and 31 deletions
17
src/Expr.cc
17
src/Expr.cc
|
@ -3063,6 +3063,15 @@ void IndexExpr::ExprDescribe(ODesc* d) const
|
||||||
d->Add("]");
|
d->Add("]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void report_field_deprecation(const RecordType* rt, const Expr* e, int field,
|
||||||
|
bool has_check = false)
|
||||||
|
{
|
||||||
|
reporter->Deprecation(util::fmt("%s (%s)",
|
||||||
|
rt->GetFieldDeprecationWarning(field, has_check).c_str(),
|
||||||
|
obj_desc_short(e).c_str()),
|
||||||
|
e->GetLocationInfo());
|
||||||
|
}
|
||||||
|
|
||||||
FieldExpr::FieldExpr(ExprPtr arg_op, const char* arg_field_name)
|
FieldExpr::FieldExpr(ExprPtr arg_op, const char* arg_field_name)
|
||||||
: UnaryExpr(EXPR_FIELD, std::move(arg_op)), field_name(util::copy_string(arg_field_name)),
|
: UnaryExpr(EXPR_FIELD, std::move(arg_op)), field_name(util::copy_string(arg_field_name)),
|
||||||
td(nullptr), field(0)
|
td(nullptr), field(0)
|
||||||
|
@ -3085,7 +3094,7 @@ FieldExpr::FieldExpr(ExprPtr arg_op, const char* arg_field_name)
|
||||||
td = rt->FieldDecl(field);
|
td = rt->FieldDecl(field);
|
||||||
|
|
||||||
if ( rt->IsFieldDeprecated(field) )
|
if ( rt->IsFieldDeprecated(field) )
|
||||||
Warn(rt->GetFieldDeprecationWarning(field, false).c_str());
|
report_field_deprecation(rt, this, field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3170,7 +3179,7 @@ HasFieldExpr::HasFieldExpr(ExprPtr arg_op, const char* arg_field_name)
|
||||||
if ( field < 0 )
|
if ( field < 0 )
|
||||||
ExprError("no such field in record");
|
ExprError("no such field in record");
|
||||||
else if ( rt->IsFieldDeprecated(field) )
|
else if ( rt->IsFieldDeprecated(field) )
|
||||||
Warn(rt->GetFieldDeprecationWarning(field, true).c_str());
|
report_field_deprecation(rt, this, field, true);
|
||||||
|
|
||||||
SetType(base_type(TYPE_BOOL));
|
SetType(base_type(TYPE_BOOL));
|
||||||
}
|
}
|
||||||
|
@ -3301,7 +3310,7 @@ RecordConstructorExpr::RecordConstructorExpr(RecordTypePtr known_rt, ListExprPtr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( known_rt->IsFieldDeprecated(i) )
|
else if ( known_rt->IsFieldDeprecated(i) )
|
||||||
Warn(known_rt->GetFieldDeprecationWarning(i, false).c_str());
|
report_field_deprecation(known_rt.get(), this, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
ValPtr RecordConstructorExpr::Eval(Frame* f) const
|
ValPtr RecordConstructorExpr::Eval(Frame* f) const
|
||||||
|
@ -4092,7 +4101,7 @@ RecordCoerceExpr::RecordCoerceExpr(ExprPtr arg_op, RecordTypePtr r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( t_r->IsFieldDeprecated(i) )
|
else if ( t_r->IsFieldDeprecated(i) )
|
||||||
Warn(t_r->GetFieldDeprecationWarning(i, false).c_str());
|
report_field_deprecation(t_r, this, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
35
src/Var.cc
35
src/Var.cc
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "zeek/Desc.h"
|
||||||
#include "zeek/EventRegistry.h"
|
#include "zeek/EventRegistry.h"
|
||||||
#include "zeek/Expr.h"
|
#include "zeek/Expr.h"
|
||||||
#include "zeek/Func.h"
|
#include "zeek/Func.h"
|
||||||
|
@ -194,7 +195,10 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init,
|
||||||
// This can happen because the grammar allows any "init_class",
|
// This can happen because the grammar allows any "init_class",
|
||||||
// including none, to be followed by an expression.
|
// including none, to be followed by an expression.
|
||||||
// Remove in v6.1 (make an error)
|
// Remove in v6.1 (make an error)
|
||||||
init->Warn("Remove in v6.1. Initialization not preceded by =/+=/-= is deprecated.");
|
reporter->Deprecation(
|
||||||
|
util::fmt("Remove in v6.1. Initialization not preceded by =/+=/-= is deprecated. (%s)",
|
||||||
|
obj_desc_short(init.get()).c_str()),
|
||||||
|
init->GetLocationInfo());
|
||||||
|
|
||||||
// The historical instances of these, such as the
|
// The historical instances of these, such as the
|
||||||
// language/redef-same-prefixtable-idx.zeek btest, treat
|
// language/redef-same-prefixtable-idx.zeek btest, treat
|
||||||
|
@ -537,14 +541,13 @@ static std::optional<FuncType::Prototype> func_type_check(const FuncType* decl,
|
||||||
{
|
{
|
||||||
auto msg = ad->DeprecationMessage();
|
auto msg = ad->DeprecationMessage();
|
||||||
|
|
||||||
if ( msg.empty() )
|
if ( ! msg.empty() )
|
||||||
impl->Warn(
|
msg = ": " + msg;
|
||||||
util::fmt("use of deprecated parameter '%s'", rval->args->FieldName(i)),
|
|
||||||
decl, true);
|
reporter->Deprecation(util::fmt("use of deprecated parameter '%s'%s (%s)",
|
||||||
else
|
rval->args->FieldName(i), msg.data(),
|
||||||
impl->Warn(util::fmt("use of deprecated parameter '%s': %s",
|
obj_desc_short(impl).c_str()),
|
||||||
rval->args->FieldName(i), msg.data()),
|
impl->GetLocationInfo(), decl->GetLocationInfo());
|
||||||
decl, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
|
@ -605,13 +608,13 @@ static auto get_prototype(IDPtr id, FuncTypePtr t)
|
||||||
|
|
||||||
if ( prototype->deprecated )
|
if ( prototype->deprecated )
|
||||||
{
|
{
|
||||||
if ( prototype->deprecation_msg.empty() )
|
auto msg = prototype->deprecation_msg;
|
||||||
t->Warn(util::fmt("use of deprecated '%s' prototype", id->Name()),
|
if ( ! msg.empty() )
|
||||||
prototype->args.get(), true);
|
msg = ": " + msg;
|
||||||
else
|
|
||||||
t->Warn(util::fmt("use of deprecated '%s' prototype: %s", id->Name(),
|
reporter->Deprecation(util::fmt("use of deprecated '%s' prototype%s (%s)", id->Name(),
|
||||||
prototype->deprecation_msg.data()),
|
msg.c_str(), obj_desc_short(t.get()).c_str()),
|
||||||
prototype->args.get(), true);
|
t->GetLocationInfo(), prototype->args->GetLocationInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -385,7 +385,7 @@ bool Ascii::InitFilterOptions()
|
||||||
// This doesn't play nice with leftover log rotation
|
// This doesn't play nice with leftover log rotation
|
||||||
// and log rotation in general. There's no documentation
|
// and log rotation in general. There's no documentation
|
||||||
// or a test for this specifically, so deprecate it.
|
// or a test for this specifically, so deprecate it.
|
||||||
reporter->Warning("Remove in v6.1. Per writer logdir is deprecated.");
|
reporter->Deprecation("Remove in v6.1. Per writer logdir is deprecated.");
|
||||||
logdir.assign(i->second);
|
logdir.assign(i->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -952,7 +952,7 @@ expr:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( id->IsDeprecated() )
|
if ( id->IsDeprecated() )
|
||||||
reporter->Warning("%s", id->GetDeprecationWarning().c_str());
|
reporter->Deprecation(id->GetDeprecationWarning());
|
||||||
|
|
||||||
if ( id->IsBlank() )
|
if ( id->IsBlank() )
|
||||||
{
|
{
|
||||||
|
@ -1286,7 +1286,7 @@ type:
|
||||||
Ref($$);
|
Ref($$);
|
||||||
|
|
||||||
if ( $1->IsDeprecated() )
|
if ( $1->IsDeprecated() )
|
||||||
reporter->Warning("%s", $1->GetDeprecationWarning().c_str());
|
reporter->Deprecation($1->GetDeprecationWarning());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -1995,7 +1995,7 @@ event:
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( id->IsDeprecated() )
|
if ( id->IsDeprecated() )
|
||||||
reporter->Warning("%s", id->GetDeprecationWarning().c_str());
|
reporter->Deprecation(id->GetDeprecationWarning());
|
||||||
|
|
||||||
$$ = new EventExpr(id->Name(), {AdoptRef{}, $3});
|
$$ = new EventExpr(id->Name(), {AdoptRef{}, $3});
|
||||||
}
|
}
|
||||||
|
@ -2202,7 +2202,7 @@ global_or_event_id:
|
||||||
|
|
||||||
if ( t->Tag() != TYPE_FUNC ||
|
if ( t->Tag() != TYPE_FUNC ||
|
||||||
t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION )
|
t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION )
|
||||||
reporter->Warning("%s", $$->GetDeprecationWarning().c_str());
|
reporter->Deprecation($$->GetDeprecationWarning());
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] $1;
|
delete [] $1;
|
||||||
|
|
11
src/scan.l
11
src/scan.l
|
@ -339,19 +339,18 @@ when return TOK_WHEN;
|
||||||
@deprecated.* {
|
@deprecated.* {
|
||||||
auto num_files = file_stack.length();
|
auto num_files = file_stack.length();
|
||||||
auto comment = zeek::util::skip_whitespace(yytext + 11);
|
auto comment = zeek::util::skip_whitespace(yytext + 11);
|
||||||
|
std::string loaded_from;
|
||||||
|
|
||||||
if ( num_files > 0 )
|
if ( num_files > 0 )
|
||||||
{
|
{
|
||||||
auto lf = file_stack[num_files - 1];
|
auto lf = file_stack[num_files - 1];
|
||||||
|
|
||||||
if ( lf->name )
|
if ( lf->name )
|
||||||
zeek::reporter->Warning("deprecated script loaded from %s:%d %s",
|
loaded_from = zeek::util::fmt(" from %s:%d", lf->name, lf->line);
|
||||||
lf->name, lf->line, comment);
|
|
||||||
else
|
else
|
||||||
zeek::reporter->Warning("deprecated script loaded from command line arguments %s", comment);
|
loaded_from = " from command line arguments";
|
||||||
}
|
}
|
||||||
else
|
|
||||||
zeek::reporter->Warning("deprecated script loaded %s", comment);
|
zeek::reporter->Deprecation(zeek::util::fmt("deprecated script loaded%s %s", loaded_from.c_str(), comment));
|
||||||
}
|
}
|
||||||
|
|
||||||
@DEBUG return TOK_DEBUG; // marks input for debugger
|
@DEBUG return TOK_DEBUG; // marks input for debugger
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue