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 = 26; // SwiftCopyable
28
29const uint8_t kSwiftCopyable = 1;
30const uint8_t kSwiftNonCopyable = 2;
31
32using IdentifierID = llvm::PointerEmbeddedInt<unsigned, 31>;
33using IdentifierIDField = llvm::BCVBR<16>;
34
35using SelectorID = llvm::PointerEmbeddedInt<unsigned, 31>;
36using SelectorIDField = llvm::BCVBR<16>;
37
38/// The various types of blocks that can occur within a API notes file.
39///
40/// These IDs must \em not be renumbered or reordered without incrementing
41/// VERSION_MAJOR.
42enum BlockID {
43 /// The control block, which contains all of the information that needs to
44 /// be validated prior to committing to loading the API notes file.
45 ///
46 /// \sa control_block
47 CONTROL_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID,
48
49 /// The identifier data block, which maps identifier strings to IDs.
51
52 /// The Objective-C context data block, which contains information about
53 /// Objective-C classes and protocols.
55
56 /// The Objective-C property data block, which maps Objective-C
57 /// (class name, property name) pairs to information about the
58 /// property.
60
61 /// The Objective-C property data block, which maps Objective-C
62 /// (class name, selector, is_instance_method) tuples to information
63 /// about the method.
65
66 /// The Objective-C selector data block, which maps Objective-C
67 /// selector names (# of pieces, identifier IDs) to the selector ID
68 /// used in other tables.
70
71 /// The global variables data block, which maps global variable names to
72 /// information about the global variable.
74
75 /// The (global) functions data block, which maps global function names to
76 /// information about the global function.
78
79 /// The tag data block, which maps tag names to information about
80 /// the tags.
82
83 /// The typedef data block, which maps typedef names to information about
84 /// the typedefs.
86
87 /// The enum constant data block, which maps enumerator names to
88 /// information about the enumerators.
90};
91
92namespace control_block {
93// These IDs must \em not be renumbered or reordered without incrementing
94// VERSION_MAJOR.
95enum {
100};
101
103 llvm::BCRecordLayout<METADATA, // ID
104 llvm::BCFixed<16>, // Module format major version
105 llvm::BCFixed<16> // Module format minor version
106 >;
107
108using ModuleNameLayout = llvm::BCRecordLayout<MODULE_NAME,
109 llvm::BCBlob // Module name
110 >;
111
113 llvm::BCRecordLayout<MODULE_OPTIONS,
114 llvm::BCFixed<1> // SwiftInferImportAsMember
115 >;
116
117using SourceFileLayout = llvm::BCRecordLayout<SOURCE_FILE,
118 llvm::BCVBR<16>, // file size
119 llvm::BCVBR<16> // creation time
120 >;
121} // namespace control_block
122
123namespace identifier_block {
124enum {
126};
127
128using IdentifierDataLayout = llvm::BCRecordLayout<
129 IDENTIFIER_DATA, // record ID
130 llvm::BCVBR<16>, // table offset within the blob (see below)
131 llvm::BCBlob // map from identifier strings to decl kinds / decl IDs
132 >;
133} // namespace identifier_block
134
135namespace objc_context_block {
136enum {
139};
140
142 llvm::BCRecordLayout<OBJC_CONTEXT_ID_DATA, // record ID
143 llvm::BCVBR<16>, // table offset within the blob (see
144 // below)
145 llvm::BCBlob // map from ObjC class names/protocol (as
146 // IDs) to context IDs
147 >;
148
149using ObjCContextInfoLayout = llvm::BCRecordLayout<
150 OBJC_CONTEXT_INFO_DATA, // record ID
151 llvm::BCVBR<16>, // table offset within the blob (see below)
152 llvm::BCBlob // map from ObjC context IDs to context information.
153 >;
154} // namespace objc_context_block
155
156namespace objc_property_block {
157enum {
159};
160
161using ObjCPropertyDataLayout = llvm::BCRecordLayout<
162 OBJC_PROPERTY_DATA, // record ID
163 llvm::BCVBR<16>, // table offset within the blob (see below)
164 llvm::BCBlob // map from ObjC (class name, property name) pairs to
165 // ObjC property information
166 >;
167} // namespace objc_property_block
168
169namespace objc_method_block {
170enum {
172};
173
175 llvm::BCRecordLayout<OBJC_METHOD_DATA, // record ID
176 llvm::BCVBR<16>, // table offset within the blob (see
177 // below)
178 llvm::BCBlob // map from ObjC (class names, selector,
179 // is-instance-method) tuples to ObjC
180 // method information
181 >;
182} // namespace objc_method_block
183
184namespace objc_selector_block {
185enum {
187};
188
190 llvm::BCRecordLayout<OBJC_SELECTOR_DATA, // record ID
191 llvm::BCVBR<16>, // table offset within the blob (see
192 // below)
193 llvm::BCBlob // map from (# pieces, identifier IDs) to
194 // Objective-C selector ID.
195 >;
196} // namespace objc_selector_block
197
198namespace global_variable_block {
200
201using GlobalVariableDataLayout = llvm::BCRecordLayout<
202 GLOBAL_VARIABLE_DATA, // record ID
203 llvm::BCVBR<16>, // table offset within the blob (see below)
204 llvm::BCBlob // map from name to global variable information
205 >;
206} // namespace global_variable_block
207
208namespace global_function_block {
210
211using GlobalFunctionDataLayout = llvm::BCRecordLayout<
212 GLOBAL_FUNCTION_DATA, // record ID
213 llvm::BCVBR<16>, // table offset within the blob (see below)
214 llvm::BCBlob // map from name to global function information
215 >;
216} // namespace global_function_block
217
218namespace tag_block {
219enum { TAG_DATA = 1 };
220
222 llvm::BCRecordLayout<TAG_DATA, // record ID
223 llvm::BCVBR<16>, // table offset within the blob (see
224 // below)
225 llvm::BCBlob // map from name to tag information
226 >;
227} // namespace tag_block
228
229namespace typedef_block {
230enum { TYPEDEF_DATA = 1 };
231
233 llvm::BCRecordLayout<TYPEDEF_DATA, // record ID
234 llvm::BCVBR<16>, // table offset within the blob (see
235 // below)
236 llvm::BCBlob // map from name to typedef information
237 >;
238} // namespace typedef_block
239
240namespace enum_constant_block {
242
244 llvm::BCRecordLayout<ENUM_CONSTANT_DATA, // record ID
245 llvm::BCVBR<16>, // table offset within the blob (see
246 // below)
247 llvm::BCBlob // map from name to enumerator information
248 >;
249} // namespace enum_constant_block
250
251/// A stored Objective-C selector.
253 unsigned NumArgs;
255};
256
257/// A stored Objective-C or C++ context, represented by the ID of its parent
258/// context, the kind of this context (Objective-C class / C++ namespace / etc),
259/// and the ID of this context.
262 uint8_t contextKind;
263 uint32_t contextID;
264
266
268 uint32_t contextID)
271
272 ContextTableKey(std::optional<Context> context, IdentifierID nameID)
273 : parentContextID(context ? context->id.Value : (uint32_t)-1),
274 contextKind(context ? static_cast<uint8_t>(context->kind)
275 : static_cast<uint8_t>(-1)),
276 contextID(nameID) {}
277
278 llvm::hash_code hashValue() const {
279 return llvm::hash_value(
281 }
282};
283
284inline bool operator==(const ContextTableKey &lhs, const ContextTableKey &rhs) {
285 return lhs.parentContextID == rhs.parentContextID &&
286 lhs.contextKind == rhs.contextKind && lhs.contextID == rhs.contextID;
287}
288
289} // namespace api_notes
290} // namespace clang
291
292namespace llvm {
293template <> struct DenseMapInfo<clang::api_notes::StoredObjCSelector> {
294 typedef DenseMapInfo<unsigned> UnsignedInfo;
295
297 return clang::api_notes::StoredObjCSelector{UnsignedInfo::getEmptyKey(),
298 {}};
299 }
300
302 return clang::api_notes::StoredObjCSelector{UnsignedInfo::getTombstoneKey(),
303 {}};
304 }
305
306 static unsigned
308 auto hash = llvm::hash_value(Selector.NumArgs);
309 hash = hash_combine(hash, Selector.Identifiers.size());
310 for (auto piece : Selector.Identifiers)
311 hash = hash_combine(hash, static_cast<unsigned>(piece));
312 // FIXME: Mix upper/lower 32-bit values together to produce
313 // unsigned rather than truncating.
314 return hash;
315 }
316
319 return LHS.NumArgs == RHS.NumArgs && LHS.Identifiers == RHS.Identifiers;
320 }
321};
322
323template <> struct DenseMapInfo<clang::api_notes::ContextTableKey> {
326 }
327
330 DenseMapInfo<uint32_t>::getTombstoneKey(),
331 DenseMapInfo<uint8_t>::getTombstoneKey(),
332 DenseMapInfo<uint32_t>::getTombstoneKey()};
333 }
334
335 static unsigned getHashValue(const clang::api_notes::ContextTableKey &value) {
336 return value.hashValue();
337 }
338
341 return lhs == rhs;
342 }
343};
344} // namespace llvm
345
346#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
const uint8_t kSwiftCopyable
bool operator==(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
Definition: Types.h:120
llvm::PointerEmbeddedInt< unsigned, 31 > IdentifierID
llvm::BCVBR< 16 > IdentifierIDField
const uint8_t kSwiftNonCopyable
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)