OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 #define CHECK_NE(unexpected, value) CheckNonEqualsHelper(__FILE__, __LINE__, \ | 223 #define CHECK_NE(unexpected, value) CheckNonEqualsHelper(__FILE__, __LINE__, \ |
224 #unexpected, unexpected, #value, value) | 224 #unexpected, unexpected, #value, value) |
225 | 225 |
226 | 226 |
227 #define CHECK_GT(a, b) CHECK((a) > (b)) | 227 #define CHECK_GT(a, b) CHECK((a) > (b)) |
228 #define CHECK_GE(a, b) CHECK((a) >= (b)) | 228 #define CHECK_GE(a, b) CHECK((a) >= (b)) |
229 #define CHECK_LT(a, b) CHECK((a) < (b)) | 229 #define CHECK_LT(a, b) CHECK((a) < (b)) |
230 #define CHECK_LE(a, b) CHECK((a) <= (b)) | 230 #define CHECK_LE(a, b) CHECK((a) <= (b)) |
231 | 231 |
232 | 232 |
233 // Use C++11 static_assert if possible, which gives error | |
234 // messages that are easier to understand on first sight. | |
235 #if __cplusplus >= 201103L || \ | |
236 (defined(__has_feature) && __has_feature(cxx_static_assert)) || \ | |
237 (defined(__has_extension) && __has_extension(cxx_static_assert)) | |
Sven Panne
2013/07/18 06:45:30
autoconf by hand? ;-)
| |
238 #define STATIC_CHECK(test) static_assert(test, #test) | |
239 #else | |
233 // This is inspired by the static assertion facility in boost. This | 240 // This is inspired by the static assertion facility in boost. This |
234 // is pretty magical. If it causes you trouble on a platform you may | 241 // is pretty magical. If it causes you trouble on a platform you may |
235 // find a fix in the boost code. | 242 // find a fix in the boost code. |
236 template <bool> class StaticAssertion; | 243 template <bool> class StaticAssertion; |
237 template <> class StaticAssertion<true> { }; | 244 template <> class StaticAssertion<true> { }; |
238 // This macro joins two tokens. If one of the tokens is a macro the | 245 // This macro joins two tokens. If one of the tokens is a macro the |
239 // helper call causes it to be resolved before joining. | 246 // helper call causes it to be resolved before joining. |
240 #define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b) | 247 #define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b) |
241 #define SEMI_STATIC_JOIN_HELPER(a, b) a##b | 248 #define SEMI_STATIC_JOIN_HELPER(a, b) a##b |
242 // Causes an error during compilation of the condition is not | 249 // Causes an error during compilation of the condition is not |
243 // statically known to be true. It is formulated as a typedef so that | 250 // statically known to be true. It is formulated as a typedef so that |
244 // it can be used wherever a typedef can be used. Beware that this | 251 // it can be used wherever a typedef can be used. Beware that this |
245 // actually causes each use to introduce a new defined type with a | 252 // actually causes each use to introduce a new defined type with a |
246 // name depending on the source line. | 253 // name depending on the source line. |
247 template <int> class StaticAssertionHelper { }; | 254 template <int> class StaticAssertionHelper { }; |
248 #define STATIC_CHECK(test) \ | 255 #define STATIC_CHECK(test) \ |
249 typedef \ | 256 typedef \ |
250 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>((test))>)> \ | 257 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>((test))>)> \ |
251 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) | 258 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) |
259 #endif | |
252 | 260 |
253 | 261 |
254 extern bool FLAG_enable_slow_asserts; | 262 extern bool FLAG_enable_slow_asserts; |
255 | 263 |
256 | 264 |
257 // The ASSERT macro is equivalent to CHECK except that it only | 265 // The ASSERT macro is equivalent to CHECK except that it only |
258 // generates code in debug builds. | 266 // generates code in debug builds. |
259 #ifdef DEBUG | 267 #ifdef DEBUG |
260 #define ASSERT_RESULT(expr) CHECK(expr) | 268 #define ASSERT_RESULT(expr) CHECK(expr) |
261 #define ASSERT(condition) CHECK(condition) | 269 #define ASSERT(condition) CHECK(condition) |
(...skipping 24 matching lines...) Expand all Loading... | |
286 | 294 |
287 // "Extra checks" are lightweight checks that are enabled in some release | 295 // "Extra checks" are lightweight checks that are enabled in some release |
288 // builds. | 296 // builds. |
289 #ifdef ENABLE_EXTRA_CHECKS | 297 #ifdef ENABLE_EXTRA_CHECKS |
290 #define EXTRA_CHECK(condition) CHECK(condition) | 298 #define EXTRA_CHECK(condition) CHECK(condition) |
291 #else | 299 #else |
292 #define EXTRA_CHECK(condition) ((void) 0) | 300 #define EXTRA_CHECK(condition) ((void) 0) |
293 #endif | 301 #endif |
294 | 302 |
295 #endif // V8_CHECKS_H_ | 303 #endif // V8_CHECKS_H_ |
OLD | NEW |