diff options
author | Jordan Rose <jordan_rose@apple.com> | 2013-06-07 17:16:01 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2013-06-07 17:16:01 +0000 |
commit | e2fad6d754fb97b6a1d531148392fd7e9a5e90a1 (patch) | |
tree | f938b2ed1832e5cec3fcfc9fdcc7ac2409129c2c /clang/lib/Frontend/TextDiagnostic.cpp | |
parent | 6d0004cd78606091c2e6c7f45373e0adc3b86379 (diff) | |
download | bcm5719-llvm-e2fad6d754fb97b6a1d531148392fd7e9a5e90a1.tar.gz bcm5719-llvm-e2fad6d754fb97b6a1d531148392fd7e9a5e90a1.zip |
Handle Unicode characters in fix-it replacement strings.
Patch by Sukolsak Sakshuwong!
llvm-svn: 183535
Diffstat (limited to 'clang/lib/Frontend/TextDiagnostic.cpp')
-rw-r--r-- | clang/lib/Frontend/TextDiagnostic.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index 1572d0f1d07..2da66d3b324 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -336,13 +336,10 @@ static void selectInterestingSourceRegion(std::string &SourceLine, if (MaxColumns <= Columns) return; - // no special characters allowed in CaretLine or FixItInsertionLine + // No special characters are allowed in CaretLine. assert(CaretLine.end() == std::find_if(CaretLine.begin(), CaretLine.end(), char_out_of_range(' ','~'))); - assert(FixItInsertionLine.end() == - std::find_if(FixItInsertionLine.begin(), FixItInsertionLine.end(), - char_out_of_range(' ','~'))); // Find the slice that we need to display the full caret line // correctly. @@ -370,8 +367,15 @@ static void selectInterestingSourceRegion(std::string &SourceLine, if (!isWhitespace(FixItInsertionLine[FixItEnd - 1])) break; - CaretStart = std::min(FixItStart, CaretStart); - CaretEnd = std::max(FixItEnd, CaretEnd); + // We can safely use the byte offset FixItStart as the column offset + // because the characters up until FixItStart are all ASCII whitespace + // characters. + unsigned FixItStartCol = FixItStart; + unsigned FixItEndCol + = llvm::sys::locale::columnWidth(FixItInsertionLine.substr(0, FixItEnd)); + + CaretStart = std::min(FixItStartCol, CaretStart); + CaretEnd = std::max(FixItEndCol, CaretEnd); } // CaretEnd may have been set at the middle of a character @@ -1023,24 +1027,18 @@ static std::string buildFixItInsertionLine(unsigned LineNo, if (HintCol < PrevHintEndCol) HintCol = PrevHintEndCol + 1; - // FIXME: This function handles multibyte characters in the source, but - // not in the fixits. This assertion is intended to catch unintended - // use of multibyte characters in fixits. If we decide to do this, we'll - // have to track separate byte widths for the source and fixit lines. - assert((size_t)llvm::sys::locale::columnWidth(I->CodeToInsert) == - I->CodeToInsert.size()); - - // This relies on one byte per column in our fixit hints. // This should NOT use HintByteOffset, because the source might have // Unicode characters in earlier columns. - unsigned LastColumnModified = HintCol + I->CodeToInsert.size(); - if (LastColumnModified > FixItInsertionLine.size()) - FixItInsertionLine.resize(LastColumnModified, ' '); + unsigned NewFixItLineSize = FixItInsertionLine.size() + + (HintCol - PrevHintEndCol) + I->CodeToInsert.size(); + if (NewFixItLineSize > FixItInsertionLine.size()) + FixItInsertionLine.resize(NewFixItLineSize, ' '); std::copy(I->CodeToInsert.begin(), I->CodeToInsert.end(), - FixItInsertionLine.begin() + HintCol); + FixItInsertionLine.end() - I->CodeToInsert.size()); - PrevHintEndCol = LastColumnModified; + PrevHintEndCol = + HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert); } else { FixItInsertionLine.clear(); break; |