Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / v8 / include / v8config.h
1 // Copyright 2013 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
4 // met:
5 //
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.
15 //
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.
27
28 #ifndef V8CONFIG_H_
29 #define V8CONFIG_H_
30
31 // Platform headers for feature detection below.
32 #if defined(__ANDROID__)
33 # include <sys/cdefs.h>
34 #elif defined(__APPLE__)
35 # include <TargetConditionals.h>
36 #elif defined(__linux__)
37 # include <features.h>
38 #endif
39
40
41 // This macro allows to test for the version of the GNU C library (or
42 // a compatible C library that masquerades as glibc). It evaluates to
43 // 0 if libc is not GNU libc or compatible.
44 // Use like:
45 //  #if V8_GLIBC_PREREQ(2, 3)
46 //   ...
47 //  #endif
48 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
49 # define V8_GLIBC_PREREQ(major, minor)                                    \
50     ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor)))
51 #else
52 # define V8_GLIBC_PREREQ(major, minor) 0
53 #endif
54
55
56 // This macro allows to test for the version of the GNU C++ compiler.
57 // Note that this also applies to compilers that masquerade as GCC,
58 // for example clang and the Intel C++ compiler for Linux.
59 // Use like:
60 //  #if V8_GNUC_PREREQ(4, 3, 1)
61 //   ...
62 //  #endif
63 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
64 # define V8_GNUC_PREREQ(major, minor, patchlevel)                         \
65     ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >=   \
66      ((major) * 10000 + (minor) * 100 + (patchlevel)))
67 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
68 # define V8_GNUC_PREREQ(major, minor, patchlevel)       \
69     ((__GNUC__ * 10000 + __GNUC_MINOR__) >=             \
70      ((major) * 10000 + (minor) * 100 + (patchlevel)))
71 #else
72 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0
73 #endif
74
75
76
77 // -----------------------------------------------------------------------------
78 // Operating system detection
79 //
80 //  V8_OS_ANDROID       - Android
81 //  V8_OS_BSD           - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD)
82 //  V8_OS_CYGWIN        - Cygwin
83 //  V8_OS_DRAGONFLYBSD  - DragonFlyBSD
84 //  V8_OS_FREEBSD       - FreeBSD
85 //  V8_OS_LINUX         - Linux
86 //  V8_OS_MACOSX        - Mac OS X
87 //  V8_OS_NACL          - Native Client
88 //  V8_OS_NETBSD        - NetBSD
89 //  V8_OS_OPENBSD       - OpenBSD
90 //  V8_OS_POSIX         - POSIX compatible (mostly everything except Windows)
91 //  V8_OS_QNX           - QNX Neutrino
92 //  V8_OS_SOLARIS       - Sun Solaris and OpenSolaris
93 //  V8_OS_WIN           - Microsoft Windows
94
95 #if defined(__ANDROID__)
96 # define V8_OS_ANDROID 1
97 # define V8_OS_LINUX 1
98 # define V8_OS_POSIX 1
99 #elif defined(__APPLE__)
100 # define V8_OS_BSD 1
101 # define V8_OS_MACOSX 1
102 # define V8_OS_POSIX 1
103 #elif defined(__native_client__)
104 # define V8_OS_NACL 1
105 # define V8_OS_POSIX 1
106 #elif defined(__CYGWIN__)
107 # define V8_OS_CYGWIN 1
108 # define V8_OS_POSIX 1
109 #elif defined(__linux__)
110 # define V8_OS_LINUX 1
111 # define V8_OS_POSIX 1
112 #elif defined(__sun)
113 # define V8_OS_POSIX 1
114 # define V8_OS_SOLARIS 1
115 #elif defined(__FreeBSD__)
116 # define V8_OS_BSD 1
117 # define V8_OS_FREEBSD 1
118 # define V8_OS_POSIX 1
119 #elif defined(__DragonFly__)
120 # define V8_OS_BSD 1
121 # define V8_OS_DRAGONFLYBSD 1
122 # define V8_OS_POSIX 1
123 #elif defined(__NetBSD__)
124 # define V8_OS_BSD 1
125 # define V8_OS_NETBSD 1
126 # define V8_OS_POSIX 1
127 #elif defined(__OpenBSD__)
128 # define V8_OS_BSD 1
129 # define V8_OS_OPENBSD 1
130 # define V8_OS_POSIX 1
131 #elif defined(__QNXNTO__)
132 # define V8_OS_POSIX 1
133 # define V8_OS_QNX 1
134 #elif defined(_WIN32)
135 # define V8_OS_WIN 1
136 #endif
137
138
139 // -----------------------------------------------------------------------------
140 // C library detection
141 //
142 //  V8_LIBC_BIONIC  - Bionic libc
143 //  V8_LIBC_BSD     - BSD libc derivate
144 //  V8_LIBC_GLIBC   - GNU C library
145 //  V8_LIBC_UCLIBC  - uClibc
146 //
147 // Note that testing for libc must be done using #if not #ifdef. For example,
148 // to test for the GNU C library, use:
149 //  #if V8_LIBC_GLIBC
150 //   ...
151 //  #endif
152
153 #if defined(__BIONIC__)
154 # define V8_LIBC_BIONIC 1
155 # define V8_LIBC_BSD 1
156 #elif defined(__UCLIBC__)
157 # define V8_LIBC_UCLIBC 1
158 #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__)
159 # define V8_LIBC_GLIBC 1
160 #else
161 # define V8_LIBC_BSD V8_OS_BSD
162 #endif
163
164
165 // -----------------------------------------------------------------------------
166 // Compiler detection
167 //
168 //  V8_CC_CLANG   - Clang
169 //  V8_CC_GNU     - GNU C++
170 //  V8_CC_INTEL   - Intel C++
171 //  V8_CC_MINGW   - Minimalist GNU for Windows
172 //  V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32)
173 //  V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64)
174 //  V8_CC_MSVC    - Microsoft Visual C/C++
175 //
176 // C++11 feature detection
177 //
178 //  V8_HAS_CXX11_ALIGNAS        - alignas specifier supported
179 //  V8_HAS_CXX11_ALIGNOF        - alignof(type) operator supported
180 //  V8_HAS_CXX11_STATIC_ASSERT  - static_assert() supported
181 //  V8_HAS_CXX11_DELETE         - deleted functions supported
182 //  V8_HAS_CXX11_FINAL          - final marker supported
183 //  V8_HAS_CXX11_OVERRIDE       - override marker supported
184 //
185 // Compiler-specific feature detection
186 //
187 //  V8_HAS___ALIGNOF                    - __alignof(type) operator supported
188 //  V8_HAS___ALIGNOF__                  - __alignof__(type) operator supported
189 //  V8_HAS_ATTRIBUTE_ALIGNED            - __attribute__((aligned(n))) supported
190 //  V8_HAS_ATTRIBUTE_ALWAYS_INLINE      - __attribute__((always_inline))
191 //                                        supported
192 //  V8_HAS_ATTRIBUTE_DEPRECATED         - __attribute__((deprecated)) supported
193 //  V8_HAS_ATTRIBUTE_NOINLINE           - __attribute__((noinline)) supported
194 //  V8_HAS_ATTRIBUTE_UNUSED             - __attribute__((unused)) supported
195 //  V8_HAS_ATTRIBUTE_VISIBILITY         - __attribute__((visibility)) supported
196 //  V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result))
197 //                                        supported
198 //  V8_HAS_BUILTIN_EXPECT               - __builtin_expect() supported
199 //  V8_HAS_DECLSPEC_ALIGN               - __declspec(align(n)) supported
200 //  V8_HAS_DECLSPEC_DEPRECATED          - __declspec(deprecated) supported
201 //  V8_HAS_DECLSPEC_NOINLINE            - __declspec(noinline) supported
202 //  V8_HAS___FINAL                      - __final supported in non-C++11 mode
203 //  V8_HAS___FORCEINLINE                - __forceinline supported
204 //  V8_HAS_SEALED                       - MSVC style sealed marker supported
205 //
206 // Note that testing for compilers and/or features must be done using #if
207 // not #ifdef. For example, to test for Intel C++ Compiler, use:
208 //  #if V8_CC_INTEL
209 //   ...
210 //  #endif
211
212 #if defined(__clang__)
213
214 # define V8_CC_CLANG 1
215
216 // Clang defines __alignof__ as alias for __alignof
217 # define V8_HAS___ALIGNOF 1
218 # define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF
219
220 # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned))
221 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
222 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated))
223 # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline))
224 # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused))
225 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
226 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
227     (__has_attribute(warn_unused_result))
228
229 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
230
231 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas))
232 # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert))
233 # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions))
234 # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control))
235 # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control))
236
237 #elif defined(__GNUC__)
238
239 # define V8_CC_GNU 1
240 // Intel C++ also masquerades as GCC 3.2.0
241 # define V8_CC_INTEL (defined(__INTEL_COMPILER))
242 # define V8_CC_MINGW32 (defined(__MINGW32__))
243 # define V8_CC_MINGW64 (defined(__MINGW64__))
244 # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64)
245
246 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0))
247
248 # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0))
249 // always_inline is available in gcc 4.0 but not very reliable until 4.4.
250 // Works around "sorry, unimplemented: inlining failed" build errors with
251 // older compilers.
252 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0))
253 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0))
254 # define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE (V8_GNUC_PREREQ(4, 5, 0))
255 # define V8_HAS_ATTRIBUTE_NOINLINE (V8_GNUC_PREREQ(3, 4, 0))
256 # define V8_HAS_ATTRIBUTE_UNUSED (V8_GNUC_PREREQ(2, 95, 0))
257 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0))
258 # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \
259     (!V8_CC_INTEL && V8_GNUC_PREREQ(4, 1, 0))
260
261 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0))
262
263 // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality
264 // without warnings (functionality used by the macros below).  These modes
265 // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or,
266 // more standardly, by checking whether __cplusplus has a C++11 or greater
267 // value. Current versions of g++ do not correctly set __cplusplus, so we check
268 // both for forward compatibility.
269 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
270 #  define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0))
271 #  define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0))
272 #  define V8_HAS_CXX11_STATIC_ASSERT (V8_GNUC_PREREQ(4, 3, 0))
273 #  define V8_HAS_CXX11_DELETE (V8_GNUC_PREREQ(4, 4, 0))
274 #  define V8_HAS_CXX11_OVERRIDE (V8_GNUC_PREREQ(4, 7, 0))
275 #  define V8_HAS_CXX11_FINAL (V8_GNUC_PREREQ(4, 7, 0))
276 # else
277 // '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655.
278 #  define V8_HAS___FINAL (V8_GNUC_PREREQ(4, 7, 0))
279 # endif
280
281 #elif defined(_MSC_VER)
282
283 # define V8_CC_MSVC 1
284
285 # define V8_HAS___ALIGNOF 1
286
287 // Override control was added with Visual Studio 2005, but
288 // Visual Studio 2010 and earlier spell "final" as "sealed".
289 # define V8_HAS_CXX11_FINAL (_MSC_VER >= 1700)
290 # define V8_HAS_CXX11_OVERRIDE (_MSC_VER >= 1400)
291 # define V8_HAS_SEALED (_MSC_VER >= 1400)
292
293 # define V8_HAS_DECLSPEC_ALIGN 1
294 # define V8_HAS_DECLSPEC_DEPRECATED (_MSC_VER >= 1300)
295 # define V8_HAS_DECLSPEC_NOINLINE 1
296
297 # define V8_HAS___FORCEINLINE 1
298
299 #endif
300
301
302 // -----------------------------------------------------------------------------
303 // Helper macros
304
305 // A macro used to make better inlining. Don't bother for debug builds.
306 // Use like:
307 //   V8_INLINE int GetZero() { return 0; }
308 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
309 # define V8_INLINE inline __attribute__((always_inline))
310 #elif !defined(DEBUG) && V8_HAS___FORCEINLINE
311 # define V8_INLINE __forceinline
312 #else
313 # define V8_INLINE inline
314 #endif
315
316
317 // A macro used to tell the compiler to never inline a particular function.
318 // Don't bother for debug builds.
319 // Use like:
320 //   V8_NOINLINE int GetMinusOne() { return -1; }
321 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_NOINLINE
322 # define V8_NOINLINE __attribute__((noinline))
323 #elif !defined(DEBUG) && V8_HAS_DECLSPEC_NOINLINE
324 # define V8_NOINLINE __declspec(noinline)
325 #else
326 # define V8_NOINLINE /* NOT SUPPORTED */
327 #endif
328
329
330 // A macro to mark classes or functions as deprecated.
331 #if defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE
332 # define V8_DEPRECATED(message, declarator) \
333 declarator __attribute__((deprecated(message)))
334 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_ATTRIBUTE_DEPRECATED
335 # define V8_DEPRECATED(message, declarator) \
336 declarator __attribute__((deprecated))
337 #elif defined(V8_DEPRECATION_WARNINGS) && V8_HAS_DECLSPEC_DEPRECATED
338 # define V8_DEPRECATED(message, declarator) __declspec(deprecated) declarator
339 #else
340 # define V8_DEPRECATED(message, declarator) declarator
341 #endif
342
343
344 // A macro to mark variables or types as unused, avoiding compiler warnings.
345 #if V8_HAS_ATTRIBUTE_UNUSED
346 # define V8_UNUSED __attribute__((unused))
347 #else
348 # define V8_UNUSED
349 #endif
350
351
352 // Annotate a function indicating the caller must examine the return value.
353 // Use like:
354 //   int foo() V8_WARN_UNUSED_RESULT;
355 #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT
356 # define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
357 #else
358 # define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */
359 #endif
360
361
362 // A macro to provide the compiler with branch prediction information.
363 #if V8_HAS_BUILTIN_EXPECT
364 # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
365 # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1))
366 #else
367 # define V8_UNLIKELY(condition) (condition)
368 # define V8_LIKELY(condition) (condition)
369 #endif
370
371
372 // A macro to specify that a method is deleted from the corresponding class.
373 // Any attempt to use the method will always produce an error at compile time
374 // when this macro can be implemented (i.e. if the compiler supports C++11).
375 // If the current compiler does not support C++11, use of the annotated method
376 // will still cause an error, but the error will most likely occur at link time
377 // rather than at compile time. As a backstop, method declarations using this
378 // macro should be private.
379 // Use like:
380 //   class A {
381 //    private:
382 //     A(const A& other) V8_DELETE;
383 //     A& operator=(const A& other) V8_DELETE;
384 //   };
385 #if V8_HAS_CXX11_DELETE
386 # define V8_DELETE = delete
387 #else
388 # define V8_DELETE /* NOT SUPPORTED */
389 #endif
390
391
392 // Annotate a virtual method indicating it must be overriding a virtual
393 // method in the parent class.
394 // Use like:
395 //   virtual void bar() V8_OVERRIDE;
396 #if V8_HAS_CXX11_OVERRIDE
397 # define V8_OVERRIDE override
398 #else
399 # define V8_OVERRIDE /* NOT SUPPORTED */
400 #endif
401
402
403 // Annotate a virtual method indicating that subclasses must not override it,
404 // or annotate a class to indicate that it cannot be subclassed.
405 // Use like:
406 //   class B V8_FINAL : public A {};
407 //   virtual void bar() V8_FINAL;
408 #if V8_HAS_CXX11_FINAL
409 # define V8_FINAL final
410 #elif V8_HAS___FINAL
411 # define V8_FINAL __final
412 #elif V8_HAS_SEALED
413 # define V8_FINAL sealed
414 #else
415 # define V8_FINAL /* NOT SUPPORTED */
416 #endif
417
418
419 // This macro allows to specify memory alignment for structs, classes, etc.
420 // Use like:
421 //   class V8_ALIGNED(16) MyClass { ... };
422 //   V8_ALIGNED(32) int array[42];
423 #if V8_HAS_CXX11_ALIGNAS
424 # define V8_ALIGNED(n) alignas(n)
425 #elif V8_HAS_ATTRIBUTE_ALIGNED
426 # define V8_ALIGNED(n) __attribute__((aligned(n)))
427 #elif V8_HAS_DECLSPEC_ALIGN
428 # define V8_ALIGNED(n) __declspec(align(n))
429 #else
430 # define V8_ALIGNED(n) /* NOT SUPPORTED */
431 #endif
432
433
434 // This macro is similar to V8_ALIGNED(), but takes a type instead of size
435 // in bytes. If the compiler does not supports using the alignment of the
436 // |type|, it will align according to the |alignment| instead. For example,
437 // Visual Studio C++ cannot combine __declspec(align) and __alignof. The
438 // |alignment| must be a literal that is used as a kind of worst-case fallback
439 // alignment.
440 // Use like:
441 //   struct V8_ALIGNAS(AnotherClass, 16) NewClass { ... };
442 //   V8_ALIGNAS(double, 8) int array[100];
443 #if V8_HAS_CXX11_ALIGNAS
444 # define V8_ALIGNAS(type, alignment) alignas(type)
445 #elif V8_HAS___ALIGNOF__ && V8_HAS_ATTRIBUTE_ALIGNED
446 # define V8_ALIGNAS(type, alignment) __attribute__((aligned(__alignof__(type))))
447 #else
448 # define V8_ALIGNAS(type, alignment) V8_ALIGNED(alignment)
449 #endif
450
451
452 // This macro returns alignment in bytes (an integer power of two) required for
453 // any instance of the given type, which is either complete type, an array type,
454 // or a reference type.
455 // Use like:
456 //   size_t alignment = V8_ALIGNOF(double);
457 #if V8_HAS_CXX11_ALIGNOF
458 # define V8_ALIGNOF(type) alignof(type)
459 #elif V8_HAS___ALIGNOF
460 # define V8_ALIGNOF(type) __alignof(type)
461 #elif V8_HAS___ALIGNOF__
462 # define V8_ALIGNOF(type) __alignof__(type)
463 #else
464 // Note that alignment of a type within a struct can be less than the
465 // alignment of the type stand-alone (because of ancient ABIs), so this
466 // should only be used as a last resort.
467 namespace v8 { template <typename T> class AlignOfHelper { char c; T t; }; }
468 # define V8_ALIGNOF(type) (sizeof(::v8::AlignOfHelper<type>) - sizeof(type))
469 #endif
470
471 #endif  // V8CONFIG_H_