11 #include "llvm/ADT/IndexedMap.h" 12 #include <initializer_list> 32 using AbbrevDsc = void (*)(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev);
34 static void AbbrevGen(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev,
35 const std::initializer_list<llvm::BitCodeAbbrevOp> Ops) {
36 for (
const auto &Op : Ops)
40 static void BoolAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev) {
43 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
47 static void IntAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev) {
50 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
57 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
60 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array),
61 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
65 static void StringAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev) {
68 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
71 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)});
79 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
82 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
85 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)});
94 : Name(Name), Abbrev(Abbrev) {}
97 operator bool()
const {
98 return Abbrev !=
nullptr && Name.data() !=
nullptr && !Name.empty();
102 static const llvm::IndexedMap<llvm::StringRef, BlockIdToIndexFunctor>
104 llvm::IndexedMap<llvm::StringRef, BlockIdToIndexFunctor>
BlockIdNameMap;
109 static const std::vector<std::pair<BlockId, const char *const>> Inits = {
121 for (
const auto &Init : Inits)
122 BlockIdNameMap[Init.first] = Init.second;
127 static const llvm::IndexedMap<RecordIdDsc, RecordIdToIndexFunctor>
134 static const std::vector<std::pair<RecordId, RecordIdDsc>> Inits = {
174 for (
const auto &Init : Inits) {
175 RecordIdNameMap[Init.first] = Init.second;
182 static const std::vector<std::pair<BlockId, std::vector<RecordId>>>
219 void ClangDocBitcodeWriter::AbbreviationMap::add(
RecordId RID,
222 assert(Abbrevs.find(RID) == Abbrevs.end() &&
"Abbreviation already added.");
223 Abbrevs[RID] = AbbrevID;
226 unsigned ClangDocBitcodeWriter::AbbreviationMap::get(
RecordId RID)
const {
228 assert(Abbrevs.find(RID) != Abbrevs.end() &&
"Unknown abbreviation.");
229 return Abbrevs.lookup(RID);
236 void ClangDocBitcodeWriter::emitHeader() {
237 for (
char C : BitCodeConstants::Signature)
241 void ClangDocBitcodeWriter::emitVersionBlock() {
247 void ClangDocBitcodeWriter::emitBlockID(
BlockId BID) {
249 assert(BlockIdName.data() && BlockIdName.size() &&
"Unknown BlockId.");
253 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID,
Record);
254 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME,
255 ArrayRef<unsigned char>(BlockIdName.bytes_begin(),
256 BlockIdName.bytes_end()));
260 void ClangDocBitcodeWriter::emitRecordID(
RecordId ID) {
265 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME,
Record);
272 auto Abbrev = std::make_shared<llvm::BitCodeAbbrev>();
273 Abbrev->Add(llvm::BitCodeAbbrevOp(ID));
275 Abbrevs.add(ID, Stream.EmitBlockInfoAbbrev(Block, std::move(Abbrev)));
283 "Abbrev type mismatch.");
284 if (!prepRecordData(ID, Sym != EmptySID))
286 assert(Sym.size() == 20);
287 Record.push_back(Sym.size());
288 Record.append(Sym.begin(), Sym.end());
289 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
292 void ClangDocBitcodeWriter::emitRecord(llvm::StringRef Str,
RecordId ID) {
295 "Abbrev type mismatch.");
296 if (!prepRecordData(ID, !Str.empty()))
299 Record.push_back(Str.size());
300 Stream.EmitRecordWithBlob(Abbrevs.get(ID),
Record, Str);
306 "Abbrev type mismatch.");
307 if (!prepRecordData(ID,
true))
315 Stream.EmitRecordWithBlob(Abbrevs.get(ID),
Record,
"test");
318 void ClangDocBitcodeWriter::emitRecord(
bool Val,
RecordId ID) {
321 if (!prepRecordData(ID, Val))
324 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
327 void ClangDocBitcodeWriter::emitRecord(
int Val,
RecordId ID) {
330 if (!prepRecordData(ID, Val))
334 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
337 void ClangDocBitcodeWriter::emitRecord(
unsigned Val,
RecordId ID) {
340 if (!prepRecordData(ID, Val))
344 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
347 bool ClangDocBitcodeWriter::prepRecordData(
RecordId ID,
bool ShouldEmit) {
358 void ClangDocBitcodeWriter::emitBlockInfoBlock() {
359 Stream.EnterBlockInfoBlock();
362 emitBlockInfo(Block.first, Block.second);
367 void ClangDocBitcodeWriter::emitBlockInfo(
BlockId BID,
368 const std::vector<RecordId> &RIDs) {
373 emitAbbrev(RID, BID);
380 if (R.
USR == EmptySID && R.
Name.empty())
386 emitRecord((
unsigned)Field, REFERENCE_FIELD);
409 for (
const auto &L : std::vector<std::pair<llvm::StringRef, RecordId>>{
416 emitRecord(L.first, L.second);
423 for (
const auto &A : I.
Args)
431 emitRecord(I.
USR, NAMESPACE_USR);
432 emitRecord(I.
Name, NAMESPACE_NAME);
441 emitRecord(I.
USR, ENUM_USR);
442 emitRecord(I.
Name, ENUM_NAME);
449 for (
const auto &L : I.
Loc)
452 for (
const auto &N : I.
Members)
458 emitRecord(I.
USR, RECORD_USR);
459 emitRecord(I.
Name, RECORD_NAME);
466 for (
const auto &L : I.
Loc)
469 for (
const auto &N : I.
Members)
471 for (
const auto &P : I.
Parents)
479 emitRecord(I.
USR, FUNCTION_USR);
480 emitRecord(I.
Name, FUNCTION_NAME);
488 for (
const auto &L : I.
Loc)
492 for (
const auto &N : I.
Params)
499 emitBlock(*static_cast<clang::doc::NamespaceInfo *>(I));
502 emitBlock(*static_cast<clang::doc::RecordInfo *>(I));
505 emitBlock(*static_cast<clang::doc::EnumInfo *>(I));
508 emitBlock(*static_cast<clang::doc::FunctionInfo *>(I));
511 llvm::errs() <<
"Unexpected info, unable to write.\n";
SourceLocation Loc
'#' location in the include directive
static void StringAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
llvm::SmallVector< Reference, 4 > Namespace
static const SymbolID EmptySID
static void AbbrevGen(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev, const std::initializer_list< llvm::BitCodeAbbrevOp > Ops)
static constexpr unsigned SignatureBitSize
static const std::vector< std::pair< BlockId, std::vector< RecordId > > > RecordsByBlock
static const unsigned VersionNumber
static constexpr unsigned SubblockIDSize
static constexpr unsigned BlockIdCount
bool dispatchInfoForWrite(Info *I)
llvm::SmallVector< uint64_t, 1024 > Record
void emitBlock(const NamespaceInfo &I)
llvm::Optional< Location > DefLoc
RecordIdDsc(llvm::StringRef Name, AbbrevDsc Abbrev)
static constexpr unsigned BoolSize
llvm::SmallVector< Location, 2 > Loc
static void BoolAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
static const llvm::IndexedMap< RecordIdDsc, RecordIdToIndexFunctor > RecordIdNameMap
unsigned operator()(unsigned ID) const
unsigned operator()(unsigned ID) const
static constexpr unsigned LineNumberSize
static void SymbolIDAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< FieldTypeInfo, 4 > Params
static constexpr char Signature[4]
llvm::SmallVector< SmallString< 16 >, 4 > Members
static void IntAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
static constexpr unsigned RecordSize
std::vector< CommentInfo > Description
void(*)(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev) AbbrevDsc
llvm::SmallVector< Reference, 4 > Parents
static const llvm::IndexedMap< llvm::StringRef, BlockIdToIndexFunctor > BlockIdNameMap
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static constexpr unsigned IntSize
static constexpr unsigned USRBitLengthSize
SmallString< 32 > Filename
static constexpr unsigned USRLengthSize
static void LocationAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
llvm::SmallVector< MemberTypeInfo, 4 > Members
static constexpr unsigned StringLengthSize
std::array< uint8_t, 20 > SymbolID
static constexpr unsigned RecordIdCount