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

@ -12,106 +12,102 @@
#include "zeek/Func.h"
#include "zeek/Scope.h"
namespace zeek
{
namespace zeek {
struct Options;
}
}
namespace zeek::detail
{
namespace zeek::detail {
// Flags controlling what sorts of analysis to do.
struct AnalyOpt
{
struct AnalyOpt {
// If non-nil, then only analyze function/event/hook(s) whose names
// match one of the given regular expressions.
//
// Applies to both ZAM and C++.
std::vector<std::regex> only_funcs;
// If non-nil, then only analyze function/event/hook(s) whose names
// match one of the given regular expressions.
//
// Applies to both ZAM and C++.
std::vector<std::regex> only_funcs;
// Same, but for the filenames where the function is found.
std::vector<std::regex> only_files;
// Same, but for the filenames where the function is found.
std::vector<std::regex> only_files;
// For a given compilation target, report functions that can't
// be compiled.
bool report_uncompilable = false;
// For a given compilation target, report functions that can't
// be compiled.
bool report_uncompilable = false;
////// Options relating to ZAM:
////// Options relating to ZAM:
// Whether to analyze scripts.
bool activate = false;
// Whether to analyze scripts.
bool activate = false;
// If true, compile all compilable functions, even those that
// are inlined. Mainly useful for ensuring compatibility for
// some tests in the test suite.
bool compile_all = false;
// If true, compile all compilable functions, even those that
// are inlined. Mainly useful for ensuring compatibility for
// some tests in the test suite.
bool compile_all = false;
// Whether to optimize the AST.
bool optimize_AST = false;
// Whether to optimize the AST.
bool optimize_AST = false;
// If true, do global inlining.
bool inliner = false;
// If true, do global inlining.
bool inliner = false;
// If true, report which functions are directly and indirectly
// recursive, and exit. Only germane if running the inliner.
bool report_recursive = false;
// If true, report which functions are directly and indirectly
// recursive, and exit. Only germane if running the inliner.
bool report_recursive = false;
// If true, generate ZAM code for applicable function bodies,
// activating all optimizations.
bool gen_ZAM = false;
// If true, generate ZAM code for applicable function bodies,
// activating all optimizations.
bool gen_ZAM = false;
// Generate ZAM code, but do not turn on optimizations unless
// specified.
bool gen_ZAM_code = false;
// Generate ZAM code, but do not turn on optimizations unless
// specified.
bool gen_ZAM_code = false;
// Deactivate the low-level ZAM optimizer.
bool no_ZAM_opt = false;
// Deactivate the low-level ZAM optimizer.
bool no_ZAM_opt = false;
// Produce a profile of ZAM execution.
bool profile_ZAM = false;
// Produce a profile of ZAM execution.
bool profile_ZAM = false;
// If true, dump out transformed code: the results of reducing
// interpreted scripts, and, if optimize is set, of then optimizing
// them.
bool dump_xform = false;
// If true, dump out transformed code: the results of reducing
// interpreted scripts, and, if optimize is set, of then optimizing
// them.
bool dump_xform = false;
// If true, dump out the use-defs for each analyzed function.
bool dump_uds = false;
// If true, dump out the use-defs for each analyzed function.
bool dump_uds = false;
// If true, dump out generated ZAM code.
bool dump_ZAM = false;
// If true, dump out generated ZAM code.
bool dump_ZAM = false;
// If non-zero, looks for variables that are used-but-possibly-not-set,
// or set-but-not-used. We store this as an int rather than a bool
// because we might at some point extend the analysis to deeper forms
// of usage issues, such as those present in record fields.
//
// Included here with other ZAM-related options since conducting
// the analysis requires activating some of the machinery used
// for ZAM.
int usage_issues = 0;
// If non-zero, looks for variables that are used-but-possibly-not-set,
// or set-but-not-used. We store this as an int rather than a bool
// because we might at some point extend the analysis to deeper forms
// of usage issues, such as those present in record fields.
//
// Included here with other ZAM-related options since conducting
// the analysis requires activating some of the machinery used
// for ZAM.
int usage_issues = 0;
////// Options relating to C++:
////// Options relating to C++:
// If true, generate C++;
bool gen_CPP = false;
// If true, generate C++;
bool gen_CPP = false;
// If true, the C++ should be standalone (not require the presence
// of the corresponding script, and not activated by default).
bool gen_standalone_CPP = false;
// If true, the C++ should be standalone (not require the presence
// of the corresponding script, and not activated by default).
bool gen_standalone_CPP = false;
// If true, use C++ bodies if available.
bool use_CPP = false;
// If true, use C++ bodies if available.
bool use_CPP = false;
// If true, report on available C++ bodies.
bool report_CPP = false;
// If true, report on available C++ bodies.
bool report_CPP = false;
// If true, allow standalone compilation in the presence of
// conditional code.
bool allow_cond = false;
};
// If true, allow standalone compilation in the presence of
// conditional code.
bool allow_cond = false;
};
extern AnalyOpt analysis_options;
@ -120,43 +116,39 @@ class ProfileFunc;
using ScriptFuncPtr = IntrusivePtr<ScriptFunc>;
// Info we need for tracking an instance of a function.
class FuncInfo
{
class FuncInfo {
public:
FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body, int _priority)
: func(std::move(_func)), scope(std::move(_scope)), body(std::move(_body)),
priority(_priority)
{
}
FuncInfo(ScriptFuncPtr _func, ScopePtr _scope, StmtPtr _body, int _priority)
: func(std::move(_func)), scope(std::move(_scope)), body(std::move(_body)), priority(_priority) {}
ScriptFunc* Func() const { return func.get(); }
const ScriptFuncPtr& FuncPtr() const { return func; }
const ScopePtr& Scope() const { return scope; }
const StmtPtr& Body() const { return body; }
int Priority() const { return priority; }
const ProfileFunc* Profile() const { return pf.get(); }
std::shared_ptr<ProfileFunc> ProfilePtr() const { return pf; }
ScriptFunc* Func() const { return func.get(); }
const ScriptFuncPtr& FuncPtr() const { return func; }
const ScopePtr& Scope() const { return scope; }
const StmtPtr& Body() const { return body; }
int Priority() const { return priority; }
const ProfileFunc* Profile() const { return pf.get(); }
std::shared_ptr<ProfileFunc> ProfilePtr() const { return pf; }
void SetBody(StmtPtr new_body) { body = std::move(new_body); }
void SetProfile(std::shared_ptr<ProfileFunc> _pf) { pf = std::move(_pf); }
void SetBody(StmtPtr new_body) { body = std::move(new_body); }
void SetProfile(std::shared_ptr<ProfileFunc> _pf) { pf = std::move(_pf); }
// The following provide a way of marking FuncInfo's as
// should-be-skipped for script optimization, generally because
// the function body has a property that a given script optimizer
// doesn't know how to deal with. Defaults to don't-skip.
bool ShouldSkip() const { return skip; }
void SetSkip(bool should_skip) { skip = should_skip; }
// The following provide a way of marking FuncInfo's as
// should-be-skipped for script optimization, generally because
// the function body has a property that a given script optimizer
// doesn't know how to deal with. Defaults to don't-skip.
bool ShouldSkip() const { return skip; }
void SetSkip(bool should_skip) { skip = should_skip; }
protected:
ScriptFuncPtr func;
ScopePtr scope;
StmtPtr body;
std::shared_ptr<ProfileFunc> pf;
int priority;
ScriptFuncPtr func;
ScopePtr scope;
StmtPtr body;
std::shared_ptr<ProfileFunc> pf;
int priority;
// Whether to skip optimizing this function.
bool skip = false;
};
// Whether to skip optimizing this function.
bool skip = false;
};
// We track which functions are definitely not recursive. We do this
// as the negative, rather than tracking functions known to be recursive,
@ -212,4 +204,4 @@ extern void (*CPP_init_hook)();
// called after parsing and BiF initialization, but before zeek_init.
extern void (*CPP_activation_hook)();
} // namespace zeek::detail
} // namespace zeek::detail