5b07b9cda8d6eab3ffefe81a5df28b2ddc7ae145
[oota-llvm.git] / tools / obj2yaml / Error.cpp
1 //===- Error.cpp - system_error extensions for obj2yaml ---------*- 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 #include "Error.h"
11 #include "llvm/Support/ErrorHandling.h"
12
13 using namespace llvm;
14
15 namespace {
16 class _obj2yaml_error_category : public std::error_category {
17 public:
18   const char *name() const LLVM_NOEXCEPT override;
19   std::string message(int ev) const override;
20   std::error_condition
21   default_error_condition(int ev) const LLVM_NOEXCEPT override;
22 };
23 } // namespace
24
25 const char *_obj2yaml_error_category::name() const { return "obj2yaml"; }
26
27 std::string _obj2yaml_error_category::message(int ev) const {
28   switch (static_cast<obj2yaml_error>(ev)) {
29   case obj2yaml_error::success:
30     return "Success";
31   case obj2yaml_error::file_not_found:
32     return "No such file.";
33   case obj2yaml_error::unrecognized_file_format:
34     return "Unrecognized file type.";
35   case obj2yaml_error::unsupported_obj_file_format:
36     return "Unsupported object file format.";
37   }
38   llvm_unreachable("An enumerator of obj2yaml_error does not have a message "
39                    "defined.");
40 }
41
42 std::error_condition
43 _obj2yaml_error_category::default_error_condition(int ev) const {
44   if (static_cast<obj2yaml_error>(ev) == obj2yaml_error::success)
45     return std::error_condition();
46   return std::errc::invalid_argument;
47 }
48
49 namespace llvm {
50   const std::error_category &obj2yaml_category() {
51   static _obj2yaml_error_category o;
52   return o;
53 }
54 } // namespace llvm