@@ -256,128 +256,6 @@ static bool isBetterThan(const SemanticAvailableAttr &newAttr,
256256 prevAttr->getPlatform ());
257257}
258258
259- static const clang::DarwinSDKInfo::RelatedTargetVersionMapping *
260- getFallbackVersionMapping (const ASTContext &Ctx,
261- clang::DarwinSDKInfo::OSEnvPair Kind) {
262- auto *SDKInfo = Ctx.getDarwinSDKInfo ();
263- if (SDKInfo)
264- return SDKInfo->getVersionMapping (Kind);
265-
266- return Ctx.getAuxiliaryDarwinPlatformRemapInfo (Kind);
267- }
268-
269- static std::optional<clang::VersionTuple>
270- getRemappedIntroducedVersionForFallbackPlatform (
271- const ASTContext &Ctx, const llvm::VersionTuple &Version) {
272- const auto *Mapping = getFallbackVersionMapping (
273- Ctx, clang::DarwinSDKInfo::OSEnvPair (
274- llvm::Triple::IOS, llvm::Triple::UnknownEnvironment,
275- llvm::Triple::XROS, llvm::Triple::UnknownEnvironment));
276- if (!Mapping)
277- return std::nullopt ;
278- return Mapping->mapIntroducedAvailabilityVersion (Version);
279- }
280-
281- static std::optional<clang::VersionTuple>
282- getRemappedDeprecatedObsoletedVersionForFallbackPlatform (
283- const ASTContext &Ctx, const llvm::VersionTuple &Version) {
284- const auto *Mapping = getFallbackVersionMapping (
285- Ctx, clang::DarwinSDKInfo::OSEnvPair (
286- llvm::Triple::IOS, llvm::Triple::UnknownEnvironment,
287- llvm::Triple::XROS, llvm::Triple::UnknownEnvironment));
288- if (!Mapping)
289- return std::nullopt ;
290- return Mapping->mapDeprecatedObsoletedAvailabilityVersion (Version);
291- }
292-
293- bool AvailabilityInference::updateIntroducedAvailabilityDomainForFallback (
294- const SemanticAvailableAttr &attr, const ASTContext &ctx,
295- AvailabilityDomain &domain, llvm::VersionTuple &platformVer) {
296- std::optional<llvm::VersionTuple> introducedVersion = attr.getIntroduced ();
297- if (!introducedVersion.has_value ())
298- return false ;
299-
300- bool hasRemap = false ;
301- auto remappedDomain = attr.getDomain ().getRemappedDomain (ctx, hasRemap);
302- if (!hasRemap)
303- return false ;
304-
305- auto potentiallyRemappedIntroducedVersion =
306- getRemappedIntroducedVersionForFallbackPlatform (ctx, *introducedVersion);
307- if (potentiallyRemappedIntroducedVersion.has_value ()) {
308- domain = remappedDomain;
309- platformVer = potentiallyRemappedIntroducedVersion.value ();
310- return true ;
311- }
312- return false ;
313- }
314-
315- bool AvailabilityInference::updateDeprecatedAvailabilityDomainForFallback (
316- const SemanticAvailableAttr &attr, const ASTContext &ctx,
317- AvailabilityDomain &domain, llvm::VersionTuple &platformVer) {
318- std::optional<llvm::VersionTuple> deprecatedVersion = attr.getDeprecated ();
319- if (!deprecatedVersion.has_value ())
320- return false ;
321-
322- bool hasRemap = false ;
323- auto remappedDomain = attr.getDomain ().getRemappedDomain (ctx, hasRemap);
324- if (!hasRemap)
325- return false ;
326-
327- auto potentiallyRemappedDeprecatedVersion =
328- getRemappedDeprecatedObsoletedVersionForFallbackPlatform (
329- ctx, *deprecatedVersion);
330- if (potentiallyRemappedDeprecatedVersion.has_value ()) {
331- domain = remappedDomain;
332- platformVer = potentiallyRemappedDeprecatedVersion.value ();
333- return true ;
334- }
335- return false ;
336- }
337-
338- bool AvailabilityInference::updateObsoletedAvailabilityDomainForFallback (
339- const SemanticAvailableAttr &attr, const ASTContext &ctx,
340- AvailabilityDomain &domain, llvm::VersionTuple &platformVer) {
341- std::optional<llvm::VersionTuple> obsoletedVersion = attr.getObsoleted ();
342- if (!obsoletedVersion.has_value ())
343- return false ;
344-
345- bool hasRemap = false ;
346- auto remappedDomain = attr.getDomain ().getRemappedDomain (ctx, hasRemap);
347- if (!hasRemap)
348- return false ;
349-
350- auto potentiallyRemappedObsoletedVersion =
351- getRemappedDeprecatedObsoletedVersionForFallbackPlatform (
352- ctx, *obsoletedVersion);
353- if (potentiallyRemappedObsoletedVersion.has_value ()) {
354- domain = remappedDomain;
355- platformVer = potentiallyRemappedObsoletedVersion.value ();
356- return true ;
357- }
358- return false ;
359- }
360-
361- bool AvailabilityInference::updateBeforeAvailabilityDomainForFallback (
362- const BackDeployedAttr *attr, const ASTContext &ctx,
363- AvailabilityDomain &domain, llvm::VersionTuple &platformVer) {
364- bool hasRemap = false ;
365- auto remappedDomain =
366- attr->getAvailabilityDomain ().getRemappedDomain (ctx, hasRemap);
367- if (!hasRemap)
368- return false ;
369-
370- auto beforeVersion = attr->getVersion ();
371- auto potentiallyRemappedIntroducedVersion =
372- getRemappedIntroducedVersionForFallbackPlatform (ctx, beforeVersion);
373- if (potentiallyRemappedIntroducedVersion.has_value ()) {
374- domain = remappedDomain;
375- platformVer = potentiallyRemappedIntroducedVersion.value ();
376- return true ;
377- }
378- return false ;
379- }
380-
381259static std::optional<SemanticAvailableAttr>
382260getDeclAvailableAttrForPlatformIntroduction (const Decl *D) {
383261 std::optional<SemanticAvailableAttr> bestAvailAttr;
@@ -917,40 +795,31 @@ std::optional<llvm::VersionTuple> SemanticAvailableAttr::getIntroduced() const {
917795std::optional<AvailabilityDomainAndRange>
918796SemanticAvailableAttr::getIntroducedDomainAndRange (
919797 const ASTContext &Ctx) const {
920- auto *attr = getParsedAttr ();
921798 auto domain = getDomain ();
922-
923799 if (domain.isUniversal ())
924800 return std::nullopt ;
925801
926- if (!attr->getRawIntroduced ().has_value ()) {
927- // For versioned domains, an "introduced:" version is always required to
928- // indicate introduction.
929- if (domain.isVersioned ())
930- return std::nullopt ;
802+ if (auto introduced = getIntroduced ())
803+ return domain.getRemappedDomainAndRange (
804+ *introduced, AvailabilityVersionKind::Introduced, Ctx);
931805
932- // For version-less domains, an attribute that does not indicate some other
933- // kind of unconditional availability constraint implicitly specifies that
934- // the decl is available in all versions of the domain.
935- switch (attr->getKind ()) {
936- case AvailableAttr::Kind::Default:
937- return AvailabilityDomainAndRange (domain.getRemappedDomain (Ctx),
938- AvailabilityRange::alwaysAvailable ());
939- case AvailableAttr::Kind::Deprecated:
940- case AvailableAttr::Kind::Unavailable:
941- case AvailableAttr::Kind::NoAsync:
942- return std::nullopt ;
943- }
944- }
945-
946- llvm::VersionTuple introducedVersion = getIntroduced ().value ();
947- llvm::VersionTuple remappedVersion;
948- if (AvailabilityInference::updateIntroducedAvailabilityDomainForFallback (
949- *this , Ctx, domain, remappedVersion))
950- introducedVersion = remappedVersion;
806+ // For versioned domains, an "introduced:" version is always required to
807+ // indicate introduction.
808+ if (domain.isVersioned ())
809+ return std::nullopt ;
951810
952- return AvailabilityDomainAndRange (domain,
953- AvailabilityRange{introducedVersion});
811+ // For version-less domains, an attribute that does not indicate some other
812+ // kind of unconditional availability constraint implicitly specifies that
813+ // the decl is available in all versions of the domain.
814+ switch (attr->getKind ()) {
815+ case AvailableAttr::Kind::Default:
816+ return AvailabilityDomainAndRange (domain.getRemappedDomain (Ctx),
817+ AvailabilityRange::alwaysAvailable ());
818+ case AvailableAttr::Kind::Deprecated:
819+ case AvailableAttr::Kind::Unavailable:
820+ case AvailableAttr::Kind::NoAsync:
821+ return std::nullopt ;
822+ }
954823}
955824
956825std::optional<llvm::VersionTuple> SemanticAvailableAttr::getDeprecated () const {
@@ -962,28 +831,18 @@ std::optional<llvm::VersionTuple> SemanticAvailableAttr::getDeprecated() const {
962831std::optional<AvailabilityDomainAndRange>
963832SemanticAvailableAttr::getDeprecatedDomainAndRange (
964833 const ASTContext &Ctx) const {
965- auto *attr = getParsedAttr ();
966- AvailabilityDomain domain = getDomain ();
967-
968- if (!attr->getRawDeprecated ().has_value ()) {
969- // Regardless of the whether the domain supports versions or not, an
970- // unconditional deprecation attribute indicates the decl is always
971- // deprecated.
972- if (isUnconditionallyDeprecated ())
973- return AvailabilityDomainAndRange (domain.getRemappedDomain (Ctx),
974- AvailabilityRange::alwaysAvailable ());
975-
976- return std::nullopt ;
977- }
834+ if (auto deprecated = getDeprecated ())
835+ return getDomain ().getRemappedDomainAndRange (
836+ *deprecated, AvailabilityVersionKind::Deprecated, Ctx);
978837
979- llvm::VersionTuple deprecatedVersion = getDeprecated ().value ();
980- llvm::VersionTuple remappedVersion;
981- if (AvailabilityInference::updateDeprecatedAvailabilityDomainForFallback (
982- *this , Ctx, domain, remappedVersion))
983- deprecatedVersion = remappedVersion;
838+ // Regardless of the whether the domain supports versions or not, an
839+ // unconditional deprecation attribute indicates the decl is always
840+ // deprecated.
841+ if (isUnconditionallyDeprecated ())
842+ return AvailabilityDomainAndRange (getDomain ().getRemappedDomain (Ctx),
843+ AvailabilityRange::alwaysAvailable ());
984844
985- return AvailabilityDomainAndRange (domain,
986- AvailabilityRange{deprecatedVersion});
845+ return std::nullopt ;
987846}
988847
989848std::optional<llvm::VersionTuple> SemanticAvailableAttr::getObsoleted () const {
@@ -994,26 +853,16 @@ std::optional<llvm::VersionTuple> SemanticAvailableAttr::getObsoleted() const {
994853
995854std::optional<AvailabilityDomainAndRange>
996855SemanticAvailableAttr::getObsoletedDomainAndRange (const ASTContext &Ctx) const {
997- auto *attr = getParsedAttr ();
998- AvailabilityDomain domain = getDomain ();
999-
1000- if (!attr->getRawObsoleted ().has_value ()) {
1001- // An "unavailable" attribute effectively means obsolete in all versions.
1002- if (attr->isUnconditionallyUnavailable ())
1003- return AvailabilityDomainAndRange (domain.getRemappedDomain (Ctx),
1004- AvailabilityRange::alwaysAvailable ());
856+ if (auto obsoleted = getObsoleted ())
857+ return getDomain ().getRemappedDomainAndRange (
858+ *obsoleted, AvailabilityVersionKind::Obsoleted, Ctx);
1005859
1006- return std::nullopt ;
1007- }
860+ // An "unavailable" attribute effectively means obsolete in all versions.
861+ if (isUnconditionallyUnavailable ())
862+ return AvailabilityDomainAndRange (getDomain ().getRemappedDomain (Ctx),
863+ AvailabilityRange::alwaysAvailable ());
1008864
1009- llvm::VersionTuple obsoletedVersion = getObsoleted ().value ();
1010- llvm::VersionTuple remappedVersion;
1011- if (AvailabilityInference::updateObsoletedAvailabilityDomainForFallback (
1012- *this , Ctx, domain, remappedVersion))
1013- obsoletedVersion = remappedVersion;
1014-
1015- return AvailabilityDomainAndRange (domain,
1016- AvailabilityRange{obsoletedVersion});
865+ return std::nullopt ;
1017866}
1018867
1019868namespace {
0 commit comments