mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user