1 //===- Error.cpp - system_error extensions for obj2yaml ---------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/ErrorHandling.h"
15 // FIXME: This class is only here to support the transition to llvm::Error. It
16 // will be removed once this transition is complete. Clients should prefer to
17 // deal with the Error value directly, rather than converting to error_code.
18 class _obj2yaml_error_category
: public std::error_category
{
20 const char *name() const noexcept override
;
21 std::string
message(int ev
) const override
;
25 const char *_obj2yaml_error_category::name() const noexcept
{
29 std::string
_obj2yaml_error_category::message(int ev
) const {
30 switch (static_cast<obj2yaml_error
>(ev
)) {
31 case obj2yaml_error::success
:
33 case obj2yaml_error::file_not_found
:
34 return "No such file.";
35 case obj2yaml_error::unrecognized_file_format
:
36 return "Unrecognized file type.";
37 case obj2yaml_error::unsupported_obj_file_format
:
38 return "Unsupported object file format.";
39 case obj2yaml_error::not_implemented
:
40 return "Feature not yet implemented.";
42 llvm_unreachable("An enumerator of obj2yaml_error does not have a message "
48 const std::error_category
&obj2yaml_category() {
49 static _obj2yaml_error_category o
;
53 char Obj2YamlError::ID
= 0;
55 void Obj2YamlError::log(raw_ostream
&OS
) const { OS
<< ErrMsg
; }
57 std::error_code
Obj2YamlError::convertToErrorCode() const {
58 return std::error_code(static_cast<int>(Code
), obj2yaml_category());