clang 19.0.0git
APINotesFormat.h
Go to the documentation of this file.
1//===-- APINotesWriter.h - API Notes Writer ---------------------*- 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_LIB_APINOTES_APINOTESFORMAT_H
10#define LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
11
13#include "llvm/ADT/PointerEmbeddedInt.h"
14#include "llvm/Bitcode/BitcodeConvenience.h"
15
16namespace clang {
17namespace api_notes {
18/// Magic number for API notes files.
19const unsigned char API_NOTES_SIGNATURE[] = {0xE2, 0x9C, 0xA8, 0x01};
20
21/// API notes file major version number.
22const uint16_t VERSION_MAJOR = 0;
23
24/// API notes file minor version number.
25///
26/// When the format changes IN ANY WAY, this number should be incremented.
27const uint16_t VERSION_MINOR = 25; // SwiftImportAs
28
29using IdentifierID = llvm::PointerEmbeddedInt<unsigned, 31>;
30using IdentifierIDField = llvm::BCVBR<16>;
31
32using SelectorID = llvm::PointerEmbeddedInt<unsigned, 31>;
33using SelectorIDField = llvm::BCVBR<16>;
34
35/// The various types of blocks that can occur within a API notes file.
36///
37/// These IDs must \em not be renumbered or reordered without incrementing
38/// VERSION_MAJOR.
39enum BlockID {
40 /// The control block, which contains all of the information that needs to
41 /// be validated prior to committing to loading the API notes file.
42 ///
43 /// \sa control_block
44 CONTROL_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID,
45
46 /// The identifier data block, which maps identifier strings to IDs.
48
49 /// The Objective-C context data block, which contains information about
50 /// Objective-C classes and protocols.
52
53 /// The Objective-C property data block, which maps Objective-C
54 /// (class name, property name) pairs to information about the
55 /// property.
57
58 /// The Objective-C property data block, which maps Objective-C
59 /// (class name, selector, is_instance_method) tuples to information
60 /// about the method.
62
63 /// The Objective-C selector data block, which maps Objective-C
64 /// selector names (# of pieces, identifier IDs) to the selector ID
65 /// used in other tables.
67
68 /// The global variables data block, which maps global variable names to
69 /// information about the global variable.
71
72 /// The (global) functions data block, which maps global function names to
73 /// information about the global function.
75
76 /// The tag data block, which maps tag names to information about
77 /// the tags.
79
80 /// The typedef data block, which maps typedef names to information about
81 /// the typedefs.
83
84 /// The enum constant data block, which maps enumerator names to
85 /// information about the enumerators.
87};
88
89namespace control_block {
90// These IDs must \em not be renumbered or reordered without incrementing
91// VERSION_MAJOR.
92enum {
97};
98
100 llvm::BCRecordLayout<METADATA, // ID
101 llvm::BCFixed<16>, // Module format major version
102 llvm::BCFixed<16> // Module format minor version
103 >;
104
105using ModuleNameLayout = llvm::BCRecordLayout<MODULE_NAME,
106 llvm::BCBlob // Module name
107 >;
108
110 llvm::BCRecordLayout<MODULE_OPTIONS,
111 llvm::BCFixed<1> // SwiftInferImportAsMember
112 >;
113
114using SourceFileLayout = llvm::BCRecordLayout<SOURCE_FILE,
115 llvm::BCVBR<16>, // file size
116 llvm::BCVBR<16> // creation time
117 >;
118} // namespace control_block
119
120namespace identifier_block {
121enum {
123};
124
125using IdentifierDataLayout = llvm::BCRecordLayout<
126 IDENTIFIER_DATA, // record ID
127 llvm::BCVBR<16>, // table offset within the blob (see below)
128 llvm::BCBlob // map from identifier strings to decl kinds / decl IDs
129 >;
130} // namespace identifier_block
131
132namespace objc_context_block {
133enum {
136};
137
139 llvm::BCRecordLayout<OBJC_CONTEXT_ID_DATA, // record ID
140 llvm::BCVBR<16>, // table offset within the blob (see
141 // below)
142 llvm::BCBlob // map from ObjC class names/protocol (as
143 // IDs) to context IDs
144 >;
145
146using ObjCContextInfoLayout = llvm::BCRecordLayout<
147 OBJC_CONTEXT_INFO_DATA, // record ID
148 llvm::BCVBR<16>, // table offset within the blob (see below)
149 llvm::BCBlob // map from ObjC context IDs to context information.
150 >;
151} // namespace objc_context_block
152
153namespace objc_property_block {
154enum {
156};
157
158using ObjCPropertyDataLayout = llvm::BCRecordLayout<
159 OBJC_PROPERTY_DATA, // record ID
160 llvm::BCVBR<16>, // table offset within the blob (see below)
161 llvm::BCBlob // map from ObjC (class name, property name) pairs to
162 // ObjC property information
163 >;
164} // namespace objc_property_block
165
166namespace objc_method_block {
167enum {
169};
170
172 llvm::BCRecordLayout<OBJC_METHOD_DATA, // record ID
173 llvm::BCVBR<16>, // table offset within the blob (see
174 // below)
175 llvm::BCBlob // map from ObjC (class names, selector,
176 // is-instance-method) tuples to ObjC
177 // method information
178 >;
179} // namespace objc_method_block
180
181namespace objc_selector_block {
182enum {
184};
185
187 llvm::BCRecordLayout<OBJC_SELECTOR_DATA, // record ID
188 llvm::BCVBR<16>, // table offset within the blob (see
189 // below)
190 llvm::BCBlob // map from (# pieces, identifier IDs) to
191 // Objective-C selector ID.
192 >;
193} // namespace objc_selector_block
194
195namespace global_variable_block {
197
198using GlobalVariableDataLayout = llvm::BCRecordLayout<
199 GLOBAL_VARIABLE_DATA, // record ID
200 llvm::BCVBR<16>, // table offset within the blob (see below)
201 llvm::BCBlob // map from name to global variable information
202 >;
203} // namespace global_variable_block
204
205namespace global_function_block {
207
208using GlobalFunctionDataLayout = llvm::BCRecordLayout<
209 GLOBAL_FUNCTION_DATA, // record ID
210 llvm::BCVBR<16>, // table offset within the blob (see below)
211 llvm::BCBlob // map from name to global function information
212 >;
213} // namespace global_function_block
214
215namespace tag_block {
216enum { TAG_DATA = 1 };
217
219 llvm::BCRecordLayout<TAG_DATA, // record ID
220 llvm::BCVBR<16>, // table offset within the blob (see
221 // below)
222 llvm::BCBlob // map from name to tag information
223 >;
224} // namespace tag_block
225
226namespace typedef_block {
227enum { TYPEDEF_DATA = 1 };
228
230 llvm::BCRecordLayout<TYPEDEF_DATA, // record ID
231 llvm::BCVBR<16>, // table offset within the blob (see
232 // below)
233 llvm::BCBlob // map from name to typedef information
234 >;
235} // namespace typedef_block
236
237namespace enum_constant_block {
239
241 llvm::BCRecordLayout<ENUM_CONSTANT_DATA, // record ID
242 llvm::BCVBR<16>, // table offset within the blob (see
243 // below)
244 llvm::BCBlob // map from name to enumerator information
245 >;
246} // namespace enum_constant_block
247
248/// A stored Objective-C selector.
250 unsigned NumArgs;
252};
253
254/// A stored Objective-C or C++ context, represented by the ID of its parent
255/// context, the kind of this context (Objective-C class / C++ namespace / etc),
256/// and the ID of this context.
259 uint8_t contextKind;
260 uint32_t contextID;
261
263
265 uint32_t contextID)
268
269 ContextTableKey(std::optional<Context> context, IdentifierID nameID)
270 : parentContextID(context ? context->id.Value : (uint32_t)-1),
271 contextKind(context ? static_cast<uint8_t>(context->kind)
272 : static_cast<uint8_t>(-1)),
273 contextID(nameID) {}
274
275 llvm::hash_code hashValue() const {
276 return llvm::hash_value(
278 }
279};
280
281inline bool operator==(const ContextTableKey &lhs, const ContextTableKey &rhs) {
282 return lhs.parentContextID == rhs.parentContextID &&
283 lhs.contextKind == rhs.contextKind && lhs.contextID == rhs.contextID;
284}
285
286} // namespace api_notes
287} // namespace clang
288
289namespace llvm {
290template <> struct DenseMapInfo<clang::api_notes::StoredObjCSelector> {
291 typedef DenseMapInfo<unsigned> UnsignedInfo;
292
294 return clang::api_notes::StoredObjCSelector{UnsignedInfo::getEmptyKey(),
295 {}};
296 }
297
299 return clang::api_notes::StoredObjCSelector{UnsignedInfo::getTombstoneKey(),
300 {}};
301 }
302
303 static unsigned
305 auto hash = llvm::hash_value(Selector.NumArgs);
306 hash = hash_combine(hash, Selector.Identifiers.size());
307 for (auto piece : Selector.Identifiers)
308 hash = hash_combine(hash, static_cast<unsigned>(piece));
309 // FIXME: Mix upper/lower 32-bit values together to produce
310 // unsigned rather than truncating.
311 return hash;
312 }
313
316 return LHS.NumArgs == RHS.NumArgs && LHS.Identifiers == RHS.Identifiers;
317 }
318};
319
320template <> struct DenseMapInfo<clang::api_notes::ContextTableKey> {
323 }
324
327 DenseMapInfo<uint32_t>::getTombstoneKey(),
328 DenseMapInfo<uint8_t>::getTombstoneKey(),
329 DenseMapInfo<uint32_t>::getTombstoneKey()};
330 }
331
332 static unsigned getHashValue(const clang::api_notes::ContextTableKey &value) {
333 return value.hashValue();
334 }
335
338 return lhs == rhs;
339 }
340};
341} // namespace llvm
342
343#endif
llvm::BCRecordLayout< SOURCE_FILE, llvm::BCVBR< 16 >, llvm::BCVBR< 16 > > SourceFileLayout
llvm::BCRecordLayout< MODULE_NAME, llvm::BCBlob > ModuleNameLayout
llvm::BCRecordLayout< MODULE_OPTIONS, llvm::BCFixed< 1 > > ModuleOptionsLayout
llvm::BCRecordLayout< METADATA, llvm::BCFixed< 16 >, llvm::BCFixed< 16 > > MetadataLayout
llvm::BCRecordLayout< ENUM_CONSTANT_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > EnumConstantDataLayout
llvm::BCRecordLayout< GLOBAL_FUNCTION_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > GlobalFunctionDataLayout
llvm::BCRecordLayout< GLOBAL_VARIABLE_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > GlobalVariableDataLayout
llvm::BCRecordLayout< IDENTIFIER_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > IdentifierDataLayout
llvm::BCRecordLayout< OBJC_CONTEXT_ID_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > ObjCContextIDLayout
llvm::BCRecordLayout< OBJC_CONTEXT_INFO_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > ObjCContextInfoLayout
llvm::BCRecordLayout< OBJC_METHOD_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > ObjCMethodDataLayout
llvm::BCRecordLayout< OBJC_PROPERTY_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > ObjCPropertyDataLayout
llvm::BCRecordLayout< OBJC_SELECTOR_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > ObjCSelectorDataLayout
llvm::BCRecordLayout< TAG_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > TagDataLayout
llvm::BCRecordLayout< TYPEDEF_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > TypedefDataLayout
llvm::BCVBR< 16 > SelectorIDField
llvm::PointerEmbeddedInt< unsigned, 31 > SelectorID
bool operator==(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
Definition: Types.h:120
llvm::PointerEmbeddedInt< unsigned, 31 > IdentifierID
llvm::BCVBR< 16 > IdentifierIDField
const uint16_t VERSION_MAJOR
API notes file major version number.
const unsigned char API_NOTES_SIGNATURE[]
Magic number for API notes files.
const uint16_t VERSION_MINOR
API notes file minor version number.
BlockID
The various types of blocks that can occur within a API notes file.
@ OBJC_CONTEXT_BLOCK_ID
The Objective-C context data block, which contains information about Objective-C classes and protocol...
@ TYPEDEF_BLOCK_ID
The typedef data block, which maps typedef names to information about the typedefs.
@ OBJC_PROPERTY_BLOCK_ID
The Objective-C property data block, which maps Objective-C (class name, property name) pairs to info...
@ ENUM_CONSTANT_BLOCK_ID
The enum constant data block, which maps enumerator names to information about the enumerators.
@ TAG_BLOCK_ID
The tag data block, which maps tag names to information about the tags.
@ OBJC_METHOD_BLOCK_ID
The Objective-C property data block, which maps Objective-C (class name, selector,...
@ OBJC_SELECTOR_BLOCK_ID
The Objective-C selector data block, which maps Objective-C selector names (# of pieces,...
@ GLOBAL_FUNCTION_BLOCK_ID
The (global) functions data block, which maps global function names to information about the global f...
@ CONTROL_BLOCK_ID
The control block, which contains all of the information that needs to be validated prior to committi...
@ IDENTIFIER_BLOCK_ID
The identifier data block, which maps identifier strings to IDs.
@ GLOBAL_VARIABLE_BLOCK_ID
The global variables data block, which maps global variable names to information about the global var...
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
hash_code hash_value(const clang::tooling::dependencies::ModuleID &ID)
A stored Objective-C or C++ context, represented by the ID of its parent context, the kind of this co...
ContextTableKey(std::optional< Context > context, IdentifierID nameID)
llvm::hash_code hashValue() const
ContextTableKey(uint32_t parentContextID, uint8_t contextKind, uint32_t contextID)
A stored Objective-C selector.
llvm::SmallVector< IdentifierID, 2 > Identifiers
static clang::api_notes::ContextTableKey getTombstoneKey()
static unsigned getHashValue(const clang::api_notes::ContextTableKey &value)
static clang::api_notes::ContextTableKey getEmptyKey()
static bool isEqual(const clang::api_notes::ContextTableKey &lhs, const clang::api_notes::ContextTableKey &rhs)
static clang::api_notes::StoredObjCSelector getEmptyKey()
static bool isEqual(const clang::api_notes::StoredObjCSelector &LHS, const clang::api_notes::StoredObjCSelector &RHS)
static clang::api_notes::StoredObjCSelector getTombstoneKey()
static unsigned getHashValue(const clang::api_notes::StoredObjCSelector &Selector)