@@ -780,6 +780,22 @@ void SourceFile::lookupObjCMethods(
780780 results.append (known->second .begin (), known->second .end ());
781781}
782782
783+ static void collectParsedExportedImports (const ModuleDecl *M, SmallPtrSetImpl<ModuleDecl *> &Imports) {
784+ for (const FileUnit *file : M->getFiles ()) {
785+ if (const SourceFile *source = dyn_cast<SourceFile>(file)) {
786+ if (source->hasImports ()) {
787+ for (auto import : source->getImports ()) {
788+ if (import .options .contains (ImportFlags::Exported)) {
789+ if (!Imports.contains (import .module .importedModule )) {
790+ Imports.insert (import .module .importedModule );
791+ }
792+ }
793+ }
794+ }
795+ }
796+ }
797+ }
798+
783799void ModuleDecl::getLocalTypeDecls (SmallVectorImpl<TypeDecl*> &Results) const {
784800 FORWARD (getLocalTypeDecls, (Results));
785801}
@@ -788,6 +804,24 @@ void ModuleDecl::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
788804 FORWARD (getTopLevelDecls, (Results));
789805}
790806
807+ void ModuleDecl::dumpDisplayDecls () const {
808+ SmallVector<Decl *, 32 > Decls;
809+ getDisplayDecls (Decls);
810+ for (auto *D : Decls) {
811+ D->dump (llvm::errs ());
812+ llvm::errs () << " \n " ;
813+ }
814+ }
815+
816+ void ModuleDecl::dumpTopLevelDecls () const {
817+ SmallVector<Decl *, 32 > Decls;
818+ getTopLevelDecls (Decls);
819+ for (auto *D : Decls) {
820+ D->dump (llvm::errs ());
821+ llvm::errs () << " \n " ;
822+ }
823+ }
824+
791825void ModuleDecl::getExportedPrespecializations (
792826 SmallVectorImpl<Decl *> &Results) const {
793827 FORWARD (getExportedPrespecializations, (Results));
@@ -908,8 +942,23 @@ SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
908942}
909943
910944void ModuleDecl::getDisplayDecls (SmallVectorImpl<Decl*> &Results) const {
945+ if (isParsedModule (this )) {
946+ SmallPtrSet<ModuleDecl *, 4 > Modules;
947+ collectParsedExportedImports (this , Modules);
948+ for (const ModuleDecl *import : Modules) {
949+ import ->getDisplayDecls (Results);
950+ }
951+ }
911952 // FIXME: Should this do extra access control filtering?
912953 FORWARD (getDisplayDecls, (Results));
954+
955+ #ifndef NDEBUG
956+ llvm::DenseSet<Decl *> visited;
957+ for (auto *D : Results) {
958+ auto inserted = visited.insert (D).second ;
959+ assert (inserted && " there should be no duplicate decls" );
960+ }
961+ #endif
913962}
914963
915964ProtocolConformanceRef
@@ -3065,6 +3114,22 @@ void FileUnit::getTopLevelDeclsWhereAttributesMatch(
30653114 Results.erase (newEnd, Results.end ());
30663115}
30673116
3117+ void FileUnit::dumpDisplayDecls () const {
3118+ SmallVector<Decl *, 32 > Decls;
3119+ getDisplayDecls (Decls);
3120+ for (auto *D : Decls) {
3121+ D->dump (llvm::errs ());
3122+ }
3123+ }
3124+
3125+ void FileUnit::dumpTopLevelDecls () const {
3126+ SmallVector<Decl *, 32 > Decls;
3127+ getTopLevelDecls (Decls);
3128+ for (auto *D : Decls) {
3129+ D->dump (llvm::errs ());
3130+ }
3131+ }
3132+
30683133void swift::simple_display (llvm::raw_ostream &out, const FileUnit *file) {
30693134 if (!file) {
30703135 out << " (null)" ;
0 commit comments