10 #include "llvm/ADT/IndexedMap.h" 11 #include <initializer_list> 31 using AbbrevDsc = void (*)(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev);
33 static void AbbrevGen(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev,
34 const std::initializer_list<llvm::BitCodeAbbrevOp> Ops) {
35 for (
const auto &Op : Ops)
39 static void BoolAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev) {
42 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
46 static void IntAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev) {
49 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
56 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
59 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array),
60 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
64 static void StringAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev) {
67 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
70 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)});
78 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
81 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
84 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
87 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)});
96 : Name(Name), Abbrev(Abbrev) {}
99 operator bool()
const {
100 return Abbrev !=
nullptr && Name.data() !=
nullptr && !Name.empty();
104 static const llvm::IndexedMap<llvm::StringRef, BlockIdToIndexFunctor>
106 llvm::IndexedMap<llvm::StringRef, BlockIdToIndexFunctor>
BlockIdNameMap;
111 static const std::vector<std::pair<BlockId, const char *const>> Inits = {
124 for (
const auto &Init : Inits)
125 BlockIdNameMap[Init.first] = Init.second;
130 static const llvm::IndexedMap<RecordIdDsc, RecordIdToIndexFunctor>
137 static const std::vector<std::pair<RecordId, RecordIdDsc>> Inits = {
190 for (
const auto &Init : Inits) {
191 RecordIdNameMap[Init.first] = Init.second;
198 static const std::vector<std::pair<BlockId, std::vector<RecordId>>>
242 void ClangDocBitcodeWriter::AbbreviationMap::add(
RecordId RID,
245 assert(Abbrevs.find(RID) == Abbrevs.end() &&
"Abbreviation already added.");
246 Abbrevs[RID] = AbbrevID;
249 unsigned ClangDocBitcodeWriter::AbbreviationMap::get(
RecordId RID)
const {
251 assert(Abbrevs.find(RID) != Abbrevs.end() &&
"Unknown abbreviation.");
252 return Abbrevs.lookup(RID);
259 void ClangDocBitcodeWriter::emitHeader() {
260 for (
char C : BitCodeConstants::Signature)
264 void ClangDocBitcodeWriter::emitVersionBlock() {
270 void ClangDocBitcodeWriter::emitBlockID(
BlockId BID) {
272 assert(BlockIdName.data() && BlockIdName.size() &&
"Unknown BlockId.");
276 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID,
Record);
277 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME,
278 ArrayRef<unsigned char>(BlockIdName.bytes_begin(),
279 BlockIdName.bytes_end()));
283 void ClangDocBitcodeWriter::emitRecordID(
RecordId ID) {
288 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME,
Record);
295 auto Abbrev = std::make_shared<llvm::BitCodeAbbrev>();
296 Abbrev->Add(llvm::BitCodeAbbrevOp(ID));
298 Abbrevs.add(ID, Stream.EmitBlockInfoAbbrev(Block, std::move(Abbrev)));
306 "Abbrev type mismatch.");
307 if (!prepRecordData(ID, Sym != EmptySID))
309 assert(Sym.size() == 20);
310 Record.push_back(Sym.size());
311 Record.append(Sym.begin(), Sym.end());
312 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
315 void ClangDocBitcodeWriter::emitRecord(llvm::StringRef Str,
RecordId ID) {
318 "Abbrev type mismatch.");
319 if (!prepRecordData(ID, !Str.empty()))
322 Record.push_back(Str.size());
323 Stream.EmitRecordWithBlob(Abbrevs.get(ID),
Record, Str);
329 "Abbrev type mismatch.");
330 if (!prepRecordData(ID,
true))
340 void ClangDocBitcodeWriter::emitRecord(
bool Val,
RecordId ID) {
343 if (!prepRecordData(ID, Val))
346 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
349 void ClangDocBitcodeWriter::emitRecord(
int Val,
RecordId ID) {
352 if (!prepRecordData(ID, Val))
356 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
359 void ClangDocBitcodeWriter::emitRecord(
unsigned Val,
RecordId ID) {
362 if (!prepRecordData(ID, Val))
366 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
369 bool ClangDocBitcodeWriter::prepRecordData(
RecordId ID,
bool ShouldEmit) {
380 void ClangDocBitcodeWriter::emitBlockInfoBlock() {
381 Stream.EnterBlockInfoBlock();
384 emitBlockInfo(Block.first, Block.second);
389 void ClangDocBitcodeWriter::emitBlockInfo(
BlockId BID,
390 const std::vector<RecordId> &RIDs) {
395 emitAbbrev(RID, BID);
402 if (R.
USR == EmptySID && R.
Name.empty())
410 emitRecord((
unsigned)Field, REFERENCE_FIELD);
433 for (
const auto &L : std::vector<std::pair<llvm::StringRef, RecordId>>{
440 emitRecord(L.first, L.second);
447 for (
const auto &A : I.
Args)
482 for (
const auto &L : I.
Loc)
485 for (
const auto &N : I.
Members)
500 for (
const auto &L : I.
Loc)
504 for (
const auto &N : I.
Members)
506 for (
const auto &P : I.
Parents)
510 for (
const auto &PB : I.
Bases)
529 for (
const auto &M : I.
Members)
547 for (
const auto &L : I.
Loc)
551 for (
const auto &N : I.
Params)
558 emitBlock(*static_cast<clang::doc::NamespaceInfo *>(I));
561 emitBlock(*static_cast<clang::doc::RecordInfo *>(I));
564 emitBlock(*static_cast<clang::doc::EnumInfo *>(I));
567 emitBlock(*static_cast<clang::doc::FunctionInfo *>(I));
570 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)
std::vector< BaseRecordInfo > Bases
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
static constexpr unsigned char Signature[4]
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)
std::vector< FunctionInfo > ChildFunctions
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
std::vector< FunctionInfo > ChildFunctions
unsigned operator()(unsigned ID) const
std::vector< EnumInfo > ChildEnums
unsigned operator()(unsigned ID) const
static constexpr unsigned LineNumberSize
std::vector< Reference > ChildRecords
static void SymbolIDAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< FieldTypeInfo, 4 > Params
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
static constexpr llvm::StringLiteral Name
llvm::SmallString< 128 > Path
llvm::SmallVector< Reference, 4 > Parents
static const llvm::IndexedMap< llvm::StringRef, BlockIdToIndexFunctor > BlockIdNameMap
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< Reference > ChildNamespaces
static constexpr unsigned IntSize
static constexpr unsigned USRBitLengthSize
std::vector< Reference > ChildRecords
SmallString< 32 > Filename
std::vector< EnumInfo > ChildEnums
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
llvm::SmallString< 128 > Path
static constexpr unsigned RecordIdCount