clang 23.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_SCALABLESTATICANALYSISFRAMEWORK_CORE_MODEL_ENTITYIDTABLE_H
10#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_MODEL_ENTITYIDTABLE_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 friend class SerializationFormat;
25 friend class TestFixture;
26
27 std::map<EntityName, EntityId> Entities;
28
29public:
30 EntityIdTable() = default;
31
32 /// Creates or retrieves an EntityId for the given EntityName.
33 ///
34 /// If the entity already exists in the table, returns its existing Id.
35 /// Otherwise, creates and returns a new Id. This operation is idempotent.
36 EntityId getId(const EntityName &Name);
37
38 /// Returns true if an entity with the given name exists in the table.
39 bool contains(const EntityName &Name) const;
40
41 /// Invokes the callback for each entity in the table.
42 ///
43 /// Iteration order is unspecified.
44 void forEach(
45 llvm::function_ref<void(const EntityName &, EntityId)> Callback) const;
46
47 /// Returns the number of unique entities in the table.
48 size_t count() const { return Entities.size(); }
49};
50
51} // namespace clang::ssaf
52
53#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_MODEL_ENTITYIDTABLE_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:31
Uniquely identifies an entity in a program.
Definition EntityName.h:28
const internal::ArgumentAdaptingMatcherFunc< internal::ForEachMatcher > forEach
Matches AST nodes that have child AST nodes that match the provided matcher.