|
18 | 18 |
|
19 | 19 | using namespace swift;
|
20 | 20 |
|
21 |
| -bool AvailabilityContext::PlatformInfo::constrainRange(const Decl *decl) { |
| 21 | +bool AvailabilityContext::PlatformInfo::constrainWith(const Decl *decl) { |
| 22 | + bool isConstrained = false; |
| 23 | + auto &ctx = decl->getASTContext(); |
| 24 | + |
22 | 25 | if (auto range = AvailabilityInference::annotatedAvailableRange(decl))
|
23 |
| - return constrainRange(*range); |
| 26 | + isConstrained |= constrainRange(*range); |
| 27 | + |
| 28 | + if (auto *attr = decl->getAttrs().getUnavailable(ctx)) |
| 29 | + isConstrained |= constrainUnavailability(attr->Platform); |
24 | 30 |
|
25 |
| - return false; |
| 31 | + if (!IsDeprecated) |
| 32 | + isConstrained |= constrainDeprecated(decl->getAttrs().isDeprecated(ctx)); |
| 33 | + |
| 34 | + return isConstrained; |
26 | 35 | }
|
27 | 36 |
|
28 | 37 | bool AvailabilityContext::PlatformInfo::constrainUnavailability(
|
29 |
| - const Decl *decl) { |
30 |
| - auto &ctx = decl->getASTContext(); |
31 |
| - auto *attr = decl->getAttrs().getUnavailable(ctx); |
32 |
| - if (!attr) |
| 38 | + std::optional<PlatformKind> unavailablePlatform) { |
| 39 | + if (!unavailablePlatform) |
33 | 40 | return false;
|
34 | 41 |
|
35 | 42 | // Check whether the decl's unavailability reason is the same.
|
36 |
| - if (IsUnavailable && UnavailablePlatform == attr->Platform) |
| 43 | + if (IsUnavailable && UnavailablePlatform == *unavailablePlatform) |
37 | 44 | return false;
|
38 | 45 |
|
39 | 46 | // Check whether the decl's unavailability reason is more specific.
|
40 |
| - if (attr->Platform != PlatformKind::none && |
41 |
| - inheritsAvailabilityFromPlatform(attr->Platform, UnavailablePlatform)) |
| 47 | + if (*unavailablePlatform != PlatformKind::none && |
| 48 | + inheritsAvailabilityFromPlatform(*unavailablePlatform, |
| 49 | + UnavailablePlatform)) |
42 | 50 | return false;
|
43 | 51 |
|
44 | 52 | IsUnavailable = true;
|
45 |
| - UnavailablePlatform = attr->Platform; |
| 53 | + UnavailablePlatform = *unavailablePlatform; |
46 | 54 | return true;
|
47 | 55 | }
|
48 | 56 |
|
49 |
| -bool AvailabilityContext::PlatformInfo::constrainDeprecated(const Decl *decl) { |
50 |
| - auto &ctx = decl->getASTContext(); |
51 |
| - if (IsDeprecated || !decl->getAttrs().isDeprecated(ctx)) |
| 57 | +bool AvailabilityContext::PlatformInfo::constrainDeprecated(bool deprecated) { |
| 58 | + if (IsDeprecated || !deprecated) |
52 | 59 | return false;
|
53 | 60 |
|
54 | 61 | IsDeprecated = true;
|
@@ -126,13 +133,11 @@ void AvailabilityContext::constrainWithPlatformRange(
|
126 | 133 | }
|
127 | 134 |
|
128 | 135 | void AvailabilityContext::constrainWithDeclAndPlatformRange(
|
129 |
| - Decl *decl, const AvailabilityRange &platformRange) { |
| 136 | + const Decl *decl, const AvailabilityRange &platformRange) { |
130 | 137 | PlatformInfo platformAvailability{Info->Platform};
|
131 | 138 | bool isConstrained = false;
|
132 |
| - isConstrained |= platformAvailability.constrainRange(decl); |
| 139 | + isConstrained |= platformAvailability.constrainWith(decl); |
133 | 140 | isConstrained |= platformAvailability.constrainRange(platformRange);
|
134 |
| - isConstrained |= platformAvailability.constrainUnavailability(decl); |
135 |
| - isConstrained |= platformAvailability.constrainDeprecated(decl); |
136 | 141 |
|
137 | 142 | if (!isConstrained)
|
138 | 143 | return;
|
|
0 commit comments