@@ -428,10 +428,17 @@ StringRef SDKNodeType::getTypeRoleDescription() const {
428
428
llvm_unreachable (" Unhandled SDKNodeKind in switch" );
429
429
}
430
430
431
- SDKNode *SDKNodeRoot::getInstance (SDKContext &Ctx) {
431
+ SDKNode *SDKNodeRoot::getInstance (SDKContext &Ctx, ArrayRef<ModuleDecl*> modules ) {
432
432
SDKNodeInitInfo Info (Ctx);
433
- Info.Name = Ctx.buffer (" TopLevel" );
434
- Info.PrintedName = Ctx.buffer (" TopLevel" );
433
+ StringRef name = Ctx.buffer (" NO_MODULE" );
434
+ if (modules.size () == 1 ) {
435
+ // use the module name
436
+ name = Ctx.buffer (modules[0 ]->getName ().str ());
437
+ } else if (!modules.empty ()) {
438
+ name = Ctx.buffer (" MULTI_MODULES" );
439
+ }
440
+ Info.Name = name;
441
+ Info.PrintedName = name;
435
442
llvm::transform (Ctx.getOpts ().ToolArgs , std::back_inserter (Info.ToolArgs ),
436
443
[&](std::string s) { return Ctx.buffer (s); });
437
444
Info.JsonFormatVer = DIGESTER_JSON_VERSION;
@@ -1976,8 +1983,13 @@ void SwiftDeclCollector::printTopLevelNames() {
1976
1983
llvm::outs () << Node->getKind () << " : " << Node->getName () << ' \n ' ;
1977
1984
}
1978
1985
}
1979
-
1980
- void SwiftDeclCollector::lookupVisibleDecls (ArrayRef<ModuleDecl *> Modules) {
1986
+ SwiftDeclCollector::SwiftDeclCollector (SDKContext &Ctx,
1987
+ ArrayRef<ModuleDecl*> Modules) : Ctx(Ctx),
1988
+ RootNode(SDKNodeRoot::getInstance(Ctx, Modules)) {
1989
+ if (Modules.empty ()) {
1990
+ return ;
1991
+ }
1992
+ assert (!Modules.empty ());
1981
1993
for (auto M: Modules) {
1982
1994
llvm::SmallVector<Decl*, 512 > Decls;
1983
1995
swift::getTopLevelDeclsForDisplay (M, Decls);
@@ -2544,8 +2556,7 @@ swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,
2544
2556
if (Opts.Verbose )
2545
2557
llvm::errs () << " Scanning symbols...\n " ;
2546
2558
2547
- SwiftDeclCollector Collector (SDKCtx);
2548
- Collector.lookupVisibleDecls (Modules);
2559
+ SwiftDeclCollector Collector (SDKCtx, Modules);
2549
2560
return Collector.getSDKRoot ();
2550
2561
}
2551
2562
@@ -2603,7 +2614,11 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
2603
2614
opts.SkipRemoveDeprecatedCheck = false ;
2604
2615
opts.Verbose = false ;
2605
2616
SDKContext ctx (opts);
2606
- SwiftDeclCollector collector (ctx);
2617
+ llvm::SmallVector<ModuleDecl*, 4 > modules;
2618
+ if (!Empty) {
2619
+ modules.push_back (MD);
2620
+ }
2621
+ SwiftDeclCollector collector (ctx, modules);
2607
2622
ConstExtractor extractor (ctx, MD->getASTContext ());
2608
2623
PayLoad payload;
2609
2624
SWIFT_DEFER {
@@ -2613,7 +2628,6 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
2613
2628
if (Empty) {
2614
2629
return ;
2615
2630
}
2616
- collector.lookupVisibleDecls ({MD});
2617
2631
extractor.extract (MD);
2618
2632
}
2619
2633
0 commit comments