summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/MSF/MSFError.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-07-29 20:56:36 +0000
committerZachary Turner <zturner@google.com>2016-07-29 20:56:36 +0000
commita3225b0451cc68788db10c62a66bb189817658b1 (patch)
tree8e91ca1dab5f2c9a04964eaa93fa0db40688ffaf /llvm/lib/DebugInfo/MSF/MSFError.cpp
parentecbe2ea002cdc4c1da279121ed66c459f0c5a3e2 (diff)
downloadbcm5719-llvm-a3225b0451cc68788db10c62a66bb189817658b1.tar.gz
bcm5719-llvm-a3225b0451cc68788db10c62a66bb189817658b1.zip
[msf] Resubmit "Rename Msf -> MSF".
Previously this change was submitted from a Windows machine, so changes made to the case of filenames and directory names did not survive the commit, and as a result the CMake source file names and the on-disk file names did not match on case-sensitive file systems. I'm resubmitting this patch from a Linux system, which hopefully allows the case changes to make it through unfettered. llvm-svn: 277213
Diffstat (limited to 'llvm/lib/DebugInfo/MSF/MSFError.cpp')
-rw-r--r--llvm/lib/DebugInfo/MSF/MSFError.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/MSF/MSFError.cpp b/llvm/lib/DebugInfo/MSF/MSFError.cpp
new file mode 100644
index 00000000000..5272cad3890
--- /dev/null
+++ b/llvm/lib/DebugInfo/MSF/MSFError.cpp
@@ -0,0 +1,70 @@
+//===- MSFError.cpp - Error extensions for MSF files ------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/DebugInfo/MSF/MSFError.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ManagedStatic.h"
+
+using namespace llvm;
+using namespace llvm::msf;
+
+namespace {
+// FIXME: This class is only here to support the transition to llvm::Error. It
+// will be removed once this transition is complete. Clients should prefer to
+// deal with the Error value directly, rather than converting to error_code.
+class MSFErrorCategory : public std::error_category {
+public:
+ const char *name() const LLVM_NOEXCEPT override { return "llvm.msf"; }
+
+ std::string message(int Condition) const override {
+ switch (static_cast<msf_error_code>(Condition)) {
+ case msf_error_code::unspecified:
+ return "An unknown error has occurred.";
+ case msf_error_code::insufficient_buffer:
+ return "The buffer is not large enough to read the requested number of "
+ "bytes.";
+ case msf_error_code::not_writable:
+ return "The specified stream is not writable.";
+ case msf_error_code::no_stream:
+ return "The specified stream does not exist.";
+ case msf_error_code::invalid_format:
+ return "The data is in an unexpected format.";
+ case msf_error_code::block_in_use:
+ return "The block is already in use.";
+ }
+ llvm_unreachable("Unrecognized msf_error_code");
+ }
+};
+} // end anonymous namespace
+
+static ManagedStatic<MSFErrorCategory> Category;
+
+char MSFError::ID = 0;
+
+MSFError::MSFError(msf_error_code C) : MSFError(C, "") {}
+
+MSFError::MSFError(const std::string &Context)
+ : MSFError(msf_error_code::unspecified, Context) {}
+
+MSFError::MSFError(msf_error_code C, const std::string &Context) : Code(C) {
+ ErrMsg = "MSF Error: ";
+ std::error_code EC = convertToErrorCode();
+ if (Code != msf_error_code::unspecified)
+ ErrMsg += EC.message() + " ";
+ if (!Context.empty())
+ ErrMsg += Context;
+}
+
+void MSFError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
+
+const std::string &MSFError::getErrorMessage() const { return ErrMsg; }
+
+std::error_code MSFError::convertToErrorCode() const {
+ return std::error_code(static_cast<int>(Code), *Category);
+}
OpenPOWER on IntegriCloud