2018-07-24 02:09:43 +08:00
|
|
|
//===- Error.cpp - system_error extensions for llvm-cxxdump -----*- C++ -*-===//
|
2014-07-25 07:14:40 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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-07-25 07:14:40 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2015-03-15 09:30:58 +08:00
|
|
|
// This defines a new error_category for the llvm-cxxdump tool.
|
2014-07-25 07:14:40 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Error.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
2016-05-25 04:13:46 +08: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.
|
2015-03-15 09:30:58 +08:00
|
|
|
class cxxdump_error_category : public std::error_category {
|
2014-07-25 07:14:40 +08:00
|
|
|
public:
|
2016-10-20 07:52:38 +08:00
|
|
|
const char *name() const noexcept override { return "llvm.cxxdump"; }
|
2014-07-25 07:14:40 +08:00
|
|
|
std::string message(int ev) const override {
|
2015-03-15 09:30:58 +08:00
|
|
|
switch (static_cast<cxxdump_error>(ev)) {
|
|
|
|
case cxxdump_error::success:
|
2014-07-25 07:14:40 +08:00
|
|
|
return "Success";
|
2015-03-15 09:30:58 +08:00
|
|
|
case cxxdump_error::file_not_found:
|
2014-07-25 07:14:40 +08:00
|
|
|
return "No such file.";
|
2015-03-15 09:30:58 +08:00
|
|
|
case cxxdump_error::unrecognized_file_format:
|
2014-07-25 07:14:40 +08:00
|
|
|
return "Unrecognized file type.";
|
|
|
|
}
|
|
|
|
llvm_unreachable(
|
2015-03-15 09:30:58 +08:00
|
|
|
"An enumerator of cxxdump_error does not have a message defined.");
|
2014-07-25 07:14:40 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace llvm {
|
2015-03-15 09:30:58 +08:00
|
|
|
const std::error_category &cxxdump_category() {
|
|
|
|
static cxxdump_error_category o;
|
2014-07-25 07:14:40 +08:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
} // namespace llvm
|