1/*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef WTF_Compiler_h
27#define WTF_Compiler_h
28
29/* COMPILER() - the compiler being used to build the project */
30#define COMPILER(WTF_FEATURE) WTF_COMPILER_##WTF_FEATURE
31
32/* COMPILER_SUPPORTS() - whether the compiler being used to build the project supports the given feature. */
33#define COMPILER_SUPPORTS(WTF_COMPILER_FEATURE) WTF_COMPILER_SUPPORTS_##WTF_COMPILER_FEATURE
34
35/* COMPILER_QUIRK() - whether the compiler being used to build the project requires a given quirk. */
36#define COMPILER_QUIRK(WTF_COMPILER_QUIRK) WTF_COMPILER_QUIRK_##WTF_COMPILER_QUIRK
37
38/* ==== COMPILER() - the compiler being used to build the project ==== */
39
40/* COMPILER(CLANG) - Clang */
41#if defined(__clang__)
42#define WTF_COMPILER_CLANG 1
43
44#ifndef __has_extension
45#define __has_extension __has_feature /* Compatibility with older versions of clang */
46#endif
47
48#define CLANG_PRAGMA(PRAGMA) _Pragma(PRAGMA)
49
50/* Specific compiler features */
51#define WTF_COMPILER_SUPPORTS_CXX_VARIADIC_TEMPLATES __has_extension(cxx_variadic_templates)
52
53/* There is a bug in clang that comes with Xcode 4.2 where AtomicStrings can't be implicitly converted to Strings
54 in the presence of move constructors and/or move assignment operators. This bug has been fixed in Xcode 4.3 clang, so we
55 check for both cxx_rvalue_references as well as the unrelated cxx_nonstatic_member_init feature which we know was added in 4.3 */
56#define WTF_COMPILER_SUPPORTS_CXX_RVALUE_REFERENCES __has_extension(cxx_rvalue_references) && __has_extension(cxx_nonstatic_member_init)
57
58#define WTF_COMPILER_SUPPORTS_CXX_DELETED_FUNCTIONS __has_extension(cxx_deleted_functions)
59#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR __has_feature(cxx_nullptr)
60#define WTF_COMPILER_SUPPORTS_CXX_EXPLICIT_CONVERSIONS __has_feature(cxx_explicit_conversions)
61#define WTF_COMPILER_SUPPORTS_BLOCKS __has_feature(blocks)
62#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT __has_extension(c_static_assert)
63#define WTF_COMPILER_SUPPORTS_CXX_STATIC_ASSERT __has_extension(cxx_static_assert)
64#define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL __has_extension(cxx_override_control)
65#define WTF_COMPILER_SUPPORTS_HAS_TRIVIAL_DESTRUCTOR __has_extension(has_trivial_destructor)
66#define WTF_COMPILER_SUPPORTS_CXX_STRONG_ENUMS __has_extension(cxx_strong_enums)
67
68#endif
69
70#ifndef CLANG_PRAGMA
71#define CLANG_PRAGMA(PRAGMA)
72#endif
73
74/* COMPILER(MSVC) - Microsoft Visual C++ */
75/* COMPILER(MSVC7_OR_LOWER) - Microsoft Visual C++ 2003 or lower*/
76/* COMPILER(MSVC9_OR_LOWER) - Microsoft Visual C++ 2008 or lower*/
77/* COMPILER(MSVC12_OR_LOWER) - Microsoft Visual C++ 2013 or lower*/
78#if defined(_MSC_VER)
79#define WTF_COMPILER_MSVC 1
80#if _MSC_VER < 1400
81#define WTF_COMPILER_MSVC7_OR_LOWER 1
82#elif _MSC_VER < 1600
83#define WTF_COMPILER_MSVC9_OR_LOWER 1
84#elif _MSC_VER < 1800
85#define WTF_COMPILER_MSVC12_OR_LOWER 1
86#endif
87
88/* Specific compiler features */
89#if !COMPILER(CLANG) && _MSC_VER >= 1600
90#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR 1
91#endif
92
93#if !COMPILER(CLANG)
94#define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL 1
95#define WTF_COMPILER_QUIRK_FINAL_IS_CALLED_SEALED 1
96#endif
97
98#endif
99
100/* COMPILER(RVCT) - ARM RealView Compilation Tools */
101#if defined(__CC_ARM) || defined(__ARMCC__)
102#define WTF_COMPILER_RVCT 1
103#define RVCT_VERSION_AT_LEAST(major, minor, patch, build) (__ARMCC_VERSION >= (major * 100000 + minor * 10000 + patch * 1000 + build))
104#else
105/* Define this for !RVCT compilers, just so we can write things like RVCT_VERSION_AT_LEAST(3, 0, 0, 0). */
106#define RVCT_VERSION_AT_LEAST(major, minor, patch, build) 0
107#endif
108
109/* COMPILER(GCCE) - GNU Compiler Collection for Embedded */
110#if defined(__GCCE__)
111#define WTF_COMPILER_GCCE 1
112#define GCCE_VERSION (__GCCE__ * 10000 + __GCCE_MINOR__ * 100 + __GCCE_PATCHLEVEL__)
113#define GCCE_VERSION_AT_LEAST(major, minor, patch) (GCCE_VERSION >= (major * 10000 + minor * 100 + patch))
114#endif
115
116/* COMPILER(GHS) - Green Hills MULTI Compiler */
117#if defined(__ghs)
118#define WTF_COMPILER_GHS 1
119#endif
120
121/* COMPILER(GCC) - GNU Compiler Collection */
122/* --gnu option of the RVCT compiler also defines __GNUC__ */
123#if defined(__GNUC__) && !COMPILER(RVCT)
124#define WTF_COMPILER_GCC 1
125#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
126#define GCC_VERSION_AT_LEAST(major, minor, patch) (GCC_VERSION >= (major * 10000 + minor * 100 + patch))
127#else
128/* Define this for !GCC compilers, just so we can write things like GCC_VERSION_AT_LEAST(4, 1, 0). */
129#define GCC_VERSION_AT_LEAST(major, minor, patch) 0
130#endif
131
132/* Specific compiler features */
133#if COMPILER(GCC) && !COMPILER(CLANG)
134#if GCC_VERSION_AT_LEAST(4, 8, 0)
135#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
136#endif
137#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
138/* C11 support */
139#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT 1
140#endif
141#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(__cplusplus) && __cplusplus >= 201103L)
142/* C++11 support */
143#if GCC_VERSION_AT_LEAST(4, 3, 0)
144#define WTF_COMPILER_SUPPORTS_CXX_RVALUE_REFERENCES 1
145#define WTF_COMPILER_SUPPORTS_CXX_STATIC_ASSERT 1
146#define WTF_COMPILER_SUPPORTS_CXX_VARIADIC_TEMPLATES 1
147#endif
148#if GCC_VERSION_AT_LEAST(4, 4, 0)
149#define WTF_COMPILER_SUPPORTS_CXX_DELETED_FUNCTIONS 1
150#endif
151#if GCC_VERSION_AT_LEAST(4, 5, 0)
152#define WTF_COMPILER_SUPPORTS_CXX_EXPLICIT_CONVERSIONS 1
153#endif
154#if GCC_VERSION_AT_LEAST(4, 6, 0)
155#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR 1
156/* Strong enums should work from gcc 4.4, but doesn't seem to support some operators */
157#define WTF_COMPILER_SUPPORTS_CXX_STRONG_ENUMS 1
158#endif
159#if GCC_VERSION_AT_LEAST(4, 7, 0)
160#define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL 1
161#endif
162#endif /* defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(__cplusplus) && __cplusplus >= 201103L) */
163#endif /* COMPILER(GCC) */
164
165/* COMPILER(MINGW) - MinGW GCC */
166/* COMPILER(MINGW64) - mingw-w64 GCC - only used as additional check to exclude mingw.org specific functions */
167#if defined(__MINGW32__)
168#define WTF_COMPILER_MINGW 1
169#include <_mingw.h> /* private MinGW header */
170 #if defined(__MINGW64_VERSION_MAJOR) /* best way to check for mingw-w64 vs mingw.org */
171 #define WTF_COMPILER_MINGW64 1
172 #endif /* __MINGW64_VERSION_MAJOR */
173#endif /* __MINGW32__ */
174
175/* COMPILER(INTEL) - Intel C++ Compiler */
176#if defined(__INTEL_COMPILER)
177#define WTF_COMPILER_INTEL 1
178#endif
179
180/* COMPILER(SUNCC) */
181#if defined(__SUNPRO_CC) || defined(__SUNPRO_C)
182#define WTF_COMPILER_SUNCC 1
183#endif
184
185/* ==== Compiler features ==== */
186
187
188/* ALWAYS_INLINE */
189
190#ifndef ALWAYS_INLINE
191#if COMPILER(GCC) && defined(NDEBUG) && !COMPILER(MINGW)
192#define ALWAYS_INLINE inline __attribute__((__always_inline__))
193#elif (COMPILER(MSVC) || COMPILER(RVCT)) && defined(NDEBUG)
194#define ALWAYS_INLINE __forceinline
195#else
196#define ALWAYS_INLINE inline
197#endif
198#endif
199
200
201/* NEVER_INLINE */
202
203#ifndef NEVER_INLINE
204#if COMPILER(GCC)
205#define NEVER_INLINE __attribute__((__noinline__))
206#elif COMPILER(RVCT)
207#define NEVER_INLINE __declspec(noinline)
208#else
209#define NEVER_INLINE
210#endif
211#endif
212
213
214/* UNLIKELY */
215
216#ifndef UNLIKELY
217#if COMPILER(GCC) || (COMPILER(RVCT) && defined(__GNUC__))
218#define UNLIKELY(x) __builtin_expect((x), 0)
219#else
220#define UNLIKELY(x) (x)
221#endif
222#endif
223
224
225/* LIKELY */
226
227#ifndef LIKELY
228#if COMPILER(GCC) || (COMPILER(RVCT) && defined(__GNUC__))
229#define LIKELY(x) __builtin_expect((x), 1)
230#else
231#define LIKELY(x) (x)
232#endif
233#endif
234
235
236/* NO_RETURN */
237
238
239#ifndef NO_RETURN
240#if COMPILER(GCC)
241#define NO_RETURN __attribute((__noreturn__))
242#elif COMPILER(MSVC) || COMPILER(RVCT)
243#define NO_RETURN __declspec(noreturn)
244#else
245#define NO_RETURN
246#endif
247#endif
248
249
250/* NO_RETURN_WITH_VALUE */
251
252#ifndef NO_RETURN_WITH_VALUE
253#if !COMPILER(MSVC)
254#define NO_RETURN_WITH_VALUE NO_RETURN
255#else
256#define NO_RETURN_WITH_VALUE
257#endif
258#endif
259
260
261/* WARN_UNUSED_RETURN */
262
263#if COMPILER(GCC)
264#define WARN_UNUSED_RETURN __attribute__ ((warn_unused_result))
265#else
266#define WARN_UNUSED_RETURN
267#endif
268
269/* OVERRIDE and FINAL */
270
271#if COMPILER_SUPPORTS(CXX_OVERRIDE_CONTROL)
272#define OVERRIDE override
273
274#if COMPILER_QUIRK(FINAL_IS_CALLED_SEALED)
275#define FINAL sealed
276#else
277#define FINAL final
278#endif
279
280#else
281#define OVERRIDE
282#define FINAL
283#endif
284
285/* REFERENCED_FROM_ASM */
286
287#ifndef REFERENCED_FROM_ASM
288#if COMPILER(GCC)
289#define REFERENCED_FROM_ASM __attribute__((used))
290#else
291#define REFERENCED_FROM_ASM
292#endif
293#endif
294
295/* OBJC_CLASS */
296
297#ifndef OBJC_CLASS
298#ifdef __OBJC__
299#define OBJC_CLASS @class
300#else
301#define OBJC_CLASS class
302#endif
303#endif
304
305/* ABI */
306#if defined(__ARM_EABI__) || defined(__EABI__)
307#define WTF_COMPILER_SUPPORTS_EABI 1
308#endif
309
310#endif /* WTF_Compiler_h */
311

source code of qtdeclarative/src/3rdparty/masm/wtf/Compiler.h