Errc.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Support/Errc.h - Defines the llvm::errc enum --------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // While std::error_code works OK on all platforms we use, there are some
  15. // some problems with std::errc that can be avoided by using our own
  16. // enumeration:
  17. //
  18. // * std::errc is a namespace in some implementations. That means that ADL
  19. // doesn't work and it is sometimes necessary to write std::make_error_code
  20. // or in templates:
  21. // using std::make_error_code;
  22. // make_error_code(...);
  23. //
  24. // with this enum it is safe to always just use make_error_code.
  25. //
  26. // * Some implementations define fewer names than others. This header has
  27. // the intersection of all the ones we support.
  28. //
  29. // * std::errc is just marked with is_error_condition_enum. This means that
  30. // common patterns like AnErrorCode == errc::no_such_file_or_directory take
  31. // 4 virtual calls instead of two comparisons.
  32. //===----------------------------------------------------------------------===//
  33. #ifndef LLVM_SUPPORT_ERRC_H
  34. #define LLVM_SUPPORT_ERRC_H
  35. #include <system_error>
  36. namespace llvm {
  37. enum class errc {
  38. argument_list_too_long = int(std::errc::argument_list_too_long),
  39. argument_out_of_domain = int(std::errc::argument_out_of_domain),
  40. bad_address = int(std::errc::bad_address),
  41. bad_file_descriptor = int(std::errc::bad_file_descriptor),
  42. broken_pipe = int(std::errc::broken_pipe),
  43. device_or_resource_busy = int(std::errc::device_or_resource_busy),
  44. directory_not_empty = int(std::errc::directory_not_empty),
  45. executable_format_error = int(std::errc::executable_format_error),
  46. file_exists = int(std::errc::file_exists),
  47. file_too_large = int(std::errc::file_too_large),
  48. filename_too_long = int(std::errc::filename_too_long),
  49. function_not_supported = int(std::errc::function_not_supported),
  50. illegal_byte_sequence = int(std::errc::illegal_byte_sequence),
  51. inappropriate_io_control_operation =
  52. int(std::errc::inappropriate_io_control_operation),
  53. interrupted = int(std::errc::interrupted),
  54. invalid_argument = int(std::errc::invalid_argument),
  55. invalid_seek = int(std::errc::invalid_seek),
  56. io_error = int(std::errc::io_error),
  57. is_a_directory = int(std::errc::is_a_directory),
  58. no_child_process = int(std::errc::no_child_process),
  59. no_lock_available = int(std::errc::no_lock_available),
  60. no_space_on_device = int(std::errc::no_space_on_device),
  61. no_such_device_or_address = int(std::errc::no_such_device_or_address),
  62. no_such_device = int(std::errc::no_such_device),
  63. no_such_file_or_directory = int(std::errc::no_such_file_or_directory),
  64. no_such_process = int(std::errc::no_such_process),
  65. not_a_directory = int(std::errc::not_a_directory),
  66. not_enough_memory = int(std::errc::not_enough_memory),
  67. not_supported = int(std::errc::not_supported),
  68. operation_not_permitted = int(std::errc::operation_not_permitted),
  69. permission_denied = int(std::errc::permission_denied),
  70. read_only_file_system = int(std::errc::read_only_file_system),
  71. resource_deadlock_would_occur = int(std::errc::resource_deadlock_would_occur),
  72. resource_unavailable_try_again =
  73. int(std::errc::resource_unavailable_try_again),
  74. result_out_of_range = int(std::errc::result_out_of_range),
  75. too_many_files_open_in_system = int(std::errc::too_many_files_open_in_system),
  76. too_many_files_open = int(std::errc::too_many_files_open),
  77. too_many_links = int(std::errc::too_many_links)
  78. };
  79. inline std::error_code make_error_code(errc E) {
  80. return std::error_code(static_cast<int>(E), std::generic_category());
  81. }
  82. }
  83. namespace std {
  84. template <> struct is_error_code_enum<llvm::errc> : std::true_type {};
  85. }
  86. #endif
  87. #ifdef __GNUC__
  88. #pragma GCC diagnostic pop
  89. #endif