Skip to content

Commit

Permalink
Move definitions to prevent incomplete types.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jensmassberg committed Jan 13, 2023
1 parent 0995b54 commit f88c6b9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 41 deletions.
49 changes: 49 additions & 0 deletions clang-tools-extra/clang-doc/Representation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 6 additions & 41 deletions clang-tools-extra/clang-doc/Representation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f88c6b9

Please sign in to comment.