[IDE] When picking regular comments from clang headers, make sure that extensions/categories

are printed in the right source location otherwise the comments will be out-of-place.

Swift SVN r16271
This commit is contained in:
Argyrios Kyrtzidis
2014-04-13 04:35:29 +00:00
parent defccdea36
commit ba30e56b58
6 changed files with 121 additions and 3 deletions

View File

@@ -210,7 +210,10 @@ void swift::ide::printSubmoduleInterface(
ImportDecls.push_back(ID);
continue;
}
if (auto CN = D->getClangNode()) {
auto addToClangDecls = [&](Decl *D) {
assert(D->hasClangNode());
auto CN = D->getClangNode();
clang::SourceLocation Loc = CN.getLocation();
auto *OwningModule = Importer.getClangOwningModule(CN);
@@ -218,6 +221,21 @@ void swift::ide::printSubmoduleInterface(
if (I != ClangDecls.end()) {
I->second.push_back({ D, Loc });
}
};
if (D->hasClangNode()) {
addToClangDecls(D);
// When picking regular comments from clang headers, make sure that
// extensions/categories are printed in the right source location
// otherwise the comments will be out-of-place.
if (Options.PrintRegularClangComments) {
if (auto NTD = dyn_cast<NominalTypeDecl>(D)) {
for (auto Ext : NTD->getExtensions()) {
if (Ext->hasClangNode())
addToClangDecls(Ext);
}
}
}
continue;
}
if (FullModuleName.empty()) {
@@ -275,14 +293,21 @@ void swift::ide::printSubmoduleInterface(
PrinterToUse = &RegularCommentPrinter;
auto PrintDecl = [&](Decl *D) {
if (isa<ExtensionDecl>(D))
return;
if (auto Ext = dyn_cast<ExtensionDecl>(D)) {
// When picking regular comments from clang headers, make sure that
// extensions/categories are printed in the right source location
// otherwise the comments will be out-of-place.
if (!(Options.PrintRegularClangComments && Ext->hasClangNode()))
return;
}
ASTPrinter &Printer = *PrinterToUse;
D->print(Printer, AdjustedOptions);
Printer << "\n";
if (auto NTD = dyn_cast<NominalTypeDecl>(D)) {
for (auto Ext : NTD->getExtensions()) {
if (Options.PrintRegularClangComments && Ext->hasClangNode())
continue; // will be printed in its source location, see above.
Ext->print(Printer, AdjustedOptions);
Printer << "\n";
}