xref: /freebsd-src/contrib/llvm-project/llvm/tools/llvm-cxxdump/Error.cpp (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
10b57cec5SDimitry Andric //===- Error.cpp - system_error extensions for llvm-cxxdump -----*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This defines a new error_category for the llvm-cxxdump tool.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "Error.h"
140b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
15*349cc55cSDimitry Andric #include <string>
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric using namespace llvm;
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric namespace {
200b57cec5SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It
210b57cec5SDimitry Andric // will be removed once this transition is complete. Clients should prefer to
220b57cec5SDimitry Andric // deal with the Error value directly, rather than converting to error_code.
230b57cec5SDimitry Andric class cxxdump_error_category : public std::error_category {
240b57cec5SDimitry Andric public:
name() const250b57cec5SDimitry Andric   const char *name() const noexcept override { return "llvm.cxxdump"; }
message(int ev) const260b57cec5SDimitry Andric   std::string message(int ev) const override {
270b57cec5SDimitry Andric     switch (static_cast<cxxdump_error>(ev)) {
280b57cec5SDimitry Andric     case cxxdump_error::success:
290b57cec5SDimitry Andric       return "Success";
300b57cec5SDimitry Andric     case cxxdump_error::file_not_found:
310b57cec5SDimitry Andric       return "No such file.";
320b57cec5SDimitry Andric     case cxxdump_error::unrecognized_file_format:
330b57cec5SDimitry Andric       return "Unrecognized file type.";
340b57cec5SDimitry Andric     }
350b57cec5SDimitry Andric     llvm_unreachable(
360b57cec5SDimitry Andric         "An enumerator of cxxdump_error does not have a message defined.");
370b57cec5SDimitry Andric   }
380b57cec5SDimitry Andric };
390b57cec5SDimitry Andric } // namespace
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric namespace llvm {
cxxdump_category()420b57cec5SDimitry Andric const std::error_category &cxxdump_category() {
430b57cec5SDimitry Andric   static cxxdump_error_category o;
440b57cec5SDimitry Andric   return o;
450b57cec5SDimitry Andric }
460b57cec5SDimitry Andric } // namespace llvm
47