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))
316 void ClangDocBitcodeWriter::emitRecord(
bool Val,
RecordId ID) {
319 if (!prepRecordData(ID, Val))
322 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
325 void ClangDocBitcodeWriter::emitRecord(
int Val,
RecordId ID) {
328 if (!prepRecordData(ID, Val))
332 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
335 void ClangDocBitcodeWriter::emitRecord(
unsigned Val,
RecordId ID) {
338 if (!prepRecordData(ID, Val))
342 Stream.EmitRecordWithAbbrev(Abbrevs.get(ID),
Record);
345 bool ClangDocBitcodeWriter::prepRecordData(
RecordId ID,
bool ShouldEmit) {
356 void ClangDocBitcodeWriter::emitBlockInfoBlock() {
357 Stream.EnterBlockInfoBlock();
360 emitBlockInfo(Block.first, Block.second);
365 void ClangDocBitcodeWriter::emitBlockInfo(
BlockId BID,
366 const std::vector<RecordId> &RIDs) {
371 emitAbbrev(RID, BID);
378 if (R.
USR == EmptySID && R.
Name.empty())
384 emitRecord((
unsigned)Field, REFERENCE_FIELD);
407 for (
const auto &L : std::vector<std::pair<llvm::StringRef, RecordId>>{
414 emitRecord(L.first, L.second);
421 for (
const auto &A : I.
Args)
455 for (
const auto &L : I.
Loc)
458 for (
const auto &N : I.
Members)
472 for (
const auto &L : I.
Loc)
475 for (
const auto &N : I.
Members)
477 for (
const auto &P : I.
Parents)
500 for (
const auto &L : I.
Loc)
504 for (
const auto &N : I.
Params)
511 emitBlock(*static_cast<clang::doc::NamespaceInfo *>(I));
514 emitBlock(*static_cast<clang::doc::RecordInfo *>(I));
517 emitBlock(*static_cast<clang::doc::EnumInfo *>(I));
520 emitBlock(*static_cast<clang::doc::FunctionInfo *>(I));
523 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)
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
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
static constexpr llvm::StringLiteral Name
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
static constexpr unsigned RecordIdCount