[cfe-commits] r70656 - /cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
Douglas Gregor
dgregor at apple.com
Sat May 2 21:33:33 PDT 2009
Author: dgregor
Date: Sat May 2 23:33:32 2009
New Revision: 70656
URL: http://llvm.org/viewvc/llvm-project?rev=70656&view=rev
Log:
When a fix-it hint would span multiple lines, don't print it; half a
fix-it hint is much worse than no fix-it hint. (Fixes PR4084).
When we need to truncate a source line to fix in the terminal, make
sure to take the width of the fix-it information into account, too.
Modified:
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=70656&r1=70655&r2=70656&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Sat May 2 23:33:32 2009
@@ -132,7 +132,25 @@
for (; CaretEnd != CaretStart; --CaretEnd)
if (!isspace(CaretLine[CaretEnd - 1]))
break;
+
+ // If we have a fix-it line, make sure the slice includes all of the
+ // fix-it information.
+ if (!FixItInsertionLine.empty()) {
+ unsigned FixItStart = 0, FixItEnd = FixItInsertionLine.size();
+ for (; FixItStart != FixItEnd; ++FixItStart)
+ if (!isspace(FixItInsertionLine[FixItStart]))
+ break;
+ for (; FixItEnd != FixItStart; --FixItEnd)
+ if (!isspace(FixItInsertionLine[FixItEnd - 1]))
+ break;
+
+ if (FixItStart < CaretStart)
+ CaretStart = FixItStart;
+ if (FixItEnd > CaretEnd)
+ CaretEnd = FixItEnd;
+ }
+
// CaretLine[CaretStart, CaretEnd) contains all of the interesting
// parts of the caret line. While this slice is smaller than the
// number of columns we have, try to grow the slice to encompass
@@ -379,6 +397,9 @@
FixItInsertionLine.resize(LastColumnModified, ' ');
std::copy(Hint->CodeToInsert.begin(), Hint->CodeToInsert.end(),
FixItInsertionLine.begin() + HintColNo - 1);
+ } else {
+ FixItInsertionLine.clear();
+ break;
}
}
}
More information about the cfe-commits
mailing list