10#include "llvm/ADT/IndexedMap.h"
11#include <initializer_list>
31using AbbrevDsc = void (*)(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev);
33static void AbbrevGen(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev,
34 const std::initializer_list<llvm::BitCodeAbbrevOp> Ops) {
35 for (
const auto &Op : Ops)
39static void BoolAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev) {
42 llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
46static 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,
64static 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)});
99 operator bool()
const {
100 return Abbrev !=
nullptr &&
Name.data() !=
nullptr && !
Name.empty();
104static 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 = {
129 for (
const auto &Init : Inits)
135static const llvm::IndexedMap<RecordIdDsc, RecordIdToIndexFunctor>
142 static const std::vector<std::pair<RecordId, RecordIdDsc>> Inits = {
203 for (
const auto &Init : Inits) {
211static const std::vector<std::pair<BlockId, std::vector<RecordId>>>
264void ClangDocBitcodeWriter::AbbreviationMap::add(
RecordId RID,
267 assert(!Abbrevs.contains(RID) &&
"Abbreviation already added.");
268 Abbrevs[RID] = AbbrevID;
271unsigned ClangDocBitcodeWriter::AbbreviationMap::get(
RecordId RID)
const {
273 assert(Abbrevs.contains(RID) &&
"Unknown abbreviation.");
274 return Abbrevs.lookup(RID);
281void ClangDocBitcodeWriter::emitHeader() {
286void ClangDocBitcodeWriter::emitVersionBlock() {
292void ClangDocBitcodeWriter::emitBlockID(
BlockId BID) {
294 assert(BlockIdName.data() && BlockIdName.size() &&
"Unknown BlockId.");
297 Record.push_back(BID);
298 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
299 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME,
300 ArrayRef<unsigned char>(BlockIdName.bytes_begin(),
301 BlockIdName.bytes_end()));
305void ClangDocBitcodeWriter::emitRecordID(
RecordId ID) {
310 Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record);
317 auto Abbrev = std::make_shared<llvm::BitCodeAbbrev>();
318 Abbrev->Add(llvm::BitCodeAbbrevOp(
ID));
320 Abbrevs.add(
ID, Stream.EmitBlockInfoAbbrev(Block, std::move(Abbrev)));
328 "Abbrev type mismatch.");
331 assert(Sym.size() == 20);
332 Record.push_back(Sym.size());
333 Record.append(Sym.begin(), Sym.end());
334 Stream.EmitRecordWithAbbrev(Abbrevs.get(
ID), Record);
337void ClangDocBitcodeWriter::emitRecord(llvm::StringRef Str,
RecordId ID) {
340 "Abbrev type mismatch.");
341 if (!prepRecordData(
ID, !Str.empty()))
344 Record.push_back(Str.size());
345 Stream.EmitRecordWithBlob(Abbrevs.get(
ID), Record, Str);
351 "Abbrev type mismatch.");
352 if (!prepRecordData(
ID,
true))
355 Record.push_back(
Loc.LineNumber);
357 Record.push_back(
Loc.IsFileInRootDir);
358 Record.push_back(
Loc.Filename.size());
359 Stream.EmitRecordWithBlob(Abbrevs.get(
ID), Record,
Loc.Filename);
362void ClangDocBitcodeWriter::emitRecord(
bool Val,
RecordId ID) {
365 if (!prepRecordData(
ID, Val))
367 Record.push_back(Val);
368 Stream.EmitRecordWithAbbrev(Abbrevs.get(
ID), Record);
371void ClangDocBitcodeWriter::emitRecord(
int Val,
RecordId ID) {
374 if (!prepRecordData(
ID, Val))
377 Record.push_back(Val);
378 Stream.EmitRecordWithAbbrev(Abbrevs.get(
ID), Record);
381void ClangDocBitcodeWriter::emitRecord(
unsigned Val,
RecordId ID) {
384 if (!prepRecordData(
ID, Val))
387 Record.push_back(Val);
388 Stream.EmitRecordWithAbbrev(Abbrevs.get(
ID), Record);
391void ClangDocBitcodeWriter::emitRecord(
const TemplateInfo &Templ) {}
393bool ClangDocBitcodeWriter::prepRecordData(
RecordId ID,
bool ShouldEmit) {
398 Record.push_back(
ID);
404void ClangDocBitcodeWriter::emitBlockInfoBlock() {
405 Stream.EnterBlockInfoBlock();
408 emitBlockInfo(Block.first, Block.second);
413void ClangDocBitcodeWriter::emitBlockInfo(
BlockId BID,
414 const std::vector<RecordId> &RIDs) {
419 emitAbbrev(RID, BID);
446 for (
const auto &N : T.Namespace)
448 for (
const auto &
CI : T.Description)
468 for (
const auto &
CI : T.Description)
474 for (
const auto &L : std::vector<std::pair<llvm::StringRef, RecordId>>{
481 emitRecord(L.first, L.second);
488 for (
const auto &A : I.
Args)
525 for (
const auto &L : I.
Loc)
530 for (
const auto &N : I.
Members)
554 for (
const auto &L : I.
Loc)
558 for (
const auto &N : I.
Members)
560 for (
const auto &P : I.
Parents)
564 for (
const auto &PB : I.
Bases)
605 for (
const auto &L : I.
Loc)
609 for (
const auto &N : I.
Params)
617 for (
const auto &P : T.Params)
619 if (T.Specialization)
626 for (
const auto &P : T.Params)
653 llvm::errs() <<
"Unexpected info, unable to write.\n";
llvm::SmallString< 256U > Name
const google::protobuf::Message & M
std::unique_ptr< CompilerInvocation > CI
void emitBlock(const NamespaceInfo &I)
bool dispatchInfoForWrite(Info *I)
static const llvm::IndexedMap< RecordIdDsc, RecordIdToIndexFunctor > RecordIdNameMap
static void SymbolIDAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
static const llvm::IndexedMap< llvm::StringRef, BlockIdToIndexFunctor > BlockIdNameMap
@ TEMPLATE_SPECIALIZATION_OF
@ TEMPLATE_PARAM_CONTENTS
static void AbbrevGen(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev, const std::initializer_list< llvm::BitCodeAbbrevOp > Ops)
static constexpr unsigned BlockIdCount
static const std::vector< std::pair< BlockId, std::vector< RecordId > > > RecordsByBlock
static const unsigned VersionNumber
static void StringAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
static constexpr unsigned RecordIdCount
static void LocationAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
static void IntAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
std::array< uint8_t, 20 > SymbolID
static void BoolAbbrev(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev)
void(*)(std::shared_ptr< llvm::BitCodeAbbrev > &Abbrev) AbbrevDsc
@ BI_TEMPLATE_SPECIALIZATION_BLOCK_ID
@ BI_TEMPLATE_PARAM_BLOCK_ID
@ BI_MEMBER_TYPE_BLOCK_ID
@ BI_BASE_RECORD_BLOCK_ID
static const SymbolID EmptySID
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static constexpr unsigned BoolSize
static constexpr unsigned LineNumberSize
static constexpr unsigned char Signature[4]
static constexpr unsigned RecordSize
static constexpr unsigned StringLengthSize
static constexpr unsigned USRBitLengthSize
static constexpr unsigned IntSize
static constexpr unsigned SignatureBitSize
static constexpr unsigned SubblockIDSize
static constexpr unsigned USRLengthSize
unsigned operator()(unsigned ID) const
llvm::SmallVector< EnumValueInfo, 4 > Members
std::optional< TypeInfo > BaseType
std::vector< CommentInfo > Description
SmallString< 16 > ValueExpr
llvm::SmallVector< FieldTypeInfo, 4 > Params
std::optional< TemplateInfo > Template
std::vector< CommentInfo > Description
llvm::SmallString< 128 > Path
llvm::SmallVector< Reference, 4 > Namespace
RecordIdDsc(llvm::StringRef Name, AbbrevDsc Abbrev)
unsigned operator()(unsigned ID) const
llvm::SmallVector< MemberTypeInfo, 4 > Members
std::optional< TemplateInfo > Template
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< Reference, 4 > Parents
std::vector< BaseRecordInfo > Bases
SmallString< 16 > QualName
llvm::SmallString< 128 > Path
std::vector< Reference > Records
std::vector< TypedefInfo > Typedefs
std::vector< FunctionInfo > Functions
std::vector< Reference > Namespaces
std::vector< EnumInfo > Enums
llvm::SmallVector< Location, 2 > Loc
std::optional< Location > DefLoc