Skip to content

Commit ba3d595

Browse files
committedAug 16, 2019
[clang-doc] Serialize inherited attributes and methods
clang-doc now serializes the inherited attributes and methods, not only the name of the base class. All inherited are tracked, if B:A and C:B, info of A is included in C. This data is stored in attribute Bases in a RecordInfo. Previously tracked inheritance data, stored in Parents and VParents, hasn't been removed to reduce review load. Differential revision: https://reviews.llvm.org/D66238 llvm-svn: 369075
1 parent 7605329 commit ba3d595

13 files changed

+373
-47
lines changed
 

‎clang-tools-extra/clang-doc/BitcodeReader.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,29 @@ llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
179179
}
180180
}
181181

182+
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
183+
BaseRecordInfo *I) {
184+
switch (ID) {
185+
case BASE_RECORD_USR:
186+
return decodeRecord(R, I->USR, Blob);
187+
case BASE_RECORD_NAME:
188+
return decodeRecord(R, I->Name, Blob);
189+
case BASE_RECORD_PATH:
190+
return decodeRecord(R, I->Path, Blob);
191+
case BASE_RECORD_TAG_TYPE:
192+
return decodeRecord(R, I->TagType, Blob);
193+
case BASE_RECORD_IS_VIRTUAL:
194+
return decodeRecord(R, I->IsVirtual, Blob);
195+
case BASE_RECORD_ACCESS:
196+
return decodeRecord(R, I->Access, Blob);
197+
case BASE_RECORD_IS_PARENT:
198+
return decodeRecord(R, I->IsParent, Blob);
199+
default:
200+
return llvm::make_error<llvm::StringError>(
201+
"Invalid field for BaseRecordInfo.\n", llvm::inconvertibleErrorCode());
202+
}
203+
}
204+
182205
llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
183206
EnumInfo *I) {
184207
switch (ID) {
@@ -350,6 +373,11 @@ template <> llvm::Error addTypeInfo(RecordInfo *I, MemberTypeInfo &&T) {
350373
return llvm::Error::success();
351374
}
352375

376+
template <> llvm::Error addTypeInfo(BaseRecordInfo *I, MemberTypeInfo &&T) {
377+
I->Members.emplace_back(std::move(T));
378+
return llvm::Error::success();
379+
}
380+
353381
template <> llvm::Error addTypeInfo(FunctionInfo *I, TypeInfo &&T) {
354382
I->ReturnType = std::move(T);
355383
return llvm::Error::success();
@@ -494,6 +522,14 @@ template <> void addChild(RecordInfo *I, EnumInfo &&R) {
494522
I->ChildEnums.emplace_back(std::move(R));
495523
}
496524

525+
template <> void addChild(RecordInfo *I, BaseRecordInfo &&R) {
526+
I->Bases.emplace_back(std::move(R));
527+
}
528+
529+
template <> void addChild(BaseRecordInfo *I, FunctionInfo &&R) {
530+
I->ChildFunctions.emplace_back(std::move(R));
531+
}
532+
497533
// Read records from bitcode into a given info.
498534
template <typename T>
499535
llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, T I) {
@@ -598,6 +634,13 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) {
598634
addChild(I, std::move(F));
599635
return llvm::Error::success();
600636
}
637+
case BI_BASE_RECORD_BLOCK_ID: {
638+
BaseRecordInfo BR;
639+
if (auto Err = readBlock(ID, &BR))
640+
return Err;
641+
addChild(I, std::move(BR));
642+
return llvm::Error::success();
643+
}
601644
case BI_ENUM_BLOCK_ID: {
602645
EnumInfo E;
603646
if (auto Err = readBlock(ID, &E))

‎clang-tools-extra/clang-doc/BitcodeWriter.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static const llvm::IndexedMap<llvm::StringRef, BlockIdToIndexFunctor>
116116
{BI_FIELD_TYPE_BLOCK_ID, "FieldTypeBlock"},
117117
{BI_MEMBER_TYPE_BLOCK_ID, "MemberTypeBlock"},
118118
{BI_RECORD_BLOCK_ID, "RecordBlock"},
119+
{BI_BASE_RECORD_BLOCK_ID, "BaseRecordBlock"},
119120
{BI_FUNCTION_BLOCK_ID, "FunctionBlock"},
120121
{BI_COMMENT_BLOCK_ID, "CommentBlock"},
121122
{BI_REFERENCE_BLOCK_ID, "ReferenceBlock"}};
@@ -165,6 +166,13 @@ static const llvm::IndexedMap<RecordIdDsc, RecordIdToIndexFunctor>
165166
{RECORD_LOCATION, {"Location", &LocationAbbrev}},
166167
{RECORD_TAG_TYPE, {"TagType", &IntAbbrev}},
167168
{RECORD_IS_TYPE_DEF, {"IsTypeDef", &BoolAbbrev}},
169+
{BASE_RECORD_USR, {"USR", &SymbolIDAbbrev}},
170+
{BASE_RECORD_NAME, {"Name", &StringAbbrev}},
171+
{BASE_RECORD_PATH, {"Path", &StringAbbrev}},
172+
{BASE_RECORD_TAG_TYPE, {"TagType", &IntAbbrev}},
173+
{BASE_RECORD_IS_VIRTUAL, {"IsVirtual", &BoolAbbrev}},
174+
{BASE_RECORD_ACCESS, {"Access", &IntAbbrev}},
175+
{BASE_RECORD_IS_PARENT, {"IsParent", &BoolAbbrev}},
168176
{FUNCTION_USR, {"USR", &SymbolIDAbbrev}},
169177
{FUNCTION_NAME, {"Name", &StringAbbrev}},
170178
{FUNCTION_DEFLOCATION, {"DefLocation", &LocationAbbrev}},
@@ -213,6 +221,11 @@ static const std::vector<std::pair<BlockId, std::vector<RecordId>>>
213221
{BI_RECORD_BLOCK_ID,
214222
{RECORD_USR, RECORD_NAME, RECORD_PATH, RECORD_DEFLOCATION,
215223
RECORD_LOCATION, RECORD_TAG_TYPE, RECORD_IS_TYPE_DEF}},
224+
// BaseRecord Block
225+
{BI_BASE_RECORD_BLOCK_ID,
226+
{BASE_RECORD_USR, BASE_RECORD_NAME, BASE_RECORD_PATH,
227+
BASE_RECORD_TAG_TYPE, BASE_RECORD_IS_VIRTUAL, BASE_RECORD_ACCESS,
228+
BASE_RECORD_IS_PARENT}},
216229
// Function Block
217230
{BI_FUNCTION_BLOCK_ID,
218231
{FUNCTION_USR, FUNCTION_NAME, FUNCTION_DEFLOCATION, FUNCTION_LOCATION,
@@ -494,6 +507,8 @@ void ClangDocBitcodeWriter::emitBlock(const RecordInfo &I) {
494507
emitBlock(P, FieldId::F_parent);
495508
for (const auto &P : I.VirtualParents)
496509
emitBlock(P, FieldId::F_vparent);
510+
for (const auto &PB : I.Bases)
511+
emitBlock(PB);
497512
for (const auto &C : I.ChildRecords)
498513
emitBlock(C, FieldId::F_child_record);
499514
for (const auto &C : I.ChildFunctions)
@@ -502,6 +517,21 @@ void ClangDocBitcodeWriter::emitBlock(const RecordInfo &I) {
502517
emitBlock(C);
503518
}
504519

520+
void ClangDocBitcodeWriter::emitBlock(const BaseRecordInfo &I) {
521+
StreamSubBlockGuard Block(Stream, BI_BASE_RECORD_BLOCK_ID);
522+
emitRecord(I.USR, BASE_RECORD_USR);
523+
emitRecord(I.Name, BASE_RECORD_NAME);
524+
emitRecord(I.Path, BASE_RECORD_PATH);
525+
emitRecord(I.TagType, BASE_RECORD_TAG_TYPE);
526+
emitRecord(I.IsVirtual, BASE_RECORD_IS_VIRTUAL);
527+
emitRecord(I.Access, BASE_RECORD_ACCESS);
528+
emitRecord(I.IsParent, BASE_RECORD_IS_PARENT);
529+
for (const auto &M : I.Members)
530+
emitBlock(M);
531+
for (const auto &C : I.ChildFunctions)
532+
emitBlock(C);
533+
}
534+
505535
void ClangDocBitcodeWriter::emitBlock(const FunctionInfo &I) {
506536
StreamSubBlockGuard Block(Stream, BI_FUNCTION_BLOCK_ID);
507537
emitRecord(I.USR, FUNCTION_USR);

‎clang-tools-extra/clang-doc/BitcodeWriter.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace doc {
3030
// Current version number of clang-doc bitcode.
3131
// Should be bumped when removing or changing BlockIds, RecordIds, or
3232
// BitCodeConstants, though they can be added without breaking it.
33-
static const unsigned VersionNumber = 2;
33+
static const unsigned VersionNumber = 3;
3434

3535
struct BitCodeConstants {
3636
static constexpr unsigned RecordSize = 32U;
@@ -58,6 +58,7 @@ enum BlockId {
5858
BI_FIELD_TYPE_BLOCK_ID,
5959
BI_MEMBER_TYPE_BLOCK_ID,
6060
BI_RECORD_BLOCK_ID,
61+
BI_BASE_RECORD_BLOCK_ID,
6162
BI_FUNCTION_BLOCK_ID,
6263
BI_COMMENT_BLOCK_ID,
6364
BI_REFERENCE_BLOCK_ID,
@@ -105,6 +106,13 @@ enum RecordId {
105106
RECORD_LOCATION,
106107
RECORD_TAG_TYPE,
107108
RECORD_IS_TYPE_DEF,
109+
BASE_RECORD_USR,
110+
BASE_RECORD_NAME,
111+
BASE_RECORD_PATH,
112+
BASE_RECORD_TAG_TYPE,
113+
BASE_RECORD_IS_VIRTUAL,
114+
BASE_RECORD_ACCESS,
115+
BASE_RECORD_IS_PARENT,
108116
REFERENCE_USR,
109117
REFERENCE_NAME,
110118
REFERENCE_TYPE,
@@ -143,6 +151,7 @@ class ClangDocBitcodeWriter {
143151
// Block emission of different info types.
144152
void emitBlock(const NamespaceInfo &I);
145153
void emitBlock(const RecordInfo &I);
154+
void emitBlock(const BaseRecordInfo &I);
146155
void emitBlock(const FunctionInfo &I);
147156
void emitBlock(const EnumInfo &I);
148157
void emitBlock(const TypeInfo &B);

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

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ void RecordInfo::merge(RecordInfo &&Other) {
178178
TagType = Other.TagType;
179179
if (Members.empty())
180180
Members = std::move(Other.Members);
181+
if (Bases.empty())
182+
Bases = std::move(Other.Bases);
181183
if (Parents.empty())
182184
Parents = std::move(Other.Parents);
183185
if (VirtualParents.empty())

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

+23-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ using SymbolID = std::array<uint8_t, 20>;
3232
struct Info;
3333
struct FunctionInfo;
3434
struct EnumInfo;
35+
struct BaseRecordInfo;
3536

3637
enum class InfoType {
3738
IT_default,
@@ -345,15 +346,33 @@ struct RecordInfo : public SymbolInfo {
345346
llvm::SmallVector<Reference, 4>
346347
VirtualParents; // List of virtual base/parent records.
347348

348-
// Records are references because they will be properly
349-
// documented in their own info, while the entirety of Functions and Enums are
350-
// included here because they should not have separate documentation from
351-
// their scope.
349+
std::vector<BaseRecordInfo>
350+
Bases; // List of base/parent records; this includes inherited methods and
351+
// attributes
352+
353+
// Records are references because they will be properly documented in their
354+
// own info, while the entirety of Functions and Enums are included here
355+
// because they should not have separate documentation from their scope.
352356
std::vector<Reference> ChildRecords;
353357
std::vector<FunctionInfo> ChildFunctions;
354358
std::vector<EnumInfo> ChildEnums;
355359
};
356360

361+
struct BaseRecordInfo : public RecordInfo {
362+
BaseRecordInfo() : RecordInfo() {}
363+
BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, bool IsVirtual,
364+
AccessSpecifier Access, bool IsParent)
365+
: RecordInfo(USR, Name, Path), IsVirtual(IsVirtual), Access(Access),
366+
IsParent(IsParent) {}
367+
368+
// Indicates if base corresponds to a virtual inheritance
369+
bool IsVirtual = false;
370+
// Access level associated with this inherited info (public, protected,
371+
// private).
372+
AccessSpecifier Access = AccessSpecifier::AS_public;
373+
bool IsParent = false; // Indicates if this base is a direct parent
374+
};
375+
357376
// TODO: Expand to allow for documenting templating.
358377
// Info for types.
359378
struct EnumInfo : public SymbolInfo {

0 commit comments

Comments
 (0)