clang 22.0.0git
EntityIdTable.h
Go to the documentation of this file.
1//===- EntityIdTable.h ------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_ANALYSIS_SCALABLE_MODEL_ENTITY_ID_TABLE_H
10#define LLVM_CLANG_ANALYSIS_SCALABLE_MODEL_ENTITY_ID_TABLE_H
11
14#include <functional>
15#include <map>
16
17namespace clang::ssaf {
18
19/// Manages entity name interning and provides efficient EntityId handles.
20///
21/// The table maps each unique EntityName to exactly one EntityId.
22/// Entities are never removed.
24 std::map<EntityName, EntityId> Entities;
25
26public:
27 EntityIdTable() = default;
28
29 /// Creates or retrieves an EntityId for the given EntityName.
30 ///
31 /// If the entity already exists in the table, returns its existing Id.
32 /// Otherwise, creates and returns a new Id. This operation is idempotent.
33 EntityId getId(const EntityName &Name);
34
35 /// Returns true if an entity with the given name exists in the table.
36 bool contains(const EntityName &Name) const;
37
38 /// Invokes the callback for each entity in the table.
39 ///
40 /// Iteration order is unspecified.
41 void forEach(
42 llvm::function_ref<void(const EntityName &, EntityId)> Callback) const;
43
44 /// Returns the number of unique entities in the table.
45 size_t count() const { return Entities.size(); }
46};
47
48} // namespace clang::ssaf
49
50#endif // LLVM_CLANG_ANALYSIS_SCALABLE_MODEL_ENTITY_ID_TABLE_H
bool contains(const EntityName &Name) const
Returns true if an entity with the given name exists in the table.
EntityId getId(const EntityName &Name)
Creates or retrieves an EntityId for the given EntityName.
size_t count() const
Returns the number of unique entities in the table.
Lightweight opaque handle representing an entity in an EntityIdTable.
Definition EntityId.h:30
Uniquely identifies an entity in a program.
Definition EntityName.h:27
const internal::ArgumentAdaptingMatcherFunc< internal::ForEachMatcher > forEach
Matches AST nodes that have child AST nodes that match the provided matcher.