From 40153cc5cbb5e9f6144856019b394f377ea0f307 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 19:04:31 -0700 Subject: [PATCH] Deprecate FuncType::Args(), replace with Params() --- NEWS | 2 ++ src/EventHandler.cc | 2 +- src/Func.cc | 4 ++-- src/Type.cc | 3 ++- src/Type.h | 4 ++++ src/Val.cc | 2 +- src/Var.cc | 18 +++++++++--------- src/broker/Manager.cc | 2 +- src/input/Manager.cc | 2 +- src/logging/Manager.cc | 2 +- 10 files changed, 24 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 909d9356b2..cae8a619d7 100644 --- a/NEWS +++ b/NEWS @@ -187,6 +187,8 @@ Deprecated Functionality - Constructors for ``Val`` types that take a ``BroType*`` are all generally deprecated, with alternatives that instead take an ``IntrusivePtr`` argument. +- ``FuncType::Args()`` is deprecated, use ``FuncType::Params()``. + Zeek 3.1.0 ========== diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 1f6172cbd8..45014bc73b 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -127,7 +127,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) // new_event() is the one event we don't want to report. return; - RecordType* args = GetType()->Args(); + const auto& args = GetType()->Params(); static auto call_argument_vector = zeek::id::find_type("call_argument_vector"); auto vargs = make_intrusive(call_argument_vector); diff --git a/src/Func.cc b/src/Func.cc index 2ee53e465e..3b1b5893fe 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -146,7 +146,7 @@ void Func::DescribeDebug(ODesc* d, const zeek::Args* args) const if ( args ) { d->Add("("); - RecordType* func_args = GetType()->Args(); + const auto& func_args = GetType()->Params(); auto num_fields = static_cast(func_args->NumFields()); for ( auto i = 0u; i < args->size(); ++i ) @@ -448,7 +448,7 @@ void BroFunc::AddBody(IntrusivePtr new_body, id_list* new_inits, if ( new_frame_size > frame_size ) frame_size = new_frame_size; - auto num_args = GetType()->Args()->NumFields(); + auto num_args = GetType()->Params()->NumFields(); if ( num_args > static_cast(frame_size) ) frame_size = num_args; diff --git a/src/Type.cc b/src/Type.cc index d5d17f7a3f..1fc09beb76 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1839,7 +1839,8 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) const FuncType* ft1 = (const FuncType*) t1; const FuncType* ft2 = (const FuncType*) t1; - auto args = cast_intrusive(merge_types(ft1->Args(), ft2->Args())); + auto args = cast_intrusive(merge_types(ft1->Params().get(), + ft2->Params().get())); auto yield = t1->Yield() ? merge_types(t1->Yield().get(), t2->Yield().get()) : nullptr; diff --git a/src/Type.h b/src/Type.h index ac537577e3..9ecedc0471 100644 --- a/src/Type.h +++ b/src/Type.h @@ -473,8 +473,12 @@ public: ~FuncType() override; + [[deprecated("Remove in v4.1. Use Params().")]] RecordType* Args() const { return args.get(); } + const IntrusivePtr& Params() const + { return args; } + const IntrusivePtr& Yield() const override { return yield; } diff --git a/src/Val.cc b/src/Val.cc index 5c8265b405..4d4c6b8e51 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1360,7 +1360,7 @@ static void find_nested_record_types(BroType* t, std::set* found) } return; case TYPE_FUNC: - find_nested_record_types(t->AsFuncType()->Args(), found); + find_nested_record_types(t->AsFuncType()->Params().get(), found); find_nested_record_types(t->AsFuncType()->Yield().get(), found); return; case TYPE_VECTOR: diff --git a/src/Var.cc b/src/Var.cc index a5d64a65d5..33895f5def 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -63,8 +63,8 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs, return false; } - auto canon_args = canon_ft->Args(); - auto alt_args = alt_ft->Args(); + const auto& canon_args = canon_ft->Params(); + const auto& alt_args = alt_ft->Params(); if ( auto p = canon_ft->FindPrototype(*alt_args); p ) { @@ -102,7 +102,7 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs, if ( a->Tag() == ATTR_DEPRECATED ) deprecated = true; - FuncType::Prototype p{deprecated, {NewRef{}, alt_args}, std::move(offsets)}; + FuncType::Prototype p{deprecated, alt_args, std::move(offsets)}; canon_ft->AddPrototype(std::move(p)); return true; } @@ -437,13 +437,13 @@ static std::optional func_type_check(const FuncType* decl, return {}; } - return decl->FindPrototype(*impl->Args()); + return decl->FindPrototype(*impl->Params()); } static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl) { - auto canon_args = decl->Args(); - auto impl_args = impl->Args(); + const auto& canon_args = decl->Params(); + const auto& impl_args = impl->Params(); if ( canon_args->NumFields() != impl_args->NumFields() ) return false; @@ -483,14 +483,14 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, // params, automatically transfer any that are missing // (convenience so that implementations don't need to specify // the &default expression again). - transfer_arg_defaults(prototype->args.get(), t->Args()); + transfer_arg_defaults(prototype->args.get(), t->Params().get()); } else { // Warn for trying to use &default parameters in hook/event // handler body when it already has a declaration since only // &default in the declaration has any effect. - auto args = t->Args(); + const auto& args = t->Params(); for ( int i = 0; i < args->NumFields(); ++i ) { @@ -555,7 +555,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, push_scope({NewRef{}, id}, attrs); - RecordType* args = t->Args(); + const auto& args = t->Params(); int num_args = args->NumFields(); for ( int i = 0; i < num_args; ++i ) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index de279a0b4b..c441f69900 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -727,7 +727,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) return rval; } - auto num_args = func->GetType()->Args()->NumFields(); + auto num_args = func->GetType()->Params()->NumFields(); if ( num_args != args->length() - 1 ) { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index efc9c48a36..be2832acc3 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1810,7 +1810,7 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu name.c_str(), num_vals); #endif - RecordType* type = handler->GetType()->Args(); + const auto& type = handler->GetType()->Params(); int num_event_vals = type->NumFields(); if ( num_vals != num_event_vals ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 935c76f77d..7bb597309b 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -744,7 +744,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) path_arg = val_mgr->EmptyString(); IntrusivePtr rec_arg; - const auto& rt = filter->path_func->GetType()->Args()->GetFieldType("rec"); + const auto& rt = filter->path_func->GetType()->Params()->GetFieldType("rec"); if ( rt->Tag() == TYPE_RECORD ) rec_arg = columns->CoerceTo(rt->AsRecordType(), true);