30
30
31
31
namespace swift {
32
32
class 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
-
50
33
class SemanticAvailabilitySpec ;
51
34
52
35
// / The root class for specifications of API availability in availability
53
36
// / queries.
54
37
class 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;
59
40
60
41
// / The range of the entire spec, including the version if there is one.
61
42
SourceRange SrcRange;
@@ -70,13 +51,15 @@ class AvailabilitySpec : public ASTAllocated<AvailabilitySpec> {
70
51
// Location of the availability macro expanded to create this spec.
71
52
SourceLoc MacroLoc;
72
53
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),
78
57
VersionStartLoc (VersionStartLoc) {}
79
58
59
+ AvailabilityDomainOrIdentifier getDomainOrIdentifier () const {
60
+ return Storage.getPointer ();
61
+ }
62
+
80
63
public:
81
64
// / Creates a wildcard availability specification that guards execution
82
65
// / by checking that the run-time version is greater than the minimum
@@ -89,33 +72,20 @@ class AvailabilitySpec : public ASTAllocated<AvailabilitySpec> {
89
72
// / compiler will still catch references to potentially unavailable symbols.
90
73
static AvailabilitySpec *createWildcard (ASTContext &ctx, SourceLoc starLoc);
91
74
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,
98
85
llvm::VersionTuple version,
99
86
SourceRange versionRange);
100
87
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 ;
119
89
120
90
// / Returns a type-checked representation of the spec, or `std::nullopt` if
121
91
// / the spec is invalid.
@@ -125,7 +95,15 @@ class AvailabilitySpec : public ASTAllocated<AvailabilitySpec> {
125
95
SourceRange getSourceRange () const { return SrcRange; }
126
96
SourceLoc getStartLoc () const { return SrcRange.Start ; }
127
97
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
+ }
129
107
130
108
PlatformKind getPlatform () const {
131
109
if (auto domain = getDomain ())
0 commit comments