clang 24.0.0git
APINotesFormat.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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/ArrayRef.h"
14#include "llvm/ADT/PointerEmbeddedInt.h"
15#include "llvm/ADT/SmallVector.h"
16#include "llvm/Bitcode/BitcodeConvenience.h"
17
18#include <optional>
19
20namespace clang {
21namespace api_notes {
22/// Magic number for API notes files.
23const unsigned char API_NOTES_SIGNATURE[] = {0xE2, 0x9C, 0xA8, 0x01};
24
25/// API notes file major version number.
27
28/// API notes file minor version number.
29///
30/// When the format changes IN ANY WAY, this number should be incremented.
31const uint16_t VERSION_MINOR = 41; // 39 for BoundsSafety;
32 // 40 for UnsafeBufferUsageAttr
33 // 41 for FunctionTableKey parameters
34
37
38using IdentifierIDField = llvm::BCVBR<16>;
39
40using SelectorID = llvm::PointerEmbeddedInt<unsigned, 31>;
41using SelectorIDField = llvm::BCVBR<16>;
42
43/// The various types of blocks that can occur within a API notes file.
44///
45/// These IDs must \em not be renumbered or reordered without incrementing
46/// VERSION_MAJOR.
47enum BlockID {
48 /// The control block, which contains all of the information that needs to
49 /// be validated prior to committing to loading the API notes file.
50 ///
51 /// \sa control_block
52 CONTROL_BLOCK_ID = llvm::bitc::FIRST_APPLICATION_BLOCKID,
53
54 /// The identifier data block, which maps identifier strings to IDs.
56
57 /// The Objective-C context data block, which contains information about
58 /// Objective-C classes and protocols.
60
61 /// The Objective-C property data block, which maps Objective-C
62 /// (class name, property name) pairs to information about the
63 /// property.
65
66 /// The Objective-C property data block, which maps Objective-C
67 /// (class name, selector, is_instance_method) tuples to information
68 /// about the method.
70
71 /// The C++ method data block, which maps C++ (context id, method name) pairs
72 /// to information about the method.
74
75 /// The Objective-C selector data block, which maps Objective-C
76 /// selector names (# of pieces, identifier IDs) to the selector ID
77 /// used in other tables.
79
80 /// The fields data block, which maps names fields of C records to
81 /// information about the field.
83
84 /// The global variables data block, which maps global variable names to
85 /// information about the global variable.
87
88 /// The (global) functions data block, which maps global function names to
89 /// information about the global function.
91
92 /// The tag data block, which maps tag names to information about
93 /// the tags.
95
96 /// The typedef data block, which maps typedef names to information about
97 /// the typedefs.
99
100 /// The enum constant data block, which maps enumerator names to
101 /// information about the enumerators.
103};
104
105namespace control_block {
106// These IDs must \em not be renumbered or reordered without incrementing
107// VERSION_MAJOR.
108enum {
113};
114
116 llvm::BCRecordLayout<METADATA, // ID
117 llvm::BCFixed<16>, // Module format major version
118 llvm::BCFixed<16> // Module format minor version
119 >;
120
121using ModuleNameLayout = llvm::BCRecordLayout<MODULE_NAME,
122 llvm::BCBlob // Module name
123 >;
124
126 llvm::BCRecordLayout<MODULE_OPTIONS,
127 llvm::BCFixed<1> // SwiftInferImportAsMember
128 >;
129
130using SourceFileLayout = llvm::BCRecordLayout<SOURCE_FILE,
131 llvm::BCVBR<16>, // file size
132 llvm::BCVBR<16> // creation time
133 >;
134} // namespace control_block
135
137enum {
139};
140
141using IdentifierDataLayout = llvm::BCRecordLayout<
142 IDENTIFIER_DATA, // record ID
143 llvm::BCVBR<16>, // table offset within the blob (see below)
144 llvm::BCBlob // map from identifier strings to decl kinds / decl IDs
145 >;
146} // namespace identifier_block
147
148namespace context_block {
149enum {
152};
153
155 llvm::BCRecordLayout<CONTEXT_ID_DATA, // record ID
156 llvm::BCVBR<16>, // table offset within the blob (see
157 // below)
158 llvm::BCBlob // map from ObjC class names/protocol (as
159 // IDs) to context IDs
160 >;
161
162using ContextInfoLayout = llvm::BCRecordLayout<
163 CONTEXT_INFO_DATA, // record ID
164 llvm::BCVBR<16>, // table offset within the blob (see below)
165 llvm::BCBlob // map from ObjC context IDs to context information.
166 >;
167} // namespace context_block
168
170enum {
172};
173
174using ObjCPropertyDataLayout = llvm::BCRecordLayout<
175 OBJC_PROPERTY_DATA, // record ID
176 llvm::BCVBR<16>, // table offset within the blob (see below)
177 llvm::BCBlob // map from ObjC (class name, property name) pairs to
178 // ObjC property information
179 >;
180} // namespace objc_property_block
181
183enum {
185};
186
188 llvm::BCRecordLayout<OBJC_METHOD_DATA, // record ID
189 llvm::BCVBR<16>, // table offset within the blob (see
190 // below)
191 llvm::BCBlob // map from ObjC (class names, selector,
192 // is-instance-method) tuples to ObjC
193 // method information
194 >;
195} // namespace objc_method_block
196
198enum {
200};
201
203 llvm::BCRecordLayout<CXX_METHOD_DATA, // record ID
204 llvm::BCVBR<16>, // table offset within the blob (see
205 // below)
206 llvm::BCBlob // map from C++ (context id, name)
207 // tuples to C++ method information
208 >;
209} // namespace cxx_method_block
210
211namespace field_block {
212enum {
214};
215
217 llvm::BCRecordLayout<FIELD_DATA, // record ID
218 llvm::BCVBR<16>, // table offset within the blob (see
219 // below)
220 llvm::BCBlob // map from C (context id, name)
221 // tuples to C field information
222 >;
223} // namespace field_block
224
226enum {
228};
229
231 llvm::BCRecordLayout<OBJC_SELECTOR_DATA, // record ID
232 llvm::BCVBR<16>, // table offset within the blob (see
233 // below)
234 llvm::BCBlob // map from (# pieces, identifier IDs) to
235 // Objective-C selector ID.
236 >;
237} // namespace objc_selector_block
238
241
242using GlobalVariableDataLayout = llvm::BCRecordLayout<
243 GLOBAL_VARIABLE_DATA, // record ID
244 llvm::BCVBR<16>, // table offset within the blob (see below)
245 llvm::BCBlob // map from name to global variable information
246 >;
247} // namespace global_variable_block
248
251
252using GlobalFunctionDataLayout = llvm::BCRecordLayout<
253 GLOBAL_FUNCTION_DATA, // record ID
254 llvm::BCVBR<16>, // table offset within the blob (see below)
255 llvm::BCBlob // map from name to global function information
256 >;
257} // namespace global_function_block
258
259namespace tag_block {
260enum { TAG_DATA = 1 };
261
263 llvm::BCRecordLayout<TAG_DATA, // record ID
264 llvm::BCVBR<16>, // table offset within the blob (see
265 // below)
266 llvm::BCBlob // map from name to tag information
267 >;
268} // namespace tag_block
269
270namespace typedef_block {
271enum { TYPEDEF_DATA = 1 };
272
274 llvm::BCRecordLayout<TYPEDEF_DATA, // record ID
275 llvm::BCVBR<16>, // table offset within the blob (see
276 // below)
277 llvm::BCBlob // map from name to typedef information
278 >;
279} // namespace typedef_block
280
283
285 llvm::BCRecordLayout<ENUM_CONSTANT_DATA, // record ID
286 llvm::BCVBR<16>, // table offset within the blob (see
287 // below)
288 llvm::BCBlob // map from name to enumerator information
289 >;
290} // namespace enum_constant_block
291
292/// A stored Objective-C selector.
297
298/// A stored Objective-C or C++ context, represented by the ID of its parent
299/// context, the kind of this context (Objective-C class / C++ namespace / etc),
300/// and the ID of this context.
305
307
312
313 ContextTableKey(std::optional<ContextID> ParentContextID, ContextKind Kind,
315 : parentContextID(ParentContextID ? ParentContextID->Value : -1),
316 contextKind(static_cast<uint8_t>(Kind)), contextID(ContextID) {}
317
318 ContextTableKey(std::optional<Context> ParentContext, ContextKind Kind,
320 : ContextTableKey(ParentContext ? std::make_optional(ParentContext->id)
321 : std::nullopt,
322 Kind, ContextID) {}
323
324 llvm::hash_code hashValue() const {
325 return llvm::hash_value(
327 }
328};
329
330inline bool operator==(const ContextTableKey &lhs, const ContextTableKey &rhs) {
331 return lhs.parentContextID == rhs.parentContextID &&
332 lhs.contextKind == rhs.contextKind && lhs.contextID == rhs.contextID;
333}
334
335/// A stored Objective-C or C++ declaration, represented by the ID of its parent
336/// context, and the name of the declaration.
340
342
343 SingleDeclTableKey(uint32_t ParentContextID, uint32_t NameID)
344 : parentContextID(ParentContextID), nameID(NameID) {}
345
346 SingleDeclTableKey(std::optional<Context> ParentCtx, IdentifierID NameID)
347 : parentContextID(ParentCtx ? ParentCtx->id.Value
348 : static_cast<uint32_t>(-1)),
349 nameID(NameID) {}
350
351 llvm::hash_code hashValue() const {
352 return llvm::hash_value(std::make_pair(parentContextID, nameID));
353 }
354};
355
356inline bool operator==(const SingleDeclTableKey &lhs,
357 const SingleDeclTableKey &rhs) {
358 return lhs.parentContextID == rhs.parentContextID && lhs.nameID == rhs.nameID;
359}
360
361/// A stored C or C++ function declaration, represented by the ID of its parent
362/// context, the name of the declaration, and optional exact parameter types.
364constexpr unsigned FunctionTableKeyBaseLength =
365 sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint16_t);
366
367template <typename GetIdentifierFn>
368std::optional<FunctionTableKey>
369getFunctionKeyImpl(uint32_t ParentContextID, llvm::StringRef Name,
370 GetIdentifierFn GetIdentifier) {
371 std::optional<IdentifierID> NameID = GetIdentifier(Name);
372 if (!NameID)
373 return std::nullopt;
374
375 return FunctionTableKey(ParentContextID, *NameID);
376}
377
378template <typename ParameterT, typename GetIdentifierFn>
379std::optional<FunctionTableKey>
380getFunctionKeyImpl(uint32_t ParentContextID, llvm::StringRef Name,
382 GetIdentifierFn GetIdentifier) {
383 std::optional<IdentifierID> NameID = GetIdentifier(Name);
384 if (!NameID)
385 return std::nullopt;
386
387 llvm::SmallVector<IdentifierID, 2> ParameterTypeIDs;
388 ParameterTypeIDs.reserve(Parameters.size());
389 for (const ParameterT &Parameter : Parameters) {
390 std::optional<IdentifierID> ParameterID =
391 GetIdentifier(llvm::StringRef(Parameter));
392 if (!ParameterID)
393 return std::nullopt;
394 ParameterTypeIDs.push_back(*ParameterID);
395 }
396 return FunctionTableKey(ParentContextID, *NameID, ParameterTypeIDs);
397}
398
399} // namespace api_notes
400} // namespace clang
401
402namespace llvm {
403template <> struct DenseMapInfo<clang::api_notes::StoredObjCSelector> {
404 typedef DenseMapInfo<unsigned> UnsignedInfo;
405
406 static unsigned
408 auto hash = llvm::hash_value(Selector.NumArgs);
409 hash = hash_combine(hash, Selector.Identifiers.size());
410 for (auto piece : Selector.Identifiers)
411 hash = hash_combine(hash, static_cast<unsigned>(piece));
412 // FIXME: Mix upper/lower 32-bit values together to produce
413 // unsigned rather than truncating.
414 return hash;
415 }
416
419 return LHS.NumArgs == RHS.NumArgs && LHS.Identifiers == RHS.Identifiers;
420 }
421};
422
423template <> struct DenseMapInfo<clang::api_notes::ContextTableKey> {
424 static unsigned getHashValue(const clang::api_notes::ContextTableKey &value) {
425 return value.hashValue();
426 }
427
430 return lhs == rhs;
431 }
432};
433
434template <> struct DenseMapInfo<clang::api_notes::SingleDeclTableKey> {
435 static unsigned
437 return value.hashValue();
438 }
439
442 return lhs == rhs;
443 }
444};
445
446} // namespace llvm
447
448#endif
Opaque context ID used to refer to an Objective-C class or protocol or a C++ namespace.
Definition Types.h:988
llvm::BCRecordLayout< CONTEXT_INFO_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > ContextInfoLayout
llvm::BCRecordLayout< CONTEXT_ID_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > ContextIDLayout
llvm::BCRecordLayout< MODULE_NAME, llvm::BCBlob > ModuleNameLayout
llvm::BCRecordLayout< SOURCE_FILE, llvm::BCVBR< 16 >, llvm::BCVBR< 16 > > SourceFileLayout
llvm::BCRecordLayout< MODULE_OPTIONS, llvm::BCFixed< 1 > > ModuleOptionsLayout
llvm::BCRecordLayout< METADATA, llvm::BCFixed< 16 >, llvm::BCFixed< 16 > > MetadataLayout
llvm::BCRecordLayout< CXX_METHOD_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > CXXMethodDataLayout
llvm::BCRecordLayout< ENUM_CONSTANT_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > EnumConstantDataLayout
llvm::BCRecordLayout< FIELD_DATA, llvm::BCVBR< 16 >, llvm::BCBlob > FieldDataLayout
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_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
constexpr unsigned FunctionTableKeyBaseLength
bool operator==(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
Definition Types.h:160
llvm::PointerEmbeddedInt< unsigned, 31 > IdentifierID
Definition Types.h:1009
llvm::PointerEmbeddedInt< unsigned, 31 > SelectorID
std::optional< FunctionTableKey > getFunctionKeyImpl(uint32_t ParentContextID, llvm::StringRef Name, GetIdentifierFn GetIdentifier)
const uint8_t kSwiftConforms
llvm::BCVBR< 16 > IdentifierIDField
const uint8_t kSwiftDoesNotConform
constexpr uint8_t FunctionKeyHasParameterSelector
A stored C or C++ function declaration, represented by the ID of its parent context,...
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,...
@ FIELD_BLOCK_ID
The fields data block, which maps names fields of C records to information about the field.
@ OBJC_SELECTOR_BLOCK_ID
The Objective-C selector data block, which maps Objective-C selector names (# of pieces,...
@ CXX_METHOD_BLOCK_ID
The C++ method data block, which maps C++ (context id, method name) pairs to information about the me...
@ 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.
@ Parameter
The parameter type of a method or function.
Definition TypeBase.h:909
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
hash_code hash_value(const clang::dependencies::ModuleID &ID)
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 uint16_t
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
A stored Objective-C or C++ context, represented by the ID of its parent context, the kind of this co...
ContextTableKey(std::optional< Context > ParentContext, ContextKind Kind, uint32_t ContextID)
llvm::hash_code hashValue() const
ContextTableKey(uint32_t parentContextID, uint8_t contextKind, uint32_t contextID)
ContextTableKey(std::optional< ContextID > ParentContextID, ContextKind Kind, uint32_t ContextID)
A key for a stored global-function or C++-method API notes entry.
Definition Types.h:1015
A stored Objective-C or C++ declaration, represented by the ID of its parent context,...
SingleDeclTableKey(std::optional< Context > ParentCtx, IdentifierID NameID)
SingleDeclTableKey(uint32_t ParentContextID, uint32_t NameID)
A stored Objective-C selector.
llvm::SmallVector< IdentifierID, 2 > Identifiers
static unsigned getHashValue(const clang::api_notes::ContextTableKey &value)
static bool isEqual(const clang::api_notes::ContextTableKey &lhs, const clang::api_notes::ContextTableKey &rhs)
static bool isEqual(const clang::api_notes::SingleDeclTableKey &lhs, const clang::api_notes::SingleDeclTableKey &rhs)
static unsigned getHashValue(const clang::api_notes::SingleDeclTableKey &value)
static bool isEqual(const clang::api_notes::StoredObjCSelector &LHS, const clang::api_notes::StoredObjCSelector &RHS)
static unsigned getHashValue(const clang::api_notes::StoredObjCSelector &Selector)