OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_BASE_MACROS_H_ | 5 #ifndef V8_BASE_MACROS_H_ |
6 #define V8_BASE_MACROS_H_ | 6 #define V8_BASE_MACROS_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 #endif | 211 #endif |
212 | 212 |
213 | 213 |
214 #if V8_CC_GNU | 214 #if V8_CC_GNU |
215 #define V8_IMMEDIATE_CRASH() __builtin_trap() | 215 #define V8_IMMEDIATE_CRASH() __builtin_trap() |
216 #else | 216 #else |
217 #define V8_IMMEDIATE_CRASH() ((void(*)())0)() | 217 #define V8_IMMEDIATE_CRASH() ((void(*)())0)() |
218 #endif | 218 #endif |
219 | 219 |
220 | 220 |
221 // Use C++11 static_assert if possible, which gives error | 221 // TODO(all) Replace all uses of this macro with static_assert, remove macro. |
222 // messages that are easier to understand on first sight. | |
223 #if V8_HAS_CXX11_STATIC_ASSERT | |
224 #define STATIC_ASSERT(test) static_assert(test, #test) | 222 #define STATIC_ASSERT(test) static_assert(test, #test) |
225 #else | |
226 // This is inspired by the static assertion facility in boost. This | |
227 // is pretty magical. If it causes you trouble on a platform you may | |
228 // find a fix in the boost code. | |
229 template <bool> class StaticAssertion; | |
230 template <> class StaticAssertion<true> { }; | |
231 // This macro joins two tokens. If one of the tokens is a macro the | |
232 // helper call causes it to be resolved before joining. | |
233 #define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b) | |
234 #define SEMI_STATIC_JOIN_HELPER(a, b) a##b | |
235 // Causes an error during compilation of the condition is not | |
236 // statically known to be true. It is formulated as a typedef so that | |
237 // it can be used wherever a typedef can be used. Beware that this | |
238 // actually causes each use to introduce a new defined type with a | |
239 // name depending on the source line. | |
240 template <int> class StaticAssertionHelper { }; | |
241 #define STATIC_ASSERT(test) \ | |
242 typedef StaticAssertionHelper< \ | |
243 sizeof(StaticAssertion<static_cast<bool>((test))>)> \ | |
244 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) ALLOW_UNUSED_TYPE | |
245 | |
246 #endif | |
247 | 223 |
248 | 224 |
249 // The USE(x) template is used to silence C++ compiler warnings | 225 // The USE(x) template is used to silence C++ compiler warnings |
250 // issued for (yet) unused variables (typically parameters). | 226 // issued for (yet) unused variables (typically parameters). |
251 template <typename T> | 227 template <typename T> |
252 inline void USE(T) { } | 228 inline void USE(T) { } |
253 | 229 |
254 | 230 |
255 #define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) | 231 #define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) |
256 | 232 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 331 |
356 template <> | 332 template <> |
357 inline bool is_fundamental<uint8_t>() { | 333 inline bool is_fundamental<uint8_t>() { |
358 return true; | 334 return true; |
359 } | 335 } |
360 | 336 |
361 } // namespace base | 337 } // namespace base |
362 } // namespace v8 | 338 } // namespace v8 |
363 | 339 |
364 #endif // V8_BASE_MACROS_H_ | 340 #endif // V8_BASE_MACROS_H_ |
OLD | NEW |