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,15 +12,14 @@
#include "zeek/TraverseTypes.h"
#include "zeek/ZeekList.h"
namespace zeek
{
namespace zeek {
class Type;
template <class T> class IntrusivePtr;
template<class T>
class IntrusivePtr;
using TypePtr = IntrusivePtr<Type>;
namespace detail
{
namespace detail {
class Attr;
class ID;
@ -30,56 +29,55 @@ using IDPtr = IntrusivePtr<ID>;
class Scope;
using ScopePtr = IntrusivePtr<Scope>;
class Scope : public Obj
{
class Scope : public Obj {
public:
explicit Scope(IDPtr id, std::unique_ptr<std::vector<AttrPtr>> al);
explicit Scope(IDPtr id, std::unique_ptr<std::vector<AttrPtr>> al);
const IDPtr& Find(std::string_view name) const;
const IDPtr& Find(std::string_view name) const;
template <typename N, typename I> void Insert(N&& name, I&& id)
{
local[std::forward<N>(name)] = std::forward<I>(id);
ordered_vars.push_back(std::forward<I>(id));
}
template<typename N, typename I>
void Insert(N&& name, I&& id) {
local[std::forward<N>(name)] = std::forward<I>(id);
ordered_vars.push_back(std::forward<I>(id));
}
const IDPtr& GetID() const { return scope_id; }
const IDPtr& GetID() const { return scope_id; }
const std::unique_ptr<std::vector<AttrPtr>>& Attrs() const { return attrs; }
const std::unique_ptr<std::vector<AttrPtr>>& Attrs() const { return attrs; }
const TypePtr& GetReturnType() const { return return_type; }
const TypePtr& GetReturnType() const { return return_type; }
size_t Length() const { return local.size(); }
const auto& Vars() const { return local; }
const auto& OrderedVars() const { return ordered_vars; }
size_t Length() const { return local.size(); }
const auto& Vars() const { return local; }
const auto& OrderedVars() const { return ordered_vars; }
IDPtr GenerateTemporary(const char* name);
IDPtr GenerateTemporary(const char* name);
// Returns the list of variables needing initialization, and
// removes it from this Scope.
std::vector<IDPtr> GetInits();
// Returns the list of variables needing initialization, and
// removes it from this Scope.
std::vector<IDPtr> GetInits();
// Adds a variable to the list.
void AddInit(IDPtr id) { inits.emplace_back(std::move(id)); }
// Adds a variable to the list.
void AddInit(IDPtr id) { inits.emplace_back(std::move(id)); }
void Describe(ODesc* d) const override;
void Describe(ODesc* d) const override;
TraversalCode Traverse(TraversalCallback* cb) const;
TraversalCode Traverse(TraversalCallback* cb) const;
protected:
IDPtr scope_id;
std::unique_ptr<std::vector<AttrPtr>> attrs;
TypePtr return_type;
std::map<std::string, IDPtr, std::less<>> local;
std::vector<IDPtr> inits;
IDPtr scope_id;
std::unique_ptr<std::vector<AttrPtr>> attrs;
TypePtr return_type;
std::map<std::string, IDPtr, std::less<>> local;
std::vector<IDPtr> inits;
// We keep track of identifiers in the order that they're added.
// This is necessary for script optimization to be able to find
// event/hook parameters for instances where the declaration of
// an additional handler uses different names for the parameters
// than the original declaration.
std::vector<IntrusivePtr<ID>> ordered_vars;
};
// We keep track of identifiers in the order that they're added.
// This is necessary for script optimization to be able to find
// event/hook parameters for instances where the declaration of
// an additional handler uses different names for the parameters
// than the original declaration.
std::vector<IntrusivePtr<ID>> ordered_vars;
};
// If no_global is true, don't search in the default "global" namespace.
extern const IDPtr& lookup_ID(const char* name, const char* module, bool no_global = false,
@ -99,7 +97,7 @@ extern ScopePtr global_scope();
// Current module (identified by its name).
extern std::string current_module;
} // namespace detail
} // namespace zeek
} // namespace detail
} // namespace zeek
extern bool in_debug;