https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/101108

>From 8d054ac3ada0e978fa1a663170090f033016edfe Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.c...@mail.utoronto.ca>
Date: Tue, 30 Jul 2024 17:48:24 -0400
Subject: [PATCH 1/6] [clang-doc] add support for block commands

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 17 +++-
 .../test/clang-doc/basic-project.test         | 92 +++++++++++++++----
 2 files changed, 89 insertions(+), 20 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index aef22453035c3..af626de8fbd02 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<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,
@@ -619,7 +620,7 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo 
&I) {
     }
     return std::move(FullComment);
   }
- 
+
   if (I.Kind == "ParagraphComment") {
     auto ParagraphComment = std::make_unique<TagNode>(HTMLTag::TAG_P);
     for (const auto &Child : I.Children) {
@@ -632,6 +633,20 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo 
&I) {
     return std::move(ParagraphComment);
   }
 
+  if (I.Kind == "BlockCommandComment") {
+    auto BlockComment = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
+    auto Command = std::make_unique<TagNode>(HTMLTag::TAG_DIV, I.Name);
+    BlockComment->Children.emplace_back(std::move(Command));
+    for (const auto &Child : I.Children) {
+      std::unique_ptr<HTMLNode> Node = genHTML(*Child);
+      if (Node)
+        BlockComment->Children.emplace_back(std::move(Node));
+    }
+    if (BlockComment->Children.empty())
+      return nullptr;
+    return std::move(BlockComment);
+  }
+
   if (I.Kind == "TextComment") {
     if (I.Text == "")
       return nullptr;
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index 38569d824f1f0..6f98d48001bdc 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -59,32 +59,63 @@
 
 // HTML-SHAPE: <h1>class Shape</h1>
 // HTML-SHAPE: <p>Defined at line 8 of file {{.*}}Shape.h</p>
+// HTML-SHAPE: <div>brief</div>
+// HTML-SHAPE: <p> Abstract base class for shapes.</p>
 // HTML-SHAPE: <p> Provides a common interface for different types of 
shapes.</p>
 // HTML-SHAPE: <h2 id="Functions">Functions</h2>
 // HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">~Shape</h3>
 // HTML-SHAPE: <p>public void ~Shape()</p>
 // HTML-SHAPE: <p>Defined at line 13 of file {{.*}}Shape.h</p>
+// HTML-SHAPE: <div>brief</div>
+// HTML-SHAPE: <p> Virtual destructor.</p>
 // HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
 // HTML-SHAPE: <p>public double area()</p>
+// HTML-SHAPE: <div>brief</div>
+// HTML-SHAPE: <p> Calculates the area of the shape.</p>
 // HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
 // HTML-SHAPE: <p>public double perimeter()</p>
+// HTML-SHAPE: <div>brief</div>
+// HTML-SHAPE: <p> Calculates the perimeter of the shape.</p>
+// HTML-SHAPE: <div>return</div>
+// HTML-SHAPE: <p> double The perimeter of the shape.</p>
 
-// HTML-CALC:  <h1>class Calculator</h1>
-// HTML-CALC:  <p>Defined at line 8 of file {{.*}}Calculator.h</p>
-// HTML-CALC:  <p> Provides basic arithmetic operations.</p>
-// HTML-CALC:  <h2 id="Functions">Functions</h2>
-// HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">add</h3>
-// HTML-CALC:  <p>public int add(int a, int b)</p>
-// HTML-CALC:  <p>Defined at line 3 of file {{.*}}Calculator.cpp</p>
-// HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
-// HTML-CALC:  <p>public int subtract(int a, int b)</p>
-// HTML-CALC:  <p>Defined at line 7 of file {{.*}}Calculator.cpp</p>
-// HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
-// HTML-CALC:  <p>public int multiply(int a, int b)</p>
-// HTML-CALC:  <p>Defined at line 11 of file {{.*}}Calculator.cpp</p>
-// HTML-CALC:  <h3 id="{{([0-9A-F]{40})}}">divide</h3>
-// HTML-CALC:  <p>public double divide(int a, int b)</p>
-// HTML-CALC:  <p>Defined at line 15 of file {{.*}}Calculator.cpp</p>
+
+// HTML-CALC: <h1>class Calculator</h1>
+// HTML-CALC: <p>Defined at line 8 of file {{.*}}Calculator.h</p>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> A simple calculator class.</p>
+// HTML-CALC: <p> Provides basic arithmetic operations.</p>
+// HTML-CALC: <h2 id="Functions">Functions</h2>
+// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">add</h3>
+// HTML-CALC: <p>public int add(int a, int b)</p>
+// HTML-CALC: <p>Defined at line 3 of file {{.*}}Calculator.cpp</p>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Adds two integers.</p>
+// HTML-CALC: <div>return</div>
+// HTML-CALC: <p> int The sum of a and b.</p>
+// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
+// HTML-CALC: <p>public int subtract(int a, int b)</p>
+// HTML-CALC: <p>Defined at line 7 of file {{.*}}Calculator.cpp</p>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Subtracts the second integer from the first.</p>
+// HTML-CALC: <div>return</div>
+// HTML-CALC: <p> int The result of a - b.</p>
+// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
+// HTML-CALC: <p>public int multiply(int a, int b)</p>
+// HTML-CALC: <p>Defined at line 11 of file {{.*}}Calculator.cpp</p>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Multiplies two integers.</p>
+// HTML-CALC: <div>return</div>
+// HTML-CALC: <p> int The product of a and b.</p>
+// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">divide</h3>
+// HTML-CALC: <p>public double divide(int a, int b)</p>
+// HTML-CALC: <p>Defined at line 15 of file {{.*}}Calculator.cpp</p>
+// HTML-CALC: <div>brief</div>
+// HTML-CALC: <p> Divides the first integer by the second.</p>
+// HTML-CALC: <div>return</div>
+// HTML-CALC: <p> double The result of a / b.</p>
+// HTML-CALC: <div>throw</div>
+// HTML-CALC: <p>if b is zero.</p>
 
 // HTML-RECTANGLE: <h1>class Rectangle</h1>
 // HTML-RECTANGLE: <p>Defined at line 10 of file {{.*}}Rectangle.h</p>
@@ -94,38 +125,61 @@
 // 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: <div>private double width_</div>
+// 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>
 // HTML-RECTANGLE: <p>Defined at line 3 of file {{.*}}Rectangle.cpp</p>
+// HTML-RECTANGLE: <div>brief</div>
+// HTML-RECTANGLE: <p> Constructs a new Rectangle object.</p>
 // HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
 // HTML-RECTANGLE: <p>public double area()</p>
 // HTML-RECTANGLE: <p>Defined at line 6 of file {{.*}}Rectangle.cpp</p>
+// HTML-RECTANGLE: <div>brief</div>
+// HTML-RECTANGLE: <p> Calculates the area of the rectangle.</p>
+// HTML-RECTANGLE: <div>return</div>
+// HTML-RECTANGLE: <p> double The area of the rectangle.</p>
 // HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
 // HTML-RECTANGLE: <p>public double perimeter()</p>
 // HTML-RECTANGLE: <p>Defined at line 10 of file {{.*}}Rectangle.cpp</p>
+// HTML-RECTANGLE: <div>brief</div>
+// HTML-RECTANGLE: <p> Calculates the perimeter of the rectangle.</p>
+// HTML-RECTANGLE: <div>return</div>
+// HTML-RECTANGLE: <p> double The perimeter of the rectangle.</p>
 
 // HTML-CIRCLE: <h1>class Circle</h1>
 // HTML-CIRCLE: <p>Defined at line 10 of file {{.*}}Circle.h</p>
+// HTML-CIRCLE: <div>brief</div>
+// HTML-CIRCLE: <p> Circle class derived from Shape.</p>
 // HTML-CIRCLE: <p> Represents a circle with a given radius.</p>
 // HTML-CIRCLE: <p>
 // HTML-CIRCLE:   Inherits from
 // 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>
 // HTML-CIRCLE: <p>Defined at line 3 of file {{.*}}Circle.cpp</p>
+// HTML-CIRCLE: <div>brief</div>
+// HTML-CIRCLE: <p> Constructs a new Circle object.</p>
 // HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
 // HTML-CIRCLE: <p>public double area()</p>
 // HTML-CIRCLE: <p>Defined at line 5 of file {{.*}}Circle.cpp</p>
+// HTML-CIRCLE: <div>brief</div>
+// HTML-CIRCLE: <p> Calculates the area of the circle.</p>
+// HTML-CIRCLE: <div>return</div>
+// HTML-CIRCLE: <p> double The area of the circle.</p>
 // HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
 // HTML-CIRCLE: <p>public double perimeter()</p>
 // HTML-CIRCLE: <p>Defined at line 9 of file {{.*}}Circle.cpp</p>
+// HTML-CIRCLE: <div>brief</div>
+// HTML-CIRCLE: <p> Calculates the perimeter of the circle.</p>
+// HTML-CIRCLE: <div>return</div>
+// HTML-CIRCLE: <p> double The perimeter of the circle.</p>
 
 // MD-CALC: # class Calculator
 // MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#8*

>From c3845b99281d43aa80ee0f91fc51e6641759f334 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.c...@mail.utoronto.ca>
Date: Tue, 30 Jul 2024 17:50:02 -0400
Subject: [PATCH 2/6] [clang-doc] modify test

---
 clang-tools-extra/test/clang-doc/basic-project.test | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index 6f98d48001bdc..c4675c00e2379 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -125,8 +125,8 @@
 // HTML-RECTANGLE:   <a href="Shape.html">Shape</a>
 // HTML-RECTANGLE: </p>
 // HTML-RECTANGLE: <h2 id="Members">Members</h2>
-// HTML-RECTANGLE: <div>private double width_</div>
-// HTML-RECTANGLE: <div>private double height_</div>
+// HTML-RECTANGLE: <li>private double width_</li>
+// HTML-RECTANGLE: <li>private double height_</li>
 // 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>

>From e4c3554f30958608db3928515d0ab5072e5380c6 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.c...@mail.utoronto.ca>
Date: Tue, 30 Jul 2024 17:52:52 -0400
Subject: [PATCH 3/6] [clang-doc] modify test

---
 clang-tools-extra/test/clang-doc/basic-project.test | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index c4675c00e2379..168c9f590612c 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -158,8 +158,7 @@
 // HTML-CIRCLE:   <a href="Shape.html">Shape</a>
 // HTML-CIRCLE: </p>
 // HTML-CIRCLE: <h2 id="Members">Members</h2>
-// HTML-CIRCLE: <p> Radius of the circle.</p>
-// HTML-CIRCLE: <div>private double radius_</div>
+// HTML-CIRCLE: <li>private double radius_</li>
 // 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>

>From eb865bdeb59ada6b8626df978c338b12ee7edbb8 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.c...@mail.utoronto.ca>
Date: Tue, 30 Jul 2024 17:55:00 -0400
Subject: [PATCH 4/6] [clang-doc] fix formatting

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index af626de8fbd02..c64f4795f87d1 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -620,7 +620,6 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo 
&I) {
     }
     return std::move(FullComment);
   }
-
   if (I.Kind == "ParagraphComment") {
     auto ParagraphComment = std::make_unique<TagNode>(HTMLTag::TAG_P);
     for (const auto &Child : I.Children) {
@@ -632,7 +631,6 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo 
&I) {
       return nullptr;
     return std::move(ParagraphComment);
   }
-
   if (I.Kind == "BlockCommandComment") {
     auto BlockComment = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
     auto Command = std::make_unique<TagNode>(HTMLTag::TAG_DIV, I.Name);
@@ -646,7 +644,6 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo 
&I) {
       return nullptr;
     return std::move(BlockComment);
   }
-
   if (I.Kind == "TextComment") {
     if (I.Text == "")
       return nullptr;

>From bb95de4d0b6d23e149709f82bcd970a749ebae64 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.c...@mail.utoronto.ca>
Date: Wed, 31 Jul 2024 00:19:50 -0400
Subject: [PATCH 5/6] [clang-doc] modify deleted newlines

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp             | 2 ++
 .../unittests/clang-doc/HTMLGeneratorTest.cpp             | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c64f4795f87d1..928f3d68f419c 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -620,6 +620,7 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo 
&I) {
     }
     return std::move(FullComment);
   }
+
   if (I.Kind == "ParagraphComment") {
     auto ParagraphComment = std::make_unique<TagNode>(HTMLTag::TAG_P);
     for (const auto &Child : I.Children) {
@@ -631,6 +632,7 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo 
&I) {
       return nullptr;
     return std::move(ParagraphComment);
   }
+
   if (I.Kind == "BlockCommandComment") {
     auto BlockComment = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
     auto Command = std::make_unique<TagNode>(HTMLTag::TAG_DIV, I.Name);
diff --git a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp 
b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
index e4a7340318b93..2475813e0700d 100644
--- a/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -92,7 +92,13 @@ TEST(HTMLGeneratorTest, emitNamespaceHTML) {
     </div>
     <h2 id="Enums">Enums</h2>
     <div>
-      <h3 id="0000000000000000000000000000000000000000">enum OneEnum</h3>
+      <table id=\"0000000000000000000000000000000000000000\">
+         <thead>
+           <tr>
+             <th colspan=\"2\">enum OneEnum</th>
+           </tr>
+         </thead>
+       </table>
     </div>
   </div>
   <div id="sidebar-right" class="col-xs-6 col-sm-6 col-md-2 sidebar 
sidebar-offcanvas-right">

>From 30d043f26ca53da2c008f9b720ec4a5a35cfd786 Mon Sep 17 00:00:00 2001
From: PeterChou1 <peter.c...@mail.utoronto.ca>
Date: Wed, 31 Jul 2024 12:11:21 -0400
Subject: [PATCH 6/6] [clang-doc] construct in place

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 928f3d68f419c..18ef146759e75 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -635,8 +635,8 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo 
&I) {
 
   if (I.Kind == "BlockCommandComment") {
     auto BlockComment = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
-    auto Command = std::make_unique<TagNode>(HTMLTag::TAG_DIV, I.Name);
-    BlockComment->Children.emplace_back(std::move(Command));
+    BlockComment->Children.emplace_back(
+        std::make_unique<TagNode>(HTMLTag::TAG_DIV, I.Name));
     for (const auto &Child : I.Children) {
       std::unique_ptr<HTMLNode> Node = genHTML(*Child);
       if (Node)

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to