diff options
author | Zachary Turner <zturner@google.com> | 2016-05-06 20:51:57 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-05-06 20:51:57 +0000 |
commit | 819e77d196f208cc8ef15b4186e07ecb14a115c8 (patch) | |
tree | 409e2ff42a99563c75759c4c22116c35eb60569c /llvm/lib/DebugInfo/PDB/Raw/RawError.cpp | |
parent | 091fcfa3a7632b6bbfbefdac84e0425d827d288c (diff) | |
download | bcm5719-llvm-819e77d196f208cc8ef15b4186e07ecb14a115c8.tar.gz bcm5719-llvm-819e77d196f208cc8ef15b4186e07ecb14a115c8.zip |
Port DebugInfoPDB over to using llvm::Error.
Differential Revision: http://reviews.llvm.org/D19940
Reviewed By: rnk
llvm-svn: 268791
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/RawError.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/RawError.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/RawError.cpp b/llvm/lib/DebugInfo/PDB/Raw/RawError.cpp new file mode 100644 index 00000000000..aa6f15726a6 --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/Raw/RawError.cpp @@ -0,0 +1,52 @@ +#include "llvm/DebugInfo/PDB/Raw/RawError.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ManagedStatic.h" + +using namespace llvm; +using namespace llvm::pdb; + +class RawErrorCategory : public std::error_category { +public: + const char *name() const LLVM_NOEXCEPT override { return "llvm.pdb.raw"; } + + std::string message(int Condition) const override { + switch (static_cast<raw_error_code>(Condition)) { + case raw_error_code::unspecified: + return "An unknown error has occurred."; + case raw_error_code::feature_unsupported: + return "The feature is unsupported by the implementation."; + case raw_error_code::corrupt_file: + return "The PDB file is corrupt."; + case raw_error_code::insufficient_buffer: + return "The buffer is not large enough to read the requested number of " + "bytes."; + } + llvm_unreachable("Unrecognized raw_error_code"); + } +}; + +static ManagedStatic<RawErrorCategory> Category; + +char RawError::ID = 0; + +RawError::RawError(raw_error_code C) : RawError(C, "") {} + +RawError::RawError(const std::string &Context) + : RawError(raw_error_code::unspecified, Context) {} + +RawError::RawError(raw_error_code C, const std::string &Context) : Code(C) { + ErrMsg = "Native PDB Error: "; + std::error_code EC = convertToErrorCode(); + if (Code != raw_error_code::unspecified) + ErrMsg += EC.message() + " "; + if (!Context.empty()) + ErrMsg += Context; +} + +void RawError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; } + +const std::string &RawError::getErrorMessage() const { return ErrMsg; } + +std::error_code RawError::convertToErrorCode() const { + return std::error_code(static_cast<int>(Code), *Category); +} |