Lang Hames | e7aad35 | 2016-03-23 23:57:28 +0000 | [diff] [blame] | 1 | //===----- lib/Support/Error.cpp - Error and associated utilities ---------===// |
| 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 | |
| 10 | #include "llvm/Support/Error.h" |
| 11 | #include "llvm/Support/ErrorHandling.h" |
| 12 | #include "llvm/Support/ManagedStatic.h" |
| 13 | |
| 14 | using namespace llvm; |
| 15 | |
| 16 | namespace { |
| 17 | |
| 18 | enum class ErrorErrorCode { |
| 19 | MultipleErrors |
| 20 | }; |
| 21 | |
Peter Collingbourne | 4718f8b | 2016-05-24 20:13:46 +0000 | [diff] [blame^] | 22 | // FIXME: This class is only here to support the transition to llvm::Error. It |
| 23 | // will be removed once this transition is complete. Clients should prefer to |
| 24 | // deal with the Error value directly, rather than converting to error_code. |
Lang Hames | e7aad35 | 2016-03-23 23:57:28 +0000 | [diff] [blame] | 25 | class ErrorErrorCategory : public std::error_category { |
| 26 | public: |
| 27 | const char *name() const LLVM_NOEXCEPT override { return "Error"; } |
| 28 | |
| 29 | std::string message(int condition) const override { |
| 30 | switch (static_cast<ErrorErrorCode>(condition)) { |
| 31 | case ErrorErrorCode::MultipleErrors: |
| 32 | return "Multiple errors"; |
| 33 | }; |
| 34 | llvm_unreachable("Unhandled error code"); |
| 35 | } |
| 36 | }; |
| 37 | |
NAKAMURA Takumi | d8c1be6 | 2016-03-24 15:19:39 +0000 | [diff] [blame] | 38 | } |
Lang Hames | e7aad35 | 2016-03-23 23:57:28 +0000 | [diff] [blame] | 39 | |
| 40 | void ErrorInfoBase::anchor() {} |
| 41 | char ErrorInfoBase::ID = 0; |
Reid Kleckner | a15b76b | 2016-03-24 23:49:34 +0000 | [diff] [blame] | 42 | char ErrorList::ID = 0; |
| 43 | char ECError::ID = 0; |
NAKAMURA Takumi | e6d29c9 | 2016-03-24 15:26:43 +0000 | [diff] [blame] | 44 | |
Lang Hames | e7aad35 | 2016-03-23 23:57:28 +0000 | [diff] [blame] | 45 | static ManagedStatic<ErrorErrorCategory> ErrorErrorCat; |
| 46 | |
| 47 | std::error_code ErrorList::convertToErrorCode() const { |
| 48 | return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors), |
| 49 | *ErrorErrorCat); |
| 50 | } |