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
3 // found in the LICENSE file.
5 #ifndef V8_BASE_MACROS_H_
6 #define V8_BASE_MACROS_H_
8 #include "../../include/v8stdint.h"
11 // The expression OFFSET_OF(type, field) computes the byte-offset
12 // of the specified field relative to the containing type. This
13 // corresponds to 'offsetof' (in stddef.h), except that it doesn't
14 // use 0 or NULL, which causes a problem with the compiler warnings
15 // we have enabled (which is also why 'offsetof' doesn't seem to work).
16 // Here we simply use the non-zero value 4, which seems to work.
17 #define OFFSET_OF(type, field) \
18 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
21 // The expression ARRAY_SIZE(a) is a compile-time constant of type
22 // size_t which represents the number of elements of the given
23 // array. You should only use ARRAY_SIZE on statically allocated
25 #define ARRAY_SIZE(a) \
26 ((sizeof(a) / sizeof(*(a))) / \
27 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
30 // A macro to disallow the evil copy constructor and operator= functions
31 // This should be used in the private: declarations for a class
32 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
33 TypeName(const TypeName&) V8_DELETE; \
34 void operator=(const TypeName&) V8_DELETE
37 // A macro to disallow all the implicit constructors, namely the
38 // default constructor, copy constructor and operator= functions.
40 // This should be used in the private: declarations for a class
41 // that wants to prevent anyone from instantiating it. This is
42 // especially useful for classes containing only static methods.
43 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
44 TypeName() V8_DELETE; \
45 DISALLOW_COPY_AND_ASSIGN(TypeName)
48 // Newly written code should use V8_INLINE and V8_NOINLINE directly.
49 #define INLINE(declarator) V8_INLINE declarator
50 #define NO_INLINE(declarator) V8_NOINLINE declarator
53 // Newly written code should use V8_WARN_UNUSED_RESULT.
54 #define MUST_USE_RESULT V8_WARN_UNUSED_RESULT
57 // Define DISABLE_ASAN macros.
58 #if defined(__has_feature)
59 #if __has_feature(address_sanitizer)
60 #define DISABLE_ASAN __attribute__((no_sanitize_address))
71 #define V8_IMMEDIATE_CRASH() __builtin_trap()
73 #define V8_IMMEDIATE_CRASH() ((void(*)())0)()
76 #endif // V8_BASE_MACROS_H_