Skip to content

Commit 565e21b

Browse files
committed
[clang][NFC] Refactor InlineCommandComment::RenderKind
This patch converts `InlineCommandComment::RenderKind` to a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for e.g. annotating bit-fields with `preferred_type`.
1 parent 609fe2c commit 565e21b

File tree

7 files changed

+43
-53
lines changed

7 files changed

+43
-53
lines changed

clang/include/clang/AST/Comment.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,31 +297,24 @@ class TextComment : public InlineContentComment {
297297
bool isWhitespaceNoCache() const;
298298
};
299299

300+
/// The most appropriate rendering mode for this command, chosen on command
301+
/// semantics in Doxygen.
302+
enum InlineCommandRenderKind { Normal, Bold, Monospaced, Emphasized, Anchor };
303+
300304
/// A command with word-like arguments that is considered inline content.
301305
class InlineCommandComment : public InlineContentComment {
302-
public:
303-
/// The most appropriate rendering mode for this command, chosen on command
304-
/// semantics in Doxygen.
305-
enum RenderKind {
306-
RenderNormal,
307-
RenderBold,
308-
RenderMonospaced,
309-
RenderEmphasized,
310-
RenderAnchor
311-
};
312-
313306
protected:
314307
/// Command arguments.
315308
ArrayRef<Argument> Args;
316309

317310
public:
318311
InlineCommandComment(SourceLocation LocBegin, SourceLocation LocEnd,
319-
unsigned CommandID, RenderKind RK,
312+
unsigned CommandID, InlineCommandRenderKind RK,
320313
ArrayRef<Argument> Args)
321314
: InlineContentComment(CommentKind::InlineCommandComment, LocBegin,
322315
LocEnd),
323316
Args(Args) {
324-
InlineCommandCommentBits.RenderKind = RK;
317+
InlineCommandCommentBits.RenderKind = llvm::to_underlying(RK);
325318
InlineCommandCommentBits.CommandID = CommandID;
326319
}
327320

@@ -345,8 +338,9 @@ class InlineCommandComment : public InlineContentComment {
345338
return SourceRange(getBeginLoc().getLocWithOffset(-1), getEndLoc());
346339
}
347340

348-
RenderKind getRenderKind() const {
349-
return static_cast<RenderKind>(InlineCommandCommentBits.RenderKind);
341+
InlineCommandRenderKind getRenderKind() const {
342+
return static_cast<InlineCommandRenderKind>(
343+
InlineCommandCommentBits.RenderKind);
350344
}
351345

352346
unsigned getNumArgs() const {

clang/include/clang/AST/CommentSema.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ class Sema {
244244
StringRef Typo,
245245
const TemplateParameterList *TemplateParameters);
246246

247-
InlineCommandComment::RenderKind
248-
getInlineCommandRenderKind(StringRef Name) const;
247+
InlineCommandRenderKind getInlineCommandRenderKind(StringRef Name) const;
249248
};
250249

251250
} // end namespace comments

clang/lib/AST/CommentSema.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,7 @@ InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
380380
unsigned CommandID) {
381381
ArrayRef<InlineCommandComment::Argument> Args;
382382
return new (Allocator) InlineCommandComment(
383-
LocBegin, LocEnd, CommandID,
384-
InlineCommandComment::RenderNormal,
385-
Args);
383+
LocBegin, LocEnd, CommandID, InlineCommandRenderKind::Normal, Args);
386384
}
387385

388386
TextComment *Sema::actOnText(SourceLocation LocBegin,
@@ -1108,16 +1106,15 @@ StringRef Sema::correctTypoInTParamReference(
11081106
return StringRef();
11091107
}
11101108

1111-
InlineCommandComment::RenderKind
1112-
Sema::getInlineCommandRenderKind(StringRef Name) const {
1109+
InlineCommandRenderKind Sema::getInlineCommandRenderKind(StringRef Name) const {
11131110
assert(Traits.getCommandInfo(Name)->IsInlineCommand);
11141111

1115-
return llvm::StringSwitch<InlineCommandComment::RenderKind>(Name)
1116-
.Case("b", InlineCommandComment::RenderBold)
1117-
.Cases("c", "p", InlineCommandComment::RenderMonospaced)
1118-
.Cases("a", "e", "em", InlineCommandComment::RenderEmphasized)
1119-
.Case("anchor", InlineCommandComment::RenderAnchor)
1120-
.Default(InlineCommandComment::RenderNormal);
1112+
return llvm::StringSwitch<InlineCommandRenderKind>(Name)
1113+
.Case("b", InlineCommandRenderKind::Bold)
1114+
.Cases("c", "p", InlineCommandRenderKind::Monospaced)
1115+
.Cases("a", "e", "em", InlineCommandRenderKind::Emphasized)
1116+
.Case("anchor", InlineCommandRenderKind::Anchor)
1117+
.Default(InlineCommandRenderKind::Normal);
11211118
}
11221119

11231120
} // end namespace comments

clang/lib/AST/JSONNodeDumper.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,19 +1680,19 @@ void JSONNodeDumper::visitInlineCommandComment(
16801680
JOS.attribute("name", getCommentCommandName(C->getCommandID()));
16811681

16821682
switch (C->getRenderKind()) {
1683-
case comments::InlineCommandComment::RenderNormal:
1683+
case comments::InlineCommandRenderKind::Normal:
16841684
JOS.attribute("renderKind", "normal");
16851685
break;
1686-
case comments::InlineCommandComment::RenderBold:
1686+
case comments::InlineCommandRenderKind::Bold:
16871687
JOS.attribute("renderKind", "bold");
16881688
break;
1689-
case comments::InlineCommandComment::RenderEmphasized:
1689+
case comments::InlineCommandRenderKind::Emphasized:
16901690
JOS.attribute("renderKind", "emphasized");
16911691
break;
1692-
case comments::InlineCommandComment::RenderMonospaced:
1692+
case comments::InlineCommandRenderKind::Monospaced:
16931693
JOS.attribute("renderKind", "monospaced");
16941694
break;
1695-
case comments::InlineCommandComment::RenderAnchor:
1695+
case comments::InlineCommandRenderKind::Anchor:
16961696
JOS.attribute("renderKind", "anchor");
16971697
break;
16981698
}

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,19 +862,19 @@ void TextNodeDumper::visitInlineCommandComment(
862862
const comments::InlineCommandComment *C, const comments::FullComment *) {
863863
OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
864864
switch (C->getRenderKind()) {
865-
case comments::InlineCommandComment::RenderNormal:
865+
case comments::InlineCommandRenderKind::Normal:
866866
OS << " RenderNormal";
867867
break;
868-
case comments::InlineCommandComment::RenderBold:
868+
case comments::InlineCommandRenderKind::Bold:
869869
OS << " RenderBold";
870870
break;
871-
case comments::InlineCommandComment::RenderMonospaced:
871+
case comments::InlineCommandRenderKind::Monospaced:
872872
OS << " RenderMonospaced";
873873
break;
874-
case comments::InlineCommandComment::RenderEmphasized:
874+
case comments::InlineCommandRenderKind::Emphasized:
875875
OS << " RenderEmphasized";
876876
break;
877-
case comments::InlineCommandComment::RenderAnchor:
877+
case comments::InlineCommandRenderKind::Anchor:
878878
OS << " RenderAnchor";
879879
break;
880880
}

clang/lib/Index/CommentToXML.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,32 +274,32 @@ void CommentASTToHTMLConverter::visitInlineCommandComment(
274274
return;
275275

276276
switch (C->getRenderKind()) {
277-
case InlineCommandComment::RenderNormal:
277+
case InlineCommandRenderKind::Normal:
278278
for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) {
279279
appendToResultWithHTMLEscaping(C->getArgText(i));
280280
Result << " ";
281281
}
282282
return;
283283

284-
case InlineCommandComment::RenderBold:
284+
case InlineCommandRenderKind::Bold:
285285
assert(C->getNumArgs() == 1);
286286
Result << "<b>";
287287
appendToResultWithHTMLEscaping(Arg0);
288288
Result << "</b>";
289289
return;
290-
case InlineCommandComment::RenderMonospaced:
290+
case InlineCommandRenderKind::Monospaced:
291291
assert(C->getNumArgs() == 1);
292292
Result << "<tt>";
293293
appendToResultWithHTMLEscaping(Arg0);
294294
Result<< "</tt>";
295295
return;
296-
case InlineCommandComment::RenderEmphasized:
296+
case InlineCommandRenderKind::Emphasized:
297297
assert(C->getNumArgs() == 1);
298298
Result << "<em>";
299299
appendToResultWithHTMLEscaping(Arg0);
300300
Result << "</em>";
301301
return;
302-
case InlineCommandComment::RenderAnchor:
302+
case InlineCommandRenderKind::Anchor:
303303
assert(C->getNumArgs() == 1);
304304
Result << "<span id=\"" << Arg0 << "\"></span>";
305305
return;
@@ -623,31 +623,31 @@ void CommentASTToXMLConverter::visitInlineCommandComment(
623623
return;
624624

625625
switch (C->getRenderKind()) {
626-
case InlineCommandComment::RenderNormal:
626+
case InlineCommandRenderKind::Normal:
627627
for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) {
628628
appendToResultWithXMLEscaping(C->getArgText(i));
629629
Result << " ";
630630
}
631631
return;
632-
case InlineCommandComment::RenderBold:
632+
case InlineCommandRenderKind::Bold:
633633
assert(C->getNumArgs() == 1);
634634
Result << "<bold>";
635635
appendToResultWithXMLEscaping(Arg0);
636636
Result << "</bold>";
637637
return;
638-
case InlineCommandComment::RenderMonospaced:
638+
case InlineCommandRenderKind::Monospaced:
639639
assert(C->getNumArgs() == 1);
640640
Result << "<monospaced>";
641641
appendToResultWithXMLEscaping(Arg0);
642642
Result << "</monospaced>";
643643
return;
644-
case InlineCommandComment::RenderEmphasized:
644+
case InlineCommandRenderKind::Emphasized:
645645
assert(C->getNumArgs() == 1);
646646
Result << "<emphasized>";
647647
appendToResultWithXMLEscaping(Arg0);
648648
Result << "</emphasized>";
649649
return;
650-
case InlineCommandComment::RenderAnchor:
650+
case InlineCommandRenderKind::Anchor:
651651
assert(C->getNumArgs() == 1);
652652
Result << "<anchor id=\"" << Arg0 << "\"></anchor>";
653653
return;

clang/tools/libclang/CXComment.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,19 @@ clang_InlineCommandComment_getRenderKind(CXComment CXC) {
148148
return CXCommentInlineCommandRenderKind_Normal;
149149

150150
switch (ICC->getRenderKind()) {
151-
case InlineCommandComment::RenderNormal:
151+
case InlineCommandRenderKind::Normal:
152152
return CXCommentInlineCommandRenderKind_Normal;
153153

154-
case InlineCommandComment::RenderBold:
154+
case InlineCommandRenderKind::Bold:
155155
return CXCommentInlineCommandRenderKind_Bold;
156156

157-
case InlineCommandComment::RenderMonospaced:
157+
case InlineCommandRenderKind::Monospaced:
158158
return CXCommentInlineCommandRenderKind_Monospaced;
159159

160-
case InlineCommandComment::RenderEmphasized:
160+
case InlineCommandRenderKind::Emphasized:
161161
return CXCommentInlineCommandRenderKind_Emphasized;
162162

163-
case InlineCommandComment::RenderAnchor:
163+
case InlineCommandRenderKind::Anchor:
164164
return CXCommentInlineCommandRenderKind_Anchor;
165165
}
166166
llvm_unreachable("unknown InlineCommandComment::RenderKind");

0 commit comments

Comments
 (0)