Deprecate FuncType::Args(), replace with Params()

This commit is contained in:
Jon Siwek 2020-05-15 19:04:31 -07:00
parent 938ad35a43
commit 40153cc5cb
10 changed files with 24 additions and 17 deletions

2
NEWS
View file

@ -187,6 +187,8 @@ Deprecated Functionality
- Constructors for ``Val`` types that take a ``BroType*`` are all generally - Constructors for ``Val`` types that take a ``BroType*`` are all generally
deprecated, with alternatives that instead take an ``IntrusivePtr`` argument. deprecated, with alternatives that instead take an ``IntrusivePtr`` argument.
- ``FuncType::Args()`` is deprecated, use ``FuncType::Params()``.
Zeek 3.1.0 Zeek 3.1.0
========== ==========

View file

@ -127,7 +127,7 @@ void EventHandler::NewEvent(const zeek::Args& vl)
// new_event() is the one event we don't want to report. // new_event() is the one event we don't want to report.
return; return;
RecordType* args = GetType()->Args(); const auto& args = GetType()->Params();
static auto call_argument_vector = zeek::id::find_type<VectorType>("call_argument_vector"); static auto call_argument_vector = zeek::id::find_type<VectorType>("call_argument_vector");
auto vargs = make_intrusive<VectorVal>(call_argument_vector); auto vargs = make_intrusive<VectorVal>(call_argument_vector);

View file

@ -146,7 +146,7 @@ void Func::DescribeDebug(ODesc* d, const zeek::Args* args) const
if ( args ) if ( args )
{ {
d->Add("("); d->Add("(");
RecordType* func_args = GetType()->Args(); const auto& func_args = GetType()->Params();
auto num_fields = static_cast<size_t>(func_args->NumFields()); auto num_fields = static_cast<size_t>(func_args->NumFields());
for ( auto i = 0u; i < args->size(); ++i ) for ( auto i = 0u; i < args->size(); ++i )
@ -448,7 +448,7 @@ void BroFunc::AddBody(IntrusivePtr<Stmt> new_body, id_list* new_inits,
if ( new_frame_size > frame_size ) if ( new_frame_size > frame_size )
frame_size = new_frame_size; frame_size = new_frame_size;
auto num_args = GetType()->Args()->NumFields(); auto num_args = GetType()->Params()->NumFields();
if ( num_args > static_cast<int>(frame_size) ) if ( num_args > static_cast<int>(frame_size) )
frame_size = num_args; frame_size = num_args;

View file

@ -1839,7 +1839,8 @@ IntrusivePtr<BroType> merge_types(const BroType* t1, const BroType* t2)
const FuncType* ft1 = (const FuncType*) t1; const FuncType* ft1 = (const FuncType*) t1;
const FuncType* ft2 = (const FuncType*) t1; const FuncType* ft2 = (const FuncType*) t1;
auto args = cast_intrusive<RecordType>(merge_types(ft1->Args(), ft2->Args())); auto args = cast_intrusive<RecordType>(merge_types(ft1->Params().get(),
ft2->Params().get()));
auto yield = t1->Yield() ? auto yield = t1->Yield() ?
merge_types(t1->Yield().get(), t2->Yield().get()) : nullptr; merge_types(t1->Yield().get(), t2->Yield().get()) : nullptr;

View file

@ -473,8 +473,12 @@ public:
~FuncType() override; ~FuncType() override;
[[deprecated("Remove in v4.1. Use Params().")]]
RecordType* Args() const { return args.get(); } RecordType* Args() const { return args.get(); }
const IntrusivePtr<RecordType>& Params() const
{ return args; }
const IntrusivePtr<BroType>& Yield() const override const IntrusivePtr<BroType>& Yield() const override
{ return yield; } { return yield; }

View file

@ -1360,7 +1360,7 @@ static void find_nested_record_types(BroType* t, std::set<RecordType*>* found)
} }
return; return;
case TYPE_FUNC: 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); find_nested_record_types(t->AsFuncType()->Yield().get(), found);
return; return;
case TYPE_VECTOR: case TYPE_VECTOR:

View file

@ -63,8 +63,8 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs,
return false; return false;
} }
auto canon_args = canon_ft->Args(); const auto& canon_args = canon_ft->Params();
auto alt_args = alt_ft->Args(); const auto& alt_args = alt_ft->Params();
if ( auto p = canon_ft->FindPrototype(*alt_args); p ) 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 ) if ( a->Tag() == ATTR_DEPRECATED )
deprecated = true; 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)); canon_ft->AddPrototype(std::move(p));
return true; return true;
} }
@ -437,13 +437,13 @@ static std::optional<FuncType::Prototype> func_type_check(const FuncType* decl,
return {}; return {};
} }
return decl->FindPrototype(*impl->Args()); return decl->FindPrototype(*impl->Params());
} }
static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl) static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl)
{ {
auto canon_args = decl->Args(); const auto& canon_args = decl->Params();
auto impl_args = impl->Args(); const auto& impl_args = impl->Params();
if ( canon_args->NumFields() != impl_args->NumFields() ) if ( canon_args->NumFields() != impl_args->NumFields() )
return false; 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 // params, automatically transfer any that are missing
// (convenience so that implementations don't need to specify // (convenience so that implementations don't need to specify
// the &default expression again). // the &default expression again).
transfer_arg_defaults(prototype->args.get(), t->Args()); transfer_arg_defaults(prototype->args.get(), t->Params().get());
} }
else else
{ {
// Warn for trying to use &default parameters in hook/event // Warn for trying to use &default parameters in hook/event
// handler body when it already has a declaration since only // handler body when it already has a declaration since only
// &default in the declaration has any effect. // &default in the declaration has any effect.
auto args = t->Args(); const auto& args = t->Params();
for ( int i = 0; i < args->NumFields(); ++i ) 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); push_scope({NewRef{}, id}, attrs);
RecordType* args = t->Args(); const auto& args = t->Params();
int num_args = args->NumFields(); int num_args = args->NumFields();
for ( int i = 0; i < num_args; ++i ) for ( int i = 0; i < num_args; ++i )

View file

@ -727,7 +727,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame)
return rval; return rval;
} }
auto num_args = func->GetType()->Args()->NumFields(); auto num_args = func->GetType()->Params()->NumFields();
if ( num_args != args->length() - 1 ) if ( num_args != args->length() - 1 )
{ {

View file

@ -1810,7 +1810,7 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu
name.c_str(), num_vals); name.c_str(), num_vals);
#endif #endif
RecordType* type = handler->GetType()->Args(); const auto& type = handler->GetType()->Params();
int num_event_vals = type->NumFields(); int num_event_vals = type->NumFields();
if ( num_vals != num_event_vals ) if ( num_vals != num_event_vals )
{ {

View file

@ -744,7 +744,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg)
path_arg = val_mgr->EmptyString(); path_arg = val_mgr->EmptyString();
IntrusivePtr<Val> rec_arg; IntrusivePtr<Val> 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 ) if ( rt->Tag() == TYPE_RECORD )
rec_arg = columns->CoerceTo(rt->AsRecordType(), true); rec_arg = columns->CoerceTo(rt->AsRecordType(), true);