File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -1446,6 +1446,11 @@ class DeclAttributes {
1446
1446
bool
1447
1447
isUnavailableInSwiftVersion (const version::Version &effectiveVersion) const ;
1448
1448
1449
+ // / Returns the first @available attribute that indicates
1450
+ // / a declaration is unavailable, or the first one that indicates it's
1451
+ // / potentially unavailable, or null otherwise.
1452
+ const AvailableAttr *getPotentiallyUnavailable (const ASTContext &ctx) const ;
1453
+
1449
1454
// / Returns the first @available attribute that indicates
1450
1455
// / a declaration is unavailable, or null otherwise.
1451
1456
const AvailableAttr *getUnavailable (const ASTContext &ctx) const ;
Original file line number Diff line number Diff line change @@ -131,6 +131,47 @@ DeclAttributes::isUnavailableInSwiftVersion(
131
131
return false ;
132
132
}
133
133
134
+ const AvailableAttr *DeclAttributes::getPotentiallyUnavailable (
135
+ const ASTContext &ctx) const {
136
+ const AvailableAttr *potential = nullptr ;
137
+ const AvailableAttr *conditional = nullptr ;
138
+
139
+ for (auto Attr : *this )
140
+ if (auto AvAttr = dyn_cast<AvailableAttr>(Attr)) {
141
+ if (AvAttr->isInvalid ())
142
+ continue ;
143
+
144
+ if (!AvAttr->isActivePlatform (ctx) &&
145
+ !AvAttr->isLanguageVersionSpecific () &&
146
+ !AvAttr->isPackageDescriptionVersionSpecific ())
147
+ continue ;
148
+
149
+ // Definitely not available.
150
+ if (AvAttr->isUnconditionallyDeprecated ())
151
+ return AvAttr;
152
+
153
+ switch (AvAttr->getVersionAvailability (ctx)) {
154
+ case AvailableVersionComparison::Available:
155
+ // Doesn't limit the introduced version.
156
+ break ;
157
+
158
+ case AvailableVersionComparison::PotentiallyUnavailable:
159
+ // We'll return this if we don't see something that proves it's
160
+ // not available in this version.
161
+ potential = AvAttr;
162
+ break ;
163
+
164
+ case AvailableVersionComparison::Unavailable:
165
+ case AvailableVersionComparison::Obsoleted:
166
+ conditional = AvAttr;
167
+ }
168
+ }
169
+
170
+ if (conditional)
171
+ return conditional;
172
+ return potential;
173
+ }
174
+
134
175
const AvailableAttr *DeclAttributes::getUnavailable (
135
176
const ASTContext &ctx) const {
136
177
const AvailableAttr *conditional = nullptr ;
You can’t perform that action at this time.
0 commit comments