@@ -333,8 +333,7 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
333
333
334
334
StringRef Message, Renamed;
335
335
VersionArg Introduced, Deprecated, Obsoleted;
336
- auto PlatformAgnostic = PlatformAgnosticAvailabilityKind::None;
337
-
336
+ auto AttrKind = AvailableAttr::Kind::Default;
338
337
bool HasUpcomingEntry = false ;
339
338
340
339
{
@@ -377,24 +376,16 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
377
376
.Default (IsInvalid);
378
377
}
379
378
380
- auto platformAgnosticKindToStr = [](PlatformAgnosticAvailabilityKind kind) {
379
+ auto attrKindToStr = [](AvailableAttr::Kind kind) {
381
380
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:
385
384
return " deprecated" ;
386
- case PlatformAgnosticAvailabilityKind ::Unavailable:
385
+ case AvailableAttr::Kind ::Unavailable:
387
386
return " unavailable" ;
388
- case PlatformAgnosticAvailabilityKind ::NoAsync:
387
+ case AvailableAttr::Kind ::NoAsync:
389
388
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" );
398
389
}
399
390
};
400
391
@@ -471,12 +462,12 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
471
462
472
463
case IsDeprecated:
473
464
if (!findAttrValueDelimiter ()) {
474
- if (PlatformAgnostic != PlatformAgnosticAvailabilityKind::None ) {
465
+ if (AttrKind != AvailableAttr::Kind::Default ) {
475
466
diagnose (Tok, diag::attr_availability_multiple_kinds, AttrName,
476
- " deprecated" , platformAgnosticKindToStr (PlatformAgnostic ));
467
+ " deprecated" , attrKindToStr (AttrKind ));
477
468
}
478
469
479
- PlatformAgnostic = PlatformAgnosticAvailabilityKind ::Deprecated;
470
+ AttrKind = AvailableAttr::Kind ::Deprecated;
480
471
break ;
481
472
}
482
473
LLVM_FALLTHROUGH;
@@ -517,20 +508,21 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
517
508
}
518
509
519
510
case IsUnavailable:
520
- if (PlatformAgnostic != PlatformAgnosticAvailabilityKind::None ) {
511
+ if (AttrKind != AvailableAttr::Kind::Default ) {
521
512
diagnose (Tok, diag::attr_availability_multiple_kinds, AttrName,
522
- " unavailable" , platformAgnosticKindToStr (PlatformAgnostic ));
513
+ " unavailable" , attrKindToStr (AttrKind ));
523
514
}
524
515
525
- PlatformAgnostic = PlatformAgnosticAvailabilityKind ::Unavailable;
516
+ AttrKind = AvailableAttr::Kind ::Unavailable;
526
517
break ;
527
518
528
519
case IsNoAsync:
529
- if (PlatformAgnostic != PlatformAgnosticAvailabilityKind::None ) {
520
+ if (AttrKind != AvailableAttr::Kind::Default ) {
530
521
diagnose (Tok, diag::attr_availability_multiple_kinds, AttrName,
531
- " noasync" , platformAgnosticKindToStr (PlatformAgnostic ));
522
+ " noasync" , attrKindToStr (AttrKind ));
532
523
}
533
- PlatformAgnostic = PlatformAgnosticAvailabilityKind::NoAsync;
524
+
525
+ AttrKind = AvailableAttr::Kind::NoAsync;
534
526
break ;
535
527
536
528
case IsInvalid:
@@ -551,6 +543,9 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
551
543
}
552
544
553
545
auto PlatformKind = platformFromString (Platform);
546
+ auto Domain = (PlatformKind && *PlatformKind != PlatformKind::none)
547
+ ? AvailabilityDomain::forPlatform (*PlatformKind)
548
+ : AvailabilityDomain::forUniversal ();
554
549
555
550
// Treat 'swift' as a valid version-qualifying token, when
556
551
// at least some versions were mentioned and no other
@@ -561,18 +556,18 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
561
556
if (!PlatformKind.has_value () &&
562
557
(Platform == " swift" || Platform == " _PackageDescription" )) {
563
558
564
- if (PlatformAgnostic == PlatformAgnosticAvailabilityKind ::Deprecated) {
559
+ if (AttrKind == AvailableAttr::Kind ::Deprecated) {
565
560
diagnose (AttrLoc,
566
561
diag::attr_availability_platform_agnostic_expected_deprecated_version,
567
562
AttrName, Platform);
568
563
return nullptr ;
569
564
}
570
- if (PlatformAgnostic == PlatformAgnosticAvailabilityKind ::Unavailable) {
565
+ if (AttrKind == AvailableAttr::Kind ::Unavailable) {
571
566
diagnose (AttrLoc, diag::attr_availability_platform_agnostic_infeasible_option,
572
567
" unavailable" , AttrName, Platform);
573
568
return nullptr ;
574
569
}
575
- assert (PlatformAgnostic == PlatformAgnosticAvailabilityKind::None );
570
+ assert (AttrKind == AvailableAttr::Kind::Default );
576
571
577
572
if (!SomeVersion) {
578
573
diagnose (AttrLoc, diag::attr_availability_platform_agnostic_expected_option,
@@ -581,9 +576,9 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
581
576
}
582
577
583
578
PlatformKind = PlatformKind::none;
584
- PlatformAgnostic = (Platform == " swift" ) ?
585
- PlatformAgnosticAvailabilityKind::SwiftVersionSpecific :
586
- PlatformAgnosticAvailabilityKind::PackageDescriptionVersionSpecific ;
579
+ Domain = (Platform == " swift" )
580
+ ? AvailabilityDomain::forSwiftLanguage ()
581
+ : AvailabilityDomain::forPackageDescription () ;
587
582
}
588
583
589
584
@@ -602,7 +597,7 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
602
597
}
603
598
604
599
// Warn if any version is specified for non-specific platform '*'.
605
- if (Platform == " * " && SomeVersion) {
600
+ if (Domain. isUniversal () && SomeVersion) {
606
601
auto diag = diagnose (AttrLoc,
607
602
diag::attr_availability_nonspecific_platform_unexpected_version,
608
603
AttrName);
@@ -633,9 +628,9 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
633
628
}
634
629
635
630
auto Attr = new (Context) AvailableAttr (
636
- AtLoc, SourceRange (AttrLoc, Tok.getLoc ()), PlatformKind. value () , Message,
631
+ AtLoc, SourceRange (AttrLoc, Tok.getLoc ()), Domain, AttrKind , Message,
637
632
Renamed, Introduced.Version , Introduced.Range , Deprecated.Version ,
638
- Deprecated.Range , Obsoleted.Version , Obsoleted.Range , PlatformAgnostic,
633
+ Deprecated.Range , Obsoleted.Version , Obsoleted.Range ,
639
634
/* Implicit=*/ false , AttrName == SPI_AVAILABLE_ATTRNAME);
640
635
return makeParserResult (Attr);
641
636
@@ -875,47 +870,45 @@ bool Parser::parseAvailability(
875
870
// @available(_PackageDescription, introduced: 4.2)
876
871
877
872
for (auto *Spec : Specs) {
878
- PlatformKind Platform ;
873
+ AvailabilityDomain Domain ;
879
874
llvm::VersionTuple Version;
880
875
SourceRange VersionRange;
881
- PlatformAgnosticAvailabilityKind PlatformAgnostic;
882
876
877
+ // FIXME: [availability] Allow arbitrary availability domains.
883
878
if (auto *PlatformVersionSpec =
884
879
dyn_cast<PlatformVersionConstraintAvailabilitySpec>(Spec)) {
885
- Platform = PlatformVersionSpec->getPlatform ();
880
+ Domain =
881
+ AvailabilityDomain::forPlatform (PlatformVersionSpec->getPlatform ());
886
882
Version = PlatformVersionSpec->getVersion ();
887
883
VersionRange = PlatformVersionSpec->getVersionSrcRange ();
888
- PlatformAgnostic = PlatformAgnosticAvailabilityKind::None;
889
884
890
885
} else if (auto *PlatformAgnosticVersionSpec = dyn_cast<
891
886
PlatformAgnosticVersionConstraintAvailabilitySpec>(Spec)) {
892
- Platform = PlatformKind::none;
887
+ Domain = PlatformAgnosticVersionSpec->isLanguageVersionSpecific ()
888
+ ? AvailabilityDomain::forSwiftLanguage ()
889
+ : AvailabilityDomain::forPackageDescription ();
893
890
Version = PlatformAgnosticVersionSpec->getVersion ();
894
891
VersionRange = PlatformAgnosticVersionSpec->getVersionSrcRange ();
895
- PlatformAgnostic =
896
- PlatformAgnosticVersionSpec->isLanguageVersionSpecific ()
897
- ? PlatformAgnosticAvailabilityKind::SwiftVersionSpecific
898
- : PlatformAgnosticAvailabilityKind::
899
- PackageDescriptionVersionSpecific;
900
892
901
893
} else {
902
894
continue ;
903
895
}
904
896
905
- Version = canonicalizePlatformVersion (Platform, Version);
897
+ if (Domain.isPlatform ())
898
+ Version =
899
+ canonicalizePlatformVersion (Domain.getPlatformKind (), Version);
906
900
907
901
addAttribute (new (Context) AvailableAttr (
908
- AtLoc, attrRange, Platform ,
902
+ AtLoc, attrRange, Domain, AvailableAttr::Kind::Default ,
909
903
/* Message=*/ StringRef (),
910
904
/* Rename=*/ StringRef (),
911
905
/* Introduced=*/ Version,
912
906
/* IntroducedRange=*/ VersionRange,
913
907
/* Deprecated=*/ llvm::VersionTuple (),
914
908
/* DeprecatedRange=*/ SourceRange (),
915
909
/* 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));
919
912
}
920
913
921
914
return true ;
0 commit comments