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

Added new preprocessing hook function: found_line_directive() to be called when a #line directive is encountered.

[SVN r34393]
This commit is contained in:
Hartmut Kaiser
2006-06-25 17:17:28 +00:00
parent ed8761fe72
commit 705dacbd48
4 changed files with 72 additions and 17 deletions

View File

@@ -481,8 +481,8 @@ struct default_preprocessing_hooks
#if BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE != 0
///////////////////////////////////////////////////////////////////////////
//
// The function 'found_warning_directive' is called, will be called by the
// library, whenever a #warning directive is found.
// The function 'found_warning_directive' will be called by the library
// whenever a #warning directive is found.
//
// The parameter 'ctx' is a reference to the context object used for
// instantiating the preprocessing iterators by the user.
@@ -499,8 +499,8 @@ struct default_preprocessing_hooks
///////////////////////////////////////////////////////////////////////////
//
// The function 'found_error_directive' is called, will be called by the
// library, whenever a #error directive is found.
// The function 'found_error_directive' will be called by the library
// whenever a #error directive is found.
//
// The parameter 'ctx' is a reference to the context object used for
// instantiating the preprocessing iterators by the user.
@@ -513,6 +513,30 @@ struct default_preprocessing_hooks
bool
found_error_directive(ContextT const& ctx, ContainerT const& message)
{ return false; }
///////////////////////////////////////////////////////////////////////////
//
// The function 'found_line_directive' will be called by the library
// whenever a #line directive is found.
//
// The parameter 'ctx' is a reference to the context object used for
// instantiating the preprocessing iterators by the user.
//
// The parameter 'arguments' references the argument token sequence of the
// encountered #line directive.
//
// The parameter 'line' contains the recognized line number from the #line
// directive.
//
// The parameter 'filename' references the recognized file name from the
// #line directive (if there was one given).
//
///////////////////////////////////////////////////////////////////////////
template <typename ContextT, typename ContainerT>
void
found_line_directive(ContextT const& ctx, ContainerT const& arguments,
unsigned int line, std::string const& filename)
{}
};
///////////////////////////////////////////////////////////////////////////////

View File

@@ -1744,13 +1744,14 @@ namespace {
template <typename IteratorT, typename StringT>
bool retrieve_line_info (IteratorT first, IteratorT const &last,
int &line, StringT &file)
unsigned int &line, StringT &file)
{
using namespace boost::wave;
if (T_PP_NUMBER == token_id(*first)) {
token_id id = token_id(*first);
if (T_PP_NUMBER == id || T_INTLIT == id) {
// extract line number
using namespace std; // some systems have atoi in namespace std
line = atoi((*first).get_value().c_str());
line = (unsigned int)atoi((*first).get_value().c_str());
// extract file name (if it is given)
while (++first != last && IS_CATEGORY(*first, WhiteSpaceTokenType))
@@ -1797,15 +1798,13 @@ const_tree_iterator_t last = make_ref_transform_iterator(end, get_value);
// try to interpret the #line body as a number followed by an optional
// string literal
int line = 0;
unsigned int line = 0;
string_type file_name;
token_sequence_type toexpand;
std::copy(first, last, std::inserter(toexpand, toexpand.end()));
if (!retrieve_line_info(first, last, line, file_name)) {
// preprocess the body of this #line message
token_sequence_type toexpand;
std::copy(first, make_ref_transform_iterator(end, get_value),
std::inserter(toexpand, toexpand.end()));
typename token_sequence_type::iterator begin2 = toexpand.begin();
ctx.expand_whole_tokensequence(begin2, toexpand.end(),
@@ -1817,6 +1816,15 @@ string_type file_name;
BOOST_WAVE_THROW(preprocess_exception, bad_line_statement,
boost::wave::util::impl::as_string(expanded).c_str(), act_pos)
}
// call the corresponding pp hook function
ctx.get_hooks().found_line_directive(ctx, expanded, line,
file_name.c_str());
}
else {
// call the corresponding pp hook function
ctx.get_hooks().found_line_directive(ctx, toexpand, line,
file_name.c_str());
}
// the queues should be empty at this point