aboutsummaryrefslogtreecommitdiffstats
path: root/longbow/src/LongBow/longBow_Compiler.h
blob: 197e1e8c015062bd76136c12968825cb71988188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file longBow_Compiler.h
 * @ingroup compiling
 * @brief LongBow compile time functionality.
 *
 */
#ifndef LongBow_compiling_h
#define LongBow_compiling_h

/**
 * @def LONGBOW_GNUC_EXACTLY
 *
 * Compile-time test to determine if the compiler is the GNU C compiler with the specfied
 * version, revision and patch levels.
 *
 * @param [in] major The required major version number of the compiler.
 * @param [in] minor The required minor version number of the compiler.
 * @param [in] patch The required patch number of the compiler.
 *
 * @return true If the current compiler matches the requirements.
 *
 * Example:
 * @code
 * #if LONGBOW_GNUC_EXACTLY(4,2,1)
 *   printf("Hello GNU compiler 4.2.1\n");
 * #endif
 * @endcode
 *
 * @see LONGBOW_GNUC_ATLEAST
 */
#ifdef __GNUC__
#  define LONGBOW_GNUC_EXACTLY(major, minor, patch) \
    (__GNUC__ == major) && (__GNUC_MINOR__ = minor) && (__GNUC_PATCHLEVEL__ == patch)
#else
#  define LONGBOW_GNUC_EXACTLY(major, minor, patch) \
    (0)
#endif

/**
 * @def LONGBOW_GNUC_ATLEAST
 *
 * Compile-time test to determine if the compiler is the GNU C compiler with at least the specfied
 * version, revision and patch levels.
 *
 * @param [in] major The minimum required major version number of the compiler.
 * @param [in] minor The minimum required minor version number of the compiler.
 * @param [in] patch The minimum required patch number of the compiler.
 *
 * @return true If the current compiler matches the requirements.
 * @return false If the current compiler fails to match the requirements.
 *
 * Example:
 * @code
 * #if LONGBOW_GNUC_ATLEAST(4,0,0)
 *   printf("Hello GNU compiler 4.x\n");
 * #endif
 * @endcode
 *
 * @see LONGBOW_GNUC_EXACTLY
 */
#ifdef __GNUC__
#  define LONGBOW_GNUC_ATLEAST(major, minor, patch) \
    (__GNUC__ >= major) && (__GNUC_MINOR__ > minor) && (__GNUC_PATCHLEVEL__ >= patch)
#else
#  define LONGBOW_GNUC_ATLEAST(major, minor, patch) \
    (0)
#endif

/**
 * @def LONGBOW_CLANG_EXACTLY
 *
 * Compile-time test to determine if the compiler is the Clang C compiler with the specfied
 * version, revision and patch levels.
 *
 * @param [in] major The required major version number of the compiler.
 * @param [in] minor The required minor version number of the compiler.
 * @param [in] patch The required patch number of the compiler.
 *
 * @return true If the current compiler matches the requirements.
 *
 * Example:
 * @code
 * #if LONGBOW_CLANG_EXACTLY(5,0,0)
 *   printf("Hello Clang 5.0.0\n");
 * #endif
 * @endcode
 *
 * @see LONGBOW_CLANG_ATLEAST
 */
#ifdef __clang__
#  define LONGBOW_CLANG_EXACTLY(major, minor, patch) \
    (__clang_major__ == major) && (__clang_major__ = minor) && (__clang_patchlevel__ == patch)
#else
#  define LONGBOW_CLANG_EXACTLY(major, minor, patch) \
    (0)
#endif

/**
 * @def LONGBOW_CLANG_ATLEAST
 *
 * Compile-time test to determine if the compiler is the GNU C compiler with at least the specfied
 * version, revision and patch levels.
 *
 * @param [in] major The minimum required major version number of the compiler.
 * @param [in] minor The minimum required minor version number of the compiler.
 * @param [in] patch The minimum required patch number of the compiler.
 *
 * @return true If the current compiler matches the requirements.
 * @return false If the current compiler fails to match the requirements.
 *
 * Example:
 * @code
 * #if LONGBOW_CLANG_ATLEAST(5,0,0)
 *   printf("Hello Clang compiler 5.x\n");
 * #endif
 * @endcode
 *
 * @see LONGBOW_CLANG_EXACTLY
 */
#ifdef __clang__
#  define LONGBOW_CLANG_ATLEAST(major, minor, patch) \
    (__clang_major__ >= major) && (__clang_major__ > minor) && (__clang_patchlevel__ >= patch)
#else
#  define LONGBOW_CLANG_ATLEAST(major, minor, patch) \
    (0)
#endif

/**
 * @def LONGBOW_START_DEPRECATED_WARNINGS
 *
 * Compile-time preprocessing to signal the compiler to not report the use of deprecated functions.
 *
 * Example:
 * @code
 * LONGBOW_STOP_DEPRECATED_WARNINGS
 *  someDeprecatedFunction();
 * @endcode
 *
 * @see LONBOW_STOP_DEPRECATED_WARNINGS
 */

/**
 * @def LONGBOW_STOP_DEPRECATED_WARNINGS
 *
 * Compile-time preprocessing to signal the compiler to report the use of deprecated functions.
 *
 * Example:
 * @code
 * LONGBOW_STOP_DEPRECATED_WARNINGS
 *  someDeprecatedFunction();
 * @endcode
 *
 * @see LONBOW_START_DEPRECATED_WARNINGS
 */
#if LONGBOW_CLANG_ATLEAST(5, 0, 0) || LONGBOW_GNUC_ATLEAST(4, 6, 0)
#  define LONGBOW_STOP_DEPRECATED_WARNINGS \
    _Pragma("GCC diagnostic push") \
    _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")

#  define LONGBOW_START_DEPRECATED_WARNINGS \
    _Pragma("GCC diagnostic pop")

#elif __clang__ || __GNUC__

#  define LONGBOW_STOP_DEPRECATED_WARNINGS \
    _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")

#  define LONGBOW_START_DEPRECATED_WARNINGS \
    _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")

#else

#  define LONGBOW_STOP_DEPRECATED_WARNINGS /* nothing */

#  define LONGBOW_START_DEPRECATED_WARNINGS /* nothing */
#endif

/**
 * @def LongBowCompiler_IgnoreInitializerOverrides
 *
 * Compile-time preprocessing to signal the compiler to not report the use of structure initializer overrides.
 *
 * Example:
 * @code
 * LongBowCompiler_IgnoreInitializerOverrides
 *  struct foo {
 *     int a;
 *  } instance = {
 *      .a = 1,
 *      .a = 1
 *  };
 * LongBowCompiler_WarnInitializerOverrides
 * @endcode
 *
 * @see LongBowCompiler_WarnInitializerOverrides
 */
#if LONGBOW_CLANG_ATLEAST(5, 0, 0)
#  define LongBowCompiler_IgnoreInitializerOverrides \
    _Pragma("GCC diagnostic push") \
    _Pragma("GCC diagnostic ignored \"-Winitializer-overrides\"")

#  define LongBowCompiler_WarnInitializerOverrides \
    _Pragma("GCC diagnostic pop")

#elif LONGBOW_GNUC_ATLEAST(4, 6, 0)
#  define LongBowCompiler_IgnoreInitializerOverrides \
    _Pragma("GCC diagnostic push") \
    _Pragma("GCC diagnostic ignored \"-Woverride-init\"")

#  define LongBowCompiler_WarnInitializerOverrides  \
    _Pragma("GCC diagnostic pop")

#elif __clang__ || __GNUC__
#  define LongBowCompiler_IgnoreInitializerOverrides \
    _Pragma("GCC diagnostic ignored \"-Woverride-init\"")

#  define LongBowCompiler_WarnInitializerOverrides \
    _Pragma("GCC diagnostic warning \"-Woverride-init\"")

#else

#  define LongBowCompiler_IgnoreInitializerOverrides /* nothing */

#  define LongBowCompiler_WarnInitializerOverrides /* nothing */
#endif

/**
 * @def LONGBOW_STOPWARNINGS_UnusedVariable
 *
 * Compile-time preprocessing to signal the compiler to report unused variables.
 *
 * Example:
 * @code
 * LONGBOW_STOPWARNINGS_UnusedVariable
 * void
 * foo(int unusedVariable)
 * {
 *    return;
 * }
 * LONGBOW_STARTWARNINGS_UnusedVariable
 * @endcode
 *
 * @see LONGBOW_STARTWARNINGS_UnusedVariable
 *
 * @def LONGBOW_STARTWARNINGS_UnusedVariable
 *
 * Compile-time preprocessing to signal the compiler to report unused variables.
 *
 * Example:
 * @code
 * LONGBOW_STOPWARNINGS_UnusedVariable
 * void
 * foo(int unusedVariable)
 * {
 *    return;
 * }
 * LONGBOW_STARTWARNINGS_UnusedVariable
 * @endcode
 *
 * @see LONGBOW_STARTWARNINGS_UnusedVariable
 */
#if LONGBOW_CLANG_ATLEAST(5, 0, 0)
#  define LONGBOW_STOPWARNINGS_UnusedVariable \
    _Pragma("GCC diagnostic push") \
    _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
#  define LONGBOW_STARTWARNINGS_UnusedVariable \
    _Pragma("GCC diagnostic pop")
#elif LONGBOW_GNUC_ATLEAST(4, 6, 0)
#  define LONGBOW_STOPWARNINGS_UnusedVariable \
    _Pragma("GCC diagnostic push") \
    _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
#  define LONGBOW_STARTWARNINGS_UnusedVariable  \
    _Pragma("GCC diagnostic pop")
#elif __clang__ || __GNUC__
#  define LONGBOW_STOPWARNINGS_UnusedVariable \
    _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
#  define LONGBOW_STARTWARNINGS_UnusedVariable \
    _Pragma("GCC diagnostic warning \"-Wunused-variable\"")
#else

#  define LONGBOW_STOPWARNINGS_UnusedVariable /* nothing */

#  define LONGBOW_STARTWARNINGS_UnusedVariable /* nothing */
#endif


#endif // LongBow_compiling_h