summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2019-11-14 11:11:20 +0100
committerRaphael Isemann <teemperor@gmail.com>2019-11-14 11:11:20 +0100
commit8715ffdf1aafbfca7c3d7f1622fe586243f31df1 (patch)
tree45e37c2cabbafcba1b77668932b1b95cb2633c73 /lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
parenta2f6ae9abffcba260c22bb235879f0576bf3b783 (diff)
downloadbcm5719-llvm-8715ffdf1aafbfca7c3d7f1622fe586243f31df1.tar.gz
bcm5719-llvm-8715ffdf1aafbfca7c3d7f1622fe586243f31df1.zip
[lldb] Fix that trailing backslashes in source lines break the Clang highlighter
Summary: Clang's raw Lexer doesn't produce any tokens for trailing backslashes in a line. This doesn't work with LLDB's Clang highlighter which builds the source code to display from the list of tokens the Lexer returns. This causes that lines with trailing backslashes are lacking the backslash and the following newline when rendering source code in LLDB. This patch removes the trailing newline from the current line we are highlighting. This way Clang doesn't drop the backslash token and we just restore the newline after tokenising. Fixes rdar://57091487 Reviewers: JDevlieghere, labath Reviewed By: JDevlieghere, labath Subscribers: labath, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D70177
Diffstat (limited to 'lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp')
-rw-r--r--lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp b/lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
index a9a1b44731f..3e77b164673 100644
--- a/lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
+++ b/lldb/source/Plugins/Language/ClangCommon/ClangHighlighter.cpp
@@ -139,6 +139,22 @@ void ClangHighlighter::Highlight(const HighlightStyle &options,
FileManager file_mgr(file_opts,
FileSystem::Instance().GetVirtualFileSystem());
+ // The line might end in a backslash which would cause Clang to drop the
+ // backslash and the terminating new line. This makes sense when parsing C++,
+ // but when highlighting we care about preserving the backslash/newline. To
+ // not lose this information we remove the new line here so that Clang knows
+ // this is just a single line we are highlighting. We add back the newline
+ // after tokenizing.
+ llvm::StringRef line_ending = "";
+ // There are a few legal line endings Clang recognizes and we need to
+ // temporarily remove from the string.
+ if (line.consume_back("\r\n"))
+ line_ending = "\r\n";
+ else if (line.consume_back("\n"))
+ line_ending = "\n";
+ else if (line.consume_back("\r"))
+ line_ending = "\r";
+
unsigned line_number = previous_lines.count('\n') + 1U;
// Let's build the actual source code Clang needs and setup some utility
@@ -227,6 +243,9 @@ void ClangHighlighter::Highlight(const HighlightStyle &options,
color.Apply(result, to_print);
}
+ // Add the line ending we trimmed before tokenizing.
+ result << line_ending;
+
// If we went over the whole file but couldn't find our own file, then
// somehow our setup was wrong. When we're in release mode we just give the
// user the normal line and pretend we don't know how to highlight it. In
OpenPOWER on IntegriCloud