Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: src/checks.h

Issue 304553002: Replace STATIC_CHECK with STATIC_ASSERT. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/arm64/codegen-arm64.cc ('k') | src/contexts.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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_CHECKS_H_ 5 #ifndef V8_CHECKS_H_
6 #define V8_CHECKS_H_ 6 #define V8_CHECKS_H_
7 7
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "../include/v8stdint.h" 10 #include "../include/v8stdint.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 #define CHECK_GT(a, b) CHECK((a) > (b)) 237 #define CHECK_GT(a, b) CHECK((a) > (b))
238 #define CHECK_GE(a, b) CHECK((a) >= (b)) 238 #define CHECK_GE(a, b) CHECK((a) >= (b))
239 #define CHECK_LT(a, b) CHECK((a) < (b)) 239 #define CHECK_LT(a, b) CHECK((a) < (b))
240 #define CHECK_LE(a, b) CHECK((a) <= (b)) 240 #define CHECK_LE(a, b) CHECK((a) <= (b))
241 241
242 242
243 // Use C++11 static_assert if possible, which gives error 243 // Use C++11 static_assert if possible, which gives error
244 // messages that are easier to understand on first sight. 244 // messages that are easier to understand on first sight.
245 #if V8_HAS_CXX11_STATIC_ASSERT 245 #if V8_HAS_CXX11_STATIC_ASSERT
246 #define STATIC_CHECK(test) static_assert(test, #test) 246 #define STATIC_ASSERT(test) static_assert(test, #test)
247 #else 247 #else
248 // This is inspired by the static assertion facility in boost. This 248 // This is inspired by the static assertion facility in boost. This
249 // is pretty magical. If it causes you trouble on a platform you may 249 // is pretty magical. If it causes you trouble on a platform you may
250 // find a fix in the boost code. 250 // find a fix in the boost code.
251 template <bool> class StaticAssertion; 251 template <bool> class StaticAssertion;
252 template <> class StaticAssertion<true> { }; 252 template <> class StaticAssertion<true> { };
253 // This macro joins two tokens. If one of the tokens is a macro the 253 // This macro joins two tokens. If one of the tokens is a macro the
254 // helper call causes it to be resolved before joining. 254 // helper call causes it to be resolved before joining.
255 #define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b) 255 #define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b)
256 #define SEMI_STATIC_JOIN_HELPER(a, b) a##b 256 #define SEMI_STATIC_JOIN_HELPER(a, b) a##b
257 // Causes an error during compilation of the condition is not 257 // Causes an error during compilation of the condition is not
258 // statically known to be true. It is formulated as a typedef so that 258 // statically known to be true. It is formulated as a typedef so that
259 // it can be used wherever a typedef can be used. Beware that this 259 // it can be used wherever a typedef can be used. Beware that this
260 // actually causes each use to introduce a new defined type with a 260 // actually causes each use to introduce a new defined type with a
261 // name depending on the source line. 261 // name depending on the source line.
262 template <int> class StaticAssertionHelper { }; 262 template <int> class StaticAssertionHelper { };
263 #define STATIC_CHECK(test) \ 263 #define STATIC_ASSERT(test) \
264 typedef \ 264 typedef \
265 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>((test))>)> \ 265 StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>((test))>)> \
266 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) V8_UNUSED 266 SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__) V8_UNUSED
267 #endif 267 #endif
268 268
269 269
270 #ifdef DEBUG 270 #ifdef DEBUG
271 #ifndef OPTIMIZED_DEBUG 271 #ifndef OPTIMIZED_DEBUG
272 #define ENABLE_SLOW_ASSERTS 1 272 #define ENABLE_SLOW_ASSERTS 1
273 #endif 273 #endif
(...skipping 29 matching lines...) Expand all
303 #define ASSERT_LE(v1, v2) CHECK_LE(v1, v2) 303 #define ASSERT_LE(v1, v2) CHECK_LE(v1, v2)
304 #else 304 #else
305 #define ASSERT_RESULT(expr) (expr) 305 #define ASSERT_RESULT(expr) (expr)
306 #define ASSERT(condition) ((void) 0) 306 #define ASSERT(condition) ((void) 0)
307 #define ASSERT_EQ(v1, v2) ((void) 0) 307 #define ASSERT_EQ(v1, v2) ((void) 0)
308 #define ASSERT_NE(v1, v2) ((void) 0) 308 #define ASSERT_NE(v1, v2) ((void) 0)
309 #define ASSERT_GE(v1, v2) ((void) 0) 309 #define ASSERT_GE(v1, v2) ((void) 0)
310 #define ASSERT_LT(v1, v2) ((void) 0) 310 #define ASSERT_LT(v1, v2) ((void) 0)
311 #define ASSERT_LE(v1, v2) ((void) 0) 311 #define ASSERT_LE(v1, v2) ((void) 0)
312 #endif 312 #endif
313 // Static asserts has no impact on runtime performance, so they can be
314 // safely enabled in release mode. Moreover, the ((void) 0) expression
315 // obeys different syntax rules than typedef's, e.g. it can't appear
316 // inside class declaration, this leads to inconsistency between debug
317 // and release compilation modes behavior.
318 #define STATIC_ASSERT(test) STATIC_CHECK(test)
319 313
320 #define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p) 314 #define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p)
321 315
322 // "Extra checks" are lightweight checks that are enabled in some release 316 // "Extra checks" are lightweight checks that are enabled in some release
323 // builds. 317 // builds.
324 #ifdef ENABLE_EXTRA_CHECKS 318 #ifdef ENABLE_EXTRA_CHECKS
325 #define EXTRA_CHECK(condition) CHECK(condition) 319 #define EXTRA_CHECK(condition) CHECK(condition)
326 #else 320 #else
327 #define EXTRA_CHECK(condition) ((void) 0) 321 #define EXTRA_CHECK(condition) ((void) 0)
328 #endif 322 #endif
329 323
330 #endif // V8_CHECKS_H_ 324 #endif // V8_CHECKS_H_
OLDNEW
« no previous file with comments | « src/arm64/codegen-arm64.cc ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698