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