diff --git a/ChangeLog b/ChangeLog index f9fb52a..891608c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -343,7 +343,9 @@ Sat Dec 24 13:33:53 CST 2005 - Added the get_severity() function to the exceptions thrown by the Wave library. - Extended the copyright notice to include the year 2006. - +- Fixed a problem in preserve=1 mode, when a C style comment triggered the + generation of a #line directive. + Mon Dec 5 22:05:22 CST 2005 Boost V1.33.1 - Version 1.2.1 diff --git a/doc/supported_pragmas.html b/doc/supported_pragmas.html index 6b640cd..ca06589 100644 --- a/doc/supported_pragmas.html +++ b/doc/supported_pragmas.html @@ -107,7 +107,7 @@

The option(line: ...) directive allows to control, whether #line directives will be generated in the output stream. Specify either '0' or '1' as the option parameter. All other values will be flaged as illegal.

The option(preserve: ...) directive allows to control the amount of whitespace generated in the output stream. The value '0' removes any not needed whitespace, the value '1' keeps comments only and the value '2' does not remove any whitespace.

The option(output: ...) directive allows to specify the name of the file, where the output is generated to. Specify either a valid filename (which will be interpreted relative to directory of the processed file), the value null to disable the output at all, or the value default to use the output as specified on the command line using the --output/-o option.

-

The pragma values push and pop may be used for all of the options (line, preserve and output) to store and restore the current value of the corresponding option .

+

The pragma values push and pop may be used for all of the options (line, preserve and output) to store and restore the current value of the corresponding option.

All pragma's not listed here but flagged as 'wave' are currently reported as @@ -134,7 +134,7 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

 

diff --git a/include/boost/wave/util/cpp_iterator.hpp b/include/boost/wave/util/cpp_iterator.hpp index edbe955..9fe6d21 100644 --- a/include/boost/wave/util/cpp_iterator.hpp +++ b/include/boost/wave/util/cpp_iterator.hpp @@ -505,15 +505,13 @@ pp_iterator_functor::operator()() seen_newline = false; switch (static_cast(id)) { case T_NONREPLACABLE_IDENTIFIER: - act_token.set_token_id(T_IDENTIFIER); - id = T_IDENTIFIER; + act_token.set_token_id(id = T_IDENTIFIER); break; - case T_GENERATEDNEWLINE: // was generated by emit_line_directive() - act_token.set_token_id(T_NEWLINE); + case T_GENERATEDNEWLINE: // was generated by emit_line_directive() + act_token.set_token_id(id = T_NEWLINE); ++iter_ctx->emitted_lines; seen_newline = true; - id = T_NEWLINE; break; case T_NEWLINE: @@ -522,9 +520,13 @@ pp_iterator_functor::operator()() ++iter_ctx->emitted_lines; break; - case T_PP_NUMBER: + case T_CCOMMENT: // will come here only if whitespace is preserved + iter_ctx->emitted_lines += + context_policies::util::ccomment_count_newlines(act_token); + break; + + case T_PP_NUMBER: // re-tokenize the pp-number { - // re-tokenize the pp-number token_sequence_type rescanned; std::string pp_number(act_token.get_value().c_str()); @@ -546,8 +548,7 @@ pp_iterator_functor::operator()() seen_newline = true; break; - default: - // make sure whitespace at line begin keeps seen_newline status + default: // make sure whitespace at line begin keeps seen_newline status if (IS_CATEGORY(id, WhiteSpaceTokenType)) seen_newline = skipped_newline; break; @@ -815,6 +816,7 @@ token_id id = token_id(*iter_ctx->first); } while (T_PLACEHOLDER == id); + act_pos = act_token.get_position(); return act_token; } diff --git a/include/boost/wave/whitespace_handling.hpp b/include/boost/wave/whitespace_handling.hpp index 3c7ca50..b546a0a 100644 --- a/include/boost/wave/whitespace_handling.hpp +++ b/include/boost/wave/whitespace_handling.hpp @@ -29,20 +29,40 @@ namespace context_policies { namespace util { /////////////////////////////////////////////////////////////////////////// + // This function returns true if the given C style comment contains at + // least one newline template bool ccomment_has_newline(TokenT const& token) { using namespace boost::wave; - if (T_CCOMMENT == token_id(token)) { - if (TokenT::string_type::npos != - token.get_value().find_first_of("\n")) - { - return true; - } + if (T_CCOMMENT == token_id(token) && + TokenT::string_type::npos != token.get_value().find_first_of("\n")) + { + return true; } return false; } + + /////////////////////////////////////////////////////////////////////////// + // This function returns the number of newlines in the given C style + // comment + template + int ccomment_count_newlines(TokenT const& token) + { + using namespace boost::wave; + int newlines = 0; + if (T_CCOMMENT == token_id(token)) { + TokenT::string_type const& value = token.get_value(); + TokenT::string_type::size_type p = value.find_first_of("\n"); + + while (TokenT::string_type::npos != p) { + ++newlines; + p = value.find_first_of("\n", p+1); + } + } + return newlines; + } } ///////////////////////////////////////////////////////////////////////////////