[Lldb-commits] [PATCH] D28519: Add format_provider for the Error class
Pavel Labath via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Jan 10 08:30:41 PST 2017
labath created this revision.
labath added reviewers: zturner, clayborg.
labath added a subscriber: lldb-commits.
Herald added a subscriber: mgorny.
The formatter supports the same options as the string-like classes, i.e. the
ability to truncate the displayed string. I don't anticipate it would be much
used, but it seems consistent.
https://reviews.llvm.org/D28519
Files:
include/lldb/Core/Error.h
unittests/Core/CMakeLists.txt
unittests/Core/ErrorTest.cpp
Index: unittests/Core/ErrorTest.cpp
===================================================================
--- /dev/null
+++ unittests/Core/ErrorTest.cpp
@@ -0,0 +1,19 @@
+//===-- ErrorTest.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "lldb/Core/Error.h"
+
+using namespace lldb_private;
+
+TEST(ErrorTest, Formatv) {
+ EXPECT_EQ("", llvm::formatv("{0}", Error()).str());
+ EXPECT_EQ("Hello Error", llvm::formatv("{0}", Error("Hello Error")).str());
+ EXPECT_EQ("Hello", llvm::formatv("{0:5}", Error("Hello Error")).str());
+}
Index: unittests/Core/CMakeLists.txt
===================================================================
--- unittests/Core/CMakeLists.txt
+++ unittests/Core/CMakeLists.txt
@@ -2,6 +2,7 @@
ArchSpecTest.cpp
BroadcasterTest.cpp
DataExtractorTest.cpp
+ ErrorTest.cpp
ListenerTest.cpp
ScalarTest.cpp
StructuredDataTest.cpp
Index: include/lldb/Core/Error.h
===================================================================
--- include/lldb/Core/Error.h
+++ include/lldb/Core/Error.h
@@ -12,6 +12,7 @@
#if defined(__cplusplus)
#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/FormatVariadic.h"
#include <cstdarg>
#include <cstdio>
@@ -300,5 +301,15 @@
} // namespace lldb_private
+namespace llvm {
+template <> struct llvm::format_provider<lldb_private::Error> {
+ static void format(const lldb_private::Error &error, llvm::raw_ostream &OS,
+ llvm::StringRef Options) {
+ llvm::format_provider<llvm::StringRef>::format(error.AsCString(), OS,
+ Options);
+ }
+};
+}
+
#endif // #if defined(__cplusplus)
#endif // #ifndef __DCError_h__
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28519.83813.patch
Type: text/x-patch
Size: 2000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170110/b8c7aaa1/attachment-0001.bin>
More information about the lldb-commits
mailing list