|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r66155 - in trunk: boost/wave boost/wave/util tools/wave
From: hartmut.kaiser_at_[hidden]
Date: 2010-10-23 19:12:08
Author: hkaiser
Date: 2010-10-23 19:12:06 EDT (Sat, 23 Oct 2010)
New Revision: 66155
URL: http://svn.boost.org/trac/boost/changeset/66155
Log:
Wave: fixing exception handling
Text files modified:
trunk/boost/wave/cpp_throw.hpp | 261 +++++++++++++++++++++------------------
trunk/boost/wave/util/cpp_iterator.hpp | 17 +
trunk/boost/wave/util/cpp_macromap.hpp | 6
trunk/boost/wave/util/interpret_pragma.hpp | 13 +
trunk/tools/wave/trace_macro_expansion.hpp | 24 ++-
5 files changed, 181 insertions(+), 140 deletions(-)
Modified: trunk/boost/wave/cpp_throw.hpp
==============================================================================
--- trunk/boost/wave/cpp_throw.hpp (original)
+++ trunk/boost/wave/cpp_throw.hpp 2010-10-23 19:12:06 EDT (Sat, 23 Oct 2010)
@@ -14,142 +14,167 @@
#include <string>
#include <boost/throw_exception.hpp>
-///////////////////////////////////////////////////////////////////////////////
-// helper macro for throwing exceptions
-#if !defined(BOOST_WAVE_THROW)
#ifdef BOOST_NO_STRINGSTREAM
#include <strstream>
-#define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
- { \
- using namespace boost::wave; \
- std::strstream stream; \
- stream << cls::severity_text(cls::code) << ": " \
- << cls::error_text(cls::code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- std::string throwmsg = stream.str(); stream.freeze(false); \
- boost::throw_exception(cls(throwmsg.c_str(), cls::code, \
- (act_pos).get_line(), (act_pos).get_column(), \
- (act_pos).get_file().c_str())); \
- } \
- /**/
-#define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos) \
- { \
- using namespace boost::wave; \
- std::strstream stream; \
- stream << cls::severity_text(cls::code) << ": " \
- << cls::error_text(cls::code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- std::string throwmsg = stream.str(); stream.freeze(false); \
- ctx.get_hooks().throw_exception(ctx.derived(), cls(throwmsg.c_str(), \
- cls::code, (act_pos).get_line(), (act_pos).get_column(), \
- (act_pos).get_file().c_str())); \
- } \
- /**/
#else
#include <sstream>
+#endif
+
+namespace boost { namespace wave { namespace util
+{
+#ifdef BOOST_NO_STRINGSTREAM
+ template <typename Exception, typename S1, typename Pos>
+ void throw_(typename Exception::error_code code, S1 msg, Pos const& pos)
+ {
+ std::strstream stream;
+ stream << Exception::severity_text(code) << ": "
+ << Exception::error_text(code);
+ if (msg[0] != 0)
+ stream << ": " << msg;
+ stream << std::ends;
+ std::string throwmsg = stream.str(); stream.freeze(false);
+ boost::throw_exception(Exception(throwmsg.c_str(), code,
+ pos.get_line(), pos.get_column(), pos.get_file().c_str()));
+ }
+
+ template <typename Exception, typename Context, typename S1, typename Pos>
+ void throw_(Context& ctx, typename Exception::error_code code,
+ S1 msg, Pos const& pos)
+ {
+ std::strstream stream;
+ stream << Exception::severity_text(code) << ": "
+ << Exception::error_text(code);
+ if (msg[0] != 0)
+ stream << ": " << msg;
+ stream << std::ends;
+ std::string throwmsg = stream.str(); stream.freeze(false);
+ ctx.get_hooks().throw_exception(ctx.derived(),
+ Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
+ pos.get_file().c_str()));
+ }
+
+ template <typename Exception, typename S1, typename Pos, typename S2>
+ void throw_(typename Exception::error_code code, S1 msg, Pos const& pos,
+ S2 name)
+ {
+ std::strstream stream;
+ stream << Exception::severity_text(code) << ": "
+ << Exception::error_text(code);
+ if (msg[0] != 0)
+ stream << ": " << msg;
+ stream << std::ends;
+ std::string throwmsg = stream.str(); stream.freeze(false);
+ boost::throw_exception(Exception(throwmsg.c_str(), code,
+ pos.get_line(), pos.get_column(), pos.get_file().c_str(), name));
+ }
+
+ template <typename Exception, typename Context, typename S1, typename Pos,
+ typename S2>
+ void throw_(Context& ctx, typename Exception::error_code code,
+ S1 msg, Pos const& pos, S2 name)
+ {
+ std::strstream stream;
+ stream << Exception::severity_text(code) << ": "
+ << Exception::error_text(code);
+ if (msg[0] != 0)
+ stream << ": " << msg;
+ stream << std::ends;
+ std::string throwmsg = stream.str(); stream.freeze(false);
+ ctx.get_hooks().throw_exception(ctx.derived(),
+ Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
+ pos.get_file().c_str(), name));
+ }
+#else
+ template <typename Exception, typename S1, typename Pos>
+ void throw_(typename Exception::error_code code, S1 msg, Pos const& pos)
+ {
+ std::stringstream stream;
+ stream << Exception::severity_text(code) << ": "
+ << Exception::error_text(code);
+ if (msg[0] != 0)
+ stream << ": " << msg;
+ stream << std::ends;
+ std::string throwmsg = stream.str();
+ boost::throw_exception(Exception(throwmsg.c_str(), code,
+ pos.get_line(), pos.get_column(), pos.get_file().c_str()));
+ }
+
+ template <typename Exception, typename Context, typename S1, typename Pos>
+ void throw_(Context& ctx, typename Exception::error_code code,
+ S1 msg, Pos const& pos)
+ {
+ std::stringstream stream;
+ stream << Exception::severity_text(code) << ": "
+ << Exception::error_text(code);
+ if (msg[0] != 0)
+ stream << ": " << msg;
+ stream << std::ends;
+ std::string throwmsg = stream.str();
+ ctx.get_hooks().throw_exception(ctx.derived(),
+ Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
+ pos.get_file().c_str()));
+ }
+
+ template <typename Exception, typename S1, typename Pos, typename S2>
+ void throw_(typename Exception::error_code code, S1 msg, Pos const& pos,
+ S2 name)
+ {
+ std::stringstream stream;
+ stream << Exception::severity_text(code) << ": "
+ << Exception::error_text(code);
+ if (msg[0] != 0)
+ stream << ": " << msg;
+ stream << std::ends;
+ std::string throwmsg = stream.str();
+ boost::throw_exception(Exception(throwmsg.c_str(), code,
+ pos.get_line(), pos.get_column(), pos.get_file().c_str(), name));
+ }
+
+ template <typename Exception, typename Context, typename S1, typename Pos1,
+ typename S2>
+ void throw_(Context& ctx, typename Exception::error_code code,
+ S1 msg, Pos1 const& pos, S2 name)
+ {
+ std::stringstream stream;
+ stream << Exception::severity_text(code) << ": "
+ << Exception::error_text(code);
+ if (msg[0] != 0)
+ stream << ": " << msg;
+ stream << std::ends;
+ std::string throwmsg = stream.str();
+ ctx.get_hooks().throw_exception(ctx.derived(),
+ Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
+ pos.get_file().c_str(), name));
+ }
+#endif
+}}}
+
+///////////////////////////////////////////////////////////////////////////////
+// helper macro for throwing exceptions
+#if !defined(BOOST_WAVE_THROW)
#define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
- { \
- using namespace boost::wave; \
- std::stringstream stream; \
- stream << cls::severity_text(cls::code) << ": " \
- << cls::error_text(cls::code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- boost::throw_exception(cls(stream.str().c_str(), cls::code, \
- (act_pos).get_line(), (act_pos).get_column(), \
- (act_pos).get_file().c_str())); \
- } \
+ boost::wave::util::throw_<cls>(cls::code, msg, act_pos) \
/**/
+
#define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos) \
- { \
- using namespace boost::wave; \
- std::stringstream stream; \
- stream << cls::severity_text(cls::code) << ": " \
- << cls::error_text(cls::code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- ctx.get_hooks().throw_exception(ctx.derived(), \
- cls(stream.str().c_str(), cls::code, (act_pos).get_line(), \
- (act_pos).get_column(), (act_pos).get_file().c_str())); \
- } \
+ boost::wave::util::throw_<cls>(ctx, cls::code, msg, act_pos) \
/**/
-#endif // BOOST_NO_STRINGSTREAM
#endif // BOOST_WAVE_THROW
///////////////////////////////////////////////////////////////////////////////
// helper macro for throwing exceptions with additional parameter
-#if !defined(BOOST_WAVE_THROW_NAME)
-#ifdef BOOST_NO_STRINGSTREAM
-#include <strstream>
-#define BOOST_WAVE_THROW_NAME_CTX(ctx, cls, code, msg, act_pos, name) \
- { \
- using namespace boost::wave; \
- std::strstream stream; \
- stream << cls::severity_text(cls::code) << ": " \
- << cls::error_text(cls::code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- std::string throwmsg = stream.str(); stream.freeze(false); \
- ctx.get_hooks().throw_exception(ctx.derived(), cls(throwmsg.c_str(), \
- cls::code, (act_pos).get_line(), (act_pos).get_column(), \
- (act_pos).get_file().c_str(), (name))); \
- } \
- /**/
-#else
-#include <sstream>
+#if !defined(BOOST_WAVE_THROW_NAME_CTX)
#define BOOST_WAVE_THROW_NAME_CTX(ctx, cls, code, msg, act_pos, name) \
- { \
- using namespace boost::wave; \
- std::stringstream stream; \
- stream << cls::severity_text(cls::code) << ": " \
- << cls::error_text(cls::code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- ctx.get_hooks().throw_exception(ctx.derived(), \
- cls(stream.str().c_str(), cls::code, (act_pos).get_line(), \
- (act_pos).get_column(), (act_pos).get_file().c_str(), (name))); \
- } \
+ boost::wave::util::throw_<cls>(cls::code, msg, act_pos, name) \
/**/
-#endif // BOOST_NO_STRINGSTREAM
-#endif // BOOST_WAVE_THROW_NAME
+#endif // BOOST_WAVE_THROW_NAME_CTX
///////////////////////////////////////////////////////////////////////////////
// helper macro for throwing exceptions with additional parameter
-#if !defined(BOOST_WAVE_THROW_VAR)
-#ifdef BOOST_NO_STRINGSTREAM
-#include <strstream>
-#define BOOST_WAVE_THROW_VAR_CTX(ctx, cls, code, msg, act_pos) \
- { \
- using namespace boost::wave; \
- std::strstream stream; \
- stream << cls::severity_text(code) << ": " \
- << cls::error_text(code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- std::string throwmsg = stream.str(); stream.freeze(false); \
- ctx.get_hooks().throw_exception(ctx.derived(), cls(throwmsg.c_str(), \
- code, (act_pos).get_line(), (act_pos).get_column(), \
- (act_pos).get_file().c_str())); \
- } \
- /**/
-#else
-#include <sstream>
+#if !defined(BOOST_WAVE_THROW_VAR_CTX)
#define BOOST_WAVE_THROW_VAR_CTX(ctx, cls, code, msg, act_pos) \
- { \
- using namespace boost::wave; \
- std::stringstream stream; \
- stream << cls::severity_text(code) << ": " \
- << cls::error_text(code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- ctx.get_hooks().throw_exception(ctx.derived(), \
- cls(stream.str().c_str(), code, (act_pos).get_line(), \
- (act_pos).get_column(), (act_pos).get_file().c_str())); \
- } \
+ boost::wave::util::throw_<cls>(ctx, code, msg, act_pos) \
/**/
-#endif // BOOST_NO_STRINGSTREAM
-#endif // BOOST_WAVE_THROW_VAR
+#endif // BOOST_WAVE_THROW_VAR_CTX
#endif // !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)
Modified: trunk/boost/wave/util/cpp_iterator.hpp
==============================================================================
--- trunk/boost/wave/util/cpp_iterator.hpp (original)
+++ trunk/boost/wave/util/cpp_iterator.hpp 2010-10-23 19:12:06 EDT (Sat, 23 Oct 2010)
@@ -440,8 +440,9 @@
// report unbalanced #if/#endif now to make it possible to recover properly
if (iter_ctx->if_block_depth != ctx.get_if_block_depth()) {
using boost::wave::util::impl::escape_lit;
+ BOOST_WAVE_STRINGTYPE msg(escape_lit(oldfile));
BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, unbalanced_if_endif,
- escape_lit(oldfile).c_str(), old_pos);
+ msg.c_str(), old_pos);
}
return true;
}
@@ -2261,8 +2262,10 @@
if (!impl::retrieve_line_info(expanded.begin(), expanded.end(),
line, file_name, error))
{
+ typename ContextT::string_type msg(
+ boost::wave::util::impl::as_string(expanded));
BOOST_WAVE_THROW_VAR_CTX(ctx, preprocess_exception, error,
- boost::wave::util::impl::as_string(expanded).c_str(), act_pos)
+ msg.c_str(), act_pos);
return;
}
@@ -2285,8 +2288,10 @@
// diagnose possible error in detected line directive
if (error != preprocess_exception::no_error) {
+ typename ContextT::string_type msg(
+ boost::wave::util::impl::as_string(expanded));
BOOST_WAVE_THROW_VAR_CTX(ctx, preprocess_exception, error,
- boost::wave::util::impl::as_string(expanded).c_str(), act_pos)
+ msg.c_str(), act_pos);
return;
}
@@ -2341,8 +2346,9 @@
#endif
{
// report the corresponding error
+ BOOST_WAVE_STRINGTYPE msg(boost::wave::util::impl::as_string(expanded));
BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, error_directive,
- boost::wave::util::impl::as_string(expanded).c_str(), act_pos);
+ msg.c_str(), act_pos);
}
}
@@ -2389,8 +2395,9 @@
#endif
{
// report the corresponding error
+ BOOST_WAVE_STRINGTYPE msg(boost::wave::util::impl::as_string(expanded));
BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, warning_directive,
- boost::wave::util::impl::as_string(expanded).c_str(), act_pos);
+ msg.c_str(), act_pos);
}
}
#endif // BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE != 0
Modified: trunk/boost/wave/util/cpp_macromap.hpp
==============================================================================
--- trunk/boost/wave/util/cpp_macromap.hpp (original)
+++ trunk/boost/wave/util/cpp_macromap.hpp 2010-10-23 19:12:06 EDT (Sat, 23 Oct 2010)
@@ -421,8 +421,9 @@
!IS_EXTCATEGORY(id, OperatorTokenType|AltExtTokenType) &&
!IS_CATEGORY(id, BoolLiteralTokenType))
{
+ std::string msg(impl::get_full_name(begin, end));
BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, invalid_macroname,
- impl::get_full_name(begin, end).c_str(), main_pos);
+ msg.c_str(), main_pos);
return false;
}
@@ -432,8 +433,9 @@
if (++it != end) {
// there should be only one token as the inspected name
+ std::string msg(impl::get_full_name(begin, end));
BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, invalid_macroname,
- impl::get_full_name(begin, end).c_str(), main_pos);
+ msg.c_str(), main_pos);
return false;
}
return is_defined(name, cit, 0);
Modified: trunk/boost/wave/util/interpret_pragma.hpp
==============================================================================
--- trunk/boost/wave/util/interpret_pragma.hpp (original)
+++ trunk/boost/wave/util/interpret_pragma.hpp 2010-10-23 19:12:06 EDT (Sat, 23 Oct 2010)
@@ -107,10 +107,11 @@
)[spirit_assign_actor(values)],
pattern_p(WhiteSpaceTokenType, TokenTypeMask|PPTokenFlag)).hit)
{
+ typename ContextT::string_type msg(
+ impl::as_string<string_type>(it, end));
BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
ill_formed_pragma_option,
- impl::as_string<string_type>(it, end).c_str(),
- act_token.get_position());
+ msg.c_str(), act_token.get_position());
return false;
}
@@ -169,10 +170,11 @@
).hit
)
{
+ typename ContextT::string_type msg(
+ impl::as_string<string_type>(it, end));
BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
ill_formed_pragma_message,
- impl::as_string<string_type>(it, end).c_str(),
- act_token.get_position());
+ msg.c_str(), act_token.get_position());
return false;
}
@@ -184,9 +186,10 @@
}
// output the message itself
+ typename ContextT::string_type msg(impl::as_string(values));
BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
pragma_message_directive,
- impl::as_string(values).c_str(), act_token.get_position());
+ msg.c_str(), act_token.get_position());
return false;
}
#endif
Modified: trunk/tools/wave/trace_macro_expansion.hpp
==============================================================================
--- trunk/tools/wave/trace_macro_expansion.hpp (original)
+++ trunk/tools/wave/trace_macro_expansion.hpp 2010-10-23 19:12:06 EDT (Sat, 23 Oct 2010)
@@ -30,6 +30,7 @@
#include <boost/wave/preprocessing_hooks.hpp>
#include <boost/wave/whitespace_handling.hpp>
#include <boost/wave/language_support.hpp>
+#include <boost/wave/cpp_exceptions.hpp>
#include "stop_watch.hpp"
@@ -69,7 +70,8 @@
{
public:
enum error_code {
- pragma_system_not_enabled = boost::wave::preprocess_exception::last_error_number + 1,
+ pragma_system_not_enabled =
+ boost::wave::preprocess_exception::last_error_number + 1,
pragma_mismatched_push_pop,
};
@@ -510,10 +512,11 @@
if (!enable_system_command) {
// if the #pragma wave system() directive is not enabled, throw
// a corresponding error (actually its a remark),
+ typename ContextT::string_type msg(
+ boost::wave::util::impl::as_string(values));
BOOST_WAVE_THROW_CTX(ctx, bad_pragma_exception,
pragma_system_not_enabled,
- boost::wave::util::impl::as_string(values).c_str(),
- act_token.get_position());
+ msg.c_str(), act_token.get_position());
return false;
}
@@ -523,9 +526,10 @@
}
if (option.get_value() == "stop") {
// stop the execution and output the argument
- BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, error_directive,
- boost::wave::util::impl::as_string(values).c_str(),
- act_token.get_position());
+ typename ContextT::string_type msg(
+ boost::wave::util::impl::as_string(values));
+ BOOST_WAVE_THROW_CTX(ctx, boost::wave::preprocess_exception,
+ error_directive, msg.c_str(), act_token.get_position());
return false;
}
if (option.get_value() == "option") {
@@ -828,7 +832,7 @@
option_str += boost::wave::util::impl::as_string(values);
option_str += ")";
}
- BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
+ BOOST_WAVE_THROW_CTX(ctx, boost::wave::preprocess_exception,
ill_formed_pragma_option, option_str.c_str(),
act_token.get_position());
return false;
@@ -1000,7 +1004,7 @@
// open the new file
outputstrm.open(fpath.string().c_str(), mode);
if (!outputstrm.is_open()) {
- BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
+ BOOST_WAVE_THROW_CTX(ctx, boost::wave::preprocess_exception,
could_not_open_output_file,
fpath.string().c_str(), act_token.get_position());
return false;
@@ -1153,7 +1157,7 @@
option_str += util::impl::as_string(values);
option_str += ")";
}
- BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
+ BOOST_WAVE_THROW_CTX(ctx, boost::wave::preprocess_exception,
ill_formed_pragma_option,
option_str.c_str(), act_token.get_position());
return false;
@@ -1190,7 +1194,7 @@
string_type error_str("unable to spawn command: ");
error_str += native_cmd;
- BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
+ BOOST_WAVE_THROW_CTX(ctx, boost::wave::preprocess_exception,
ill_formed_pragma_option,
error_str.c_str(), act_token.get_position());
return false;
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