Reformat Zeek in Spicy style

This largely copies over Spicy's `.clang-format` configuration file. The
one place where we deviate is header include order since Zeek depends on
headers being included in a certain order.
This commit is contained in:
Benjamin Bannier 2023-10-10 21:13:34 +02:00
parent 7b8e7ed72c
commit f5a76c1aed
786 changed files with 131714 additions and 153609 deletions

View file

@ -10,108 +10,93 @@
#include "zeek/ZeekString.h"
#include "zeek/script_opt/ProfileFunc.h"
namespace zeek::detail
{
namespace zeek::detail {
StmtPtr curr_stmt;
TypePtr log_ID_enum_type;
TypePtr any_base_type;
bool ZAM_error = false;
bool is_ZAM_compilable(const ProfileFunc* pf, const char** reason)
{
auto b = pf->ProfiledBody();
auto is_hook = pf->ProfiledFunc()->Flavor() == FUNC_FLAVOR_HOOK;
if ( b && ! script_is_valid(b, is_hook) )
{
if ( reason )
*reason = "invalid script body";
return false;
}
bool is_ZAM_compilable(const ProfileFunc* pf, const char** reason) {
auto b = pf->ProfiledBody();
auto is_hook = pf->ProfiledFunc()->Flavor() == FUNC_FLAVOR_HOOK;
if ( b && ! script_is_valid(b, is_hook) ) {
if ( reason )
*reason = "invalid script body";
return false;
}
return true;
}
return true;
}
bool IsAny(const Type* t)
{
return t->Tag() == TYPE_ANY;
}
bool IsAny(const Type* t) { return t->Tag() == TYPE_ANY; }
StringVal* ZAM_to_lower(const StringVal* sv)
{
auto bs = sv->AsString();
const u_char* s = bs->Bytes();
int n = bs->Len();
u_char* lower_s = new u_char[n + 1];
u_char* ls = lower_s;
StringVal* ZAM_to_lower(const StringVal* sv) {
auto bs = sv->AsString();
const u_char* s = bs->Bytes();
int n = bs->Len();
u_char* lower_s = new u_char[n + 1];
u_char* ls = lower_s;
for ( int i = 0; i < n; ++i )
{
if ( isascii(s[i]) && isupper(s[i]) )
*ls++ = tolower(s[i]);
else
*ls++ = s[i];
}
for ( int i = 0; i < n; ++i ) {
if ( isascii(s[i]) && isupper(s[i]) )
*ls++ = tolower(s[i]);
else
*ls++ = s[i];
}
*ls++ = '\0';
*ls++ = '\0';
return new StringVal(new String(true, lower_s, n));
}
return new StringVal(new String(true, lower_s, n));
}
StringVal* ZAM_sub_bytes(const StringVal* s, zeek_uint_t start, zeek_int_t n)
{
if ( start > 0 )
--start; // make it 0-based
StringVal* ZAM_sub_bytes(const StringVal* s, zeek_uint_t start, zeek_int_t n) {
if ( start > 0 )
--start; // make it 0-based
auto ss = s->AsString()->GetSubstring(start, n);
auto ss = s->AsString()->GetSubstring(start, n);
return new StringVal(ss ? ss : new String(""));
}
return new StringVal(ss ? ss : new String(""));
}
StringValPtr ZAM_val_cat(const ValPtr& v)
{
// Quite similar to cat(), but for only one value.
zeek::ODesc d;
d.SetStyle(RAW_STYLE);
StringValPtr ZAM_val_cat(const ValPtr& v) {
// Quite similar to cat(), but for only one value.
zeek::ODesc d;
d.SetStyle(RAW_STYLE);
v->Describe(&d);
v->Describe(&d);
String* s = new String(true, d.TakeBytes(), d.Len());
s->SetUseFreeToDelete(true);
String* s = new String(true, d.TakeBytes(), d.Len());
s->SetUseFreeToDelete(true);
return make_intrusive<StringVal>(s);
}
return make_intrusive<StringVal>(s);
}
void ZAM_run_time_error(const char* msg)
{
fprintf(stderr, "%s\n", msg);
ZAM_error = true;
}
void ZAM_run_time_error(const char* msg) {
fprintf(stderr, "%s\n", msg);
ZAM_error = true;
}
void ZAM_run_time_error(const Location* loc, const char* msg)
{
reporter->RuntimeError(loc, "%s", msg);
ZAM_error = true;
}
void ZAM_run_time_error(const Location* loc, const char* msg) {
reporter->RuntimeError(loc, "%s", msg);
ZAM_error = true;
}
void ZAM_run_time_error(const char* msg, const Obj* o)
{
fprintf(stderr, "%s: %s\n", msg, obj_desc(o).c_str());
ZAM_error = true;
}
void ZAM_run_time_error(const char* msg, const Obj* o) {
fprintf(stderr, "%s: %s\n", msg, obj_desc(o).c_str());
ZAM_error = true;
}
void ZAM_run_time_error(const Location* loc, const char* msg, const Obj* o)
{
reporter->RuntimeError(loc, "%s (%s)", msg, obj_desc(o).c_str());
ZAM_error = true;
}
void ZAM_run_time_error(const Location* loc, const char* msg, const Obj* o) {
reporter->RuntimeError(loc, "%s (%s)", msg, obj_desc(o).c_str());
ZAM_error = true;
}
void ZAM_run_time_warning(const Location* loc, const char* msg)
{
ODesc d;
loc->Describe(&d);
void ZAM_run_time_warning(const Location* loc, const char* msg) {
ODesc d;
loc->Describe(&d);
reporter->Warning("%s: %s", d.Description(), msg);
}
reporter->Warning("%s: %s", d.Description(), msg);
}
} // namespace zeek::detail
} // namespace zeek::detail