Aaron Ballman | c250bf8 | 2018-07-23 18:09:43 +0000 | [diff] [blame] | 1 | //===- Error.cpp - system_error extensions for llvm-cxxdump -----*- C++ -*-===// |
David Majnemer | c976146 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 6b54768 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
David Majnemer | c976146 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This defines a new error_category for the llvm-cxxdump tool. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "Error.h" |
| 14 | #include "llvm/Support/ErrorHandling.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | namespace { |
Peter Collingbourne | 84e27c2 | 2016-05-24 20:13:46 +0000 | [diff] [blame] | 19 | // FIXME: This class is only here to support the transition to llvm::Error. It |
| 20 | // will be removed once this transition is complete. Clients should prefer to |
| 21 | // deal with the Error value directly, rather than converting to error_code. |
David Majnemer | c976146 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 22 | class cxxdump_error_category : public std::error_category { |
| 23 | public: |
Reid Kleckner | 5b1c9f3 | 2016-10-19 23:52:38 +0000 | [diff] [blame] | 24 | const char *name() const noexcept override { return "llvm.cxxdump"; } |
David Majnemer | c976146 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 25 | std::string message(int ev) const override { |
| 26 | switch (static_cast<cxxdump_error>(ev)) { |
| 27 | case cxxdump_error::success: |
| 28 | return "Success"; |
| 29 | case cxxdump_error::file_not_found: |
| 30 | return "No such file."; |
| 31 | case cxxdump_error::unrecognized_file_format: |
| 32 | return "Unrecognized file type."; |
| 33 | } |
| 34 | llvm_unreachable( |
| 35 | "An enumerator of cxxdump_error does not have a message defined."); |
| 36 | } |
| 37 | }; |
| 38 | } // namespace |
| 39 | |
| 40 | namespace llvm { |
| 41 | const std::error_category &cxxdump_category() { |
| 42 | static cxxdump_error_category o; |
| 43 | return o; |
| 44 | } |
| 45 | } // namespace llvm |