Error.cpp 1.5 KB

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