Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
RUNTIME_IN_STD.cpp
Go to the documentation of this file.
1// checking for runtime support in namespace std
2
3
25#include "config.h"
26
27#include <stdio.h>
28
29
30#ifndef _RWSTD_NO_HONOR_STD
31# define STD_NAME(name) name
32#else // if defined (_RWSTD_NO_HONOR_STD)
33# define STD_NAME(ignore) ""
34#endif // _RWSTD_NO_HONOR_STD
35
36const char* const std_defs[] = {
37
38 // avoid false positives if namespace std is not honored
39
40#ifdef _RWSTD_NO_STD_BAD_ALLOC
41 STD_NAME ("BAD_ALLOC"),
42#else
43 "",
44#endif // _RWSTD_NO_STD_BAD_ALLOC
45
46#ifdef _RWSTD_NO_STD_BAD_CAST
47 STD_NAME ("BAD_CAST"),
48#else
49 "",
50#endif // _RWSTD_NO_STD_BAD_CAST
51
52#ifdef _RWSTD_NO_STD_BAD_EXCEPTION
53 STD_NAME ("BAD_EXCEPTION"),
54#else
55 "",
56#endif // _RWSTD_NO_STD_BAD_EXCEPTION
57
58#ifdef _RWSTD_NO_STD_BAD_TYPEID
59 STD_NAME ("BAD_TYPEID"),
60#else
61 "",
62#endif // _RWSTD_NO_STD_BAD_TYPEID
63
64#ifdef _RWSTD_NO_STD_EXCEPTION
65 STD_NAME ("EXCEPTION"),
66#else
67 "",
68#endif // _RWSTD_NO_STD_EXCEPTION
69
70#ifdef _RWSTD_NO_STD_SET_NEW_HANDLER
71 STD_NAME ("SET_NEW_HANDLER"),
72#else
73 "",
74#endif // _RWSTD_NO_STD_SET_NEW_HANDLER
75
76#ifdef _RWSTD_NO_STD_SET_TERMINATE
77 STD_NAME ("SET_TERMINATE"),
78#else
79 "",
80#endif // _RWSTD_NO_STD_SET_TERMINATE
81
82#ifdef _RWSTD_NO_STD_SET_UNEXPECTED
83 STD_NAME ("SET_UNEXPECTED"),
84#else
85 "",
86#endif // _RWSTD_NO_STD_SET_UNEXPECTED
87
88#ifdef _RWSTD_NO_STD_TERMINATE
89 STD_NAME ("TERMINATE"),
90#else
91 "",
92#endif // _RWSTD_NO_STD_TERMINATE
93
94#ifdef _RWSTD_NO_STD_UNCAUGHT_EXCEPTION
95 STD_NAME ("UNCAUGHT_EXCEPTION"),
96#else
97 "",
98#endif // _RWSTD_NO_STD_UNCAUGHT_EXCEPTION
99
100#ifdef _RWSTD_NO_STD_UNEXPECTED
101 STD_NAME ("UNEXPECTED"),
102#else
103 "",
104#endif // _RWSTD_NO_STD_UNEXPECTED
105
106 0 // sentinel
107};
108
109
110const char* const global_defs[] = {
111
112#ifdef _RWSTD_NO_GLOBAL_BAD_ALLOC
113 "BAD_ALLOC",
114#else
115 "",
116#endif // _RWSTD_NO_GLOBAL_BAD_ALLOC
117
118#ifdef _RWSTD_NO_GLOBAL_BAD_CAST
119 "BAD_CAST",
120#else
121 "",
122#endif // _RWSTD_NO_GLOBAL_BAD_CAST
123
124#ifdef _RWSTD_NO_GLOBAL_BAD_EXCEPTION
125 "BAD_EXCEPTION",
126#else
127 "",
128#endif // _RWSTD_NO_GLOBAL_BAD_EXCEPTION
129
130#ifdef _RWSTD_NO_GLOBAL_BAD_TYPEID
131 "BAD_TYPEID",
132#else
133 "",
134#endif // _RWSTD_NO_GLOBAL_BAD_TYPEID
135
136#ifdef _RWSTD_NO_GLOBAL_EXCEPTION
137 "EXCEPTION",
138#else
139 "",
140#endif // _RWSTD_NO_GLOBAL_EXCEPTION
141
142#ifdef _RWSTD_NO_GLOBAL_SET_NEW_HANDLER
143 "SET_NEW_HANDLER",
144#else
145 "",
146#endif // _RWSTD_NO_GLOBAL_SET_NEW_HANDLER
147
148#ifdef _RWSTD_NO_GLOBAL_SET_TERMINATE
149 "SET_TERMINATE",
150#else
151 "",
152#endif // _RWSTD_NO_GLOBAL_SET_TERMINATE
153
154#ifdef _RWSTD_NO_GLOBAL_SET_UNEXPECTED
155 "SET_UNEXPECTED",
156#else
157 "",
158#endif // _RWSTD_NO_GLOBAL_SET_UNEXPECTED
159
160#ifdef _RWSTD_NO_GLOBAL_TERMINATE
161 "TERMINATE",
162#else
163 "",
164#endif // _RWSTD_NO_GLOBAL_TERMINATE
165
166#ifdef _RWSTD_NO_GLOBAL_UNCAUGHT_EXCEPTION
167 "UNCAUGHT_EXCEPTION",
168#else
169 "",
170#endif // _RWSTD_NO_GLOBAL_UNCAUGHT_EXCEPTION
171
172#ifdef _RWSTD_NO_GLOBAL_UNEXPECTED
173 "UNEXPECTED",
174#else
175 "",
176#endif // _RWSTD_NO_GLOBAL_UNEXPECTED
177
178 0 // sentinel
179};
180
181
182int main ()
183{
184 // since some (possibly many) individual config tests fail
185 // to detect either an STD or a GLOBAL version of the feature,
186 // this test overrides (#undef-ines) one of the matching pair
187 // of macros based on the overall findings to avoid complex
188 // #ifdef logic in the library headers
189
190 unsigned n_std_defs = 0; // number of macros defined for std names
191 unsigned n_global_defs = 0; // number of macros defined for global names
192 unsigned n_both_defs = 0; // number of macros defined for both
193 unsigned n_neither_defs = 0; // number of macros defined for neither
194 unsigned n_count = 0; // total number of symbols
195
196 // numbers of symbols found to be defined only in namespace std
197 // and not in the global namespace, and vice versa
198 unsigned n_std_only_syms = 0;
199 unsigned n_global_only_syms = 0;
200
201 unsigned i;
202
203 // count the number of macro definitions for the symbols
204 // found to be missing in namespace std and in the global
205 // namespace, the number of symbols found to be defined
206 // in both namespaces, and the total number of symbols
207 for (i = 0; std_defs [i]; ++i, ++n_count) {
208
209 // number of macros defined
210 int cnt = 0;
211
212 if (*std_defs [i]) {
213 ++n_std_defs;
214 ++cnt;
215 }
216
217 if (*global_defs [i]) {
218
219 if (0 == cnt) {
220 // increment the number of symbols that are found to be
221 // defined in namespace std and not in the global namespace
222 ++n_std_only_syms;
223 }
224
225 ++n_global_defs;
226 ++cnt;
227 }
228 else {
229 if (1 == cnt) {
230 // increment the number of symbols that are found to be
231 // defined in the global namespace and not also in std
232 ++n_global_only_syms;
233 }
234 }
235
236 if (2 == cnt)
237 ++n_both_defs;
238 else if (0 == cnt)
239 ++n_neither_defs;
240 }
241
242 // #undef macros that are (assumed to be) #defined due to
243 // false negative test results
244 for (i = 0; std_defs [i]; ++i) {
245 if (*std_defs [i] && *global_defs [i]) {
246
247 // both the NO_STD and NO_GLOBAL forms of the same macro
248 // are #defined (i.e., the symbol wasn't found in either
249 // namespace, presumably because of a false negative
250 // result of one or both tests for the symbol)
251
252 const char *symbol_scope;
253
254 if (n_std_only_syms && n_global_only_syms <= n_std_only_syms) {
255 // there are at least as many names defined only in
256 // namespace std and not also in the global namespace
257 // than there are those defined in the global namespace
258 // that are not also defined in namespace std (and this
259 // number is non-zero)
260 symbol_scope = "STD";
261 }
262 else if (n_global_defs < n_std_defs) {
263 // there are more symbols found to be defined in the global
264 // namespace than there are those defined in namespace std
265 symbol_scope = "GLOBAL";
266 }
267 else
268 symbol_scope = "STD";
269
270 // undefine the macro
271 printf ("#undef _RWSTD_NO_%s_%s\n", symbol_scope, std_defs [i]);
272 }
273 }
274
275 // in a comment print out the number of symbols found to be defined
276 // in namespace std, in the global namespace, in both namespaces,
277 // and in neither
278 printf ("// number of runtime library symbols examined: %2u\n"
279 "// symbols found only in namespace std: %2u\n"
280 "// symbols found only in the global namespace: %2u\n"
281 "// symbols found in both namespaces: %2u\n"
282 "// symbols found in neither namespace: %2u\n",
283 n_count,
284 n_std_only_syms,
285 n_global_only_syms,
286 n_neither_defs,
287 n_both_defs);
288
289 if (n_std_only_syms) {
290 // comment out the NO_RUNTIME_IN_STD macro when at least one symbol
291 // is defined in namespace std and not also defined in the global
292 // namespace
293 printf ("%s ", "//");
294 }
295
296 printf ("#define %s\n", "_RWSTD_NO_RUNTIME_IN_STD\n");
297
298 return 0;
299}
#define i
Definition 17.names.cpp:126
#define cnt
Definition 17.names.cpp:459
IMPORT_C SInt32 printf(const Char *,...)
const char *const std_defs[]
const char *const global_defs[]
#define STD_NAME(name)
int main()