Re-apply "ModulePrinter: Print decls from the same source file near each other."

This reverts commit 1db83907e3.
This commit is contained in:
Xi Ge
2016-03-08 10:00:03 -08:00
parent 4b86ad2d9f
commit 7a3276738b
9 changed files with 83 additions and 10 deletions

View File

@@ -1539,13 +1539,9 @@ Optional<CommentInfo> ModuleFile::getCommentForDecl(const Decl *D) const {
return getCommentForDeclByUSR(USRBuffer.str());
}
Optional<StringRef> ModuleFile::getGroupNameById(unsigned Id) const {
if(!GroupNamesMap || GroupNamesMap->count(Id) == 0)
return None;
return (*GroupNamesMap)[Id];
}
const static std::string Separator = "/";
Optional<StringRef> ModuleFile::getGroupNameForDecl(const Decl *D) const {
const Decl* getGroupDecl(const Decl *D) {
auto GroupD = D;
// Extensions always exist in the same group with the nominal.
@@ -1553,6 +1549,32 @@ Optional<StringRef> ModuleFile::getGroupNameForDecl(const Decl *D) const {
getInnermostTypeContext())) {
GroupD = ED->getExtendedType()->getAnyNominal();
}
return GroupD;
}
Optional<StringRef> ModuleFile::getGroupNameById(unsigned Id) const {
if(!GroupNamesMap || GroupNamesMap->count(Id) == 0)
return None;
auto Original = (*GroupNamesMap)[Id];
if (Original.empty())
return None;
return StringRef(Original.data(), Original.find_last_of(Separator));
}
Optional<StringRef> ModuleFile::getSourceFileNameById(unsigned Id) const {
if(!GroupNamesMap || GroupNamesMap->count(Id) == 0)
return None;
auto Original = (*GroupNamesMap)[Id];
if (Original.empty())
return None;
auto SepPos = Original.find_last_of(Separator);
auto Start = Original.data() + SepPos + 1;
auto Len = Original.size() - SepPos - 1;
return StringRef(Start, Len);
}
Optional<StringRef> ModuleFile::getGroupNameForDecl(const Decl *D) const {
auto GroupD = getGroupDecl(D);
auto Triple = getCommentForDecl(GroupD);
if (!Triple.hasValue()) {
return None;
@@ -1560,6 +1582,16 @@ Optional<StringRef> ModuleFile::getGroupNameForDecl(const Decl *D) const {
return getGroupNameById(Triple.getValue().Group);
}
Optional<StringRef>
ModuleFile::getSourceFileNameForDecl(const Decl *D) const {
auto GroupD = getGroupDecl(D);
auto Triple = getCommentForDecl(GroupD);
if (!Triple.hasValue()) {
return None;
}
return getSourceFileNameById(Triple.getValue().Group);
}
void ModuleFile::collectAllGroups(std::vector<StringRef> &Names) const {
if (!GroupNamesMap)
return;