@@ -35,6 +35,22 @@ struct ExpectedFixIt {
35
35
};
36
36
} // end namespace swift
37
37
38
+ const LineColumnRange &
39
+ CapturedFixItInfo::getLineColumnRange (const SourceManager &SM,
40
+ unsigned BufferID) const {
41
+ if (LineColRange.StartCol == LineColumnRange::NoValue) {
42
+ LineColRange.StartCol =
43
+ SM.getColumnInBuffer (getSourceRange ().getStart (), BufferID);
44
+ }
45
+
46
+ if (LineColRange.EndCol == LineColumnRange::NoValue) {
47
+ LineColRange.EndCol =
48
+ SM.getColumnInBuffer (getSourceRange ().getEnd (), BufferID);
49
+ }
50
+
51
+ return LineColRange;
52
+ }
53
+
38
54
namespace {
39
55
40
56
static constexpr StringLiteral fixitExpectationNoneString (" none" );
@@ -246,11 +262,10 @@ bool DiagnosticVerifier::checkForFixIt(const ExpectedFixIt &Expected,
246
262
if (ActualFixIt.getText () != Expected.Text )
247
263
continue ;
248
264
249
- CharSourceRange Range = ActualFixIt.getRange ();
250
- if (SM.getColumnInBuffer (Range.getStart (), BufferID) !=
251
- Expected.Range .StartCol )
265
+ LineColumnRange ActualRange = ActualFixIt.getLineColumnRange (SM, BufferID);
266
+ if (ActualRange.StartCol != Expected.Range .StartCol )
252
267
continue ;
253
- if (SM. getColumnInBuffer (Range. getEnd (), BufferID) != Expected.Range .EndCol )
268
+ if (ActualRange. EndCol != Expected.Range .EndCol )
254
269
continue ;
255
270
256
271
return true ;
@@ -260,31 +275,29 @@ bool DiagnosticVerifier::checkForFixIt(const ExpectedFixIt &Expected,
260
275
}
261
276
262
277
std::string
263
- DiagnosticVerifier::renderFixits (ArrayRef<DiagnosticInfo::FixIt> fixits ,
278
+ DiagnosticVerifier::renderFixits (ArrayRef<CapturedFixItInfo> ActualFixIts ,
264
279
unsigned BufferID) const {
265
280
std::string Result;
266
281
llvm::raw_string_ostream OS (Result);
267
- interleave (fixits,
268
- [&](const DiagnosticInfo::FixIt &ActualFixIt) {
269
- CharSourceRange Range = ActualFixIt.getRange ();
270
-
271
- OS << " {{"
272
- << SM.getColumnInBuffer (Range.getStart (), BufferID)
273
- << ' -'
274
- << SM.getColumnInBuffer (Range.getEnd (), BufferID)
275
- << ' =' ;
276
-
277
- for (auto C : ActualFixIt.getText ()) {
278
- if (C == ' \n ' )
279
- OS << " \\ n" ;
280
- else if (C == ' }' || C == ' \\ ' )
281
- OS << ' \\ ' << C;
282
- else
283
- OS << C;
284
- }
285
- OS << " }}" ;
286
- },
287
- [&] { OS << ' ' ; });
282
+ interleave (
283
+ ActualFixIts,
284
+ [&](const CapturedFixItInfo &ActualFixIt) {
285
+ LineColumnRange ActualRange =
286
+ ActualFixIt.getLineColumnRange (SM, BufferID);
287
+
288
+ OS << " {{" << ActualRange.StartCol << ' -' << ActualRange.EndCol << ' =' ;
289
+
290
+ for (auto C : ActualFixIt.getText ()) {
291
+ if (C == ' \n ' )
292
+ OS << " \\ n" ;
293
+ else if (C == ' }' || C == ' \\ ' )
294
+ OS << ' \\ ' << C;
295
+ else
296
+ OS << C;
297
+ }
298
+ OS << " }}" ;
299
+ },
300
+ [&] { OS << ' ' ; });
288
301
return OS.str ();
289
302
}
290
303
@@ -628,8 +641,7 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
628
641
};
629
642
630
643
auto makeActualFixitsPhrase =
631
- [&](ArrayRef<DiagnosticInfo::FixIt> actualFixits)
632
- -> ActualFixitsPhrase {
644
+ [&](ArrayRef<CapturedFixItInfo> actualFixits) -> ActualFixitsPhrase {
633
645
std::string actualFixitsStr = renderFixits (actualFixits, BufferID);
634
646
635
647
return ActualFixitsPhrase{(Twine (" actual fix-it" ) +
@@ -933,8 +945,10 @@ void DiagnosticVerifier::printRemainingDiagnostics() const {
933
945
// / file.
934
946
void DiagnosticVerifier::handleDiagnostic (SourceManager &SM,
935
947
const DiagnosticInfo &Info) {
936
- SmallVector<DiagnosticInfo::FixIt, 2 > fixIts;
937
- std::copy (Info.FixIts .begin (), Info.FixIts .end (), std::back_inserter (fixIts));
948
+ SmallVector<CapturedFixItInfo, 2 > fixIts;
949
+ for (const auto &fixIt : Info.FixIts ) {
950
+ fixIts.emplace_back (fixIt);
951
+ }
938
952
939
953
llvm::SmallVector<std::string, 1 > eduNotes;
940
954
for (auto ¬ePath : Info.EducationalNotePaths ) {
@@ -968,11 +982,11 @@ void DiagnosticVerifier::handleDiagnostic(SourceManager &SM,
968
982
969
983
capturedDiag.Loc = correctSM.getLocForForeignLoc (capturedDiag.Loc , SM);
970
984
for (auto &fixIt : capturedDiag.FixIts ) {
971
- auto newStart = correctSM. getLocForForeignLoc (fixIt. getRange (). getStart (),
972
- SM);
973
- auto &mutableRange = fixIt.getRange ();
985
+ auto newStart =
986
+ correctSM. getLocForForeignLoc (fixIt. getSourceRange (). getStart (), SM);
987
+ auto &mutableRange = fixIt.getSourceRange ();
974
988
mutableRange =
975
- CharSourceRange (newStart, fixIt.getRange ().getByteLength ());
989
+ CharSourceRange (newStart, fixIt.getSourceRange ().getByteLength ());
976
990
}
977
991
}
978
992
}
0 commit comments