1*9880d681SAndroid Build Coastguard Worker //===- Error.cxx - system_error extensions for llvm-cxxdump -----*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This defines a new error_category for the llvm-cxxdump tool. 11*9880d681SAndroid Build Coastguard Worker // 12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker #include "Error.h" 15*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ErrorHandling.h" 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker using namespace llvm; 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker namespace { 20*9880d681SAndroid Build Coastguard Worker // FIXME: This class is only here to support the transition to llvm::Error. It 21*9880d681SAndroid Build Coastguard Worker // will be removed once this transition is complete. Clients should prefer to 22*9880d681SAndroid Build Coastguard Worker // deal with the Error value directly, rather than converting to error_code. 23*9880d681SAndroid Build Coastguard Worker class cxxdump_error_category : public std::error_category { 24*9880d681SAndroid Build Coastguard Worker public: name() const25*9880d681SAndroid Build Coastguard Worker const char *name() const LLVM_NOEXCEPT override { return "llvm.cxxdump"; } message(int ev) const26*9880d681SAndroid Build Coastguard Worker std::string message(int ev) const override { 27*9880d681SAndroid Build Coastguard Worker switch (static_cast<cxxdump_error>(ev)) { 28*9880d681SAndroid Build Coastguard Worker case cxxdump_error::success: 29*9880d681SAndroid Build Coastguard Worker return "Success"; 30*9880d681SAndroid Build Coastguard Worker case cxxdump_error::file_not_found: 31*9880d681SAndroid Build Coastguard Worker return "No such file."; 32*9880d681SAndroid Build Coastguard Worker case cxxdump_error::unrecognized_file_format: 33*9880d681SAndroid Build Coastguard Worker return "Unrecognized file type."; 34*9880d681SAndroid Build Coastguard Worker } 35*9880d681SAndroid Build Coastguard Worker llvm_unreachable( 36*9880d681SAndroid Build Coastguard Worker "An enumerator of cxxdump_error does not have a message defined."); 37*9880d681SAndroid Build Coastguard Worker } 38*9880d681SAndroid Build Coastguard Worker }; 39*9880d681SAndroid Build Coastguard Worker } // namespace 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Worker namespace llvm { cxxdump_category()42*9880d681SAndroid Build Coastguard Workerconst std::error_category &cxxdump_category() { 43*9880d681SAndroid Build Coastguard Worker static cxxdump_error_category o; 44*9880d681SAndroid Build Coastguard Worker return o; 45*9880d681SAndroid Build Coastguard Worker } 46*9880d681SAndroid Build Coastguard Worker } // namespace llvm 47