|
Boost-Commit : |
From: hartmut.kaiser_at_[hidden]
Date: 2008-04-03 21:22:12
Author: hkaiser
Date: 2008-04-03 21:22:12 EDT (Thu, 03 Apr 2008)
New Revision: 44023
URL: http://svn.boost.org/trac/boost/changeset/44023
Log:
Wave: Some updates to the new 'preprocess_pragma_output' example. This fixes ticket #1752.
Text files modified:
trunk/boost/wave/util/macro_helpers.hpp | 18 +++++++++---
trunk/libs/wave/samples/preprocess_pragma_output/example.cpp | 11 ++++---
trunk/libs/wave/samples/preprocess_pragma_output/preprocess_pragma_output.hpp | 55 ++++++++++++++++++++++++++++++++++-----
trunk/tools/build/v2/user-config.jam | 12 ++++++++
4 files changed, 78 insertions(+), 18 deletions(-)
Modified: trunk/boost/wave/util/macro_helpers.hpp
==============================================================================
--- trunk/boost/wave/util/macro_helpers.hpp (original)
+++ trunk/boost/wave/util/macro_helpers.hpp 2008-04-03 21:22:12 EDT (Thu, 03 Apr 2008)
@@ -63,13 +63,21 @@
typename StringT::size_type pos1 = value.find_first_of ("\\", 0);
if (StringT::npos != pos1) {
do {
- if ('\\' == value[pos1+1] || '\"' == value[pos1+1] ||
- '?' == value[pos1+1])
- {
+ switch (value[pos1+1]) {
+ case '\\':
+ case '\"':
+ case '?':
result = result + value.substr(pos, pos1-pos);
pos1 = value.find_first_of ("\\", (pos = pos1+1)+1);
- }
- else {
+ break;
+
+ case 'n':
+ result = result + value.substr(pos, pos1-pos) + "\n";
+ pos1 = value.find_first_of ("\\", pos = pos1+1);
+ ++pos;
+ break;
+
+ default:
result = result + value.substr(pos, pos1-pos+1);
pos1 = value.find_first_of ("\\", pos = pos1+1);
}
Modified: trunk/libs/wave/samples/preprocess_pragma_output/example.cpp
==============================================================================
--- trunk/libs/wave/samples/preprocess_pragma_output/example.cpp (original)
+++ trunk/libs/wave/samples/preprocess_pragma_output/example.cpp 2008-04-03 21:22:12 EDT (Thu, 03 Apr 2008)
@@ -11,13 +11,14 @@
=============================================================================*/
///////////////////////////////////////////////////////////////////////////////
-// This special pragma will be analyzed by the corresponding hook function
-// implemented in the preprocess_pragma_output_hooks policy class. This
+// This special pragma is implemented by the interpret_pragma hook function
+// provided in the preprocess_pragma_output_hooks policy class. This
// #pragma preprocesses the provided arguments in the current context.
#pragma wave pp ( \
- #define M() "some text" \
+ "#define A() \"some text\" and more\n" \
+ "#define B() 1.0\n" \
) \
/**/
-M() // this should produce: "some text"
-
+A() // this should produce: "some text" and more
+B() // and this expands to 1.0
Modified: trunk/libs/wave/samples/preprocess_pragma_output/preprocess_pragma_output.hpp
==============================================================================
--- trunk/libs/wave/samples/preprocess_pragma_output/preprocess_pragma_output.hpp (original)
+++ trunk/libs/wave/samples/preprocess_pragma_output/preprocess_pragma_output.hpp 2008-04-03 21:22:12 EDT (Thu, 03 Apr 2008)
@@ -13,6 +13,41 @@
#if !defined(BOOST_WAVE_SAMPLE_PREPROCESS_PRAGMA_OUTPUT_APR_03_2008_0813AM)
#define BOOST_WAVE_SAMPLE_PREPROCESS_PRAGMA_OUTPUT_APR_03_2008_0813AM
+template <typename String, typename Iterator>
+inline String
+as_unescaped_string(Iterator it, Iterator const& end)
+{
+ using namespace boost::wave;
+
+ String result;
+ for (/**/; it != end; ++it)
+ {
+ switch (token_id(*it)) {
+ case T_STRINGLIT:
+ {
+ string val (util::impl::unescape_lit((*it).get_value()).c_str());
+ val.erase(val.size()-1);
+ val.erase(0, 1);
+ result += val;
+ }
+ break;
+
+ default: // just skip everything else (hey it's a sample)
+ break;
+ }
+ }
+ return result;
+}
+
+// return the string representation of a token sequence
+template <typename String, typename Container>
+inline String
+as_unescaped_string(Container const &token_sequence)
+{
+ return as_unescaped_string<String>(token_sequence.begin(),
+ token_sequence.end());
+}
+
///////////////////////////////////////////////////////////////////////////////
//
// The preprocess_pragma_output_hooks policy class is used implement a special
@@ -83,19 +118,25 @@
typedef typename Context::token_type token_type;
typedef typename Context::iterator_type iterator_type;
- if (option.get_value() == "pp")
- {
+ if (option.get_value() == "pp") {
+ // Concatenate the string(s) passed as the options to this pragma,
+ // preprocess the result using the current context and insert the
+ // generated token sequence in place of the pragma directive into the
+ // output stream.
+
try {
// We're explicitly using a std::string here since the type of the
// iterators passed to the ctx.begin() below must match the types
// of the iterator the original context instance has been created
// with.
- std::string s (boost::wave::util::impl::as_string(values).c_str());
+ std::string s (as_unescaped_string<std::string>(values));
reset_language_support<Context> lang(ctx);
- using boost::wave::token_id;
- using boost::wave::T_EOF;
-
+ using namespace boost::wave;
+
+ // The expanded token sequence is stored in the 'pragma' container
+ // to ensure consistency in the output in the case of an error
+ // while preprocessing the pragma option strings.
Container pragma;
iterator_type end = ctx.end();
for (iterator_type it = ctx.begin(s.begin(), s.end());
@@ -109,7 +150,7 @@
// container
pending.splice(pending.begin(), pragma);
}
- catch (boost::wave::preprocess_exception const& e) {
+ catch (boost::wave::preprocess_exception const& /*e*/) {
// the library will report an 'ill_formed_pragma_option' for us
return false;
}
Modified: trunk/tools/build/v2/user-config.jam
==============================================================================
--- trunk/tools/build/v2/user-config.jam (original)
+++ trunk/tools/build/v2/user-config.jam 2008-04-03 21:22:12 EDT (Thu, 03 Apr 2008)
@@ -51,7 +51,7 @@
# Configure msvc (default version, searched in standard location
# and PATH).
-# using msvc ;
+using msvc : 8.0 : ;
# Borland configuration
# using borland ;
@@ -76,3 +76,13 @@
# Configure with explicit installation prefix
# using qt : /usr/opt/qt ;
+# XSLT configuration
+using xsltproc
+ : "C:/Downloads/C++/Boost/boost.book/xsltproc-win32/xsltproc.exe"
+ ;
+
+# BoostBook configuration
+using boostbook
+ : "C:/Downloads/C++/Boost/boost.book/docbook-xsl-1.66.1"
+ : "C:/Downloads/C++/Boost/boost.book/docbook-xml-4.2"
+ ;
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