mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ModulePrinter] When printing decls in a module group, we print them according to their source order.
Source order preserves semantic information better than printing alphabetically.
This commit is contained in:
@@ -308,6 +308,10 @@ void swift::ide::printSubmoduleInterface(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (FullModuleName.empty()) {
|
if (FullModuleName.empty()) {
|
||||||
|
// If group name is given and the decl does not belong to the group, skip it.
|
||||||
|
if (GroupName && (!D->getGroupName() ||
|
||||||
|
D->getGroupName().getValue() != GroupName.getValue()))
|
||||||
|
continue;
|
||||||
// Add Swift decls if we are printing the top-level module.
|
// Add Swift decls if we are printing the top-level module.
|
||||||
SwiftDecls.push_back(D);
|
SwiftDecls.push_back(D);
|
||||||
}
|
}
|
||||||
@@ -344,9 +348,15 @@ void swift::ide::printSubmoduleInterface(
|
|||||||
});
|
});
|
||||||
|
|
||||||
std::sort(SwiftDecls.begin(), SwiftDecls.end(),
|
std::sort(SwiftDecls.begin(), SwiftDecls.end(),
|
||||||
[](Decl *LHS, Decl *RHS) -> bool {
|
[&](Decl *LHS, Decl *RHS) -> bool {
|
||||||
auto *LHSValue = dyn_cast<ValueDecl>(LHS);
|
auto *LHSValue = dyn_cast<ValueDecl>(LHS);
|
||||||
auto *RHSValue = dyn_cast<ValueDecl>(RHS);
|
auto *RHSValue = dyn_cast<ValueDecl>(RHS);
|
||||||
|
|
||||||
|
// If group is specified, we order the decls by their source order.
|
||||||
|
if (GroupName && LHS->getSourceOrder() && RHS->getSourceOrder()) {
|
||||||
|
return LHS->getSourceOrder().getValue() < RHS->getSourceOrder().getValue();
|
||||||
|
}
|
||||||
|
|
||||||
if (LHSValue && RHSValue) {
|
if (LHSValue && RHSValue) {
|
||||||
StringRef LHSName = LHSValue->getName().str();
|
StringRef LHSName = LHSValue->getName().str();
|
||||||
StringRef RHSName = RHSValue->getName().str();
|
StringRef RHSName = RHSValue->getName().str();
|
||||||
@@ -368,10 +378,6 @@ void swift::ide::printSubmoduleInterface(
|
|||||||
|
|
||||||
auto PrintDecl = [&](Decl *D) -> bool {
|
auto PrintDecl = [&](Decl *D) -> bool {
|
||||||
ASTPrinter &Printer = *PrinterToUse;
|
ASTPrinter &Printer = *PrinterToUse;
|
||||||
if (GroupName && (!D->getGroupName() ||
|
|
||||||
D->getGroupName().getValue() != GroupName.getValue()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!shouldPrint(D, AdjustedOptions)) {
|
if (!shouldPrint(D, AdjustedOptions)) {
|
||||||
Printer.avoidPrintDeclPost(D);
|
Printer.avoidPrintDeclPost(D);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user