Error.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //===- Error.cpp - system_error extensions for llvm-cxxdump -----*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This defines a new error_category for the llvm-cxxdump tool.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "Error.h"
  13. #include "llvm/Support/ErrorHandling.h"
  14. #include <string>
  15. using namespace llvm;
  16. namespace {
  17. // FIXME: This class is only here to support the transition to llvm::Error. It
  18. // will be removed once this transition is complete. Clients should prefer to
  19. // deal with the Error value directly, rather than converting to error_code.
  20. class cxxdump_error_category : public std::error_category {
  21. public:
  22. const char *name() const noexcept override { return "llvm.cxxdump"; }
  23. std::string message(int ev) const override {
  24. switch (static_cast<cxxdump_error>(ev)) {
  25. case cxxdump_error::success:
  26. return "Success";
  27. case cxxdump_error::file_not_found:
  28. return "No such file.";
  29. case cxxdump_error::unrecognized_file_format:
  30. return "Unrecognized file type.";
  31. }
  32. llvm_unreachable(
  33. "An enumerator of cxxdump_error does not have a message defined.");
  34. }
  35. };
  36. } // namespace
  37. namespace llvm {
  38. const std::error_category &cxxdump_category() {
  39. static cxxdump_error_category o;
  40. return o;
  41. }
  42. } // namespace llvm