3030
3131namespace swift {
3232class ASTContext ;
33-
34- enum class AvailabilitySpecKind {
35- // / A platform-version constraint of the form "PlatformName X.Y.Z"
36- PlatformVersionConstraint,
37-
38- // / A wildcard constraint, spelled '*', that is equivalent
39- // / to CurrentPlatformName >= MinimumDeploymentTargetVersion
40- Wildcard,
41-
42- // / A language-version constraint of the form "swift X.Y.Z"
43- LanguageVersionConstraint,
44-
45- // / A PackageDescription version constraint of the form "_PackageDescription
46- // / X.Y.Z"
47- PackageDescriptionVersionConstraint,
48- };
49-
5033class SemanticAvailabilitySpec ;
5134
5235// / The root class for specifications of API availability in availability
5336// / queries.
5437class AvailabilitySpec : public ASTAllocated <AvailabilitySpec> {
55- protected:
56- AvailabilitySpecKind Kind;
57-
58- std::optional<AvailabilityDomain> Domain;
38+ using DomainStorage = llvm::PointerIntPair<AvailabilityDomainOrIdentifier, 1 >;
39+ DomainStorage Storage;
5940
6041 // / The range of the entire spec, including the version if there is one.
6142 SourceRange SrcRange;
@@ -70,13 +51,15 @@ class AvailabilitySpec : public ASTAllocated<AvailabilitySpec> {
7051 // Location of the availability macro expanded to create this spec.
7152 SourceLoc MacroLoc;
7253
73- AvailabilitySpec (AvailabilitySpecKind Kind,
74- std::optional<AvailabilityDomain> Domain,
75- SourceRange SrcRange, llvm::VersionTuple Version,
76- SourceLoc VersionStartLoc)
77- : Kind(Kind), Domain(Domain), SrcRange(SrcRange), Version(Version),
54+ AvailabilitySpec (DomainStorage Storage, SourceRange SrcRange,
55+ llvm::VersionTuple Version, SourceLoc VersionStartLoc)
56+ : Storage(Storage), SrcRange(SrcRange), Version(Version),
7857 VersionStartLoc (VersionStartLoc) {}
7958
59+ AvailabilityDomainOrIdentifier getDomainOrIdentifier () const {
60+ return Storage.getPointer ();
61+ }
62+
8063public:
8164 // / Creates a wildcard availability specification that guards execution
8265 // / by checking that the run-time version is greater than the minimum
@@ -89,33 +72,20 @@ class AvailabilitySpec : public ASTAllocated<AvailabilitySpec> {
8972 // / compiler will still catch references to potentially unavailable symbols.
9073 static AvailabilitySpec *createWildcard (ASTContext &ctx, SourceLoc starLoc);
9174
92- // / Creates an availability specification that guards execution based on the
93- // / compile-time platform agnostic version, e.g., swift >= 3.0.1,
94- // / package-description >= 4.0.
95- static AvailabilitySpec *createPlatformAgnostic (ASTContext &ctx,
96- AvailabilitySpecKind kind,
97- SourceLoc nameLoc,
75+ // / Creates an availability specification that requires a minimum version of
76+ // / some availability domain, e.g., macOS >= 10.10 or swift >= 3.0.1.
77+ static AvailabilitySpec *
78+ createForDomain (ASTContext &ctx, AvailabilityDomain domain, SourceLoc loc,
79+ llvm::VersionTuple version, SourceRange versionRange);
80+
81+ // / Creates an availability specification for an unknown availability domain.
82+ static AvailabilitySpec *createForUnknownDomain (ASTContext &ctx,
83+ Identifier domainIdentifier,
84+ SourceLoc loc,
9885 llvm::VersionTuple version,
9986 SourceRange versionRange);
10087
101- // / Creates an availability specification that guards execution based on the
102- // / run-time platform and version, e.g., macOS >= 10.10.
103- static AvailabilitySpec *createPlatformVersioned (ASTContext &ctx,
104- PlatformKind platform,
105- SourceLoc platformLoc,
106- llvm::VersionTuple version,
107- SourceRange versionRange);
108-
109- AvailabilitySpec *clone (ASTContext &ctx) const {
110- return new (ctx)
111- AvailabilitySpec (Kind, Domain, SrcRange, Version, VersionStartLoc);
112- }
113-
114- AvailabilitySpecKind getKind () const { return Kind; }
115-
116- bool isWildcard () const {
117- return getKind () == AvailabilitySpecKind::Wildcard;
118- }
88+ AvailabilitySpec *clone (ASTContext &ctx) const ;
11989
12090 // / Returns a type-checked representation of the spec, or `std::nullopt` if
12191 // / the spec is invalid.
@@ -125,7 +95,15 @@ class AvailabilitySpec : public ASTAllocated<AvailabilitySpec> {
12595 SourceRange getSourceRange () const { return SrcRange; }
12696 SourceLoc getStartLoc () const { return SrcRange.Start ; }
12797
128- std::optional<AvailabilityDomain> getDomain () const { return Domain; }
98+ bool isWildcard () const {
99+ if (auto domain = getDomain ())
100+ return domain->isUniversal ();
101+ return false ;
102+ }
103+
104+ std::optional<AvailabilityDomain> getDomain () const {
105+ return getDomainOrIdentifier ().getAsDomain ();
106+ }
129107
130108 PlatformKind getPlatform () const {
131109 if (auto domain = getDomain ())
0 commit comments