@@ -30,18 +30,19 @@ namespace swift {
30
30
class ASTContext ;
31
31
32
32
enum class AvailabilitySpecKind {
33
- // / A platform-version constraint of the form "PlatformName X.Y.Z"
34
- PlatformVersionConstraint,
33
+ // / A platform-version constraint of the form "PlatformName X.Y.Z"
34
+ PlatformVersionConstraint,
35
35
36
- // / A wildcard constraint, spelled '*', that is equivalent
37
- // / to CurrentPlatformName >= MinimumDeploymentTargetVersion
38
- OtherPlatform ,
36
+ // / A wildcard constraint, spelled '*', that is equivalent
37
+ // / to CurrentPlatformName >= MinimumDeploymentTargetVersion
38
+ Wildcard ,
39
39
40
- // / A language-version constraint of the form "swift X.Y.Z"
41
- LanguageVersionConstraint,
40
+ // / A language-version constraint of the form "swift X.Y.Z"
41
+ LanguageVersionConstraint,
42
42
43
- // / A PackageDescription version constraint of the form "_PackageDescription X.Y.Z"
44
- PackageDescriptionVersionConstraint,
43
+ // / A PackageDescription version constraint of the form "_PackageDescription
44
+ // / X.Y.Z"
45
+ PackageDescriptionVersionConstraint,
45
46
};
46
47
47
48
// / The root class for specifications of API availability in availability
@@ -65,16 +66,29 @@ class AvailabilitySpec : public ASTAllocated<AvailabilitySpec> {
65
66
// Location of the availability macro expanded to create this spec.
66
67
SourceLoc MacroLoc;
67
68
68
- public:
69
69
AvailabilitySpec (AvailabilitySpecKind Kind,
70
70
std::optional<AvailabilityDomain> Domain,
71
71
SourceRange SrcRange, llvm::VersionTuple Version,
72
72
SourceLoc VersionStartLoc)
73
73
: Kind(Kind), Domain(Domain), SrcRange(SrcRange), Version(Version),
74
74
VersionStartLoc (VersionStartLoc) {}
75
75
76
+ public:
77
+ // / Creates a wildcard availability specification that guards execution
78
+ // / by checking that the run-time version is greater than the minimum
79
+ // / deployment target. This specification is designed to ease porting
80
+ // / to new platforms. Because new platforms typically branch from
81
+ // / existing platforms, the wildcard allows an #available() check to do the
82
+ // / "right" thing (executing the guarded branch) on the new platform without
83
+ // / requiring a modification to every availability guard in the program. Note
84
+ // / that we still do compile-time availability checking with '*', so the
85
+ // / compiler will still catch references to potentially unavailable symbols.
86
+ static AvailabilitySpec *createWildcard (ASTContext &ctx, SourceLoc starLoc);
87
+
76
88
AvailabilitySpecKind getKind () const { return Kind; }
77
89
90
+ bool isWildcard () { return getKind () == AvailabilitySpecKind::Wildcard; }
91
+
78
92
SourceRange getSourceRange () const { return SrcRange; }
79
93
SourceLoc getStartLoc () const { return SrcRange.Start ; }
80
94
@@ -147,7 +161,7 @@ class PlatformAgnosticVersionConstraintAvailabilitySpec
147
161
static AvailabilityDomain getDomainForSpecKind (AvailabilitySpecKind Kind) {
148
162
switch (Kind) {
149
163
case AvailabilitySpecKind::PlatformVersionConstraint:
150
- case AvailabilitySpecKind::OtherPlatform :
164
+ case AvailabilitySpecKind::Wildcard :
151
165
llvm_unreachable (" unexpected spec kind" );
152
166
case AvailabilitySpecKind::LanguageVersionConstraint:
153
167
return AvailabilityDomain::forSwiftLanguage ();
@@ -184,37 +198,6 @@ class PlatformAgnosticVersionConstraintAvailabilitySpec
184
198
}
185
199
};
186
200
187
- // / A wildcard availability specification that guards execution
188
- // / by checking that the run-time version is greater than the minimum
189
- // / deployment target. This specification is designed to ease porting
190
- // / to new platforms. Because new platforms typically branch from
191
- // / existing platforms, the wildcard allows an #available() check to do the
192
- // / "right" thing (executing the guarded branch) on the new platform without
193
- // / requiring a modification to every availability guard in the program. Note
194
- // / that we still do compile-time availability checking with '*', so the
195
- // / compiler will still catch references to potentially unavailable symbols.
196
- class OtherPlatformAvailabilitySpec : public AvailabilitySpec {
197
- public:
198
- OtherPlatformAvailabilitySpec (SourceLoc StarLoc)
199
- : AvailabilitySpec(AvailabilitySpecKind::OtherPlatform, std::nullopt,
200
- StarLoc,
201
- /* Version=*/ {},
202
- /* VersionStartLoc=*/ {}) {}
203
-
204
- void print (raw_ostream &OS, unsigned Indent) const ;
205
-
206
- static bool classof (const AvailabilitySpec *Spec) {
207
- return Spec->getKind () == AvailabilitySpecKind::OtherPlatform;
208
- }
209
-
210
- void *
211
- operator new (size_t Bytes, ASTContext &C,
212
- unsigned Alignment = alignof(OtherPlatformAvailabilitySpec)) {
213
- return AvailabilitySpec::operator new (Bytes, C, AllocationArena::Permanent,
214
- Alignment);
215
- }
216
- };
217
-
218
201
// / Maps of macro name and version to availability specifications.
219
202
// / Organized as two nested \c DenseMap keyed first on the macro name then
220
203
// / the macro version. This structure allows to peek at macro names before
0 commit comments