Skip to content

Commit 6826682

Browse files
brettwilovepi
authored andcommitted
[clang-doc] Always emit the TagType for RecordInfo
Always emit the TagType for RecordInfo in YAML output. Previously this omitted the type for "struct", considering it the default. But records in C++ don't really have a default type so always emitting this is more clear. Emit IsTypeDef in YAML. Previously this existed only in the Representation but was never written. Additionally, adds IsTypeDef to the record merge operation which was clearing it (all RecordInfo structures are merged with am empty RecordInfo during the reduce phase). Reviewed By: paulkirth Differential Revision: https://reviews.llvm.org/D131739
1 parent 75c7e79 commit 6826682

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ void RecordInfo::merge(RecordInfo &&Other) {
222222
assert(mergeable(Other));
223223
if (!TagType)
224224
TagType = Other.TagType;
225+
IsTypeDef = IsTypeDef || Other.IsTypeDef;
225226
if (Members.empty())
226227
Members = std::move(Other.Members);
227228
if (Bases.empty())

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,15 @@ struct RecordInfo : public SymbolInfo {
348348

349349
void merge(RecordInfo &&I);
350350

351-
TagTypeKind TagType = TagTypeKind::TTK_Struct; // Type of this record
352-
// (struct, class, union,
353-
// interface).
354-
bool IsTypeDef = false; // Indicates if record was declared using typedef
351+
// Type of this record (struct, class, union, interface).
352+
TagTypeKind TagType = TagTypeKind::TTK_Struct;
353+
354+
// Indicates if the record was declared using a typedef. Things like anonymous
355+
// structs in a typedef:
356+
// typedef struct { ... } foo_t;
357+
// are converted into records with the typedef as the Name + this flag set.
358+
bool IsTypeDef = false;
359+
355360
llvm::SmallVector<MemberTypeInfo, 4>
356361
Members; // List of info about record members.
357362
llvm::SmallVector<Reference, 4> Parents; // List of base/parent records

clang-tools-extra/clang-doc/YAMLGenerator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ static void SymbolInfoMapping(IO &IO, SymbolInfo &I) {
127127

128128
static void RecordInfoMapping(IO &IO, RecordInfo &I) {
129129
SymbolInfoMapping(IO, I);
130-
IO.mapOptional("TagType", I.TagType, clang::TagTypeKind::TTK_Struct);
130+
IO.mapOptional("TagType", I.TagType);
131+
IO.mapOptional("IsTypeDef", I.IsTypeDef, false);
131132
IO.mapOptional("Members", I.Members);
132133
IO.mapOptional("Bases", I.Bases);
133134
IO.mapOptional("Parents", I.Parents, llvm::SmallVector<Reference, 4>());

clang-tools-extra/unittests/clang-doc/MergeTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ TEST(MergeTest, mergeNamespaceInfos) {
7878
TEST(MergeTest, mergeRecordInfos) {
7979
RecordInfo One;
8080
One.Name = "r";
81+
One.IsTypeDef = true;
8182
One.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
8283

8384
One.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
@@ -119,6 +120,7 @@ TEST(MergeTest, mergeRecordInfos) {
119120

120121
auto Expected = std::make_unique<RecordInfo>();
121122
Expected->Name = "r";
123+
Expected->IsTypeDef = true;
122124
Expected->Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
123125

124126
Expected->DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});

clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ TEST(YAMLGeneratorTest, emitRecordYAML) {
7676
RecordInfo I;
7777
I.Name = "r";
7878
I.Path = "path/to/A";
79+
I.IsTypeDef = true;
7980
I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
8081

8182
I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
@@ -136,6 +137,7 @@ Path: 'path/to/A'
136137
- LineNumber: 12
137138
Filename: 'test.cpp'
138139
TagType: Class
140+
IsTypeDef: true
139141
Members:
140142
- Type:
141143
Name: 'int'
@@ -154,6 +156,7 @@ TagType: Class
154156
- USR: '0000000000000000000000000000000000000000'
155157
Name: 'F'
156158
Path: 'path/to/F'
159+
TagType: Struct
157160
Members:
158161
- Type:
159162
Name: 'int'

0 commit comments

Comments
 (0)