Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72162 - in trunk: boost/wave boost/wave/grammars libs/wave libs/wave/samples/cpp_tokens libs/wave/samples/list_includes libs/wave/samples/real_positions libs/wave/src tools/wave
From: hartmut.kaiser_at_[hidden]
Date: 2011-05-25 14:32:53


Author: hkaiser
Date: 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
New Revision: 72162
URL: http://svn.boost.org/trac/boost/changeset/72162

Log:
Wave: allowing to force interpretation of wchar_t as signed/unsigned, fixed a problem in #pragma option_str(output)
Text files modified:
   trunk/boost/wave/grammars/cpp_chlit_grammar.hpp | 12 ++++++------
   trunk/boost/wave/grammars/cpp_expression_grammar.hpp | 22 ++++++++++++++++++++--
   trunk/boost/wave/grammars/cpp_literal_grammar_gen.hpp | 4 ++--
   trunk/boost/wave/wave_config.hpp | 16 ++++++++++++++++
   trunk/libs/wave/ChangeLog | 6 ++++++
   trunk/libs/wave/samples/cpp_tokens/instantiate_cpp_literalgrs.cpp | 6 +++++-
   trunk/libs/wave/samples/list_includes/instantiate_cpp_literalgrs.cpp | 6 +++++-
   trunk/libs/wave/samples/real_positions/instantiate_cpp_literalgrs.cpp | 6 +++++-
   trunk/libs/wave/src/instantiate_cpp_literalgrs.cpp | 6 +++++-
   trunk/tools/wave/trace_macro_expansion.hpp | 12 +++++++-----
   10 files changed, 77 insertions(+), 19 deletions(-)

Modified: trunk/boost/wave/grammars/cpp_chlit_grammar.hpp
==============================================================================
--- trunk/boost/wave/grammars/cpp_chlit_grammar.hpp (original)
+++ trunk/boost/wave/grammars/cpp_chlit_grammar.hpp 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -298,15 +298,15 @@
 #define BOOST_WAVE_CHLITGRAMMAR_GEN_INLINE inline
 #endif
 
-template <typename TokenT>
+template <typename IntegralResult, typename TokenT>
 BOOST_WAVE_CHLITGRAMMAR_GEN_INLINE
-unsigned int
-chlit_grammar_gen<TokenT>::evaluate(TokenT const &token, value_error &status)
+IntegralResult
+chlit_grammar_gen<IntegralResult, TokenT>::evaluate(TokenT const &token, value_error &status)
 {
     using namespace boost::spirit::classic;
     
 chlit_grammar g;
-boost::uint32_t result = 0;
+IntegralResult result = 0;
 typename TokenT::string_type const &token_val = token.get_value();
 parse_info<typename TokenT::string_type::const_iterator> hit =
     parse(token_val.begin(), token_val.end(), g[spirit_assign_actor(result)]);
@@ -320,7 +320,7 @@
         if ('L' == token_val[0]) {
         // recognized wide character
             if (g.overflow ||
- result > (unsigned long)(std::numeric_limits<wchar_t>::max)())
+ result > (IntegralResult)(std::numeric_limits<wchar_t>::max)())
             {
             // out of range
                 status = error_character_overflow;
@@ -329,7 +329,7 @@
         else {
         // recognized narrow ('normal') character
             if (g.overflow ||
- result > (unsigned long)(std::numeric_limits<unsigned char>::max)())
+ result > (IntegralResult)(std::numeric_limits<unsigned char>::max)())
             {
             // out of range
                 status = error_character_overflow;

Modified: trunk/boost/wave/grammars/cpp_expression_grammar.hpp
==============================================================================
--- trunk/boost/wave/grammars/cpp_expression_grammar.hpp (original)
+++ trunk/boost/wave/grammars/cpp_expression_grammar.hpp 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -105,7 +105,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 //
-// convert the given token value (character literal) to a unsigned int
+// Convert the given token value (character literal) to a unsigned int
 //
 ///////////////////////////////////////////////////////////////////////////////
     struct convert_chlit {
@@ -122,7 +122,25 @@
         {
             typedef boost::wave::grammars::closures::closure_value return_type;
             value_error status = error_noerror;
- unsigned int value = chlit_grammar_gen<TokenT>::evaluate(token, status);
+
+ // If the literal is a wchar_t and wchar_t is represented by a
+ // signed integral type, then the created value will be signed as
+ // well, otherwise we assume unsigned values.
+#if BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_AUTOSELECT
+ if ('L' == token.get_value()[0] && std::numeric_limits<wchar_t>::is_signed)
+ {
+ int value = chlit_grammar_gen<int, TokenT>::evaluate(token, status);
+ return return_type(value, status);
+ }
+#elif BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_FORCE_SIGNED
+ if ('L' == token.get_value()[0])
+ {
+ int value = chlit_grammar_gen<int, TokenT>::evaluate(token, status);
+ return return_type(value, status);
+ }
+#endif
+
+ unsigned int value = chlit_grammar_gen<unsigned int, TokenT>::evaluate(token, status);
             return return_type(value, status);
         }
     };

Modified: trunk/boost/wave/grammars/cpp_literal_grammar_gen.hpp
==============================================================================
--- trunk/boost/wave/grammars/cpp_literal_grammar_gen.hpp (original)
+++ trunk/boost/wave/grammars/cpp_literal_grammar_gen.hpp 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -54,10 +54,10 @@
 // to safe compilation time.
 //
 ///////////////////////////////////////////////////////////////////////////////
-template <typename TokenT>
+template <typename IntegralResult, typename TokenT>
 struct BOOST_WAVE_DECL chlit_grammar_gen {
 
- static unsigned int evaluate(TokenT const &tok, value_error& status);
+ static IntegralResult evaluate(TokenT const &tok, value_error& status);
 };
 
 ///////////////////////////////////////////////////////////////////////////////

Modified: trunk/boost/wave/wave_config.hpp
==============================================================================
--- trunk/boost/wave/wave_config.hpp (original)
+++ trunk/boost/wave/wave_config.hpp 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -403,6 +403,22 @@
 }}
 
 ///////////////////////////////////////////////////////////////////////////////
+// On some platforms Wave will not be able to properly detect whether wchar_t
+// is representing a signed or unsigned integral data type. Use the
+// configuration constants below to force wchar_t being signed or unsigned, as
+// appropriate.
+//
+// The default is to use std::numeric_limits<wchar_t>::is_signed.
+
+#define BOOST_WAVE_WCHAR_T_AUTOSELECT 1
+#define BOOST_WAVE_WCHAR_T_FORCE_SIGNED 2
+#define BOOST_WAVE_WCHAR_T_FORCE_UNSIGNED 3
+
+#if !defined(BOOST_WAVE_WCHAR_T_SIGNEDNESS)
+#define BOOST_WAVE_WCHAR_T_SIGNEDNESS BOOST_WAVE_WCHAR_T_AUTOSELECT
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
 // Wave needs at least 4 parameters for phoenix actors
 #if !defined(PHOENIX_LIMIT)
 #define PHOENIX_LIMIT 6

Modified: trunk/libs/wave/ChangeLog
==============================================================================
--- trunk/libs/wave/ChangeLog (original)
+++ trunk/libs/wave/ChangeLog 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -38,6 +38,12 @@
 - Fixed Wave driver to retain all macros defined on the command line in
   interactive mode.
 - Fixed problem #5554: wave slex parser eof without eol skips the last line.
+- Added the compile time configuartion option BOOST_WAVE_WCHAR_T_SIGNEDNESS,
+ which can be set to BOOST_WAVE_WCHAR_T_AUTOSELECT, BOOST_WAVE_WCHAR_T_FORCE_SIGNED,
+ or BOOST_WAVE_WCHAR_T_FORCE_UNSIGNED), it defaults to autoßselect.
+- Fixed a problem in teh wave driver tool related to #pragma option(output).
+ If wave was invoked in rapid succession this erroneously appended to an
+ existing file instead of overwriting that file.
 
 Boost V1.46.0
 - V2.2.0

Modified: trunk/libs/wave/samples/cpp_tokens/instantiate_cpp_literalgrs.cpp
==============================================================================
--- trunk/libs/wave/samples/cpp_tokens/instantiate_cpp_literalgrs.cpp (original)
+++ trunk/libs/wave/samples/cpp_tokens/instantiate_cpp_literalgrs.cpp 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -37,7 +37,11 @@
 typedef boost::wave::cpplexer::slex_token<> token_type;
 
 template struct boost::wave::grammars::intlit_grammar_gen<token_type>;
-template struct boost::wave::grammars::chlit_grammar_gen<token_type>;
+#if BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_AUTOSELECT || \
+ BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_FORCE_SIGNED
+template struct boost::wave::grammars::chlit_grammar_gen<int, token_type>;
+#endif
+template struct boost::wave::grammars::chlit_grammar_gen<unsigned int, token_type>;
 
 #endif // #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
 

Modified: trunk/libs/wave/samples/list_includes/instantiate_cpp_literalgrs.cpp
==============================================================================
--- trunk/libs/wave/samples/list_includes/instantiate_cpp_literalgrs.cpp (original)
+++ trunk/libs/wave/samples/list_includes/instantiate_cpp_literalgrs.cpp 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -37,7 +37,11 @@
 typedef boost::wave::cpplexer::lex_token<> token_type;
 
 template struct boost::wave::grammars::intlit_grammar_gen<token_type>;
-template struct boost::wave::grammars::chlit_grammar_gen<token_type>;
+#if BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_AUTOSELECT || \
+ BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_FORCE_SIGNED
+template struct boost::wave::grammars::chlit_grammar_gen<int, token_type>;
+#endif
+template struct boost::wave::grammars::chlit_grammar_gen<unsigned int, token_type>;
 
 #endif // #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
 

Modified: trunk/libs/wave/samples/real_positions/instantiate_cpp_literalgrs.cpp
==============================================================================
--- trunk/libs/wave/samples/real_positions/instantiate_cpp_literalgrs.cpp (original)
+++ trunk/libs/wave/samples/real_positions/instantiate_cpp_literalgrs.cpp 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -36,7 +36,11 @@
 typedef lex_token<> token_type;
 
 template struct boost::wave::grammars::intlit_grammar_gen<token_type>;
-template struct boost::wave::grammars::chlit_grammar_gen<token_type>;
+#if BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_AUTOSELECT || \
+ BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_FORCE_SIGNED
+template struct boost::wave::grammars::chlit_grammar_gen<int, token_type>;
+#endif
+template struct boost::wave::grammars::chlit_grammar_gen<unsigned int, token_type>;
 
 #endif // #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
 

Modified: trunk/libs/wave/src/instantiate_cpp_literalgrs.cpp
==============================================================================
--- trunk/libs/wave/src/instantiate_cpp_literalgrs.cpp (original)
+++ trunk/libs/wave/src/instantiate_cpp_literalgrs.cpp 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -41,7 +41,11 @@
 
 // no need to change anything below
 template struct boost::wave::grammars::intlit_grammar_gen<token_type>;
-template struct boost::wave::grammars::chlit_grammar_gen<token_type>;
+#if BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_AUTOSELECT || \
+ BOOST_WAVE_WCHAR_T_SIGNEDNESS == BOOST_WAVE_WCHAR_T_FORCE_SIGNED
+template struct boost::wave::grammars::chlit_grammar_gen<int, token_type>;
+#endif
+template struct boost::wave::grammars::chlit_grammar_gen<unsigned int, token_type>;
 
 // the suffix header occurs after all of the code
 #ifdef BOOST_HAS_ABI_HEADERS

Modified: trunk/tools/wave/trace_macro_expansion.hpp
==============================================================================
--- trunk/tools/wave/trace_macro_expansion.hpp (original)
+++ trunk/tools/wave/trace_macro_expansion.hpp 2011-05-25 14:32:51 EDT (Wed, 25 May 2011)
@@ -17,6 +17,7 @@
 #include <ostream>
 #include <string>
 #include <stack>
+#include <set>
 
 #include <boost/assert.hpp>
 #include <boost/config.hpp>
@@ -161,8 +162,6 @@
         default_outfile(default_outfile_),
         emit_relative_filenames(false)
     {
- using namespace std; // some systems have time in namespace std
- time(&started_at);
     }
     ~trace_macro_expansion()
     {
@@ -1046,11 +1045,14 @@
         // ensure all directories for this file do exist
         fs::create_directories(boost::wave::util::branch_path(fpath));
 
- // figure out, whether the file to open was last accessed by us
+ // figure out, whether the file has been written to by us, if yes, we
+ // append any output to this file, otherwise we overwrite it
         std::ios::openmode mode = std::ios::out;
- if (fs::exists(fpath) && fs::last_write_time(fpath) >= started_at)
+ if (fs::exists(fpath) && written_by_us.find(fpath) != written_by_us.end())
             mode = (std::ios::openmode)(std::ios::out | std::ios::app);
 
+ written_by_us.insert(fpath);
+
         // close the current file
         if (outputstrm.is_open())
             outputstrm.close();
@@ -1460,7 +1462,7 @@
     boost::filesystem::path current_outfile; // name of the current output file
 
     stop_watch elapsed_time; // trace timings
- std::time_t started_at; // time, this process was started at
+ std::set<boost::filesystem::path> written_by_us; // all files we have written to
 
     typedef std::pair<bool, boost::filesystem::path> output_option_type;
     std::stack<output_option_type> output_options; // output option stack


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk