Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 1 | //===- MSFError.cpp - Error extensions for MSF files ------------*- C++ -*-===// |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/MSF/MSFError.h" |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 11 | #include "llvm/Support/ErrorHandling.h" |
| 12 | #include "llvm/Support/ManagedStatic.h" |
| 13 | |
| 14 | using namespace llvm; |
| 15 | using namespace llvm::msf; |
| 16 | |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 17 | // FIXME: This class is only here to support the transition to llvm::Error. It |
| 18 | // will be removed once this transition is complete. Clients should prefer to |
| 19 | // deal with the Error value directly, rather than converting to error_code. |
Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 20 | class MSFErrorCategory : public std::error_category { |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 21 | public: |
Reid Kleckner | 990504e | 2016-10-19 23:52:38 +0000 | [diff] [blame] | 22 | const char *name() const noexcept override { return "llvm.msf"; } |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 23 | std::string message(int Condition) const override { |
| 24 | switch (static_cast<msf_error_code>(Condition)) { |
| 25 | case msf_error_code::unspecified: |
| 26 | return "An unknown error has occurred."; |
| 27 | case msf_error_code::insufficient_buffer: |
| 28 | return "The buffer is not large enough to read the requested number of " |
| 29 | "bytes."; |
| 30 | case msf_error_code::not_writable: |
| 31 | return "The specified stream is not writable."; |
| 32 | case msf_error_code::no_stream: |
| 33 | return "The specified stream does not exist."; |
| 34 | case msf_error_code::invalid_format: |
| 35 | return "The data is in an unexpected format."; |
| 36 | case msf_error_code::block_in_use: |
| 37 | return "The block is already in use."; |
| 38 | } |
| 39 | llvm_unreachable("Unrecognized msf_error_code"); |
| 40 | } |
| 41 | }; |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 42 | |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 43 | static llvm::ManagedStatic<MSFErrorCategory> MSFCategory; |
| 44 | const std::error_category &llvm::msf::MSFErrCategory() { return *MSFCategory; } |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 45 | |
Alexandre Ganea | 6a7efef | 2018-08-31 17:41:58 +0000 | [diff] [blame] | 46 | char MSFError::ID; |