[clang-tools-extra] f88c6b9 - Move definitions to prevent incomplete types.
Jens Massberg via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 13 07:45:15 PST 2023
Author: Jens Massberg
Date: 2023-01-13T16:44:49+01:00
New Revision: f88c6b9166f885e7089cb15095e38868aaba04da
URL: https://github.com/llvm/llvm-project/commit/f88c6b9166f885e7089cb15095e38868aaba04da
DIFF: https://github.com/llvm/llvm-project/commit/f88c6b9166f885e7089cb15095e38868aaba04da.diff
LOG: Move definitions to prevent incomplete types.
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
Added:
Modified:
clang-tools-extra/clang-doc/Representation.cpp
clang-tools-extra/clang-doc/Representation.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index c1279997813a8..31bb07d04b35d 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -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;
diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h
index 564488ceb027f..15e1abf858aaa 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -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;
More information about the cfe-commits
mailing list