1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
4 Definition of the predefined macros
8 Copyright (c) 2001-2012 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 =============================================================================*/
13 #if !defined(CPP_MACROMAP_PREDEF_HPP_HK041119)
14 #define CPP_MACROMAP_PREDEF_HPP_HK041119
17 #include <boost/assert.hpp>
19 #include <boost/wave/wave_config.hpp>
20 #include <boost/wave/wave_config_constant.hpp>
21 #include <boost/wave/token_ids.hpp>
22 #include <boost/wave/util/time_conversion_helper.hpp> // time_conversion_helper
24 // this must occur after all of the includes and before any code appears
25 #ifdef BOOST_HAS_ABI_HEADERS
26 #include BOOST_ABI_PREFIX
29 ///////////////////////////////////////////////////////////////////////////////
31 // This file contains the definition of functions needed for the management
32 // of static and dynamic predefined macros, such as __DATE__, __TIME__ etc.
34 // Note: __FILE__, __LINE__ and __INCLUDE_LEVEL__ are handled in the file
37 ///////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////////////
45 class predefined_macros
47 typedef BOOST_WAVE_STRINGTYPE string_type;
50 // list of static predefined macros
51 struct static_macros {
53 boost::wave::token_id token_id;
57 // list of dynamic predefined macros
58 struct dynamic_macros {
60 boost::wave::token_id token_id;
61 string_type (predefined_macros:: *generator)() const;
65 boost::wave::util::time_conversion_helper compilation_time_;
66 string_type datestr_; // __DATE__
67 string_type timestr_; // __TIME__
68 string_type version_; // __SPIRIT_PP_VERSION__/__WAVE_VERSION__
69 string_type versionstr_; // __SPIRIT_PP_VERSION_STR__/__WAVE_VERSION_STR__
74 static const char *const monthnames[] = {
75 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
76 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
79 // for some systems sprintf, time_t etc. is in namespace std
85 if (tt != (time_t)-1) {
86 char buffer[sizeof("\"Oct 11 1347\"")+1];
89 sprintf (buffer, "\"%s %2d %4d\"",
90 monthnames[tb->tm_mon], tb->tm_mday, tb->tm_year + 1900);
94 datestr_ = "\"??? ?? ????\"";
100 // for some systems sprintf, time_t etc. is in namespace std
106 if (tt != (time_t)-1) {
107 char buffer[sizeof("\"12:34:56\"")+1];
109 tb = localtime (&tt);
110 sprintf (buffer, "\"%02d:%02d:%02d\"", tb->tm_hour,
111 tb->tm_min, tb->tm_sec);
115 timestr_ = "\"??:??:??\"";
121 char buffer[sizeof("0x00000000")+1];
123 // for some systems sprintf, time_t etc. is in namespace std
126 // calculate the number of days since Dec 13 2001
127 // (the day the Wave project was started)
130 using namespace std; // for some systems memset is in namespace std
131 memset (&first_day, 0, sizeof(tm));
132 first_day.tm_mon = 11; // Dec
133 first_day.tm_mday = 13; // 13
134 first_day.tm_year = 101; // 2001
136 long seconds = long(difftime(compilation_time_.get_time(), mktime(&first_day)));
138 sprintf(buffer, "0x%02d%1d%1d%04ld", BOOST_WAVE_VERSION_MAJOR,
139 BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR,
144 void reset_versionstr()
146 char buffer[sizeof("\"00.00.00.0000 \"")+sizeof(BOOST_PLATFORM)+sizeof(BOOST_COMPILER)+4];
148 // for some systems sprintf, time_t etc. is in namespace std
151 // calculate the number of days since Dec 13 2001
152 // (the day the Wave project was started)
155 memset (&first_day, 0, sizeof(tm));
156 first_day.tm_mon = 11; // Dec
157 first_day.tm_mday = 13; // 13
158 first_day.tm_year = 101; // 2001
160 long seconds = long(difftime(compilation_time_.get_time(), mktime(&first_day)));
162 sprintf(buffer, "\"%d.%d.%d.%ld [%s/%s]\"", BOOST_WAVE_VERSION_MAJOR,
163 BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR,
164 seconds/(3600*24), BOOST_PLATFORM, BOOST_COMPILER);
165 versionstr_ = buffer;
168 // dynamic predefined macros
169 string_type get_date() const { return datestr_; } // __DATE__
170 string_type get_time() const { return timestr_; } // __TIME__
172 // __SPIRIT_PP__/__WAVE__
173 string_type get_version() const
175 char buffer[sizeof("0x0000")+1];
177 using namespace std; // for some systems sprintf is in namespace std
178 sprintf(buffer, "0x%02d%1d%1d", BOOST_WAVE_VERSION_MAJOR,
179 BOOST_WAVE_VERSION_MINOR, BOOST_WAVE_VERSION_SUBMINOR);
184 string_type get_config() const
186 char buffer[sizeof("0x00000000")+1];
188 using namespace std; // for some systems sprintf is in namespace std
189 sprintf(buffer, "0x%08x", BOOST_WAVE_CONFIG);
195 : compilation_time_(__DATE__ " " __TIME__)
208 // __SPIRIT_PP_VERSION__/__WAVE_VERSION__
209 string_type get_fullversion() const { return version_; }
211 // __SPIRIT_PP_VERSION_STR__/__WAVE_VERSION_STR__
212 string_type get_versionstr() const { return versionstr_; }
215 static_macros const& static_data_cpp(std::size_t i) const
217 static static_macros data[] = {
218 { "__STDC__", T_INTLIT, "1" },
219 { "__cplusplus", T_INTLIT, "199711L" },
222 BOOST_ASSERT(i < sizeof(data)/sizeof(data[0]));
226 #if BOOST_WAVE_SUPPORT_CPP0X != 0
228 static_macros const& static_data_cpp0x(std::size_t i) const
230 static static_macros data[] = {
231 { "__STDC__", T_INTLIT, "1" },
232 { "__cplusplus", T_INTLIT, "201103L" },
233 { "__STDC_VERSION__", T_INTLIT, "199901L" },
234 { "__STDC_HOSTED__", T_INTLIT, "0" },
235 { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" },
238 BOOST_ASSERT(i < sizeof(data)/sizeof(data[0]));
243 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
245 static_macros const& static_data_c99(std::size_t i) const
247 static static_macros data[] = {
248 { "__STDC__", T_INTLIT, "1" },
249 { "__STDC_VERSION__", T_INTLIT, "199901L" },
250 { "__STDC_HOSTED__", T_INTLIT, "0" },
251 { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" },
254 BOOST_ASSERT(i < sizeof(data)/sizeof(data[0]));
259 dynamic_macros const& dynamic_data(std::size_t i) const
261 static dynamic_macros data[] = {
262 { "__DATE__", T_STRINGLIT, &predefined_macros::get_date },
263 { "__TIME__", T_STRINGLIT, &predefined_macros::get_time },
264 { "__SPIRIT_PP__", T_INTLIT, &predefined_macros::get_version },
265 { "__SPIRIT_PP_VERSION__", T_INTLIT, &predefined_macros::get_fullversion },
266 { "__SPIRIT_PP_VERSION_STR__", T_STRINGLIT, &predefined_macros::get_versionstr },
267 { "__WAVE__", T_INTLIT, &predefined_macros::get_version },
268 { "__WAVE_VERSION__", T_INTLIT, &predefined_macros::get_fullversion },
269 { "__WAVE_VERSION_STR__", T_STRINGLIT, &predefined_macros::get_versionstr },
270 { "__WAVE_CONFIG__", T_INTLIT, &predefined_macros::get_config },
273 BOOST_ASSERT(i < sizeof(data)/sizeof(data[0]));
276 }; // predefined_macros
278 ///////////////////////////////////////////////////////////////////////////////
283 // the suffix header occurs after all of the code
284 #ifdef BOOST_HAS_ABI_HEADERS
285 #include BOOST_ABI_SUFFIX
288 #endif // !defined(CPP_MACROMAP_PREDEF_HPP_HK041119)