| 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_CHECKS_H_ | 28 #ifndef V8_CHECKS_H_ |
| 29 #define V8_CHECKS_H_ | 29 #define V8_CHECKS_H_ |
| 30 | 30 |
| 31 #include <string.h> | 31 #include <string.h> |
| 32 | 32 |
| 33 #include "globals.h" | |
| 34 | |
| 35 #include "../include/v8stdint.h" | 33 #include "../include/v8stdint.h" |
| 36 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...); | 34 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...); |
| 37 | 35 |
| 38 // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during | 36 // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during |
| 39 // development, but they should not be relied on in the final product. | 37 // development, but they should not be relied on in the final product. |
| 40 #ifdef DEBUG | 38 #ifdef DEBUG |
| 41 #define FATAL(msg) \ | 39 #define FATAL(msg) \ |
| 42 V8_Fatal(__FILE__, __LINE__, "%s", (msg)) | 40 V8_Fatal(__FILE__, __LINE__, "%s", (msg)) |
| 43 #define UNIMPLEMENTED() \ | 41 #define UNIMPLEMENTED() \ |
| 44 V8_Fatal(__FILE__, __LINE__, "unimplemented code") | 42 V8_Fatal(__FILE__, __LINE__, "unimplemented code") |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 225 |
| 228 | 226 |
| 229 #define CHECK_GT(a, b) CHECK((a) > (b)) | 227 #define CHECK_GT(a, b) CHECK((a) > (b)) |
| 230 #define CHECK_GE(a, b) CHECK((a) >= (b)) | 228 #define CHECK_GE(a, b) CHECK((a) >= (b)) |
| 231 #define CHECK_LT(a, b) CHECK((a) < (b)) | 229 #define CHECK_LT(a, b) CHECK((a) < (b)) |
| 232 #define CHECK_LE(a, b) CHECK((a) <= (b)) | 230 #define CHECK_LE(a, b) CHECK((a) <= (b)) |
| 233 | 231 |
| 234 | 232 |
| 235 // Use C++11 static_assert if possible, which gives error | 233 // Use C++11 static_assert if possible, which gives error |
| 236 // messages that are easier to understand on first sight. | 234 // messages that are easier to understand on first sight. |
| 237 #if V8_CXX_STATIC_ASSERT | 235 #if __cplusplus >= 201103L |
| 238 #define STATIC_CHECK(test) static_assert(test, #test) | 236 #define STATIC_CHECK(test) static_assert(test, #test) |
| 239 #else | 237 #else |
| 240 // This is inspired by the static assertion facility in boost. This | 238 // This is inspired by the static assertion facility in boost. This |
| 241 // is pretty magical. If it causes you trouble on a platform you may | 239 // is pretty magical. If it causes you trouble on a platform you may |
| 242 // find a fix in the boost code. | 240 // find a fix in the boost code. |
| 243 template <bool> class StaticAssertion; | 241 template <bool> class StaticAssertion; |
| 244 template <> class StaticAssertion<true> { }; | 242 template <> class StaticAssertion<true> { }; |
| 245 // This macro joins two tokens. If one of the tokens is a macro the | 243 // This macro joins two tokens. If one of the tokens is a macro the |
| 246 // helper call causes it to be resolved before joining. | 244 // helper call causes it to be resolved before joining. |
| 247 #define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b) | 245 #define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b) |
| 248 #define SEMI_STATIC_JOIN_HELPER(a, b) a##b | 246 #define SEMI_STATIC_JOIN_HELPER(a, b) a##b |
| 249 // Causes an error during compilation of the condition is not | 247 // Causes an error during compilation of the condition is not |
| 250 // statically known to be true. It is formulated as a typedef so that | 248 // statically known to be true. It is formulated as a typedef so that |
| 251 // it can be used wherever a typedef can be used. Beware that this | 249 // it can be used wherever a typedef can be used. Beware that this |
| 252 // actually causes each use to introduce a new defined type with a | 250 // actually causes each use to introduce a new defined type with a |
| 253 // name depending on the source line. | 251 // name depending on the source line. |
| 254 template <int> class StaticAssertionHelper { }; | 252 template <int> class StaticAssertionHelper { }; |
| 255 #define STATIC_CHECK(test) \ | 253 #define STATIC_CHECK(test) \ |
| 256 typedef \ | 254 typedef \ |
| 257 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>((test))>)> \ | 255 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>((test))>)> \ |
| 258 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) | 256 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) |
| 259 #endif // V8_CXX_STATIC_ASSERT | 257 #endif |
| 260 | 258 |
| 261 | 259 |
| 262 extern bool FLAG_enable_slow_asserts; | 260 extern bool FLAG_enable_slow_asserts; |
| 263 | 261 |
| 264 | 262 |
| 265 // The ASSERT macro is equivalent to CHECK except that it only | 263 // The ASSERT macro is equivalent to CHECK except that it only |
| 266 // generates code in debug builds. | 264 // generates code in debug builds. |
| 267 #ifdef DEBUG | 265 #ifdef DEBUG |
| 268 #define ASSERT_RESULT(expr) CHECK(expr) | 266 #define ASSERT_RESULT(expr) CHECK(expr) |
| 269 #define ASSERT(condition) CHECK(condition) | 267 #define ASSERT(condition) CHECK(condition) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 294 | 292 |
| 295 // "Extra checks" are lightweight checks that are enabled in some release | 293 // "Extra checks" are lightweight checks that are enabled in some release |
| 296 // builds. | 294 // builds. |
| 297 #ifdef ENABLE_EXTRA_CHECKS | 295 #ifdef ENABLE_EXTRA_CHECKS |
| 298 #define EXTRA_CHECK(condition) CHECK(condition) | 296 #define EXTRA_CHECK(condition) CHECK(condition) |
| 299 #else | 297 #else |
| 300 #define EXTRA_CHECK(condition) ((void) 0) | 298 #define EXTRA_CHECK(condition) ((void) 0) |
| 301 #endif | 299 #endif |
| 302 | 300 |
| 303 #endif // V8_CHECKS_H_ | 301 #endif // V8_CHECKS_H_ |
| OLD | NEW |