[clang-tools-extra] [clang-doc][NFC] Fix style guide violations in HTMLGenerator.cpp (PR #96924)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 27 09:27:29 PDT 2024
https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/96924
This patch addresses several code style issues that conflict with the
project's style guide. Primarily the naming of functions, and `else`
after `return` statements. It only addresses issues found in
HTMLGenerator.cpp.
>From 57a0b31b9b3fed6df56c251609076a89e951ef92 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Thu, 27 Jun 2024 09:27:15 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
clang-tools-extra/clang-doc/HTMLGenerator.cpp | 101 +++++++++---------
1 file changed, 50 insertions(+), 51 deletions(-)
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c0faf5f7e8fd9..69d95256d7c14 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -55,7 +55,7 @@ class HTMLTag {
operator TagType() const { return Value; }
operator bool() = delete;
- bool IsSelfClosing() const;
+ bool isSelfClosing() const;
llvm::SmallString<16> ToString() const;
private:
@@ -71,7 +71,7 @@ struct HTMLNode {
HTMLNode(NodeType Type) : Type(Type) {}
virtual ~HTMLNode() = default;
- virtual void Render(llvm::raw_ostream &OS, int IndentationLevel) = 0;
+ virtual void render(llvm::raw_ostream &OS, int IndentationLevel) = 0;
NodeType Type; // Type of node
};
@@ -80,7 +80,7 @@ struct TextNode : public HTMLNode {
: HTMLNode(NodeType::NODE_TEXT), Text(Text.str()) {}
std::string Text; // Content of node
- void Render(llvm::raw_ostream &OS, int IndentationLevel) override;
+ void render(llvm::raw_ostream &OS, int IndentationLevel) override;
};
struct TagNode : public HTMLNode {
@@ -94,17 +94,17 @@ struct TagNode : public HTMLNode {
std::vector<std::pair<std::string, std::string>>
Attributes; // List of key-value attributes for tag
- void Render(llvm::raw_ostream &OS, int IndentationLevel) override;
+ void render(llvm::raw_ostream &OS, int IndentationLevel) override;
};
constexpr const char *kDoctypeDecl = "<!DOCTYPE html>";
struct HTMLFile {
std::vector<std::unique_ptr<HTMLNode>> Children; // List of child nodes
- void Render(llvm::raw_ostream &OS) {
+ void render(llvm::raw_ostream &OS) {
OS << kDoctypeDecl << "\n";
for (const auto &C : Children) {
- C->Render(OS, 0);
+ C->render(OS, 0);
OS << "\n";
}
}
@@ -112,7 +112,7 @@ struct HTMLFile {
} // namespace
-bool HTMLTag::IsSelfClosing() const {
+bool HTMLTag::isSelfClosing() const {
switch (Value) {
case HTMLTag::TAG_META:
case HTMLTag::TAG_LINK:
@@ -177,12 +177,12 @@ llvm::SmallString<16> HTMLTag::ToString() const {
llvm_unreachable("Unhandled HTMLTag::TagType");
}
-void TextNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {
+void TextNode::render(llvm::raw_ostream &OS, int IndentationLevel) {
OS.indent(IndentationLevel * 2);
printHTMLEscaped(Text, OS);
}
-void TagNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {
+void TagNode::render(llvm::raw_ostream &OS, int IndentationLevel) {
// Children nodes are rendered in the same line if all of them are text nodes
bool InlineChildren = true;
for (const auto &C : Children)
@@ -194,7 +194,7 @@ void TagNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {
OS << "<" << Tag.ToString();
for (const auto &A : Attributes)
OS << " " << A.first << "=\"" << A.second << "\"";
- if (Tag.IsSelfClosing()) {
+ if (Tag.isSelfClosing()) {
OS << "/>";
return;
}
@@ -205,7 +205,7 @@ void TagNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {
for (const auto &C : Children) {
int ChildrenIndentation =
InlineChildren || !NewLineRendered ? 0 : IndentationLevel + 1;
- C->Render(OS, ChildrenIndentation);
+ C->render(OS, ChildrenIndentation);
if (!InlineChildren && (C == Children.back() ||
(C->Type != NodeType::NODE_TEXT ||
(&C + 1)->get()->Type != NodeType::NODE_TEXT))) {
@@ -221,7 +221,7 @@ void TagNode::Render(llvm::raw_ostream &OS, int IndentationLevel) {
template <typename Derived, typename Base,
typename = std::enable_if<std::is_base_of<Derived, Base>::value>>
-static void AppendVector(std::vector<Derived> &&New,
+static void appendVector(std::vector<Derived> &&New,
std::vector<Base> &Original) {
std::move(New.begin(), New.end(), std::back_inserter(Original));
}
@@ -313,8 +313,7 @@ genReference(const Reference &Type, StringRef CurrentDirectory,
if (Type.Path.empty()) {
if (!JumpToSection)
return std::make_unique<TextNode>(Type.Name);
- else
- return genLink(Type.Name, "#" + *JumpToSection);
+ return genLink(Type.Name, "#" + *JumpToSection);
}
llvm::SmallString<64> Path = Type.getRelativeFilePath(CurrentDirectory);
llvm::sys::path::append(Path, Type.getFileBaseName() + ".html");
@@ -357,7 +356,7 @@ genEnumsBlock(const std::vector<EnumInfo> &Enums,
auto &DivBody = Out.back();
for (const auto &E : Enums) {
std::vector<std::unique_ptr<TagNode>> Nodes = genHTML(E, CDCtx);
- AppendVector(std::move(Nodes), DivBody->Children);
+ appendVector(std::move(Nodes), DivBody->Children);
}
return Out;
}
@@ -388,7 +387,7 @@ genFunctionsBlock(const std::vector<FunctionInfo> &Functions,
for (const auto &F : Functions) {
std::vector<std::unique_ptr<TagNode>> Nodes =
genHTML(F, CDCtx, ParentInfoDir);
- AppendVector(std::move(Nodes), DivBody->Children);
+ appendVector(std::move(Nodes), DivBody->Children);
}
return Out;
}
@@ -478,10 +477,10 @@ genFileHeadNodes(StringRef Title, StringRef InfoPath,
Out.emplace_back(std::make_unique<TagNode>(HTMLTag::TAG_TITLE, Title));
std::vector<std::unique_ptr<TagNode>> StylesheetsNodes =
genStylesheetsHTML(InfoPath, CDCtx);
- AppendVector(std::move(StylesheetsNodes), Out);
+ appendVector(std::move(StylesheetsNodes), Out);
std::vector<std::unique_ptr<TagNode>> JsNodes =
genJsScriptsHTML(InfoPath, CDCtx);
- AppendVector(std::move(JsNodes), Out);
+ appendVector(std::move(JsNodes), Out);
return Out;
}
@@ -513,7 +512,7 @@ static std::unique_ptr<TagNode> genInfoFileMainNode(
MainContentNode->Attributes.emplace_back("id", "main-content");
MainContentNode->Attributes.emplace_back(
"class", "col-xs-12 col-sm-9 col-md-8 main-content");
- AppendVector(std::move(MainContentInnerNodes), MainContentNode->Children);
+ appendVector(std::move(MainContentInnerNodes), MainContentNode->Children);
auto RightSidebarNode = std::make_unique<TagNode>(HTMLTag::TAG_DIV);
RightSidebarNode->Attributes.emplace_back("id", "sidebar-right");
@@ -521,7 +520,7 @@ static std::unique_ptr<TagNode> genInfoFileMainNode(
"class", "col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right");
std::vector<std::unique_ptr<TagNode>> InfoIndexHTML =
genHTML(InfoIndex, InfoPath, true);
- AppendVector(std::move(InfoIndexHTML), RightSidebarNode->Children);
+ appendVector(std::move(InfoIndexHTML), RightSidebarNode->Children);
MainNode->Children.emplace_back(std::move(LeftSidebarNode));
MainNode->Children.emplace_back(std::move(MainContentNode));
@@ -555,7 +554,7 @@ genInfoFile(StringRef Title, StringRef InfoPath,
genInfoFileMainNode(InfoPath, MainContentNodes, InfoIndex);
std::unique_ptr<TagNode> FooterNode = genFileFooterNode();
- AppendVector(std::move(HeadNodes), F.Children);
+ appendVector(std::move(HeadNodes), F.Children);
F.Children.emplace_back(std::move(HeaderNode));
F.Children.emplace_back(std::move(MainNode));
F.Children.emplace_back(std::move(FooterNode));
@@ -594,7 +593,7 @@ genHTML(const Index &Index, StringRef InfoPath, bool IsOutermostList) {
for (const auto &C : Index.Children) {
auto LiBody = std::make_unique<TagNode>(HTMLTag::TAG_LI);
std::vector<std::unique_ptr<TagNode>> Nodes = genHTML(C, InfoPath, false);
- AppendVector(std::move(Nodes), LiBody->Children);
+ appendVector(std::move(Nodes), LiBody->Children);
UlBody->Children.emplace_back(std::move(LiBody));
}
return Out;
@@ -609,7 +608,9 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo &I) {
FullComment->Children.emplace_back(std::move(Node));
}
return std::move(FullComment);
- } else if (I.Kind == "ParagraphComment") {
+ }
+
+ if (I.Kind == "ParagraphComment") {
auto ParagraphComment = std::make_unique<TagNode>(HTMLTag::TAG_P);
for (const auto &Child : I.Children) {
std::unique_ptr<HTMLNode> Node = genHTML(*Child);
@@ -619,7 +620,9 @@ static std::unique_ptr<HTMLNode> genHTML(const CommentInfo &I) {
if (ParagraphComment->Children.empty())
return nullptr;
return std::move(ParagraphComment);
- } else if (I.Kind == "TextComment") {
+ }
+
+ if (I.Kind == "TextComment") {
if (I.Text == "")
return nullptr;
return std::make_unique<TextNode>(I.Text);
@@ -639,11 +642,7 @@ static std::unique_ptr<TagNode> genHTML(const std::vector<CommentInfo> &C) {
static std::vector<std::unique_ptr<TagNode>>
genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
std::vector<std::unique_ptr<TagNode>> Out;
- std::string EnumType;
- if (I.Scoped)
- EnumType = "enum class ";
- else
- EnumType = "enum ";
+ std::string EnumType = I.Scoped ? "enum class " : "enum ";
Out.emplace_back(
std::make_unique<TagNode>(HTMLTag::TAG_H3, EnumType + I.Name));
@@ -737,17 +736,17 @@ genHTML(const NamespaceInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx,
std::vector<std::unique_ptr<TagNode>> ChildNamespaces =
genReferencesBlock(I.Children.Namespaces, "Namespaces", BasePath);
- AppendVector(std::move(ChildNamespaces), Out);
+ appendVector(std::move(ChildNamespaces), Out);
std::vector<std::unique_ptr<TagNode>> ChildRecords =
genReferencesBlock(I.Children.Records, "Records", BasePath);
- AppendVector(std::move(ChildRecords), Out);
+ appendVector(std::move(ChildRecords), Out);
std::vector<std::unique_ptr<TagNode>> ChildFunctions =
genFunctionsBlock(I.Children.Functions, CDCtx, BasePath);
- AppendVector(std::move(ChildFunctions), Out);
+ appendVector(std::move(ChildFunctions), Out);
std::vector<std::unique_ptr<TagNode>> ChildEnums =
genEnumsBlock(I.Children.Enums, CDCtx);
- AppendVector(std::move(ChildEnums), Out);
+ appendVector(std::move(ChildEnums), Out);
if (!I.Children.Namespaces.empty())
InfoIndex.Children.emplace_back("Namespaces", "Namespaces");
@@ -791,29 +790,29 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx,
auto &PBody = Out.back();
PBody->Children.emplace_back(std::make_unique<TextNode>("Inherits from "));
if (Parents.empty())
- AppendVector(std::move(VParents), PBody->Children);
+ appendVector(std::move(VParents), PBody->Children);
else if (VParents.empty())
- AppendVector(std::move(Parents), PBody->Children);
+ appendVector(std::move(Parents), PBody->Children);
else {
- AppendVector(std::move(Parents), PBody->Children);
+ appendVector(std::move(Parents), PBody->Children);
PBody->Children.emplace_back(std::make_unique<TextNode>(", "));
- AppendVector(std::move(VParents), PBody->Children);
+ appendVector(std::move(VParents), PBody->Children);
}
}
std::vector<std::unique_ptr<TagNode>> Members =
genRecordMembersBlock(I.Members, I.Path);
- AppendVector(std::move(Members), Out);
+ appendVector(std::move(Members), Out);
std::vector<std::unique_ptr<TagNode>> ChildRecords =
genReferencesBlock(I.Children.Records, "Records", I.Path);
- AppendVector(std::move(ChildRecords), Out);
+ appendVector(std::move(ChildRecords), Out);
std::vector<std::unique_ptr<TagNode>> ChildFunctions =
genFunctionsBlock(I.Children.Functions, CDCtx, I.Path);
- AppendVector(std::move(ChildFunctions), Out);
+ appendVector(std::move(ChildFunctions), Out);
std::vector<std::unique_ptr<TagNode>> ChildEnums =
genEnumsBlock(I.Children.Enums, CDCtx);
- AppendVector(std::move(ChildEnums), Out);
+ appendVector(std::move(ChildEnums), Out);
if (!I.Members.empty())
InfoIndex.Children.emplace_back("Members", "Members");
@@ -936,7 +935,7 @@ llvm::Error HTMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream &OS,
HTMLFile F = genInfoFile(InfoTitle, I->getRelativeFilePath(""),
MainContentNodes, InfoIndex, CDCtx);
- F.Render(OS);
+ F.render(OS);
return llvm::Error::success();
}
@@ -959,7 +958,7 @@ static std::string getRefType(InfoType IT) {
llvm_unreachable("Unknown InfoType");
}
-static llvm::Error SerializeIndex(ClangDocContext &CDCtx) {
+static llvm::Error serializeIndex(ClangDocContext &CDCtx) {
std::error_code OK;
std::error_code FileErr;
llvm::SmallString<128> FilePath;
@@ -1009,7 +1008,7 @@ static std::unique_ptr<TagNode> genIndexFileMainNode() {
return MainNode;
}
-static llvm::Error GenIndex(const ClangDocContext &CDCtx) {
+static llvm::Error genIndex(const ClangDocContext &CDCtx) {
std::error_code FileErr, OK;
llvm::SmallString<128> IndexPath;
llvm::sys::path::native(CDCtx.OutDirectory, IndexPath);
@@ -1029,17 +1028,17 @@ static llvm::Error GenIndex(const ClangDocContext &CDCtx) {
std::unique_ptr<TagNode> MainNode = genIndexFileMainNode();
std::unique_ptr<TagNode> FooterNode = genFileFooterNode();
- AppendVector(std::move(HeadNodes), F.Children);
+ appendVector(std::move(HeadNodes), F.Children);
F.Children.emplace_back(std::move(HeaderNode));
F.Children.emplace_back(std::move(MainNode));
F.Children.emplace_back(std::move(FooterNode));
- F.Render(IndexOS);
+ F.render(IndexOS);
return llvm::Error::success();
}
-static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) {
+static llvm::Error copyFile(StringRef FilePath, StringRef OutDirectory) {
llvm::SmallString<128> PathWrite;
llvm::sys::path::native(OutDirectory, PathWrite);
llvm::sys::path::append(PathWrite, llvm::sys::path::filename(FilePath));
@@ -1057,20 +1056,20 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) {
}
llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
- auto Err = SerializeIndex(CDCtx);
+ auto Err = serializeIndex(CDCtx);
if (Err)
return Err;
- Err = GenIndex(CDCtx);
+ Err = genIndex(CDCtx);
if (Err)
return Err;
for (const auto &FilePath : CDCtx.UserStylesheets) {
- Err = CopyFile(FilePath, CDCtx.OutDirectory);
+ Err = copyFile(FilePath, CDCtx.OutDirectory);
if (Err)
return Err;
}
for (const auto &FilePath : CDCtx.FilesToCopy) {
- Err = CopyFile(FilePath, CDCtx.OutDirectory);
+ Err = copyFile(FilePath, CDCtx.OutDirectory);
if (Err)
return Err;
}
More information about the cfe-commits
mailing list