@@ -35,6 +35,22 @@ struct ExpectedFixIt {
3535};
3636} // end namespace swift
3737
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+
3854namespace {
3955
4056static constexpr StringLiteral fixitExpectationNoneString (" none" );
@@ -246,11 +262,10 @@ bool DiagnosticVerifier::checkForFixIt(const ExpectedFixIt &Expected,
246262 if (ActualFixIt.getText () != Expected.Text )
247263 continue ;
248264
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 )
252267 continue ;
253- if (SM. getColumnInBuffer (Range. getEnd (), BufferID) != Expected.Range .EndCol )
268+ if (ActualRange. EndCol != Expected.Range .EndCol )
254269 continue ;
255270
256271 return true ;
@@ -260,31 +275,29 @@ bool DiagnosticVerifier::checkForFixIt(const ExpectedFixIt &Expected,
260275}
261276
262277std::string
263- DiagnosticVerifier::renderFixits (ArrayRef<DiagnosticInfo::FixIt> fixits ,
278+ DiagnosticVerifier::renderFixits (ArrayRef<CapturedFixItInfo> ActualFixIts ,
264279 unsigned BufferID) const {
265280 std::string Result;
266281 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 << ' ' ; });
288301 return OS.str ();
289302}
290303
@@ -628,8 +641,7 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
628641 };
629642
630643 auto makeActualFixitsPhrase =
631- [&](ArrayRef<DiagnosticInfo::FixIt> actualFixits)
632- -> ActualFixitsPhrase {
644+ [&](ArrayRef<CapturedFixItInfo> actualFixits) -> ActualFixitsPhrase {
633645 std::string actualFixitsStr = renderFixits (actualFixits, BufferID);
634646
635647 return ActualFixitsPhrase{(Twine (" actual fix-it" ) +
@@ -933,8 +945,10 @@ void DiagnosticVerifier::printRemainingDiagnostics() const {
933945// / file.
934946void DiagnosticVerifier::handleDiagnostic (SourceManager &SM,
935947 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+ }
938952
939953 llvm::SmallVector<std::string, 1 > eduNotes;
940954 for (auto ¬ePath : Info.EducationalNotePaths ) {
@@ -968,11 +982,11 @@ void DiagnosticVerifier::handleDiagnostic(SourceManager &SM,
968982
969983 capturedDiag.Loc = correctSM.getLocForForeignLoc (capturedDiag.Loc , SM);
970984 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 ();
974988 mutableRange =
975- CharSourceRange (newStart, fixIt.getRange ().getByteLength ());
989+ CharSourceRange (newStart, fixIt.getSourceRange ().getByteLength ());
976990 }
977991 }
978992}
0 commit comments