Skip to content

Commit 54d91c9

Browse files
committed
[test] Since group info is independent from doc comment table, strengthen the test to make sure every display decl from stdlib has an associated group name.
1 parent a1d885c commit 54d91c9

File tree

1 file changed

+61
-17
lines changed

1 file changed

+61
-17
lines changed

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,36 +1612,80 @@ class AnnotatingPrinter : public StreamPrinter {
16121612
};
16131613
}
16141614

1615-
struct GroupNamesPrinter : public StreamPrinter {
1615+
struct GroupNamesPrinter {
16161616
llvm::StringSet<> Groups;
1617-
GroupNamesPrinter(raw_ostream &OS) : StreamPrinter(OS) {}
1617+
raw_ostream &OS;
1618+
GroupNamesPrinter(raw_ostream &OS) : OS(OS) {}
16181619
~GroupNamesPrinter() {
16191620
OS << "Module groups begin:\n";
16201621
for (auto &Entry : Groups) {
16211622
OS << Entry.getKey() << "\n";
16221623
}
16231624
OS << "Module groups end.\n";
16241625
}
1625-
void printText(StringRef Text) override { } // Drop Declarations.
16261626

1627-
void printDeclPre(const Decl *D) override {
1628-
StreamPrinter::printDeclPre(D);
1629-
// If we have raw comment, we should have group name.
1630-
if (!D->getRawComment().Comments.empty()) {
1631-
StringRef Name = D->getGroupName().getValue();
1632-
Groups.insert(Name.empty() ? "<NULL>" : Name);
1627+
void addDecl(const Decl *D) {
1628+
if(auto VD = dyn_cast<ValueDecl>(D)) {
1629+
if (!VD->isImplicit() && !VD->isPrivateStdlibDecl()) {
1630+
StringRef Name = VD->getGroupName().getValue();
1631+
Groups.insert(Name.empty() ? "<NULL>" : Name);
1632+
}
16331633
}
16341634
}
16351635
};
16361636

1637+
static int doPrintModuleGroups(const CompilerInvocation &InitInvok,
1638+
const std::vector<std::string> ModulesToPrint) {
1639+
CompilerInvocation Invocation(InitInvok);
1640+
1641+
CompilerInstance CI;
1642+
// Display diagnostics to stderr.
1643+
PrintingDiagnosticConsumer PrintDiags;
1644+
CI.addDiagnosticConsumer(&PrintDiags);
1645+
if (CI.setup(Invocation))
1646+
return 1;
1647+
1648+
auto &Context = CI.getASTContext();
1649+
1650+
// Load standard library so that Clang importer can use it.
1651+
auto *Stdlib = getModuleByFullName(Context, Context.StdlibModuleName);
1652+
if (!Stdlib) {
1653+
llvm::errs() << "Failed loading stdlib\n";
1654+
return 1;
1655+
}
1656+
1657+
int ExitCode = 0;
1658+
for (StringRef ModuleToPrint : ModulesToPrint) {
1659+
if (ModuleToPrint.empty()) {
1660+
ExitCode = 1;
1661+
continue;
1662+
}
1663+
1664+
// Get the (sub)module to print.
1665+
auto *M = getModuleByFullName(Context, ModuleToPrint);
1666+
if (!M) {
1667+
ExitCode = 1;
1668+
continue;
1669+
}
1670+
{
1671+
GroupNamesPrinter Printer(llvm::outs());
1672+
llvm::SmallVector<Decl*, 256> Results;
1673+
M->getDisplayDecls(Results);
1674+
for (auto R : Results) {
1675+
Printer.addDecl(R);
1676+
}
1677+
}
1678+
}
1679+
return ExitCode;
1680+
}
1681+
16371682
static int doPrintModules(const CompilerInvocation &InitInvok,
16381683
const std::vector<std::string> ModulesToPrint,
16391684
const std::vector<std::string> GroupsToPrint,
16401685
ide::ModuleTraversalOptions TraversalOptions,
16411686
const PrintOptions &Options,
16421687
bool AnnotatePrint,
1643-
bool SynthesizeExtensions,
1644-
bool PrintGroupNames) {
1688+
bool SynthesizeExtensions) {
16451689
CompilerInvocation Invocation(InitInvok);
16461690

16471691
CompilerInstance CI;
@@ -1663,9 +1707,7 @@ static int doPrintModules(const CompilerInvocation &InitInvok,
16631707
int ExitCode = 0;
16641708

16651709
std::unique_ptr<ASTPrinter> Printer;
1666-
if (PrintGroupNames)
1667-
Printer.reset(new GroupNamesPrinter(llvm::outs()));
1668-
else if (AnnotatePrint)
1710+
if (AnnotatePrint)
16691711
Printer.reset(new AnnotatingPrinter(llvm::outs()));
16701712
else
16711713
Printer.reset(new StreamPrinter(llvm::outs()));
@@ -2706,11 +2748,13 @@ int main(int argc, char *argv[]) {
27062748
if (options::ModulePrintSkipOverlay)
27072749
TraversalOptions |= ide::ModuleTraversal::SkipOverlay;
27082750

2709-
ExitCode = doPrintModules(
2751+
if (options::Action == ActionType::PrintModuleGroups)
2752+
ExitCode = doPrintModuleGroups(InitInvok, options::ModuleToPrint);
2753+
else
2754+
ExitCode = doPrintModules(
27102755
InitInvok, options::ModuleToPrint, options::ModuleGroupToPrint,
27112756
TraversalOptions, PrintOpts, options::AnnotatePrint,
2712-
options::SynthesizeExtension,
2713-
options::Action == ActionType::PrintModuleGroups);
2757+
options::SynthesizeExtension);
27142758
break;
27152759
}
27162760

0 commit comments

Comments
 (0)