Deprecate Func::FType(), replace with Func::GetType()

This commit is contained in:
Jon Siwek 2020-05-15 18:21:06 -07:00
parent 0f5bb4b83d
commit 688bed97bc
9 changed files with 37 additions and 28 deletions

View file

@ -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<size_t>(func_args->NumFields());
for ( auto i = 0u; i < args->size(); ++i )
@ -244,7 +244,7 @@ std::pair<bool, Val*> Func::HandlePluginResult(std::pair<bool, Val*> 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<Stmt> arg_body, id_list* aggr_inits,
: Func(BRO_FUNC)
{
name = arg_id->Name();
type = arg_id->GetType();
type = arg_id->GetType<FuncType>();
frame_size = arg_frame_size;
if ( arg_body )
@ -345,7 +345,7 @@ IntrusivePtr<Val> 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<Val> 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<Stmt> 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<int>(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<FuncType>();
id->SetVal(make_intrusive<Val>(IntrusivePtr{NewRef{}, this}));
}

View file

@ -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<Stmt> stmts;
@ -78,7 +78,11 @@ public:
virtual void SetScope(IntrusivePtr<Scope> 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<FuncType>& GetType() const
{ return type; }
Kind GetKind() const { return kind; }
@ -112,7 +116,7 @@ protected:
IntrusivePtr<Scope> scope;
Kind kind;
uint32_t unique_id;
IntrusivePtr<BroType> type;
IntrusivePtr<FuncType> type;
std::string name;
static inline std::vector<IntrusivePtr<Func>> unique_ids;
};

View file

@ -51,6 +51,10 @@ public:
const IntrusivePtr<BroType>& GetType() const
{ return type; }
template <class T>
IntrusivePtr<T> GetType() const
{ return cast_intrusive<T>(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().")]]

View file

@ -46,7 +46,7 @@ Val::Val(Func* f) : Val({NewRef{}, f})
{}
Val::Val(IntrusivePtr<Func> f)
: val(f.release()), type({NewRef{}, val.func_val->FType()})
: val(f.release()), type(val.func_val->GetType())
{}
static const IntrusivePtr<FileType>& GetStringFileType() noexcept
@ -269,7 +269,7 @@ IntrusivePtr<Val> 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>(val.file_val->Size(), TYPE_DOUBLE);
@ -2482,7 +2482,7 @@ double TableVal::CallExpireFunc(IntrusivePtr<ListVal> 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;

View file

@ -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()) )
{

View file

@ -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 )
{

View file

@ -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<Val> 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);

View file

@ -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);

View file

@ -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) )
{