Skip to content

Commit 41021e8

Browse files
authored
[APINotes] Upstream APINotes YAML compiler
This upstreams more of the Clang API Notes functionality that is currently implemented in the Apple fork: https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes
1 parent 743c4fe commit 41021e8

File tree

6 files changed

+495
-6
lines changed

6 files changed

+495
-6
lines changed

clang/include/clang/APINotes/APINotesYAMLCompiler.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,25 @@
1010
#define LLVM_CLANG_APINOTES_APINOTESYAMLCOMPILER_H
1111

1212
#include "llvm/ADT/StringRef.h"
13+
#include "llvm/Support/SourceMgr.h"
1314
#include "llvm/Support/raw_ostream.h"
1415

16+
namespace clang {
17+
class FileEntry;
18+
} // namespace clang
19+
1520
namespace clang {
1621
namespace api_notes {
1722
/// Parses the APINotes YAML content and writes the representation back to the
1823
/// specified stream. This provides a means of testing the YAML processing of
1924
/// the APINotes format.
2025
bool parseAndDumpAPINotes(llvm::StringRef YI, llvm::raw_ostream &OS);
26+
27+
/// Converts API notes from YAML format to binary format.
28+
bool compileAPINotes(llvm::StringRef YAMLInput, const FileEntry *SourceFile,
29+
llvm::raw_ostream &OS,
30+
llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr,
31+
void *DiagHandlerCtxt = nullptr);
2132
} // namespace api_notes
2233
} // namespace clang
2334

clang/include/clang/APINotes/Types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ struct Context {
766766
/// data they contain; it is up to the user to ensure that the data
767767
/// referenced by the identifier list persists.
768768
struct ObjCSelectorRef {
769+
unsigned NumArgs;
769770
llvm::ArrayRef<llvm::StringRef> Identifiers;
770771
};
771772
} // namespace api_notes

clang/lib/APINotes/APINotesFormat.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ using EnumConstantDataLayout =
247247

248248
/// A stored Objective-C selector.
249249
struct StoredObjCSelector {
250-
unsigned NumPieces;
250+
unsigned NumArgs;
251251
llvm::SmallVector<IdentifierID, 2> Identifiers;
252252
};
253253

@@ -302,7 +302,7 @@ template <> struct DenseMapInfo<clang::api_notes::StoredObjCSelector> {
302302

303303
static unsigned
304304
getHashValue(const clang::api_notes::StoredObjCSelector &Selector) {
305-
auto hash = llvm::hash_value(Selector.NumPieces);
305+
auto hash = llvm::hash_value(Selector.NumArgs);
306306
hash = hash_combine(hash, Selector.Identifiers.size());
307307
for (auto piece : Selector.Identifiers)
308308
hash = hash_combine(hash, static_cast<unsigned>(piece));
@@ -313,7 +313,7 @@ template <> struct DenseMapInfo<clang::api_notes::StoredObjCSelector> {
313313

314314
static bool isEqual(const clang::api_notes::StoredObjCSelector &LHS,
315315
const clang::api_notes::StoredObjCSelector &RHS) {
316-
return LHS.NumPieces == RHS.NumPieces && LHS.Identifiers == RHS.Identifiers;
316+
return LHS.NumArgs == RHS.NumArgs && LHS.Identifiers == RHS.Identifiers;
317317
}
318318
};
319319

clang/lib/APINotes/APINotesReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ class ObjCSelectorTableInfo {
421421

422422
static internal_key_type ReadKey(const uint8_t *Data, unsigned Length) {
423423
internal_key_type Key;
424-
Key.NumPieces =
424+
Key.NumArgs =
425425
endian::readNext<uint16_t, llvm::endianness::little, unaligned>(Data);
426426
unsigned NumIdents = (Length - sizeof(uint16_t)) / sizeof(uint32_t);
427427
for (unsigned i = 0; i != NumIdents; ++i) {
@@ -741,6 +741,7 @@ APINotesReader::Implementation::getSelector(ObjCSelectorRef Selector) {
741741

742742
// Translate the identifiers.
743743
StoredObjCSelector Key;
744+
Key.NumArgs = Selector.NumArgs;
744745
for (auto Ident : Selector.Identifiers) {
745746
if (auto IdentID = getIdentifier(Ident)) {
746747
Key.Identifiers.push_back(*IdentID);

clang/lib/APINotes/APINotesWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ class ObjCSelectorTableInfo {
823823

824824
void EmitKey(raw_ostream &OS, key_type_ref Key, unsigned) {
825825
llvm::support::endian::Writer writer(OS, llvm::endianness::little);
826-
writer.write<uint16_t>(Key.NumPieces);
826+
writer.write<uint16_t>(Key.NumArgs);
827827
for (auto Identifier : Key.Identifiers)
828828
writer.write<uint32_t>(Identifier);
829829
}

0 commit comments

Comments
 (0)