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

@ -16,24 +16,25 @@
#include "zeek/script_opt/CPP/HashMgr.h"
namespace zeek::detail {
namespace zeek::detail
{
// T is a type that has an IntrusivePtr instantiation.
template <class T>
class CPPTracker {
template <class T> class CPPTracker
{
public:
// The base name is used to construct key names. The mapper,
// if present, maps hash values to information about the previously
// generated scope in which the value appears.
CPPTracker(const char* _base_name, VarMapper* _mapper = nullptr)
: base_name(_base_name), mapper(_mapper)
: base_name(_base_name), mapper(_mapper)
{
}
// True if the given key has already been entered.
bool HasKey(const T* key) const { return map.count(key) > 0; }
bool HasKey(IntrusivePtr<T> key) const { return HasKey(key.get()); }
bool HasKey(const T* key) const { return map.count(key) > 0; }
bool HasKey(IntrusivePtr<T> key) const { return HasKey(key.get()); }
// Only adds the key if it's not already present. If a hash
// is provided, then refrains from computing it.
@ -41,26 +42,33 @@ public:
// Returns the (C++ variable) name associated with the given key.
std::string KeyName(const T* key);
std::string KeyName(IntrusivePtr<T> key)
{ return KeyName(key.get()); }
std::string KeyName(IntrusivePtr<T> key) { return KeyName(key.get()); }
// Returns all of the distinct keys entered into the tracker.
// A key is "distinct" if it's both (1) a representative and
// (2) not inherited.
const std::vector<IntrusivePtr<T>>& DistinctKeys() const
{ return keys; }
const std::vector<IntrusivePtr<T>>& DistinctKeys() const { return keys; }
// For a given key, get its representative.
const T* GetRep(const T* key)
{ ASSERT(HasKey(key)); return reps[map[key]]; }
const T* GetRep(IntrusivePtr<T> key) { return GetRep(key.get()); }
{
ASSERT(HasKey(key));
return reps[map[key]];
}
const T* GetRep(IntrusivePtr<T> key) { return GetRep(key.get()); }
// True if the given key is represented by an inherited value.
bool IsInherited(const T* key)
{ ASSERT(HasKey(key)); return IsInherited(map[key]); }
{
ASSERT(HasKey(key));
return IsInherited(map[key]);
}
bool IsInherited(const IntrusivePtr<T>& key)
{ ASSERT(HasKey(key)); return IsInherited(map[key.get()]); }
bool IsInherited(p_hash_type h) { return inherited.count(h) > 0; }
{
ASSERT(HasKey(key));
return IsInherited(map[key.get()]);
}
bool IsInherited(p_hash_type h) { return inherited.count(h) > 0; }
// If the given key is not inherited, logs it and its associated
// scope to the given file.
@ -76,9 +84,9 @@ private:
// Maps internal representations to distinct values. These
// may-or-may-not be indices into an "inherited" namespace scope.
std::unordered_map<p_hash_type, int> map2;
std::unordered_map<p_hash_type, std::string> scope2; // only if inherited
std::unordered_set<p_hash_type> inherited; // which are inherited
int num_non_inherited = 0; // distinct non-inherited map2 entries
std::unordered_map<p_hash_type, std::string> scope2; // only if inherited
std::unordered_set<p_hash_type> inherited; // which are inherited
int num_non_inherited = 0; // distinct non-inherited map2 entries
// Tracks the set of distinct keys, to facilitate iterating over them.
// Each such key also has an entry in map2.
@ -92,6 +100,6 @@ private:
// If non-nil, the mapper to consult for previous names.
VarMapper* mapper;
};
};
} // zeek::detail
} // zeek::detail