2014-05-07 07:18:51 +02:00
|
|
|
//===- Error.cpp - system_error extensions for obj2yaml ---------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-05-07 07:18:51 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Error.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
2016-05-24 22:13:46 +02:00
|
|
|
// FIXME: This class is only here to support the transition to llvm::Error. It
|
|
|
|
// will be removed once this transition is complete. Clients should prefer to
|
|
|
|
// deal with the Error value directly, rather than converting to error_code.
|
2014-06-12 03:45:43 +02:00
|
|
|
class _obj2yaml_error_category : public std::error_category {
|
2014-05-07 07:18:51 +02:00
|
|
|
public:
|
2016-10-20 01:52:38 +02:00
|
|
|
const char *name() const noexcept override;
|
2014-05-07 07:18:51 +02:00
|
|
|
std::string message(int ev) const override;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2016-10-20 01:52:38 +02:00
|
|
|
const char *_obj2yaml_error_category::name() const noexcept {
|
2014-09-11 19:19:54 +02:00
|
|
|
return "obj2yaml";
|
|
|
|
}
|
2014-05-07 07:18:51 +02:00
|
|
|
|
|
|
|
std::string _obj2yaml_error_category::message(int ev) const {
|
2014-06-11 03:09:09 +02:00
|
|
|
switch (static_cast<obj2yaml_error>(ev)) {
|
2014-05-07 07:18:51 +02:00
|
|
|
case obj2yaml_error::success:
|
|
|
|
return "Success";
|
|
|
|
case obj2yaml_error::file_not_found:
|
|
|
|
return "No such file.";
|
|
|
|
case obj2yaml_error::unrecognized_file_format:
|
|
|
|
return "Unrecognized file type.";
|
|
|
|
case obj2yaml_error::unsupported_obj_file_format:
|
|
|
|
return "Unsupported object file format.";
|
2016-05-12 00:07:45 +02:00
|
|
|
case obj2yaml_error::not_implemented:
|
|
|
|
return "Feature not yet implemented.";
|
2014-05-07 07:18:51 +02:00
|
|
|
}
|
2014-06-11 03:09:09 +02:00
|
|
|
llvm_unreachable("An enumerator of obj2yaml_error does not have a message "
|
|
|
|
"defined.");
|
2014-05-07 07:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace llvm {
|
2016-05-12 03:52:33 +02:00
|
|
|
|
|
|
|
const std::error_category &obj2yaml_category() {
|
2014-05-07 07:18:51 +02:00
|
|
|
static _obj2yaml_error_category o;
|
|
|
|
return o;
|
|
|
|
}
|
2016-05-12 03:52:33 +02:00
|
|
|
|
|
|
|
char Obj2YamlError::ID = 0;
|
|
|
|
|
2018-08-31 19:41:58 +02:00
|
|
|
void Obj2YamlError::log(raw_ostream &OS) const { OS << ErrMsg; }
|
2016-05-12 03:52:33 +02:00
|
|
|
|
|
|
|
std::error_code Obj2YamlError::convertToErrorCode() const {
|
|
|
|
return std::error_code(static_cast<int>(Code), obj2yaml_category());
|
|
|
|
}
|
|
|
|
|
2014-05-07 07:18:51 +02:00
|
|
|
} // namespace llvm
|