2
0
mirror of https://github.com/boostorg/wave.git synced 2026-02-12 00:32:17 +00:00

Wave: Fixed a problem in preserve=1 mode, when a C style comment triggered the generation of a #line directive.

[SVN r36710]
This commit is contained in:
Hartmut Kaiser
2007-01-12 19:44:19 +00:00
parent 836feceeb1
commit 45dec9c8a3
4 changed files with 42 additions and 18 deletions

View File

@@ -505,15 +505,13 @@ pp_iterator_functor<ContextT>::operator()()
seen_newline = false;
switch (static_cast<unsigned int>(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<ContextT>::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<ContextT>::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;
}

View File

@@ -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 <typename TokenT>
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 <typename TokenT>
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;
}
}
///////////////////////////////////////////////////////////////////////////////