diff --git a/ChangeLog b/ChangeLog index e875a30..586d53d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,10 +38,13 @@ CHANGELOG something not equal zero. - Added new preprocessing hook functions: found_error_directive() and found_warning_directive() to be called when #error/#warning directives are - encountered. + encountered. This was suggested by Andreas Sæbjørnsen. - Added a new sample to Wave: hannibal, a partial C++ parser implementation initially written by Danny Havenith (http://havenith-verlinden.nl/hannibal/) who agreed to add this here. Thanks! +- Added new preprocessing hook function: found_line_directive() to be called + when a #line directive is encountered. This was suggested by Andreas + Sæbjørnsen. Boost V1.34.0 - Wave Version 1.2.4 diff --git a/doc/class_reference_ctxpolicy.html b/doc/class_reference_ctxpolicy.html index 81dd540..e839455 100644 --- a/doc/class_reference_ctxpolicy.html +++ b/doc/class_reference_ctxpolicy.html @@ -129,11 +129,17 @@ // #error and #warning directive hooks template <typename ContextT, typename ContainerT> bool found_warning_directive(ContextT const &ctx, - ContainerT const &pending); + ContainerT const &message); template <typename ContextT, typename ContainerT> - bool found_error_directive(ContextT const &ctx, - ContainerT const &pending); + bool found_error_directive(ContextT const &ctx, + ContainerT const &message); + + // #line directive hook + template <typename ContextT, typename ContainerT> + bool found_line_directive(ContextT const &ctx, + ContainerT const &arguments, unsigned int line, + std::string const& filename); }; }}} // namespace boost::wave::context_policies @@ -395,6 +401,20 @@

The parameter message references the argument token sequence of the encountered #error directive.

+

found_line_drective

+
    template <typename ContextT, typename ContainerT>
+    void found_error_directive(ContextT const& ctx, 
+        ContainerT const &arguments, unsigned int line,
+        std::string const& filename);
+
+
+

The function found_line_directive is called whenever a #line directive has been encountered. Note, this functions was added for the Boost V1.35.0 release.

+

The ctx parameter provides a reference to the context_type used during instantiation of 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).
+

+
@@ -408,7 +428,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/preprocessing_hooks.hpp b/include/boost/wave/preprocessing_hooks.hpp index 8fe2f85..24d4f33 100644 --- a/include/boost/wave/preprocessing_hooks.hpp +++ b/include/boost/wave/preprocessing_hooks.hpp @@ -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 + void + found_line_directive(ContextT const& ctx, ContainerT const& arguments, + unsigned int line, std::string const& filename) + {} }; /////////////////////////////////////////////////////////////////////////////// diff --git a/include/boost/wave/util/cpp_iterator.hpp b/include/boost/wave/util/cpp_iterator.hpp index 43855bf..8375103 100644 --- a/include/boost/wave/util/cpp_iterator.hpp +++ b/include/boost/wave/util/cpp_iterator.hpp @@ -1744,13 +1744,14 @@ namespace { template 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