@@ -2125,55 +2125,100 @@ AvailableAttr::AvailableAttr(
2125
2125
Bits.AvailableAttr .IsSPI = IsSPI;
2126
2126
2127
2127
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)
2130
2130
Bits.AvailableAttr .IsForEmbedded = true ;
2131
2131
assert (getPlatform () == PlatformKind::none);
2132
2132
}
2133
2133
}
2134
2134
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
+
2135
2177
#undef INIT_VER_TUPLE
2136
2178
2137
2179
AvailableAttr *AvailableAttr::createUniversallyUnavailable (ASTContext &C,
2138
2180
StringRef Message,
2139
2181
StringRef Rename) {
2140
2182
return new (C) AvailableAttr (
2141
- SourceLoc (), SourceRange (), PlatformKind::none, Message, Rename,
2183
+ SourceLoc (), SourceRange (), AvailabilityDomain::forUniversal (),
2184
+ Kind::Unavailable, Message, Rename,
2142
2185
/* Introduced=*/ {}, SourceRange (), /* Deprecated=*/ {}, SourceRange (),
2143
2186
/* Obsoleted=*/ {}, SourceRange (),
2144
- PlatformAgnosticAvailabilityKind::Unavailable, /* Implicit=*/ false ,
2187
+ /* Implicit=*/ false ,
2145
2188
/* SPI=*/ false );
2146
2189
}
2147
2190
2148
2191
AvailableAttr *AvailableAttr::createUniversallyDeprecated (ASTContext &C,
2149
2192
StringRef Message,
2150
2193
StringRef Rename) {
2151
2194
return new (C) AvailableAttr (
2152
- SourceLoc (), SourceRange (), PlatformKind::none, Message, Rename,
2195
+ SourceLoc (), SourceRange (), AvailabilityDomain::forUniversal (),
2196
+ Kind::Deprecated, Message, Rename,
2153
2197
/* Introduced=*/ {}, SourceRange (), /* Deprecated=*/ {}, SourceRange (),
2154
2198
/* Obsoleted=*/ {}, SourceRange (),
2155
- PlatformAgnosticAvailabilityKind::Deprecated, /* Implicit=*/ false ,
2199
+ /* Implicit=*/ false ,
2156
2200
/* SPI=*/ false );
2157
2201
}
2158
2202
2159
2203
AvailableAttr *AvailableAttr::createUnavailableInSwift (ASTContext &C,
2160
2204
StringRef Message,
2161
2205
StringRef Rename) {
2162
2206
return new (C) AvailableAttr (
2163
- SourceLoc (), SourceRange (), PlatformKind::none, Message, Rename,
2207
+ SourceLoc (), SourceRange (), AvailabilityDomain::forSwiftLanguage (),
2208
+ Kind::Unavailable, Message, Rename,
2164
2209
/* Introduced=*/ {}, SourceRange (), /* Deprecated=*/ {}, SourceRange (),
2165
2210
/* Obsoleted=*/ {}, SourceRange (),
2166
- PlatformAgnosticAvailabilityKind::UnavailableInSwift, /* Implicit=*/ false ,
2211
+ /* Implicit=*/ false ,
2167
2212
/* SPI=*/ false );
2168
2213
}
2169
2214
2170
2215
AvailableAttr *AvailableAttr::createSwiftLanguageModeVersioned (
2171
2216
ASTContext &C, StringRef Message, StringRef Rename,
2172
2217
llvm::VersionTuple Introduced, llvm::VersionTuple Obsoleted) {
2173
2218
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 () ,
2177
2222
/* Implicit=*/ false ,
2178
2223
/* SPI=*/ false );
2179
2224
}
@@ -2182,12 +2227,12 @@ AvailableAttr *AvailableAttr::createPlatformVersioned(
2182
2227
ASTContext &C, PlatformKind Platform, StringRef Message, StringRef Rename,
2183
2228
llvm::VersionTuple Introduced, llvm::VersionTuple Deprecated,
2184
2229
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 );
2191
2236
}
2192
2237
2193
2238
bool BackDeployedAttr::isActivePlatform (const ASTContext &ctx,
0 commit comments