Library of Assembled Shared Sources
common_macros.h
Go to the documentation of this file.
1
/** @file
2
* @author Bram de Greve (bram@cocamware.com)
3
* @author Tom De Muer (tom@cocamware.com)
4
*
5
* *** BEGIN LICENSE INFORMATION ***
6
*
7
* The contents of this file are subject to the Common Public Attribution License
8
* Version 1.0 (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
10
* http://lass.sourceforge.net/cpal-license. The License is based on the
11
* Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12
* use of software over a computer network and provide for limited attribution for
13
* the Original Developer. In addition, Exhibit A has been modified to be consistent
14
* with Exhibit B.
15
*
16
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18
* language governing rights and limitations under the License.
19
*
20
* The Original Code is LASS - Library of Assembled Shared Sources.
21
*
22
* The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23
* The Original Developer is the Initial Developer.
24
*
25
* All portions of the code written by the Initial Developer are:
26
* Copyright (C) 2004-2022 the Initial Developer.
27
* All Rights Reserved.
28
*
29
* Contributor(s):
30
*
31
* Alternatively, the contents of this file may be used under the terms of the
32
* GNU General Public License Version 2 or later (the GPL), in which case the
33
* provisions of GPL are applicable instead of those above. If you wish to allow use
34
* of your version of this file only under the terms of the GPL and not to allow
35
* others to use your version of this file under the CPAL, indicate your decision by
36
* deleting the provisions above and replace them with the notice and other
37
* provisions required by the GPL License. If you do not delete the provisions above,
38
* a recipient may use your version of this file under either the CPAL or the GPL.
39
*
40
* *** END LICENSE INFORMATION ***
41
*/
42
43
44
/** @defgroup CommonMacros Common Macros
45
* @author Bramz
46
* @brief usefull macros to use all over the place.
47
*/
48
49
50
51
#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_MACRO_H
52
#define LASS_GUARDIAN_OF_INCLUSION_UTIL_MACRO_H
53
54
55
#define LASS_WRAP(x) x
56
57
// first of all, the usual stuff on stringifying, concatenating and breakpoint preprocessor stuff.
58
59
/** convert to string at preprocessor time.
60
* @ingroup CommonMacros
61
*/
62
#define LASS_STRINGIFY(iA) LASS_STRINGIFY_IMPL(iA)
63
#define LASS_STRINGIFY_IMPL(iA) #iA
64
65
/** concatenate two words at preprocessor time.
66
* @ingroup CommonMacros
67
*/
68
#define LASS_CONCATENATE( iA, iB ) LASS_CONCATENATE_IMPL(iA, iB)
69
#define LASS_CONCATENATE_IMPL( iA, iB ) iA##iB
70
71
/** concatenate three words at preprocessor time.
72
* @ingroup CommonMacros
73
*/
74
#define LASS_CONCATENATE_3( iA, iB, iC ) LASS_CONCATENATE_3_IMPL(iA, iB, iC)
75
#define LASS_CONCATENATE_3_IMPL( iA, iB, iC ) iA##iB##iC
76
77
/** user breakpoint
78
* @ingroup CommonMacros
79
*/
80
#if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_MSVC
81
# define LASS_BREAK_HERE __debugbreak();
82
#elif LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_SUNPRO
83
# define LASS_BREAK_HERE
84
#else
85
# if defined(LASS_PROCESSOR_ARCHITECTURE_x86)
86
# define LASS_BREAK_HERE __asm__("int $3");
87
# elif defined(LASS_PROCESSOR_ARCHITECTURE_ARM)
88
# ifdef __thumb__
89
# define LASS_BREAK_HERE __asm__(".inst.w 0xe7f001f0");
90
# else
91
# define LASS_BREAK_HERE __asm__(".inst 0xe7f001f0");
92
# endif
93
# elif defined(LASS_PROCESSOR_ARCHITECTURE_ARM64)
94
# define LASS_BREAK_HERE __asm__(".inst 0xd4200000");
95
# else
96
# define LASS_BREAK_HERE
97
# endif
98
#endif
99
100
/** create a unique name based on a prefix and line number
101
* @ingroup CommonMacros
102
*/
103
#define LASS_UNIQUENAME( iPrefix ) LASS_CONCATENATE(iPrefix,LASS_LINE)
104
105
106
107
// second, the name of the game, where we are.
108
109
/** current file
110
* @ingroup CommonMacros
111
*/
112
#define LASS_FILE __FILE__
113
114
/** current line (stringified!)
115
* @ingroup CommonMacros
116
*/
117
#define LASS_LINE __LINE__
118
119
#define LASS_HERE LASS_FILE "(" LASS_STRINGIFY(LASS_LINE) ")"
120
121
/** current function
122
* @ingroup CommonMacros
123
*/
124
#ifdef __FUNCTION__
125
# define LASS_FUNCTION __FUNCTION__
126
# define LASS_PRETTY_FUNCTION LASS_FUNCTION
127
#else
128
# define LASS_FUNCTION "??"
129
# define LASS_PRETTY_FUNCTION LASS_HERE
130
#endif
131
132
133
134
135
// debug jumbo jambo
136
137
#include "
common_macros.inl
"
138
139
#if !defined(NDEBUG)
140
# define LASS_ASSERT( iExpression ) LASS_ASSERT_IMPL( iExpression )
141
# define LASS_ASSERT_UNREACHABLE LASS_ASSERT_UNREACHABLE_IMPL
142
# define LASS_WARNING( iMessage ) LASS_WARNING_IMPL( iMessage )
143
# define LASS_WARNING_ONCE_EX( iMessage, iUniqueName ) LASS_WARNING_ONCE_IMPL( iMessage, LASS_UNIQUENAME(iUniqueName) )
144
# define LASS_WARNING_ONCE( iMessage ) LASS_WARNING_ONCE_EX( iMessage, lassWarnOnce )
145
# define LASS_EVAL( iExpression ) LASS_EVAL_IMPL( iExpression )
146
# define LASS_LOG( iMessage ) LASS_LOG_IMPL( iMessage )
147
#else
148
# define LASS_ASSERT( iExpression )
149
# define LASS_ASSERT_UNREACHABLE
150
# define LASS_WARNING( iMessage ) LASS_WARNING_IMPL( iMessage )
151
# define LASS_WARNING_ONCE_EX( iMessage, iUniqueName ) LASS_WARNING_ONCE_IMPL( iMessage, LASS_UNIQUENAME(iUniqueName) )
152
# define LASS_WARNING_ONCE( iMessage ) LASS_WARNING_ONCE_EX( iMessage, lassWarnOnce )
153
# define LASS_EVAL( iExpression ) LASS_EVAL_IMPL( iExpression )
154
# define LASS_LOG( iMessage ) LASS_LOG_IMPL( iMessage )
155
#endif
156
157
158
// now some pragma's you can use to leave messages behind
159
160
/** pragma for leaving notes in build window
161
* @ingroup CommonMacros
162
*/
163
#define LASS_NOTE( iMessage )\
164
message(LASS_FILE "(" LASS_STRINGIFY(LASS_LINE) "):\n[LASS BUILD MSG] " iMessage)
165
166
167
/** pragma for leaving todo notes in build window
168
* @ingroup CommonMacros
169
*/
170
#define LASS_TODO( iMessage )\
171
message(LASS_FILE "(" LASS_STRINGIFY(LASS_LINE) "):\n[LASS BUILD MSG] *** TODO: " iMessage " ***")
172
173
/** pragma for leaving fixme notes in build window
174
* @ingroup CommonMacros
175
*/
176
#define LASS_FIXME( iMessage )\
177
message(LASS_FILE "(" LASS_STRINGIFY(LASS_LINE) "):\n[LASS BUILD MSG] *** FIXME: " iMessage " ***")
178
179
180
// some other usefull macros
181
182
/** @def LASS_UNUSED
183
* tell the compiler that some variable may stay unused.
184
* @ingroup CommonMacros
185
* Some compilers throw warnings at us if a variable stays unused.
186
* Often this is a good thing, but sometimes that's exactly what we want.
187
* This macro will attempt to avoid the warning (as long as the
188
* compiler suports such an attempt).
189
*
190
* @code
191
* int LASS_UNUSED(foobar) = 0;
192
* @endcode
193
*/
194
#if (LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_GCC) || (LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_CLANG)
195
# define LASS_UNUSED(x) x __attribute__((__unused__))
196
#else
197
# define LASS_UNUSED(x) x
198
#endif
199
200
201
202
/** Executes code before the main has actually begun. The macro relies on line numbers, so
203
* only one LASS_EXECUTE_BEFORE_MAIN per line!
204
* @ingroup CommonMacros
205
*/
206
#define LASS_EXECUTE_BEFORE_MAIN( x ) LASS_EXECUTE_BEFORE_MAIN_EX(lassDummyName, x)
207
208
/** Same as LASS_EXECUTE_BEFORE_MAIN but with an additional parameter that let's you specify the
209
* used prefix. Mmmh, let's use this as implementation of LASS_EXECUTE_BEFORE_MAIN :)
210
* @ingroup CommonMacros
211
*/
212
#define LASS_EXECUTE_BEFORE_MAIN_EX( iPrefix, x ) \
213
namespace \
214
{ \
215
inline bool LASS_CONCATENATE( LASS_UNIQUENAME(iPrefix),func ) () \
216
{ \
217
x \
218
return true; \
219
} \
220
const bool LASS_UNUSED(LASS_CONCATENATE( LASS_UNIQUENAME(iPrefix),var )) = \
221
LASS_CONCATENATE( LASS_UNIQUENAME(iPrefix),func ) (); \
222
}
223
224
225
#define LASS_DEPRECATED(reason) [[deprecated(reason)]]
226
227
228
#endif
common_macros.inl
lass
util
common_macros.h
Generated by
1.13.2