aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2018-12-15 13:49:25 +0000
committerPavel Labath <pavel@labath.sk>2018-12-15 13:49:25 +0000
commitd211d1a59c2fa1b341607ec14059a11c70c5525e (patch)
tree6f7261b646868f3a772c05fcdf541aa06381620e /lldb/tools/lldb-test/FormatUtil.cpp
parentELF: more section creation cleanup (diff)
downloadllvm-project-d211d1a59c2fa1b341607ec14059a11c70c5525e.tar.gz
llvm-project-d211d1a59c2fa1b341607ec14059a11c70c5525e.tar.bz2
llvm-project-d211d1a59c2fa1b341607ec14059a11c70c5525e.zip
lldb-test: Improve newline handling
Summary: Previously lldb-test's LinePrinter would output the indentation spaces even on completely empty lines. This is not nice, as trailing spaces get flagged as errors in some tools/editors, and it prevents FileCheck's CHECK-EMPTY from working. Equally annoying was the fact that the LinePrinter did not terminate it's output with a newline (instead it would leave the unterminated hanging indent from the last NewLine() command), which meant that the shell prompt following the lldb-test command came out wrong. This fixes both issues by changing how newlines are handled. NewLine(), which was ending the previous line ('\n') *and* begging the next line by printing the indent, is now "demoted" to just printing literal "\n". Instead, lines are now delimited via a helper Line object, which makes sure the line is indented and terminated in an RAII fashion. The typical usage would be: Printer.line() << "This text will be indented and terminated"; If one needs to do more work than it will fit into a single statement, one can also assign the result of the line() function to a local variable. The line will then be terminated when that object goes out of scope. Reviewers: zturner Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D55597 llvm-svn: 349269
Diffstat (limited to 'lldb/tools/lldb-test/FormatUtil.cpp')
-rw-r--r--lldb/tools/lldb-test/FormatUtil.cpp47
1 files changed, 22 insertions, 25 deletions
diff --git a/lldb/tools/lldb-test/FormatUtil.cpp b/lldb/tools/lldb-test/FormatUtil.cpp
index 381cbd6e25b8..970f25a6b42f 100644
--- a/lldb/tools/lldb-test/FormatUtil.cpp
+++ b/lldb/tools/lldb-test/FormatUtil.cpp
@@ -14,6 +14,11 @@
using namespace lldb_private;
using namespace llvm;
+LinePrinter::Line::~Line() {
+ if (P)
+ P->NewLine();
+}
+
LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
: OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {}
@@ -31,39 +36,31 @@ void LinePrinter::Unindent(uint32_t Amount) {
void LinePrinter::NewLine() {
OS << "\n";
- OS.indent(CurrentIndent);
-}
-
-void LinePrinter::print(const Twine &T) { OS << T; }
-
-void LinePrinter::printLine(const Twine &T) {
- NewLine();
- OS << T;
}
void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
uint32_t StartOffset) {
- NewLine();
- OS << Label << " (";
- if (!Data.empty()) {
- OS << "\n";
- OS << format_bytes_with_ascii(Data, StartOffset, 32, 4,
- CurrentIndent + IndentSpaces, true);
- NewLine();
+ if (Data.empty()) {
+ line() << Label << " ()";
+ return;
}
- OS << ")";
+ line() << Label << " (";
+ OS << format_bytes_with_ascii(Data, StartOffset, 32, 4,
+ CurrentIndent + IndentSpaces, true);
+ NewLine();
+ line() << ")";
}
void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
uint64_t Base, uint32_t StartOffset) {
- NewLine();
- OS << Label << " (";
- if (!Data.empty()) {
- OS << "\n";
- Base += StartOffset;
- OS << format_bytes_with_ascii(Data, Base, 32, 4,
- CurrentIndent + IndentSpaces, true);
- NewLine();
+ if (Data.empty()) {
+ line() << Label << " ()";
+ return;
}
- OS << ")";
+ line() << Label << " (";
+ Base += StartOffset;
+ OS << format_bytes_with_ascii(Data, Base, 32, 4, CurrentIndent + IndentSpaces,
+ true);
+ NewLine();
+ line() << ")";
}