Skip to content

Commit 51ae094

Browse files
committed
CodeCompletion: Adopt SemanticAvailableAttr.
1 parent a4203ed commit 51ae094

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

lib/IDE/CodeCompletionDiagnostics.cpp

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class CodeCompletionDiagnostics {
5656
llvm::raw_ostream &Out, Diag<ArgTypes...> ID,
5757
typename swift::detail::PassArgument<ArgTypes>::type... VArgs);
5858

59-
bool getDiagnosticForDeprecated(const ValueDecl *D, const AvailableAttr *Attr,
59+
bool getDiagnosticForDeprecated(const ValueDecl *D,
60+
SemanticAvailableAttr Attr,
6061
bool isSoftDeprecated,
6162
CodeCompletionDiagnosticSeverity &severity,
6263
llvm::raw_ostream &Out);
@@ -81,40 +82,40 @@ bool CodeCompletionDiagnostics::getDiagnostics(
8182
}
8283

8384
bool CodeCompletionDiagnostics::getDiagnosticForDeprecated(
84-
const ValueDecl *D, const AvailableAttr *Attr, bool isSoftDeprecated,
85+
const ValueDecl *D, SemanticAvailableAttr Attr, bool isSoftDeprecated,
8586
CodeCompletionDiagnosticSeverity &severity, llvm::raw_ostream &Out) {
86-
assert(Attr);
87-
8887
// FIXME: Code completion doesn't offer accessors. It only emits 'VarDecl's.
8988
// So getter/setter specific availability doesn't work in code completion.
9089

91-
StringRef Platform = Attr->prettyPlatformString();
90+
StringRef Platform = Attr.getDomain().getNameForDiagnostics();
9291
llvm::VersionTuple DeprecatedVersion;
93-
if (Attr->Deprecated)
94-
DeprecatedVersion = Attr->Deprecated.value();
92+
if (Attr.getDeprecated())
93+
DeprecatedVersion = Attr.getDeprecated().value();
9594

9695
llvm::VersionTuple RemappedDeprecatedVersion;
9796
if (AvailabilityInference::updateDeprecatedPlatformForFallback(
98-
Attr, Ctx, Platform, RemappedDeprecatedVersion))
97+
Attr.getParsedAttr(), Ctx, Platform, RemappedDeprecatedVersion))
9998
DeprecatedVersion = RemappedDeprecatedVersion;
10099

100+
auto Message = Attr.getMessage();
101+
auto NewName = Attr.getRename();
101102
if (!isSoftDeprecated) {
102-
if (Attr->Message.empty() && Attr->Rename.empty()) {
103-
getDiagnostics(severity, Out, diag::availability_deprecated,
104-
D, Attr->hasPlatform(), Platform,
105-
Attr->Deprecated.has_value(), DeprecatedVersion,
103+
if (Message.empty() && NewName.empty()) {
104+
getDiagnostics(severity, Out, diag::availability_deprecated, D,
105+
Attr.isPlatformSpecific(), Platform,
106+
Attr.getDeprecated().has_value(), DeprecatedVersion,
106107
/*message*/ StringRef());
107-
} else if (!Attr->Message.empty()) {
108-
EncodedDiagnosticMessage EncodedMessage(Attr->Message);
109-
getDiagnostics(severity, Out, diag::availability_deprecated,
110-
D, Attr->hasPlatform(), Platform,
111-
Attr->Deprecated.has_value(), DeprecatedVersion,
108+
} else if (!Message.empty()) {
109+
EncodedDiagnosticMessage EncodedMessage(Message);
110+
getDiagnostics(severity, Out, diag::availability_deprecated, D,
111+
Attr.isPlatformSpecific(), Platform,
112+
Attr.getDeprecated().has_value(), DeprecatedVersion,
112113
EncodedMessage.Message);
113114
} else {
114-
getDiagnostics(severity, Out, diag::availability_deprecated_rename,
115-
D, Attr->hasPlatform(), Platform,
116-
Attr->Deprecated.has_value(), DeprecatedVersion, false,
117-
/*ReplaceKind*/ 0, Attr->Rename);
115+
getDiagnostics(severity, Out, diag::availability_deprecated_rename, D,
116+
Attr.isPlatformSpecific(), Platform,
117+
Attr.getDeprecated().has_value(), DeprecatedVersion, false,
118+
/*ReplaceKind*/ 0, NewName);
118119
}
119120
} else {
120121
// '100000' is used as a version number in API that will be deprecated in an
@@ -123,36 +124,34 @@ bool CodeCompletionDiagnostics::getDiagnosticForDeprecated(
123124
static llvm::VersionTuple DISTANT_FUTURE_VESION(100000);
124125
bool isDistantFuture = DeprecatedVersion >= DISTANT_FUTURE_VESION;
125126

126-
if (Attr->Message.empty() && Attr->Rename.empty()) {
127-
getDiagnostics(severity, Out, diag::ide_availability_softdeprecated,
128-
D, Attr->hasPlatform(), Platform,
129-
!isDistantFuture, DeprecatedVersion,
127+
if (Message.empty() && NewName.empty()) {
128+
getDiagnostics(severity, Out, diag::ide_availability_softdeprecated, D,
129+
Attr.isPlatformSpecific(), Platform, !isDistantFuture,
130+
DeprecatedVersion,
130131
/*message*/ StringRef());
131-
} else if (!Attr->Message.empty()) {
132-
EncodedDiagnosticMessage EncodedMessage(Attr->Message);
133-
getDiagnostics(severity, Out, diag::ide_availability_softdeprecated,
134-
D, Attr->hasPlatform(), Platform,
135-
!isDistantFuture, DeprecatedVersion,
136-
EncodedMessage.Message);
132+
} else if (!Message.empty()) {
133+
EncodedDiagnosticMessage EncodedMessage(Message);
134+
getDiagnostics(severity, Out, diag::ide_availability_softdeprecated, D,
135+
Attr.isPlatformSpecific(), Platform, !isDistantFuture,
136+
DeprecatedVersion, EncodedMessage.Message);
137137
} else {
138-
getDiagnostics(severity, Out, diag::ide_availability_softdeprecated_rename,
139-
D, Attr->hasPlatform(), Platform,
140-
!isDistantFuture, DeprecatedVersion, Attr->Rename);
138+
getDiagnostics(severity, Out,
139+
diag::ide_availability_softdeprecated_rename, D,
140+
Attr.isPlatformSpecific(), Platform, !isDistantFuture,
141+
DeprecatedVersion, NewName);
141142
}
142143
}
143-
return false;;
144+
return false;
144145
}
145146

146147
bool CodeCompletionDiagnostics::getDiagnosticForDeprecated(
147148
const ValueDecl *D, CodeCompletionDiagnosticSeverity &severity,
148149
llvm::raw_ostream &Out) {
149150
if (auto attr = D->getDeprecatedAttr())
150-
return getDiagnosticForDeprecated(D, attr->getParsedAttr(), false, severity,
151-
Out);
151+
return getDiagnosticForDeprecated(D, *attr, false, severity, Out);
152152

153153
if (auto attr = D->getSoftDeprecatedAttr())
154-
return getDiagnosticForDeprecated(D, attr->getParsedAttr(), true, severity,
155-
Out);
154+
return getDiagnosticForDeprecated(D, *attr, true, severity, Out);
156155

157156
return true;
158157
}

0 commit comments

Comments
 (0)