@@ -780,6 +780,22 @@ void SourceFile::lookupObjCMethods(
780
780
results.append (known->second .begin (), known->second .end ());
781
781
}
782
782
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
+
783
799
void ModuleDecl::getLocalTypeDecls (SmallVectorImpl<TypeDecl*> &Results) const {
784
800
FORWARD (getLocalTypeDecls, (Results));
785
801
}
@@ -788,6 +804,24 @@ void ModuleDecl::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
788
804
FORWARD (getTopLevelDecls, (Results));
789
805
}
790
806
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
+
791
825
void ModuleDecl::getExportedPrespecializations (
792
826
SmallVectorImpl<Decl *> &Results) const {
793
827
FORWARD (getExportedPrespecializations, (Results));
@@ -908,8 +942,23 @@ SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
908
942
}
909
943
910
944
void 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
+ }
911
952
// FIXME: Should this do extra access control filtering?
912
953
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
913
962
}
914
963
915
964
ProtocolConformanceRef
@@ -3065,6 +3114,22 @@ void FileUnit::getTopLevelDeclsWhereAttributesMatch(
3065
3114
Results.erase (newEnd, Results.end ());
3066
3115
}
3067
3116
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
+
3068
3133
void swift::simple_display (llvm::raw_ostream &out, const FileUnit *file) {
3069
3134
if (!file) {
3070
3135
out << " (null)" ;
0 commit comments