From: Douglas Gregor Date: Sun, 3 May 2009 04:12:51 +0000 (+0000) Subject: When we truncate a source line to fit it within the terminal width, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d101f6fd7f311b0a7fdd83a50f8668bd8a659cd;p=clang When we truncate a source line to fit it within the terminal width, show an ellipsis where we have removed text. An example: /Users/dgregor/Projects/llvm/tools/clang/test/Misc/message-length.c:18:120: warning: comparison of distinct pointer types ('int *' and 'float *') ...a_func_to_call(ip == FloatPointer, ip[ALongIndexName], ... ~~ ^ ~~~~~~~~~~~~ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70655 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index b8c10b536b..bcf30a5f56 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -143,7 +143,7 @@ static void SelectInterestingSourceRegion(std::string &SourceLine, if (CaretEnd < Columns) CaretStart = 0; - unsigned TargetColumns = Columns - 4; // Give us a little extra room. + unsigned TargetColumns = Columns - 8; // Give us extra room for the ellipses. unsigned SourceLength = SourceLine.size(); bool StartIsFixed = false; while (CaretEnd - CaretStart < TargetColumns) { @@ -231,16 +231,17 @@ static void SelectInterestingSourceRegion(std::string &SourceLine, // [CaretStart, CaretEnd) is the slice we want. Update the various // output lines to show only this slice, with two-space padding // before the lines so that it looks nicer. - SourceLine.erase(CaretEnd, std::string::npos); + if (CaretEnd < SourceLine.size()) + SourceLine.replace(CaretEnd, std::string::npos, "..."); CaretLine.erase(CaretEnd, std::string::npos); if (FixItInsertionLine.size() > CaretEnd) FixItInsertionLine.erase(CaretEnd, std::string::npos); if (CaretStart > 2) { - SourceLine.replace(0, CaretStart, " "); - CaretLine.replace(0, CaretStart, " "); + SourceLine.replace(0, CaretStart, " ..."); + CaretLine.replace(0, CaretStart, " "); if (FixItInsertionLine.size() >= CaretStart) - FixItInsertionLine.replace(0, CaretStart, " "); + FixItInsertionLine.replace(0, CaretStart, " "); } }