diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-05-03 04:12:51 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-05-03 04:12:51 +0000 |
commit | 7d101f6fd7f311b0a7fdd83a50f8668bd8a659cd (patch) | |
tree | 6625864f5ddf85679d45a6f17c4f9e8f1cf2905f /lib/Frontend/TextDiagnosticPrinter.cpp | |
parent | 44cf08ecf648210347191942b1664e36d46290c5 (diff) |
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
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnosticPrinter.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
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, " "); } } |