diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-01-18 19:28:01 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-01-18 19:28:01 +0000 |
commit | 9a48db1659dbd53cc71ecf940fb6a865f2ee4e26 (patch) | |
tree | c96222cb3c19ca15f999437ae68cc1f1f2b3325e /clang/lib/Frontend/TextDiagnosticPrinter.cpp | |
parent | 6bc5be24fad0c16646f07773f7a0f6fda32bcc53 (diff) | |
download | bcm5719-llvm-9a48db1659dbd53cc71ecf940fb6a865f2ee4e26.tar.gz bcm5719-llvm-9a48db1659dbd53cc71ecf940fb6a865f2ee4e26.zip |
Print fix-it hints properly around tabs, from Christian Adåker!
llvm-svn: 93750
Diffstat (limited to 'clang/lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r-- | clang/lib/Frontend/TextDiagnosticPrinter.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp b/clang/lib/Frontend/TextDiagnosticPrinter.cpp index fcefd4e3582..83b4542caa2 100644 --- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp @@ -428,6 +428,42 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc, } } } + // Now that we have the entire fixit line, expand the tabs in it. + // Since we don't want to insert spaces in the middle of a word, + // find each word and the column it should line up with and insert + // spaces until they match. + if (!FixItInsertionLine.empty()) { + unsigned FixItPos = 0; + unsigned LinePos = 0; + unsigned TabExpandedCol = 0; + unsigned LineLength = LineEnd - LineStart; + + while (FixItPos < FixItInsertionLine.size() && LinePos < LineLength) { + // Find the next word in the FixIt line. + while (FixItPos < FixItInsertionLine.size() && + FixItInsertionLine[FixItPos] == ' ') + ++FixItPos; + unsigned CharDistance = FixItPos - TabExpandedCol; + + // Walk forward in the source line, keeping track of + // the tab-expanded column. + for (unsigned I = 0; I < CharDistance; ++I, ++LinePos) + if (LinePos >= LineLength || LineStart[LinePos] != '\t') + ++TabExpandedCol; + else + TabExpandedCol = + (TabExpandedCol/DiagOpts->TabStop + 1) * DiagOpts->TabStop; + + // Adjust the fixit line to match this column. + FixItInsertionLine.insert(FixItPos, TabExpandedCol-FixItPos, ' '); + FixItPos = TabExpandedCol; + + // Walk to the end of the word. + while (FixItPos < FixItInsertionLine.size() && + FixItInsertionLine[FixItPos] != ' ') + ++FixItPos; + } + } } // If the source line is too long for our terminal, select only the |