Skip to content

Commit 8d054ac

Browse files
committed
[clang-doc] add support for block commands
1 parent 03e1eb2 commit 8d054ac

File tree

2 files changed

+89
-20
lines changed

2 files changed

+89
-20
lines changed

clang-tools-extra/clang-doc/HTMLGenerator.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx);
352352
static std::vector<std::unique_ptr<TagNode>>
353353
genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
354354
StringRef ParentInfoDir);
355+
static std::unique_ptr<TagNode> genHTML(const std::vector<CommentInfo> &C);
355356

356357
static std::vector<std::unique_ptr<TagNode>>
357358
genEnumsBlock(const std::vector<EnumInfo> &Enums,
@@ -619,7 +620,7 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo &I) {
619620
}
620621
return std::move(FullComment);
621622
}
622-
623+
623624
if (I.Kind == "ParagraphComment") {
624625
auto ParagraphComment = std::make_unique<TagNode>(HTMLTag::TAG_P);
625626
for (const auto &Child : I.Children) {
@@ -632,6 +633,20 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo &I) {
632633
return std::move(ParagraphComment);
633634
}
634635

636+
if (I.Kind == "BlockCommandComment") {
637+
auto BlockComment = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
638+
auto Command = std::make_unique<TagNode>(HTMLTag::TAG_DIV, I.Name);
639+
BlockComment->Children.emplace_back(std::move(Command));
640+
for (const auto &Child : I.Children) {
641+
std::unique_ptr<HTMLNode> Node = genHTML(*Child);
642+
if (Node)
643+
BlockComment->Children.emplace_back(std::move(Node));
644+
}
645+
if (BlockComment->Children.empty())
646+
return nullptr;
647+
return std::move(BlockComment);
648+
}
649+
635650
if (I.Kind == "TextComment") {
636651
if (I.Text == "")
637652
return nullptr;

clang-tools-extra/test/clang-doc/basic-project.test

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,63 @@
5959

6060
// HTML-SHAPE: <h1>class Shape</h1>
6161
// HTML-SHAPE: <p>Defined at line 8 of file {{.*}}Shape.h</p>
62+
// HTML-SHAPE: <div>brief</div>
63+
// HTML-SHAPE: <p> Abstract base class for shapes.</p>
6264
// HTML-SHAPE: <p> Provides a common interface for different types of shapes.</p>
6365
// HTML-SHAPE: <h2 id="Functions">Functions</h2>
6466
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">~Shape</h3>
6567
// HTML-SHAPE: <p>public void ~Shape()</p>
6668
// HTML-SHAPE: <p>Defined at line 13 of file {{.*}}Shape.h</p>
69+
// HTML-SHAPE: <div>brief</div>
70+
// HTML-SHAPE: <p> Virtual destructor.</p>
6771
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
6872
// HTML-SHAPE: <p>public double area()</p>
73+
// HTML-SHAPE: <div>brief</div>
74+
// HTML-SHAPE: <p> Calculates the area of the shape.</p>
6975
// HTML-SHAPE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
7076
// HTML-SHAPE: <p>public double perimeter()</p>
77+
// HTML-SHAPE: <div>brief</div>
78+
// HTML-SHAPE: <p> Calculates the perimeter of the shape.</p>
79+
// HTML-SHAPE: <div>return</div>
80+
// HTML-SHAPE: <p> double The perimeter of the shape.</p>
7181

72-
// HTML-CALC: <h1>class Calculator</h1>
73-
// HTML-CALC: <p>Defined at line 8 of file {{.*}}Calculator.h</p>
74-
// HTML-CALC: <p> Provides basic arithmetic operations.</p>
75-
// HTML-CALC: <h2 id="Functions">Functions</h2>
76-
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">add</h3>
77-
// HTML-CALC: <p>public int add(int a, int b)</p>
78-
// HTML-CALC: <p>Defined at line 3 of file {{.*}}Calculator.cpp</p>
79-
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
80-
// HTML-CALC: <p>public int subtract(int a, int b)</p>
81-
// HTML-CALC: <p>Defined at line 7 of file {{.*}}Calculator.cpp</p>
82-
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
83-
// HTML-CALC: <p>public int multiply(int a, int b)</p>
84-
// HTML-CALC: <p>Defined at line 11 of file {{.*}}Calculator.cpp</p>
85-
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">divide</h3>
86-
// HTML-CALC: <p>public double divide(int a, int b)</p>
87-
// HTML-CALC: <p>Defined at line 15 of file {{.*}}Calculator.cpp</p>
82+
83+
// HTML-CALC: <h1>class Calculator</h1>
84+
// HTML-CALC: <p>Defined at line 8 of file {{.*}}Calculator.h</p>
85+
// HTML-CALC: <div>brief</div>
86+
// HTML-CALC: <p> A simple calculator class.</p>
87+
// HTML-CALC: <p> Provides basic arithmetic operations.</p>
88+
// HTML-CALC: <h2 id="Functions">Functions</h2>
89+
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">add</h3>
90+
// HTML-CALC: <p>public int add(int a, int b)</p>
91+
// HTML-CALC: <p>Defined at line 3 of file {{.*}}Calculator.cpp</p>
92+
// HTML-CALC: <div>brief</div>
93+
// HTML-CALC: <p> Adds two integers.</p>
94+
// HTML-CALC: <div>return</div>
95+
// HTML-CALC: <p> int The sum of a and b.</p>
96+
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">subtract</h3>
97+
// HTML-CALC: <p>public int subtract(int a, int b)</p>
98+
// HTML-CALC: <p>Defined at line 7 of file {{.*}}Calculator.cpp</p>
99+
// HTML-CALC: <div>brief</div>
100+
// HTML-CALC: <p> Subtracts the second integer from the first.</p>
101+
// HTML-CALC: <div>return</div>
102+
// HTML-CALC: <p> int The result of a - b.</p>
103+
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">multiply</h3>
104+
// HTML-CALC: <p>public int multiply(int a, int b)</p>
105+
// HTML-CALC: <p>Defined at line 11 of file {{.*}}Calculator.cpp</p>
106+
// HTML-CALC: <div>brief</div>
107+
// HTML-CALC: <p> Multiplies two integers.</p>
108+
// HTML-CALC: <div>return</div>
109+
// HTML-CALC: <p> int The product of a and b.</p>
110+
// HTML-CALC: <h3 id="{{([0-9A-F]{40})}}">divide</h3>
111+
// HTML-CALC: <p>public double divide(int a, int b)</p>
112+
// HTML-CALC: <p>Defined at line 15 of file {{.*}}Calculator.cpp</p>
113+
// HTML-CALC: <div>brief</div>
114+
// HTML-CALC: <p> Divides the first integer by the second.</p>
115+
// HTML-CALC: <div>return</div>
116+
// HTML-CALC: <p> double The result of a / b.</p>
117+
// HTML-CALC: <div>throw</div>
118+
// HTML-CALC: <p>if b is zero.</p>
88119

89120
// HTML-RECTANGLE: <h1>class Rectangle</h1>
90121
// HTML-RECTANGLE: <p>Defined at line 10 of file {{.*}}Rectangle.h</p>
@@ -94,38 +125,61 @@
94125
// HTML-RECTANGLE: <a href="Shape.html">Shape</a>
95126
// HTML-RECTANGLE: </p>
96127
// HTML-RECTANGLE: <h2 id="Members">Members</h2>
97-
// HTML-RECTANGLE: <li>private double width_</li>
98-
// HTML-RECTANGLE: <li>private double height_</li>
128+
// HTML-RECTANGLE: <div>private double width_</div>
129+
// HTML-RECTANGLE: <div>private double height_</div>
99130
// HTML-RECTANGLE: <h2 id="Functions">Functions</h2>
100131
// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">Rectangle</h3>
101132
// HTML-RECTANGLE: <p>public void Rectangle(double width, double height)</p>
102133
// HTML-RECTANGLE: <p>Defined at line 3 of file {{.*}}Rectangle.cpp</p>
134+
// HTML-RECTANGLE: <div>brief</div>
135+
// HTML-RECTANGLE: <p> Constructs a new Rectangle object.</p>
103136
// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
104137
// HTML-RECTANGLE: <p>public double area()</p>
105138
// HTML-RECTANGLE: <p>Defined at line 6 of file {{.*}}Rectangle.cpp</p>
139+
// HTML-RECTANGLE: <div>brief</div>
140+
// HTML-RECTANGLE: <p> Calculates the area of the rectangle.</p>
141+
// HTML-RECTANGLE: <div>return</div>
142+
// HTML-RECTANGLE: <p> double The area of the rectangle.</p>
106143
// HTML-RECTANGLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
107144
// HTML-RECTANGLE: <p>public double perimeter()</p>
108145
// HTML-RECTANGLE: <p>Defined at line 10 of file {{.*}}Rectangle.cpp</p>
146+
// HTML-RECTANGLE: <div>brief</div>
147+
// HTML-RECTANGLE: <p> Calculates the perimeter of the rectangle.</p>
148+
// HTML-RECTANGLE: <div>return</div>
149+
// HTML-RECTANGLE: <p> double The perimeter of the rectangle.</p>
109150

110151
// HTML-CIRCLE: <h1>class Circle</h1>
111152
// HTML-CIRCLE: <p>Defined at line 10 of file {{.*}}Circle.h</p>
153+
// HTML-CIRCLE: <div>brief</div>
154+
// HTML-CIRCLE: <p> Circle class derived from Shape.</p>
112155
// HTML-CIRCLE: <p> Represents a circle with a given radius.</p>
113156
// HTML-CIRCLE: <p>
114157
// HTML-CIRCLE: Inherits from
115158
// HTML-CIRCLE: <a href="Shape.html">Shape</a>
116159
// HTML-CIRCLE: </p>
117160
// HTML-CIRCLE: <h2 id="Members">Members</h2>
118-
// HTML-CIRCLE: <li>private double radius_</li>
161+
// HTML-CIRCLE: <p> Radius of the circle.</p>
162+
// HTML-CIRCLE: <div>private double radius_</div>
119163
// HTML-CIRCLE: <h2 id="Functions">Functions</h2>
120164
// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">Circle</h3>
121165
// HTML-CIRCLE: <p>public void Circle(double radius)</p>
122166
// HTML-CIRCLE: <p>Defined at line 3 of file {{.*}}Circle.cpp</p>
167+
// HTML-CIRCLE: <div>brief</div>
168+
// HTML-CIRCLE: <p> Constructs a new Circle object.</p>
123169
// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">area</h3>
124170
// HTML-CIRCLE: <p>public double area()</p>
125171
// HTML-CIRCLE: <p>Defined at line 5 of file {{.*}}Circle.cpp</p>
172+
// HTML-CIRCLE: <div>brief</div>
173+
// HTML-CIRCLE: <p> Calculates the area of the circle.</p>
174+
// HTML-CIRCLE: <div>return</div>
175+
// HTML-CIRCLE: <p> double The area of the circle.</p>
126176
// HTML-CIRCLE: <h3 id="{{([0-9A-F]{40})}}">perimeter</h3>
127177
// HTML-CIRCLE: <p>public double perimeter()</p>
128178
// HTML-CIRCLE: <p>Defined at line 9 of file {{.*}}Circle.cpp</p>
179+
// HTML-CIRCLE: <div>brief</div>
180+
// HTML-CIRCLE: <p> Calculates the perimeter of the circle.</p>
181+
// HTML-CIRCLE: <div>return</div>
182+
// HTML-CIRCLE: <p> double The perimeter of the circle.</p>
129183

130184
// MD-CALC: # class Calculator
131185
// MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#8*

0 commit comments

Comments
 (0)