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

Side by Side Diff: src/base/macros.h

Issue 353113003: Remove dependency from platform files on v8.h (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 | « no previous file | src/globals.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 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 "include/v8stdint.h" 8 #include "include/v8stdint.h"
9 #include "src/base/build_config.h"
9 10
10 11
11 // The expression OFFSET_OF(type, field) computes the byte-offset 12 // The expression OFFSET_OF(type, field) computes the byte-offset
12 // of the specified field relative to the containing type. This 13 // of the specified field relative to the containing type. This
13 // corresponds to 'offsetof' (in stddef.h), except that it doesn't 14 // 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 // 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 // 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 // Here we simply use the non-zero value 4, which seems to work.
17 #define OFFSET_OF(type, field) \ 18 #define OFFSET_OF(type, field) \
18 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4) 19 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 106
106 107
107 // The USE(x) template is used to silence C++ compiler warnings 108 // The USE(x) template is used to silence C++ compiler warnings
108 // issued for (yet) unused variables (typically parameters). 109 // issued for (yet) unused variables (typically parameters).
109 template <typename T> 110 template <typename T>
110 inline void USE(T) { } 111 inline void USE(T) { }
111 112
112 113
113 #define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) 114 #define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
114 115
116
117 // Define our own macros for writing 64-bit constants. This is less fragile
118 // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
119 // works on compilers that don't have it (like MSVC).
120 #if V8_CC_MSVC
121 # define V8_UINT64_C(x) (x ## UI64)
122 # define V8_INT64_C(x) (x ## I64)
123 # if V8_HOST_ARCH_64_BIT
124 # define V8_INTPTR_C(x) (x ## I64)
125 # define V8_PTR_PREFIX "ll"
126 # else
127 # define V8_INTPTR_C(x) (x)
128 # define V8_PTR_PREFIX ""
129 # endif // V8_HOST_ARCH_64_BIT
130 #elif V8_CC_MINGW64
131 # define V8_UINT64_C(x) (x ## ULL)
132 # define V8_INT64_C(x) (x ## LL)
133 # define V8_INTPTR_C(x) (x ## LL)
134 # define V8_PTR_PREFIX "I64"
135 #elif V8_HOST_ARCH_64_BIT
136 # if V8_OS_MACOSX
137 # define V8_UINT64_C(x) (x ## ULL)
138 # define V8_INT64_C(x) (x ## LL)
139 # else
140 # define V8_UINT64_C(x) (x ## UL)
141 # define V8_INT64_C(x) (x ## L)
142 # endif
143 # define V8_INTPTR_C(x) (x ## L)
144 # define V8_PTR_PREFIX "l"
145 #else
146 # define V8_UINT64_C(x) (x ## ULL)
147 # define V8_INT64_C(x) (x ## LL)
148 # define V8_INTPTR_C(x) (x)
149 # define V8_PTR_PREFIX ""
150 #endif
151
152 #define V8PRIxPTR V8_PTR_PREFIX "x"
153 #define V8PRIdPTR V8_PTR_PREFIX "d"
154 #define V8PRIuPTR V8_PTR_PREFIX "u"
155
156 // Fix for Mac OS X defining uintptr_t as "unsigned long":
157 #if V8_OS_MACOSX
158 #undef V8PRIxPTR
159 #define V8PRIxPTR "lx"
160 #endif
161
115 // The following macro works on both 32 and 64-bit platforms. 162 // The following macro works on both 32 and 64-bit platforms.
116 // Usage: instead of writing 0x1234567890123456 163 // Usage: instead of writing 0x1234567890123456
117 // write V8_2PART_UINT64_C(0x12345678,90123456); 164 // write V8_2PART_UINT64_C(0x12345678,90123456);
118 #define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u)) 165 #define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
119 166
120 #endif // V8_BASE_MACROS_H_ 167 #endif // V8_BASE_MACROS_H_
OLDNEW
« no previous file with comments | « no previous file | src/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698