bifcl: Add clang-format and run it on everything

This commit is contained in:
Tim Wojtulewicz 2022-10-18 14:56:28 -07:00
parent 552be424c4
commit 3a18b2144c
3 changed files with 30 additions and 33 deletions

View file

@ -7,7 +7,8 @@ using namespace std;
#include "bif_arg.h" #include "bif_arg.h"
static struct { static struct
{
const char* bif_type; const char* bif_type;
const char* zeek_type; const char* zeek_type;
const char* c_type; const char* c_type;
@ -17,12 +18,14 @@ static struct {
const char* cast_smart; const char* cast_smart;
const char* constructor; const char* constructor;
const char* ctor_smart; const char* ctor_smart;
} builtin_func_arg_type[] = { } builtin_func_arg_type[] = {
#define DEFINE_BIF_TYPE(id, bif_type, zeek_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart) \ #define DEFINE_BIF_TYPE(id, bif_type, zeek_type, c_type, c_type_smart, accessor, accessor_smart, \
{bif_type, zeek_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart}, cast_smart, constructor, ctor_smart) \
{bif_type, zeek_type, c_type, c_type_smart, accessor, \
accessor_smart, cast_smart, constructor, ctor_smart},
#include "bif_type.def" #include "bif_type.def"
#undef DEFINE_BIF_TYPE #undef DEFINE_BIF_TYPE
}; };
extern const char* arg_list_name; extern const char* arg_list_name;
@ -52,17 +55,13 @@ BuiltinFuncArg::BuiltinFuncArg(const char* arg_name, const char* arg_type_str,
void BuiltinFuncArg::PrintZeek(FILE* fp) void BuiltinFuncArg::PrintZeek(FILE* fp)
{ {
fprintf(fp, "%s: %s%s %s", name, builtin_func_arg_type[type].zeek_type, fprintf(fp, "%s: %s%s %s", name, builtin_func_arg_type[type].zeek_type, type_str, attr_str);
type_str, attr_str);
} }
void BuiltinFuncArg::PrintCDef(FILE* fp, int n) void BuiltinFuncArg::PrintCDef(FILE* fp, int n)
{ {
fprintf(fp, fprintf(fp, "\t%s %s = (%s) (", builtin_func_arg_type[type].c_type, name,
"\t%s %s = (%s) (", builtin_func_arg_type[type].c_type);
builtin_func_arg_type[type].c_type,
name,
builtin_func_arg_type[type].c_type);
char buf[1024]; char buf[1024];
snprintf(buf, sizeof(buf), "(*%s)[%d].get()", arg_list_name, n); snprintf(buf, sizeof(buf), "(*%s)[%d].get()", arg_list_name, n);

View file

@ -2,28 +2,27 @@
#include <stdio.h> #include <stdio.h>
enum builtin_func_arg_type { enum builtin_func_arg_type
#define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart) \ {
#define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, \
cast_smart, constructor, ctor_smart) \
id, id,
#include "bif_type.def" #include "bif_type.def"
#undef DEFINE_BIF_TYPE #undef DEFINE_BIF_TYPE
}; };
extern const char* builtin_func_arg_type_bro_name[]; extern const char* builtin_func_arg_type_bro_name[];
class BuiltinFuncArg { class BuiltinFuncArg
{
public: public:
BuiltinFuncArg(const char* arg_name, int arg_type); BuiltinFuncArg(const char* arg_name, int arg_type);
BuiltinFuncArg(const char* arg_name, const char* arg_type_str, BuiltinFuncArg(const char* arg_name, const char* arg_type_str, const char* arg_attr_str = "");
const char* arg_attr_str = "");
void SetAttrStr(const char* arg_attr_str) void SetAttrStr(const char* arg_attr_str) { attr_str = arg_attr_str; };
{
attr_str = arg_attr_str;
};
const char* Name() const { return name; } const char* Name() const { return name; }
int Type() const { return type; } int Type() const { return type; }
void PrintZeek(FILE* fp); void PrintZeek(FILE* fp);
void PrintCDef(FILE* fp, int n); void PrintCDef(FILE* fp, int n);
@ -35,4 +34,4 @@ protected:
int type; int type;
const char* type_str; const char* type_str;
const char* attr_str; const char* attr_str;
}; };

View file

@ -1,10 +1,11 @@
// //
// See the file "COPYING" in the main distribution directory for copyright. // See the file "COPYING" in the main distribution directory for copyright.
#include <string>
#include <string.h>
#include "module_util.h" #include "module_util.h"
#include <string.h>
#include <string>
static int streq(const char* s1, const char* s2) static int streq(const char* s1, const char* s2)
{ {
return ! strcmp(s1, s2); return ! strcmp(s1, s2);
@ -24,7 +25,7 @@ string extract_module_name(const char* name)
return module_name; return module_name;
} }
string extract_var_name(const char *name) string extract_var_name(const char* name)
{ {
string var_name = name; string var_name = name;
string::size_type pos = var_name.rfind("::"); string::size_type pos = var_name.rfind("::");
@ -35,14 +36,13 @@ string extract_var_name(const char *name)
if ( pos + 2 > var_name.size() ) if ( pos + 2 > var_name.size() )
return string(""); return string("");
return var_name.substr(pos+2); return var_name.substr(pos + 2);
} }
string normalized_module_name(const char* module_name) string normalized_module_name(const char* module_name)
{ {
int mod_len; int mod_len;
if ( (mod_len = strlen(module_name)) >= 2 && if ( (mod_len = strlen(module_name)) >= 2 && streq(module_name + mod_len - 2, "::") )
streq(module_name + mod_len - 2, "::") )
mod_len -= 2; mod_len -= 2;
return string(module_name, mod_len); return string(module_name, mod_len);
@ -50,8 +50,7 @@ string normalized_module_name(const char* module_name)
string make_full_var_name(const char* module_name, const char* var_name) string make_full_var_name(const char* module_name, const char* var_name)
{ {
if ( ! module_name || streq(module_name, GLOBAL_MODULE_NAME) || if ( ! module_name || streq(module_name, GLOBAL_MODULE_NAME) || strstr(var_name, "::") )
strstr(var_name, "::") )
{ {
if ( streq(GLOBAL_MODULE_NAME, extract_module_name(var_name).c_str()) ) if ( streq(GLOBAL_MODULE_NAME, extract_module_name(var_name).c_str()) )
return extract_var_name(var_name); return extract_var_name(var_name);