@@ -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
@@ -3060,6 +3109,22 @@ void FileUnit::getTopLevelDeclsWhereAttributesMatch(
30603109 Results.erase (newEnd, Results.end ());
30613110}
30623111
3112+ void FileUnit::dumpDisplayDecls () const {
3113+ SmallVector<Decl *, 32 > Decls;
3114+ getDisplayDecls (Decls);
3115+ for (auto *D : Decls) {
3116+ D->dump (llvm::errs ());
3117+ }
3118+ }
3119+
3120+ void FileUnit::dumpTopLevelDecls () const {
3121+ SmallVector<Decl *, 32 > Decls;
3122+ getTopLevelDecls (Decls);
3123+ for (auto *D : Decls) {
3124+ D->dump (llvm::errs ());
3125+ }
3126+ }
3127+
30633128void swift::simple_display (llvm::raw_ostream &out, const FileUnit *file) {
30643129 if (!file) {
30653130 out << " (null)" ;
0 commit comments