brettw created this revision. brettw added a reviewer: paulkirth. brettw added a project: clang-tools-extra. Herald added a project: All. brettw requested review of this revision. Herald added a subscriber: cfe-commits.
Provides an initializer for the TypedefInfo.IsUsing member. Previously this member was uninitialized and would produce random output. Adds the Description (code comments) to the bitcode reader/writer. Previously the typedef/using descriptions were lost during the bitcode round-trip. Adds a test for this. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D136638 Files: clang-tools-extra/clang-doc/BitcodeReader.cpp clang-tools-extra/clang-doc/BitcodeWriter.cpp clang-tools-extra/clang-doc/Representation.h clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp Index: clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp =================================================================== --- clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp +++ clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp @@ -183,6 +183,17 @@ I.Underlying = TypeInfo("unsigned"); I.IsUsing = true; + CommentInfo Top; + Top.Kind = "FullComment"; + + Top.Children.emplace_back(std::make_unique<CommentInfo>()); + CommentInfo *BlankLine = Top.Children.back().get(); + BlankLine->Kind = "ParagraphComment"; + BlankLine->Children.emplace_back(std::make_unique<CommentInfo>()); + BlankLine->Children.back()->Kind = "TextComment"; + + I.Description.emplace_back(std::move(Top)); + std::string WriteResult = writeInfo(&I); EXPECT_TRUE(WriteResult.size() > 0); std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1); Index: clang-tools-extra/clang-doc/Representation.h =================================================================== --- clang-tools-extra/clang-doc/Representation.h +++ clang-tools-extra/clang-doc/Representation.h @@ -365,7 +365,7 @@ // using MyVector = std::vector<int> // False means it's a C-style typedef: // typedef std::vector<int> MyVector; - bool IsUsing; + bool IsUsing = false; }; struct BaseRecordInfo : public RecordInfo { Index: clang-tools-extra/clang-doc/BitcodeWriter.cpp =================================================================== --- clang-tools-extra/clang-doc/BitcodeWriter.cpp +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp @@ -432,6 +432,8 @@ emitRecord(T.Name, TYPEDEF_NAME); for (const auto &N : T.Namespace) emitBlock(N, FieldId::F_namespace); + for (const auto &CI : T.Description) + emitBlock(CI); if (T.DefLoc) emitRecord(*T.DefLoc, TYPEDEF_DEFLOCATION); emitRecord(T.IsUsing, TYPEDEF_IS_USING); Index: clang-tools-extra/clang-doc/BitcodeReader.cpp =================================================================== --- clang-tools-extra/clang-doc/BitcodeReader.cpp +++ clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -392,6 +392,11 @@ return &I->Description.back(); } +template <> llvm::Expected<CommentInfo *> getCommentInfo(TypedefInfo *I) { + I->Description.emplace_back(); + return &I->Description.back(); +} + template <> llvm::Expected<CommentInfo *> getCommentInfo(CommentInfo *I) { I->Children.emplace_back(std::make_unique<CommentInfo>()); return I->Children.back().get();
Index: clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp =================================================================== --- clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp +++ clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp @@ -183,6 +183,17 @@ I.Underlying = TypeInfo("unsigned"); I.IsUsing = true; + CommentInfo Top; + Top.Kind = "FullComment"; + + Top.Children.emplace_back(std::make_unique<CommentInfo>()); + CommentInfo *BlankLine = Top.Children.back().get(); + BlankLine->Kind = "ParagraphComment"; + BlankLine->Children.emplace_back(std::make_unique<CommentInfo>()); + BlankLine->Children.back()->Kind = "TextComment"; + + I.Description.emplace_back(std::move(Top)); + std::string WriteResult = writeInfo(&I); EXPECT_TRUE(WriteResult.size() > 0); std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1); Index: clang-tools-extra/clang-doc/Representation.h =================================================================== --- clang-tools-extra/clang-doc/Representation.h +++ clang-tools-extra/clang-doc/Representation.h @@ -365,7 +365,7 @@ // using MyVector = std::vector<int> // False means it's a C-style typedef: // typedef std::vector<int> MyVector; - bool IsUsing; + bool IsUsing = false; }; struct BaseRecordInfo : public RecordInfo { Index: clang-tools-extra/clang-doc/BitcodeWriter.cpp =================================================================== --- clang-tools-extra/clang-doc/BitcodeWriter.cpp +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp @@ -432,6 +432,8 @@ emitRecord(T.Name, TYPEDEF_NAME); for (const auto &N : T.Namespace) emitBlock(N, FieldId::F_namespace); + for (const auto &CI : T.Description) + emitBlock(CI); if (T.DefLoc) emitRecord(*T.DefLoc, TYPEDEF_DEFLOCATION); emitRecord(T.IsUsing, TYPEDEF_IS_USING); Index: clang-tools-extra/clang-doc/BitcodeReader.cpp =================================================================== --- clang-tools-extra/clang-doc/BitcodeReader.cpp +++ clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -392,6 +392,11 @@ return &I->Description.back(); } +template <> llvm::Expected<CommentInfo *> getCommentInfo(TypedefInfo *I) { + I->Description.emplace_back(); + return &I->Description.back(); +} + template <> llvm::Expected<CommentInfo *> getCommentInfo(CommentInfo *I) { I->Children.emplace_back(std::make_unique<CommentInfo>()); return I->Children.back().get();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits