[Serialization] Add grouping information of Stdlib to its module documentation file and deserialize it into ModuleFile.

We currently do not support more sophisticated naming mechanisms; group names are stemmed source file names.
This commit is contained in:
Xi Ge
2016-02-05 14:26:43 -08:00
parent 33756a53b2
commit 33b4de7ff6
5 changed files with 143 additions and 9 deletions

View File

@@ -596,6 +596,7 @@ public:
new (&Comments[i]) SingleRawComment(RawText, StartColumn);
}
result.Raw = RawComment(Comments);
result.Group = endian::readNext<uint32_t, little, unaligned>(data);
return result;
}
};
@@ -613,6 +614,21 @@ ModuleFile::readDeclCommentTable(ArrayRef<uint64_t> fields,
DeclCommentTableInfo(*this)));
}
std::unique_ptr<ModuleFile::GroupNameTable>
ModuleFile::readGroupTable(ArrayRef<uint64_t> Fields, StringRef BlobData) {
std::unique_ptr<ModuleFile::GroupNameTable> pMap(
new ModuleFile::GroupNameTable);
auto Data = reinterpret_cast<const uint8_t *>(BlobData.data());
unsigned GroupCount = endian::readNext<uint32_t, little, unaligned>(Data);
for (unsigned I = 0; I < GroupCount; I ++) {
auto RawSize = endian::readNext<uint32_t, little, unaligned>(Data);
auto RawText = StringRef(reinterpret_cast<const char *>(Data), RawSize);
Data += RawSize;
(*pMap)[I] = RawText;
}
return std::move(pMap);
}
bool ModuleFile::readCommentBlock(llvm::BitstreamCursor &cursor) {
cursor.EnterSubBlock(COMMENT_BLOCK_ID);
@@ -642,6 +658,9 @@ bool ModuleFile::readCommentBlock(llvm::BitstreamCursor &cursor) {
case comment_block::DECL_COMMENTS:
DeclCommentTable = readDeclCommentTable(scratch, blobData);
break;
case comment_block::GROUP_NAMES:
GroupNamesMap = readGroupTable(scratch, blobData);
break;
default:
// Unknown index kind, which this version of the compiler won't use.
break;
@@ -1513,6 +1532,23 @@ Optional<BriefAndRawComment> ModuleFile::getCommentForDecl(const Decl *D) {
return getCommentForDeclByUSR(USRBuffer.str());
}
Optional<StringRef> ModuleFile::getGroupNameById(unsigned Id) {
if(GroupNamesMap || GroupNamesMap->count(Id) == 0)
return None;
auto Group = (*GroupNamesMap)[Id];
if (Group.empty())
return None;
return Group;
}
Optional<StringRef> ModuleFile::getGroupNameForDecl(const Decl *D) {
auto Triple = getCommentForDecl(D);
if (!Triple.hasValue()) {
return None;
}
return getGroupNameById(Triple.getValue().Group);
}
Optional<BriefAndRawComment> ModuleFile::getCommentForDeclByUSR(StringRef USR) {
if (!DeclCommentTable)
return None;