Introduce EntityId and EntityIdTable to provide efficient, lightweight handles for working with EntityNames in the Scalable Static Analysis Framework (SSAF). Introduces two key components: - EntityId: Lightweight opaque handle representing an entity in an EntityIdTable - EntityIdTable: Entity name interning table that maps unique EntityNames to EntityIds The interning table ensures each EntityName maps to exactly one EntityId, providing fast equality comparisons and lookups. EntityIds are index-based and remain stable for the lifetime of their table. This enables efficient entity tracking and comparison operations needed for TU summary extraction and serialization. --------- Co-authored-by: Yitzhak Mandelbaum <ymand@users.noreply.github.com>
32 lines
989 B
C++
32 lines
989 B
C++
//===- EntityIdTable.cpp ----------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Analysis/Scalable/Model/EntityIdTable.h"
|
|
#include <cassert>
|
|
|
|
namespace clang::ssaf {
|
|
|
|
EntityId EntityIdTable::getId(const EntityName &Name) {
|
|
EntityId Id(Entities.size());
|
|
const auto Res = Entities.try_emplace(Name, Id);
|
|
return Res.first->second;
|
|
}
|
|
|
|
bool EntityIdTable::contains(const EntityName &Name) const {
|
|
return Entities.find(Name) != Entities.end();
|
|
}
|
|
|
|
void EntityIdTable::forEach(
|
|
llvm::function_ref<void(const EntityName &, EntityId)> Callback) const {
|
|
for (const auto &NameIdPair : Entities) {
|
|
Callback(NameIdPair.first, NameIdPair.second);
|
|
}
|
|
}
|
|
|
|
} // namespace clang::ssaf
|