@@ -333,8 +333,7 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
333333
334334 StringRef Message, Renamed;
335335 VersionArg Introduced, Deprecated, Obsoleted;
336- auto PlatformAgnostic = PlatformAgnosticAvailabilityKind::None;
337-
336+ auto AttrKind = AvailableAttr::Kind::Default;
338337 bool HasUpcomingEntry = false ;
339338
340339 {
@@ -377,24 +376,16 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
377376 .Default (IsInvalid);
378377 }
379378
380- auto platformAgnosticKindToStr = [](PlatformAgnosticAvailabilityKind kind) {
379+ auto attrKindToStr = [](AvailableAttr::Kind kind) {
381380 switch (kind) {
382- case PlatformAgnosticAvailabilityKind::None :
383- return " none " ;
384- case PlatformAgnosticAvailabilityKind ::Deprecated:
381+ case AvailableAttr::Kind::Default :
382+ return " default " ;
383+ case AvailableAttr::Kind ::Deprecated:
385384 return " deprecated" ;
386- case PlatformAgnosticAvailabilityKind ::Unavailable:
385+ case AvailableAttr::Kind ::Unavailable:
387386 return " unavailable" ;
388- case PlatformAgnosticAvailabilityKind ::NoAsync:
387+ case AvailableAttr::Kind ::NoAsync:
389388 return " noasync" ;
390-
391- // These are possible platform agnostic availability kinds.
392- // I'm not sure what their spellings are at the moment, so I'm
393- // crashing instead of handling them.
394- case PlatformAgnosticAvailabilityKind::UnavailableInSwift:
395- case PlatformAgnosticAvailabilityKind::SwiftVersionSpecific:
396- case PlatformAgnosticAvailabilityKind::PackageDescriptionVersionSpecific:
397- llvm_unreachable (" Unknown availability kind for parser" );
398389 }
399390 };
400391
@@ -471,12 +462,12 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
471462
472463 case IsDeprecated:
473464 if (!findAttrValueDelimiter ()) {
474- if (PlatformAgnostic != PlatformAgnosticAvailabilityKind::None ) {
465+ if (AttrKind != AvailableAttr::Kind::Default ) {
475466 diagnose (Tok, diag::attr_availability_multiple_kinds, AttrName,
476- " deprecated" , platformAgnosticKindToStr (PlatformAgnostic ));
467+ " deprecated" , attrKindToStr (AttrKind ));
477468 }
478469
479- PlatformAgnostic = PlatformAgnosticAvailabilityKind ::Deprecated;
470+ AttrKind = AvailableAttr::Kind ::Deprecated;
480471 break ;
481472 }
482473 LLVM_FALLTHROUGH;
@@ -517,20 +508,21 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
517508 }
518509
519510 case IsUnavailable:
520- if (PlatformAgnostic != PlatformAgnosticAvailabilityKind::None ) {
511+ if (AttrKind != AvailableAttr::Kind::Default ) {
521512 diagnose (Tok, diag::attr_availability_multiple_kinds, AttrName,
522- " unavailable" , platformAgnosticKindToStr (PlatformAgnostic ));
513+ " unavailable" , attrKindToStr (AttrKind ));
523514 }
524515
525- PlatformAgnostic = PlatformAgnosticAvailabilityKind ::Unavailable;
516+ AttrKind = AvailableAttr::Kind ::Unavailable;
526517 break ;
527518
528519 case IsNoAsync:
529- if (PlatformAgnostic != PlatformAgnosticAvailabilityKind::None ) {
520+ if (AttrKind != AvailableAttr::Kind::Default ) {
530521 diagnose (Tok, diag::attr_availability_multiple_kinds, AttrName,
531- " noasync" , platformAgnosticKindToStr (PlatformAgnostic ));
522+ " noasync" , attrKindToStr (AttrKind ));
532523 }
533- PlatformAgnostic = PlatformAgnosticAvailabilityKind::NoAsync;
524+
525+ AttrKind = AvailableAttr::Kind::NoAsync;
534526 break ;
535527
536528 case IsInvalid:
@@ -551,6 +543,9 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
551543 }
552544
553545 auto PlatformKind = platformFromString (Platform);
546+ auto Domain = (PlatformKind && *PlatformKind != PlatformKind::none)
547+ ? AvailabilityDomain::forPlatform (*PlatformKind)
548+ : AvailabilityDomain::forUniversal ();
554549
555550 // Treat 'swift' as a valid version-qualifying token, when
556551 // at least some versions were mentioned and no other
@@ -561,18 +556,18 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
561556 if (!PlatformKind.has_value () &&
562557 (Platform == " swift" || Platform == " _PackageDescription" )) {
563558
564- if (PlatformAgnostic == PlatformAgnosticAvailabilityKind ::Deprecated) {
559+ if (AttrKind == AvailableAttr::Kind ::Deprecated) {
565560 diagnose (AttrLoc,
566561 diag::attr_availability_platform_agnostic_expected_deprecated_version,
567562 AttrName, Platform);
568563 return nullptr ;
569564 }
570- if (PlatformAgnostic == PlatformAgnosticAvailabilityKind ::Unavailable) {
565+ if (AttrKind == AvailableAttr::Kind ::Unavailable) {
571566 diagnose (AttrLoc, diag::attr_availability_platform_agnostic_infeasible_option,
572567 " unavailable" , AttrName, Platform);
573568 return nullptr ;
574569 }
575- assert (PlatformAgnostic == PlatformAgnosticAvailabilityKind::None );
570+ assert (AttrKind == AvailableAttr::Kind::Default );
576571
577572 if (!SomeVersion) {
578573 diagnose (AttrLoc, diag::attr_availability_platform_agnostic_expected_option,
@@ -581,9 +576,9 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
581576 }
582577
583578 PlatformKind = PlatformKind::none;
584- PlatformAgnostic = (Platform == " swift" ) ?
585- PlatformAgnosticAvailabilityKind::SwiftVersionSpecific :
586- PlatformAgnosticAvailabilityKind::PackageDescriptionVersionSpecific ;
579+ Domain = (Platform == " swift" )
580+ ? AvailabilityDomain::forSwiftLanguage ()
581+ : AvailabilityDomain::forPackageDescription () ;
587582 }
588583
589584
@@ -602,7 +597,7 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
602597 }
603598
604599 // Warn if any version is specified for non-specific platform '*'.
605- if (Platform == " * " && SomeVersion) {
600+ if (Domain. isUniversal () && SomeVersion) {
606601 auto diag = diagnose (AttrLoc,
607602 diag::attr_availability_nonspecific_platform_unexpected_version,
608603 AttrName);
@@ -633,9 +628,9 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
633628 }
634629
635630 auto Attr = new (Context) AvailableAttr (
636- AtLoc, SourceRange (AttrLoc, Tok.getLoc ()), PlatformKind. value () , Message,
631+ AtLoc, SourceRange (AttrLoc, Tok.getLoc ()), Domain, AttrKind , Message,
637632 Renamed, Introduced.Version , Introduced.Range , Deprecated.Version ,
638- Deprecated.Range , Obsoleted.Version , Obsoleted.Range , PlatformAgnostic,
633+ Deprecated.Range , Obsoleted.Version , Obsoleted.Range ,
639634 /* Implicit=*/ false , AttrName == SPI_AVAILABLE_ATTRNAME);
640635 return makeParserResult (Attr);
641636
@@ -875,47 +870,45 @@ bool Parser::parseAvailability(
875870 // @available(_PackageDescription, introduced: 4.2)
876871
877872 for (auto *Spec : Specs) {
878- PlatformKind Platform ;
873+ AvailabilityDomain Domain ;
879874 llvm::VersionTuple Version;
880875 SourceRange VersionRange;
881- PlatformAgnosticAvailabilityKind PlatformAgnostic;
882876
877+ // FIXME: [availability] Allow arbitrary availability domains.
883878 if (auto *PlatformVersionSpec =
884879 dyn_cast<PlatformVersionConstraintAvailabilitySpec>(Spec)) {
885- Platform = PlatformVersionSpec->getPlatform ();
880+ Domain =
881+ AvailabilityDomain::forPlatform (PlatformVersionSpec->getPlatform ());
886882 Version = PlatformVersionSpec->getVersion ();
887883 VersionRange = PlatformVersionSpec->getVersionSrcRange ();
888- PlatformAgnostic = PlatformAgnosticAvailabilityKind::None;
889884
890885 } else if (auto *PlatformAgnosticVersionSpec = dyn_cast<
891886 PlatformAgnosticVersionConstraintAvailabilitySpec>(Spec)) {
892- Platform = PlatformKind::none;
887+ Domain = PlatformAgnosticVersionSpec->isLanguageVersionSpecific ()
888+ ? AvailabilityDomain::forSwiftLanguage ()
889+ : AvailabilityDomain::forPackageDescription ();
893890 Version = PlatformAgnosticVersionSpec->getVersion ();
894891 VersionRange = PlatformAgnosticVersionSpec->getVersionSrcRange ();
895- PlatformAgnostic =
896- PlatformAgnosticVersionSpec->isLanguageVersionSpecific ()
897- ? PlatformAgnosticAvailabilityKind::SwiftVersionSpecific
898- : PlatformAgnosticAvailabilityKind::
899- PackageDescriptionVersionSpecific;
900892
901893 } else {
902894 continue ;
903895 }
904896
905- Version = canonicalizePlatformVersion (Platform, Version);
897+ if (Domain.isPlatform ())
898+ Version =
899+ canonicalizePlatformVersion (Domain.getPlatformKind (), Version);
906900
907901 addAttribute (new (Context) AvailableAttr (
908- AtLoc, attrRange, Platform ,
902+ AtLoc, attrRange, Domain, AvailableAttr::Kind::Default ,
909903 /* Message=*/ StringRef (),
910904 /* Rename=*/ StringRef (),
911905 /* Introduced=*/ Version,
912906 /* IntroducedRange=*/ VersionRange,
913907 /* Deprecated=*/ llvm::VersionTuple (),
914908 /* DeprecatedRange=*/ SourceRange (),
915909 /* Obsoleted=*/ llvm::VersionTuple (),
916- /* ObsoletedRange=*/ SourceRange (), PlatformAgnostic,
917- /* Implicit=*/ false ,
918- AttrName == SPI_AVAILABLE_ATTRNAME));
910+ /* ObsoletedRange=*/ SourceRange (),
911+ /* Implicit=*/ false , AttrName == SPI_AVAILABLE_ATTRNAME));
919912 }
920913
921914 return true ;
0 commit comments