Mercurial > hg > CbC > CbC_llvm
comparison lib/Support/system_error.cpp @ 0:95c75e76d11b LLVM3.4
LLVM 3.4
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 12 Dec 2013 13:56:28 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:95c75e76d11b |
---|---|
1 //===---------------------- system_error.cpp ------------------------------===// | |
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 // This was lifted from libc++ and modified for C++03. | |
11 // | |
12 //===----------------------------------------------------------------------===// | |
13 | |
14 #include "llvm/Support/system_error.h" | |
15 #include "llvm/Support/Errno.h" | |
16 #include <cstring> | |
17 #include <string> | |
18 | |
19 namespace llvm { | |
20 | |
21 // class error_category | |
22 | |
23 error_category::error_category() { | |
24 } | |
25 | |
26 error_category::~error_category() { | |
27 } | |
28 | |
29 error_condition | |
30 error_category::default_error_condition(int ev) const { | |
31 return error_condition(ev, *this); | |
32 } | |
33 | |
34 bool | |
35 error_category::equivalent(int code, const error_condition& condition) const { | |
36 return default_error_condition(code) == condition; | |
37 } | |
38 | |
39 bool | |
40 error_category::equivalent(const error_code& code, int condition) const { | |
41 return *this == code.category() && code.value() == condition; | |
42 } | |
43 | |
44 std::string | |
45 _do_message::message(int ev) const { | |
46 return std::string(sys::StrError(ev)); | |
47 } | |
48 | |
49 class _generic_error_category : public _do_message { | |
50 public: | |
51 virtual const char* name() const LLVM_OVERRIDE; | |
52 virtual std::string message(int ev) const LLVM_OVERRIDE; | |
53 }; | |
54 | |
55 const char* | |
56 _generic_error_category::name() const { | |
57 return "generic"; | |
58 } | |
59 | |
60 std::string | |
61 _generic_error_category::message(int ev) const { | |
62 #ifdef ELAST | |
63 if (ev > ELAST) | |
64 return std::string("unspecified generic_category error"); | |
65 #endif // ELAST | |
66 return _do_message::message(ev); | |
67 } | |
68 | |
69 const error_category& | |
70 generic_category() { | |
71 static _generic_error_category s; | |
72 return s; | |
73 } | |
74 | |
75 class _system_error_category : public _do_message { | |
76 public: | |
77 virtual const char* name() const LLVM_OVERRIDE; | |
78 virtual std::string message(int ev) const LLVM_OVERRIDE; | |
79 virtual error_condition default_error_condition(int ev) const LLVM_OVERRIDE; | |
80 }; | |
81 | |
82 const char* | |
83 _system_error_category::name() const { | |
84 return "system"; | |
85 } | |
86 | |
87 // std::string _system_error_category::message(int ev) const { | |
88 // Is in Platform/system_error.inc | |
89 | |
90 // error_condition _system_error_category::default_error_condition(int ev) const | |
91 // Is in Platform/system_error.inc | |
92 | |
93 const error_category& | |
94 system_category() { | |
95 static _system_error_category s; | |
96 return s; | |
97 } | |
98 | |
99 const error_category& | |
100 posix_category() { | |
101 #ifdef LLVM_ON_WIN32 | |
102 return generic_category(); | |
103 #else | |
104 return system_category(); | |
105 #endif | |
106 } | |
107 | |
108 // error_condition | |
109 | |
110 std::string | |
111 error_condition::message() const { | |
112 return _cat_->message(_val_); | |
113 } | |
114 | |
115 // error_code | |
116 | |
117 std::string | |
118 error_code::message() const { | |
119 return _cat_->message(_val_); | |
120 } | |
121 | |
122 } // end namespace llvm | |
123 | |
124 // Include the truly platform-specific parts of this class. | |
125 #if defined(LLVM_ON_UNIX) | |
126 #include "Unix/system_error.inc" | |
127 #endif | |
128 #if defined(LLVM_ON_WIN32) | |
129 #include "Windows/system_error.inc" | |
130 #endif |