OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // actually causes each use to introduce a new defined type with a | 273 // actually causes each use to introduce a new defined type with a |
274 // name depending on the source line. | 274 // name depending on the source line. |
275 template <int> class StaticAssertionHelper { }; | 275 template <int> class StaticAssertionHelper { }; |
276 #define STATIC_CHECK(test) \ | 276 #define STATIC_CHECK(test) \ |
277 typedef \ | 277 typedef \ |
278 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>(test)>)> \ | 278 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>(test)>)> \ |
279 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) | 279 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) |
280 | 280 |
281 | 281 |
282 // The ASSERT macro is equivalent to CHECK except that it only | 282 // The ASSERT macro is equivalent to CHECK except that it only |
283 // generates code in debug builds. Ditto STATIC_ASSERT. | 283 // generates code in debug builds. |
284 #ifdef DEBUG | 284 #ifdef DEBUG |
285 #define ASSERT_RESULT(expr) CHECK(expr) | 285 #define ASSERT_RESULT(expr) CHECK(expr) |
286 #define ASSERT(condition) CHECK(condition) | 286 #define ASSERT(condition) CHECK(condition) |
287 #define ASSERT_EQ(v1, v2) CHECK_EQ(v1, v2) | 287 #define ASSERT_EQ(v1, v2) CHECK_EQ(v1, v2) |
288 #define ASSERT_NE(v1, v2) CHECK_NE(v1, v2) | 288 #define ASSERT_NE(v1, v2) CHECK_NE(v1, v2) |
289 #define ASSERT_GE(v1, v2) CHECK_GE(v1, v2) | 289 #define ASSERT_GE(v1, v2) CHECK_GE(v1, v2) |
290 #define STATIC_ASSERT(test) STATIC_CHECK(test) | |
291 #define SLOW_ASSERT(condition) if (FLAG_enable_slow_asserts) CHECK(condition) | 290 #define SLOW_ASSERT(condition) if (FLAG_enable_slow_asserts) CHECK(condition) |
292 #else | 291 #else |
293 #define ASSERT_RESULT(expr) (expr) | 292 #define ASSERT_RESULT(expr) (expr) |
294 #define ASSERT(condition) ((void) 0) | 293 #define ASSERT(condition) ((void) 0) |
295 #define ASSERT_EQ(v1, v2) ((void) 0) | 294 #define ASSERT_EQ(v1, v2) ((void) 0) |
296 #define ASSERT_NE(v1, v2) ((void) 0) | 295 #define ASSERT_NE(v1, v2) ((void) 0) |
297 #define ASSERT_GE(v1, v2) ((void) 0) | 296 #define ASSERT_GE(v1, v2) ((void) 0) |
298 #define STATIC_ASSERT(test) ((void) 0) | |
299 #define SLOW_ASSERT(condition) ((void) 0) | 297 #define SLOW_ASSERT(condition) ((void) 0) |
300 #endif | 298 #endif |
| 299 // Static asserts has no impact on runtime performance, so they can be |
| 300 // safely enabled in release mode. Moreover, the ((void) 0) expression |
| 301 // obeys different syntax rules than typedef's, e.g. it can't appear |
| 302 // inside class declaration, this leads to inconsistency between debug |
| 303 // and release compilation modes behaviour. |
| 304 #define STATIC_ASSERT(test) STATIC_CHECK(test) |
301 | 305 |
302 | 306 |
303 #define ASSERT_TAG_ALIGNED(address) \ | 307 #define ASSERT_TAG_ALIGNED(address) \ |
304 ASSERT((reinterpret_cast<intptr_t>(address) & kHeapObjectTagMask) == 0) | 308 ASSERT((reinterpret_cast<intptr_t>(address) & kHeapObjectTagMask) == 0) |
305 | 309 |
306 #define ASSERT_SIZE_TAG_ALIGNED(size) ASSERT((size & kHeapObjectTagMask) == 0) | 310 #define ASSERT_SIZE_TAG_ALIGNED(size) ASSERT((size & kHeapObjectTagMask) == 0) |
307 | 311 |
308 #define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p) | 312 #define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p) |
309 | 313 |
310 #endif // V8_CHECKS_H_ | 314 #endif // V8_CHECKS_H_ |
OLD | NEW |