summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Wilson <brettw@google.com>2022-08-11 17:11:23 +0000
committerPaul Kirth <paulkirth@google.com>2022-08-11 17:14:15 +0000
commit99baa10f8f01f5c054d259182b24ae04ae57101d (patch)
tree4218bb7f7f696170fa6cdbd20c217e297126dc4e /clang-tools-extra/unittests
parent[RISCV] Move isValidCPUName to RISCVTargetInfo. NFC (diff)
downloadllvm-project-99baa10f8f01f5c054d259182b24ae04ae57101d.tar.gz
llvm-project-99baa10f8f01f5c054d259182b24ae04ae57101d.tar.bz2
llvm-project-99baa10f8f01f5c054d259182b24ae04ae57101d.zip
[clang-doc] Read docstrings for record members
Struct/class data members did not have the comments associated with them. This adds that information to the MemberTypeInfo class and emits it in the YAML. This does not update the frontends yet. Reviewed By: paulkirth Differential Revision: https://reviews.llvm.org/D131298
Diffstat (limited to 'clang-tools-extra/unittests')
-rw-r--r--clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp12
-rw-r--r--clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp30
-rw-r--r--clang-tools-extra/unittests/clang-doc/SerializeTest.cpp26
-rw-r--r--clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp21
4 files changed, 82 insertions, 7 deletions
diff --git a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
index ca51f14dfaff..784e85f98eeb 100644
--- a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -88,6 +88,18 @@ TEST(BitcodeTest, emitRecordInfoBitcode) {
I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+ // Documentation for the data member.
+ CommentInfo TopComment;
+ TopComment.Kind = "FullComment";
+ TopComment.Children.emplace_back(std::make_unique<CommentInfo>());
+ CommentInfo *Brief = TopComment.Children.back().get();
+ Brief->Kind = "ParagraphComment";
+ Brief->Children.emplace_back(std::make_unique<CommentInfo>());
+ Brief->Children.back()->Kind = "TextComment";
+ Brief->Children.back()->Name = "ParagraphComment";
+ Brief->Children.back()->Text = "Value of the thing.";
+ I.Bases.back().Members.back().Description.emplace_back(std::move(TopComment));
+
I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
I.ChildFunctions.emplace_back();
I.ChildEnums.emplace_back();
diff --git a/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp b/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
index f3b885f8b406..01816fb28ee6 100644
--- a/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
@@ -34,7 +34,12 @@ EnumInfo *InfoAsEnum(Info *I) {
return static_cast<EnumInfo *>(I);
}
-void CheckCommentInfo(CommentInfo &Expected, CommentInfo &Actual) {
+void CheckCommentInfo(const std::vector<CommentInfo> &Expected,
+ const std::vector<CommentInfo> &Actual);
+void CheckCommentInfo(const std::vector<std::unique_ptr<CommentInfo>> &Expected,
+ const std::vector<std::unique_ptr<CommentInfo>> &Actual);
+
+void CheckCommentInfo(const CommentInfo &Expected, const CommentInfo &Actual) {
EXPECT_EQ(Expected.Kind, Actual.Kind);
EXPECT_EQ(Expected.Text, Actual.Text);
EXPECT_EQ(Expected.Name, Actual.Name);
@@ -56,9 +61,21 @@ void CheckCommentInfo(CommentInfo &Expected, CommentInfo &Actual) {
for (size_t Idx = 0; Idx < Actual.Args.size(); ++Idx)
EXPECT_EQ(Expected.Args[Idx], Actual.Args[Idx]);
- ASSERT_EQ(Expected.Children.size(), Actual.Children.size());
- for (size_t Idx = 0; Idx < Actual.Children.size(); ++Idx)
- CheckCommentInfo(*Expected.Children[Idx], *Actual.Children[Idx]);
+ CheckCommentInfo(Expected.Children, Actual.Children);
+}
+
+void CheckCommentInfo(const std::vector<CommentInfo> &Expected,
+ const std::vector<CommentInfo> &Actual) {
+ ASSERT_EQ(Expected.size(), Actual.size());
+ for (size_t Idx = 0; Idx < Actual.size(); ++Idx)
+ CheckCommentInfo(Expected[Idx], Actual[Idx]);
+}
+
+void CheckCommentInfo(const std::vector<std::unique_ptr<CommentInfo>> &Expected,
+ const std::vector<std::unique_ptr<CommentInfo>> &Actual) {
+ ASSERT_EQ(Expected.size(), Actual.size());
+ for (size_t Idx = 0; Idx < Actual.size(); ++Idx)
+ CheckCommentInfo(*Expected[Idx], *Actual[Idx]);
}
void CheckReference(Reference &Expected, Reference &Actual) {
@@ -79,6 +96,7 @@ void CheckFieldTypeInfo(FieldTypeInfo *Expected, FieldTypeInfo *Actual) {
void CheckMemberTypeInfo(MemberTypeInfo *Expected, MemberTypeInfo *Actual) {
CheckFieldTypeInfo(Expected, Actual);
EXPECT_EQ(Expected->Access, Actual->Access);
+ CheckCommentInfo(Expected->Description, Actual->Description);
}
void CheckBaseInfo(Info *Expected, Info *Actual) {
@@ -88,9 +106,7 @@ void CheckBaseInfo(Info *Expected, Info *Actual) {
ASSERT_EQ(Expected->Namespace.size(), Actual->Namespace.size());
for (size_t Idx = 0; Idx < Actual->Namespace.size(); ++Idx)
CheckReference(Expected->Namespace[Idx], Actual->Namespace[Idx]);
- ASSERT_EQ(Expected->Description.size(), Actual->Description.size());
- for (size_t Idx = 0; Idx < Actual->Description.size(); ++Idx)
- CheckCommentInfo(Expected->Description[Idx], Actual->Description[Idx]);
+ CheckCommentInfo(Expected->Description, Actual->Description);
}
void CheckSymbolInfo(SymbolInfo *Expected, SymbolInfo *Actual) {
diff --git a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
index b846f0acf881..187ea39b7fe6 100644
--- a/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -80,6 +80,26 @@ void ExtractInfosFromCodeWithArgs(StringRef Code, size_t NumExpectedInfos,
ASSERT_EQ(NumExpectedInfos, EmittedInfos.size());
}
+// Constructs a comment definition as the parser would for one comment line.
+/* TODO uncomment this when the missing comment is fixed in emitRecordInfo and
+ the code that calls this is re-enabled.
+CommentInfo MakeOneLineCommentInfo(const std::string &Text) {
+ CommentInfo TopComment;
+ TopComment.Kind = "FullComment";
+ TopComment.Children.emplace_back(std::make_unique<CommentInfo>());
+
+ CommentInfo *Brief = TopComment.Children.back().get();
+ Brief->Kind = "ParagraphComment";
+
+ Brief->Children.emplace_back(std::make_unique<CommentInfo>());
+ Brief->Children.back()->Kind = "TextComment";
+ Brief->Children.back()->Name = "ParagraphComment";
+ Brief->Children.back()->Text = Text;
+
+ return TopComment;
+}
+*/
+
// Test serialization of namespace declarations.
TEST(SerializeTest, emitNamespaceInfo) {
EmittedInfoList Infos;
@@ -124,6 +144,9 @@ TEST(SerializeTest, emitRecordInfo) {
ExtractInfosFromCode(R"raw(class E {
public:
E() {}
+
+ // Some docs.
+ int value;
protected:
void ProtectedMethod();
};
@@ -142,6 +165,9 @@ typedef struct {} G;)raw",
InfoType::IT_namespace);
ExpectedE.TagType = TagTypeKind::TTK_Class;
ExpectedE.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+ ExpectedE.Members.emplace_back("int", "value", AccessSpecifier::AS_public);
+ // TODO the data member should have the docstring on it:
+ //ExpectedE.Members.back().Description.push_back(MakeOneLineCommentInfo(" Some docs"));
CheckRecordInfo(&ExpectedE, E);
RecordInfo *RecordWithEConstructor = InfoAsRecord(Infos[2].get());
diff --git a/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
index 8d116d8df8b9..b87b62bd9a4e 100644
--- a/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -83,6 +83,19 @@ TEST(YAMLGeneratorTest, emitRecordYAML) {
I.Members.emplace_back("int", "path/to/int", "X",
AccessSpecifier::AS_private);
+
+ // Member documentation.
+ CommentInfo TopComment;
+ TopComment.Kind = "FullComment";
+ TopComment.Children.emplace_back(std::make_unique<CommentInfo>());
+ CommentInfo *Brief = TopComment.Children.back().get();
+ Brief->Kind = "ParagraphComment";
+ Brief->Children.emplace_back(std::make_unique<CommentInfo>());
+ Brief->Children.back()->Kind = "TextComment";
+ Brief->Children.back()->Name = "ParagraphComment";
+ Brief->Children.back()->Text = "Value of the thing.";
+ I.Members.back().Description.push_back(std::move(TopComment));
+
I.TagType = TagTypeKind::TTK_Class;
I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
AccessSpecifier::AS_public, true);
@@ -129,6 +142,14 @@ Members:
Path: 'path/to/int'
Name: 'X'
Access: Private
+ Description:
+ - Kind: 'FullComment'
+ Children:
+ - Kind: 'ParagraphComment'
+ Children:
+ - Kind: 'TextComment'
+ Text: 'Value of the thing.'
+ Name: 'ParagraphComment'
Bases:
- USR: '0000000000000000000000000000000000000000'
Name: 'F'