mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 23:28:20 +00:00
reintroduction of "-O add-C++" option
This commit is contained in:
parent
7a6a81c200
commit
8c59626eb9
12 changed files with 74 additions and 488 deletions
|
@ -4,17 +4,15 @@
|
|||
// where the key can have any IntrusivePtr type. The properties of a
|
||||
// tracker are that it (1) supports a notion that two technically distinct
|
||||
// keys in fact reflect the same underlying object, (2) provides an
|
||||
// instance of such keys to consistently serve as their "representative",
|
||||
// instance of such keys to consistently serve as their "representative", and
|
||||
// (3) provides names (suitable for use as C++ variables) for representative
|
||||
// keys, and (4) has a notion of "inheritance" (the underlying object is
|
||||
// already available from a previously generated namespace).
|
||||
// keys.
|
||||
//
|
||||
// Notions of "same" are taken from hash values ala those provided by
|
||||
// ProfileFunc.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "zeek/script_opt/CPP/HashMgr.h"
|
||||
#include "zeek/script_opt/CPP/InitsInfo.h"
|
||||
|
||||
namespace zeek::detail
|
||||
|
@ -28,10 +26,8 @@ public:
|
|||
// The base name is used to construct key names. "single_global",
|
||||
// if true, specifies that the names should be constructed as
|
||||
// indexes into a single global, rather than as distinct globals.
|
||||
// The mapper, if present, maps hash values to information about
|
||||
// the previously generated scope in which the value appears.
|
||||
CPPTracker(const char* _base_name, bool _single_global, VarMapper* _mapper = nullptr)
|
||||
: base_name(_base_name), single_global(_single_global), mapper(_mapper)
|
||||
CPPTracker(const char* _base_name, bool _single_global)
|
||||
: base_name(_base_name), single_global(_single_global)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -50,8 +46,7 @@ public:
|
|||
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.
|
||||
// A key is "distinct" if it's a representative.
|
||||
const std::vector<IntrusivePtr<T>>& DistinctKeys() const { return keys; }
|
||||
|
||||
// For a given key, get its representative.
|
||||
|
@ -62,23 +57,6 @@ public:
|
|||
}
|
||||
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]);
|
||||
}
|
||||
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; }
|
||||
|
||||
// If the given key is not inherited, logs it and its associated
|
||||
// scope to the given file.
|
||||
void LogIfNew(IntrusivePtr<T> key, int scope, FILE* log_file);
|
||||
|
||||
private:
|
||||
// Compute a hash for the given key.
|
||||
p_hash_type Hash(IntrusivePtr<T> key) const;
|
||||
|
@ -88,12 +66,8 @@ private:
|
|||
|
||||
std::unordered_map<const T*, std::shared_ptr<CPP_InitInfo>> gi_s;
|
||||
|
||||
// Maps internal representations to distinct values. These
|
||||
// may-or-may-not be indices into an "inherited" namespace scope.
|
||||
// Maps internal representations to distinct values.
|
||||
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
|
||||
|
||||
// Tracks the set of distinct keys, to facilitate iterating over them.
|
||||
// Each such key also has an entry in map2.
|
||||
|
@ -108,9 +82,6 @@ private:
|
|||
// Whether to base the names out of a single global, or distinct
|
||||
// globals.
|
||||
bool single_global;
|
||||
|
||||
// If non-nil, the mapper to consult for previous names.
|
||||
VarMapper* mapper;
|
||||
};
|
||||
|
||||
} // zeek::detail
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue