[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Highlighter.cpp ---------------------------------------------------===//
|
2018-08-02 08:30:15 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-08-02 08:30:15 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/Highlighter.h"
|
|
|
|
|
|
|
|
#include "lldb/Target/Language.h"
|
|
|
|
#include "lldb/Utility/AnsiTerminal.h"
|
|
|
|
#include "lldb/Utility/StreamString.h"
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
2019-08-21 08:50:46 +08:00
|
|
|
using namespace lldb_private::ansi;
|
2018-08-02 08:30:15 +08:00
|
|
|
|
2018-08-15 01:12:54 +08:00
|
|
|
void HighlightStyle::ColorStyle::Apply(Stream &s, llvm::StringRef value) const {
|
2018-08-02 08:30:15 +08:00
|
|
|
s << m_prefix << value << m_suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HighlightStyle::ColorStyle::Set(llvm::StringRef prefix,
|
|
|
|
llvm::StringRef suffix) {
|
2019-08-21 08:50:46 +08:00
|
|
|
m_prefix = FormatAnsiTerminalCodes(prefix);
|
|
|
|
m_suffix = FormatAnsiTerminalCodes(suffix);
|
2018-08-02 08:30:15 +08:00
|
|
|
}
|
|
|
|
|
2018-08-30 08:09:21 +08:00
|
|
|
void DefaultHighlighter::Highlight(const HighlightStyle &options,
|
|
|
|
llvm::StringRef line,
|
|
|
|
llvm::Optional<size_t> cursor_pos,
|
|
|
|
llvm::StringRef previous_lines,
|
|
|
|
Stream &s) const {
|
|
|
|
// If we don't have a valid cursor, then we just print the line as-is.
|
|
|
|
if (!cursor_pos || *cursor_pos >= line.size()) {
|
|
|
|
s << line;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a valid cursor, we have to apply the 'selected' style around
|
|
|
|
// the character below the cursor.
|
|
|
|
|
|
|
|
// Split the line around the character which is below the cursor.
|
|
|
|
size_t column = *cursor_pos;
|
|
|
|
// Print the characters before the cursor.
|
|
|
|
s << line.substr(0, column);
|
|
|
|
// Print the selected character with the defined color codes.
|
|
|
|
options.selected.Apply(s, line.substr(column, 1));
|
|
|
|
// Print the rest of the line.
|
|
|
|
s << line.substr(column + 1U);
|
2018-08-02 08:30:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static HighlightStyle::ColorStyle GetColor(const char *c) {
|
|
|
|
return HighlightStyle::ColorStyle(c, "${ansi.normal}");
|
|
|
|
}
|
|
|
|
|
|
|
|
HighlightStyle HighlightStyle::MakeVimStyle() {
|
|
|
|
HighlightStyle result;
|
|
|
|
result.comment = GetColor("${ansi.fg.purple}");
|
|
|
|
result.scalar_literal = GetColor("${ansi.fg.red}");
|
|
|
|
result.keyword = GetColor("${ansi.fg.green}");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Highlighter &
|
|
|
|
HighlighterManager::getHighlighterFor(lldb::LanguageType language_type,
|
|
|
|
llvm::StringRef path) const {
|
|
|
|
Language *language = lldb_private::Language::FindPlugin(language_type, path);
|
|
|
|
if (language && language->GetHighlighter())
|
|
|
|
return *language->GetHighlighter();
|
2018-08-30 08:09:21 +08:00
|
|
|
return m_default;
|
2018-08-02 08:30:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Highlighter::Highlight(const HighlightStyle &options,
|
|
|
|
llvm::StringRef line,
|
2018-08-30 08:09:21 +08:00
|
|
|
llvm::Optional<size_t> cursor_pos,
|
2018-08-02 08:30:15 +08:00
|
|
|
llvm::StringRef previous_lines) const {
|
|
|
|
StreamString s;
|
2018-08-30 08:09:21 +08:00
|
|
|
Highlight(options, line, cursor_pos, previous_lines, s);
|
2018-08-02 08:30:15 +08:00
|
|
|
s.Flush();
|
|
|
|
return s.GetString().str();
|
|
|
|
}
|