From b4bc7b182c696c540f40bc887d7d20a95a0a5cde Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Mon, 12 Aug 2024 15:08:30 -0400 Subject: [PATCH] [clang-doc] add support for comments for members in HTML output (#101255) currently the HTML output does not support comments attached to class members, this patch modifies the HTMLGenerator to add comments for the output. --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 11 ++++++++--- clang-tools-extra/test/clang-doc/basic-project.test | 9 ++++++--- .../unittests/clang-doc/HTMLGeneratorTest.cpp | 4 +++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index aef22453035c30..21ee417da6028a 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -352,6 +352,7 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx); static std::vector> genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx, StringRef ParentInfoDir); +static std::unique_ptr genHTML(const std::vector &C); static std::vector> genEnumsBlock(const std::vector &Enums, @@ -418,9 +419,13 @@ genRecordMembersBlock(const llvm::SmallVector &Members, if (Access != "") Access = Access + " "; auto LIBody = std::make_unique(HTMLTag::TAG_LI); - LIBody->Children.emplace_back(std::make_unique(Access)); - LIBody->Children.emplace_back(genReference(M.Type, ParentInfoDir)); - LIBody->Children.emplace_back(std::make_unique(" " + M.Name)); + auto MemberDecl = std::make_unique(HTMLTag::TAG_DIV); + MemberDecl->Children.emplace_back(std::make_unique(Access)); + MemberDecl->Children.emplace_back(genReference(M.Type, ParentInfoDir)); + MemberDecl->Children.emplace_back(std::make_unique(" " + 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 c2c7548f5a9690..2865ed4446e7ef 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.test +++ b/clang-tools-extra/test/clang-doc/basic-project.test @@ -91,8 +91,10 @@ // HTML-RECTANGLE: Shape // HTML-RECTANGLE:

// HTML-RECTANGLE:

Members

-// HTML-RECTANGLE:
  • private double width_
  • -// HTML-RECTANGLE:
  • private double height_
  • +// HTML-RECTANGLE:

    Width of the rectangle.

    +// HTML-RECTANGLE:
    private double width_
    +// HTML-RECTANGLE:

    Height of the rectangle.

    +// HTML-RECTANGLE:
    private double height_
    // HTML-RECTANGLE:

    Functions

    // HTML-RECTANGLE:

    Rectangle

    // HTML-RECTANGLE:

    public void Rectangle(double width, double height)

    @@ -112,7 +114,8 @@ // HTML-CIRCLE: Shape // HTML-CIRCLE:

    // HTML-CIRCLE:

    Members

    -// HTML-CIRCLE:
  • private double radius_
  • +// HTML-CIRCLE:

    Radius of the circle.

    +// HTML-CIRCLE:
    private double radius_
    // HTML-CIRCLE:

    Functions

    // HTML-CIRCLE:

    Circle

    // HTML-CIRCLE:

    public void Circle(double radius)

    diff --git a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp index e4a7340318b934..bd031282b042ab 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) {

    Members

      -
    • private int X
    • +
    • +
      private int X
      +

    Records