Skip to content

Commit 0421835

Browse files
committed
AST: Adopt SemanticAvailableAttr in availability attribute inference.
1 parent c76c637 commit 0421835

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

lib/AST/Availability.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,23 @@ mergeIntoInferredVersion(const std::optional<llvm::VersionTuple> &Version,
145145
/// Merge an attribute's availability with an existing inferred availability
146146
/// so that the new inferred availability is at least as available as
147147
/// the attribute requires.
148-
static void mergeWithInferredAvailability(const AvailableAttr *Attr,
148+
static void mergeWithInferredAvailability(SemanticAvailableAttr Attr,
149149
InferredAvailability &Inferred) {
150-
Inferred.PlatformAgnostic
151-
= static_cast<PlatformAgnosticAvailabilityKind>(
150+
auto *ParsedAttr = Attr.getParsedAttr();
151+
Inferred.PlatformAgnostic = static_cast<PlatformAgnosticAvailabilityKind>(
152152
std::max(static_cast<unsigned>(Inferred.PlatformAgnostic),
153-
static_cast<unsigned>(Attr->getPlatformAgnosticAvailability())));
153+
static_cast<unsigned>(
154+
ParsedAttr->getPlatformAgnosticAvailability())));
154155

155156
// The merge of two introduction versions is the maximum of the two versions.
156-
if (mergeIntoInferredVersion(Attr->Introduced, Inferred.Introduced, std::max)) {
157-
Inferred.IsSPI = Attr->isSPI();
157+
if (mergeIntoInferredVersion(Attr.getIntroduced(), Inferred.Introduced,
158+
std::max)) {
159+
Inferred.IsSPI = ParsedAttr->isSPI();
158160
}
159161

160162
// The merge of deprecated and obsoleted versions takes the minimum.
161-
mergeIntoInferredVersion(Attr->Deprecated, Inferred.Deprecated, std::min);
162-
mergeIntoInferredVersion(Attr->Obsoleted, Inferred.Obsoleted, std::min);
163+
mergeIntoInferredVersion(Attr.getDeprecated(), Inferred.Deprecated, std::min);
164+
mergeIntoInferredVersion(Attr.getObsoleted(), Inferred.Obsoleted, std::min);
163165
}
164166

165167
/// Create an implicit availability attribute for the given platform
@@ -204,36 +206,34 @@ void AvailabilityInference::applyInferredAvailableAttrs(
204206

205207
// Iterate over the declarations and infer required availability on
206208
// a per-platform basis.
209+
// FIXME: [availability] Generalize to AvailabilityDomain.
207210
std::map<PlatformKind, InferredAvailability> Inferred;
208211
for (const Decl *D : InferredFromDecls) {
209-
llvm::SmallVector<const AvailableAttr *, 8> MergedAttrs;
212+
llvm::SmallVector<SemanticAvailableAttr, 8> MergedAttrs;
210213

211214
do {
212-
llvm::SmallVector<const AvailableAttr *, 8> PendingAttrs;
213-
214-
for (const DeclAttribute *Attr : D->getAttrs()) {
215-
auto *AvAttr = dyn_cast<AvailableAttr>(Attr);
216-
if (!AvAttr || AvAttr->isInvalid())
217-
continue;
215+
llvm::SmallVector<SemanticAvailableAttr, 8> PendingAttrs;
218216

217+
for (auto AvAttr :
218+
D->getSemanticAvailableAttrs()) {
219219
// Skip an attribute from an outer declaration if it is for a platform
220220
// that was already handled implicitly by an attribute from an inner
221221
// declaration.
222-
if (llvm::any_of(
223-
MergedAttrs, [&AvAttr](const AvailableAttr *MergedAttr) {
224-
return inheritsAvailabilityFromPlatform(
225-
AvAttr->getPlatform(), MergedAttr->getPlatform());
226-
}))
222+
if (llvm::any_of(MergedAttrs,
223+
[&AvAttr](SemanticAvailableAttr MergedAttr) {
224+
return inheritsAvailabilityFromPlatform(
225+
AvAttr.getPlatform(), MergedAttr.getPlatform());
226+
}))
227227
continue;
228228

229-
mergeWithInferredAvailability(AvAttr, Inferred[AvAttr->getPlatform()]);
229+
mergeWithInferredAvailability(AvAttr, Inferred[AvAttr.getPlatform()]);
230230
PendingAttrs.push_back(AvAttr);
231231

232-
if (Message.empty() && !AvAttr->Message.empty())
233-
Message = AvAttr->Message;
232+
if (Message.empty() && !AvAttr.getMessage().empty())
233+
Message = AvAttr.getMessage();
234234

235-
if (Rename.empty() && !AvAttr->Rename.empty())
236-
Rename = AvAttr->Rename;
235+
if (Rename.empty() && !AvAttr.getRename().empty())
236+
Rename = AvAttr.getRename();
237237
}
238238

239239
MergedAttrs.append(PendingAttrs);

0 commit comments

Comments
 (0)