llvm.org GIT mirror llvm / fae76d0
This is the first step in adding sane error handling support to LLVMSystem. The system API's will be shifted over to returning an error_code, and returning other return values as out parameters to the function. Code that needs to check error conditions will use the errc enum values which are the same as the posix_errno defines (EBADF, E2BIG, etc...), and are compatable with the error codes in WinError.h due to some magic in system_error. An example would be: if (error_code ec = KillEvil("Java")) { // error_code can be converted to bool. handle_error(ec); } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119360 91177308-0d34-0410-b5e6-96231b3b80d8 Michael J. Spencer 9 years ago
9 changed file(s) with 1183 addition(s) and 1192 deletion(s). Raw diff Collapse all Expand all
0 //===---------------------------- system_error ----------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This was lifted from libc++ and modified for C++03. This is called
10 // system_error even though it does not define that class because that's what
11 // it's called in C++0x. We don't define system_error because it is only used
12 // for exception handling, which we don't use in LLVM.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_SYSTEM_SYSTEM_ERROR_H
17 #define LLVM_SYSTEM_SYSTEM_ERROR_H
18
19 /*
20 system_error synopsis
21
22 namespace std
23 {
24
25 class error_category
26 {
27 public:
28 virtual ~error_category();
29
30 error_category(const error_category&) = delete;
31 error_category& operator=(const error_category&) = delete;
32
33 virtual const char* name() const = 0;
34 virtual error_condition default_error_condition(int ev) const;
35 virtual bool equivalent(int code, const error_condition& condition) const;
36 virtual bool equivalent(const error_code& code, int condition) const;
37 virtual std::string message(int ev) const = 0;
38
39 bool operator==(const error_category& rhs) const;
40 bool operator!=(const error_category& rhs) const;
41 bool operator<(const error_category& rhs) const;
42 };
43
44 const error_category& generic_category();
45 const error_category& system_category();
46
47 template struct is_error_code_enum
48 : public false_type {};
49
50 template struct is_error_condition_enum
51 : public false_type {};
52
53 class error_code
54 {
55 public:
56 // constructors:
57 error_code();
58 error_code(int val, const error_category& cat);
59 template
60 error_code(ErrorCodeEnum e);
61
62 // modifiers:
63 void assign(int val, const error_category& cat);
64 template
65 error_code& operator=(ErrorCodeEnum e);
66 void clear();
67
68 // observers:
69 int value() const;
70 const error_category& category() const;
71 error_condition default_error_condition() const;
72 std::string message() const;
73 explicit operator bool() const;
74 };
75
76 // non-member functions:
77 bool operator<(const error_code& lhs, const error_code& rhs);
78 template
79 basic_ostream&
80 operator<<(basic_ostream& os, const error_code& ec);
81
82 class error_condition
83 {
84 public:
85 // constructors:
86 error_condition();
87 error_condition(int val, const error_category& cat);
88 template
89 error_condition(ErrorConditionEnum e);
90
91 // modifiers:
92 void assign(int val, const error_category& cat);
93 template
94 error_condition& operator=(ErrorConditionEnum e);
95 void clear();
96
97 // observers:
98 int value() const;
99 const error_category& category() const;
100 std::string message() const;
101 explicit operator bool() const;
102 };
103
104 bool operator<(const error_condition& lhs, const error_condition& rhs);
105
106 class system_error
107 : public runtime_error
108 {
109 public:
110 system_error(error_code ec, const std::string& what_arg);
111 system_error(error_code ec, const char* what_arg);
112 system_error(error_code ec);
113 system_error(int ev, const error_category& ecat, const std::string& what_arg);
114 system_error(int ev, const error_category& ecat, const char* what_arg);
115 system_error(int ev, const error_category& ecat);
116
117 const error_code& code() const throw();
118 const char* what() const throw();
119 };
120
121 enum class errc
122 {
123 address_family_not_supported, // EAFNOSUPPORT
124 address_in_use, // EADDRINUSE
125 address_not_available, // EADDRNOTAVAIL
126 already_connected, // EISCONN
127 argument_list_too_long, // E2BIG
128 argument_out_of_domain, // EDOM
129 bad_address, // EFAULT
130 bad_file_descriptor, // EBADF
131 bad_message, // EBADMSG
132 broken_pipe, // EPIPE
133 connection_aborted, // ECONNABORTED
134 connection_already_in_progress, // EALREADY
135 connection_refused, // ECONNREFUSED
136 connection_reset, // ECONNRESET
137 cross_device_link, // EXDEV
138 destination_address_required, // EDESTADDRREQ
139 device_or_resource_busy, // EBUSY
140 directory_not_empty, // ENOTEMPTY
141 executable_format_error, // ENOEXEC
142 file_exists, // EEXIST
143 file_too_large, // EFBIG
144 filename_too_long, // ENAMETOOLONG
145 function_not_supported, // ENOSYS
146 host_unreachable, // EHOSTUNREACH
147 identifier_removed, // EIDRM
148 illegal_byte_sequence, // EILSEQ
149 inappropriate_io_control_operation, // ENOTTY
150 interrupted, // EINTR
151 invalid_argument, // EINVAL
152 invalid_seek, // ESPIPE
153 io_error, // EIO
154 is_a_directory, // EISDIR
155 message_size, // EMSGSIZE
156 network_down, // ENETDOWN
157 network_reset, // ENETRESET
158 network_unreachable, // ENETUNREACH
159 no_buffer_space, // ENOBUFS
160 no_child_process, // ECHILD
161 no_link, // ENOLINK
162 no_lock_available, // ENOLCK
163 no_message_available, // ENODATA
164 no_message, // ENOMSG
165 no_protocol_option, // ENOPROTOOPT
166 no_space_on_device, // ENOSPC
167 no_stream_resources, // ENOSR
168 no_such_device_or_address, // ENXIO
169 no_such_device, // ENODEV
170 no_such_file_or_directory, // ENOENT
171 no_such_process, // ESRCH
172 not_a_directory, // ENOTDIR
173 not_a_socket, // ENOTSOCK
174 not_a_stream, // ENOSTR
175 not_connected, // ENOTCONN
176 not_enough_memory, // ENOMEM
177 not_supported, // ENOTSUP
178 operation_canceled, // ECANCELED
179 operation_in_progress, // EINPROGRESS
180 operation_not_permitted, // EPERM
181 operation_not_supported, // EOPNOTSUPP
182 operation_would_block, // EWOULDBLOCK
183 owner_dead, // EOWNERDEAD
184 permission_denied, // EACCES
185 protocol_error, // EPROTO
186 protocol_not_supported, // EPROTONOSUPPORT
187 read_only_file_system, // EROFS
188 resource_deadlock_would_occur, // EDEADLK
189 resource_unavailable_try_again, // EAGAIN
190 result_out_of_range, // ERANGE
191 state_not_recoverable, // ENOTRECOVERABLE
192 stream_timeout, // ETIME
193 text_file_busy, // ETXTBSY
194 timed_out, // ETIMEDOUT
195 too_many_files_open_in_system, // ENFILE
196 too_many_files_open, // EMFILE
197 too_many_links, // EMLINK
198 too_many_symbolic_link_levels, // ELOOP
199 value_too_large, // EOVERFLOW
200 wrong_protocol_type // EPROTOTYPE
201 };
202
203 template <> struct is_error_condition_enum : true_type { }
204
205 error_code make_error_code(errc e);
206 error_condition make_error_condition(errc e);
207
208 // Comparison operators:
209 bool operator==(const error_code& lhs, const error_code& rhs);
210 bool operator==(const error_code& lhs, const error_condition& rhs);
211 bool operator==(const error_condition& lhs, const error_code& rhs);
212 bool operator==(const error_condition& lhs, const error_condition& rhs);
213 bool operator!=(const error_code& lhs, const error_code& rhs);
214 bool operator!=(const error_code& lhs, const error_condition& rhs);
215 bool operator!=(const error_condition& lhs, const error_code& rhs);
216 bool operator!=(const error_condition& lhs, const error_condition& rhs);
217
218 template <> struct hash;
219
220 } // std
221
222 */
223
224 #include "llvm/Config/config.h"
225 #include "llvm/Support/type_traits.h"
226 #include
227 #include
228
229 // This must be here instead of a .inc file because it is used in the definition
230 // of the enum values below.
231 #ifdef LLVM_ON_WIN32
232 // VS 2008 needs this for some of the defines below.
233 # include
234
235 // The following numbers were taken from VS2010.
236 # ifndef EAFNOSUPPORT
237 # define EAFNOSUPPORT WSAEAFNOSUPPORT
238 # endif
239 # ifndef EADDRINUSE
240 # define EADDRINUSE WSAEADDRINUSE
241 # endif
242 # ifndef EADDRNOTAVAIL
243 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
244 # endif
245 # ifndef EISCONN
246 # define EISCONN WSAEISCONN
247 # endif
248 # ifndef E2BIG
249 # define E2BIG WSAE2BIG
250 # endif
251 # ifndef EDOM
252 # define EDOM WSAEDOM
253 # endif
254 # ifndef EFAULT
255 # define EFAULT WSAEFAULT
256 # endif
257 # ifndef EBADF
258 # define EBADF WSAEBADF
259 # endif
260 # ifndef EBADMSG
261 # define EBADMSG 104
262 # endif
263 # ifndef EPIPE
264 # define EPIPE WSAEPIPE
265 # endif
266 # ifndef ECONNABORTED
267 # define ECONNABORTED WSAECONNABORTED
268 # endif
269 # ifndef EALREADY
270 # define EALREADY WSAEALREADY
271 # endif
272 # ifndef ECONNREFUSED
273 # define ECONNREFUSED WSAECONNREFUSED
274 # endif
275 # ifndef ECONNRESET
276 # define ECONNRESET WSAECONNRESET
277 # endif
278 # ifndef EXDEV
279 # define EXDEV WSAEXDEV
280 # endif
281 # ifndef EDESTADDRREQ
282 # define EDESTADDRREQ WSAEDESTADDRREQ
283 # endif
284 # ifndef EBUSY
285 # define EBUSY WSAEBUSY
286 # endif
287 # ifndef ENOTEMPTY
288 # define ENOTEMPTY WSAENOTEMPTY
289 # endif
290 # ifndef ENOEXEC
291 # define ENOEXEC WSAENOEXEC
292 # endif
293 # ifndef EEXIST
294 # define EEXIST WSAEEXIST
295 # endif
296 # ifndef EFBIG
297 # define EFBIG WSAEFBIG
298 # endif
299 # ifndef ENAMETOOLONG
300 # define ENAMETOOLONG WSAENAMETOOLONG
301 # endif
302 # ifndef ENOSYS
303 # define ENOSYS WSAENOSYS
304 # endif
305 # ifndef EHOSTUNREACH
306 # define EHOSTUNREACH WSAEHOSTUNREACH
307 # endif
308 # ifndef EIDRM
309 # define EIDRM 111
310 # endif
311 # ifndef EILSEQ
312 # define EILSEQ WSAEILSEQ
313 # endif
314 # ifndef ENOTTY
315 # define ENOTTY WSAENOTTY
316 # endif
317 # ifndef EINTR
318 # define EINTR WSAEINTR
319 # endif
320 # ifndef EINVAL
321 # define EINVAL WSAEINVAL
322 # endif
323 # ifndef ESPIPE
324 # define ESPIPE WSAESPIPE
325 # endif
326 # ifndef EIO
327 # define EIO WSAEIO
328 # endif
329 # ifndef EISDIR
330 # define EISDIR WSAEISDIR
331 # endif
332 # ifndef EMSGSIZE
333 # define EMSGSIZE WSAEMSGSIZE
334 # endif
335 # ifndef ENETDOWN
336 # define ENETDOWN WSAENETDOWN
337 # endif
338 # ifndef ENETRESET
339 # define ENETRESET WSAENETRESET
340 # endif
341 # ifndef ENETUNREACH
342 # define ENETUNREACH WSAENETUNREACH
343 # endif
344 # ifndef ENOBUFS
345 # define ENOBUFS WSAENOBUFS
346 # endif
347 # ifndef ECHILD
348 # define ECHILD WSAECHILD
349 # endif
350 # ifndef ENOLINK
351 # define ENOLINK 121
352 # endif
353 # ifndef ENOLCK
354 # define ENOLCK WSAENOLCK
355 # endif
356 # ifndef ENODATA
357 # define ENODATA 120
358 # endif
359 # ifndef ENOMSG
360 # define ENOMSG 122
361 # endif
362 # ifndef ENOPROTOOPT
363 # define ENOPROTOOPT WSAENOPROTOOPT
364 # endif
365 # ifndef ENOSPC
366 # define ENOSPC WSAENOSPC
367 # endif
368 # ifndef ENOSR
369 # define ENOSR 124
370 # endif
371 # ifndef ENXIO
372 # define ENXIO WSAENXIO
373 # endif
374 # ifndef ENODEV
375 # define ENODEV WSAENODEV
376 # endif
377 # ifndef ENOENT
378 # define ENOENT WSAENOENT
379 # endif
380 # ifndef ESRCH
381 # define ESRCH WSAESRCH
382 # endif
383 # ifndef ENOTDIR
384 # define ENOTDIR WSAENOTDIR
385 # endif
386 # ifndef ENOTSOCK
387 # define ENOTSOCK WSAENOTSOCK
388 # endif
389 # ifndef ENOSTR
390 # define ENOSTR 125
391 # endif
392 # ifndef ENOTCONN
393 # define ENOTCONN WSAENOTCONN
394 # endif
395 # ifndef ENOMEM
396 # define ENOMEM WSAENOMEM
397 # endif
398 # ifndef ENOTSUP
399 # define ENOTSUP 129
400 # endif
401 # ifndef ECANCELED
402 # define ECANCELED 105
403 # endif
404 # ifndef EINPROGRESS
405 # define EINPROGRESS WSAEINPROGRESS
406 # endif
407 # ifndef EPERM
408 # define EPERM WSAEPERM
409 # endif
410 # ifndef EOPNOTSUPP
411 # define EOPNOTSUPP WSAEOPNOTSUPP
412 # endif
413 # ifndef EWOULDBLOCK
414 # define EWOULDBLOCK WSAEWOULDBLOCK
415 # endif
416 # ifndef EOWNERDEAD
417 # define EOWNERDEAD 133
418 # endif
419 # ifndef EACCES
420 # define EACCES WSAEACCES
421 # endif
422 # ifndef EPROTO
423 # define EPROTO 134
424 # endif
425 # ifndef EPROTONOSUPPORT
426 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
427 # endif
428 # ifndef EROFS
429 # define EROFS WSAEROFS
430 # endif
431 # ifndef EDEADLK
432 # define EDEADLK WSAEDEADLK
433 # endif
434 # ifndef EAGAIN
435 # define EAGAIN WSAEAGAIN
436 # endif
437 # ifndef ERANGE
438 # define ERANGE WSAERANGE
439 # endif
440 # ifndef ENOTRECOVERABLE
441 # define ENOTRECOVERABLE 127
442 # endif
443 # ifndef ETIME
444 # define ETIME 137
445 # endif
446 # ifndef ETXTBSY
447 # define ETXTBSY 139
448 # endif
449 # ifndef ETIMEDOUT
450 # define ETIMEDOUT WSAETIMEDOUT
451 # endif
452 # ifndef ENFILE
453 # define ENFILE WSAENFILE
454 # endif
455 # ifndef EMFILE
456 # define EMFILE WSAEMFILE
457 # endif
458 # ifndef EMLINK
459 # define EMLINK WSAEMLINK
460 # endif
461 # ifndef ELOOP
462 # define ELOOP WSAELOOP
463 # endif
464 # ifndef EOVERFLOW
465 # define EOVERFLOW 132
466 # endif
467 # ifndef EPROTOTYPE
468 # define EPROTOTYPE WSAEPROTOTYPE
469 # endif
470 #endif
471
472 namespace llvm {
473
474 template
475 struct integral_constant {
476 typedef T value_type;
477 static const value_type value = v;
478 typedef integral_constant type;
479 operator value_type() { return value; }
480 };
481
482 typedef integral_constant true_type;
483 typedef integral_constant false_type;
484
485 // is_error_code_enum
486
487 template struct is_error_code_enum : public false_type {};
488
489 // is_error_condition_enum
490
491 template struct is_error_condition_enum : public false_type {};
492
493 // Some error codes are not present on all platforms, so we provide equivalents
494 // for them:
495
496 //enum class errc
497 struct errc {
498 enum _ {
499 success = 0,
500 address_family_not_supported = EAFNOSUPPORT,
501 address_in_use = EADDRINUSE,
502 address_not_available = EADDRNOTAVAIL,
503 already_connected = EISCONN,
504 argument_list_too_long = E2BIG,
505 argument_out_of_domain = EDOM,
506 bad_address = EFAULT,
507 bad_file_descriptor = EBADF,
508 bad_message = EBADMSG,
509 broken_pipe = EPIPE,
510 connection_aborted = ECONNABORTED,
511 connection_already_in_progress = EALREADY,
512 connection_refused = ECONNREFUSED,
513 connection_reset = ECONNRESET,
514 cross_device_link = EXDEV,
515 destination_address_required = EDESTADDRREQ,
516 device_or_resource_busy = EBUSY,
517 directory_not_empty = ENOTEMPTY,
518 executable_format_error = ENOEXEC,
519 file_exists = EEXIST,
520 file_too_large = EFBIG,
521 filename_too_long = ENAMETOOLONG,
522 function_not_supported = ENOSYS,
523 host_unreachable = EHOSTUNREACH,
524 identifier_removed = EIDRM,
525 illegal_byte_sequence = EILSEQ,
526 inappropriate_io_control_operation = ENOTTY,
527 interrupted = EINTR,
528 invalid_argument = EINVAL,
529 invalid_seek = ESPIPE,
530 io_error = EIO,
531 is_a_directory = EISDIR,
532 message_size = EMSGSIZE,
533 network_down = ENETDOWN,
534 network_reset = ENETRESET,
535 network_unreachable = ENETUNREACH,
536 no_buffer_space = ENOBUFS,
537 no_child_process = ECHILD,
538 no_link = ENOLINK,
539 no_lock_available = ENOLCK,
540 #ifdef ENODATA
541 no_message_available = ENODATA,
542 #else
543 no_message_available = ENOMSG,
544 #endif
545 no_message = ENOMSG,
546 no_protocol_option = ENOPROTOOPT,
547 no_space_on_device = ENOSPC,
548 #ifdef ENOSR
549 no_stream_resources = ENOSR,
550 #else
551 no_stream_resources = ENOMEM,
552 #endif
553 no_such_device_or_address = ENXIO,
554 no_such_device = ENODEV,
555 no_such_file_or_directory = ENOENT,
556 no_such_process = ESRCH,
557 not_a_directory = ENOTDIR,
558 not_a_socket = ENOTSOCK,
559 #ifdef ENOSTR
560 not_a_stream = ENOSTR,
561 #else
562 not_a_stream = EINVAL,
563 #endif
564 not_connected = ENOTCONN,
565 not_enough_memory = ENOMEM,
566 not_supported = ENOTSUP,
567 operation_canceled = ECANCELED,
568 operation_in_progress = EINPROGRESS,
569 operation_not_permitted = EPERM,
570 operation_not_supported = EOPNOTSUPP,
571 operation_would_block = EWOULDBLOCK,
572 owner_dead = EOWNERDEAD,
573 permission_denied = EACCES,
574 protocol_error = EPROTO,
575 protocol_not_supported = EPROTONOSUPPORT,
576 read_only_file_system = EROFS,
577 resource_deadlock_would_occur = EDEADLK,
578 resource_unavailable_try_again = EAGAIN,
579 result_out_of_range = ERANGE,
580 state_not_recoverable = ENOTRECOVERABLE,
581 #ifdef ETIME
582 stream_timeout = ETIME,
583 #else
584 stream_timeout = ETIMEDOUT,
585 #endif
586 text_file_busy = ETXTBSY,
587 timed_out = ETIMEDOUT,
588 too_many_files_open_in_system = ENFILE,
589 too_many_files_open = EMFILE,
590 too_many_links = EMLINK,
591 too_many_symbolic_link_levels = ELOOP,
592 value_too_large = EOVERFLOW,
593 wrong_protocol_type = EPROTOTYPE
594 };
595
596 _ v_;
597
598 errc(_ v) : v_(v) {}
599 operator int() const {return v_;}
600 };
601
602 template <> struct is_error_condition_enum : true_type { };
603
604 template <> struct is_error_condition_enum : true_type { };
605
606 class error_condition;
607 class error_code;
608
609 // class error_category
610
611 class _do_message;
612
613 class error_category
614 {
615 public:
616 virtual ~error_category();
617
618 private:
619 error_category();
620 error_category(const error_category&);// = delete;
621 error_category& operator=(const error_category&);// = delete;
622
623 public:
624 virtual const char* name() const = 0;
625 virtual error_condition default_error_condition(int _ev) const;
626 virtual bool equivalent(int _code, const error_condition& _condition) const;
627 virtual bool equivalent(const error_code& _code, int _condition) const;
628 virtual std::string message(int _ev) const = 0;
629
630 bool operator==(const error_category& _rhs) const {return this == &_rhs;}
631
632 bool operator!=(const error_category& _rhs) const {return !(*this == _rhs);}
633
634 bool operator< (const error_category& _rhs) const {return this < &_rhs;}
635
636 friend class _do_message;
637 };
638
639 class _do_message : public error_category
640 {
641 public:
642 virtual std::string message(int ev) const;
643 };
644
645 const error_category& generic_category();
646 const error_category& system_category();
647
648 class error_condition
649 {
650 int _val_;
651 const error_category* _cat_;
652 public:
653 error_condition() : _val_(0), _cat_(&generic_category()) {}
654
655 error_condition(int _val, const error_category& _cat)
656 : _val_(_val), _cat_(&_cat) {}
657
658 template
659 error_condition(E _e, typename enable_if_c<
660 is_error_condition_enum::value
661 >::type* = 0)
662 {*this = make_error_condition(_e);}
663
664 void assign(int _val, const error_category& _cat) {
665 _val_ = _val;
666 _cat_ = &_cat;
667 }
668
669 template
670 typename enable_if_c
671 <
672 is_error_condition_enum::value,
673 error_condition&
674 >::type
675 operator=(E _e)
676 {*this = make_error_condition(_e); return *this;}
677
678 void clear() {
679 _val_ = 0;
680 _cat_ = &generic_category();
681 }
682
683 int value() const {return _val_;}
684
685 const error_category& category() const {return *_cat_;}
686 std::string message() const;
687
688 // explicit
689 operator bool() const {return _val_ != 0;}
690 };
691
692 inline error_condition make_error_condition(errc _e) {
693 return error_condition(static_cast(_e), generic_category());
694 }
695
696 inline bool operator<(const error_condition& _x, const error_condition& _y) {
697 return _x.category() < _y.category()
698 || (_x.category() == _y.category() && _x.value() < _y.value());
699 }
700
701 // error_code
702
703 class error_code {
704 int _val_;
705 const error_category* _cat_;
706 public:
707 error_code() : _val_(0), _cat_(&system_category()) {}
708
709 error_code(int _val, const error_category& _cat)
710 : _val_(_val), _cat_(&_cat) {}
711
712 template
713 error_code(E _e, typename enable_if_c<
714 is_error_code_enum::value
715 >::type* = 0) {
716 *this = make_error_code(_e);
717 }
718
719 void assign(int _val, const error_category& _cat) {
720 _val_ = _val;
721 _cat_ = &_cat;
722 }
723
724 template
725 typename enable_if_c
726 <
727 is_error_code_enum::value,
728 error_code&
729 >::type
730 operator=(E _e)
731 {*this = make_error_code(_e); return *this;}
732
733 void clear() {
734 _val_ = 0;
735 _cat_ = &system_category();
736 }
737
738 int value() const {return _val_;}
739
740 const error_category& category() const {return *_cat_;}
741
742 error_condition default_error_condition() const
743 {return _cat_->default_error_condition(_val_);}
744
745 std::string message() const;
746
747 // explicit
748 operator bool() const {return _val_ != 0;}
749 };
750
751 inline error_code make_error_code(errc _e) {
752 return error_code(static_cast(_e), generic_category());
753 }
754
755 inline bool operator<(const error_code& _x, const error_code& _y) {
756 return _x.category() < _y.category()
757 || (_x.category() == _y.category() && _x.value() < _y.value());
758 }
759
760 inline bool operator==(const error_code& _x, const error_code& _y) {
761 return _x.category() == _y.category() && _x.value() == _y.value();
762 }
763
764 inline bool operator==(const error_code& _x, const error_condition& _y) {
765 return _x.category().equivalent(_x.value(), _y)
766 || _y.category().equivalent(_x, _y.value());
767 }
768
769 inline bool operator==(const error_condition& _x, const error_code& _y) {
770 return _y == _x;
771 }
772
773 inline bool operator==(const error_condition& _x, const error_condition& _y) {
774 return _x.category() == _y.category() && _x.value() == _y.value();
775 }
776
777 inline bool operator!=(const error_code& _x, const error_code& _y) {
778 return !(_x == _y);
779 }
780
781 inline bool operator!=(const error_code& _x, const error_condition& _y) {
782 return !(_x == _y);
783 }
784
785 inline bool operator!=(const error_condition& _x, const error_code& _y) {
786 return !(_x == _y);
787 }
788
789 inline bool operator!=(const error_condition& _x, const error_condition& _y) {
790 return !(_x == _y);
791 }
792
793 // system_error
794
795 } // end namespace llvm
796
797 // This needs to stay here for KillTheDoctor.
798 #ifdef LLVM_ON_WIN32
799 #include
800 #include
801
802 namespace llvm {
803
804 // To construct an error_code after an API error:
805 //
806 // error_code( ::GetLastError(), system_category() )
807 struct windows_error {
808 enum _ {
809 success = 0,
810 // These names and values are based on Windows winerror.h
811 // This is not a complete list.
812 invalid_function = ERROR_INVALID_FUNCTION,
813 file_not_found = ERROR_FILE_NOT_FOUND,
814 path_not_found = ERROR_PATH_NOT_FOUND,
815 too_many_open_files = ERROR_TOO_MANY_OPEN_FILES,
816 access_denied = ERROR_ACCESS_DENIED,
817 invalid_handle = ERROR_INVALID_HANDLE,
818 arena_trashed = ERROR_ARENA_TRASHED,
819 not_enough_memory = ERROR_NOT_ENOUGH_MEMORY,
820 invalid_block = ERROR_INVALID_BLOCK,
821 bad_environment = ERROR_BAD_ENVIRONMENT,
822 bad_format = ERROR_BAD_FORMAT,
823 invalid_access = ERROR_INVALID_ACCESS,
824 outofmemory = ERROR_OUTOFMEMORY,
825 invalid_drive = ERROR_INVALID_DRIVE,
826 current_directory = ERROR_CURRENT_DIRECTORY,
827 not_same_device = ERROR_NOT_SAME_DEVICE,
828 no_more_files = ERROR_NO_MORE_FILES,
829 write_protect = ERROR_WRITE_PROTECT,
830 bad_unit = ERROR_BAD_UNIT,
831 not_ready = ERROR_NOT_READY,
832 bad_command = ERROR_BAD_COMMAND,
833 crc = ERROR_CRC,
834 bad_length = ERROR_BAD_LENGTH,
835 seek = ERROR_SEEK,
836 not_dos_disk = ERROR_NOT_DOS_DISK,
837 sector_not_found = ERROR_SECTOR_NOT_FOUND,
838 out_of_paper = ERROR_OUT_OF_PAPER,
839 write_fault = ERROR_WRITE_FAULT,
840 read_fault = ERROR_READ_FAULT,
841 gen_failure = ERROR_GEN_FAILURE,
842 sharing_violation = ERROR_SHARING_VIOLATION,
843 lock_violation = ERROR_LOCK_VIOLATION,
844 wrong_disk = ERROR_WRONG_DISK,
845 sharing_buffer_exceeded = ERROR_SHARING_BUFFER_EXCEEDED,
846 handle_eof = ERROR_HANDLE_EOF,
847 handle_disk_full = ERROR_HANDLE_DISK_FULL,
848 rem_not_list = ERROR_REM_NOT_LIST,
849 dup_name = ERROR_DUP_NAME,
850 bad_net_path = ERROR_BAD_NETPATH,
851 network_busy = ERROR_NETWORK_BUSY,
852 file_exists = ERROR_FILE_EXISTS,
853 cannot_make = ERROR_CANNOT_MAKE,
854 broken_pipe = ERROR_BROKEN_PIPE,
855 open_failed = ERROR_OPEN_FAILED,
856 buffer_overflow = ERROR_BUFFER_OVERFLOW,
857 disk_full = ERROR_DISK_FULL,
858 lock_failed = ERROR_LOCK_FAILED,
859 busy = ERROR_BUSY,
860 cancel_violation = ERROR_CANCEL_VIOLATION,
861 already_exists = ERROR_ALREADY_EXISTS
862 };
863 _ v_;
864
865 windows_error(_ v) : v_(v) {}
866 explicit windows_error(DWORD v) : v_(_(v)) {}
867 operator int() const {return v_;}
868 };
869
870
871 template <> struct is_error_code_enum : true_type { };
872
873 template <> struct is_error_code_enum : true_type { };
874
875 inline error_code make_error_code(windows_error e) {
876 return error_code(static_cast(e), system_category());
877 }
878
879 } // end namespace llvm
880
881 #endif // LLVM_ON_WINDOWS
882
883 #endif
1818 RWMutex.cpp
1919 SearchForAddressOfSpecialSymbol.cpp
2020 Signals.cpp
21 system_error.cpp
2122 ThreadLocal.cpp
2223 Threading.cpp
2324 TimeValue.cpp
3132 Unix/Program.inc
3233 Unix/RWMutex.inc
3334 Unix/Signals.inc
35 Unix/system_error.inc
3436 Unix/ThreadLocal.inc
3537 Unix/TimeValue.inc
3638 Win32/Alarm.inc
4345 Win32/Program.inc
4446 Win32/RWMutex.inc
4547 Win32/Signals.inc
48 Win32/system_error.inc
4649 Win32/ThreadLocal.inc
4750 Win32/TimeValue.inc
4851 )
0 //===- llvm/System/Unix/system_error.inc - Unix error_code ------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the Unix specific implementation of the error_code
10 // and error_condition classes.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic UNIX code that
16 //=== is guaranteed to work on *all* UNIX variants.
17 //===----------------------------------------------------------------------===//
18
19 using namespace llvm;
20
21 std::string
22 _system_error_category::message(int ev) const {
23 return _do_message::message(ev);
24 }
25
26 error_condition
27 _system_error_category::default_error_condition(int ev) const {
28 #ifdef ELAST
29 if (ev > ELAST)
30 return error_condition(ev, system_category());
31 #endif // ELAST
32 return error_condition(ev, generic_category());
33 }
0 //===- llvm/System/Win32/system_error.inc - Windows error_code --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the Windows specific implementation of the error_code
10 // and error_condition classes.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic Windows code that
16 //=== is guaranteed to work on *all* Windows variants.
17 //===----------------------------------------------------------------------===//
18
19 #include
20 #include
21
22 using namespace llvm;
23
24 std::string
25 _system_error_category::message(int ev) const {
26 LPVOID lpMsgBuf = 0;
27 DWORD retval = ::FormatMessageA(
28 FORMAT_MESSAGE_ALLOCATE_BUFFER |
29 FORMAT_MESSAGE_FROM_SYSTEM |
30 FORMAT_MESSAGE_IGNORE_INSERTS,
31 NULL,
32 ev,
33 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
34 (LPSTR) &lpMsgBuf,
35 0,
36 NULL);
37 if (retval == 0) {
38 ::LocalFree(lpMsgBuf);
39 return std::string("Unknown error");
40 }
41
42 std::string str( static_cast(lpMsgBuf) );
43 ::LocalFree(lpMsgBuf);
44
45 while (str.size()
46 && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r'))
47 str.erase( str.size()-1 );
48 if (str.size() && str[str.size()-1] == '.')
49 str.erase( str.size()-1 );
50 return str;
51 }
52
53 // I'd rather not double the line count of the following.
54 #define MAP_ERR_TO_COND(x, y) case x: return make_error_condition(errc::y)
55
56 error_condition
57 _system_error_category::default_error_condition(int ev) const {
58 switch (ev) {
59 MAP_ERR_TO_COND(0, success);
60 // Windows system -> posix_errno decode table ---------------------------//
61 // see WinError.h comments for descriptions of errors
62 MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied);
63 MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists);
64 MAP_ERR_TO_COND(ERROR_BAD_UNIT, no_such_device);
65 MAP_ERR_TO_COND(ERROR_BUFFER_OVERFLOW, filename_too_long);
66 MAP_ERR_TO_COND(ERROR_BUSY, device_or_resource_busy);
67 MAP_ERR_TO_COND(ERROR_BUSY_DRIVE, device_or_resource_busy);
68 MAP_ERR_TO_COND(ERROR_CANNOT_MAKE, permission_denied);
69 MAP_ERR_TO_COND(ERROR_CANTOPEN, io_error);
70 MAP_ERR_TO_COND(ERROR_CANTREAD, io_error);
71 MAP_ERR_TO_COND(ERROR_CANTWRITE, io_error);
72 MAP_ERR_TO_COND(ERROR_CURRENT_DIRECTORY, permission_denied);
73 MAP_ERR_TO_COND(ERROR_DEV_NOT_EXIST, no_such_device);
74 MAP_ERR_TO_COND(ERROR_DEVICE_IN_USE, device_or_resource_busy);
75 MAP_ERR_TO_COND(ERROR_DIR_NOT_EMPTY, directory_not_empty);
76 MAP_ERR_TO_COND(ERROR_DIRECTORY, invalid_argument);
77 MAP_ERR_TO_COND(ERROR_DISK_FULL, no_space_on_device);
78 MAP_ERR_TO_COND(ERROR_FILE_EXISTS, file_exists);
79 MAP_ERR_TO_COND(ERROR_FILE_NOT_FOUND, no_such_file_or_directory);
80 MAP_ERR_TO_COND(ERROR_HANDLE_DISK_FULL, no_space_on_device);
81 MAP_ERR_TO_COND(ERROR_INVALID_ACCESS, permission_denied);
82 MAP_ERR_TO_COND(ERROR_INVALID_DRIVE, no_such_device);
83 MAP_ERR_TO_COND(ERROR_INVALID_FUNCTION, function_not_supported);
84 MAP_ERR_TO_COND(ERROR_INVALID_HANDLE, invalid_argument);
85 MAP_ERR_TO_COND(ERROR_INVALID_NAME, invalid_argument);
86 MAP_ERR_TO_COND(ERROR_LOCK_VIOLATION, no_lock_available);
87 MAP_ERR_TO_COND(ERROR_LOCKED, no_lock_available);
88 MAP_ERR_TO_COND(ERROR_NEGATIVE_SEEK, invalid_argument);
89 MAP_ERR_TO_COND(ERROR_NOACCESS, permission_denied);
90 MAP_ERR_TO_COND(ERROR_NOT_ENOUGH_MEMORY, not_enough_memory);
91 MAP_ERR_TO_COND(ERROR_NOT_READY, resource_unavailable_try_again);
92 MAP_ERR_TO_COND(ERROR_NOT_SAME_DEVICE, cross_device_link);
93 MAP_ERR_TO_COND(ERROR_OPEN_FAILED, io_error);
94 MAP_ERR_TO_COND(ERROR_OPEN_FILES, device_or_resource_busy);
95 MAP_ERR_TO_COND(ERROR_OPERATION_ABORTED, operation_canceled);
96 MAP_ERR_TO_COND(ERROR_OUTOFMEMORY, not_enough_memory);
97 MAP_ERR_TO_COND(ERROR_PATH_NOT_FOUND, no_such_file_or_directory);
98 MAP_ERR_TO_COND(ERROR_READ_FAULT, io_error);
99 MAP_ERR_TO_COND(ERROR_RETRY, resource_unavailable_try_again);
100 MAP_ERR_TO_COND(ERROR_SEEK, io_error);
101 MAP_ERR_TO_COND(ERROR_SHARING_VIOLATION, permission_denied);
102 MAP_ERR_TO_COND(ERROR_TOO_MANY_OPEN_FILES, too_many_files_open);
103 MAP_ERR_TO_COND(ERROR_WRITE_FAULT, io_error);
104 MAP_ERR_TO_COND(ERROR_WRITE_PROTECT, permission_denied);
105 MAP_ERR_TO_COND(ERROR_SEM_TIMEOUT, timed_out);
106 MAP_ERR_TO_COND(WSAEACCES, permission_denied);
107 MAP_ERR_TO_COND(WSAEADDRINUSE, address_in_use);
108 MAP_ERR_TO_COND(WSAEADDRNOTAVAIL, address_not_available);
109 MAP_ERR_TO_COND(WSAEAFNOSUPPORT, address_family_not_supported);
110 MAP_ERR_TO_COND(WSAEALREADY, connection_already_in_progress);
111 MAP_ERR_TO_COND(WSAEBADF, bad_file_descriptor);
112 MAP_ERR_TO_COND(WSAECONNABORTED, connection_aborted);
113 MAP_ERR_TO_COND(WSAECONNREFUSED, connection_refused);
114 MAP_ERR_TO_COND(WSAECONNRESET, connection_reset);
115 MAP_ERR_TO_COND(WSAEDESTADDRREQ, destination_address_required);
116 MAP_ERR_TO_COND(WSAEFAULT, bad_address);
117 MAP_ERR_TO_COND(WSAEHOSTUNREACH, host_unreachable);
118 MAP_ERR_TO_COND(WSAEINPROGRESS, operation_in_progress);
119 MAP_ERR_TO_COND(WSAEINTR, interrupted);
120 MAP_ERR_TO_COND(WSAEINVAL, invalid_argument);
121 MAP_ERR_TO_COND(WSAEISCONN, already_connected);
122 MAP_ERR_TO_COND(WSAEMFILE, too_many_files_open);
123 MAP_ERR_TO_COND(WSAEMSGSIZE, message_size);
124 MAP_ERR_TO_COND(WSAENAMETOOLONG, filename_too_long);
125 MAP_ERR_TO_COND(WSAENETDOWN, network_down);
126 MAP_ERR_TO_COND(WSAENETRESET, network_reset);
127 MAP_ERR_TO_COND(WSAENETUNREACH, network_unreachable);
128 MAP_ERR_TO_COND(WSAENOBUFS, no_buffer_space);
129 MAP_ERR_TO_COND(WSAENOPROTOOPT, no_protocol_option);
130 MAP_ERR_TO_COND(WSAENOTCONN, not_connected);
131 MAP_ERR_TO_COND(WSAENOTSOCK, not_a_socket);
132 MAP_ERR_TO_COND(WSAEOPNOTSUPP, operation_not_supported);
133 MAP_ERR_TO_COND(WSAEPROTONOSUPPORT, protocol_not_supported);
134 MAP_ERR_TO_COND(WSAEPROTOTYPE, wrong_protocol_type);
135 MAP_ERR_TO_COND(WSAETIMEDOUT, timed_out);
136 MAP_ERR_TO_COND(WSAEWOULDBLOCK, operation_would_block);
137 default: return error_condition(ev, system_category());
138 }
139 }
0 //===---------------------- system_error.cpp ------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This was lifted from libc++ and modified for C++03.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/System/system_error.h"
14 #include "llvm/System/Errno.h"
15 #include
16 #include
17
18 namespace llvm {
19
20 // class error_category
21
22 error_category::error_category() {
23 }
24
25 error_category::~error_category() {
26 }
27
28 error_condition
29 error_category::default_error_condition(int ev) const {
30 return error_condition(ev, *this);
31 }
32
33 bool
34 error_category::equivalent(int code, const error_condition& condition) const {
35 return default_error_condition(code) == condition;
36 }
37
38 bool
39 error_category::equivalent(const error_code& code, int condition) const {
40 return *this == code.category() && code.value() == condition;
41 }
42
43 std::string
44 _do_message::message(int ev) const {
45 return std::string(sys::StrError(ev));
46 }
47
48 class _generic_error_category : public _do_message {
49 public:
50 virtual const char* name() const;
51 virtual std::string message(int ev) const;
52 };
53
54 const char*
55 _generic_error_category::name() const {
56 return "generic";
57 }
58
59 std::string
60 _generic_error_category::message(int ev) const {
61 #ifdef ELAST
62 if (ev > ELAST)
63 return std::string("unspecified generic_category error");
64 #endif // ELAST
65 return _do_message::message(ev);
66 }
67
68 const error_category&
69 generic_category() {
70 static _generic_error_category s;
71 return s;
72 }
73
74 class _system_error_category : public _do_message {
75 public:
76 virtual const char* name() const;
77 virtual std::string message(int ev) const;
78 virtual error_condition default_error_condition(int ev) const;
79 };
80
81 const char*
82 _system_error_category::name() const {
83 return "system";
84 }
85
86 // std::string _system_error_category::message(int ev) const {
87 // Is in Platform/system_error.inc
88
89 // error_condition _system_error_category::default_error_condition(int ev) const
90 // Is in Platform/system_error.inc
91
92 const error_category&
93 system_category() {
94 static _system_error_category s;
95 return s;
96 }
97
98 // error_condition
99
100 std::string
101 error_condition::message() const {
102 return _cat_->message(_val_);
103 }
104
105 // error_code
106
107 std::string
108 error_code::message() const {
109 return _cat_->message(_val_);
110 }
111
112 } // end namespace llvm
113
114 // Include the truly platform-specific parts of this class.
115 #if defined(LLVM_ON_UNIX)
116 #include "Unix/system_error.inc"
117 #endif
118 #if defined(LLVM_ON_WIN32)
119 #include "Win32/system_error.inc"
120 #endif
0 add_executable(KillTheDoctor
11 KillTheDoctor.cpp
2 system_error.cpp
32 )
43
54 target_link_libraries(KillTheDoctor LLVMSupport LLVMSystem)
4141 #include "llvm/Support/raw_ostream.h"
4242 #include "llvm/Support/type_traits.h"
4343 #include "llvm/System/Signals.h"
44 #include "system_error.h"
44 #include "llvm/System/system_error.h"
4545 #include
4646 #include
4747 #include
+0
-287
utils/KillTheDoctor/system_error.cpp less more
None //===---------------------- system_error.cpp ------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This was lifted from libc++ and modified for C++03.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Config/config.h"
14 #include "system_error.h"
15 #include
16 #include
17
18 namespace llvm {
19
20 // class error_category
21
22 error_category::error_category() {
23 }
24
25 error_category::~error_category() {
26 }
27
28 error_condition
29 error_category::default_error_condition(int ev) const {
30 return error_condition(ev, *this);
31 }
32
33 bool
34 error_category::equivalent(int code, const error_condition& condition) const {
35 return default_error_condition(code) == condition;
36 }
37
38 bool
39 error_category::equivalent(const error_code& code, int condition) const {
40 return *this == code.category() && code.value() == condition;
41 }
42
43 std::string
44 _do_message::message(int ev) const {
45 return std::string(std::strerror(ev));
46 }
47
48 class _generic_error_category : public _do_message {
49 public:
50 virtual const char* name() const;
51 virtual std::string message(int ev) const;
52 };
53
54 const char*
55 _generic_error_category::name() const {
56 return "generic";
57 }
58
59 std::string
60 _generic_error_category::message(int ev) const {
61 #ifdef ELAST
62 if (ev > ELAST)
63 return std::string("unspecified generic_category error");
64 #endif // ELAST
65 return _do_message::message(ev);
66 }
67
68 const error_category&
69 generic_category() {
70 static _generic_error_category s;
71 return s;
72 }
73
74 class _system_error_category : public _do_message {
75 public:
76 virtual const char* name() const;
77 virtual std::string message(int ev) const;
78 virtual error_condition default_error_condition(int ev) const;
79 };
80
81 const char*
82 _system_error_category::name() const {
83 return "system";
84 }
85
86 // std::string _system_error_category::message(int ev) const {
87 // Is in Platform/system_error.inc
88
89 // error_condition _system_error_category::default_error_condition(int ev) const
90 // Is in Platform/system_error.inc
91
92 const error_category&
93 system_category() {
94 static _system_error_category s;
95 return s;
96 }
97
98 // error_condition
99
100 std::string
101 error_condition::message() const {
102 return _cat_->message(_val_);
103 }
104
105 // error_code
106
107 std::string
108 error_code::message() const {
109 return _cat_->message(_val_);
110 }
111
112 // system_error
113
114 std::string
115 system_error::_init(const error_code& ec, std::string what_arg) {
116 if (ec)
117 {
118 if (!what_arg.empty())
119 what_arg += ": ";
120 what_arg += ec.message();
121 }
122 return what_arg;
123 }
124
125 system_error::system_error(error_code ec, const std::string& what_arg)
126 : runtime_error(_init(ec, what_arg)), _ec_(ec) {
127 }
128
129 system_error::system_error(error_code ec, const char* what_arg)
130 : runtime_error(_init(ec, what_arg)), _ec_(ec) {
131 }
132
133 system_error::system_error(error_code ec)
134 : runtime_error(_init(ec, "")), _ec_(ec) {
135 }
136
137 system_error::system_error(int ev, const error_category& ecat,
138 const std::string& what_arg)
139 : runtime_error(_init(error_code(ev, ecat), what_arg))
140 , _ec_(error_code(ev, ecat)) {
141 }
142
143 system_error::system_error(int ev, const error_category& ecat,
144 const char* what_arg)
145 : runtime_error(_init(error_code(ev, ecat), what_arg))
146 , _ec_(error_code(ev, ecat)) {
147 }
148
149 system_error::system_error(int ev, const error_category& ecat)
150 : runtime_error(_init(error_code(ev, ecat), "")), _ec_(error_code(ev, ecat)) {
151 }
152
153 system_error::~system_error() throw() {
154 }
155
156 void
157 _throw_system_error(int ev, const char* what_arg) {
158 throw system_error(error_code(ev, system_category()), what_arg);
159 }
160
161 } // end namespace llvm
162
163 #ifdef LLVM_ON_WIN32
164 #include
165 #include
166
167 namespace llvm {
168
169 std::string
170 _system_error_category::message(int ev) const {
171 LPVOID lpMsgBuf = 0;
172 DWORD retval = ::FormatMessageA(
173 FORMAT_MESSAGE_ALLOCATE_BUFFER |
174 FORMAT_MESSAGE_FROM_SYSTEM |
175 FORMAT_MESSAGE_IGNORE_INSERTS,
176 NULL,
177 ev,
178 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
179 (LPSTR) &lpMsgBuf,
180 0,
181 NULL);
182 if (retval == 0) {
183 ::LocalFree(lpMsgBuf);
184 return std::string("Unknown error");
185 }
186
187 std::string str( static_cast(lpMsgBuf) );
188 ::LocalFree(lpMsgBuf);
189
190 while (str.size()
191 && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r'))
192 str.erase( str.size()-1 );
193 if (str.size() && str[str.size()-1] == '.')
194 str.erase( str.size()-1 );
195 return str;
196 }
197
198 error_condition
199 _system_error_category::default_error_condition(int ev) const {
200 switch (ev)
201 {
202 case 0: return make_error_condition(errc::success);
203 // Windows system -> posix_errno decode table ---------------------------//
204 // see WinError.h comments for descriptions of errors
205 case ERROR_ACCESS_DENIED: return make_error_condition(errc::permission_denied);
206 case ERROR_ALREADY_EXISTS: return make_error_condition(errc::file_exists);
207 case ERROR_BAD_UNIT: return make_error_condition(errc::no_such_device);
208 case ERROR_BUFFER_OVERFLOW: return make_error_condition(errc::filename_too_long);
209 case ERROR_BUSY: return make_error_condition(errc::device_or_resource_busy);
210 case ERROR_BUSY_DRIVE: return make_error_condition(errc::device_or_resource_busy);
211 case ERROR_CANNOT_MAKE: return make_error_condition(errc::permission_denied);
212 case ERROR_CANTOPEN: return make_error_condition(errc::io_error);
213 case ERROR_CANTREAD: return make_error_condition(errc::io_error);
214 case ERROR_CANTWRITE: return make_error_condition(errc::io_error);
215 case ERROR_CURRENT_DIRECTORY: return make_error_condition(errc::permission_denied);
216 case ERROR_DEV_NOT_EXIST: return make_error_condition(errc::no_such_device);
217 case ERROR_DEVICE_IN_USE: return make_error_condition(errc::device_or_resource_busy);
218 case ERROR_DIR_NOT_EMPTY: return make_error_condition(errc::directory_not_empty);
219 case ERROR_DIRECTORY: return make_error_condition(errc::invalid_argument);
220 case ERROR_DISK_FULL: return make_error_condition(errc::no_space_on_device);
221 case ERROR_FILE_EXISTS: return make_error_condition(errc::file_exists);
222 case ERROR_FILE_NOT_FOUND: return make_error_condition(errc::no_such_file_or_directory);
223 case ERROR_HANDLE_DISK_FULL: return make_error_condition(errc::no_space_on_device);
224 case ERROR_INVALID_ACCESS: return make_error_condition(errc::permission_denied);
225 case ERROR_INVALID_DRIVE: return make_error_condition(errc::no_such_device);
226 case ERROR_INVALID_FUNCTION: return make_error_condition(errc::function_not_supported);
227 case ERROR_INVALID_HANDLE: return make_error_condition(errc::invalid_argument);
228 case ERROR_INVALID_NAME: return make_error_condition(errc::invalid_argument);
229 case ERROR_LOCK_VIOLATION: return make_error_condition(errc::no_lock_available);
230 case ERROR_LOCKED: return make_error_condition(errc::no_lock_available);
231 case ERROR_NEGATIVE_SEEK: return make_error_condition(errc::invalid_argument);
232 case ERROR_NOACCESS: return make_error_condition(errc::permission_denied);
233 case ERROR_NOT_ENOUGH_MEMORY: return make_error_condition(errc::not_enough_memory);
234 case ERROR_NOT_READY: return make_error_condition(errc::resource_unavailable_try_again);
235 case ERROR_NOT_SAME_DEVICE: return make_error_condition(errc::cross_device_link);
236 case ERROR_OPEN_FAILED: return make_error_condition(errc::io_error);
237 case ERROR_OPEN_FILES: return make_error_condition(errc::device_or_resource_busy);
238 case ERROR_OPERATION_ABORTED: return make_error_condition(errc::operation_canceled);
239 case ERROR_OUTOFMEMORY: return make_error_condition(errc::not_enough_memory);
240 case ERROR_PATH_NOT_FOUND: return make_error_condition(errc::no_such_file_or_directory);
241 case ERROR_READ_FAULT: return make_error_condition(errc::io_error);
242 case ERROR_RETRY: return make_error_condition(errc::resource_unavailable_try_again);
243 case ERROR_SEEK: return make_error_condition(errc::io_error);
244 case ERROR_SHARING_VIOLATION: return make_error_condition(errc::permission_denied);
245 case ERROR_TOO_MANY_OPEN_FILES: return make_error_condition(errc::too_many_files_open);
246 case ERROR_WRITE_FAULT: return make_error_condition(errc::io_error);
247 case ERROR_WRITE_PROTECT: return make_error_condition(errc::permission_denied);
248 case ERROR_SEM_TIMEOUT: return make_error_condition(errc::timed_out);
249 case WSAEACCES: return make_error_condition(errc::permission_denied);
250 case WSAEADDRINUSE: return make_error_condition(errc::address_in_use);
251 case WSAEADDRNOTAVAIL: return make_error_condition(errc::address_not_available);
252 case WSAEAFNOSUPPORT: return make_error_condition(errc::address_family_not_supported);
253 case WSAEALREADY: return make_error_condition(errc::connection_already_in_progress);
254 case WSAEBADF: return make_error_condition(errc::bad_file_descriptor);
255 case WSAECONNABORTED: return make_error_condition(errc::connection_aborted);
256 case WSAECONNREFUSED: return make_error_condition(errc::connection_refused);
257 case WSAECONNRESET: return make_error_condition(errc::connection_reset);
258 case WSAEDESTADDRREQ: return make_error_condition(errc::destination_address_required);
259 case WSAEFAULT: return make_error_condition(errc::bad_address);
260 case WSAEHOSTUNREACH: return make_error_condition(errc::host_unreachable);
261 case WSAEINPROGRESS: return make_error_condition(errc::operation_in_progress);
262 case WSAEINTR: return make_error_condition(errc::interrupted);
263 case WSAEINVAL: return make_error_condition(errc::invalid_argument);
264 case WSAEISCONN: return make_error_condition(errc::already_connected);
265 case WSAEMFILE: return make_error_condition(errc::too_many_files_open);
266 case WSAEMSGSIZE: return make_error_condition(errc::message_size);
267 case WSAENAMETOOLONG: return make_error_condition(errc::filename_too_long);
268 case WSAENETDOWN: return make_error_condition(errc::network_down);
269 case WSAENETRESET: return make_error_condition(errc::network_reset);
270 case WSAENETUNREACH: return make_error_condition(errc::network_unreachable);
271 case WSAENOBUFS: return make_error_condition(errc::no_buffer_space);
272 case WSAENOPROTOOPT: return make_error_condition(errc::no_protocol_option);
273 case WSAENOTCONN: return make_error_condition(errc::not_connected);
274 case WSAENOTSOCK: return make_error_condition(errc::not_a_socket);
275 case WSAEOPNOTSUPP: return make_error_condition(errc::operation_not_supported);
276 case WSAEPROTONOSUPPORT: return make_error_condition(errc::protocol_not_supported);
277 case WSAEPROTOTYPE: return make_error_condition(errc::wrong_protocol_type);
278 case WSAETIMEDOUT: return make_error_condition(errc::timed_out);
279 case WSAEWOULDBLOCK: return make_error_condition(errc::operation_would_block);
280 default: return error_condition(ev, system_category());
281 }
282 }
283
284 } // end namespace llvm
285
286 #endif // LLVM_ON_WIN32
+0
-903
utils/KillTheDoctor/system_error.h less more
None //===---------------------------- system_error ----------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This was lifted from libc++ and modified for C++03.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_SYSTEM_SYSTEM_ERROR_H
14 #define LLVM_SYSTEM_SYSTEM_ERROR_H
15
16 /*
17 system_error synopsis
18
19 namespace std
20 {
21
22 class error_category
23 {
24 public:
25 virtual ~error_category();
26
27 error_category(const error_category&) = delete;
28 error_category& operator=(const error_category&) = delete;
29
30 virtual const char* name() const = 0;
31 virtual error_condition default_error_condition(int ev) const;
32 virtual bool equivalent(int code, const error_condition& condition) const;
33 virtual bool equivalent(const error_code& code, int condition) const;
34 virtual std::string message(int ev) const = 0;
35
36 bool operator==(const error_category& rhs) const;
37 bool operator!=(const error_category& rhs) const;
38 bool operator<(const error_category& rhs) const;
39 };
40
41 const error_category& generic_category();
42 const error_category& system_category();
43
44 template struct is_error_code_enum
45 : public false_type {};
46
47 template struct is_error_condition_enum
48 : public false_type {};
49
50 class error_code
51 {
52 public:
53 // constructors:
54 error_code();
55 error_code(int val, const error_category& cat);
56 template
57 error_code(ErrorCodeEnum e);
58
59 // modifiers:
60 void assign(int val, const error_category& cat);
61 template
62 error_code& operator=(ErrorCodeEnum e);
63 void clear();
64
65 // observers:
66 int value() const;
67 const error_category& category() const;
68 error_condition default_error_condition() const;
69 std::string message() const;
70 explicit operator bool() const;
71 };
72
73 // non-member functions:
74 bool operator<(const error_code& lhs, const error_code& rhs);
75 template
76 basic_ostream&
77 operator<<(basic_ostream& os, const error_code& ec);
78
79 class error_condition
80 {
81 public:
82 // constructors:
83 error_condition();
84 error_condition(int val, const error_category& cat);
85 template
86 error_condition(ErrorConditionEnum e);
87
88 // modifiers:
89 void assign(int val, const error_category& cat);
90 template
91 error_condition& operator=(ErrorConditionEnum e);
92 void clear();
93
94 // observers:
95 int value() const;
96 const error_category& category() const;
97 std::string message() const;
98 explicit operator bool() const;
99 };
100
101 bool operator<(const error_condition& lhs, const error_condition& rhs);
102
103 class system_error
104 : public runtime_error
105 {
106 public:
107 system_error(error_code ec, const std::string& what_arg);
108 system_error(error_code ec, const char* what_arg);
109 system_error(error_code ec);
110 system_error(int ev, const error_category& ecat, const std::string& what_arg);
111 system_error(int ev, const error_category& ecat, const char* what_arg);
112 system_error(int ev, const error_category& ecat);
113
114 const error_code& code() const throw();
115 const char* what() const throw();
116 };
117
118 enum class errc
119 {
120 address_family_not_supported, // EAFNOSUPPORT
121 address_in_use, // EADDRINUSE
122 address_not_available, // EADDRNOTAVAIL
123 already_connected, // EISCONN
124 argument_list_too_long, // E2BIG
125 argument_out_of_domain, // EDOM
126 bad_address, // EFAULT
127 bad_file_descriptor, // EBADF
128 bad_message, // EBADMSG
129 broken_pipe, // EPIPE
130 connection_aborted, // ECONNABORTED
131 connection_already_in_progress, // EALREADY
132 connection_refused, // ECONNREFUSED
133 connection_reset, // ECONNRESET
134 cross_device_link, // EXDEV
135 destination_address_required, // EDESTADDRREQ
136 device_or_resource_busy, // EBUSY
137 directory_not_empty, // ENOTEMPTY
138 executable_format_error, // ENOEXEC
139 file_exists, // EEXIST
140 file_too_large, // EFBIG
141 filename_too_long, // ENAMETOOLONG
142 function_not_supported, // ENOSYS
143 host_unreachable, // EHOSTUNREACH
144 identifier_removed, // EIDRM
145 illegal_byte_sequence, // EILSEQ
146 inappropriate_io_control_operation, // ENOTTY
147 interrupted, // EINTR
148 invalid_argument, // EINVAL
149 invalid_seek, // ESPIPE
150 io_error, // EIO
151 is_a_directory, // EISDIR
152 message_size, // EMSGSIZE
153 network_down, // ENETDOWN
154 network_reset, // ENETRESET
155 network_unreachable, // ENETUNREACH
156 no_buffer_space, // ENOBUFS
157 no_child_process, // ECHILD
158 no_link, // ENOLINK
159 no_lock_available, // ENOLCK
160 no_message_available, // ENODATA
161 no_message, // ENOMSG
162 no_protocol_option, // ENOPROTOOPT
163 no_space_on_device, // ENOSPC
164 no_stream_resources, // ENOSR
165 no_such_device_or_address, // ENXIO
166 no_such_device, // ENODEV
167 no_such_file_or_directory, // ENOENT
168 no_such_process, // ESRCH
169 not_a_directory, // ENOTDIR
170 not_a_socket, // ENOTSOCK
171 not_a_stream, // ENOSTR
172 not_connected, // ENOTCONN
173 not_enough_memory, // ENOMEM
174 not_supported, // ENOTSUP
175 operation_canceled, // ECANCELED
176 operation_in_progress, // EINPROGRESS
177 operation_not_permitted, // EPERM
178 operation_not_supported, // EOPNOTSUPP
179 operation_would_block, // EWOULDBLOCK
180 owner_dead, // EOWNERDEAD
181 permission_denied, // EACCES
182 protocol_error, // EPROTO
183 protocol_not_supported, // EPROTONOSUPPORT
184 read_only_file_system, // EROFS
185 resource_deadlock_would_occur, // EDEADLK
186 resource_unavailable_try_again, // EAGAIN
187 result_out_of_range, // ERANGE
188 state_not_recoverable, // ENOTRECOVERABLE
189 stream_timeout, // ETIME
190 text_file_busy, // ETXTBSY
191 timed_out, // ETIMEDOUT
192 too_many_files_open_in_system, // ENFILE
193 too_many_files_open, // EMFILE
194 too_many_links, // EMLINK
195 too_many_symbolic_link_levels, // ELOOP
196 value_too_large, // EOVERFLOW
197 wrong_protocol_type // EPROTOTYPE
198 };
199
200 template <> struct is_error_condition_enum : true_type { }
201
202 error_code make_error_code(errc e);
203 error_condition make_error_condition(errc e);
204
205 // Comparison operators:
206 bool operator==(const error_code& lhs, const error_code& rhs);
207 bool operator==(const error_code& lhs, const error_condition& rhs);
208 bool operator==(const error_condition& lhs, const error_code& rhs);
209 bool operator==(const error_condition& lhs, const error_condition& rhs);
210 bool operator!=(const error_code& lhs, const error_code& rhs);
211 bool operator!=(const error_code& lhs, const error_condition& rhs);
212 bool operator!=(const error_condition& lhs, const error_code& rhs);
213 bool operator!=(const error_condition& lhs, const error_condition& rhs);
214
215 template <> struct hash;
216
217 } // std
218
219 */
220
221 #include "llvm/Config/config.h"
222 #include "llvm/Support/type_traits.h"
223 #include
224 #include
225
226 #ifdef LLVM_ON_WIN32
227 // VS 2008 needs this for some of the defines below.
228 # include
229
230 // The following numbers were taken from VS2010.
231 # ifndef EAFNOSUPPORT
232 # define EAFNOSUPPORT WSAEAFNOSUPPORT
233 # endif
234 # ifndef EADDRINUSE
235 # define EADDRINUSE WSAEADDRINUSE
236 # endif
237 # ifndef EADDRNOTAVAIL
238 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
239 # endif
240 # ifndef EISCONN
241 # define EISCONN WSAEISCONN
242 # endif
243 # ifndef E2BIG
244 # define E2BIG WSAE2BIG
245 # endif
246 # ifndef EDOM
247 # define EDOM WSAEDOM
248 # endif
249 # ifndef EFAULT
250 # define EFAULT WSAEFAULT
251 # endif
252 # ifndef EBADF
253 # define EBADF WSAEBADF
254 # endif
255 # ifndef EBADMSG
256 # define EBADMSG 104
257 # endif
258 # ifndef EPIPE
259 # define EPIPE WSAEPIPE
260 # endif
261 # ifndef ECONNABORTED
262 # define ECONNABORTED WSAECONNABORTED
263 # endif
264 # ifndef EALREADY
265 # define EALREADY WSAEALREADY
266 # endif
267 # ifndef ECONNREFUSED
268 # define ECONNREFUSED WSAECONNREFUSED
269 # endif
270 # ifndef ECONNRESET
271 # define ECONNRESET WSAECONNRESET
272 # endif
273 # ifndef EXDEV
274 # define EXDEV WSAEXDEV
275 # endif
276 # ifndef EDESTADDRREQ
277 # define EDESTADDRREQ WSAEDESTADDRREQ
278 # endif
279 # ifndef EBUSY
280 # define EBUSY WSAEBUSY
281 # endif
282 # ifndef ENOTEMPTY
283 # define ENOTEMPTY WSAENOTEMPTY
284 # endif
285 # ifndef ENOEXEC
286 # define ENOEXEC WSAENOEXEC
287 # endif
288 # ifndef EEXIST
289 # define EEXIST WSAEEXIST
290 # endif
291 # ifndef EFBIG
292 # define EFBIG WSAEFBIG
293 # endif
294 # ifndef ENAMETOOLONG
295 # define ENAMETOOLONG WSAENAMETOOLONG
296 # endif
297 # ifndef ENOSYS
298 # define ENOSYS WSAENOSYS
299 # endif
300 # ifndef EHOSTUNREACH
301 # define EHOSTUNREACH WSAEHOSTUNREACH
302 # endif
303 # ifndef EIDRM
304 # define EIDRM 111
305 # endif
306 # ifndef EILSEQ
307 # define EILSEQ WSAEILSEQ
308 # endif
309 # ifndef ENOTTY
310 # define ENOTTY WSAENOTTY
311 # endif
312 # ifndef EINTR
313 # define EINTR WSAEINTR
314 # endif
315 # ifndef EINVAL
316 # define EINVAL WSAEINVAL
317 # endif
318 # ifndef ESPIPE
319 # define ESPIPE WSAESPIPE
320 # endif
321 # ifndef EIO
322 # define EIO WSAEIO
323 # endif
324 # ifndef EISDIR
325 # define EISDIR WSAEISDIR
326 # endif
327 # ifndef EMSGSIZE
328 # define EMSGSIZE WSAEMSGSIZE
329 # endif
330 # ifndef ENETDOWN
331 # define ENETDOWN WSAENETDOWN
332 # endif
333 # ifndef ENETRESET
334 # define ENETRESET WSAENETRESET
335 # endif
336 # ifndef ENETUNREACH
337 # define ENETUNREACH WSAENETUNREACH
338 # endif
339 # ifndef ENOBUFS
340 # define ENOBUFS WSAENOBUFS
341 # endif
342 # ifndef ECHILD
343 # define ECHILD WSAECHILD
344 # endif
345 # ifndef ENOLINK
346 # define ENOLINK 121
347 # endif
348 # ifndef ENOLCK
349 # define ENOLCK WSAENOLCK
350 # endif
351 # ifndef ENODATA
352 # define ENODATA 120
353 # endif
354 # ifndef ENOMSG
355 # define ENOMSG 122
356 # endif
357 # ifndef ENOPROTOOPT
358 # define ENOPROTOOPT WSAENOPROTOOPT
359 # endif
360 # ifndef ENOSPC
361 # define ENOSPC WSAENOSPC
362 # endif
363 # ifndef ENOSR
364 # define ENOSR 124
365 # endif
366 # ifndef ENXIO
367 # define ENXIO WSAENXIO
368 # endif
369 # ifndef ENODEV
370 # define ENODEV WSAENODEV
371 # endif
372 # ifndef ENOENT
373 # define ENOENT WSAENOENT
374 # endif
375 # ifndef ESRCH
376 # define ESRCH WSAESRCH
377 # endif
378 # ifndef ENOTDIR
379 # define ENOTDIR WSAENOTDIR
380 # endif
381 # ifndef ENOTSOCK
382 # define ENOTSOCK WSAENOTSOCK
383 # endif
384 # ifndef ENOSTR
385 # define ENOSTR 125
386 # endif
387 # ifndef ENOTCONN
388 # define ENOTCONN WSAENOTCONN
389 # endif
390 # ifndef ENOMEM
391 # define ENOMEM WSAENOMEM
392 # endif
393 # ifndef ENOTSUP
394 # define ENOTSUP 129
395 # endif
396 # ifndef ECANCELED
397 # define ECANCELED 105
398 # endif
399 # ifndef EINPROGRESS
400 # define EINPROGRESS WSAEINPROGRESS
401 # endif
402 # ifndef EPERM
403 # define EPERM WSAEPERM
404 # endif
405 # ifndef EOPNOTSUPP
406 # define EOPNOTSUPP WSAEOPNOTSUPP
407 # endif
408 # ifndef EWOULDBLOCK
409 # define EWOULDBLOCK WSAEWOULDBLOCK
410 # endif
411 # ifndef EOWNERDEAD
412 # define EOWNERDEAD 133
413 # endif
414 # ifndef EACCES
415 # define EACCES WSAEACCES
416 # endif
417 # ifndef EPROTO
418 # define EPROTO 134
419 # endif
420 # ifndef EPROTONOSUPPORT
421 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
422 # endif
423 # ifndef EROFS
424 # define EROFS WSAEROFS
425 # endif
426 # ifndef EDEADLK
427 # define EDEADLK WSAEDEADLK
428 # endif
429 # ifndef EAGAIN
430 # define EAGAIN WSAEAGAIN
431 # endif
432 # ifndef ERANGE
433 # define ERANGE WSAERANGE
434 # endif
435 # ifndef ENOTRECOVERABLE
436 # define ENOTRECOVERABLE 127
437 # endif
438 # ifndef ETIME
439 # define ETIME 137
440 # endif
441 # ifndef ETXTBSY
442 # define ETXTBSY 139
443 # endif
444 # ifndef ETIMEDOUT
445 # define ETIMEDOUT WSAETIMEDOUT
446 # endif
447 # ifndef ENFILE
448 # define ENFILE WSAENFILE
449 # endif
450 # ifndef EMFILE
451 # define EMFILE WSAEMFILE
452 # endif
453 # ifndef EMLINK
454 # define EMLINK WSAEMLINK
455 # endif
456 # ifndef ELOOP
457 # define ELOOP WSAELOOP
458 # endif
459 # ifndef EOVERFLOW
460 # define EOVERFLOW 132
461 # endif
462 # ifndef EPROTOTYPE
463 # define EPROTOTYPE WSAEPROTOTYPE
464 # endif
465 #endif
466
467 namespace llvm {
468
469 template
470 struct integral_constant {
471 typedef T value_type;
472 static const value_type value = v;
473 typedef integral_constant type;
474 operator value_type() { return value; }
475 };
476
477 typedef integral_constant true_type;
478 typedef integral_constant false_type;
479
480 // is_error_code_enum
481
482 template struct is_error_code_enum : public false_type {};
483
484 // is_error_condition_enum
485
486 template struct is_error_condition_enum : public false_type {};
487
488 // Some error codes are not present on all platforms, so we provide equivalents
489 // for them:
490
491 //enum class errc
492 struct errc {
493 enum _ {
494 success = 0,
495 address_family_not_supported = EAFNOSUPPORT,
496 address_in_use = EADDRINUSE,
497 address_not_available = EADDRNOTAVAIL,
498 already_connected = EISCONN,
499 argument_list_too_long = E2BIG,
500 argument_out_of_domain = EDOM,
501 bad_address = EFAULT,
502 bad_file_descriptor = EBADF,
503 bad_message = EBADMSG,
504 broken_pipe = EPIPE,
505 connection_aborted = ECONNABORTED,
506 connection_already_in_progress = EALREADY,
507 connection_refused = ECONNREFUSED,
508 connection_reset = ECONNRESET,
509 cross_device_link = EXDEV,
510 destination_address_required = EDESTADDRREQ,
511 device_or_resource_busy = EBUSY,
512 directory_not_empty = ENOTEMPTY,
513 executable_format_error = ENOEXEC,
514 file_exists = EEXIST,
515 file_too_large = EFBIG,
516 filename_too_long = ENAMETOOLONG,
517 function_not_supported = ENOSYS,
518 host_unreachable = EHOSTUNREACH,
519 identifier_removed = EIDRM,
520 illegal_byte_sequence = EILSEQ,
521 inappropriate_io_control_operation = ENOTTY,
522 interrupted = EINTR,
523 invalid_argument = EINVAL,
524 invalid_seek = ESPIPE,
525 io_error = EIO,
526 is_a_directory = EISDIR,
527 message_size = EMSGSIZE,
528 network_down = ENETDOWN,
529 network_reset = ENETRESET,
530 network_unreachable = ENETUNREACH,
531 no_buffer_space = ENOBUFS,
532 no_child_process = ECHILD,
533 no_link = ENOLINK,
534 no_lock_available = ENOLCK,
535 #ifdef ENODATA
536 no_message_available = ENODATA,
537 #else
538 no_message_available = ENOMSG,
539 #endif
540 no_message = ENOMSG,
541 no_protocol_option = ENOPROTOOPT,
542 no_space_on_device = ENOSPC,
543 #ifdef ENOSR
544 no_stream_resources = ENOSR,
545 #else
546 no_stream_resources = ENOMEM,
547 #endif
548 no_such_device_or_address = ENXIO,
549 no_such_device = ENODEV,
550 no_such_file_or_directory = ENOENT,
551 no_such_process = ESRCH,
552 not_a_directory = ENOTDIR,
553 not_a_socket = ENOTSOCK,
554 #ifdef ENOSTR
555 not_a_stream = ENOSTR,
556 #else
557 not_a_stream = EINVAL,
558 #endif
559 not_connected = ENOTCONN,
560 not_enough_memory = ENOMEM,
561 not_supported = ENOTSUP,
562 operation_canceled = ECANCELED,
563 operation_in_progress = EINPROGRESS,
564 operation_not_permitted = EPERM,
565 operation_not_supported = EOPNOTSUPP,
566 operation_would_block = EWOULDBLOCK,
567 owner_dead = EOWNERDEAD,
568 permission_denied = EACCES,
569 protocol_error = EPROTO,
570 protocol_not_supported = EPROTONOSUPPORT,
571 read_only_file_system = EROFS,
572 resource_deadlock_would_occur = EDEADLK,
573 resource_unavailable_try_again = EAGAIN,
574 result_out_of_range = ERANGE,
575 state_not_recoverable = ENOTRECOVERABLE,
576 #ifdef ETIME
577 stream_timeout = ETIME,
578 #else
579 stream_timeout = ETIMEDOUT,
580 #endif
581 text_file_busy = ETXTBSY,
582 timed_out = ETIMEDOUT,
583 too_many_files_open_in_system = ENFILE,
584 too_many_files_open = EMFILE,
585 too_many_links = EMLINK,
586 too_many_symbolic_link_levels = ELOOP,
587 value_too_large = EOVERFLOW,
588 wrong_protocol_type = EPROTOTYPE
589 };
590
591 _ v_;
592
593 errc(_ v) : v_(v) {}
594 operator int() const {return v_;}
595 };
596
597 template <> struct is_error_condition_enum : true_type { };
598
599 template <> struct is_error_condition_enum : true_type { };
600
601 class error_condition;
602 class error_code;
603
604 // class error_category
605
606 class _do_message;
607
608 class error_category
609 {
610 public:
611 virtual ~error_category();
612
613 private:
614 error_category();
615 error_category(const error_category&);// = delete;
616 error_category& operator=(const error_category&);// = delete;
617
618 public:
619 virtual const char* name() const = 0;
620 virtual error_condition default_error_condition(int _ev) const;
621 virtual bool equivalent(int _code, const error_condition& _condition) const;
622 virtual bool equivalent(const error_code& _code, int _condition) const;
623 virtual std::string message(int _ev) const = 0;
624
625 bool operator==(const error_category& _rhs) const {return this == &_rhs;}
626
627 bool operator!=(const error_category& _rhs) const {return !(*this == _rhs);}
628
629 bool operator< (const error_category& _rhs) const {return this < &_rhs;}
630
631 friend class _do_message;
632 };
633
634 class _do_message : public error_category
635 {
636 public:
637 virtual std::string message(int ev) const;
638 };
639
640 const error_category& generic_category();
641 const error_category& system_category();
642
643 class error_condition
644 {
645 int _val_;
646 const error_category* _cat_;
647 public:
648 error_condition() : _val_(0), _cat_(&generic_category()) {}
649
650 error_condition(int _val, const error_category& _cat)
651 : _val_(_val), _cat_(&_cat) {}
652
653 template
654 error_condition(E _e, typename enable_if_c<
655 is_error_condition_enum::value
656 >::type* = 0)
657 {*this = make_error_condition(_e);}
658
659 void assign(int _val, const error_category& _cat) {
660 _val_ = _val;
661 _cat_ = &_cat;
662 }
663
664 template
665 typename enable_if_c
666 <
667 is_error_condition_enum::value,
668 error_condition&
669 >::type
670 operator=(E _e)
671 {*this = make_error_condition(_e); return *this;}
672
673 void clear() {
674 _val_ = 0;
675 _cat_ = &generic_category();
676 }
677
678 int value() const {return _val_;}
679
680 const error_category& category() const {return *_cat_;}
681 std::string message() const;
682
683 // explicit
684 operator bool() const {return _val_ != 0;}
685 };
686
687 inline error_condition make_error_condition(errc _e) {
688 return error_condition(static_cast(_e), generic_category());
689 }
690
691 inline bool operator<(const error_condition& _x, const error_condition& _y) {
692 return _x.category() < _y.category()
693 || _x.category() == _y.category() && _x.value() < _y.value();
694 }
695
696 // error_code
697
698 class error_code {
699 int _val_;
700 const error_category* _cat_;
701 public:
702 error_code() : _val_(0), _cat_(&system_category()) {}
703
704 error_code(int _val, const error_category& _cat)
705 : _val_(_val), _cat_(&_cat) {}
706
707 template
708 error_code(E _e, typename enable_if_c<
709 is_error_code_enum::value
710 >::type* = 0) {
711 *this = make_error_code(_e);
712 }
713
714 void assign(int _val, const error_category& _cat) {
715 _val_ = _val;
716 _cat_ = &_cat;
717 }
718
719 template
720 typename enable_if_c
721 <
722 is_error_code_enum::value,
723 error_code&
724 >::type
725 operator=(E _e)
726 {*this = make_error_code(_e); return *this;}
727
728 void clear() {
729 _val_ = 0;
730 _cat_ = &system_category();
731 }
732
733 int value() const {return _val_;}
734
735 const error_category& category() const {return *_cat_;}
736
737 error_condition default_error_condition() const
738 {return _cat_->default_error_condition(_val_);}
739
740 std::string message() const;
741
742 // explicit
743 operator bool() const {return _val_ != 0;}
744 };
745
746 inline error_code make_error_code(errc _e) {
747 return error_code(static_cast(_e), generic_category());
748 }
749
750 inline bool operator<(const error_code& _x, const error_code& _y) {
751 return _x.category() < _y.category()
752 || _x.category() == _y.category() && _x.value() < _y.value();
753 }
754
755 inline bool operator==(const error_code& _x, const error_code& _y) {
756 return _x.category() == _y.category() && _x.value() == _y.value();
757 }
758
759 inline bool operator==(const error_code& _x, const error_condition& _y) {
760 return _x.category().equivalent(_x.value(), _y)
761 || _y.category().equivalent(_x, _y.value());
762 }
763
764 inline bool operator==(const error_condition& _x, const error_code& _y) {
765 return _y == _x;
766 }
767
768 inline bool operator==(const error_condition& _x, const error_condition& _y) {
769 return _x.category() == _y.category() && _x.value() == _y.value();
770 }
771
772 inline bool operator!=(const error_code& _x, const error_code& _y) {
773 return !(_x == _y);
774 }
775
776 inline bool operator!=(const error_code& _x, const error_condition& _y) {
777 return !(_x == _y);
778 }
779
780 inline bool operator!=(const error_condition& _x, const error_code& _y) {
781 return !(_x == _y);
782 }
783
784 inline bool operator!=(const error_condition& _x, const error_condition& _y) {
785 return !(_x == _y);
786 }
787
788 // system_error
789
790 class system_error : public std::runtime_error {
791 error_code _ec_;
792 public:
793 system_error(error_code _ec, const std::string& _what_arg);
794 system_error(error_code _ec, const char* _what_arg);
795 system_error(error_code _ec);
796 system_error(int _ev, const error_category& _ecat,
797 const std::string& _what_arg);
798 system_error(int _ev, const error_category& _ecat, const char* _what_arg);
799 system_error(int _ev, const error_category& _ecat);
800 ~system_error() throw();
801
802 const error_code& code() const throw() {return _ec_;}
803
804 private:
805 static std::string _init(const error_code&, std::string);
806 };
807
808 void _throw_system_error(int ev, const char* what_arg);
809
810 } // end namespace llvm
811
812 #ifdef LLVM_ON_WIN32
813 #include
814 #include
815
816 namespace llvm {
817
818 // To construct an error_code after a API error:
819 //
820 // error_code( ::GetLastError(), system_category() )
821 struct windows_error {
822 enum _ {
823 success = 0,
824 // These names and values are based on Windows winerror.h
825 invalid_function = ERROR_INVALID_FUNCTION,
826 file_not_found = ERROR_FILE_NOT_FOUND,
827 path_not_found = ERROR_PATH_NOT_FOUND,
828 too_many_open_files = ERROR_TOO_MANY_OPEN_FILES,
829 access_denied = ERROR_ACCESS_DENIED,
830 invalid_handle = ERROR_INVALID_HANDLE,
831 arena_trashed = ERROR_ARENA_TRASHED,
832 not_enough_memory = ERROR_NOT_ENOUGH_MEMORY,
833 invalid_block = ERROR_INVALID_BLOCK,
834 bad_environment = ERROR_BAD_ENVIRONMENT,
835 bad_format = ERROR_BAD_FORMAT,
836 invalid_access = ERROR_INVALID_ACCESS,
837 outofmemory = ERROR_OUTOFMEMORY,
838 invalid_drive = ERROR_INVALID_DRIVE,
839 current_directory = ERROR_CURRENT_DIRECTORY,
840 not_same_device = ERROR_NOT_SAME_DEVICE,
841 no_more_files = ERROR_NO_MORE_FILES,
842 write_protect = ERROR_WRITE_PROTECT,
843 bad_unit = ERROR_BAD_UNIT,
844 not_ready = ERROR_NOT_READY,
845 bad_command = ERROR_BAD_COMMAND,
846 crc = ERROR_CRC,
847 bad_length = ERROR_BAD_LENGTH,
848 seek = ERROR_SEEK,
849 not_dos_disk = ERROR_NOT_DOS_DISK,
850 sector_not_found = ERROR_SECTOR_NOT_FOUND,
851 out_of_paper = ERROR_OUT_OF_PAPER,
852 write_fault = ERROR_WRITE_FAULT,
853 read_fault = ERROR_READ_FAULT,
854 gen_failure = ERROR_GEN_FAILURE,
855 sharing_violation = ERROR_SHARING_VIOLATION,
856 lock_violation = ERROR_LOCK_VIOLATION,
857 wrong_disk = ERROR_WRONG_DISK,
858 sharing_buffer_exceeded = ERROR_SHARING_BUFFER_EXCEEDED,
859 handle_eof = ERROR_HANDLE_EOF,
860 handle_disk_full= ERROR_HANDLE_DISK_FULL,
861 rem_not_list = ERROR_REM_NOT_LIST,
862 dup_name = ERROR_DUP_NAME,
863 bad_net_path = ERROR_BAD_NETPATH,
864 network_busy = ERROR_NETWORK_BUSY,
865 // ...
866 file_exists = ERROR_FILE_EXISTS,
867 cannot_make = ERROR_CANNOT_MAKE,
868 // ...
869 broken_pipe = ERROR_BROKEN_PIPE,
870 open_failed = ERROR_OPEN_FAILED,
871 buffer_overflow = ERROR_BUFFER_OVERFLOW,
872 disk_full= ERROR_DISK_FULL,
873 // ...
874 lock_failed = ERROR_LOCK_FAILED,
875 busy = ERROR_BUSY,
876 cancel_violation = ERROR_CANCEL_VIOLATION,
877 already_exists = ERROR_ALREADY_EXISTS
878 // ...
879
880 // TODO: add more Windows errors
881 };
882 _ v_;
883
884 windows_error(_ v) : v_(v) {}
885 explicit windows_error(DWORD v) : v_(_(v)) {}
886 operator int() const {return v_;}
887 };
888
889
890 template <> struct is_error_code_enum : true_type { };
891
892 template <> struct is_error_code_enum : true_type { };
893
894 inline error_code make_error_code(windows_error e) {
895 return error_code(static_cast(e), system_category());
896 }
897
898 } // end namespace llvm
899
900 #endif // LLVM_ON_WINDOWS
901
902 #endif