Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71779 - in trunk: boost/wave libs/wave tools/wave
From: hartmut.kaiser_at_[hidden]
Date: 2011-05-07 11:13:46


Author: hkaiser
Date: 2011-05-07 11:13:45 EDT (Sat, 07 May 2011)
New Revision: 71779
URL: http://svn.boost.org/trac/boost/changeset/71779

Log:
Wave: added new command line option --noexpand/-N
Text files modified:
   trunk/boost/wave/cpp_context.hpp | 2 +-
   trunk/libs/wave/ChangeLog | 7 +++++++
   trunk/tools/wave/cpp.cpp | 18 ++++++++++++++++++
   trunk/tools/wave/cpp_version.hpp | 4 ++--
   trunk/tools/wave/trace_macro_expansion.hpp | 35 +++++++++++++++++++++++++++++++----
   5 files changed, 59 insertions(+), 7 deletions(-)

Modified: trunk/boost/wave/cpp_context.hpp
==============================================================================
--- trunk/boost/wave/cpp_context.hpp (original)
+++ trunk/boost/wave/cpp_context.hpp 2011-05-07 11:13:45 EDT (Sat, 07 May 2011)
@@ -100,7 +100,7 @@
 // concept checks
 // the given iterator should be at least a forward iterator type
     BOOST_CLASS_REQUIRE(IteratorT, boost, ForwardIteratorConcept);
-
+
 // public typedefs
     typedef typename LexIteratorT::token_type token_type;
     typedef typename token_type::string_type string_type;

Modified: trunk/libs/wave/ChangeLog
==============================================================================
--- trunk/libs/wave/ChangeLog (original)
+++ trunk/libs/wave/ChangeLog 2011-05-07 11:13:45 EDT (Sat, 07 May 2011)
@@ -28,6 +28,13 @@
   (t_9_020.cpp)
 - Added a new preprocessing hook: locate_include_file allowing to customize the
   way include files are located.
+- Added new command line option --noexpand/-N to the Wave driver allowing to
+ suppress macro expansion for a given macro name (works for both, object like
+ and function like macros). This option has to be used very carefully as it
+ not only leaves the whole macro invocation untouched in the generated output
+ but also removes this macro from consideration for Wave itself. This can
+ cause unexpected results if the suppressed macro would influence #ifdef's
+ later on.
 
 Boost V1.46.0
 - V2.2.0

Modified: trunk/tools/wave/cpp.cpp
==============================================================================
--- trunk/tools/wave/cpp.cpp (original)
+++ trunk/tools/wave/cpp.cpp 2011-05-07 11:13:45 EDT (Sat, 07 May 2011)
@@ -979,6 +979,20 @@
             }
         }
 
+#if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS == 0
+ // suppress expansion of, specified macros
+ if (vm.count("noexpand")) {
+ vector<std::string> const &noexpandmacros =
+ vm["noexpand"].as<vector<std::string> >();
+ vector<std::string>::const_iterator end = noexpandmacros.end();
+ for (vector<std::string>::const_iterator cit = noexpandmacros.begin();
+ cit != end; ++cit)
+ {
+ ctx.get_hooks().add_noexpandmacro(*cit);
+ }
+ }
+#endif
+
     // maximal include nesting depth
         if (vm.count("nesting")) {
             int max_depth = vm["nesting"].as<int>();
@@ -1236,6 +1250,10 @@
                 "specify a macro to predefine (as macro[=[value]])")
             ("undefine,U", po::value<vector<std::string> >()->composing(),
                 "specify a macro to undefine")
+#if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS == 0
+ ("noexpand,N", po::value<vector<std::string> >()->composing(),
+ "specify a macro name, which should not be expanded")
+#endif
             ("nesting,n", po::value<int>(),
                 "specify a new maximal include nesting depth")
         ;

Modified: trunk/tools/wave/cpp_version.hpp
==============================================================================
--- trunk/tools/wave/cpp_version.hpp (original)
+++ trunk/tools/wave/cpp_version.hpp 2011-05-07 11:13:45 EDT (Sat, 07 May 2011)
@@ -19,7 +19,7 @@
 
 #define CPP_VERSION_FULL_STR BOOST_PP_STRINGIZE(CPP_VERSION_FULL)
 
-#define CPP_VERSION_DATE 20110109L
-#define CPP_VERSION_DATE_STR "20110109"
+#define CPP_VERSION_DATE 20110507L
+#define CPP_VERSION_DATE_STR "20110507"
 
 #endif // !defined(CPP_VERSION_HPP_CE4FE67F_63F9_468D_8364_C855F89D3C5D_INCLUDED)

Modified: trunk/tools/wave/trace_macro_expansion.hpp
==============================================================================
--- trunk/tools/wave/trace_macro_expansion.hpp (original)
+++ trunk/tools/wave/trace_macro_expansion.hpp 2011-05-07 11:13:45 EDT (Sat, 07 May 2011)
@@ -186,6 +186,12 @@
         return emit_relative_filenames;
     }
 
+ // add a macro name, which should not be expanded at all (left untouched)
+ void add_noexpandmacro(std::string const& name)
+ {
+ noexpandmacros.insert(name);
+ }
+
     ///////////////////////////////////////////////////////////////////////////
     //
     // The function 'expanding_function_like_macro' is called whenever a
@@ -213,6 +219,11 @@
     // invocation (starting with the opening parenthesis and ending after the
     // closing one).
     //
+ // The return value defines whether the corresponding macro will be
+ // expanded (return false) or will be copied to the output (return true).
+ // Note: the whole argument list is copied unchanged to the output as well
+ // without any further processing.
+ //
     ///////////////////////////////////////////////////////////////////////////
 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
     // old signature
@@ -237,8 +248,15 @@
         TokenT const &macrocall, std::vector<ContainerT> const &arguments,
         IteratorT const& seqstart, IteratorT const& seqend)
     {
- if (enabled_macro_counting())
- count_invocation(macrodef.get_value().c_str());
+ if (enabled_macro_counting() || !noexpandmacros.empty()) {
+ std::string name (macrodef.get_value().c_str());
+
+ if (noexpandmacros.find(name.c_str()) != noexpandmacros.end())
+ return true; // do not expand this macro
+
+ if (enabled_macro_counting())
+ count_invocation(name.c_str());
+ }
 
         if (!enabled_macro_tracing())
             return false;
@@ -356,8 +374,15 @@
         TokenT const &macrodef, ContainerT const &definition,
         TokenT const &macrocall)
     {
- if (enabled_macro_counting())
- count_invocation(macrodef.get_value().c_str());
+ if (enabled_macro_counting() || !noexpandmacros.empty()) {
+ std::string name (macrodef.get_value().c_str());
+
+ if (noexpandmacros.find(name.c_str()) != noexpandmacros.end())
+ return true; // do not expand this macro
+
+ if (enabled_macro_counting())
+ count_invocation(name.c_str());
+ }
 
         if (!enabled_macro_tracing())
             return false;
@@ -1444,6 +1469,8 @@
 
     std::map<std::string, std::size_t> counts; // macro invocation counts
     bool emit_relative_filenames; // emit relative names in #line directives
+
+ std::set<std::string> noexpandmacros; // list of macros not to expand
 };
 
 #undef BOOST_WAVE_GETSTRING


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