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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 // actually causes each use to introduce a new defined type with a | 265 // actually causes each use to introduce a new defined type with a |
266 // name depending on the source line. | 266 // name depending on the source line. |
267 template <int> class StaticAssertionHelper { }; | 267 template <int> class StaticAssertionHelper { }; |
268 #define STATIC_CHECK(test) \ | 268 #define STATIC_CHECK(test) \ |
269 typedef \ | 269 typedef \ |
270 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>((test))>)> \ | 270 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>((test))>)> \ |
271 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) | 271 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) |
272 #endif | 272 #endif |
273 | 273 |
274 | 274 |
275 #ifdef DEBUG | |
276 #ifndef OPTIMIZED_DEBUG | |
277 #define ENABLE_SLOW_ASSERTS 1 | |
278 #endif | |
279 #endif | |
280 | |
281 namespace v8 { | |
282 namespace internal { | |
283 #if ENABLE_SLOW_ASSERTS | |
Jakob Kummerow
2013/10/24 13:52:09
s/if/ifdef/?
| |
275 extern bool FLAG_enable_slow_asserts; | 284 extern bool FLAG_enable_slow_asserts; |
285 #else | |
286 const bool FLAG_enable_slow_asserts = false; | |
287 #endif | |
288 } // namespace internal | |
289 } // namespace v8 | |
276 | 290 |
277 | 291 |
278 // The ASSERT macro is equivalent to CHECK except that it only | 292 // The ASSERT macro is equivalent to CHECK except that it only |
279 // generates code in debug builds. | 293 // generates code in debug builds. |
280 #ifdef DEBUG | 294 #ifdef DEBUG |
281 #define ASSERT_RESULT(expr) CHECK(expr) | 295 #define ASSERT_RESULT(expr) CHECK(expr) |
282 #define ASSERT(condition) CHECK(condition) | 296 #define ASSERT(condition) CHECK(condition) |
283 #define ASSERT_EQ(v1, v2) CHECK_EQ(v1, v2) | 297 #define ASSERT_EQ(v1, v2) CHECK_EQ(v1, v2) |
284 #define ASSERT_NE(v1, v2) CHECK_NE(v1, v2) | 298 #define ASSERT_NE(v1, v2) CHECK_NE(v1, v2) |
285 #define ASSERT_GE(v1, v2) CHECK_GE(v1, v2) | 299 #define ASSERT_GE(v1, v2) CHECK_GE(v1, v2) |
286 #define ASSERT_LT(v1, v2) CHECK_LT(v1, v2) | 300 #define ASSERT_LT(v1, v2) CHECK_LT(v1, v2) |
287 #define ASSERT_LE(v1, v2) CHECK_LE(v1, v2) | 301 #define ASSERT_LE(v1, v2) CHECK_LE(v1, v2) |
288 #define SLOW_ASSERT(condition) CHECK(!FLAG_enable_slow_asserts || (condition)) | 302 #ifdef ENABLE_SLOW_ASSERTS |
303 #define SLOW_ASSERT(condition) \ | |
304 CHECK(!v8::internal::FLAG_enable_slow_asserts || (condition)) | |
305 #else | |
306 #define SLOW_ASSERT(condition) ((void) 0) | |
307 #endif | |
289 #else | 308 #else |
290 #define ASSERT_RESULT(expr) (expr) | 309 #define ASSERT_RESULT(expr) (expr) |
291 #define ASSERT(condition) ((void) 0) | 310 #define ASSERT(condition) ((void) 0) |
292 #define ASSERT_EQ(v1, v2) ((void) 0) | 311 #define ASSERT_EQ(v1, v2) ((void) 0) |
293 #define ASSERT_NE(v1, v2) ((void) 0) | 312 #define ASSERT_NE(v1, v2) ((void) 0) |
294 #define ASSERT_GE(v1, v2) ((void) 0) | 313 #define ASSERT_GE(v1, v2) ((void) 0) |
295 #define ASSERT_LT(v1, v2) ((void) 0) | 314 #define ASSERT_LT(v1, v2) ((void) 0) |
296 #define ASSERT_LE(v1, v2) ((void) 0) | 315 #define ASSERT_LE(v1, v2) ((void) 0) |
297 #define SLOW_ASSERT(condition) ((void) 0) | 316 #define SLOW_ASSERT(condition) ((void) 0) |
298 #endif | 317 #endif |
299 // Static asserts has no impact on runtime performance, so they can be | 318 // Static asserts has no impact on runtime performance, so they can be |
300 // safely enabled in release mode. Moreover, the ((void) 0) expression | 319 // safely enabled in release mode. Moreover, the ((void) 0) expression |
301 // obeys different syntax rules than typedef's, e.g. it can't appear | 320 // obeys different syntax rules than typedef's, e.g. it can't appear |
302 // inside class declaration, this leads to inconsistency between debug | 321 // inside class declaration, this leads to inconsistency between debug |
303 // and release compilation modes behavior. | 322 // and release compilation modes behavior. |
304 #define STATIC_ASSERT(test) STATIC_CHECK(test) | 323 #define STATIC_ASSERT(test) STATIC_CHECK(test) |
305 | 324 |
306 #define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p) | 325 #define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p) |
307 | 326 |
308 // "Extra checks" are lightweight checks that are enabled in some release | 327 // "Extra checks" are lightweight checks that are enabled in some release |
309 // builds. | 328 // builds. |
310 #ifdef ENABLE_EXTRA_CHECKS | 329 #ifdef ENABLE_EXTRA_CHECKS |
311 #define EXTRA_CHECK(condition) CHECK(condition) | 330 #define EXTRA_CHECK(condition) CHECK(condition) |
312 #else | 331 #else |
313 #define EXTRA_CHECK(condition) ((void) 0) | 332 #define EXTRA_CHECK(condition) ((void) 0) |
314 #endif | 333 #endif |
315 | 334 |
316 #endif // V8_CHECKS_H_ | 335 #endif // V8_CHECKS_H_ |
OLD | NEW |