1 | // ==================================================================== // |
---|
2 | // // |
---|
3 | // File : attributes.h // |
---|
4 | // Purpose : declare attribute macros // |
---|
5 | // // |
---|
6 | // // |
---|
7 | // Coded by Ralf Westram (coder@reallysoft.de) in June 2005 // |
---|
8 | // Copyright Department of Microbiology (Technical University Munich) // |
---|
9 | // // |
---|
10 | // Visit our web site at: http://www.arb-home.de/ // |
---|
11 | // // |
---|
12 | // ==================================================================== // |
---|
13 | #ifndef ATTRIBUTES_H |
---|
14 | #define ATTRIBUTES_H |
---|
15 | |
---|
16 | // ------------------------------------------------------------ |
---|
17 | // short description of attributes defined: |
---|
18 | // |
---|
19 | // __ATTR__FORMAT(p) used for printf-like functions. 'p' is the position of the format string, args follow directly |
---|
20 | // __ATTR__VFORMAT(p) used for vprintf-like functions. 'p' is the position of the format string, args are NOT checked |
---|
21 | // __ATTR__SENTINEL used for function that expect a parameter list terminated by NULL |
---|
22 | // __ATTR__NORETURN used for functions which do NEVER return |
---|
23 | // __ATTR__DEPRECATED used for deprecated functions (useful for redesign) |
---|
24 | // __ATTR__PURE used for functions w/o side-effects, where result only depends on parameters + global data |
---|
25 | // __ATTR__CONST same as __ATTR__PURE, but w/o global-data-access |
---|
26 | // __ATTR__USERESULT warn if result of function is unused |
---|
27 | // |
---|
28 | // __ATTR__FORMAT_MEMBER(p) same as __ATTR__FORMAT for member functions |
---|
29 | // __ATTR__VFORMAT_MEMBER(p) same as __ATTR__VFORMAT for member functions |
---|
30 | // |
---|
31 | // ------------------------------------------------------------ |
---|
32 | |
---|
33 | #ifndef __GNUC__ |
---|
34 | # error You have to use the gnu compiler! |
---|
35 | #endif |
---|
36 | |
---|
37 | #if (__GNUC__ < 4) |
---|
38 | #else |
---|
39 | # if (__GNUC__ > 4) |
---|
40 | # define COMPILER_OK |
---|
41 | # else |
---|
42 | // gcc 4.xx: |
---|
43 | # ifdef __clang__ |
---|
44 | # if (__GNUC_MINOR__ >= 2) |
---|
45 | # define COMPILER_OK |
---|
46 | # endif |
---|
47 | # else |
---|
48 | # if (__GNUC_MINOR__ >= 3) |
---|
49 | # define COMPILER_OK |
---|
50 | # endif |
---|
51 | # endif |
---|
52 | # endif |
---|
53 | #endif |
---|
54 | |
---|
55 | #ifndef COMPILER_OK |
---|
56 | # error Wrong compiler version (need at least gcc 4.3 or clang 4.2) |
---|
57 | #endif |
---|
58 | |
---|
59 | |
---|
60 | #if (__GNUC_MINOR__ > 5 || (__GNUC_MINOR__ == 5 && __GNUC_PATCHLEVEL__ >= 2)) // gcc 4.5.2 and higher |
---|
61 | # define __ATTR__DEPRECATED(reason) __attribute__((deprecated(reason))) |
---|
62 | #endif |
---|
63 | |
---|
64 | // ------------------------------------------------------------ |
---|
65 | // helper macro to declare attributes for function-pointers |
---|
66 | |
---|
67 | #define FUNCTION_TYPE_ATTR(x) x |
---|
68 | |
---|
69 | // ------------------------------------------------------------ |
---|
70 | // valid for any gcc above 4.3 |
---|
71 | |
---|
72 | #ifndef __ATTR__DEPRECATED |
---|
73 | # define __ATTR__DEPRECATED(reason) __attribute__((deprecated)) |
---|
74 | #endif |
---|
75 | #define __ATTR__DEPRECATED_FUNCTION __attribute__((deprecated)) // function attributes sometimes cant handle reason (e.g. ctors) |
---|
76 | |
---|
77 | #define __ATTR__PURE __attribute__((pure)) |
---|
78 | #define __ATTR__CONST __attribute__((const)) |
---|
79 | #define __ATTR__NORETURN __attribute__((noreturn)) |
---|
80 | #define __ATTR__SENTINEL __attribute__((sentinel)) |
---|
81 | #define __ATTR__USERESULT __attribute__((warn_unused_result)) |
---|
82 | |
---|
83 | #define __ATTR__FORMAT(pos) __attribute__((format(__printf__, pos, (pos)+1))) |
---|
84 | #define __ATTR__VFORMAT(pos) __attribute__((format(__printf__, pos, 0))) |
---|
85 | #define __ATTR__FORMAT_MEMBER(pos) __attribute__((format(__printf__, (pos)+1, (pos)+2))) |
---|
86 | #define __ATTR__VFORMAT_MEMBER(pos) __attribute__((format(__printf__, (pos)+1, 0))) |
---|
87 | // when used for member functions, start with pos+1 (pos = 1 seems to be the this-pointer!?) |
---|
88 | |
---|
89 | // ------------------------------------------------------------ |
---|
90 | // temporary disable |
---|
91 | |
---|
92 | // #undef __ATTR__DEPRECATED |
---|
93 | // #undef __ATTR__USERESULT |
---|
94 | // #undef __ATTR__SENTINEL |
---|
95 | |
---|
96 | // ------------------------------------------------------------ |
---|
97 | // now define undefined attributes empty : |
---|
98 | |
---|
99 | #ifndef __ATTR__SENTINEL |
---|
100 | # define __ATTR__SENTINEL |
---|
101 | #endif |
---|
102 | #ifndef __ATTR__USERESULT |
---|
103 | # define __ATTR__USERESULT |
---|
104 | #endif |
---|
105 | #ifndef __ATTR__DEPRECATED |
---|
106 | # define __ATTR__DEPRECATED(reason) |
---|
107 | #endif |
---|
108 | |
---|
109 | // ------------------------------------------------------------ |
---|
110 | // quickly disable attributes |
---|
111 | |
---|
112 | #if defined(WARN_TODO) |
---|
113 | #define __ATTR__USERESULT_TODO __ATTR__USERESULT |
---|
114 | #define __ATTR__DEPRECATED_TODO(reason) __ATTR__DEPRECATED(reason) |
---|
115 | #define __ATTR__DEPRECATED_FUNCTION_TODO __ATTR__DEPRECATED_FUNCTION |
---|
116 | #else |
---|
117 | #define __ATTR__USERESULT_TODO |
---|
118 | #define __ATTR__DEPRECATED_TODO(reason) |
---|
119 | #define __ATTR__DEPRECATED_FUNCTION_TODO |
---|
120 | #endif |
---|
121 | |
---|
122 | // ------------------------------------------------------------ |
---|
123 | // casting result to void does not help when a function is |
---|
124 | // declared with __ATTR__USERESULT. Use |
---|
125 | |
---|
126 | #ifdef __cplusplus |
---|
127 | template <typename T> void IGNORE_RESULT(const T&) {} |
---|
128 | #endif |
---|
129 | |
---|
130 | // ------------------------------------------------------------ |
---|
131 | // helper macros to declare attributed function prototype and |
---|
132 | // start function definition in one line (static or inline functions only) |
---|
133 | // (change also at ../AISC_MKPTPS/mkptypes.cxx@specialHandling_ATTRIBUTED) |
---|
134 | #define STATIC_ATTRIBUTED(attribute, proto) static proto attribute; static proto |
---|
135 | #define INLINE_ATTRIBUTED(attribute, proto) inline proto attribute; inline proto |
---|
136 | |
---|
137 | #else |
---|
138 | #error attributes.h included twice |
---|
139 | #endif // ATTRIBUTES_H |
---|
140 | |
---|