Boost logo

Boost-Commit :

From: hartmut.kaiser_at_[hidden]
Date: 2008-03-07 09:12:05


Author: hkaiser
Date: 2008-03-07 09:12:04 EST (Fri, 07 Mar 2008)
New Revision: 43536
URL: http://svn.boost.org/trac/boost/changeset/43536

Log:
Wave: more fixes for #1673
Text files modified:
   branches/release/boost/wave/cpp_context.hpp | 4 +-
   branches/release/boost/wave/util/cpp_iterator.hpp | 14 ++++----
   branches/release/boost/wave/util/cpp_macromap.hpp | 58 ++++++++++++++++++++++-----------------
   branches/release/boost/wave/util/cpp_macromap_utils.hpp | 7 +++-
   branches/release/tools/wave/build/Jamfile.v2 | 1
   5 files changed, 47 insertions(+), 37 deletions(-)

Modified: branches/release/boost/wave/cpp_context.hpp
==============================================================================
--- branches/release/boost/wave/cpp_context.hpp (original)
+++ branches/release/boost/wave/cpp_context.hpp 2008-03-07 09:12:04 EST (Fri, 07 Mar 2008)
@@ -332,10 +332,10 @@
     template <typename IteratorT2>
     token_type expand_tokensequence(IteratorT2 &first_, IteratorT2 const &last_,
         token_sequence_type &pending, token_sequence_type &expanded,
- bool expand_undefined = false)
+ bool& seen_newline, bool expand_undefined = false)
     {
         return macros.expand_tokensequence(first_, last_, pending, expanded,
- expand_undefined);
+ seen_newline, expand_undefined);
     }
 
     template <typename IteratorT2>

Modified: branches/release/boost/wave/util/cpp_iterator.hpp
==============================================================================
--- branches/release/boost/wave/util/cpp_iterator.hpp (original)
+++ branches/release/boost/wave/util/cpp_iterator.hpp 2008-03-07 09:12:04 EST (Fri, 07 Mar 2008)
@@ -284,7 +284,7 @@
     
 protected:
     result_type const &get_next_token();
- result_type const &pp_token(bool consider_emitting_line_directive = false);
+ result_type const &pp_token();
 
     bool pp_directive();
     template <typename IteratorT>
@@ -340,6 +340,7 @@
     boost::shared_ptr<base_iteration_context_type> iter_ctx;
     
     bool seen_newline; // needed for recognizing begin of line
+ bool skipped_newline; // a newline has been skipped since last one
     bool must_emit_line_directive; // must emit a line directive
     result_type act_token; // current token
     typename result_type::position_type &act_pos; // current fileposition (references the macromap)
@@ -463,14 +464,13 @@
     ctx.init_context();
     
     // loop over skip able whitespace until something significant is found
- bool skipped_newline = false;
     bool was_seen_newline = seen_newline;
     token_id id = T_UNKNOWN;
         
     try { // catch lexer exceptions
         do {
         // get_next_token assigns result to act_token member
- if (!seen_newline && skipped_newline)
+ if (skipped_newline)
                 seen_newline = true;
             get_next_token();
 
@@ -553,7 +553,7 @@
 
     default: // make sure whitespace at line begin keeps seen_newline status
         if (IS_CATEGORY(id, WhiteSpaceTokenType))
- seen_newline = skipped_newline;
+ seen_newline = was_seen_newline;
         break;
     }
 
@@ -657,7 +657,7 @@
             else if (ctx.get_if_block_status()) {
             // preprocess this token, eat up more, if appropriate, return
             // the next preprocessed token
- return pp_token(was_seen_newline);
+ return pp_token();
             }
             else {
             // compilation condition is false: if the current token is a
@@ -785,7 +785,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 template <typename ContextT>
 inline typename pp_iterator_functor<ContextT>::result_type const &
-pp_iterator_functor<ContextT>::pp_token(bool consider_emitting_line_directive)
+pp_iterator_functor<ContextT>::pp_token()
 {
     using namespace boost::wave;
 
@@ -809,7 +809,7 @@
         // call the lexer, preprocess the required number of tokens, put them
         // into the unput queue
             act_token = ctx.expand_tokensequence(iter_ctx->first,
- iter_ctx->last, pending_queue, unput_queue);
+ iter_ctx->last, pending_queue, unput_queue, skipped_newline);
         }
         else {
         // simply return the next token

Modified: branches/release/boost/wave/util/cpp_macromap.hpp
==============================================================================
--- branches/release/boost/wave/util/cpp_macromap.hpp (original)
+++ branches/release/boost/wave/util/cpp_macromap.hpp 2008-03-07 09:12:04 EST (Fri, 07 Mar 2008)
@@ -121,7 +121,7 @@
     template <typename IteratorT, typename ContainerT>
     token_type const &expand_tokensequence(IteratorT &first,
         IteratorT const &last, ContainerT &pending, ContainerT &expanded,
- bool expand_operator_defined);
+ bool& seen_newline, bool expand_operator_defined);
 
 // Expand all macros inside the given token sequence
     template <typename IteratorT, typename ContainerT>
@@ -159,27 +159,29 @@
     token_type const &expand_tokensequence_worker(ContainerT &pending,
         unput_queue_iterator<IteratorT, token_type, ContainerT> &first,
         unput_queue_iterator<IteratorT, token_type, ContainerT> const &last,
- bool expand_operator_defined);
+ bool& seen_newline, bool expand_operator_defined);
 
 // Collect all arguments supplied to a macro invocation
 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
     template <typename IteratorT, typename ContainerT, typename SizeT>
     typename std::vector<ContainerT>::size_type collect_arguments (
         token_type const curr_token, std::vector<ContainerT> &arguments,
- IteratorT &next, IteratorT const &end, SizeT const &parameter_count);
+ IteratorT &next, IteratorT const &end, SizeT const &parameter_count,
+ bool& seen_newline);
 #else
     template <typename IteratorT, typename ContainerT, typename SizeT>
     typename std::vector<ContainerT>::size_type collect_arguments (
         token_type const curr_token, std::vector<ContainerT> &arguments,
         IteratorT &next, IteratorT &endparen, IteratorT const &end,
- SizeT const &parameter_count);
+ SizeT const &parameter_count, bool& seen_newline);
 #endif
 
 // Expand a single macro name
     template <typename IteratorT, typename ContainerT>
     bool expand_macro(ContainerT &pending, token_type const &name,
         typename defined_macros_type::iterator it,
- IteratorT &first, IteratorT const &last, bool expand_operator_defined,
+ IteratorT &first, IteratorT const &last,
+ bool& seen_newline, bool expand_operator_defined,
         defined_macros_type *scope = 0, ContainerT *queue_symbol = 0);
 
 // Expand a predefined macro (__LINE__, __FILE__ and __INCLUDE_LEVEL__)
@@ -216,7 +218,7 @@
 // Resolve operator _Pragma or the #pragma directive
     template <typename IteratorT, typename ContainerT>
     bool resolve_operator_pragma(IteratorT &first,
- IteratorT const &last, ContainerT &expanded);
+ IteratorT const &last, ContainerT &expanded, bool& seen_newline);
 
 // Handle the concatenation operator '##'
     template <typename ContainerT>
@@ -530,7 +532,7 @@
 inline typename ContextT::token_type const &
 macromap<ContextT>::expand_tokensequence(IteratorT &first,
     IteratorT const &last, ContainerT &pending, ContainerT &expanded,
- bool expand_operator_defined)
+ bool& seen_newline, bool expand_operator_defined)
 {
     typedef impl::gen_unput_queue_iterator<IteratorT, token_type, ContainerT>
         gen_type;
@@ -542,7 +544,7 @@
 on_exit::assign<IteratorT, iterator_type> on_exit(first, first_it);
 
     return expand_tokensequence_worker(pending, first_it, last_it,
- expand_operator_defined);
+ seen_newline, expand_operator_defined);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -564,7 +566,7 @@
     ContainerT &pending,
     unput_queue_iterator<IteratorT, token_type, ContainerT> &first,
     unput_queue_iterator<IteratorT, token_type, ContainerT> const &last,
- bool expand_operator_defined)
+ bool& seen_newline, bool expand_operator_defined)
 {
 // if there exist pending tokens (tokens, which are already preprocessed), then
 // return the next one from there
@@ -607,7 +609,7 @@
             // in C99 mode only: resolve the operator _Pragma
             token_type curr_token = *first;
             
- if (!resolve_operator_pragma(first, last, pending) ||
+ if (!resolve_operator_pragma(first, last, pending, seen_newline) ||
                     pending.size() > 0)
                 {
                 // unknown to us pragma or supplied replacement, return the
@@ -629,7 +631,7 @@
             // the current token contains an identifier, which is currently
             // defined as a macro
                 if (expand_macro(pending, name_token, it, first, last,
- expand_operator_defined))
+ seen_newline, expand_operator_defined))
                 {
                 // the tokens returned by expand_macro should be rescanned
                 // beginning at the last token of the returned replacement list
@@ -657,7 +659,7 @@
 
             // return the next preprocessed token
                 return expand_tokensequence_worker(pending, first, last,
- expand_operator_defined);
+ seen_newline, expand_operator_defined);
             }
 // else if (expand_operator_defined) {
 // // in preprocessing conditionals undefined identifiers and keywords
@@ -702,14 +704,14 @@
 inline typename std::vector<ContainerT>::size_type
 macromap<ContextT>::collect_arguments (token_type const curr_token,
     std::vector<ContainerT> &arguments, IteratorT &next,
- IteratorT const &end, SizeT const &parameter_count)
+ IteratorT const &end, SizeT const &parameter_count, bool& seen_newline)
 #else
 template <typename ContextT>
 template <typename IteratorT, typename ContainerT, typename SizeT>
 inline typename std::vector<ContainerT>::size_type
 macromap<ContextT>::collect_arguments (token_type const curr_token,
     std::vector<ContainerT> &arguments, IteratorT &next, IteratorT &endparen,
- IteratorT const &end, SizeT const &parameter_count)
+ IteratorT const &end, SizeT const &parameter_count, bool& seen_newline)
 #endif
 {
     using namespace boost::wave;
@@ -805,10 +807,12 @@
             was_whitespace = false;
             break;
 
+ case T_NEWLINE:
+ seen_newline = true;
+ /* fall through */
         case T_SPACE:
         case T_SPACE2:
         case T_CCOMMENT:
- case T_NEWLINE:
             if (!was_whitespace)
                 argument->push_back(token_type(T_SPACE, " ", (*next).get_position()));
             was_whitespace = true;
@@ -863,10 +867,11 @@
 
 on_exit::assign<IteratorT, iterator_type> on_exit(first, first_it);
 ContainerT pending_queue;
+bool seen_newline;
     
     while (!pending_queue.empty() || first_it != last_it) {
         token_type t = expand_tokensequence_worker(pending_queue, first_it,
- last_it, expand_operator_defined);
+ last_it, seen_newline, expand_operator_defined);
 
         expanded.push_back(t);
     }
@@ -1146,8 +1151,8 @@
 macromap<ContextT>::expand_macro(ContainerT &expanded,
     token_type const &curr_token, typename defined_macros_type::iterator it,
     IteratorT &first, IteratorT const &last,
- bool expand_operator_defined, defined_macros_type *scope,
- ContainerT *queue_symbol)
+ bool& seen_newline, bool expand_operator_defined,
+ defined_macros_type *scope, ContainerT *queue_symbol)
 {
     using namespace boost::wave;
     
@@ -1202,7 +1207,7 @@
 
     if (T_LEFTPAREN == impl::next_token<IteratorT>::peek(first, last)) {
     // called as a function-like macro
- impl::skip_to_token(first, last, T_LEFTPAREN);
+ impl::skip_to_token(first, last, T_LEFTPAREN, seen_newline);
         
 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS == 0
         IteratorT seqstart = first;
@@ -1217,11 +1222,11 @@
 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
         typename std::vector<ContainerT>::size_type count_args =
             collect_arguments (curr_token, arguments, first, last,
- macro_def.macroparameters.size());
+ macro_def.macroparameters.size(), seen_newline);
 #else
         typename std::vector<ContainerT>::size_type count_args =
             collect_arguments (curr_token, arguments, first, seqend, last,
- macro_def.macroparameters.size());
+ macro_def.macroparameters.size(), seen_newline);
 #endif
 
         // verify the parameter count
@@ -1267,7 +1272,7 @@
             if (ctx.get_hooks().expanding_function_like_macro(
                     ctx, macro_def.macroname, macro_def.macroparameters,
                     macro_def.macrodefinition, curr_token, arguments,
- seqend, first))
+ seqstart, seqend))
             {
                 // do not expand this macro, just copy the whole sequence
                 std::copy(seqstart, first,
@@ -1491,12 +1496,12 @@
 template <typename IteratorT, typename ContainerT>
 inline bool
 macromap<ContextT>::resolve_operator_pragma(IteratorT &first,
- IteratorT const &last, ContainerT &pending)
+ IteratorT const &last, ContainerT &pending, bool& seen_newline)
 {
 // isolate the parameter of the operator _Pragma
     token_type pragma_token = *first;
     
- if (!impl::skip_to_token(first, last, T_LEFTPAREN)) {
+ if (!impl::skip_to_token(first, last, T_LEFTPAREN, seen_newline)) {
     // illformed operator _Pragma
         BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, ill_formed_expression,
             "operator _Pragma()", pragma_token.get_position());
@@ -1506,11 +1511,12 @@
     std::vector<ContainerT> arguments;
 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
     typename std::vector<ContainerT>::size_type count_args =
- collect_arguments (pragma_token, arguments, first, last, 1);
+ collect_arguments (pragma_token, arguments, first, last, 1, seen_newline);
 #else
     IteratorT endparen = first;
     typename std::vector<ContainerT>::size_type count_args =
- collect_arguments (pragma_token, arguments, first, endparen, last, 1);
+ collect_arguments (pragma_token, arguments, first, endparen, last, 1,
+ seen_newline);
 #endif
 
 // verify the parameter count

Modified: branches/release/boost/wave/util/cpp_macromap_utils.hpp
==============================================================================
--- branches/release/boost/wave/util/cpp_macromap_utils.hpp (original)
+++ branches/release/boost/wave/util/cpp_macromap_utils.hpp 2008-03-07 09:12:04 EST (Fri, 07 Mar 2008)
@@ -438,7 +438,8 @@
 ///////////////////////////////////////////////////////////////////////////////
 template <typename IteratorT>
 inline bool
-skip_to_token(IteratorT &it, IteratorT const &end, token_id id)
+skip_to_token(IteratorT &it, IteratorT const &end, token_id id,
+ bool& seen_newline)
 {
     using namespace boost::wave;
     if (token_id(*it) == id)
@@ -447,8 +448,10 @@
         return false;
 
     while (IS_CATEGORY(*it, WhiteSpaceTokenType) ||
- T_NEWLINE == token_id(*it))
+ T_NEWLINE == token_id(*it))
     {
+ if (T_NEWLINE == token_id(*it))
+ seen_newline = true;
         if (++it == end)
             return false;
     }

Modified: branches/release/tools/wave/build/Jamfile.v2
==============================================================================
--- branches/release/tools/wave/build/Jamfile.v2 (original)
+++ branches/release/tools/wave/build/Jamfile.v2 2008-03-07 09:12:04 EST (Fri, 07 Mar 2008)
@@ -24,6 +24,7 @@
     /boost//thread
     /boost//date_time
     :
+ <threading>multi
 # <debug-symbols>on
     :
     release


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