[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:
Xi Ge
2016-02-10 17:12:03 -08:00
parent 98734f588a
commit c97f115219
2 changed files with 594 additions and 588 deletions

View File

@@ -308,6 +308,10 @@ void swift::ide::printSubmoduleInterface(
continue;
}
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.
SwiftDecls.push_back(D);
}
@@ -344,9 +348,15 @@ void swift::ide::printSubmoduleInterface(
});
std::sort(SwiftDecls.begin(), SwiftDecls.end(),
[](Decl *LHS, Decl *RHS) -> bool {
[&](Decl *LHS, Decl *RHS) -> bool {
auto *LHSValue = dyn_cast<ValueDecl>(LHS);
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) {
StringRef LHSName = LHSValue->getName().str();
StringRef RHSName = RHSValue->getName().str();
@@ -368,10 +378,6 @@ void swift::ide::printSubmoduleInterface(
auto PrintDecl = [&](Decl *D) -> bool {
ASTPrinter &Printer = *PrinterToUse;
if (GroupName && (!D->getGroupName() ||
D->getGroupName().getValue() != GroupName.getValue()))
return false;
if (!shouldPrint(D, AdjustedOptions)) {
Printer.avoidPrintDeclPost(D);
return false;