Skip to content

Commit 5ff3ee3

Browse files
committed
[IDE] Don't assume a platform name's SourceRange matches its length.
We're about to make 'macOS' and 'OSX' aliases. Groundwork for SE-0106.
1 parent 443bb59 commit 5ff3ee3

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

include/swift/AST/Stmt.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,10 @@ class alignas(8) PoundAvailableInfo final :
269269
const VersionRange &getAvailableRange() const { return AvailableRange; }
270270
void setAvailableRange(const VersionRange &Range) { AvailableRange = Range; }
271271

272-
void getPlatformKeywordRanges(SmallVectorImpl<CharSourceRange>
273-
&PlatformRanges);
272+
void getPlatformKeywordLocs(SmallVectorImpl<SourceLoc> &PlatformLocs);
274273
};
275274

276-
277275

278-
279276
/// This represents an entry in an "if" or "while" condition. Pattern bindings
280277
/// can bind any number of names in the pattern binding decl, and may have an
281278
/// associated where clause. When "if let" is involved, an arbitrary number of

lib/AST/Stmt.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,24 +284,14 @@ SourceLoc PoundAvailableInfo::getEndLoc() const {
284284
}
285285

286286
void PoundAvailableInfo::
287-
getPlatformKeywordRanges(SmallVectorImpl<CharSourceRange> &PlatformRanges) {
287+
getPlatformKeywordLocs(SmallVectorImpl<SourceLoc> &PlatformLocs) {
288288
for (unsigned i = 0; i < NumQueries; i++) {
289289
auto *VersionSpec =
290290
dyn_cast<VersionConstraintAvailabilitySpec>(getQueries()[i]);
291291
if (!VersionSpec)
292292
continue;
293293

294-
auto Loc = VersionSpec->getPlatformLoc();
295-
auto Platform = VersionSpec->getPlatform();
296-
switch (Platform) {
297-
case PlatformKind::none:
298-
break;
299-
#define AVAILABILITY_PLATFORM(X, PrettyName) \
300-
case PlatformKind::X: \
301-
PlatformRanges.push_back(CharSourceRange(Loc, strlen(#X))); \
302-
break;
303-
#include "swift/AST/PlatformKinds.def"
304-
}
294+
PlatformLocs.push_back(VersionSpec->getPlatformLoc());
305295
}
306296
}
307297

lib/IDE/SyntaxModel.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,13 @@ void ModelASTWalker::handleStmtCondition(StmtCondition cond) {
549549
for (const auto &elt : cond) {
550550
if (elt.getKind() != StmtConditionElement::CK_Availability) continue;
551551

552-
SmallVector<CharSourceRange, 5> PlatformRanges;
553-
elt.getAvailability()->getPlatformKeywordRanges(PlatformRanges);
554-
std::for_each(PlatformRanges.begin(), PlatformRanges.end(),
555-
[&](CharSourceRange &Range) {
556-
passNonTokenNode({SyntaxNodeKind::Keyword, Range});
557-
});
552+
SmallVector<SourceLoc, 5> PlatformLocs;
553+
elt.getAvailability()->getPlatformKeywordLocs(PlatformLocs);
554+
std::for_each(PlatformLocs.begin(), PlatformLocs.end(),
555+
[&](SourceLoc loc) {
556+
auto range = charSourceRangeFromSourceRange(SM, loc);
557+
passNonTokenNode({SyntaxNodeKind::Keyword, range});
558+
});
558559
}
559560
}
560561

0 commit comments

Comments
 (0)