Move definitions to prevent incomplete types.
authorJens Massberg <massberg@google.com>
Fri, 13 Jan 2023 10:37:13 +0000 (11:37 +0100)
committerJens Massberg <massberg@google.com>
Fri, 13 Jan 2023 15:44:49 +0000 (16:44 +0100)
C++20 is more strict when erroring out due to incomplete types.
Thus the code required some restructoring so that it complies in C++20.

Differential Revision: https://reviews.llvm.org/D141671

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

index c127999..31bb07d 100644 (file)
@@ -128,6 +128,41 @@ mergeInfos(std::vector<std::unique_ptr<Info>> &Values) {
   }
 }
 
+bool CommentInfo::operator==(const CommentInfo &Other) const {
+  auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,
+                          SelfClosing, Explicit, AttrKeys, AttrValues, Args);
+  auto SecondCI =
+      std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction,
+               Other.ParamName, Other.CloseName, Other.SelfClosing,
+               Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args);
+
+  if (FirstCI != SecondCI || Children.size() != Other.Children.size())
+    return false;
+
+  return std::equal(Children.begin(), Children.end(), Other.Children.begin(),
+                    llvm::deref<std::equal_to<>>{});
+}
+
+bool CommentInfo::operator<(const CommentInfo &Other) const {
+  auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,
+                          SelfClosing, Explicit, AttrKeys, AttrValues, Args);
+  auto SecondCI =
+      std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction,
+               Other.ParamName, Other.CloseName, Other.SelfClosing,
+               Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args);
+
+  if (FirstCI < SecondCI)
+    return true;
+
+  if (FirstCI == SecondCI) {
+    return std::lexicographical_compare(
+        Children.begin(), Children.end(), Other.Children.begin(),
+        Other.Children.end(), llvm::deref<std::less<>>());
+  }
+
+  return false;
+}
+
 static llvm::SmallString<64>
 calculateRelativeFilePath(const InfoType &Type, const StringRef &Path,
                           const StringRef &Name, const StringRef &CurrentPath) {
@@ -220,6 +255,9 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
   mergeBase(std::move(Other));
 }
 
+NamespaceInfo::NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path)
+      : Info(InfoType::IT_namespace, USR, Name, Path) {}
+
 void NamespaceInfo::merge(NamespaceInfo &&Other) {
   assert(mergeable(Other));
   // Reduce children if necessary.
@@ -231,6 +269,9 @@ void NamespaceInfo::merge(NamespaceInfo &&Other) {
   mergeBase(std::move(Other));
 }
 
+RecordInfo::RecordInfo(SymbolID USR, StringRef Name, StringRef Path)
+    : SymbolInfo(InfoType::IT_record, USR, Name, Path) {}
+
 void RecordInfo::merge(RecordInfo &&Other) {
   assert(mergeable(Other));
   if (!TagType)
@@ -289,6 +330,14 @@ void TypedefInfo::merge(TypedefInfo &&Other) {
   SymbolInfo::merge(std::move(Other));
 }
 
+BaseRecordInfo::BaseRecordInfo() : RecordInfo() {}
+
+BaseRecordInfo::BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path,
+                               bool IsVirtual, AccessSpecifier Access,
+                               bool IsParent)
+    : RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
+      IsParent(IsParent) {}
+
 llvm::SmallString<16> Info::extractName() const {
   if (!Name.empty())
     return Name;
index 564488c..15e1abf 100644 (file)
@@ -52,44 +52,13 @@ struct CommentInfo {
   CommentInfo(CommentInfo &&Other) = default;
   CommentInfo &operator=(CommentInfo &&Other) = default;
 
-  bool operator==(const CommentInfo &Other) const {
-    auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,
-                            SelfClosing, Explicit, AttrKeys, AttrValues, Args);
-    auto SecondCI =
-        std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction,
-                 Other.ParamName, Other.CloseName, Other.SelfClosing,
-                 Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args);
-
-    if (FirstCI != SecondCI || Children.size() != Other.Children.size())
-      return false;
-
-    return std::equal(Children.begin(), Children.end(), Other.Children.begin(),
-                      llvm::deref<std::equal_to<>>{});
-  }
+  bool operator==(const CommentInfo &Other) const;
 
   // This operator is used to sort a vector of CommentInfos.
   // No specific order (attributes more important than others) is required. Any
   // sort is enough, the order is only needed to call std::unique after sorting
   // the vector.
-  bool operator<(const CommentInfo &Other) const {
-    auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,
-                            SelfClosing, Explicit, AttrKeys, AttrValues, Args);
-    auto SecondCI =
-        std::tie(Other.Kind, Other.Text, Other.Name, Other.Direction,
-                 Other.ParamName, Other.CloseName, Other.SelfClosing,
-                 Other.Explicit, Other.AttrKeys, Other.AttrValues, Other.Args);
-
-    if (FirstCI < SecondCI)
-      return true;
-
-    if (FirstCI == SecondCI) {
-      return std::lexicographical_compare(
-          Children.begin(), Children.end(), Other.Children.begin(),
-          Other.Children.end(), llvm::deref<std::less<>>());
-    }
-
-    return false;
-  }
+  bool operator<(const CommentInfo &Other) const;
 
   SmallString<16>
       Kind; // Kind of comment (FullComment, ParagraphComment, TextComment,
@@ -330,8 +299,7 @@ struct Info {
 // Info for namespaces.
 struct NamespaceInfo : public Info {
   NamespaceInfo(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
-                StringRef Path = StringRef())
-      : Info(InfoType::IT_namespace, USR, Name, Path) {}
+                StringRef Path = StringRef());
 
   void merge(NamespaceInfo &&I);
 
@@ -381,8 +349,7 @@ struct FunctionInfo : public SymbolInfo {
 // Info for types.
 struct RecordInfo : public SymbolInfo {
   RecordInfo(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
-             StringRef Path = StringRef())
-      : SymbolInfo(InfoType::IT_record, USR, Name, Path) {}
+             StringRef Path = StringRef());
 
   void merge(RecordInfo &&I);
 
@@ -434,11 +401,9 @@ struct TypedefInfo : public SymbolInfo {
 };
 
 struct BaseRecordInfo : public RecordInfo {
-  BaseRecordInfo() : RecordInfo() {}
+  BaseRecordInfo();
   BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, bool IsVirtual,
-                 AccessSpecifier Access, bool IsParent)
-      : RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
-        IsParent(IsParent) {}
+                 AccessSpecifier Access, bool IsParent);
 
   // Indicates if base corresponds to a virtual inheritance
   bool IsVirtual = false;