diff --git a/src/Func.cc b/src/Func.cc index 5d4da73ced..2ee53e465e 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 = FType()->Args(); + RecordType* func_args = GetType()->Args(); auto num_fields = static_cast(func_args->NumFields()); for ( auto i = 0u; i < args->size(); ++i ) @@ -244,7 +244,7 @@ std::pair Func::HandlePluginResult(std::pair plugin_resu case FUNC_FLAVOR_FUNCTION: { - const auto& yt = FType()->Yield(); + const auto& yt = GetType()->Yield(); if ( (! yt) || yt->Tag() == TYPE_VOID ) { @@ -270,7 +270,7 @@ BroFunc::BroFunc(ID* arg_id, IntrusivePtr arg_body, id_list* aggr_inits, : Func(BRO_FUNC) { name = arg_id->Name(); - type = arg_id->GetType(); + type = arg_id->GetType(); frame_size = arg_frame_size; if ( arg_body ) @@ -345,7 +345,7 @@ IntrusivePtr BroFunc::Call(const zeek::Args& args, Frame* parent) const DescribeDebug(&d, &args); g_trace_state.LogTrace("%s called: %s\n", - FType()->FlavorString().c_str(), d.Description()); + GetType()->FlavorString().c_str(), d.Description()); } stmt_flow_type flow = FLOW_NEXT; @@ -422,7 +422,7 @@ IntrusivePtr BroFunc::Call(const zeek::Args& args, Frame* parent) const // Warn if the function returns something, but we returned from // the function without an explicit return, or without a value. - else if ( FType()->Yield() && FType()->Yield()->Tag() != TYPE_VOID && + else if ( GetType()->Yield() && GetType()->Yield()->Tag() != TYPE_VOID && (flow != FLOW_RETURN /* we fell off the end */ || ! result /* explicit return with no result */) && ! f->HasDelayed() ) @@ -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 = FType()->Args()->NumFields(); + auto num_args = GetType()->Args()->NumFields(); if ( num_args > static_cast(frame_size) ) frame_size = num_args; @@ -592,7 +592,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, if ( id->HasVal() ) reporter->InternalError("built-in function %s multiply defined", Name()); - type = id->GetType(); + type = id->GetType(); id->SetVal(make_intrusive(IntrusivePtr{NewRef{}, this})); } diff --git a/src/Func.h b/src/Func.h index 9eaedd5ac8..6bec0d259c 100644 --- a/src/Func.h +++ b/src/Func.h @@ -37,7 +37,7 @@ public: ~Func() override; virtual bool IsPure() const = 0; - function_flavor Flavor() const { return FType()->Flavor(); } + function_flavor Flavor() const { return GetType()->Flavor(); } struct Body { IntrusivePtr stmts; @@ -78,7 +78,11 @@ public: virtual void SetScope(IntrusivePtr newscope); virtual Scope* GetScope() const { return scope.get(); } - virtual FuncType* FType() const { return type->AsFuncType(); } + [[deprecated("Remove in v4.1. Use GetType().")]] + virtual FuncType* FType() const { return type.get(); } + + const IntrusivePtr& GetType() const + { return type; } Kind GetKind() const { return kind; } @@ -112,7 +116,7 @@ protected: IntrusivePtr scope; Kind kind; uint32_t unique_id; - IntrusivePtr type; + IntrusivePtr type; std::string name; static inline std::vector> unique_ids; }; diff --git a/src/ID.h b/src/ID.h index 631bff4179..0cce2e4239 100644 --- a/src/ID.h +++ b/src/ID.h @@ -51,6 +51,10 @@ public: const IntrusivePtr& GetType() const { return type; } + template + IntrusivePtr GetType() const + { return cast_intrusive(type); } + [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] BroType* AsType() { return is_type ? GetType().get() : nullptr; } [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] diff --git a/src/Val.cc b/src/Val.cc index 53769963ca..533f433989 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -46,7 +46,7 @@ Val::Val(Func* f) : Val({NewRef{}, f}) {} Val::Val(IntrusivePtr f) - : val(f.release()), type({NewRef{}, val.func_val->FType()}) + : val(f.release()), type(val.func_val->GetType()) {} static const IntrusivePtr& GetStringFileType() noexcept @@ -269,7 +269,7 @@ IntrusivePtr Val::SizeVal() const case TYPE_INTERNAL_OTHER: if ( type->Tag() == TYPE_FUNC ) - return val_mgr->Count(val.func_val->FType()->ArgTypes()->Types().size()); + return val_mgr->Count(val.func_val->GetType()->ArgTypes()->Types().size()); if ( type->Tag() == TYPE_FILE ) return make_intrusive(val.file_val->Size(), TYPE_DOUBLE); @@ -2482,7 +2482,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) const Func* f = vf->AsFunc(); zeek::Args vl; - const auto& func_args = f->FType()->ArgTypes()->Types(); + const auto& func_args = f->GetType()->ArgTypes()->Types(); // backwards compatibility with idx: any idiom bool any_idiom = func_args.size() == 2 && func_args.back()->Tag() == TYPE_ANY; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 446ac93fd2..ab2851e4af 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->FType()->Args()->NumFields(); + auto num_args = func->GetType()->Args()->NumFields(); if ( num_args != args->length() - 1 ) { @@ -741,7 +741,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) } const auto& got_type = (*args)[i]->GetType(); - const auto& expected_type = func->FType()->ArgTypes()->Types()[i - 1]; + const auto& expected_type = func->GetType()->ArgTypes()->Types()[i - 1]; if ( ! same_type(got_type.get(), expected_type.get()) ) { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 4b80d657a1..9fceb2ee67 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -326,7 +326,7 @@ bool Manager::CreateEventStream(RecordVal* fval) Func* event = fval->Lookup("ev", true)->AsFunc(); - FuncType* etype = event->FType()->AsFuncType(); + const auto& etype = event->GetType(); bool allow_file_func = false; @@ -556,7 +556,7 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( event ) { - FuncType* etype = event->FType()->AsFuncType(); + const auto& etype = event->GetType(); if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) { @@ -703,7 +703,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e if ( ev == nullptr ) return true; - FuncType* etype = ev->FType()->AsFuncType(); + const auto& etype = ev->GetType(); if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index cbaf7c53e7..935c76f77d 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -270,7 +270,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) if ( event ) { // Make sure the event is prototyped as expected. - FuncType* etype = event->FType()->AsFuncType(); + const auto& etype = event->GetType(); if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) { @@ -401,7 +401,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, if ( j < num_ext_fields ) { i = j; - rtype = filter->ext_func->FType()->Yield()->AsRecordType(); + rtype = filter->ext_func->GetType()->Yield()->AsRecordType(); } else { @@ -587,18 +587,18 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) filter->num_ext_fields = 0; if ( filter->ext_func ) { - if ( filter->ext_func->FType()->Yield()->Tag() == TYPE_RECORD ) + if ( filter->ext_func->GetType()->Yield()->Tag() == TYPE_RECORD ) { - filter->num_ext_fields = filter->ext_func->FType()->Yield()->AsRecordType()->NumFields(); + filter->num_ext_fields = filter->ext_func->GetType()->Yield()->AsRecordType()->NumFields(); } - else if ( filter->ext_func->FType()->Yield()->Tag() == TYPE_VOID ) + else if ( filter->ext_func->GetType()->Yield()->Tag() == TYPE_VOID ) { // This is a special marker for the default no-implementation // of the ext_func and we'll allow it to slide. } else { - reporter->Error("Return value of log_ext is not a record (got %s)", type_name(filter->ext_func->FType()->Yield()->Tag())); + reporter->Error("Return value of log_ext is not a record (got %s)", type_name(filter->ext_func->GetType()->Yield()->Tag())); delete filter; return false; } @@ -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->FType()->Args()->GetFieldType("rec"); + const auto& rt = filter->path_func->GetType()->Args()->GetFieldType("rec"); if ( rt->Tag() == TYPE_RECORD ) rec_arg = columns->CoerceTo(rt->AsRecordType(), true); diff --git a/src/option.bif b/src/option.bif index 352ffb9631..de9d2894c7 100644 --- a/src/option.bif +++ b/src/option.bif @@ -15,7 +15,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, const IntrusiveP { for ( auto handler_function : i->GetOptionHandlers() ) { - bool add_loc = handler_function->FType()->AsFuncType()->ArgTypes()->Types().size() == 3; + bool add_loc = handler_function->GetType()->ArgTypes()->Types().size() == 3; zeek::Args vl; vl.reserve(2 + add_loc); vl.emplace_back(NewRef{}, name); diff --git a/src/zeek.bif b/src/zeek.bif index 01d933dfcd..0af1ef72f3 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1435,7 +1435,8 @@ function sort%(v: any, ...%) : any if ( comp ) { - FuncType* comp_type = comp->FType()->AsFuncType(); + const auto& comp_type = comp->GetType(); + if ( comp_type->Yield()->Tag() != TYPE_INT || ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) { @@ -1516,7 +1517,7 @@ function order%(v: any, ...%) : index_vec if ( comp ) { - FuncType* comp_type = comp->FType()->AsFuncType(); + const auto& comp_type = comp->GetType()->AsFuncType(); if ( comp_type->Yield()->Tag() != TYPE_INT || ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) {