-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-doc] add support for comments for members in HTML output #101255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
PeterChou1
merged 2 commits into
llvm:main
from
PeterChou1:clang-doc-add-comment-to-members
Aug 12, 2024
Merged
[clang-doc] add support for comments for members in HTML output #101255
PeterChou1
merged 2 commits into
llvm:main
from
PeterChou1:clang-doc-add-comment-to-members
Aug 12, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang-tools-extra Author: None (PeterChou1) Changescurrently the HTML output does not support comments attached to class members, this patch modifies the HTMLGenerator to add comments for the output. Full diff: https://github.com/llvm/llvm-project/pull/101255.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index aef22453035c3..4383d0250f05d 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -352,6 +352,8 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx);
static std::vector<std::unique_ptr<TagNode>>
genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
StringRef ParentInfoDir);
+static std::unique_ptr<TagNode>
+genHTML(const std::vector<CommentInfo> &C);
static std::vector<std::unique_ptr<TagNode>>
genEnumsBlock(const std::vector<EnumInfo> &Enums,
@@ -418,9 +420,13 @@ genRecordMembersBlock(const llvm::SmallVector<MemberTypeInfo, 4> &Members,
if (Access != "")
Access = Access + " ";
auto LIBody = std::make_unique<TagNode>(HTMLTag::TAG_LI);
- LIBody->Children.emplace_back(std::make_unique<TextNode>(Access));
- LIBody->Children.emplace_back(genReference(M.Type, ParentInfoDir));
- LIBody->Children.emplace_back(std::make_unique<TextNode>(" " + M.Name));
+ auto MemberDecl = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
+ MemberDecl->Children.emplace_back(std::make_unique<TextNode>(Access));
+ MemberDecl->Children.emplace_back(genReference(M.Type, ParentInfoDir));
+ MemberDecl->Children.emplace_back(std::make_unique<TextNode>(" " + M.Name));
+ if (!M.Description.empty())
+ LIBody->Children.emplace_back(genHTML(M.Description));
+ LIBody->Children.emplace_back(std::move(MemberDecl));
ULBody->Children.emplace_back(std::move(LIBody));
}
return Out;
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test b/clang-tools-extra/test/clang-doc/basic-project.test
index 38569d824f1f0..dac18899fad74 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -94,8 +94,10 @@
// HTML-RECTANGLE: <a href="Shape.html">Shape</a>
// HTML-RECTANGLE: </p>
// HTML-RECTANGLE: <h2 id="Members">Members</h2>
-// HTML-RECTANGLE: <li>private double width_</li>
-// HTML-RECTANGLE: <li>private double height_</li>
+// HTML-RECTANGLE: <p> Width of the rectangle.</p>
+// HTML-RECTANGLE: <div>private double width_</div>
+// HTML-RECTANGLE: <p> Height of the rectangle.</p>
+// HTML-RECTANGLE: <div>private double height_</div>
// HTML-RECTANGLE: <h2 id="Functions">Functions</h2>
// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">Rectangle</h3>
// HTML-RECTANGLE: <p>public void Rectangle(double width, double height)</p>
@@ -115,7 +117,8 @@
// HTML-CIRCLE: <a href="Shape.html">Shape</a>
// HTML-CIRCLE: </p>
// HTML-CIRCLE: <h2 id="Members">Members</h2>
-// HTML-CIRCLE: <li>private double radius_</li>
+// HTML-CIRCLE: <p> Radius of the circle.</p>
+// HTML-CIRCLE: <div>private double radius_</div>
// HTML-CIRCLE: <h2 id="Functions">Functions</h2>
// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
// HTML-CIRCLE: <p>public void Circle(double radius)</p>
diff --git a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
index e4a7340318b93..bd031282b042a 100644
--- a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -197,7 +197,9 @@ TEST(HTMLGeneratorTest, emitRecordHTML) {
</p>
<h2 id="Members">Members</h2>
<ul>
- <li>private int X</li>
+ <li>
+ <div>private int X</div>
+ </li>
</ul>
<h2 id="Records">Records</h2>
<ul>
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
ilovepi
approved these changes
Aug 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
currently the HTML output does not support comments attached to class members, this patch modifies the HTMLGenerator to add comments for the output.