| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_BASE_MACROS_H_ | 5 #ifndef V8_BASE_MACROS_H_ |
| 6 #define V8_BASE_MACROS_H_ | 6 #define V8_BASE_MACROS_H_ |
| 7 | 7 |
| 8 #include "src/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
| 9 #include "src/base/format-macros.h" | 9 #include "src/base/format-macros.h" |
| 10 #include "src/base/logging.h" | 10 #include "src/base/logging.h" |
| 11 | 11 |
| 12 | 12 |
| 13 // TODO(all) Replace all uses of this macro with C++'s offsetof. To do that, we | 13 // TODO(all) Replace all uses of this macro with C++'s offsetof. To do that, we |
| 14 // have to make sure that only standard-layout types and simple field | 14 // have to make sure that only standard-layout types and simple field |
| 15 // designators are used. | 15 // designators are used. |
| 16 #define OFFSET_OF(type, field) \ | 16 #define OFFSET_OF(type, field) \ |
| 17 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(16)->field)) - 16) | 17 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(16)->field)) - 16) |
| 18 | 18 |
| 19 | 19 |
| 20 // The arraysize(arr) macro returns the # of elements in an array arr. | 20 // The arraysize(arr) macro returns the # of elements in an array arr. |
| 21 // The expression is a compile-time constant, and therefore can be | 21 // The expression is a compile-time constant, and therefore can be |
| 22 // used in defining new arrays, for example. If you use arraysize on | 22 // used in defining new arrays, for example. If you use arraysize on |
| 23 // a pointer by mistake, you will get a compile-time error. | 23 // a pointer by mistake, you will get a compile-time error. |
| 24 // | |
| 25 // One caveat is that arraysize() doesn't accept any array of an | |
| 26 // anonymous type or a type defined inside a function. In these rare | |
| 27 // cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is | |
| 28 // due to a limitation in C++'s template system. The limitation might | |
| 29 // eventually be removed, but it hasn't happened yet. | |
| 30 #define arraysize(array) (sizeof(ArraySizeHelper(array))) | 24 #define arraysize(array) (sizeof(ArraySizeHelper(array))) |
| 31 | 25 |
| 32 | 26 |
| 33 // This template function declaration is used in defining arraysize. | 27 // This template function declaration is used in defining arraysize. |
| 34 // Note that the function doesn't need an implementation, as we only | 28 // Note that the function doesn't need an implementation, as we only |
| 35 // use its type. | 29 // use its type. |
| 36 template <typename T, size_t N> | 30 template <typename T, size_t N> |
| 37 char (&ArraySizeHelper(T (&array)[N]))[N]; | 31 char (&ArraySizeHelper(T (&array)[N]))[N]; |
| 38 | 32 |
| 39 | 33 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 295 |
| 302 template <> | 296 template <> |
| 303 inline bool is_fundamental<uint8_t>() { | 297 inline bool is_fundamental<uint8_t>() { |
| 304 return true; | 298 return true; |
| 305 } | 299 } |
| 306 | 300 |
| 307 } // namespace base | 301 } // namespace base |
| 308 } // namespace v8 | 302 } // namespace v8 |
| 309 | 303 |
| 310 #endif // V8_BASE_MACROS_H_ | 304 #endif // V8_BASE_MACROS_H_ |
| OLD | NEW |