@@ -812,131 +812,6 @@ bool ClangImporter::addSearchPath(StringRef newSearchPath, bool isFramework) {
812
812
return false ;
813
813
}
814
814
815
- void importer::addEntryToLookupTable (SwiftLookupTable &table,
816
- clang::NamedDecl *named,
817
- NameImporter &nameImporter) {
818
- // Determine whether this declaration is suppressed in Swift.
819
- if (shouldSuppressDeclImport (named)) return ;
820
-
821
- // Leave incomplete struct/enum/union types out of the table; Swift only
822
- // handles pointers to them.
823
- // FIXME: At some point we probably want to be importing incomplete types,
824
- // so that pointers to different incomplete types themselves have distinct
825
- // types. At that time it will be necessary to make the decision of whether
826
- // or not to import an incomplete type declaration based on whether it's
827
- // actually the struct backing a CF type:
828
- //
829
- // typedef struct CGColor *CGColorRef;
830
- //
831
- // The best way to do this is probably to change CFDatabase.def to include
832
- // struct names when relevant, not just pointer names. That way we can check
833
- // both CFDatabase.def and the objc_bridge attribute and cover all our bases.
834
- if (auto *tagDecl = dyn_cast<clang::TagDecl>(named)) {
835
- if (!tagDecl->getDefinition ())
836
- return ;
837
- }
838
-
839
- // If we have a name to import as, add this entry to the table.
840
- if (auto importedName = nameImporter.importName (named, None)) {
841
- table.addEntry (importedName.Imported , named, importedName.EffectiveContext );
842
-
843
- // Also add the subscript entry, if needed.
844
- if (importedName.isSubscriptAccessor ())
845
- table.addEntry (DeclName (nameImporter.getContext (),
846
- nameImporter.getContext ().Id_subscript ,
847
- ArrayRef<Identifier>()),
848
- named, importedName.EffectiveContext );
849
-
850
- // Import the Swift 2 name of this entity, and record it as well if it is
851
- // different.
852
- if (auto swift2Name =
853
- nameImporter.importName (named, ImportNameFlags::Swift2Name)) {
854
- if (swift2Name.Imported != importedName.Imported )
855
- table.addEntry (swift2Name.Imported , named, swift2Name.EffectiveContext );
856
- }
857
- } else if (auto category = dyn_cast<clang::ObjCCategoryDecl>(named)) {
858
- // If the category is invalid, don't add it.
859
- if (category->isInvalidDecl ()) return ;
860
-
861
- table.addCategory (category);
862
- }
863
-
864
- // Walk the members of any context that can have nested members.
865
- if (isa<clang::TagDecl>(named) ||
866
- isa<clang::ObjCInterfaceDecl>(named) ||
867
- isa<clang::ObjCProtocolDecl>(named) ||
868
- isa<clang::ObjCCategoryDecl>(named)) {
869
- clang::DeclContext *dc = cast<clang::DeclContext>(named);
870
- for (auto member : dc->decls ()) {
871
- if (auto namedMember = dyn_cast<clang::NamedDecl>(member))
872
- addEntryToLookupTable (table, namedMember, nameImporter);
873
- }
874
- }
875
- }
876
-
877
- void importer::addMacrosToLookupTable (clang::ASTContext &clangCtx,
878
- clang::Preprocessor &pp,
879
- SwiftLookupTable &table,
880
- ASTContext &SwiftContext) {
881
- for (const auto ¯o : pp.macros (false )) {
882
- // Find the local history of this macro directive.
883
- clang::MacroDirective *MD = pp.getLocalMacroDirectiveHistory (macro.first );
884
-
885
- // Walk the history.
886
- for (; MD; MD = MD->getPrevious ()) {
887
- // Don't look at any definitions that are followed by undefs.
888
- // FIXME: This isn't quite correct across explicit submodules -- one
889
- // submodule might define a macro, while another defines and then
890
- // undefines the same macro. If they are processed in that order, the
891
- // history will have the undef at the end, and we'll miss the first
892
- // definition.
893
- if (isa<clang::UndefMacroDirective>(MD))
894
- break ;
895
-
896
- // Only interested in macro definitions.
897
- auto *defMD = dyn_cast<clang::DefMacroDirective>(MD);
898
- if (!defMD) continue ;
899
-
900
- // Is this definition from this module?
901
- auto info = defMD->getInfo ();
902
- if (!info || info->isFromASTFile ()) continue ;
903
-
904
- // If we hit a builtin macro, we're done.
905
- if (info->isBuiltinMacro ()) break ;
906
-
907
- // If we hit a macro with invalid or predefined location, we're done.
908
- auto loc = defMD->getLocation ();
909
- if (loc.isInvalid ()) break ;
910
- if (pp.getSourceManager ().getFileID (loc) == pp.getPredefinesFileID ())
911
- break ;
912
-
913
- // Add this entry.
914
- auto name = importMacroName (macro.first , info, clangCtx, SwiftContext);
915
- if (name.empty ()) continue ;
916
- table.addEntry (name, info, clangCtx.getTranslationUnitDecl (), &pp);
917
- }
918
- }
919
- }
920
-
921
- void importer::finalizeLookupTable (clang::ASTContext &clangCtx,
922
- clang::Preprocessor &pp,
923
- SwiftLookupTable &table,
924
- ASTContext &SwiftContext) {
925
- // Resolve any unresolved entries.
926
- SmallVector<SwiftLookupTable::SingleEntry, 4 > unresolved;
927
- if (table.resolveUnresolvedEntries (unresolved)) {
928
- // Complain about unresolved entries that remain.
929
- for (auto entry : unresolved) {
930
- auto decl = entry.get <clang::NamedDecl *>();
931
- auto swiftName = decl->getAttr <clang::SwiftNameAttr>();
932
-
933
- SwiftContext.Diags .diagnose (SourceLoc (), diag::unresolvable_clang_decl,
934
- decl->getNameAsString (),
935
- swiftName->getName ());
936
- }
937
- }
938
- }
939
-
940
815
bool ClangImporter::Implementation::importHeader (
941
816
Module *adapter, StringRef headerName, SourceLoc diagLoc,
942
817
bool trackParsedSymbols,
@@ -997,14 +872,14 @@ bool ClangImporter::Implementation::importHeader(
997
872
for (auto group : allParsedDecls)
998
873
for (auto *D : group)
999
874
if (auto named = dyn_cast<clang::NamedDecl>(D))
1000
- addEntryToLookupTable (BridgingHeaderLookupTable, named, *nameImporter);
875
+ addEntryToLookupTable (BridgingHeaderLookupTable, named,
876
+ getNameImporter ());
1001
877
1002
878
pp.EndSourceFile ();
1003
879
bumpGeneration ();
1004
880
1005
881
// Add any defined macros to the bridging header lookup table.
1006
- addMacrosToLookupTable (getClangASTContext (), getClangPreprocessor (),
1007
- BridgingHeaderLookupTable, SwiftContext);
882
+ addMacrosToLookupTable (BridgingHeaderLookupTable, getNameImporter ());
1008
883
1009
884
// Wrap all Clang imports under a Swift import decl.
1010
885
for (auto &Import : BridgeHeaderTopLevelImports) {
@@ -1014,8 +889,7 @@ bool ClangImporter::Implementation::importHeader(
1014
889
}
1015
890
1016
891
// Finalize the lookup table, which may fail.
1017
- finalizeLookupTable (getClangASTContext (), getClangPreprocessor (),
1018
- BridgingHeaderLookupTable, SwiftContext);
892
+ finalizeLookupTable (BridgingHeaderLookupTable, getNameImporter ());
1019
893
1020
894
// FIXME: What do we do if there was already an error?
1021
895
if (!hadError && clangDiags.hasErrorOccurred ()) {
@@ -1854,12 +1728,11 @@ void ClangImporter::lookupBridgingHeaderDecls(
1854
1728
}
1855
1729
}
1856
1730
1857
- auto &ClangCtx = Impl.getClangASTContext ();
1858
1731
auto &ClangPP = Impl.getClangPreprocessor ();
1859
1732
for (clang::IdentifierInfo *II : Impl.BridgeHeaderMacros ) {
1860
1733
if (auto *MI = ClangPP.getMacroInfo (II)) {
1861
1734
if (filter (MI)) {
1862
- Identifier Name = importMacroName (II, MI, ClangCtx, Impl. SwiftContext );
1735
+ Identifier Name = Impl. getNameImporter (). importMacroName (II, MI);
1863
1736
if (Decl *imported = Impl.importMacro (Name, MI))
1864
1737
receiver (imported);
1865
1738
}
@@ -1936,8 +1809,7 @@ bool ClangImporter::lookupDeclsFromHeader(StringRef Filename,
1936
1809
auto *II = const_cast <clang::IdentifierInfo*>(MD->getName ());
1937
1810
if (auto *MI = ClangPP.getMacroInfo (II)) {
1938
1811
if (filter (MI)) {
1939
- Identifier Name =
1940
- importMacroName (II, MI, ClangCtx, Impl.SwiftContext );
1812
+ Identifier Name = Impl.getNameImporter ().importMacroName (II, MI);
1941
1813
if (Decl *imported = Impl.importMacro (Name, MI))
1942
1814
receiver (imported);
1943
1815
}
@@ -2324,7 +2196,7 @@ void ClangModuleUnit::lookupObjCMethods(
2324
2196
results.push_back (func);
2325
2197
2326
2198
// If there is an alternate declaration, also look at it.
2327
- if (auto alternate = owner.Impl .getAlternateDecl (imported)) {
2199
+ for (auto alternate : owner.Impl .getAlternateDecls (imported)) {
2328
2200
if (auto func = dyn_cast<AbstractFunctionDecl>(alternate))
2329
2201
results.push_back (func);
2330
2202
}
@@ -2713,7 +2585,7 @@ void ClangImporter::Implementation::lookupValue(
2713
2585
2714
2586
// If there is an alternate declaration and the name matches,
2715
2587
// report this result.
2716
- if (auto alternate = getAlternateDecl (decl)) {
2588
+ for (auto alternate : getAlternateDecls (decl)) {
2717
2589
if (alternate->getFullName ().matchesRef (name) &&
2718
2590
alternate->getDeclContext ()->isModuleScopeContext ()) {
2719
2591
consumer.foundDecl (alternate, DeclVisibilityKind::VisibleAtTopLevel);
@@ -2777,7 +2649,7 @@ void ClangImporter::Implementation::lookupObjCMembers(
2777
2649
2778
2650
// Check for an alternate declaration; if it's name matches,
2779
2651
// report it.
2780
- if (auto alternate = getAlternateDecl (decl)) {
2652
+ for (auto alternate : getAlternateDecls (decl)) {
2781
2653
if (alternate->getFullName ().matchesRef (name)) {
2782
2654
consumer.foundDecl (alternate, DeclVisibilityKind::DynamicLookup);
2783
2655
matchedAny = true ;
0 commit comments