mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Deprecate Func::FType(), replace with Func::GetType()
This commit is contained in:
parent
0f5bb4b83d
commit
688bed97bc
9 changed files with 37 additions and 28 deletions
14
src/Func.cc
14
src/Func.cc
|
@ -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 = FType()->Args();
|
RecordType* func_args = GetType()->Args();
|
||||||
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 )
|
||||||
|
@ -244,7 +244,7 @@ std::pair<bool, Val*> Func::HandlePluginResult(std::pair<bool, Val*> plugin_resu
|
||||||
|
|
||||||
case FUNC_FLAVOR_FUNCTION:
|
case FUNC_FLAVOR_FUNCTION:
|
||||||
{
|
{
|
||||||
const auto& yt = FType()->Yield();
|
const auto& yt = GetType()->Yield();
|
||||||
|
|
||||||
if ( (! yt) || yt->Tag() == TYPE_VOID )
|
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)
|
: Func(BRO_FUNC)
|
||||||
{
|
{
|
||||||
name = arg_id->Name();
|
name = arg_id->Name();
|
||||||
type = arg_id->GetType();
|
type = arg_id->GetType<FuncType>();
|
||||||
frame_size = arg_frame_size;
|
frame_size = arg_frame_size;
|
||||||
|
|
||||||
if ( arg_body )
|
if ( arg_body )
|
||||||
|
@ -345,7 +345,7 @@ IntrusivePtr<Val> BroFunc::Call(const zeek::Args& args, Frame* parent) const
|
||||||
DescribeDebug(&d, &args);
|
DescribeDebug(&d, &args);
|
||||||
|
|
||||||
g_trace_state.LogTrace("%s called: %s\n",
|
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;
|
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
|
// Warn if the function returns something, but we returned from
|
||||||
// the function without an explicit return, or without a value.
|
// 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 */ ||
|
(flow != FLOW_RETURN /* we fell off the end */ ||
|
||||||
! result /* explicit return with no result */) &&
|
! result /* explicit return with no result */) &&
|
||||||
! f->HasDelayed() )
|
! f->HasDelayed() )
|
||||||
|
@ -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 = FType()->Args()->NumFields();
|
auto num_args = GetType()->Args()->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;
|
||||||
|
@ -592,7 +592,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
|
||||||
if ( id->HasVal() )
|
if ( id->HasVal() )
|
||||||
reporter->InternalError("built-in function %s multiply defined", Name());
|
reporter->InternalError("built-in function %s multiply defined", Name());
|
||||||
|
|
||||||
type = id->GetType();
|
type = id->GetType<FuncType>();
|
||||||
id->SetVal(make_intrusive<Val>(IntrusivePtr{NewRef{}, this}));
|
id->SetVal(make_intrusive<Val>(IntrusivePtr{NewRef{}, this}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/Func.h
10
src/Func.h
|
@ -37,7 +37,7 @@ public:
|
||||||
~Func() override;
|
~Func() override;
|
||||||
|
|
||||||
virtual bool IsPure() const = 0;
|
virtual bool IsPure() const = 0;
|
||||||
function_flavor Flavor() const { return FType()->Flavor(); }
|
function_flavor Flavor() const { return GetType()->Flavor(); }
|
||||||
|
|
||||||
struct Body {
|
struct Body {
|
||||||
IntrusivePtr<Stmt> stmts;
|
IntrusivePtr<Stmt> stmts;
|
||||||
|
@ -78,7 +78,11 @@ public:
|
||||||
virtual void SetScope(IntrusivePtr<Scope> newscope);
|
virtual void SetScope(IntrusivePtr<Scope> newscope);
|
||||||
virtual Scope* GetScope() const { return scope.get(); }
|
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; }
|
Kind GetKind() const { return kind; }
|
||||||
|
|
||||||
|
@ -112,7 +116,7 @@ protected:
|
||||||
IntrusivePtr<Scope> scope;
|
IntrusivePtr<Scope> scope;
|
||||||
Kind kind;
|
Kind kind;
|
||||||
uint32_t unique_id;
|
uint32_t unique_id;
|
||||||
IntrusivePtr<BroType> type;
|
IntrusivePtr<FuncType> type;
|
||||||
std::string name;
|
std::string name;
|
||||||
static inline std::vector<IntrusivePtr<Func>> unique_ids;
|
static inline std::vector<IntrusivePtr<Func>> unique_ids;
|
||||||
};
|
};
|
||||||
|
|
4
src/ID.h
4
src/ID.h
|
@ -51,6 +51,10 @@ public:
|
||||||
const IntrusivePtr<BroType>& GetType() const
|
const IntrusivePtr<BroType>& GetType() const
|
||||||
{ return type; }
|
{ return type; }
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
IntrusivePtr<T> GetType() const
|
||||||
|
{ return cast_intrusive<T>(type); }
|
||||||
|
|
||||||
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
|
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
|
||||||
BroType* AsType() { return is_type ? GetType().get() : nullptr; }
|
BroType* AsType() { return is_type ? GetType().get() : nullptr; }
|
||||||
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
|
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
|
||||||
|
|
|
@ -46,7 +46,7 @@ Val::Val(Func* f) : Val({NewRef{}, f})
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Val::Val(IntrusivePtr<Func> 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
|
static const IntrusivePtr<FileType>& GetStringFileType() noexcept
|
||||||
|
@ -269,7 +269,7 @@ IntrusivePtr<Val> Val::SizeVal() const
|
||||||
|
|
||||||
case TYPE_INTERNAL_OTHER:
|
case TYPE_INTERNAL_OTHER:
|
||||||
if ( type->Tag() == TYPE_FUNC )
|
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 )
|
if ( type->Tag() == TYPE_FILE )
|
||||||
return make_intrusive<Val>(val.file_val->Size(), TYPE_DOUBLE);
|
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();
|
const Func* f = vf->AsFunc();
|
||||||
zeek::Args vl;
|
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
|
// backwards compatibility with idx: any idiom
|
||||||
bool any_idiom = func_args.size() == 2 && func_args.back()->Tag() == TYPE_ANY;
|
bool any_idiom = func_args.size() == 2 && func_args.back()->Tag() == TYPE_ANY;
|
||||||
|
|
||||||
|
|
|
@ -727,7 +727,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame)
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto num_args = func->FType()->Args()->NumFields();
|
auto num_args = func->GetType()->Args()->NumFields();
|
||||||
|
|
||||||
if ( num_args != args->length() - 1 )
|
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& 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()) )
|
if ( ! same_type(got_type.get(), expected_type.get()) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -326,7 +326,7 @@ bool Manager::CreateEventStream(RecordVal* fval)
|
||||||
|
|
||||||
Func* event = fval->Lookup("ev", true)->AsFunc();
|
Func* event = fval->Lookup("ev", true)->AsFunc();
|
||||||
|
|
||||||
FuncType* etype = event->FType()->AsFuncType();
|
const auto& etype = event->GetType();
|
||||||
|
|
||||||
bool allow_file_func = false;
|
bool allow_file_func = false;
|
||||||
|
|
||||||
|
@ -556,7 +556,7 @@ bool Manager::CreateTableStream(RecordVal* fval)
|
||||||
|
|
||||||
if ( event )
|
if ( event )
|
||||||
{
|
{
|
||||||
FuncType* etype = event->FType()->AsFuncType();
|
const auto& etype = event->GetType();
|
||||||
|
|
||||||
if ( etype->Flavor() != FUNC_FLAVOR_EVENT )
|
if ( etype->Flavor() != FUNC_FLAVOR_EVENT )
|
||||||
{
|
{
|
||||||
|
@ -703,7 +703,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e
|
||||||
if ( ev == nullptr )
|
if ( ev == nullptr )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
FuncType* etype = ev->FType()->AsFuncType();
|
const auto& etype = ev->GetType();
|
||||||
|
|
||||||
if ( etype->Flavor() != FUNC_FLAVOR_EVENT )
|
if ( etype->Flavor() != FUNC_FLAVOR_EVENT )
|
||||||
{
|
{
|
||||||
|
|
|
@ -270,7 +270,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval)
|
||||||
if ( event )
|
if ( event )
|
||||||
{
|
{
|
||||||
// Make sure the event is prototyped as expected.
|
// Make sure the event is prototyped as expected.
|
||||||
FuncType* etype = event->FType()->AsFuncType();
|
const auto& etype = event->GetType();
|
||||||
|
|
||||||
if ( etype->Flavor() != FUNC_FLAVOR_EVENT )
|
if ( etype->Flavor() != FUNC_FLAVOR_EVENT )
|
||||||
{
|
{
|
||||||
|
@ -401,7 +401,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt,
|
||||||
if ( j < num_ext_fields )
|
if ( j < num_ext_fields )
|
||||||
{
|
{
|
||||||
i = j;
|
i = j;
|
||||||
rtype = filter->ext_func->FType()->Yield()->AsRecordType();
|
rtype = filter->ext_func->GetType()->Yield()->AsRecordType();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -587,18 +587,18 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval)
|
||||||
filter->num_ext_fields = 0;
|
filter->num_ext_fields = 0;
|
||||||
if ( filter->ext_func )
|
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
|
// This is a special marker for the default no-implementation
|
||||||
// of the ext_func and we'll allow it to slide.
|
// of the ext_func and we'll allow it to slide.
|
||||||
}
|
}
|
||||||
else
|
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;
|
delete filter;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -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->FType()->Args()->GetFieldType("rec");
|
const auto& rt = filter->path_func->GetType()->Args()->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);
|
||||||
|
|
|
@ -15,7 +15,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, const IntrusiveP
|
||||||
{
|
{
|
||||||
for ( auto handler_function : i->GetOptionHandlers() )
|
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;
|
zeek::Args vl;
|
||||||
vl.reserve(2 + add_loc);
|
vl.reserve(2 + add_loc);
|
||||||
vl.emplace_back(NewRef{}, name);
|
vl.emplace_back(NewRef{}, name);
|
||||||
|
|
|
@ -1435,7 +1435,8 @@ function sort%(v: any, ...%) : any
|
||||||
|
|
||||||
if ( comp )
|
if ( comp )
|
||||||
{
|
{
|
||||||
FuncType* comp_type = comp->FType()->AsFuncType();
|
const auto& comp_type = comp->GetType();
|
||||||
|
|
||||||
if ( comp_type->Yield()->Tag() != TYPE_INT ||
|
if ( comp_type->Yield()->Tag() != TYPE_INT ||
|
||||||
! comp_type->ArgTypes()->AllMatch(elt_type, 0) )
|
! comp_type->ArgTypes()->AllMatch(elt_type, 0) )
|
||||||
{
|
{
|
||||||
|
@ -1516,7 +1517,7 @@ function order%(v: any, ...%) : index_vec
|
||||||
|
|
||||||
if ( comp )
|
if ( comp )
|
||||||
{
|
{
|
||||||
FuncType* comp_type = comp->FType()->AsFuncType();
|
const auto& comp_type = comp->GetType()->AsFuncType();
|
||||||
if ( comp_type->Yield()->Tag() != TYPE_INT ||
|
if ( comp_type->Yield()->Tag() != TYPE_INT ||
|
||||||
! comp_type->ArgTypes()->AllMatch(elt_type, 0) )
|
! comp_type->ArgTypes()->AllMatch(elt_type, 0) )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue