@@ -237,34 +237,19 @@ verifyUnknown(SourceManager &SM,
237
237
}
238
238
} // end anonymous namespace
239
239
240
- static unsigned getColumnNumber (StringRef buffer, llvm::SMLoc loc) {
241
- assert (loc.getPointer () >= buffer.data ());
242
- assert ((size_t )(loc.getPointer () - buffer.data ()) <= buffer.size ());
243
-
244
- StringRef UpToLoc = buffer.slice (0 , loc.getPointer () - buffer.data ());
245
-
246
- size_t ColumnNo = UpToLoc.size ();
247
- size_t NewlinePos = UpToLoc.find_last_of (" \r\n " );
248
- if (NewlinePos != StringRef::npos)
249
- ColumnNo -= NewlinePos;
250
-
251
- return static_cast <unsigned >(ColumnNo);
252
- }
253
-
254
240
// / Return true if the given \p ExpectedFixIt is in the fix-its emitted by
255
241
// / diagnostic \p D.
256
242
bool DiagnosticVerifier::checkForFixIt (const ExpectedFixIt &Expected,
257
243
const CapturedDiagnosticInfo &D,
258
- StringRef buffer) {
244
+ unsigned BufferID) const {
259
245
for (auto &ActualFixIt : D.FixIts ) {
260
246
if (ActualFixIt.getText () != Expected.Text )
261
247
continue ;
262
248
263
249
CharSourceRange Range = ActualFixIt.getRange ();
264
- if (getColumnNumber (buffer, getRawLoc (Range.getStart ())) !=
265
- Expected.StartCol )
250
+ if (SM.getColumnInBuffer (Range.getStart (), BufferID) != Expected.StartCol )
266
251
continue ;
267
- if (getColumnNumber (buffer, getRawLoc ( Range.getEnd ()) ) != Expected.EndCol )
252
+ if (SM. getColumnInBuffer ( Range.getEnd (), BufferID ) != Expected.EndCol )
268
253
continue ;
269
254
270
255
return true ;
@@ -275,17 +260,17 @@ bool DiagnosticVerifier::checkForFixIt(const ExpectedFixIt &Expected,
275
260
276
261
std::string
277
262
DiagnosticVerifier::renderFixits (ArrayRef<DiagnosticInfo::FixIt> fixits,
278
- StringRef InputFile) {
263
+ unsigned BufferID) const {
279
264
std::string Result;
280
265
llvm::raw_string_ostream OS (Result);
281
266
interleave (fixits,
282
267
[&](const DiagnosticInfo::FixIt &ActualFixIt) {
283
268
CharSourceRange Range = ActualFixIt.getRange ();
284
269
285
270
OS << " {{"
286
- << getColumnNumber (InputFile, getRawLoc ( Range.getStart ()) )
271
+ << SM. getColumnInBuffer ( Range.getStart (), BufferID )
287
272
<< ' -'
288
- << getColumnNumber (InputFile, getRawLoc ( Range.getEnd ()) )
273
+ << SM. getColumnInBuffer ( Range.getEnd (), BufferID )
289
274
<< ' =' ;
290
275
291
276
for (auto C : ActualFixIt.getText ()) {
@@ -627,7 +612,7 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
627
612
// Verify that any expected fix-its are present in the diagnostic.
628
613
for (auto fixit : expected.Fixits ) {
629
614
// If we found it, we're ok.
630
- if (!checkForFixIt (fixit, FoundDiagnostic, InputFile )) {
615
+ if (!checkForFixIt (fixit, FoundDiagnostic, BufferID )) {
631
616
missedFixitLoc = fixit.StartLoc ;
632
617
break ;
633
618
}
@@ -644,7 +629,7 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
644
629
auto makeActualFixitsPhrase =
645
630
[&](ArrayRef<DiagnosticInfo::FixIt> actualFixits)
646
631
-> ActualFixitsPhrase {
647
- std::string actualFixitsStr = renderFixits (actualFixits, InputFile );
632
+ std::string actualFixitsStr = renderFixits (actualFixits, BufferID );
648
633
649
634
return ActualFixitsPhrase{(Twine (" actual fix-it" ) +
650
635
(actualFixits.size () >= 2 ? " s" : " " ) +
0 commit comments