Skip to content

Commit 9003d83

Browse files
author
Nathan Hawes
committed
[gardening] convert ByteBasedSourceRange to CharSourceRange rather than SourceRange
The only client of the 'toSourceRange' method immediately constructs a CharSourceRange from it, and ByteBasedSourceRange's EndLoc isn't the start of the last token in the range (as SourceRange expects).
1 parent efa2c54 commit 9003d83

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tools/swift-syntax-test/swift-syntax-test.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ struct ByteBasedSourceRange {
246246

247247
bool empty() { return Start == End; }
248248

249-
SourceRange toSourceRange(SourceManager &SourceMgr, unsigned BufferID) {
249+
CharSourceRange toCharSourceRange(SourceManager &SourceMgr, unsigned BufferID) {
250250
auto StartLoc = SourceMgr.getLocForOffset(BufferID, Start);
251251
auto EndLoc = SourceMgr.getLocForOffset(BufferID, End);
252-
return SourceRange(StartLoc, EndLoc);
252+
return CharSourceRange(SourceMgr, StartLoc, EndLoc);
253253
}
254254
};
255255

@@ -538,12 +538,11 @@ bool verifyReusedRegions(ByteBasedSourceRangeSet ExpectedReparseRegions,
538538
bool NoUnexpectedParse = true;
539539

540540
for (auto ReparseRegion : UnexpectedReparseRegions.Ranges) {
541-
auto ReparseRange = ReparseRegion.toSourceRange(SourceMgr, BufferID);
541+
auto ReparseRange = ReparseRegion.toCharSourceRange(SourceMgr, BufferID);
542542

543543
// To improve the ergonomics when writing tests we do not want to complain
544544
// about reparsed whitespaces.
545-
auto RangeStr =
546-
CharSourceRange(SourceMgr, ReparseRange.Start, ReparseRange.End).str();
545+
auto RangeStr = ReparseRange.str();
547546
llvm::Regex WhitespaceOnlyRegex("^[ \t\r\n]*$");
548547
if (WhitespaceOnlyRegex.match(RangeStr)) {
549548
continue;

0 commit comments

Comments
 (0)