30#include <nlohmann/json.hpp>
31#include <unordered_map>
36#ifdef ACAV_ENABLE_STRING_STATS
38struct TypeDeduplicationStats {
39 std::size_t totalTypeLookups;
40 std::size_t cacheHits;
41 std::size_t uniqueTypeNodes;
42 std::size_t totalTypeReferences;
43 std::size_t estimatedSavedNodes;
44 std::size_t estimatedSavedBytes;
45 double deduplicationRatio;
46 double savingsPercent;
52 nlohmann::basic_json<std::map, std::vector,
InternedString, bool, int64_t,
53 uint64_t, double, std::allocator,
54 nlohmann::adl_serializer, std::vector<uint8_t>>;
68 AstContext() =
default;
71 AstContext(
const AstContext &) =
delete;
72 AstContext &operator=(
const AstContext &) =
delete;
73 AstContext(AstContext &&) =
delete;
74 AstContext &operator=(AstContext &&) =
delete;
126#ifdef ACAV_ENABLE_STRING_STATS
128 TypeDeduplicationStats getTypeDeduplicationStats()
const;
130 void printTypeDeduplicationStats(
const char *label =
nullptr)
const;
134 std::vector<AstNode *> allAstNodes_;
135 std::vector<AstViewNode *> allAstViewNodes_;
140 std::unordered_map<const void *, AstNode *> typeDeduplicationMap_;
145#ifdef ACAV_ENABLE_STRING_STATS
147 mutable std::size_t typeLookupCount_ = 0;
148 mutable std::size_t typeCacheHits_ = 0;
188 std::size_t refCount_ = 0;
199 AstViewNode(
const AstViewNode &) =
delete;
200 AstViewNode &operator=(
const AstViewNode &) =
delete;
201 AstViewNode(AstViewNode &&) =
delete;
202 AstViewNode &operator=(AstViewNode &&) =
delete;
209 const std::vector<AstViewNode *> &
getChildren()
const {
return children_; }
212 void setParent(AstViewNode *parent) { parent_ = parent; }
228 std::vector<AstViewNode *> children_;
nlohmann::basic_json< std::map, std::vector, InternedString, bool, int64_t, uint64_t, double, std::allocator, nlohmann::adl_serializer, std::vector< uint8_t > > AcavJson
Custom JSON type using InternedString for automatic string deduplication.
Memory-efficient immutable string with automatic deduplication.
Source-to-AST node lookup index.
Source code location representation.
Memory manager for AST nodes in a translation unit.
std::size_t getAstViewNodeCount() const
Get total number of view nodes.
AstNode * findTypeNode(const void *typePtr) const
Find existing deduplicated Type node (or nullptr).
AstViewNode * createAstViewNode(AstNode *node)
Create a new AST view node wrapping data.
std::size_t getAstNodeCount() const
Get total number of data nodes.
const SourceLocationIndex & getLocationIndex() const
Get location index for source-to-AST queries.
void finalizeLocationIndex()
Finalize location index (call after all nodes indexed).
void indexNode(AstViewNode *node)
Add node to location index.
AstNode * getOrCreateTypeNode(const void *typePtr, AcavJson properties, const SourceRange &range)
Get or create deduplicated Type node.
AstNode * createAstNode(AcavJson properties, const SourceRange &range)
Create a new AST data node.
Pure data container for AST node properties.
void hold()
Increment reference count.
AcavJson & getProperties()
Get mutable properties.
void release()
Decrement reference count.
const AcavJson & getProperties() const
Get node properties (kind, name, type, etc.).
std::size_t getUseCount() const
Get number of view nodes referencing this data.
const SourceRange & getSourceRange() const
Get source location range.
Represents node in AST tree hierarchy.
void setParent(AstViewNode *parent)
Set parent node.
AstNode * getNode() const
Get underlying data node.
const AcavJson & getProperties() const
Get node properties (delegates to data node).
const SourceRange & getSourceRange() const
Get source range (delegates to data node).
const std::vector< AstViewNode * > & getChildren() const
Get children in tree hierarchy.
AstViewNode * getParent() const
Get parent in tree hierarchy.
void addChild(AstViewNode *child)
Add child node.
Immutable string with automatic deduplication via global pool.
Index for source-to-AST node lookup.
Represents a span of source code (begin to end).