@@ -1684,65 +1684,88 @@ ModuleDecl *ClangImporter::getImportedHeaderModule() const {
1684
1684
return Impl.ImportedHeaderUnit ->getParentModule ();
1685
1685
}
1686
1686
1687
- PlatformAvailability::PlatformAvailability (LangOptions &langOpts) {
1688
- // Add filters to determine if a Clang availability attribute
1689
- // applies in Swift, and if so, what is the cutoff for deprecated
1690
- // declarations that are now considered unavailable in Swift.
1691
-
1692
- if (langOpts.Target .isiOS () && !langOpts.Target .isTvOS ()) {
1693
- if (!langOpts.EnableAppExtensionRestrictions ) {
1694
- filter = [](StringRef Platform) { return Platform == " ios" ; };
1695
- } else {
1696
- filter = [](StringRef Platform) {
1697
- return Platform == " ios" || Platform == " ios_app_extension" ;
1698
- };
1699
- }
1700
- // Anything deprecated in iOS 7.x and earlier is unavailable in Swift.
1701
- deprecatedAsUnavailableFilter = [](
1702
- unsigned major, llvm::Optional<unsigned > minor) { return major <= 7 ; };
1687
+ PlatformAvailability::PlatformAvailability (LangOptions &langOpts)
1688
+ : platformKind(targetPlatform(langOpts)) {
1689
+ switch (platformKind) {
1690
+ case PlatformKind::iOS:
1691
+ case PlatformKind::iOSApplicationExtension:
1692
+ case PlatformKind::tvOS:
1693
+ case PlatformKind::tvOSApplicationExtension:
1703
1694
deprecatedAsUnavailableMessage =
1704
1695
" APIs deprecated as of iOS 7 and earlier are unavailable in Swift" ;
1705
- } else if (langOpts.Target .isTvOS ()) {
1706
- if (!langOpts.EnableAppExtensionRestrictions ) {
1707
- filter = [](StringRef Platform) { return Platform == " tvos" ; };
1708
- } else {
1709
- filter = [](StringRef Platform) {
1710
- return Platform == " tvos" || Platform == " tvos_app_extension" ;
1711
- };
1712
- }
1713
- // Anything deprecated in iOS 7.x and earlier is unavailable in Swift.
1714
- deprecatedAsUnavailableFilter = [](
1715
- unsigned major, llvm::Optional<unsigned > minor) { return major <= 7 ; };
1716
- deprecatedAsUnavailableMessage =
1717
- " APIs deprecated as of iOS 7 and earlier are unavailable in Swift" ;
1718
- } else if (langOpts.Target .isWatchOS ()) {
1719
- if (!langOpts.EnableAppExtensionRestrictions ) {
1720
- filter = [](StringRef Platform) { return Platform == " watchos" ; };
1721
- } else {
1722
- filter = [](StringRef Platform) {
1723
- return Platform == " watchos" || Platform == " watchos_app_extension" ;
1724
- };
1725
- }
1726
- // No deprecation filter on watchOS
1727
- deprecatedAsUnavailableFilter = [](
1728
- unsigned major, llvm::Optional<unsigned > minor) { return false ; };
1696
+ break ;
1697
+
1698
+ case PlatformKind::watchOS:
1699
+ case PlatformKind::watchOSApplicationExtension:
1729
1700
deprecatedAsUnavailableMessage = " " ;
1730
- } else if (langOpts.Target .isMacOSX ()) {
1731
- if (!langOpts.EnableAppExtensionRestrictions ) {
1732
- filter = [](StringRef Platform) { return Platform == " macos" ; };
1733
- } else {
1734
- filter = [](StringRef Platform) {
1735
- return Platform == " macos" || Platform == " macos_app_extension" ;
1736
- };
1737
- }
1738
- // Anything deprecated in OSX 10.9.x and earlier is unavailable in Swift.
1739
- deprecatedAsUnavailableFilter = [](unsigned major,
1740
- llvm::Optional<unsigned > minor) {
1741
- return major < 10 ||
1742
- (major == 10 && (!minor.hasValue () || minor.getValue () <= 9 ));
1743
- };
1701
+ break ;
1702
+
1703
+ case PlatformKind::OSX:
1704
+ case PlatformKind::OSXApplicationExtension:
1744
1705
deprecatedAsUnavailableMessage =
1745
1706
" APIs deprecated as of OS X 10.9 and earlier are unavailable in Swift" ;
1707
+ break ;
1708
+
1709
+ default :
1710
+ break ;
1711
+ }
1712
+ }
1713
+
1714
+ bool PlatformAvailability::isPlatformRelevant (StringRef name) const {
1715
+ switch (platformKind) {
1716
+ case PlatformKind::OSX:
1717
+ return name == " macos" ;
1718
+ case PlatformKind::OSXApplicationExtension:
1719
+ return name == " macos" || name == " macos_app_extension" ;
1720
+
1721
+ case PlatformKind::iOS:
1722
+ return name == " ios" ;
1723
+ case PlatformKind::iOSApplicationExtension:
1724
+ return name == " ios" || name == " ios_app_extension" ;
1725
+
1726
+ case PlatformKind::tvOS:
1727
+ return name == " tvos" ;
1728
+ case PlatformKind::tvOSApplicationExtension:
1729
+ return name == " tvos" || name == " tvos_app_extension" ;
1730
+
1731
+ case PlatformKind::watchOS:
1732
+ return name == " watchos" ;
1733
+ case PlatformKind::watchOSApplicationExtension:
1734
+ return name == " watchos" || name == " watchos_app_extension" ;
1735
+
1736
+ case PlatformKind::none:
1737
+ return false ;
1738
+ }
1739
+
1740
+ llvm_unreachable (" Unexpected platform" );
1741
+ }
1742
+
1743
+ bool PlatformAvailability::treatDeprecatedAsUnavailable (
1744
+ const clang::Decl *clangDecl, const llvm::VersionTuple &version) const {
1745
+ assert (!version.empty () && " Must provide version when deprecated" );
1746
+ unsigned major = version.getMajor ();
1747
+ Optional<unsigned > minor = version.getMinor ();
1748
+
1749
+ switch (platformKind) {
1750
+ case PlatformKind::OSX:
1751
+ // Anything deprecated in OSX 10.9.x and earlier is unavailable in Swift.
1752
+ return major < 10 ||
1753
+ (major == 10 && (!minor.hasValue () || minor.getValue () <= 9 ));
1754
+
1755
+ case PlatformKind::iOS:
1756
+ case PlatformKind::iOSApplicationExtension:
1757
+ case PlatformKind::tvOS:
1758
+ case PlatformKind::tvOSApplicationExtension:
1759
+ // Anything deprecated in iOS 7.x and earlier is unavailable in Swift.
1760
+ return major <= 7 ;
1761
+
1762
+ case PlatformKind::watchOS:
1763
+ case PlatformKind::watchOSApplicationExtension:
1764
+ // No deprecation filter on watchOS
1765
+ return false ;
1766
+
1767
+ default :
1768
+ return false ;
1746
1769
}
1747
1770
}
1748
1771
0 commit comments