~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WTF/wtf/Compiler.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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) (defined WTF_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) (defined WTF_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) (defined WTF_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_OVERRIDE_CONTROL __has_extension(cxx_override_control)
 
64
#define WTF_COMPILER_SUPPORTS_HAS_TRIVIAL_DESTRUCTOR __has_extension(has_trivial_destructor)
 
65
 
 
66
#endif
 
67
 
 
68
#ifndef CLANG_PRAGMA
 
69
#define CLANG_PRAGMA(PRAGMA)
 
70
#endif
 
71
 
 
72
/* COMPILER(MSVC) - Microsoft Visual C++ */
 
73
/* COMPILER(MSVC7_OR_LOWER) - Microsoft Visual C++ 2003 or lower*/
 
74
/* COMPILER(MSVC9_OR_LOWER) - Microsoft Visual C++ 2008 or lower*/
 
75
#if defined(_MSC_VER)
 
76
#define WTF_COMPILER_MSVC 1
 
77
#if _MSC_VER < 1400
 
78
#define WTF_COMPILER_MSVC7_OR_LOWER 1
 
79
#elif _MSC_VER < 1600
 
80
#define WTF_COMPILER_MSVC9_OR_LOWER 1
 
81
#endif
 
82
 
 
83
/* Specific compiler features */
 
84
#if !COMPILER(CLANG) && _MSC_VER >= 1600
 
85
#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR 1
 
86
#endif
 
87
 
 
88
#if !COMPILER(CLANG)
 
89
#define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL 1
 
90
#define WTF_COMPILER_QUIRK_FINAL_IS_CALLED_SEALED 1
 
91
#endif
 
92
 
 
93
#endif
 
94
 
 
95
/* COMPILER(RVCT) - ARM RealView Compilation Tools */
 
96
/* COMPILER(RVCT4_OR_GREATER) - ARM RealView Compilation Tools 4.0 or greater */
 
97
#if defined(__CC_ARM) || defined(__ARMCC__)
 
98
#define WTF_COMPILER_RVCT 1
 
99
#define RVCT_VERSION_AT_LEAST(major, minor, patch, build) (__ARMCC_VERSION >= (major * 100000 + minor * 10000 + patch * 1000 + build))
 
100
#else
 
101
/* Define this for !RVCT compilers, just so we can write things like RVCT_VERSION_AT_LEAST(3, 0, 0, 0). */
 
102
#define RVCT_VERSION_AT_LEAST(major, minor, patch, build) 0
 
103
#endif
 
104
 
 
105
/* COMPILER(GCCE) - GNU Compiler Collection for Embedded */
 
106
#if defined(__GCCE__)
 
107
#define WTF_COMPILER_GCCE 1
 
108
#define GCCE_VERSION (__GCCE__ * 10000 + __GCCE_MINOR__ * 100 + __GCCE_PATCHLEVEL__)
 
109
#define GCCE_VERSION_AT_LEAST(major, minor, patch) (GCCE_VERSION >= (major * 10000 + minor * 100 + patch))
 
110
#endif
 
111
 
 
112
/* COMPILER(GCC) - GNU Compiler Collection */
 
113
/* --gnu option of the RVCT compiler also defines __GNUC__ */
 
114
#if defined(__GNUC__) && !COMPILER(RVCT)
 
115
#define WTF_COMPILER_GCC 1
 
116
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
 
117
#define GCC_VERSION_AT_LEAST(major, minor, patch) (GCC_VERSION >= (major * 10000 + minor * 100 + patch))
 
118
#else
 
119
/* Define this for !GCC compilers, just so we can write things like GCC_VERSION_AT_LEAST(4, 1, 0). */
 
120
#define GCC_VERSION_AT_LEAST(major, minor, patch) 0
 
121
#endif
 
122
 
 
123
/* Specific compiler features */
 
124
#if COMPILER(GCC) && !COMPILER(CLANG)
 
125
#if GCC_VERSION_AT_LEAST(4, 7, 0) && defined(__cplusplus) && __cplusplus >= 201103L
 
126
#define WTF_COMPILER_SUPPORTS_CXX_RVALUE_REFERENCES 1
 
127
#define WTF_COMPILER_SUPPORTS_CXX_DELETED_FUNCTIONS 1
 
128
#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR 1
 
129
#define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL 1
 
130
#define WTF_COMPILER_QUIRK_GCC11_GLOBAL_ISINF_ISNAN 1
 
131
 
 
132
#elif GCC_VERSION_AT_LEAST(4, 6, 0) && defined(__GXX_EXPERIMENTAL_CXX0X__)
 
133
#define WTF_COMPILER_SUPPORTS_CXX_NULLPTR 1 
 
134
#define WTF_COMPILER_QUIRK_GCC11_GLOBAL_ISINF_ISNAN 1
 
135
#endif
 
136
 
 
137
#endif
 
138
 
 
139
/* COMPILER(MINGW) - MinGW GCC */
 
140
/* COMPILER(MINGW64) - mingw-w64 GCC - only used as additional check to exclude mingw.org specific functions */
 
141
#if defined(__MINGW32__)
 
142
#define WTF_COMPILER_MINGW 1
 
143
#include <_mingw.h> /* private MinGW header */
 
144
    #if defined(__MINGW64_VERSION_MAJOR) /* best way to check for mingw-w64 vs mingw.org */
 
145
        #define WTF_COMPILER_MINGW64 1
 
146
    #endif /* __MINGW64_VERSION_MAJOR */
 
147
#endif /* __MINGW32__ */
 
148
 
 
149
/* COMPILER(INTEL) - Intel C++ Compiler */
 
150
#if defined(__INTEL_COMPILER)
 
151
#define WTF_COMPILER_INTEL 1
 
152
#endif
 
153
 
 
154
/* COMPILER(SUNCC) */
 
155
#if defined(__SUNPRO_CC) || defined(__SUNPRO_C)
 
156
#define WTF_COMPILER_SUNCC 1
 
157
#endif
 
158
 
 
159
/* ==== Compiler features ==== */
 
160
 
 
161
 
 
162
/* ALWAYS_INLINE */
 
163
 
 
164
#ifndef ALWAYS_INLINE
 
165
#if COMPILER(GCC) && defined(NDEBUG) && !COMPILER(MINGW)
 
166
#define ALWAYS_INLINE inline __attribute__((__always_inline__))
 
167
#elif (COMPILER(MSVC) || COMPILER(RVCT)) && defined(NDEBUG)
 
168
#define ALWAYS_INLINE __forceinline
 
169
#else
 
170
#define ALWAYS_INLINE inline
 
171
#endif
 
172
#endif
 
173
 
 
174
 
 
175
/* NEVER_INLINE */
 
176
 
 
177
#ifndef NEVER_INLINE
 
178
#if COMPILER(GCC)
 
179
#define NEVER_INLINE __attribute__((__noinline__))
 
180
#elif COMPILER(RVCT)
 
181
#define NEVER_INLINE __declspec(noinline)
 
182
#else
 
183
#define NEVER_INLINE
 
184
#endif
 
185
#endif
 
186
 
 
187
 
 
188
/* UNLIKELY */
 
189
 
 
190
#ifndef UNLIKELY
 
191
#if COMPILER(GCC) || (RVCT_VERSION_AT_LEAST(3, 0, 0, 0) && defined(__GNUC__))
 
192
#define UNLIKELY(x) __builtin_expect((x), 0)
 
193
#else
 
194
#define UNLIKELY(x) (x)
 
195
#endif
 
196
#endif
 
197
 
 
198
 
 
199
/* LIKELY */
 
200
 
 
201
#ifndef LIKELY
 
202
#if COMPILER(GCC) || (RVCT_VERSION_AT_LEAST(3, 0, 0, 0) && defined(__GNUC__))
 
203
#define LIKELY(x) __builtin_expect((x), 1)
 
204
#else
 
205
#define LIKELY(x) (x)
 
206
#endif
 
207
#endif
 
208
 
 
209
 
 
210
/* NO_RETURN */
 
211
 
 
212
 
 
213
#ifndef NO_RETURN
 
214
#if COMPILER(GCC)
 
215
#define NO_RETURN __attribute((__noreturn__))
 
216
#elif COMPILER(MSVC) || COMPILER(RVCT)
 
217
#define NO_RETURN __declspec(noreturn)
 
218
#else
 
219
#define NO_RETURN
 
220
#endif
 
221
#endif
 
222
 
 
223
 
 
224
/* NO_RETURN_WITH_VALUE */
 
225
 
 
226
#ifndef NO_RETURN_WITH_VALUE
 
227
#if !COMPILER(MSVC)
 
228
#define NO_RETURN_WITH_VALUE NO_RETURN
 
229
#else
 
230
#define NO_RETURN_WITH_VALUE
 
231
#endif
 
232
#endif
 
233
 
 
234
 
 
235
/* WARN_UNUSED_RETURN */
 
236
 
 
237
#if COMPILER(GCC)
 
238
#define WARN_UNUSED_RETURN __attribute__ ((warn_unused_result))
 
239
#else
 
240
#define WARN_UNUSED_RETURN
 
241
#endif
 
242
 
 
243
/* OVERRIDE and FINAL */
 
244
 
 
245
#if COMPILER_SUPPORTS(CXX_OVERRIDE_CONTROL)
 
246
#define OVERRIDE override
 
247
 
 
248
#if COMPILER_QUIRK(FINAL_IS_CALLED_SEALED)
 
249
#define FINAL sealed
 
250
#else
 
251
#define FINAL final
 
252
#endif
 
253
 
 
254
#else
 
255
#define OVERRIDE
 
256
#define FINAL
 
257
#endif
 
258
 
 
259
/* REFERENCED_FROM_ASM */
 
260
 
 
261
#ifndef REFERENCED_FROM_ASM
 
262
#if COMPILER(GCC)
 
263
#define REFERENCED_FROM_ASM __attribute__((used))
 
264
#else
 
265
#define REFERENCED_FROM_ASM
 
266
#endif
 
267
#endif
 
268
 
 
269
/* OBJC_CLASS */
 
270
 
 
271
#ifndef OBJC_CLASS
 
272
#ifdef __OBJC__
 
273
#define OBJC_CLASS @class
 
274
#else
 
275
#define OBJC_CLASS class
 
276
#endif
 
277
#endif
 
278
 
 
279
/* ABI */
 
280
#if defined(__ARM_EABI__) || defined(__EABI__)
 
281
#define WTF_COMPILER_SUPPORTS_EABI 1
 
282
#endif
 
283
 
 
284
#endif /* WTF_Compiler_h */