Move Func and associated classes into zeek::detail namespace

This commit is contained in:
Tim Wojtulewicz 2020-06-22 15:45:40 -07:00
parent 937a462e70
commit d6f1ea16ac
51 changed files with 516 additions and 453 deletions

View file

@ -55,8 +55,25 @@
#include "iosource/PktSrc.h"
#include "iosource/PktDumper.h"
#include "zeek.bif.func_h"
#include "stats.bif.func_h"
#include "reporter.bif.func_h"
#include "strings.bif.func_h"
#include "option.bif.func_h"
#include "supervisor.bif.func_h"
#include "zeek.bif.func_def"
#include "stats.bif.func_def"
#include "reporter.bif.func_def"
#include "strings.bif.func_def"
#include "option.bif.func_def"
#include "supervisor.bif.func_def"
extern RETSIGTYPE sig_handler(int signo);
namespace zeek {
namespace detail {
std::vector<CallInfo> call_stack;
bool did_builtin_init = false;
@ -134,7 +151,7 @@ void Func::SetScope(zeek::detail::ScopePtr newscope)
scope = std::move(newscope);
}
FuncPtr Func::DoClone()
zeek::detail::FuncPtr Func::DoClone()
{
// By default, ok just to return a reference. Func does not have any state
// that is different across instances.
@ -541,7 +558,7 @@ bool BroFunc::UpdateClosure(const broker::vector& data)
}
FuncPtr BroFunc::DoClone()
zeek::detail::FuncPtr BroFunc::DoClone()
{
// BroFunc could hold a closure. In this case a clone of it must
// store a copy of this closure.
@ -665,132 +682,6 @@ void BuiltinFunc::Describe(ODesc* d) const
d->AddCount(is_pure);
}
void builtin_error(const char* msg)
{
builtin_error(msg, zeek::ValPtr{});
}
void builtin_error(const char* msg, zeek::ValPtr arg)
{
builtin_error(msg, arg.get());
}
void builtin_error(const char* msg, BroObj* arg)
{
auto emit = [=](const zeek::detail::CallExpr* ce)
{
if ( ce )
ce->Error(msg, arg);
else
reporter->Error(msg, arg);
};
if ( call_stack.empty() )
{
emit(nullptr);
return;
}
auto last_call = call_stack.back();
if ( call_stack.size() < 2 )
{
// Don't need to check for wrapper function like "<module>::__<func>"
emit(last_call.call);
return;
}
auto starts_with_double_underscore = [](const std::string& name) -> bool
{ return name.size() > 2 && name[0] == '_' && name[1] == '_'; };
std::string last_func = last_call.func->Name();
auto pos = last_func.find_first_of("::");
std::string wrapper_func;
if ( pos == std::string::npos )
{
if ( ! starts_with_double_underscore(last_func) )
{
emit(last_call.call);
return;
}
wrapper_func = last_func.substr(2);
}
else
{
auto module_name = last_func.substr(0, pos);
auto func_name = last_func.substr(pos + 2);
if ( ! starts_with_double_underscore(func_name) )
{
emit(last_call.call);
return;
}
wrapper_func = module_name + "::" + func_name.substr(2);
}
auto parent_call = call_stack[call_stack.size() - 2];
auto parent_func = parent_call.func->Name();
if ( wrapper_func == parent_func )
emit(parent_call.call);
else
emit(last_call.call);
}
#include "zeek.bif.func_h"
#include "stats.bif.func_h"
#include "reporter.bif.func_h"
#include "strings.bif.func_h"
#include "option.bif.func_h"
#include "supervisor.bif.func_h"
#include "zeek.bif.func_def"
#include "stats.bif.func_def"
#include "reporter.bif.func_def"
#include "strings.bif.func_def"
#include "option.bif.func_def"
#include "supervisor.bif.func_def"
#include "__all__.bif.cc" // Autogenerated for compiling in the bif_target() code.
#include "__all__.bif.register.cc" // Autogenerated for compiling in the bif_target() code.
void init_builtin_funcs()
{
ProcStats = zeek::id::find_type<zeek::RecordType>("ProcStats");
NetStats = zeek::id::find_type<zeek::RecordType>("NetStats");
MatcherStats = zeek::id::find_type<zeek::RecordType>("MatcherStats");
ConnStats = zeek::id::find_type<zeek::RecordType>("ConnStats");
ReassemblerStats = zeek::id::find_type<zeek::RecordType>("ReassemblerStats");
DNSStats = zeek::id::find_type<zeek::RecordType>("DNSStats");
GapStats = zeek::id::find_type<zeek::RecordType>("GapStats");
EventStats = zeek::id::find_type<zeek::RecordType>("EventStats");
TimerStats = zeek::id::find_type<zeek::RecordType>("TimerStats");
FileAnalysisStats = zeek::id::find_type<zeek::RecordType>("FileAnalysisStats");
ThreadStats = zeek::id::find_type<zeek::RecordType>("ThreadStats");
BrokerStats = zeek::id::find_type<zeek::RecordType>("BrokerStats");
ReporterStats = zeek::id::find_type<zeek::RecordType>("ReporterStats");
var_sizes = zeek::id::find_type("var_sizes")->AsTableType();
#include "zeek.bif.func_init"
#include "stats.bif.func_init"
#include "reporter.bif.func_init"
#include "strings.bif.func_init"
#include "option.bif.func_init"
#include "supervisor.bif.func_init"
did_builtin_init = true;
}
void init_builtin_funcs_subdirs()
{
#include "__all__.bif.init.cc" // Autogenerated for compiling in the bif_target() code.
}
bool check_built_in_call(BuiltinFunc* f, zeek::detail::CallExpr* call)
{
if ( f->TheFunc() != zeek::BifFunc::fmt_bif)
@ -894,3 +785,134 @@ function_ingredients::function_ingredients(zeek::detail::ScopePtr scope, zeek::d
priority = (attrs ? get_func_priority(*attrs) : 0);
this->body = std::move(body);
}
} // namespace detail
void emit_builtin_error(const char* msg)
{
emit_builtin_error(msg, zeek::ValPtr{});
}
void emit_builtin_error(const char* msg, zeek::ValPtr arg)
{
emit_builtin_error(msg, arg.get());
}
void emit_builtin_error(const char* msg, BroObj* arg)
{
auto emit = [=](const zeek::detail::CallExpr* ce)
{
if ( ce )
ce->Error(msg, arg);
else
reporter->Error(msg, arg);
};
if ( zeek::detail::call_stack.empty() )
{
emit(nullptr);
return;
}
auto last_call = zeek::detail::call_stack.back();
if ( zeek::detail::call_stack.size() < 2 )
{
// Don't need to check for wrapper function like "<module>::__<func>"
emit(last_call.call);
return;
}
auto starts_with_double_underscore = [](const std::string& name) -> bool
{ return name.size() > 2 && name[0] == '_' && name[1] == '_'; };
std::string last_func = last_call.func->Name();
auto pos = last_func.find_first_of("::");
std::string wrapper_func;
if ( pos == std::string::npos )
{
if ( ! starts_with_double_underscore(last_func) )
{
emit(last_call.call);
return;
}
wrapper_func = last_func.substr(2);
}
else
{
auto module_name = last_func.substr(0, pos);
auto func_name = last_func.substr(pos + 2);
if ( ! starts_with_double_underscore(func_name) )
{
emit(last_call.call);
return;
}
wrapper_func = module_name + "::" + func_name.substr(2);
}
auto parent_call = zeek::detail::call_stack[zeek::detail::call_stack.size() - 2];
auto parent_func = parent_call.func->Name();
if ( wrapper_func == parent_func )
emit(parent_call.call);
else
emit(last_call.call);
}
} // namespace zeek
void builtin_error(const char* msg)
{
zeek::emit_builtin_error(msg);
}
void builtin_error(const char* msg, zeek::ValPtr arg)
{
zeek::emit_builtin_error(msg, arg);
}
void builtin_error(const char* msg, BroObj* arg)
{
zeek::emit_builtin_error(msg, arg);
}
#include "__all__.bif.cc" // Autogenerated for compiling in the bif_target() code.
#include "__all__.bif.register.cc" // Autogenerated for compiling in the bif_target() code.
void init_builtin_funcs()
{
ProcStats = zeek::id::find_type<zeek::RecordType>("ProcStats");
NetStats = zeek::id::find_type<zeek::RecordType>("NetStats");
MatcherStats = zeek::id::find_type<zeek::RecordType>("MatcherStats");
ConnStats = zeek::id::find_type<zeek::RecordType>("ConnStats");
ReassemblerStats = zeek::id::find_type<zeek::RecordType>("ReassemblerStats");
DNSStats = zeek::id::find_type<zeek::RecordType>("DNSStats");
GapStats = zeek::id::find_type<zeek::RecordType>("GapStats");
EventStats = zeek::id::find_type<zeek::RecordType>("EventStats");
TimerStats = zeek::id::find_type<zeek::RecordType>("TimerStats");
FileAnalysisStats = zeek::id::find_type<zeek::RecordType>("FileAnalysisStats");
ThreadStats = zeek::id::find_type<zeek::RecordType>("ThreadStats");
BrokerStats = zeek::id::find_type<zeek::RecordType>("BrokerStats");
ReporterStats = zeek::id::find_type<zeek::RecordType>("ReporterStats");
var_sizes = zeek::id::find_type("var_sizes")->AsTableType();
#include "zeek.bif.func_init"
#include "stats.bif.func_init"
#include "reporter.bif.func_init"
#include "strings.bif.func_init"
#include "option.bif.func_init"
#include "supervisor.bif.func_init"
zeek::detail::did_builtin_init = true;
}
void init_builtin_funcs_subdirs()
{
#include "__all__.bif.init.cc" // Autogenerated for compiling in the bif_target() code.
}