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