@@ -856,15 +856,14 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
856
856
FileID CaretFileID = Loc.getExpansionLoc ().getFileID ();
857
857
bool PrintedRange = false ;
858
858
859
- for (ArrayRef<CharSourceRange>::const_iterator RI = Ranges.begin (),
860
- RE = Ranges.end ();
861
- RI != RE; ++RI) {
859
+ for (const auto &R : Ranges) {
862
860
// Ignore invalid ranges.
863
- if (!RI->isValid ()) continue ;
861
+ if (!R.isValid ())
862
+ continue ;
864
863
865
864
auto &SM = Loc.getManager ();
866
- SourceLocation B = SM.getExpansionLoc (RI-> getBegin ());
867
- CharSourceRange ERange = SM.getExpansionRange (RI-> getEnd ());
865
+ SourceLocation B = SM.getExpansionLoc (R. getBegin ());
866
+ CharSourceRange ERange = SM.getExpansionRange (R. getEnd ());
868
867
SourceLocation E = ERange.getEnd ();
869
868
bool IsTokenRange = ERange.isTokenRange ();
870
869
@@ -1068,51 +1067,51 @@ static std::string buildFixItInsertionLine(FileID FID,
1068
1067
return FixItInsertionLine;
1069
1068
unsigned PrevHintEndCol = 0 ;
1070
1069
1071
- for (ArrayRef<FixItHint>::iterator I = Hints. begin (), E = Hints. end ();
1072
- I != E; ++I) {
1073
- if (!I-> CodeToInsert . empty ()) {
1074
- // We have an insertion hint. Determine whether the inserted
1075
- // code contains no newlines and is on the same line as the caret.
1076
- std::pair<FileID, unsigned > HintLocInfo
1077
- = SM. getDecomposedExpansionLoc (I-> RemoveRange . getBegin ());
1078
- if (FID == HintLocInfo. first &&
1079
- LineNo == SM. getLineNumber ( HintLocInfo.first , HintLocInfo. second ) &&
1080
- StringRef (I-> CodeToInsert ). find_first_of ( " \n\r " ) == StringRef::npos) {
1081
- // Insert the new code into the line just below the code
1082
- // that the user wrote.
1083
- // Note: When modifying this function, be very careful about what is a
1084
- // "column" (printed width, platform-dependent) and what is a
1085
- // "byte offset " (SourceManager "column").
1086
- unsigned HintByteOffset
1087
- = SM. getColumnNumber (HintLocInfo. first , HintLocInfo. second ) - 1 ;
1088
-
1089
- // The hint must start inside the source or right at the end
1090
- assert (HintByteOffset < static_cast < unsigned >(map. bytes ())+ 1 );
1091
- unsigned HintCol = map.byteToContainingColumn (HintByteOffset );
1092
-
1093
- // If we inserted a long previous hint, push this one forwards, and add
1094
- // an extra space to show that this is not part of the previous
1095
- // completion. This is sort of the best we can do when two hints appear
1096
- // to overlap.
1097
- //
1098
- // Note that if this hint is located immediately after the previous
1099
- // hint, no space will be added, since the location is more important.
1100
- if (HintCol < PrevHintEndCol)
1101
- HintCol = PrevHintEndCol + 1 ;
1102
-
1103
- // This should NOT use HintByteOffset, because the source might have
1104
- // Unicode characters in earlier columns.
1105
- unsigned NewFixItLineSize = FixItInsertionLine. size () +
1106
- (HintCol - PrevHintEndCol) + I-> CodeToInsert .size ();
1107
- if (NewFixItLineSize > FixItInsertionLine. size ())
1108
- FixItInsertionLine. resize (NewFixItLineSize, ' ' );
1109
-
1110
- std::copy (I-> CodeToInsert . begin (), I-> CodeToInsert . end (),
1111
- FixItInsertionLine. end () - I-> CodeToInsert . size ());
1112
-
1113
- PrevHintEndCol =
1114
- HintCol + llvm::sys::locale::columnWidth (I-> CodeToInsert );
1115
- }
1070
+ for (const auto &H : Hints) {
1071
+ if (H. CodeToInsert . empty ())
1072
+ continue ;
1073
+
1074
+ // We have an insertion hint. Determine whether the inserted
1075
+ // code contains no newlines and is on the same line as the caret.
1076
+ std::pair<FileID, unsigned > HintLocInfo =
1077
+ SM. getDecomposedExpansionLoc (H. RemoveRange . getBegin ());
1078
+ if (FID == HintLocInfo.first &&
1079
+ LineNo == SM. getLineNumber (HintLocInfo. first , HintLocInfo. second ) &&
1080
+ StringRef (H. CodeToInsert ). find_first_of ( " \n\r " ) == StringRef::npos) {
1081
+ // Insert the new code into the line just below the code
1082
+ // that the user wrote.
1083
+ // Note: When modifying this function, be very careful about what is a
1084
+ // "column " (printed width, platform-dependent) and what is a
1085
+ // "byte offset" (SourceManager "column").
1086
+ unsigned HintByteOffset =
1087
+ SM. getColumnNumber (HintLocInfo. first , HintLocInfo. second ) - 1 ;
1088
+
1089
+ // The hint must start inside the source or right at the end
1090
+ assert (HintByteOffset < static_cast < unsigned >( map.bytes ()) + 1 );
1091
+ unsigned HintCol = map. byteToContainingColumn (HintByteOffset);
1092
+
1093
+ // If we inserted a long previous hint, push this one forwards, and add
1094
+ // an extra space to show that this is not part of the previous
1095
+ // completion. This is sort of the best we can do when two hints appear
1096
+ // to overlap.
1097
+ //
1098
+ // Note that if this hint is located immediately after the previous
1099
+ // hint, no space will be added, since the location is more important.
1100
+ if ( HintCol < PrevHintEndCol)
1101
+ HintCol = PrevHintEndCol + 1 ;
1102
+
1103
+ // This should NOT use HintByteOffset, because the source might have
1104
+ // Unicode characters in earlier columns.
1105
+ unsigned NewFixItLineSize = FixItInsertionLine .size () +
1106
+ (HintCol - PrevHintEndCol) +
1107
+ H. CodeToInsert . size ( );
1108
+ if (NewFixItLineSize > FixItInsertionLine. size ())
1109
+ FixItInsertionLine. resize (NewFixItLineSize, ' ' );
1110
+
1111
+ std::copy (H. CodeToInsert . begin (), H. CodeToInsert . end (),
1112
+ FixItInsertionLine. end () - H. CodeToInsert . size ());
1113
+
1114
+ PrevHintEndCol = HintCol + llvm::sys::locale::columnWidth (H. CodeToInsert );
1116
1115
}
1117
1116
}
1118
1117
@@ -1168,7 +1167,7 @@ void TextDiagnostic::emitSnippetAndCaret(
1168
1167
// Find the set of lines to include.
1169
1168
const unsigned MaxLines = DiagOpts->SnippetLineLimit ;
1170
1169
std::pair<unsigned , unsigned > Lines = {CaretLineNo, CaretLineNo};
1171
- for (auto &I : Ranges) {
1170
+ for (const auto &I : Ranges) {
1172
1171
if (auto OptionalRange = findLinesForRange (I, FID, SM))
1173
1172
Lines = maybeAddRange (Lines, *OptionalRange, MaxLines);
1174
1173
}
@@ -1211,7 +1210,7 @@ void TextDiagnostic::emitSnippetAndCaret(
1211
1210
std::string CaretLine (sourceColMap.columns (), ' ' );
1212
1211
1213
1212
// Highlight all of the characters covered by Ranges with ~ characters.
1214
- for (auto &I : Ranges)
1213
+ for (const auto &I : Ranges)
1215
1214
highlightRange (I, LineNo, FID, sourceColMap, CaretLine, SM, LangOpts);
1216
1215
1217
1216
// Next, insert the caret itself.
@@ -1315,24 +1314,21 @@ void TextDiagnostic::emitParseableFixits(ArrayRef<FixItHint> Hints,
1315
1314
1316
1315
// We follow FixItRewriter's example in not (yet) handling
1317
1316
// fix-its in macros.
1318
- for (ArrayRef<FixItHint>::iterator I = Hints.begin (), E = Hints.end ();
1319
- I != E; ++I) {
1320
- if (I->RemoveRange .isInvalid () ||
1321
- I->RemoveRange .getBegin ().isMacroID () ||
1322
- I->RemoveRange .getEnd ().isMacroID ())
1317
+ for (const auto &H : Hints) {
1318
+ if (H.RemoveRange .isInvalid () || H.RemoveRange .getBegin ().isMacroID () ||
1319
+ H.RemoveRange .getEnd ().isMacroID ())
1323
1320
return ;
1324
1321
}
1325
1322
1326
- for (ArrayRef<FixItHint>::iterator I = Hints.begin (), E = Hints.end ();
1327
- I != E; ++I) {
1328
- SourceLocation BLoc = I->RemoveRange .getBegin ();
1329
- SourceLocation ELoc = I->RemoveRange .getEnd ();
1323
+ for (const auto &H : Hints) {
1324
+ SourceLocation BLoc = H.RemoveRange .getBegin ();
1325
+ SourceLocation ELoc = H.RemoveRange .getEnd ();
1330
1326
1331
1327
std::pair<FileID, unsigned > BInfo = SM.getDecomposedLoc (BLoc);
1332
1328
std::pair<FileID, unsigned > EInfo = SM.getDecomposedLoc (ELoc);
1333
1329
1334
1330
// Adjust for token ranges.
1335
- if (I-> RemoveRange .isTokenRange ())
1331
+ if (H. RemoveRange .isTokenRange ())
1336
1332
EInfo.second += Lexer::MeasureTokenLength (ELoc, SM, LangOpts);
1337
1333
1338
1334
// We specifically do not do word-wrapping or tab-expansion here,
@@ -1348,7 +1344,7 @@ void TextDiagnostic::emitParseableFixits(ArrayRef<FixItHint> Hints,
1348
1344
<< ' -' << SM.getLineNumber (EInfo.first , EInfo.second )
1349
1345
<< ' :' << SM.getColumnNumber (EInfo.first , EInfo.second )
1350
1346
<< " }:\" " ;
1351
- OS.write_escaped (I-> CodeToInsert );
1347
+ OS.write_escaped (H. CodeToInsert );
1352
1348
OS << " \"\n " ;
1353
1349
}
1354
1350
}
0 commit comments