@@ -2125,55 +2125,100 @@ AvailableAttr::AvailableAttr(
21252125 Bits.AvailableAttr .IsSPI = IsSPI;
21262126
21272127 if (IsForEmbedded) {
2128- // FIXME: The IsForEmbedded bit should be removed when library availability
2129- // conditions are implemented (rdar://138802876)
2128+ // FIXME: [availability] The IsForEmbedded bit should be removed when
2129+ // it can be represented with AvailabilityDomain (rdar://138802876)
21302130 Bits.AvailableAttr .IsForEmbedded = true ;
21312131 assert (getPlatform () == PlatformKind::none);
21322132 }
21332133}
21342134
2135+ static PlatformAgnosticAvailabilityKind
2136+ platformAgnosticFromDomainAndKind (const AvailabilityDomain &Domain,
2137+ AvailableAttr::Kind Kind) {
2138+ switch (Kind) {
2139+ case swift::AvailableAttr::Kind::NoAsync:
2140+ return PlatformAgnosticAvailabilityKind::NoAsync;
2141+
2142+ case swift::AvailableAttr::Kind::Default:
2143+ if (Domain.isSwiftLanguage ()) {
2144+ return PlatformAgnosticAvailabilityKind::SwiftVersionSpecific;
2145+ } else if (Domain.isPackageDescription ()) {
2146+ return PlatformAgnosticAvailabilityKind::
2147+ PackageDescriptionVersionSpecific;
2148+ }
2149+ return PlatformAgnosticAvailabilityKind::None;
2150+
2151+ case swift::AvailableAttr::Kind::Deprecated:
2152+ return PlatformAgnosticAvailabilityKind::Deprecated;
2153+
2154+ case swift::AvailableAttr::Kind::Unavailable:
2155+ if (Domain.isSwiftLanguage ()) {
2156+ return PlatformAgnosticAvailabilityKind::UnavailableInSwift;
2157+ } else if (Domain.isUniversal () || Domain.isPlatform ()) {
2158+ return PlatformAgnosticAvailabilityKind::Unavailable;
2159+ }
2160+ llvm_unreachable (" unexpected domain for unavailable attr" );
2161+ }
2162+ }
2163+
2164+ AvailableAttr::AvailableAttr (
2165+ SourceLoc AtLoc, SourceRange Range, const AvailabilityDomain &Domain,
2166+ Kind Kind, StringRef Message, StringRef Rename,
2167+ const llvm::VersionTuple &Introduced, SourceRange IntroducedRange,
2168+ const llvm::VersionTuple &Deprecated, SourceRange DeprecatedRange,
2169+ const llvm::VersionTuple &Obsoleted, SourceRange ObsoletedRange,
2170+ bool Implicit, bool IsSPI, bool IsForEmbedded)
2171+ : AvailableAttr(AtLoc, Range, Domain.getPlatformKind(), Message, Rename,
2172+ Introduced, IntroducedRange, Deprecated, DeprecatedRange,
2173+ Obsoleted, ObsoletedRange,
2174+ platformAgnosticFromDomainAndKind(Domain, Kind), Implicit,
2175+ IsSPI, IsForEmbedded) {}
2176+
21352177#undef INIT_VER_TUPLE
21362178
21372179AvailableAttr *AvailableAttr::createUniversallyUnavailable (ASTContext &C,
21382180 StringRef Message,
21392181 StringRef Rename) {
21402182 return new (C) AvailableAttr (
2141- SourceLoc (), SourceRange (), PlatformKind::none, Message, Rename,
2183+ SourceLoc (), SourceRange (), AvailabilityDomain::forUniversal (),
2184+ Kind::Unavailable, Message, Rename,
21422185 /* Introduced=*/ {}, SourceRange (), /* Deprecated=*/ {}, SourceRange (),
21432186 /* Obsoleted=*/ {}, SourceRange (),
2144- PlatformAgnosticAvailabilityKind::Unavailable, /* Implicit=*/ false ,
2187+ /* Implicit=*/ false ,
21452188 /* SPI=*/ false );
21462189}
21472190
21482191AvailableAttr *AvailableAttr::createUniversallyDeprecated (ASTContext &C,
21492192 StringRef Message,
21502193 StringRef Rename) {
21512194 return new (C) AvailableAttr (
2152- SourceLoc (), SourceRange (), PlatformKind::none, Message, Rename,
2195+ SourceLoc (), SourceRange (), AvailabilityDomain::forUniversal (),
2196+ Kind::Deprecated, Message, Rename,
21532197 /* Introduced=*/ {}, SourceRange (), /* Deprecated=*/ {}, SourceRange (),
21542198 /* Obsoleted=*/ {}, SourceRange (),
2155- PlatformAgnosticAvailabilityKind::Deprecated, /* Implicit=*/ false ,
2199+ /* Implicit=*/ false ,
21562200 /* SPI=*/ false );
21572201}
21582202
21592203AvailableAttr *AvailableAttr::createUnavailableInSwift (ASTContext &C,
21602204 StringRef Message,
21612205 StringRef Rename) {
21622206 return new (C) AvailableAttr (
2163- SourceLoc (), SourceRange (), PlatformKind::none, Message, Rename,
2207+ SourceLoc (), SourceRange (), AvailabilityDomain::forSwiftLanguage (),
2208+ Kind::Unavailable, Message, Rename,
21642209 /* Introduced=*/ {}, SourceRange (), /* Deprecated=*/ {}, SourceRange (),
21652210 /* Obsoleted=*/ {}, SourceRange (),
2166- PlatformAgnosticAvailabilityKind::UnavailableInSwift, /* Implicit=*/ false ,
2211+ /* Implicit=*/ false ,
21672212 /* SPI=*/ false );
21682213}
21692214
21702215AvailableAttr *AvailableAttr::createSwiftLanguageModeVersioned (
21712216 ASTContext &C, StringRef Message, StringRef Rename,
21722217 llvm::VersionTuple Introduced, llvm::VersionTuple Obsoleted) {
21732218 return new (C) AvailableAttr (
2174- SourceLoc (), SourceRange (), PlatformKind::none, Message, Rename ,
2175- Introduced, SourceRange (), /* Deprecated= */ {}, SourceRange (), Obsoleted ,
2176- SourceRange (), PlatformAgnosticAvailabilityKind::SwiftVersionSpecific ,
2219+ SourceLoc (), SourceRange (), AvailabilityDomain::forSwiftLanguage () ,
2220+ Kind::Default, Message, Rename, Introduced, SourceRange (),
2221+ /* Deprecated= */ {}, SourceRange (), Obsoleted, SourceRange () ,
21772222 /* Implicit=*/ false ,
21782223 /* SPI=*/ false );
21792224}
@@ -2182,12 +2227,12 @@ AvailableAttr *AvailableAttr::createPlatformVersioned(
21822227 ASTContext &C, PlatformKind Platform, StringRef Message, StringRef Rename,
21832228 llvm::VersionTuple Introduced, llvm::VersionTuple Deprecated,
21842229 llvm::VersionTuple Obsoleted) {
2185- return new (C) AvailableAttr (SourceLoc (), SourceRange (), Platform, Message,
2186- Rename, Introduced, SourceRange (), Deprecated ,
2187- SourceRange (), Obsoleted , SourceRange (),
2188- PlatformAgnosticAvailabilityKind::None ,
2189- /* Implicit=*/ false ,
2190- /* SPI=*/ false );
2230+ return new (C) AvailableAttr (
2231+ SourceLoc (), SourceRange (), AvailabilityDomain::forPlatform (Platform) ,
2232+ Kind::Default, Message, Rename, Introduced , SourceRange (), Deprecated ,
2233+ SourceRange (), Obsoleted, SourceRange () ,
2234+ /* Implicit=*/ false ,
2235+ /* SPI=*/ false );
21912236}
21922237
21932238bool BackDeployedAttr::isActivePlatform (const ASTContext &ctx,
0 commit comments