@@ -428,10 +428,17 @@ StringRef SDKNodeType::getTypeRoleDescription() const {
428428 llvm_unreachable (" Unhandled SDKNodeKind in switch" );
429429}
430430
431- SDKNode *SDKNodeRoot::getInstance (SDKContext &Ctx) {
431+ SDKNode *SDKNodeRoot::getInstance (SDKContext &Ctx, ArrayRef<ModuleDecl*> modules ) {
432432 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;
435442 llvm::transform (Ctx.getOpts ().ToolArgs , std::back_inserter (Info.ToolArgs ),
436443 [&](std::string s) { return Ctx.buffer (s); });
437444 Info.JsonFormatVer = DIGESTER_JSON_VERSION;
@@ -1976,8 +1983,13 @@ void SwiftDeclCollector::printTopLevelNames() {
19761983 llvm::outs () << Node->getKind () << " : " << Node->getName () << ' \n ' ;
19771984 }
19781985}
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 ());
19811993 for (auto M: Modules) {
19821994 llvm::SmallVector<Decl*, 512 > Decls;
19831995 swift::getTopLevelDeclsForDisplay (M, Decls);
@@ -2544,8 +2556,7 @@ swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,
25442556 if (Opts.Verbose )
25452557 llvm::errs () << " Scanning symbols...\n " ;
25462558
2547- SwiftDeclCollector Collector (SDKCtx);
2548- Collector.lookupVisibleDecls (Modules);
2559+ SwiftDeclCollector Collector (SDKCtx, Modules);
25492560 return Collector.getSDKRoot ();
25502561}
25512562
@@ -2603,7 +2614,11 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
26032614 opts.SkipRemoveDeprecatedCheck = false ;
26042615 opts.Verbose = false ;
26052616 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);
26072622 ConstExtractor extractor (ctx, MD->getASTContext ());
26082623 PayLoad payload;
26092624 SWIFT_DEFER {
@@ -2613,7 +2628,6 @@ void swift::ide::api::dumpModuleContent(ModuleDecl *MD, llvm::raw_ostream &os,
26132628 if (Empty) {
26142629 return ;
26152630 }
2616- collector.lookupVisibleDecls ({MD});
26172631 extractor.extract (MD);
26182632}
26192633
0 commit comments