Skip to content

Commit 99b8ae0

Browse files
committed
[NFC] DiagnosticVerifier: Use a dedicated struct for fix-it column-based ranges
1 parent 8e4ea9b commit 99b8ae0

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

include/swift/Frontend/DiagnosticVerifier.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ bool verifyDependencies(SourceManager &SM, ArrayRef<SourceFile *> SFs);
3636
// MARK: - DiagnosticVerifier
3737
struct ExpectedFixIt;
3838

39+
/// A range expressed in terms of line-and-column pairs.
40+
struct LineColumnRange {
41+
static constexpr unsigned NoValue = ~0u;
42+
43+
unsigned StartCol, EndCol;
44+
45+
LineColumnRange() : StartCol(NoValue), EndCol(NoValue) {}
46+
};
47+
3948
struct CapturedDiagnosticInfo {
4049
llvm::SmallString<128> Message;
4150
llvm::SmallString<32> FileName;

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ using namespace swift;
2929
namespace swift {
3030
struct ExpectedFixIt {
3131
const char *StartLoc, *EndLoc; // The loc of the {{ and }}'s.
32-
unsigned StartCol;
33-
unsigned EndCol;
32+
LineColumnRange Range;
33+
3434
std::string Text;
3535
};
3636
} // end namespace swift
@@ -247,9 +247,10 @@ bool DiagnosticVerifier::checkForFixIt(const ExpectedFixIt &Expected,
247247
continue;
248248

249249
CharSourceRange Range = ActualFixIt.getRange();
250-
if (SM.getColumnInBuffer(Range.getStart(), BufferID) != Expected.StartCol)
250+
if (SM.getColumnInBuffer(Range.getStart(), BufferID) !=
251+
Expected.Range.StartCol)
251252
continue;
252-
if (SM.getColumnInBuffer(Range.getEnd(), BufferID) != Expected.EndCol)
253+
if (SM.getColumnInBuffer(Range.getEnd(), BufferID) != Expected.Range.EndCol)
253254
continue;
254255

255256
return true;
@@ -544,12 +545,12 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
544545
ExpectedFixIt FixIt;
545546
FixIt.StartLoc = OpenLoc;
546547
FixIt.EndLoc = CloseLoc;
547-
if (StartColStr.getAsInteger(10, FixIt.StartCol)) {
548+
if (StartColStr.getAsInteger(10, FixIt.Range.StartCol)) {
548549
addError(StartColStr.data(),
549550
"invalid column number in fix-it verification");
550551
continue;
551552
}
552-
if (EndColStr.getAsInteger(10, FixIt.EndCol)) {
553+
if (EndColStr.getAsInteger(10, FixIt.Range.EndCol)) {
553554
addError(EndColStr.data(),
554555
"invalid column number in fix-it verification");
555556
continue;

0 commit comments

Comments
 (0)