Reformat the world

This commit is contained in:
Tim Wojtulewicz 2021-09-16 15:35:39 -07:00
parent 194cb24547
commit b2f171ec69
714 changed files with 35149 additions and 35203 deletions

View file

@ -38,7 +38,8 @@
#include "zeek/Traverse.h"
#include "zeek/script_opt/ScriptOpt.h"
namespace zeek::detail {
namespace zeek::detail
{
// The type used to represent hashes. We use the mnemonic "p_hash" as
// short for "profile hash", to avoid confusion with hashes used elsehwere
@ -49,14 +50,20 @@ using p_hash_type = unsigned long long;
// Helper functions for computing/managing hashes.
inline p_hash_type p_hash(int val)
{ return std::hash<int>{}(val); }
{
return std::hash<int>{}(val);
}
inline p_hash_type p_hash(std::string_view val)
{ return std::hash<std::string_view>{}(val); }
{
return std::hash<std::string_view>{}(val);
}
extern p_hash_type p_hash(const Obj* o);
inline p_hash_type p_hash(const IntrusivePtr<Obj>& o)
{ return p_hash(o.get()); }
{
return p_hash(o.get());
}
inline p_hash_type merge_p_hashes(p_hash_type h1, p_hash_type h2)
{
@ -67,7 +74,7 @@ inline p_hash_type merge_p_hashes(p_hash_type h1, p_hash_type h2)
return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
}
// Returns a filename associated with the given function body. Used to
// Returns a filename associated with the given function body. Used to
// provide distinctness to identical function bodies seen in separate,
// potentially conflicting incremental compilations. This is only germane
// for allowing incremental compilation of subsets of the test suite, so
@ -78,9 +85,9 @@ extern std::string script_specific_filename(const StmtPtr& body);
// body, given it's non-specific hash is "generic_hash".
extern p_hash_type script_specific_hash(const StmtPtr& body, p_hash_type generic_hash);
// Class for profiling the components of a single function (or expression).
class ProfileFunc : public TraversalCallback {
class ProfileFunc : public TraversalCallback
{
public:
// Constructor used for the usual case of profiling a script
// function and one of its bodies.
@ -95,61 +102,42 @@ public:
// See the comments for the associated member variables for each
// of these accessors.
const std::unordered_set<const ID*>& Globals() const
{ return globals; }
const std::unordered_set<const ID*>& AllGlobals() const
{ return all_globals; }
const std::unordered_set<const ID*>& Locals() const
{ return locals; }
const std::unordered_set<const ID*>& Params() const
{ return params; }
const std::unordered_map<const ID*, int>& Assignees() const
{ return assignees; }
const std::unordered_set<const ID*>& Inits() const
{ return inits; }
const std::vector<const Stmt*>& Stmts() const
{ return stmts; }
const std::vector<const Expr*>& Exprs() const
{ return exprs; }
const std::vector<const LambdaExpr*>& Lambdas() const
{ return lambdas; }
const std::vector<const ConstExpr*>& Constants() const
{ return constants; }
const std::unordered_set<const ID*>& UnorderedIdentifiers() const
{ return ids; }
const std::vector<const ID*>& OrderedIdentifiers() const
{ return ordered_ids; }
const std::unordered_set<const Type*>& UnorderedTypes() const
{ return types; }
const std::vector<const Type*>& OrderedTypes() const
{ return ordered_types; }
const std::unordered_set<ScriptFunc*>& ScriptCalls() const
{ return script_calls; }
const std::unordered_set<const ID*>& BiFGlobals() const
{ return BiF_globals; }
const std::unordered_set<ScriptFunc*>& WhenCalls() const
{ return when_calls; }
const std::unordered_set<std::string>& Events() const
{ return events; }
const std::unordered_set<const ID*>& Globals() const { return globals; }
const std::unordered_set<const ID*>& AllGlobals() const { return all_globals; }
const std::unordered_set<const ID*>& Locals() const { return locals; }
const std::unordered_set<const ID*>& Params() const { return params; }
const std::unordered_map<const ID*, int>& Assignees() const { return assignees; }
const std::unordered_set<const ID*>& Inits() const { return inits; }
const std::vector<const Stmt*>& Stmts() const { return stmts; }
const std::vector<const Expr*>& Exprs() const { return exprs; }
const std::vector<const LambdaExpr*>& Lambdas() const { return lambdas; }
const std::vector<const ConstExpr*>& Constants() const { return constants; }
const std::unordered_set<const ID*>& UnorderedIdentifiers() const { return ids; }
const std::vector<const ID*>& OrderedIdentifiers() const { return ordered_ids; }
const std::unordered_set<const Type*>& UnorderedTypes() const { return types; }
const std::vector<const Type*>& OrderedTypes() const { return ordered_types; }
const std::unordered_set<ScriptFunc*>& ScriptCalls() const { return script_calls; }
const std::unordered_set<const ID*>& BiFGlobals() const { return BiF_globals; }
const std::unordered_set<ScriptFunc*>& WhenCalls() const { return when_calls; }
const std::unordered_set<std::string>& Events() const { return events; }
const std::unordered_set<const Attributes*>& ConstructorAttrs() const
{ return constructor_attrs; }
const std::unordered_set<const SwitchStmt*>& ExprSwitches() const
{ return expr_switches; }
const std::unordered_set<const SwitchStmt*>& TypeSwitches() const
{ return type_switches; }
{
return constructor_attrs;
}
const std::unordered_set<const SwitchStmt*>& ExprSwitches() const { return expr_switches; }
const std::unordered_set<const SwitchStmt*>& TypeSwitches() const { return type_switches; }
bool DoesIndirectCalls() { return does_indirect_calls; }
bool DoesIndirectCalls() { return does_indirect_calls; }
int NumParams() const { return num_params; }
int NumLambdas() const { return lambdas.size(); }
int NumWhenStmts() const { return num_when_stmts; }
int NumParams() const { return num_params; }
int NumLambdas() const { return lambdas.size(); }
int NumWhenStmts() const { return num_when_stmts; }
const std::vector<p_hash_type>& AdditionalHashes() const
{ return addl_hashes; }
const std::vector<p_hash_type>& AdditionalHashes() const { return addl_hashes; }
// Set this function's hash to the given value; retrieve that value.
void SetHashVal(p_hash_type hash) { hash_val = hash; }
p_hash_type HashVal() const { return hash_val; }
void SetHashVal(p_hash_type hash) { hash_val = hash; }
p_hash_type HashVal() const { return hash_val; }
protected:
// Construct the profile for the given function signature and body.
@ -161,7 +149,7 @@ protected:
// Take note of the presence of a given type.
void TrackType(const Type* t);
void TrackType(const TypePtr& t) { TrackType(t.get()); }
void TrackType(const TypePtr& t) { TrackType(t.get()); }
// Take note of the presence of an identifier.
void TrackID(const ID* id);
@ -275,7 +263,7 @@ protected:
// Whether we're separately processing a "when" condition to
// mine out its script calls.
bool in_when = false;
};
};
// Function pointer for a predicate that determines whether a given
// profile is compilable. Alternatively we could derive subclasses
@ -284,7 +272,8 @@ protected:
using is_compilable_pred = bool (*)(const ProfileFunc*, const char** reason);
// Collectively profile an entire collection of functions.
class ProfileFuncs {
class ProfileFuncs
{
public:
// Updates entries in "funcs" to include profiles. If pred is
// non-nil, then it is called for each profile to see whether it's
@ -292,37 +281,25 @@ public:
// "full_record_hashes" controls whether the hashes for extended
// records covers their final, full form, or should only their
// original fields.
ProfileFuncs(std::vector<FuncInfo>& funcs,
is_compilable_pred pred, bool full_record_hashes);
ProfileFuncs(std::vector<FuncInfo>& funcs, is_compilable_pred pred, bool full_record_hashes);
// The following accessors provide a global profile across all of
// the (non-skipped) functions in "funcs". See the comments for
// the associated member variables for documentation.
const std::unordered_set<const ID*>& Globals() const
{ return globals; }
const std::unordered_set<const ID*>& AllGlobals() const
{ return all_globals; }
const std::unordered_set<const ConstExpr*>& Constants() const
{ return constants; }
const std::vector<const Type*>& MainTypes() const
{ return main_types; }
const std::vector<const Type*>& RepTypes() const
{ return rep_types; }
const std::unordered_set<ScriptFunc*>& ScriptCalls() const
{ return script_calls; }
const std::unordered_set<const ID*>& BiFGlobals() const
{ return BiF_globals; }
const std::unordered_set<const LambdaExpr*>& Lambdas() const
{ return lambdas; }
const std::unordered_set<std::string>& Events() const
{ return events; }
const std::unordered_set<const ID*>& Globals() const { return globals; }
const std::unordered_set<const ID*>& AllGlobals() const { return all_globals; }
const std::unordered_set<const ConstExpr*>& Constants() const { return constants; }
const std::vector<const Type*>& MainTypes() const { return main_types; }
const std::vector<const Type*>& RepTypes() const { return rep_types; }
const std::unordered_set<ScriptFunc*>& ScriptCalls() const { return script_calls; }
const std::unordered_set<const ID*>& BiFGlobals() const { return BiF_globals; }
const std::unordered_set<const LambdaExpr*>& Lambdas() const { return lambdas; }
const std::unordered_set<std::string>& Events() const { return events; }
std::shared_ptr<ProfileFunc> FuncProf(const ScriptFunc* f)
{ return func_profs[f]; }
std::shared_ptr<ProfileFunc> FuncProf(const ScriptFunc* f) { return func_profs[f]; }
// This is only externally germane for LambdaExpr's.
std::shared_ptr<ProfileFunc> ExprProf(const Expr* e)
{ return expr_profs[e]; }
std::shared_ptr<ProfileFunc> ExprProf(const Expr* e) { return expr_profs[e]; }
// Returns the "representative" Type* for the hash associated with
// the parameter (which might be the parameter itself).
@ -335,7 +312,7 @@ public:
// Returns the hash associated with the given type, computing it
// if necessary.
p_hash_type HashType(const TypePtr& t) { return HashType(t.get()); }
p_hash_type HashType(const TypePtr& t) { return HashType(t.get()); }
p_hash_type HashType(const Type* t);
p_hash_type HashAttrs(const AttributesPtr& attrs);
@ -437,7 +414,6 @@ protected:
// Whether the hashes for extended records should cover their final,
// full form, or only their original fields.
bool full_record_hashes;
};
};
} // namespace zeek::detail
} // namespace zeek::detail