Skip to content

Commit f806be5

Browse files
committed
APINotes: add initial stub of APINotesWriter
This adds the skeleton for serializing out the APINotes data from the APINotes. The writer uses a private implementation pattern to reduce the exposed surface to just the programmatic representation of the APINotes and not expose the details of the bitcode encoding. The format itself is not considered stable and should only be accessed through the APINotes Reader and Writer types. Differential Revision: https://reviews.llvm.org/D92797 Reviewed By: martong
1 parent 12babb0 commit f806be5

File tree

4 files changed

+1235
-0
lines changed

4 files changed

+1235
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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_APINOTES_WRITER_H
10+
#define LLVM_CLANG_APINOTES_WRITER_H
11+
12+
#include "llvm/ADT/StringRef.h"
13+
#include "llvm/Support/raw_ostream.h"
14+
15+
#include <memory>
16+
17+
namespace clang {
18+
class FileEntry;
19+
20+
namespace api_notes {
21+
class APINotesWriter {
22+
class Implementation;
23+
std::unique_ptr<Implementation> Implementation;
24+
25+
public:
26+
APINotesWriter(llvm::StringRef ModuleName, const FileEntry *SF);
27+
~APINotesWriter();
28+
29+
APINotesWriter(const APINotesWriter &) = delete;
30+
APINotesWriter &operator=(const APINotesWriter &) = delete;
31+
32+
void writeToStream(llvm::raw_ostream &OS);
33+
};
34+
} // namespace api_notes
35+
} // namespace clang
36+
37+
#endif

clang/lib/APINotes/APINotesFormat.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,36 @@ struct StoredObjCSelector {
252252
} // namespace api_notes
253253
} // namespace clang
254254

255+
namespace llvm {
256+
template <> struct DenseMapInfo<clang::api_notes::StoredObjCSelector> {
257+
typedef DenseMapInfo<unsigned> UnsignedInfo;
258+
259+
static inline clang::api_notes::StoredObjCSelector getEmptyKey() {
260+
return clang::api_notes::StoredObjCSelector{UnsignedInfo::getEmptyKey(),
261+
{}};
262+
}
263+
264+
static inline clang::api_notes::StoredObjCSelector getTombstoneKey() {
265+
return clang::api_notes::StoredObjCSelector{UnsignedInfo::getTombstoneKey(),
266+
{}};
267+
}
268+
269+
static unsigned
270+
getHashValue(const clang::api_notes::StoredObjCSelector &Selector) {
271+
auto hash = llvm::hash_value(Selector.NumPieces);
272+
hash = hash_combine(hash, Selector.Identifiers.size());
273+
for (auto piece : Selector.Identifiers)
274+
hash = hash_combine(hash, static_cast<unsigned>(piece));
275+
// FIXME: Mix upper/lower 32-bit values together to produce
276+
// unsigned rather than truncating.
277+
return hash;
278+
}
279+
280+
static bool isEqual(const clang::api_notes::StoredObjCSelector &LHS,
281+
const clang::api_notes::StoredObjCSelector &RHS) {
282+
return LHS.NumPieces == RHS.NumPieces && LHS.Identifiers == RHS.Identifiers;
283+
}
284+
};
285+
} // namespace llvm
286+
255287
#endif

0 commit comments

Comments
 (0)