@@ -654,7 +654,7 @@ ClangImporter::create(ASTContext &ctx,
654
654
655
655
// Install a Clang module file extension to build Swift name lookup tables.
656
656
invocation->getFrontendOpts ().ModuleFileExtensions .push_back (
657
- new Implementation:: SwiftNameLookupExtension (importer->Impl ));
657
+ new SwiftNameLookupExtension (importer->Impl ));
658
658
659
659
// Create a compiler instance.
660
660
auto PCHContainerOperations =
@@ -739,10 +739,9 @@ ClangImporter::create(ASTContext &ctx,
739
739
importer->Impl .addBridgeHeaderTopLevelDecls (D);
740
740
741
741
if (auto named = dyn_cast<clang::NamedDecl>(D)) {
742
- importer->Impl .addEntryToLookupTable (
743
- instance.getSema (),
744
- importer->Impl .BridgingHeaderLookupTable ,
745
- named);
742
+ addEntryToLookupTable (instance.getSema (),
743
+ importer->Impl .BridgingHeaderLookupTable , named,
744
+ importer->Impl .nameImporter );
746
745
}
747
746
}
748
747
}
@@ -800,9 +799,10 @@ bool ClangImporter::addSearchPath(StringRef newSearchPath, bool isFramework) {
800
799
return false ;
801
800
}
802
801
803
- void ClangImporter::Implementation::addEntryToLookupTable (
804
- clang::Sema &clangSema, SwiftLookupTable &table, clang::NamedDecl *named,
805
- NameImporter &nameImporter) {
802
+ void importer::addEntryToLookupTable (clang::Sema &clangSema,
803
+ SwiftLookupTable &table,
804
+ clang::NamedDecl *named,
805
+ NameImporter &nameImporter) {
806
806
// Determine whether this declaration is suppressed in Swift.
807
807
if (shouldSuppressDeclImport (named)) return ;
808
808
@@ -863,9 +863,10 @@ void ClangImporter::Implementation::addEntryToLookupTable(
863
863
}
864
864
}
865
865
866
- void ClangImporter::Implementation::addMacrosToLookupTable (
867
- clang::ASTContext &clangCtx, clang::Preprocessor &pp,
868
- SwiftLookupTable &table, ASTContext &SwiftContext) {
866
+ void importer::addMacrosToLookupTable (clang::ASTContext &clangCtx,
867
+ clang::Preprocessor &pp,
868
+ SwiftLookupTable &table,
869
+ ASTContext &SwiftContext) {
869
870
for (const auto ¯o : pp.macros (false )) {
870
871
// Find the local history of this macro directive.
871
872
clang::MacroDirective *MD = pp.getLocalMacroDirectiveHistory (macro.first );
@@ -906,11 +907,10 @@ void ClangImporter::Implementation::addMacrosToLookupTable(
906
907
}
907
908
}
908
909
909
- void ClangImporter::Implementation::finalizeLookupTable (
910
- clang::ASTContext &clangCtx,
911
- clang::Preprocessor &pp,
912
- SwiftLookupTable &table,
913
- ASTContext &SwiftContext) {
910
+ void importer::finalizeLookupTable (clang::ASTContext &clangCtx,
911
+ clang::Preprocessor &pp,
912
+ SwiftLookupTable &table,
913
+ ASTContext &SwiftContext) {
914
914
// Resolve any unresolved entries.
915
915
SmallVector<SwiftLookupTable::SingleEntry, 4 > unresolved;
916
916
if (table.resolveUnresolvedEntries (unresolved)) {
@@ -986,7 +986,8 @@ bool ClangImporter::Implementation::importHeader(
986
986
for (auto group : allParsedDecls)
987
987
for (auto *D : group)
988
988
if (auto named = dyn_cast<clang::NamedDecl>(D))
989
- addEntryToLookupTable (getClangSema (), BridgingHeaderLookupTable, named);
989
+ addEntryToLookupTable (getClangSema (), BridgingHeaderLookupTable, named,
990
+ nameImporter);
990
991
991
992
pp.EndSourceFile ();
992
993
bumpGeneration ();
@@ -1418,50 +1419,6 @@ ClangImporter::Implementation::exportName(Identifier name) {
1418
1419
return ident;
1419
1420
}
1420
1421
1421
- // / Returns true if it is expected that the macro is ignored.
1422
- static bool shouldIgnoreMacro (StringRef name, const clang::MacroInfo *macro) {
1423
- // Ignore include guards.
1424
- if (macro->isUsedForHeaderGuard ())
1425
- return true ;
1426
-
1427
- // If there are no tokens, there is nothing to convert.
1428
- if (macro->tokens_empty ())
1429
- return true ;
1430
-
1431
- // Currently we only convert non-function-like macros.
1432
- if (macro->isFunctionLike ())
1433
- return true ;
1434
-
1435
- // Consult the blacklist of macros to suppress.
1436
- auto suppressMacro =
1437
- llvm::StringSwitch<bool >(name)
1438
- #define SUPPRESS_MACRO (NAME ) .Case(#NAME, true )
1439
- #include " MacroTable.def"
1440
- .Default (false );
1441
-
1442
- if (suppressMacro)
1443
- return true ;
1444
-
1445
- return false ;
1446
- }
1447
-
1448
- bool ClangImporter::shouldIgnoreMacro (StringRef Name,
1449
- const clang::MacroInfo *Macro) {
1450
- return ::shouldIgnoreMacro (Name, Macro);
1451
- }
1452
-
1453
- Identifier ClangImporter::Implementation::importMacroName (
1454
- const clang::IdentifierInfo *clangIdentifier, const clang::MacroInfo *macro,
1455
- clang::ASTContext &clangCtx, ASTContext &SwiftContext) {
1456
- // If we're supposed to ignore this macro, return an empty identifier.
1457
- if (::shouldIgnoreMacro (clangIdentifier->getName (), macro))
1458
- return Identifier ();
1459
-
1460
- // No transformation is applied to the name.
1461
- StringRef name = clangIdentifier->getName ();
1462
- return SwiftContext.getIdentifier (name);
1463
- }
1464
-
1465
1422
namespace llvm {
1466
1423
// An Identifier is "pointer like".
1467
1424
template <typename T> class PointerLikeTypeTraits ;
@@ -1575,8 +1532,7 @@ isPotentiallyConflictingSetter(const clang::ObjCProtocolDecl *proto,
1575
1532
return false ;
1576
1533
}
1577
1534
1578
- bool ClangImporter::Implementation::shouldSuppressDeclImport (
1579
- const clang::Decl *decl) {
1535
+ bool importer::shouldSuppressDeclImport (const clang::Decl *decl) {
1580
1536
if (auto objcMethod = dyn_cast<clang::ObjCMethodDecl>(decl)) {
1581
1537
// First check if we're actually in a Swift class.
1582
1538
auto dc = decl->getDeclContext ();
@@ -1894,8 +1850,7 @@ void ClangImporter::lookupBridgingHeaderDecls(
1894
1850
for (clang::IdentifierInfo *II : Impl.BridgeHeaderMacros ) {
1895
1851
if (auto *MI = ClangPP.getMacroInfo (II)) {
1896
1852
if (filter (MI)) {
1897
- Identifier Name =
1898
- Impl.importMacroName (II, MI, ClangCtx, Impl.SwiftContext );
1853
+ Identifier Name = importMacroName (II, MI, ClangCtx, Impl.SwiftContext );
1899
1854
if (Decl *imported = Impl.importMacro (Name, MI))
1900
1855
receiver (imported);
1901
1856
}
@@ -1973,7 +1928,7 @@ bool ClangImporter::lookupDeclsFromHeader(StringRef Filename,
1973
1928
if (auto *MI = ClangPP.getMacroInfo (II)) {
1974
1929
if (filter (MI)) {
1975
1930
Identifier Name =
1976
- Impl. importMacroName (II, MI, ClangCtx, Impl.SwiftContext );
1931
+ importMacroName (II, MI, ClangCtx, Impl.SwiftContext );
1977
1932
if (Decl *imported = Impl.importMacro (Name, MI))
1978
1933
receiver (imported);
1979
1934
}
@@ -2673,8 +2628,7 @@ void ClangImporter::getMangledName(raw_ostream &os,
2673
2628
// ---------------------------------------------------------------------------
2674
2629
2675
2630
clang::ModuleFileExtensionMetadata
2676
- ClangImporter::Implementation::SwiftNameLookupExtension::
2677
- getExtensionMetadata () const {
2631
+ SwiftNameLookupExtension::getExtensionMetadata () const {
2678
2632
clang::ModuleFileExtensionMetadata metadata;
2679
2633
metadata.BlockName = " swift.lookup" ;
2680
2634
metadata.MajorVersion = SWIFT_LOOKUP_TABLE_VERSION_MAJOR;
@@ -2685,17 +2639,15 @@ getExtensionMetadata() const {
2685
2639
}
2686
2640
2687
2641
llvm::hash_code
2688
- ClangImporter::Implementation::SwiftNameLookupExtension::hashExtension (
2689
- llvm::hash_code code) const {
2642
+ SwiftNameLookupExtension::hashExtension (llvm::hash_code code) const {
2690
2643
return llvm::hash_combine (code, StringRef (" swift.lookup" ),
2691
2644
SWIFT_LOOKUP_TABLE_VERSION_MAJOR,
2692
2645
SWIFT_LOOKUP_TABLE_VERSION_MINOR,
2693
2646
nameImporter.isInferImportAsMember ());
2694
2647
}
2695
2648
2696
2649
std::unique_ptr<clang::ModuleFileExtensionWriter>
2697
- ClangImporter::Implementation::SwiftNameLookupExtension::createExtensionWriter (
2698
- clang::ASTWriter &writer) {
2650
+ SwiftNameLookupExtension::createExtensionWriter (clang::ASTWriter &writer) {
2699
2651
// Local function to populate the lookup table.
2700
2652
auto populateTable = [this ](clang::Sema &sema, SwiftLookupTable &table) {
2701
2653
auto &swiftCtx = nameImporter.getContext ();
@@ -2725,12 +2677,10 @@ ClangImporter::Implementation::SwiftNameLookupExtension::createExtensionWriter(
2725
2677
}
2726
2678
2727
2679
std::unique_ptr<clang::ModuleFileExtensionReader>
2728
- ClangImporter::Implementation::SwiftNameLookupExtension::createExtensionReader (
2729
- const clang::ModuleFileExtensionMetadata &metadata,
2730
- clang::ASTReader &reader,
2731
- clang::serialization::ModuleFile &mod,
2732
- const llvm::BitstreamCursor &stream)
2733
- {
2680
+ SwiftNameLookupExtension::createExtensionReader (
2681
+ const clang::ModuleFileExtensionMetadata &metadata,
2682
+ clang::ASTReader &reader, clang::serialization::ModuleFile &mod,
2683
+ const llvm::BitstreamCursor &stream) {
2734
2684
// Make sure we have a compatible block. Since these values are part
2735
2685
// of the hash, it should never be wrong.
2736
2686
assert (metadata.BlockName == " swift.lookup" );
0 commit comments