1 | /*============================================================================= |
---|
2 | Boost.Wave: A Standard compliant C++ preprocessor library |
---|
3 | |
---|
4 | Definition of the predefined macros |
---|
5 | |
---|
6 | http://www.boost.org/ |
---|
7 | |
---|
8 | Copyright (c) 2001-2007 Hartmut Kaiser. Distributed under the Boost |
---|
9 | Software License, Version 1.0. (See accompanying file |
---|
10 | LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
11 | =============================================================================*/ |
---|
12 | |
---|
13 | #if !defined(CPP_MACROMAP_PREDEF_HPP_HK041119) |
---|
14 | #define CPP_MACROMAP_PREDEF_HPP_HK041119 |
---|
15 | |
---|
16 | #include <cstdio> |
---|
17 | #include <boost/assert.hpp> |
---|
18 | |
---|
19 | #include <boost/wave/wave_config.hpp> |
---|
20 | #include <boost/wave/wave_config_constant.hpp> |
---|
21 | #include <boost/wave/token_ids.hpp> |
---|
22 | |
---|
23 | // this must occur after all of the includes and before any code appears |
---|
24 | #ifdef BOOST_HAS_ABI_HEADERS |
---|
25 | #include BOOST_ABI_PREFIX |
---|
26 | #endif |
---|
27 | |
---|
28 | /////////////////////////////////////////////////////////////////////////////// |
---|
29 | // |
---|
30 | // This file contains the definition of functions needed for the management |
---|
31 | // of static and dynamic predefined macros, such as __DATE__, __TIME__ etc. |
---|
32 | // |
---|
33 | // Note: __FILE__, __LINE__ and __INCLUDE_LEVEL__ are handled in the file |
---|
34 | // cpp_macromap.hpp. |
---|
35 | // |
---|
36 | /////////////////////////////////////////////////////////////////////////////// |
---|
37 | |
---|
38 | /////////////////////////////////////////////////////////////////////////////// |
---|
39 | namespace boost { |
---|
40 | namespace wave { |
---|
41 | namespace util { |
---|
42 | |
---|
43 | namespace predefined_macros { |
---|
44 | |
---|
45 | // list of static predefined macros |
---|
46 | struct static_macros { |
---|
47 | char const *name; |
---|
48 | boost::wave::token_id token_id; |
---|
49 | char const *value; |
---|
50 | }; |
---|
51 | |
---|
52 | // C++ mode |
---|
53 | inline static_macros const & |
---|
54 | static_data_cpp(std::size_t i) |
---|
55 | { |
---|
56 | static static_macros data[] = { |
---|
57 | { "__STDC__", T_INTLIT, "1" }, |
---|
58 | { "__cplusplus", T_INTLIT, "199711L" }, |
---|
59 | { 0, T_EOF, 0 } |
---|
60 | }; |
---|
61 | BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); |
---|
62 | return data[i]; |
---|
63 | } |
---|
64 | |
---|
65 | #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 |
---|
66 | // C99 mode |
---|
67 | inline static_macros const & |
---|
68 | static_data_c99(std::size_t i) |
---|
69 | { |
---|
70 | static static_macros data[] = { |
---|
71 | { "__STDC__", T_INTLIT, "1" }, |
---|
72 | { "__STDC_VERSION__", T_INTLIT, "199901L" }, |
---|
73 | { "__STDC_HOSTED__", T_INTLIT, "0" }, |
---|
74 | { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" }, |
---|
75 | { 0, T_EOF, 0 } |
---|
76 | }; |
---|
77 | BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); |
---|
78 | return data[i]; |
---|
79 | } |
---|
80 | #endif |
---|
81 | |
---|
82 | // list of dynamic predefined macros |
---|
83 | typedef char const * (* get_dynamic_value)(bool); |
---|
84 | |
---|
85 | // __DATE__ |
---|
86 | inline |
---|
87 | char const *get_date(bool reset) |
---|
88 | { |
---|
89 | static std::string datestr; |
---|
90 | static const char *const monthnames[] = { |
---|
91 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
---|
92 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
---|
93 | }; |
---|
94 | |
---|
95 | if (reset) { |
---|
96 | datestr.erase(); |
---|
97 | } |
---|
98 | else { |
---|
99 | // for some systems sprintf, time_t etc. is in namespace std |
---|
100 | using namespace std; |
---|
101 | |
---|
102 | time_t tt = time(0); |
---|
103 | struct tm *tb = 0; |
---|
104 | |
---|
105 | if (tt != (time_t)-1) { |
---|
106 | char buffer[sizeof("\"Oct 11 1347\"")+1]; |
---|
107 | |
---|
108 | tb = localtime (&tt); |
---|
109 | sprintf (buffer, "\"%s %2d %4d\"", |
---|
110 | monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900); |
---|
111 | datestr = buffer; |
---|
112 | } |
---|
113 | else { |
---|
114 | datestr = "\"??? ?? ????\""; |
---|
115 | } |
---|
116 | } |
---|
117 | return datestr.c_str(); |
---|
118 | } |
---|
119 | |
---|
120 | // __TIME__ |
---|
121 | inline |
---|
122 | char const *get_time(bool reset) |
---|
123 | { |
---|
124 | static std::string timestr; |
---|
125 | |
---|
126 | if (reset) { |
---|
127 | timestr.erase(); |
---|
128 | } |
---|
129 | else { |
---|
130 | // for some systems sprintf, time_t etc. is in namespace std |
---|
131 | using namespace std; |
---|
132 | |
---|
133 | time_t tt = time(0); |
---|
134 | struct tm *tb = 0; |
---|
135 | |
---|
136 | if (tt != (time_t)-1) { |
---|
137 | char buffer[sizeof("\"12:34:56\"")+1]; |
---|
138 | |
---|
139 | tb = localtime (&tt); |
---|
140 | sprintf (buffer, "\"%02d:%02d:%02d\"", tb->tm_hour, |
---|
141 | tb->tm_min, tb->tm_sec); |
---|
142 | timestr = buffer; |
---|
143 | } |
---|
144 | else { |
---|
145 | timestr = "\"??:??:??\""; |
---|
146 | } |
---|
147 | } |
---|
148 | return timestr.c_str(); |
---|
149 | } |
---|
150 | |
---|
151 | // __SPIRIT_PP__/__WAVE__ |
---|
152 | inline |
---|
153 | char const *get_version(bool /*reset*/) |
---|
154 | { |
---|
155 | static std::string versionstr; |
---|
156 | char buffer[sizeof("0x0000")+1]; |
---|
157 | |
---|
158 | using namespace std; // for some systems sprintf is in namespace std |
---|
159 | sprintf(buffer, "0x%02d%1d%1d", BOOST_WAVE_VERSION_MAJOR, |
---|
160 | BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR); |
---|
161 | versionstr = buffer; |
---|
162 | return versionstr.c_str(); |
---|
163 | } |
---|
164 | |
---|
165 | // __SPIRIT_PP_VERSION__/__WAVE_VERSION__ |
---|
166 | boost::wave::util::time_conversion_helper const |
---|
167 | compilation_time(__DATE__ " " __TIME__); |
---|
168 | |
---|
169 | inline |
---|
170 | char const *get_fullversion(bool /*reset*/) |
---|
171 | { |
---|
172 | static std::string versionstr; |
---|
173 | char buffer[sizeof("0x00000000")+1]; |
---|
174 | |
---|
175 | // for some systems sprintf, time_t etc. is in namespace std |
---|
176 | using namespace std; |
---|
177 | |
---|
178 | // calculate the number of days since Dec 13 2001 |
---|
179 | // (the day the Wave project was started) |
---|
180 | tm first_day; |
---|
181 | |
---|
182 | using namespace std; // for some systems memset is in namespace std |
---|
183 | memset (&first_day, 0, sizeof(tm)); |
---|
184 | first_day.tm_mon = 11; // Dec |
---|
185 | first_day.tm_mday = 13; // 13 |
---|
186 | first_day.tm_year = 101; // 2001 |
---|
187 | |
---|
188 | long seconds = long(difftime(compilation_time.get_time(), |
---|
189 | mktime(&first_day))); |
---|
190 | |
---|
191 | sprintf(buffer, "0x%02d%1d%1d%04ld", BOOST_WAVE_VERSION_MAJOR, |
---|
192 | BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR, |
---|
193 | seconds/(3600*24)); |
---|
194 | versionstr = buffer; |
---|
195 | return versionstr.c_str(); |
---|
196 | } |
---|
197 | |
---|
198 | // __SPIRIT_PP_VERSION_STR__/__WAVE_VERSION_STR__ |
---|
199 | inline |
---|
200 | char const *get_versionstr(bool /*reset*/) |
---|
201 | { |
---|
202 | using namespace std; // for some systems memset is in namespace std |
---|
203 | |
---|
204 | static std::string versionstr; |
---|
205 | char buffer[sizeof("\"00.00.00.0000 \"")+sizeof(BOOST_PLATFORM)+sizeof(BOOST_COMPILER)+4]; |
---|
206 | |
---|
207 | // for some systems sprintf, time_t etc. is in namespace std |
---|
208 | using namespace std; |
---|
209 | |
---|
210 | // calculate the number of days since Dec 13 2001 |
---|
211 | // (the day the Wave project was started) |
---|
212 | tm first_day; |
---|
213 | |
---|
214 | memset (&first_day, 0, sizeof(tm)); |
---|
215 | first_day.tm_mon = 11; // Dec |
---|
216 | first_day.tm_mday = 13; // 13 |
---|
217 | first_day.tm_year = 101; // 2001 |
---|
218 | |
---|
219 | long seconds = long(difftime(compilation_time.get_time(), |
---|
220 | mktime(&first_day))); |
---|
221 | |
---|
222 | sprintf(buffer, "\"%d.%d.%d.%ld [%s/%s]\"", BOOST_WAVE_VERSION_MAJOR, |
---|
223 | BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR, |
---|
224 | seconds/(3600*24), BOOST_PLATFORM, BOOST_COMPILER); |
---|
225 | versionstr = buffer; |
---|
226 | return versionstr.c_str(); |
---|
227 | } |
---|
228 | |
---|
229 | // __WAVE_CONFIG__ |
---|
230 | inline |
---|
231 | char const *get_config(bool /*reset*/) |
---|
232 | { |
---|
233 | using namespace std; // for some systems memset is in namespace std |
---|
234 | |
---|
235 | static std::string configstr; |
---|
236 | char buffer[sizeof("0x00000000")+1]; |
---|
237 | |
---|
238 | // for some systems sprintf is in namespace std |
---|
239 | using namespace std; |
---|
240 | |
---|
241 | sprintf(buffer, "0x%08x", BOOST_WAVE_CONFIG); |
---|
242 | configstr = buffer; |
---|
243 | return configstr.c_str(); |
---|
244 | } |
---|
245 | |
---|
246 | struct dynamic_macros { |
---|
247 | char const *name; |
---|
248 | boost::wave::token_id token_id; |
---|
249 | get_dynamic_value generator; |
---|
250 | }; |
---|
251 | |
---|
252 | inline dynamic_macros const & |
---|
253 | dynamic_data(std::size_t i) |
---|
254 | { |
---|
255 | static dynamic_macros data[] = { |
---|
256 | { "__DATE__", T_STRINGLIT, get_date }, |
---|
257 | { "__TIME__", T_STRINGLIT, get_time }, |
---|
258 | { "__SPIRIT_PP__", T_INTLIT, get_version }, |
---|
259 | { "__SPIRIT_PP_VERSION__", T_INTLIT, get_fullversion }, |
---|
260 | { "__SPIRIT_PP_VERSION_STR__", T_STRINGLIT, get_versionstr }, |
---|
261 | { "__WAVE__", T_INTLIT, get_version }, |
---|
262 | { "__WAVE_VERSION__", T_INTLIT, get_fullversion }, |
---|
263 | { "__WAVE_VERSION_STR__", T_STRINGLIT, get_versionstr }, |
---|
264 | { "__WAVE_CONFIG__", T_INTLIT, get_config }, |
---|
265 | { 0, T_EOF, 0 } |
---|
266 | }; |
---|
267 | BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); |
---|
268 | return data[i]; |
---|
269 | } |
---|
270 | |
---|
271 | } // namespace predefined_macros |
---|
272 | |
---|
273 | /////////////////////////////////////////////////////////////////////////////// |
---|
274 | } // namespace util |
---|
275 | } // namespace wave |
---|
276 | } // namespace boost |
---|
277 | |
---|
278 | // the suffix header occurs after all of the code |
---|
279 | #ifdef BOOST_HAS_ABI_HEADERS |
---|
280 | #include BOOST_ABI_SUFFIX |
---|
281 | #endif |
---|
282 | |
---|
283 | #endif // !defined(CPP_MACROMAP_PREDEF_HPP_HK041119) |
---|