clang 24.0.0git
EntityId.h
Go to the documentation of this file.
1//===- EntityId.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// This file defines the EntityId class, which provides a lightweight opaque
10// handle to entities in an EntityIdTable. EntityIds are index-based for
11// efficient comparison and lookup.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_MODEL_ENTITYID_H
16#define LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_MODEL_ENTITYID_H
17
18#include "llvm/Support/raw_ostream.h"
19#include <cstddef>
20
21namespace clang::ssaf {
22
23class EntityIdTable;
24
25/// Lightweight opaque handle representing an entity in an EntityIdTable.
26///
27/// EntityIds are created by EntityIdTable. Equality and ordering comparisons
28/// are well-defined for EntityIds created by the same EntityIdTable.
29///
30/// \see EntityIdTable
31class EntityId {
32 friend class EntityIdTable;
33 friend class SerializationFormat;
34 friend class TestFixture;
35 friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
36 const EntityId &Id);
37 friend struct llvm::DenseMapInfo<EntityId>;
38
39 size_t Index;
40
41 explicit EntityId(size_t Index) : Index(Index) {}
42
43 EntityId() = delete;
44
45public:
46 bool operator==(const EntityId &Other) const { return Index == Other.Index; }
47 bool operator<(const EntityId &Other) const { return Index < Other.Index; }
48 bool operator!=(const EntityId &Other) const { return !(*this == Other); }
49};
50
51llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const EntityId &Id);
52
53} // namespace clang::ssaf
54
55namespace llvm {
56template <> struct DenseMapInfo<clang::ssaf::EntityId> {
58 static unsigned getHashValue(EntityId Val) {
59 return densemap::detail::mix(Val.Index);
60 }
61 static bool isEqual(EntityId LHS, EntityId RHS) { return LHS == RHS; }
62};
63} // namespace llvm
64
65#endif // LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_MODEL_ENTITYID_H
Manages entity name interning and provides efficient EntityId handles.
Lightweight opaque handle representing an entity in an EntityIdTable.
Definition EntityId.h:31
bool operator==(const EntityId &Other) const
Definition EntityId.h:46
bool operator!=(const EntityId &Other) const
Definition EntityId.h:48
friend class EntityIdTable
Definition EntityId.h:32
friend llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const EntityId &Id)
Definition EntityId.cpp:13
friend class SerializationFormat
Definition EntityId.h:33
bool operator<(const EntityId &Other) const
Definition EntityId.h:47
friend class TestFixture
Definition EntityId.h:34
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const VirtualMethodSummary &S)
Prints S as "VirtualMethodSummary { params=[...], return=..., overridden=[...] }".
Top level wrappers for InstallAPI frontend operations.
@ Other
Other implicit parameter.
Definition Decl.h:1775
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
static bool isEqual(EntityId LHS, EntityId RHS)
Definition EntityId.h:61
static unsigned getHashValue(EntityId Val)
Definition EntityId.h:58