@@ -357,13 +357,13 @@ struct SourceColumnMap {
357357static void selectInterestingSourceRegion (std::string &SourceLine,
358358 std::string &CaretLine,
359359 std::string &FixItInsertionLine,
360- unsigned NonGutterColumns,
360+ Columns NonGutterColumns,
361361 const SourceColumnMap &map) {
362362 Columns CaretColumns = Columns (CaretLine.size ());
363363 Columns FixItColumns =
364364 Columns (llvm::sys::locale::columnWidth (FixItInsertionLine));
365- unsigned MaxColumns =
366- std::max (map.columns ().V , std::max ( CaretColumns.V , FixItColumns.V ) );
365+ Columns MaxColumns =
366+ std::max ({ map.columns ().V , CaretColumns.V , FixItColumns.V } );
367367 // if the number of columns is less than the desired number we're done
368368 if (MaxColumns <= NonGutterColumns)
369369 return ;
@@ -391,21 +391,24 @@ static void selectInterestingSourceRegion(std::string &SourceLine,
391391 // We can safely use the byte offset FixItStart as the column offset
392392 // because the characters up until FixItStart are all ASCII whitespace
393393 // characters.
394- unsigned FixItStart = 0 , FixItEnd = FixItInsertionLine.size ();
395- for (; FixItStart != FixItEnd; ++FixItStart)
396- if (!isWhitespace (FixItInsertionLine[FixItStart]))
394+ Bytes FixItStart = 0 ;
395+ Bytes FixItEnd = Bytes (FixItInsertionLine.size ());
396+ for (; FixItStart != FixItEnd; FixItStart = FixItStart.next ())
397+ if (!isWhitespace (FixItInsertionLine[FixItStart.V ]))
397398 break ;
398399
399- for (; FixItEnd != FixItStart; -- FixItEnd)
400- if (!isWhitespace (FixItInsertionLine[FixItEnd - 1 ]))
400+ for (; FixItEnd != FixItStart; FixItEnd = FixItEnd. prev () )
401+ if (!isWhitespace (FixItInsertionLine[FixItEnd. V - 1 ]))
401402 break ;
402403
403- Columns FixItStartCol = FixItStart;
404- Columns FixItEndCol = Columns (
405- llvm::sys::locale::columnWidth (FixItInsertionLine.substr (0 , FixItEnd)));
404+ assert (map.byteToColumn (FixItStart).V == FixItStart.V &&
405+ " FixItStart should be all ASCII" );
406+ Columns FixItStartCol = Columns (FixItStart.V );
407+ Columns FixItEndCol = Columns (llvm::sys::locale::columnWidth (
408+ FixItInsertionLine.substr (0 , FixItEnd.V )));
406409
407- CaretStart = Columns ( std::min (FixItStartCol.V , CaretStart.V ) );
408- CaretEnd = Columns ( std::max (FixItEndCol.V , CaretEnd.V ) );
410+ CaretStart = std::min (FixItStartCol.V , CaretStart.V );
411+ CaretEnd = std::max (FixItEndCol.V , CaretEnd.V );
409412 }
410413
411414 // CaretEnd may have been set at the middle of a character
@@ -427,10 +430,8 @@ static void selectInterestingSourceRegion(std::string &SourceLine,
427430 // number of columns we have, try to grow the slice to encompass
428431 // more context.
429432
430- Bytes SourceStart =
431- map.columnToByte (Columns (std::min<int >(CaretStart.V , map.columns ().V )));
432- Bytes SourceEnd =
433- map.columnToByte (Columns (std::min<int >(CaretEnd.V , map.columns ().V )));
433+ Bytes SourceStart = map.columnToByte (std::min (CaretStart.V , map.columns ().V ));
434+ Bytes SourceEnd = map.columnToByte (std::min (CaretEnd.V , map.columns ().V ));
434435
435436 Columns CaretColumnsOutsideSource =
436437 CaretEnd - CaretStart -
@@ -1016,7 +1017,7 @@ static void highlightRange(const LineRange &R, const SourceColumnMap &Map,
10161017 StartByte = Map.startOfNextColumn (StartByte);
10171018
10181019 // Pick the last non-whitespace column.
1019- Bytes EndByte = Bytes{ std::min (R.EndByte .V , Map.bytes ().V )} ;
1020+ Bytes EndByte = std::min (R.EndByte .V , Map.bytes ().V );
10201021 while (EndByte.V != 0 && (Map.getSourceLine ()[EndByte.V - 1 ] == ' ' ||
10211022 Map.getSourceLine ()[EndByte.V - 1 ] == ' \t ' ))
10221023 EndByte = Map.startOfPreviousColumn (EndByte);
@@ -1437,7 +1438,8 @@ void TextDiagnostic::emitSnippetAndCaret(
14371438 // Next, insert the caret itself.
14381439 if (CaretLineNo == LineNo) {
14391440 Columns Col = SourceColMap.byteToContainingColumn (CaretByte.prev ());
1440- CaretLine.resize (std::max ((size_t )Col.V + 1 , CaretLine.size ()), ' ' );
1441+ CaretLine.resize (
1442+ std::max (static_cast <size_t >(Col.V ) + 1 , CaretLine.size ()), ' ' );
14411443 CaretLine[Col.V ] = ' ^' ;
14421444 }
14431445
@@ -1446,8 +1448,8 @@ void TextDiagnostic::emitSnippetAndCaret(
14461448
14471449 // If the source line is too long for our terminal, select only the
14481450 // "interesting" source region within that line.
1449- unsigned MessageLength = DiagOpts.MessageLength ;
1450- if (MessageLength)
1451+ Columns MessageLength = DiagOpts.MessageLength ;
1452+ if (MessageLength. V != 0 )
14511453 selectInterestingSourceRegion (SourceLine, CaretLine, FixItInsertionLine,
14521454 MessageLength, SourceColMap);
14531455
0 commit comments