1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
28 #ifndef V8_BASE_MACROS_H_
29 #define V8_BASE_MACROS_H_
31 #include "../../include/v8stdint.h"
34 // The expression OFFSET_OF(type, field) computes the byte-offset
35 // of the specified field relative to the containing type. This
36 // corresponds to 'offsetof' (in stddef.h), except that it doesn't
37 // use 0 or NULL, which causes a problem with the compiler warnings
38 // we have enabled (which is also why 'offsetof' doesn't seem to work).
39 // Here we simply use the non-zero value 4, which seems to work.
40 #define OFFSET_OF(type, field) \
41 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
44 // The expression ARRAY_SIZE(a) is a compile-time constant of type
45 // size_t which represents the number of elements of the given
46 // array. You should only use ARRAY_SIZE on statically allocated
48 #define ARRAY_SIZE(a) \
49 ((sizeof(a) / sizeof(*(a))) / \
50 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
53 // A macro to disallow the evil copy constructor and operator= functions
54 // This should be used in the private: declarations for a class
55 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
56 TypeName(const TypeName&) V8_DELETE; \
57 void operator=(const TypeName&) V8_DELETE
60 // A macro to disallow all the implicit constructors, namely the
61 // default constructor, copy constructor and operator= functions.
63 // This should be used in the private: declarations for a class
64 // that wants to prevent anyone from instantiating it. This is
65 // especially useful for classes containing only static methods.
66 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
67 TypeName() V8_DELETE; \
68 DISALLOW_COPY_AND_ASSIGN(TypeName)
71 // Newly written code should use V8_INLINE and V8_NOINLINE directly.
72 #define INLINE(declarator) V8_INLINE declarator
73 #define NO_INLINE(declarator) V8_NOINLINE declarator
76 // Newly written code should use V8_WARN_UNUSED_RESULT.
77 #define MUST_USE_RESULT V8_WARN_UNUSED_RESULT
80 // Define DISABLE_ASAN macros.
81 #if defined(__has_feature)
82 #if __has_feature(address_sanitizer)
83 #define DISABLE_ASAN __attribute__((no_sanitize_address))
94 #define V8_IMMEDIATE_CRASH() __builtin_trap()
96 #define V8_IMMEDIATE_CRASH() ((void(*)())0)()
99 #endif // V8_BASE_MACROS_H_