@@ -30,18 +30,19 @@ namespace swift {
3030class ASTContext ;
3131
3232enum 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,
3535
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 ,
3939
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,
4242
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,
4546};
4647
4748// / The root class for specifications of API availability in availability
@@ -65,16 +66,29 @@ class AvailabilitySpec : public ASTAllocated<AvailabilitySpec> {
6566 // Location of the availability macro expanded to create this spec.
6667 SourceLoc MacroLoc;
6768
68- public:
6969 AvailabilitySpec (AvailabilitySpecKind Kind,
7070 std::optional<AvailabilityDomain> Domain,
7171 SourceRange SrcRange, llvm::VersionTuple Version,
7272 SourceLoc VersionStartLoc)
7373 : Kind(Kind), Domain(Domain), SrcRange(SrcRange), Version(Version),
7474 VersionStartLoc (VersionStartLoc) {}
7575
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+
7688 AvailabilitySpecKind getKind () const { return Kind; }
7789
90+ bool isWildcard () { return getKind () == AvailabilitySpecKind::Wildcard; }
91+
7892 SourceRange getSourceRange () const { return SrcRange; }
7993 SourceLoc getStartLoc () const { return SrcRange.Start ; }
8094
@@ -147,7 +161,7 @@ class PlatformAgnosticVersionConstraintAvailabilitySpec
147161 static AvailabilityDomain getDomainForSpecKind (AvailabilitySpecKind Kind) {
148162 switch (Kind) {
149163 case AvailabilitySpecKind::PlatformVersionConstraint:
150- case AvailabilitySpecKind::OtherPlatform :
164+ case AvailabilitySpecKind::Wildcard :
151165 llvm_unreachable (" unexpected spec kind" );
152166 case AvailabilitySpecKind::LanguageVersionConstraint:
153167 return AvailabilityDomain::forSwiftLanguage ();
@@ -184,37 +198,6 @@ class PlatformAgnosticVersionConstraintAvailabilitySpec
184198 }
185199};
186200
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-
218201// / Maps of macro name and version to availability specifications.
219202// / Organized as two nested \c DenseMap keyed first on the macro name then
220203// / the macro version. This structure allows to peek at macro names before
0 commit comments