diff --git a/src/Expr.cc b/src/Expr.cc index f37669eae1..68933eb228 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3063,6 +3063,15 @@ void IndexExpr::ExprDescribe(ODesc* d) const 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) : UnaryExpr(EXPR_FIELD, std::move(arg_op)), field_name(util::copy_string(arg_field_name)), td(nullptr), field(0) @@ -3085,7 +3094,7 @@ FieldExpr::FieldExpr(ExprPtr arg_op, const char* arg_field_name) td = rt->FieldDecl(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 ) ExprError("no such field in record"); else if ( rt->IsFieldDeprecated(field) ) - Warn(rt->GetFieldDeprecationWarning(field, true).c_str()); + report_field_deprecation(rt, this, field, true); SetType(base_type(TYPE_BOOL)); } @@ -3301,7 +3310,7 @@ RecordConstructorExpr::RecordConstructorExpr(RecordTypePtr known_rt, ListExprPtr } } 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 @@ -4092,7 +4101,7 @@ RecordCoerceExpr::RecordCoerceExpr(ExprPtr arg_op, RecordTypePtr r) } } else if ( t_r->IsFieldDeprecated(i) ) - Warn(t_r->GetFieldDeprecationWarning(i, false).c_str()); + report_field_deprecation(t_r, this, i); } } } diff --git a/src/Var.cc b/src/Var.cc index 587ab9caf4..a21abb2e73 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -6,6 +6,7 @@ #include +#include "zeek/Desc.h" #include "zeek/EventRegistry.h" #include "zeek/Expr.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", // including none, to be followed by an expression. // 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 // language/redef-same-prefixtable-idx.zeek btest, treat @@ -537,14 +541,13 @@ static std::optional func_type_check(const FuncType* decl, { auto msg = ad->DeprecationMessage(); - if ( msg.empty() ) - impl->Warn( - util::fmt("use of deprecated parameter '%s'", rval->args->FieldName(i)), - decl, true); - else - impl->Warn(util::fmt("use of deprecated parameter '%s': %s", - rval->args->FieldName(i), msg.data()), - decl, true); + if ( ! msg.empty() ) + msg = ": " + msg; + + reporter->Deprecation(util::fmt("use of deprecated parameter '%s'%s (%s)", + rval->args->FieldName(i), msg.data(), + obj_desc_short(impl).c_str()), + impl->GetLocationInfo(), decl->GetLocationInfo()); } return rval; @@ -605,13 +608,13 @@ static auto get_prototype(IDPtr id, FuncTypePtr t) if ( prototype->deprecated ) { - if ( prototype->deprecation_msg.empty() ) - t->Warn(util::fmt("use of deprecated '%s' prototype", id->Name()), - prototype->args.get(), true); - else - t->Warn(util::fmt("use of deprecated '%s' prototype: %s", id->Name(), - prototype->deprecation_msg.data()), - prototype->args.get(), true); + auto msg = prototype->deprecation_msg; + if ( ! msg.empty() ) + msg = ": " + msg; + + reporter->Deprecation(util::fmt("use of deprecated '%s' prototype%s (%s)", id->Name(), + msg.c_str(), obj_desc_short(t.get()).c_str()), + t->GetLocationInfo(), prototype->args->GetLocationInfo()); } } diff --git a/src/logging/writers/ascii/Ascii.cc b/src/logging/writers/ascii/Ascii.cc index 0e4e6150cc..fd73b4a9c2 100644 --- a/src/logging/writers/ascii/Ascii.cc +++ b/src/logging/writers/ascii/Ascii.cc @@ -385,7 +385,7 @@ bool Ascii::InitFilterOptions() // This doesn't play nice with leftover log rotation // and log rotation in general. There's no documentation // 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); } } diff --git a/src/parse.y b/src/parse.y index e7fe98c074..2334b2eae3 100644 --- a/src/parse.y +++ b/src/parse.y @@ -952,7 +952,7 @@ expr: else { if ( id->IsDeprecated() ) - reporter->Warning("%s", id->GetDeprecationWarning().c_str()); + reporter->Deprecation(id->GetDeprecationWarning()); if ( id->IsBlank() ) { @@ -1286,7 +1286,7 @@ type: Ref($$); if ( $1->IsDeprecated() ) - reporter->Warning("%s", $1->GetDeprecationWarning().c_str()); + reporter->Deprecation($1->GetDeprecationWarning()); } } ; @@ -1995,7 +1995,7 @@ event: } if ( id->IsDeprecated() ) - reporter->Warning("%s", id->GetDeprecationWarning().c_str()); + reporter->Deprecation(id->GetDeprecationWarning()); $$ = new EventExpr(id->Name(), {AdoptRef{}, $3}); } @@ -2202,7 +2202,7 @@ global_or_event_id: if ( t->Tag() != TYPE_FUNC || t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) - reporter->Warning("%s", $$->GetDeprecationWarning().c_str()); + reporter->Deprecation($$->GetDeprecationWarning()); } delete [] $1; diff --git a/src/scan.l b/src/scan.l index 3540c5b8a6..aeb9ba2e0a 100644 --- a/src/scan.l +++ b/src/scan.l @@ -339,19 +339,18 @@ when return TOK_WHEN; @deprecated.* { auto num_files = file_stack.length(); auto comment = zeek::util::skip_whitespace(yytext + 11); + std::string loaded_from; if ( num_files > 0 ) { auto lf = file_stack[num_files - 1]; - if ( lf->name ) - zeek::reporter->Warning("deprecated script loaded from %s:%d %s", - lf->name, lf->line, comment); + loaded_from = zeek::util::fmt(" from %s:%d", lf->name, lf->line); 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