diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp b/clang-tools-extra/clang-doc/BitcodeWriter.cpp index 91d855e8527d4..cbd61b05c6e0a 100644 --- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp +++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp @@ -14,8 +14,7 @@ using namespace clang; using namespace clang::doc; using namespace llvm; -namespace clang { -namespace doc { +namespace { // Empty SymbolID for comparison, so we don't have to construct one every time. static const SymbolID EmptySID = SymbolID(); @@ -32,72 +31,68 @@ struct RecordIdToIndexFunctor { unsigned operator()(unsigned ID) const { return ID - RI_FIRST; } }; -using AbbrevDsc = void (*)(std::shared_ptr &Abbrev); +using AbbrevDsc = void (*)(std::shared_ptr &Abbrev); +} // namespace -static void -generateAbbrev(std::shared_ptr &Abbrev, - const std::initializer_list Ops) { +static void generateAbbrev(std::shared_ptr &Abbrev, + const std::initializer_list Ops) { for (const auto &Op : Ops) Abbrev->Add(Op); } -static void genBoolAbbrev(std::shared_ptr &Abbrev) { - generateAbbrev(Abbrev, - {// 0. Boolean - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, - BitCodeConstants::BoolSize)}); +static void genBoolAbbrev(std::shared_ptr &Abbrev) { + generateAbbrev( + Abbrev, + {// 0. Boolean + BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, BitCodeConstants::BoolSize)}); } -static void genIntAbbrev(std::shared_ptr &Abbrev) { - generateAbbrev(Abbrev, - {// 0. Fixed-size integer - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, - BitCodeConstants::IntSize)}); +static void genIntAbbrev(std::shared_ptr &Abbrev) { + generateAbbrev( + Abbrev, + {// 0. Fixed-size integer + BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, BitCodeConstants::IntSize)}); } -static void genSymbolIdAbbrev(std::shared_ptr &Abbrev) { - generateAbbrev(Abbrev, - {// 0. Fixed-size integer (length of the sha1'd USR) - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, - BitCodeConstants::USRLengthSize), - // 1. Fixed-size array of Char6 (USR) - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array), - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, - BitCodeConstants::USRBitLengthSize)}); +static void genSymbolIdAbbrev(std::shared_ptr &Abbrev) { + generateAbbrev( + Abbrev, + {// 0. Fixed-size integer (length of the sha1'd USR) + BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, BitCodeConstants::USRLengthSize), + // 1. Fixed-size array of Char6 (USR) + BitCodeAbbrevOp(BitCodeAbbrevOp::Array), + BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, + BitCodeConstants::USRBitLengthSize)}); } -static void genStringAbbrev(std::shared_ptr &Abbrev) { +static void genStringAbbrev(std::shared_ptr &Abbrev) { generateAbbrev(Abbrev, {// 0. Fixed-size integer (length of the following string) - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, - BitCodeConstants::StringLengthSize), + BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, + BitCodeConstants::StringLengthSize), // 1. The string blob - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)}); + BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)}); } // Assumes that the file will not have more than 65535 lines. -static void genLocationAbbrev(std::shared_ptr &Abbrev) { +static void genLocationAbbrev(std::shared_ptr &Abbrev) { generateAbbrev( Abbrev, {// 0. Fixed-size integer (line number) - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, - BitCodeConstants::LineNumberSize), + BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, + BitCodeConstants::LineNumberSize), // 1. Fixed-size integer (start line number) - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, - BitCodeConstants::LineNumberSize), + BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, + BitCodeConstants::LineNumberSize), // 2. Boolean (IsFileInRootDir) - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, - BitCodeConstants::BoolSize), + BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, BitCodeConstants::BoolSize), // 3. Fixed-size integer (length of the following string (filename)) - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed, - BitCodeConstants::StringLengthSize), + BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, + BitCodeConstants::StringLengthSize), // 4. The string blob - llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)}); + BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)}); } -} // namespace doc -} // namespace clang - namespace { struct RecordIdDsc { RecordIdDsc() = default; @@ -113,9 +108,9 @@ struct RecordIdDsc { AbbrevDsc Abbrev = nullptr; }; -static const llvm::IndexedMap - BlockIdNameMap = []() { - llvm::IndexedMap BlockIdNameMap; +static const IndexedMap BlockIdNameMap = + []() { + IndexedMap BlockIdNameMap; BlockIdNameMap.resize(BlockIdCount); // There is no init-list constructor for the IndexedMap, so have to @@ -149,9 +144,9 @@ static const llvm::IndexedMap return BlockIdNameMap; }(); -static const llvm::IndexedMap - RecordIdNameMap = []() { - llvm::IndexedMap RecordIdNameMap; +static const IndexedMap RecordIdNameMap = + []() { + IndexedMap RecordIdNameMap; RecordIdNameMap.resize(RecordIdCount); // There is no init-list constructor for the IndexedMap, so have to @@ -358,8 +353,8 @@ void ClangDocBitcodeWriter::emitBlockID(BlockId BID) { Record.clear(); Record.push_back(BID); - Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); - Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, + Stream.EmitRecord(bitc::BLOCKINFO_CODE_SETBID, Record); + Stream.EmitRecord(bitc::BLOCKINFO_CODE_BLOCKNAME, ArrayRef(BlockIdName.bytes_begin(), BlockIdName.bytes_end())); } @@ -370,15 +365,15 @@ void ClangDocBitcodeWriter::emitRecordID(RecordId ID) { prepRecordData(ID); Record.append(RecordIdNameMap[ID].Name.begin(), RecordIdNameMap[ID].Name.end()); - Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); + Stream.EmitRecord(bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); } // Abbreviations void ClangDocBitcodeWriter::emitAbbrev(RecordId ID, BlockId Block) { assert(RecordIdNameMap[ID] && "Unknown abbreviation."); - auto Abbrev = std::make_shared(); - Abbrev->Add(llvm::BitCodeAbbrevOp(ID)); + auto Abbrev = std::make_shared(); + Abbrev->Add(BitCodeAbbrevOp(ID)); RecordIdNameMap[ID].Abbrev(Abbrev); Abbrevs.add(ID, Stream.EmitBlockInfoAbbrev(Block, std::move(Abbrev))); } @@ -397,7 +392,7 @@ void ClangDocBitcodeWriter::emitRecord(const SymbolID &Sym, RecordId ID) { Stream.EmitRecordWithAbbrev(Abbrevs.get(ID), Record); } -void ClangDocBitcodeWriter::emitRecord(llvm::StringRef Str, RecordId ID) { +void ClangDocBitcodeWriter::emitRecord(StringRef Str, RecordId ID) { assert(RecordIdNameMap[ID] && "Unknown RecordId."); assert(RecordIdNameMap[ID].Abbrev == &genStringAbbrev && "Abbrev type mismatch."); @@ -565,7 +560,7 @@ void ClangDocBitcodeWriter::emitBlock(const CommentInfo &I) { StreamSubBlockGuard Block(Stream, BI_COMMENT_BLOCK_ID); // Handle Kind (enum) separately, since it is not a string. emitRecord(commentKindToString(I.Kind), COMMENT_KIND); - for (const auto &L : std::vector>{ + for (const auto &L : std::vector>{ {I.Text, COMMENT_TEXT}, {I.Name, COMMENT_NAME}, {I.Direction, COMMENT_DIRECTION}, @@ -773,22 +768,22 @@ void ClangDocBitcodeWriter::emitBlock(const VarInfo &I) { bool ClangDocBitcodeWriter::dispatchInfoForWrite(Info *I) { switch (I->IT) { case InfoType::IT_namespace: - emitBlock(*static_cast(I)); + emitBlock(*static_cast(I)); break; case InfoType::IT_record: - emitBlock(*static_cast(I)); + emitBlock(*static_cast(I)); break; case InfoType::IT_enum: - emitBlock(*static_cast(I)); + emitBlock(*static_cast(I)); break; case InfoType::IT_function: - emitBlock(*static_cast(I)); + emitBlock(*static_cast(I)); break; case InfoType::IT_typedef: - emitBlock(*static_cast(I)); + emitBlock(*static_cast(I)); break; case InfoType::IT_concept: - emitBlock(*static_cast(I)); + emitBlock(*static_cast(I)); break; case InfoType::IT_variable: emitBlock(*static_cast(I)); diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.h b/clang-tools-extra/clang-doc/BitcodeWriter.h index e3459850eab90..cbd8d833f1698 100644 --- a/clang-tools-extra/clang-doc/BitcodeWriter.h +++ b/clang-tools-extra/clang-doc/BitcodeWriter.h @@ -19,7 +19,6 @@ #include "clang/Basic/Diagnostic.h" #include "llvm/ADT/DenseMap.h" #include "llvm/Bitstream/BitstreamWriter.h" -#include namespace clang { namespace doc { @@ -225,8 +224,8 @@ class ClangDocBitcodeWriter { llvm::BitstreamWriter &Stream; public: - StreamSubBlockGuard(llvm::BitstreamWriter &Stream_, BlockId ID) - : Stream(Stream_) { + StreamSubBlockGuard(llvm::BitstreamWriter &Stream, BlockId ID) + : Stream(Stream) { // NOTE: SubBlockIDSize could theoretically be calculated on the fly, // based on the initialization list of records in each block. Stream.EnterSubblock(ID, BitCodeConstants::SubblockIDSize);