[PATCH] D62970: [clang-doc] De-duplicate comments

Diego Astiazarán via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 6 11:05:44 PDT 2019


DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich, lebedev.ri.
DiegoAstiazaran added a project: clang-tools-extra.

De-duplicate comments in reduce function.
When two files include the same header file, this file's content is mapped twice and comments are duplicated after the reduce stage.


https://reviews.llvm.org/D62970

Files:
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h


Index: clang-tools-extra/clang-doc/Representation.h
===================================================================
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -47,6 +47,23 @@
   CommentInfo(CommentInfo &Other) = delete;
   CommentInfo(CommentInfo &&Other) = default;
 
+  bool operator==(const CommentInfo &Other) const {
+    bool AreEqual =
+        Kind == Other.Kind && Text == Other.Text && Name == Other.Name &&
+        Direction == Other.Direction && ParamName == Other.ParamName &&
+        CloseName == Other.CloseName && SelfClosing == Other.SelfClosing &&
+        Explicit == Other.Explicit && AttrKeys == Other.AttrKeys &&
+        AttrValues == Other.AttrValues && Args == Other.Args &&
+        Children.size() == Other.Children.size();
+    if (!AreEqual)
+      return false;
+    for (unsigned I = 0; I < Children.size(); ++I) {
+      if (!(*Children[I] == *Other.Children[I]))
+        return false;
+    }
+    return true;
+  }
+
   SmallString<16>
       Kind; // Kind of comment (FullComment, ParagraphComment, TextComment,
             // InlineCommandComment, HTMLStartTagComment, HTMLEndTagComment,
Index: clang-tools-extra/clang-doc/Representation.cpp
===================================================================
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -120,8 +120,12 @@
   if (Namespace.empty())
     Namespace = std::move(Other.Namespace);
   // Unconditionally extend the description, since each decl may have a comment.
-  std::move(Other.Description.begin(), Other.Description.end(),
-            std::back_inserter(Description));
+  for (auto &Comment : Other.Description) {
+    bool IsCommentUnique = std::find(Description.begin(), Description.end(),
+                                     Comment) == Description.end();
+    if (IsCommentUnique)
+      Description.emplace_back(std::move(Comment));
+  }
 }
 
 bool Info::mergeable(const Info &Other) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62970.203404.patch
Type: text/x-patch
Size: 2023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190606/b6f1d54d/attachment.bin>


More information about the cfe-commits mailing list