Errc.h 3.7 KB

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