[clang-tools-extra] [clang-doc] add support for enums in html generation (PR #101282)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 30 20:59:35 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 03e1eb29e7169ddb0804b1d0b9d71d6d2aaf531d 4c7623635dee6acac9b732808934efd884cfecbf --extensions h,cpp -- clang-tools-extra/clang-doc/BitcodeReader.cpp clang-tools-extra/clang-doc/BitcodeWriter.cpp clang-tools-extra/clang-doc/HTMLGenerator.cpp clang-tools-extra/clang-doc/Representation.cpp clang-tools-extra/clang-doc/Representation.h clang-tools-extra/clang-doc/Serialize.cpp clang-tools-extra/test/clang-doc/enum.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index b65fc2a1c6..1f2fb0a8b2 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -429,7 +429,6 @@ llvm::Expected<CommentInfo *> getCommentInfo(std::unique_ptr<CommentInfo> &I) {
   return getCommentInfo(I.get());
 }
 
-
 // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on
 // the parent block to set it. The template specializations define what to do
 // for each supported parent block.
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index c2cc3fe612..a37192d6ce 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -377,7 +377,7 @@ 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,
               const ClangDocContext &CDCtx) {
@@ -403,26 +403,26 @@ genEnumMembersBlock(const llvm::SmallVector<EnumValueInfo, 4> &Members,
     return nullptr;
 
   auto List = std::make_unique<TagNode>(HTMLTag::TAG_TBODY);
-  
+
   for (const auto &M : Members) {
-        auto TRNode = std::make_unique<TagNode>(HTMLTag::TAG_TR);
-        TRNode->Children.emplace_back(
-            std::make_unique<TagNode>(HTMLTag::TAG_TD, M.Name));
-        // Use user supplied value if it exists, otherwise use the value
-        if (!M.ValueExpr.empty()) {
-          TRNode->Children.emplace_back(
+    auto TRNode = std::make_unique<TagNode>(HTMLTag::TAG_TR);
+    TRNode->Children.emplace_back(
+        std::make_unique<TagNode>(HTMLTag::TAG_TD, M.Name));
+    // Use user supplied value if it exists, otherwise use the value
+    if (!M.ValueExpr.empty()) {
+      TRNode->Children.emplace_back(
           std::make_unique<TagNode>(HTMLTag::TAG_TD, M.ValueExpr));
-        } else {
-          TRNode->Children.emplace_back(
-                std::make_unique<TagNode>(HTMLTag::TAG_TD, M.Value));
-        }
-        
-        if (HasComments) {
-           auto TD = std::make_unique<TagNode>(HTMLTag::TAG_TD);
-           TD->Children.emplace_back(genHTML(M.Description));
-           TRNode->Children.emplace_back(std::move(TD));
-        }
-        List->Children.emplace_back(std::move(TRNode));
+    } else {
+      TRNode->Children.emplace_back(
+          std::make_unique<TagNode>(HTMLTag::TAG_TD, M.Value));
+    }
+
+    if (HasComments) {
+      auto TD = std::make_unique<TagNode>(HTMLTag::TAG_TD);
+      TD->Children.emplace_back(genHTML(M.Description));
+      TRNode->Children.emplace_back(std::move(TD));
+    }
+    List->Children.emplace_back(std::move(TRNode));
   }
   return List;
 }
@@ -705,30 +705,28 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
       break;
     }
   }
-  std::unique_ptr<TagNode> Table = 
+  std::unique_ptr<TagNode> Table =
       std::make_unique<TagNode>(HTMLTag::TAG_TABLE);
-  std::unique_ptr<TagNode> Thead = 
+  std::unique_ptr<TagNode> Thead =
       std::make_unique<TagNode>(HTMLTag::TAG_THEAD);
-  std::unique_ptr<TagNode> TRow =
-      std::make_unique<TagNode>(HTMLTag::TAG_TR);
-  std::unique_ptr<TagNode> TD = 
+  std::unique_ptr<TagNode> TRow = std::make_unique<TagNode>(HTMLTag::TAG_TR);
+  std::unique_ptr<TagNode> TD =
       std::make_unique<TagNode>(HTMLTag::TAG_TH, EnumType + I.Name);
   // Span 3 columns if enum has comments
   TD->Attributes.emplace_back("colspan", HasComments ? "3" : "2");
-  
-  Table->Attributes.emplace_back("id",
-                                 llvm::toHex(llvm::toStringRef(I.USR)));
+
+  Table->Attributes.emplace_back("id", llvm::toHex(llvm::toStringRef(I.USR)));
   TRow->Children.emplace_back(std::move(TD));
   Thead->Children.emplace_back(std::move(TRow));
   Table->Children.emplace_back(std::move(Thead));
-  
+
   std::unique_ptr<TagNode> Node = genEnumMembersBlock(I.Members, HasComments);
-  
+
   if (Node)
     Table->Children.emplace_back(std::move(Node));
 
   Out.emplace_back(std::move(Table));
-  
+
   if (I.DefLoc) {
     if (!CDCtx.RepositoryUrl)
       Out.emplace_back(writeFileDefinition(*I.DefLoc));
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index 6814c8441d..db3aff2d60 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -431,7 +431,7 @@ struct EnumValueInfo {
   // Stores the user-supplied initialization expression for this enumeration
   // constant. This will be empty for implicit enumeration values.
   SmallString<16> ValueExpr;
-  
+
   std::vector<CommentInfo> Description; // Comment description of this field.
 };
 
@@ -447,7 +447,7 @@ struct EnumInfo : public SymbolInfo {
   bool Scoped = false;
   // Indicates whether or not enum members have comments attached
   bool HasComments = false;
-  
+
   // Set to nonempty to the type when this is an explicitly typed enum. For
   //   enum Foo : short { ... };
   // this will be "short".
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index c15cf1e489..78b7041368 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -397,13 +397,13 @@ static void parseEnumerators(EnumInfo &I, const EnumDecl *D) {
     SmallString<16> ValueStr;
     E->getInitVal().toString(ValueStr);
     I.Members.emplace_back(E->getNameAsString(), ValueStr.str(), ValueExpr);
-    ASTContext& Context = E->getASTContext();
+    ASTContext &Context = E->getASTContext();
     RawComment *Comment = E->getASTContext().getRawCommentForDeclNoCache(E);
     if (Comment) {
       CommentInfo CInfo;
       Comment->setAttached();
-      if (comments::FullComment* Fc = Comment->parse(Context, nullptr, E)) {
-        EnumValueInfo& Member = I.Members.back();
+      if (comments::FullComment *Fc = Comment->parse(Context, nullptr, E)) {
+        EnumValueInfo &Member = I.Members.back();
         Member.Description.emplace_back();
         parseFullComment(Fc, Member.Description.back());
       }

``````````

</details>


https://github.com/llvm/llvm-project/pull/101282


More information about the cfe-commits mailing list