[clang] 565e21b - [clang][NFC] Refactor `InlineCommandComment::RenderKind`
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 6 11:39:34 PST 2023
Author: Vlad Serebrennikov
Date: 2023-11-06T22:39:26+03:00
New Revision: 565e21b3e079e53c4fcf47d2ec898dbc248fbd3a
URL: https://github.com/llvm/llvm-project/commit/565e21b3e079e53c4fcf47d2ec898dbc248fbd3a
DIFF: https://github.com/llvm/llvm-project/commit/565e21b3e079e53c4fcf47d2ec898dbc248fbd3a.diff
LOG: [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`.
Added:
Modified:
clang/include/clang/AST/Comment.h
clang/include/clang/AST/CommentSema.h
clang/lib/AST/CommentSema.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Index/CommentToXML.cpp
clang/tools/libclang/CXComment.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h
index 7cbed3600d28287..06effad42db45e6 100644
--- a/clang/include/clang/AST/Comment.h
+++ b/clang/include/clang/AST/Comment.h
@@ -297,31 +297,24 @@ class TextComment : public InlineContentComment {
bool isWhitespaceNoCache() const;
};
+/// The most appropriate rendering mode for this command, chosen on command
+/// semantics in Doxygen.
+enum InlineCommandRenderKind { Normal, Bold, Monospaced, Emphasized, Anchor };
+
/// A command with word-like arguments that is considered inline content.
class InlineCommandComment : public InlineContentComment {
-public:
- /// The most appropriate rendering mode for this command, chosen on command
- /// semantics in Doxygen.
- enum RenderKind {
- RenderNormal,
- RenderBold,
- RenderMonospaced,
- RenderEmphasized,
- RenderAnchor
- };
-
protected:
/// Command arguments.
ArrayRef<Argument> Args;
public:
InlineCommandComment(SourceLocation LocBegin, SourceLocation LocEnd,
- unsigned CommandID, RenderKind RK,
+ unsigned CommandID, InlineCommandRenderKind RK,
ArrayRef<Argument> Args)
: InlineContentComment(CommentKind::InlineCommandComment, LocBegin,
LocEnd),
Args(Args) {
- InlineCommandCommentBits.RenderKind = RK;
+ InlineCommandCommentBits.RenderKind = llvm::to_underlying(RK);
InlineCommandCommentBits.CommandID = CommandID;
}
@@ -345,8 +338,9 @@ class InlineCommandComment : public InlineContentComment {
return SourceRange(getBeginLoc().getLocWithOffset(-1), getEndLoc());
}
- RenderKind getRenderKind() const {
- return static_cast<RenderKind>(InlineCommandCommentBits.RenderKind);
+ InlineCommandRenderKind getRenderKind() const {
+ return static_cast<InlineCommandRenderKind>(
+ InlineCommandCommentBits.RenderKind);
}
unsigned getNumArgs() const {
diff --git a/clang/include/clang/AST/CommentSema.h b/clang/include/clang/AST/CommentSema.h
index 5d8df7dbf385a12..03f13283ac0d977 100644
--- a/clang/include/clang/AST/CommentSema.h
+++ b/clang/include/clang/AST/CommentSema.h
@@ -244,8 +244,7 @@ class Sema {
StringRef Typo,
const TemplateParameterList *TemplateParameters);
- InlineCommandComment::RenderKind
- getInlineCommandRenderKind(StringRef Name) const;
+ InlineCommandRenderKind getInlineCommandRenderKind(StringRef Name) const;
};
} // end namespace comments
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index 66660512d6af5ce..6f68577954137f3 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -380,9 +380,7 @@ InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
unsigned CommandID) {
ArrayRef<InlineCommandComment::Argument> Args;
return new (Allocator) InlineCommandComment(
- LocBegin, LocEnd, CommandID,
- InlineCommandComment::RenderNormal,
- Args);
+ LocBegin, LocEnd, CommandID, InlineCommandRenderKind::Normal, Args);
}
TextComment *Sema::actOnText(SourceLocation LocBegin,
@@ -1108,16 +1106,15 @@ StringRef Sema::correctTypoInTParamReference(
return StringRef();
}
-InlineCommandComment::RenderKind
-Sema::getInlineCommandRenderKind(StringRef Name) const {
+InlineCommandRenderKind Sema::getInlineCommandRenderKind(StringRef Name) const {
assert(Traits.getCommandInfo(Name)->IsInlineCommand);
- return llvm::StringSwitch<InlineCommandComment::RenderKind>(Name)
- .Case("b", InlineCommandComment::RenderBold)
- .Cases("c", "p", InlineCommandComment::RenderMonospaced)
- .Cases("a", "e", "em", InlineCommandComment::RenderEmphasized)
- .Case("anchor", InlineCommandComment::RenderAnchor)
- .Default(InlineCommandComment::RenderNormal);
+ return llvm::StringSwitch<InlineCommandRenderKind>(Name)
+ .Case("b", InlineCommandRenderKind::Bold)
+ .Cases("c", "p", InlineCommandRenderKind::Monospaced)
+ .Cases("a", "e", "em", InlineCommandRenderKind::Emphasized)
+ .Case("anchor", InlineCommandRenderKind::Anchor)
+ .Default(InlineCommandRenderKind::Normal);
}
} // end namespace comments
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index bc7bc7337b15e92..cfcf27ecddebbc4 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -1680,19 +1680,19 @@ void JSONNodeDumper::visitInlineCommandComment(
JOS.attribute("name", getCommentCommandName(C->getCommandID()));
switch (C->getRenderKind()) {
- case comments::InlineCommandComment::RenderNormal:
+ case comments::InlineCommandRenderKind::Normal:
JOS.attribute("renderKind", "normal");
break;
- case comments::InlineCommandComment::RenderBold:
+ case comments::InlineCommandRenderKind::Bold:
JOS.attribute("renderKind", "bold");
break;
- case comments::InlineCommandComment::RenderEmphasized:
+ case comments::InlineCommandRenderKind::Emphasized:
JOS.attribute("renderKind", "emphasized");
break;
- case comments::InlineCommandComment::RenderMonospaced:
+ case comments::InlineCommandRenderKind::Monospaced:
JOS.attribute("renderKind", "monospaced");
break;
- case comments::InlineCommandComment::RenderAnchor:
+ case comments::InlineCommandRenderKind::Anchor:
JOS.attribute("renderKind", "anchor");
break;
}
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 8d0f421e3a7dbc9..e8274fcd5cfe9cb 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -862,19 +862,19 @@ void TextNodeDumper::visitInlineCommandComment(
const comments::InlineCommandComment *C, const comments::FullComment *) {
OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
switch (C->getRenderKind()) {
- case comments::InlineCommandComment::RenderNormal:
+ case comments::InlineCommandRenderKind::Normal:
OS << " RenderNormal";
break;
- case comments::InlineCommandComment::RenderBold:
+ case comments::InlineCommandRenderKind::Bold:
OS << " RenderBold";
break;
- case comments::InlineCommandComment::RenderMonospaced:
+ case comments::InlineCommandRenderKind::Monospaced:
OS << " RenderMonospaced";
break;
- case comments::InlineCommandComment::RenderEmphasized:
+ case comments::InlineCommandRenderKind::Emphasized:
OS << " RenderEmphasized";
break;
- case comments::InlineCommandComment::RenderAnchor:
+ case comments::InlineCommandRenderKind::Anchor:
OS << " RenderAnchor";
break;
}
diff --git a/clang/lib/Index/CommentToXML.cpp b/clang/lib/Index/CommentToXML.cpp
index ddd3498f92718e7..e7f5bfebec2334c 100644
--- a/clang/lib/Index/CommentToXML.cpp
+++ b/clang/lib/Index/CommentToXML.cpp
@@ -274,32 +274,32 @@ void CommentASTToHTMLConverter::visitInlineCommandComment(
return;
switch (C->getRenderKind()) {
- case InlineCommandComment::RenderNormal:
+ case InlineCommandRenderKind::Normal:
for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) {
appendToResultWithHTMLEscaping(C->getArgText(i));
Result << " ";
}
return;
- case InlineCommandComment::RenderBold:
+ case InlineCommandRenderKind::Bold:
assert(C->getNumArgs() == 1);
Result << "<b>";
appendToResultWithHTMLEscaping(Arg0);
Result << "</b>";
return;
- case InlineCommandComment::RenderMonospaced:
+ case InlineCommandRenderKind::Monospaced:
assert(C->getNumArgs() == 1);
Result << "<tt>";
appendToResultWithHTMLEscaping(Arg0);
Result<< "</tt>";
return;
- case InlineCommandComment::RenderEmphasized:
+ case InlineCommandRenderKind::Emphasized:
assert(C->getNumArgs() == 1);
Result << "<em>";
appendToResultWithHTMLEscaping(Arg0);
Result << "</em>";
return;
- case InlineCommandComment::RenderAnchor:
+ case InlineCommandRenderKind::Anchor:
assert(C->getNumArgs() == 1);
Result << "<span id=\"" << Arg0 << "\"></span>";
return;
@@ -623,31 +623,31 @@ void CommentASTToXMLConverter::visitInlineCommandComment(
return;
switch (C->getRenderKind()) {
- case InlineCommandComment::RenderNormal:
+ case InlineCommandRenderKind::Normal:
for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) {
appendToResultWithXMLEscaping(C->getArgText(i));
Result << " ";
}
return;
- case InlineCommandComment::RenderBold:
+ case InlineCommandRenderKind::Bold:
assert(C->getNumArgs() == 1);
Result << "<bold>";
appendToResultWithXMLEscaping(Arg0);
Result << "</bold>";
return;
- case InlineCommandComment::RenderMonospaced:
+ case InlineCommandRenderKind::Monospaced:
assert(C->getNumArgs() == 1);
Result << "<monospaced>";
appendToResultWithXMLEscaping(Arg0);
Result << "</monospaced>";
return;
- case InlineCommandComment::RenderEmphasized:
+ case InlineCommandRenderKind::Emphasized:
assert(C->getNumArgs() == 1);
Result << "<emphasized>";
appendToResultWithXMLEscaping(Arg0);
Result << "</emphasized>";
return;
- case InlineCommandComment::RenderAnchor:
+ case InlineCommandRenderKind::Anchor:
assert(C->getNumArgs() == 1);
Result << "<anchor id=\"" << Arg0 << "\"></anchor>";
return;
diff --git a/clang/tools/libclang/CXComment.cpp b/clang/tools/libclang/CXComment.cpp
index 79b42ae0c00120f..5abbf9c1161a1b7 100644
--- a/clang/tools/libclang/CXComment.cpp
+++ b/clang/tools/libclang/CXComment.cpp
@@ -148,19 +148,19 @@ clang_InlineCommandComment_getRenderKind(CXComment CXC) {
return CXCommentInlineCommandRenderKind_Normal;
switch (ICC->getRenderKind()) {
- case InlineCommandComment::RenderNormal:
+ case InlineCommandRenderKind::Normal:
return CXCommentInlineCommandRenderKind_Normal;
- case InlineCommandComment::RenderBold:
+ case InlineCommandRenderKind::Bold:
return CXCommentInlineCommandRenderKind_Bold;
- case InlineCommandComment::RenderMonospaced:
+ case InlineCommandRenderKind::Monospaced:
return CXCommentInlineCommandRenderKind_Monospaced;
- case InlineCommandComment::RenderEmphasized:
+ case InlineCommandRenderKind::Emphasized:
return CXCommentInlineCommandRenderKind_Emphasized;
- case InlineCommandComment::RenderAnchor:
+ case InlineCommandRenderKind::Anchor:
return CXCommentInlineCommandRenderKind_Anchor;
}
llvm_unreachable("unknown InlineCommandComment::RenderKind");
More information about the cfe-commits
mailing list