David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 1 | //===- Error.cxx - system_error extensions for llvm-cxxdump -----*- C++ -*-===// |
| 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 | // This defines a new error_category for the llvm-cxxdump tool. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Error.h" |
| 15 | #include "llvm/Support/ErrorHandling.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | |
| 19 | namespace { |
Peter Collingbourne | 4718f8b | 2016-05-24 20:13:46 +0000 | [diff] [blame] | 20 | // FIXME: This class is only here to support the transition to llvm::Error. It |
| 21 | // will be removed once this transition is complete. Clients should prefer to |
| 22 | // deal with the Error value directly, rather than converting to error_code. |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 23 | class cxxdump_error_category : public std::error_category { |
| 24 | public: |
Reid Kleckner | 990504e | 2016-10-19 23:52:38 +0000 | [diff] [blame] | 25 | const char *name() const noexcept override { return "llvm.cxxdump"; } |
David Majnemer | f45bbd0 | 2015-03-15 01:30:58 +0000 | [diff] [blame] | 26 | std::string message(int ev) const override { |
| 27 | switch (static_cast<cxxdump_error>(ev)) { |
| 28 | case cxxdump_error::success: |
| 29 | return "Success"; |
| 30 | case cxxdump_error::file_not_found: |
| 31 | return "No such file."; |
| 32 | case cxxdump_error::unrecognized_file_format: |
| 33 | return "Unrecognized file type."; |
| 34 | } |
| 35 | llvm_unreachable( |
| 36 | "An enumerator of cxxdump_error does not have a message defined."); |
| 37 | } |
| 38 | }; |
| 39 | } // namespace |
| 40 | |
| 41 | namespace llvm { |
| 42 | const std::error_category &cxxdump_category() { |
| 43 | static cxxdump_error_category o; |
| 44 | return o; |
| 45 | } |
| 46 | } // namespace llvm |