1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/wave/cpp_exceptions.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,421 @@
1.4 +/*=============================================================================
1.5 + Boost.Wave: A Standard compliant C++ preprocessor library
1.6 +
1.7 + http://www.boost.org/
1.8 +
1.9 + Copyright (c) 2001-2007 Hartmut Kaiser. Distributed under the Boost
1.10 + Software License, Version 1.0. (See accompanying file
1.11 + LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1.12 +=============================================================================*/
1.13 +
1.14 +#if !defined(CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED)
1.15 +#define CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED
1.16 +
1.17 +#include <exception>
1.18 +#include <string>
1.19 +#include <limits>
1.20 +
1.21 +#include <boost/assert.hpp>
1.22 +#include <boost/config.hpp>
1.23 +#include <boost/throw_exception.hpp>
1.24 +#include <boost/wave/wave_config.hpp>
1.25 +#include <boost/wave/cpp_throw.hpp>
1.26 +
1.27 +// this must occur after all of the includes and before any code appears
1.28 +#ifdef BOOST_HAS_ABI_HEADERS
1.29 +#include BOOST_ABI_PREFIX
1.30 +#endif
1.31 +
1.32 +///////////////////////////////////////////////////////////////////////////////
1.33 +namespace boost {
1.34 +namespace wave {
1.35 +
1.36 +///////////////////////////////////////////////////////////////////////////////
1.37 +// exception severity
1.38 +namespace util {
1.39 +
1.40 + enum severity {
1.41 + severity_remark = 0,
1.42 + severity_warning,
1.43 + severity_error,
1.44 + severity_fatal,
1.45 + severity_commandline_error,
1.46 + last_severity_code = severity_commandline_error
1.47 + };
1.48 +
1.49 + inline char const *
1.50 + get_severity(int level)
1.51 + {
1.52 + static char const *severity_text[] =
1.53 + {
1.54 + "remark", // severity_remark
1.55 + "warning", // severity_warning
1.56 + "error", // severity_error
1.57 + "fatal error", // severity_fatal
1.58 + "command line error" // severity_commandline_error
1.59 + };
1.60 + BOOST_ASSERT(severity_remark <= level &&
1.61 + level <= last_severity_code);
1.62 + return severity_text[level];
1.63 + }
1.64 +}
1.65 +
1.66 +///////////////////////////////////////////////////////////////////////////////
1.67 +// cpp_exception, the base class for all specific C preprocessor exceptions
1.68 +class cpp_exception
1.69 +: public std::exception
1.70 +{
1.71 +public:
1.72 + cpp_exception(int line_, int column_, char const *filename_) throw()
1.73 + : line(line_), column(column_)
1.74 + {
1.75 + unsigned int off = 0;
1.76 + while (off < sizeof(filename)-1 && *filename_)
1.77 + filename[off++] = *filename_++;
1.78 + filename[off] = 0;
1.79 + }
1.80 + ~cpp_exception() throw() {}
1.81 +
1.82 + virtual char const *what() const throw() = 0; // to be overloaded
1.83 + virtual char const *description() const throw() = 0;
1.84 + virtual int get_errorcode() const throw() = 0;
1.85 + virtual int get_severity() const throw() = 0;
1.86 + virtual char const* get_related_name() const throw() = 0;
1.87 + virtual bool is_recoverable() const throw() = 0;
1.88 +
1.89 + int line_no() const throw() { return line; }
1.90 + int column_no() const throw() { return column; }
1.91 + char const *file_name() const throw() { return filename; }
1.92 +
1.93 +protected:
1.94 + char filename[512];
1.95 + int line;
1.96 + int column;
1.97 +};
1.98 +
1.99 +///////////////////////////////////////////////////////////////////////////////
1.100 +// preprocessor error
1.101 +class preprocess_exception :
1.102 + public cpp_exception
1.103 +{
1.104 +public:
1.105 + enum error_code {
1.106 + no_error = 0,
1.107 + unexpected_error,
1.108 + macro_redefinition,
1.109 + macro_insertion_error,
1.110 + bad_include_file,
1.111 + bad_include_statement,
1.112 + ill_formed_directive,
1.113 + error_directive,
1.114 + warning_directive,
1.115 + ill_formed_expression,
1.116 + missing_matching_if,
1.117 + missing_matching_endif,
1.118 + ill_formed_operator,
1.119 + bad_define_statement,
1.120 + bad_define_statement_va_args,
1.121 + too_few_macroarguments,
1.122 + too_many_macroarguments,
1.123 + empty_macroarguments,
1.124 + improperly_terminated_macro,
1.125 + bad_line_statement,
1.126 + bad_line_number,
1.127 + bad_line_filename,
1.128 + bad_undefine_statement,
1.129 + bad_macro_definition,
1.130 + illegal_redefinition,
1.131 + duplicate_parameter_name,
1.132 + invalid_concat,
1.133 + last_line_not_terminated,
1.134 + ill_formed_pragma_option,
1.135 + include_nesting_too_deep,
1.136 + misplaced_operator,
1.137 + alreadydefined_name,
1.138 + undefined_macroname,
1.139 + invalid_macroname,
1.140 + unexpected_qualified_name,
1.141 + division_by_zero,
1.142 + integer_overflow,
1.143 + illegal_operator_redefinition,
1.144 + ill_formed_integer_literal,
1.145 + ill_formed_character_literal,
1.146 + unbalanced_if_endif,
1.147 + character_literal_out_of_range,
1.148 + could_not_open_output_file,
1.149 + incompatible_config,
1.150 + ill_formed_pragma_message,
1.151 + pragma_message_directive,
1.152 + last_error_number = pragma_message_directive
1.153 + };
1.154 +
1.155 + preprocess_exception(char const *what_, error_code code, int line_,
1.156 + int column_, char const *filename_) throw()
1.157 + : cpp_exception(line_, column_, filename_),
1.158 + code(code)
1.159 + {
1.160 + unsigned int off = 0;
1.161 + while (off < sizeof(buffer) && *what_)
1.162 + buffer[off++] = *what_++;
1.163 + buffer[off] = 0;
1.164 + }
1.165 + ~preprocess_exception() throw() {}
1.166 +
1.167 + virtual char const *what() const throw()
1.168 + {
1.169 + return "boost::wave::preprocess_exception";
1.170 + }
1.171 + virtual char const *description() const throw()
1.172 + {
1.173 + return buffer;
1.174 + }
1.175 + virtual int get_severity() const throw()
1.176 + {
1.177 + return severity_level(code);
1.178 + }
1.179 + virtual int get_errorcode() const throw()
1.180 + {
1.181 + return code;
1.182 + }
1.183 + virtual char const* get_related_name() const throw()
1.184 + {
1.185 + return "<unknown>";
1.186 + }
1.187 + virtual bool is_recoverable() const throw()
1.188 + {
1.189 + switch (get_errorcode()) {
1.190 + // these are the exceptions thrown during processing not supposed to
1.191 + // produce any tokens on the context::iterator level
1.192 + case preprocess_exception::no_error: // just a placeholder
1.193 + case preprocess_exception::macro_redefinition:
1.194 + case preprocess_exception::macro_insertion_error:
1.195 + case preprocess_exception::bad_macro_definition:
1.196 + case preprocess_exception::illegal_redefinition:
1.197 + case preprocess_exception::duplicate_parameter_name:
1.198 + case preprocess_exception::invalid_macroname:
1.199 + case preprocess_exception::bad_include_file:
1.200 + case preprocess_exception::bad_include_statement:
1.201 + case preprocess_exception::ill_formed_directive:
1.202 + case preprocess_exception::error_directive:
1.203 + case preprocess_exception::warning_directive:
1.204 + case preprocess_exception::ill_formed_expression:
1.205 + case preprocess_exception::missing_matching_if:
1.206 + case preprocess_exception::missing_matching_endif:
1.207 + case preprocess_exception::unbalanced_if_endif:
1.208 + case preprocess_exception::bad_define_statement:
1.209 + case preprocess_exception::bad_define_statement_va_args:
1.210 + case preprocess_exception::bad_line_statement:
1.211 + case preprocess_exception::bad_line_number:
1.212 + case preprocess_exception::bad_line_filename:
1.213 + case preprocess_exception::bad_undefine_statement:
1.214 + case preprocess_exception::division_by_zero:
1.215 + case preprocess_exception::integer_overflow:
1.216 + case preprocess_exception::ill_formed_integer_literal:
1.217 + case preprocess_exception::ill_formed_character_literal:
1.218 + case preprocess_exception::character_literal_out_of_range:
1.219 + case preprocess_exception::last_line_not_terminated:
1.220 + case preprocess_exception::include_nesting_too_deep:
1.221 + case preprocess_exception::illegal_operator_redefinition:
1.222 + case preprocess_exception::incompatible_config:
1.223 + case preprocess_exception::ill_formed_pragma_option:
1.224 + case preprocess_exception::ill_formed_pragma_message:
1.225 + case preprocess_exception::pragma_message_directive:
1.226 + return true;
1.227 +
1.228 + case preprocess_exception::unexpected_error:
1.229 + case preprocess_exception::ill_formed_operator:
1.230 + case preprocess_exception::too_few_macroarguments:
1.231 + case preprocess_exception::too_many_macroarguments:
1.232 + case preprocess_exception::empty_macroarguments:
1.233 + case preprocess_exception::improperly_terminated_macro:
1.234 + case preprocess_exception::invalid_concat:
1.235 + case preprocess_exception::could_not_open_output_file:
1.236 + break;
1.237 + }
1.238 + return false;
1.239 + }
1.240 +
1.241 + static char const *error_text(int code)
1.242 + {
1.243 + // error texts in this array must appear in the same order as the items in
1.244 + // the error enum above
1.245 + static char const *preprocess_exception_errors[] = {
1.246 + "no error", // no_error
1.247 + "unexpected error (should not happen)", // unexpected_error
1.248 + "illegal macro redefinition", // macro_redefinition
1.249 + "macro definition failed (out of memory?)", // macro_insertion_error
1.250 + "could not find include file", // bad_include_file
1.251 + "ill formed #include directive", // bad_include_statement
1.252 + "ill formed preprocessor directive", // ill_formed_directive
1.253 + "encountered #error directive or #pragma wave stop()", // error_directive
1.254 + "encountered #warning directive", // warning_directive
1.255 + "ill formed preprocessor expression", // ill_formed_expression
1.256 + "the #if for this directive is missing", // missing_matching_if
1.257 + "detected at least one missing #endif directive", // missing_matching_endif
1.258 + "ill formed preprocessing operator", // ill_formed_operator
1.259 + "ill formed #define directive", // bad_define_statement
1.260 + "__VA_ARGS__ can only appear in the "
1.261 + "expansion of a C99 variadic macro", // bad_define_statement_va_args
1.262 + "too few macro arguments", // too_few_macroarguments
1.263 + "too many macro arguments", // too_many_macroarguments
1.264 + "empty macro arguments are not supported in pure C++ mode, "
1.265 + "use variadics mode to allow these", // empty_macroarguments
1.266 + "improperly terminated macro invocation "
1.267 + "or replacement-list terminates in partial "
1.268 + "macro expansion (not supported yet)", // improperly_terminated_macro
1.269 + "ill formed #line directive", // bad_line_statement
1.270 + "line number argument of #line directive "
1.271 + "should consist out of decimal digits "
1.272 + "only and must be in range of [1..INT_MAX]", // bad_line_number
1.273 + "filename argument of #line directive should "
1.274 + "be a narrow string literal", // bad_line_filename
1.275 + "#undef may not be used on this predefined name", // bad_undefine_statement
1.276 + "invalid macro definition", // bad_macro_definition
1.277 + "this predefined name may not be redefined", // illegal_redefinition
1.278 + "duplicate macro parameter name", // duplicate_parameter_name
1.279 + "pasting the following two tokens does not "
1.280 + "give a valid preprocessing token", // invalid_concat
1.281 + "last line of file ends without a newline", // last_line_not_terminated
1.282 + "unknown or illformed pragma option", // ill_formed_pragma_option
1.283 + "include files nested too deep", // include_nesting_too_deep
1.284 + "misplaced operator defined()", // misplaced_operator
1.285 + "the name is already used in this scope as "
1.286 + "a macro or scope name", // alreadydefined_name
1.287 + "undefined macro or scope name may not be imported", // undefined_macroname
1.288 + "ill formed macro name", // invalid_macroname
1.289 + "qualified names are supported in C++0x mode only", // unexpected_qualified_name
1.290 + "division by zero in preprocessor expression", // division_by_zero
1.291 + "integer overflow in preprocessor expression", // integer_overflow
1.292 + "this cannot be used as a macro name as it is "
1.293 + "an operator in C++", // illegal_operator_redefinition
1.294 + "ill formed integer literal or integer constant too large", // ill_formed_integer_literal
1.295 + "ill formed character literal", // ill_formed_character_literal
1.296 + "unbalanced #if/#endif in include file", // unbalanced_if_endif
1.297 + "expression contains out of range character literal", // character_literal_out_of_range
1.298 + "could not open output file", // could_not_open_output_file
1.299 + "incompatible state information", // incompatible_config
1.300 + "illformed pragma message", // ill_formed_pragma_message
1.301 + "encountered #pragma message directive" // pragma_message_directive
1.302 + };
1.303 + BOOST_ASSERT(no_error <= code && code <= last_error_number);
1.304 + return preprocess_exception_errors[code];
1.305 + }
1.306 +
1.307 + static util::severity severity_level(int code)
1.308 + {
1.309 + static util::severity preprocess_exception_severity[] = {
1.310 + util::severity_remark, // no_error
1.311 + util::severity_fatal, // unexpected_error
1.312 + util::severity_warning, // macro_redefinition
1.313 + util::severity_fatal, // macro_insertion_error
1.314 + util::severity_error, // bad_include_file
1.315 + util::severity_error, // bad_include_statement
1.316 + util::severity_error, // ill_formed_directive
1.317 + util::severity_fatal, // error_directive
1.318 + util::severity_warning, // warning_directive
1.319 + util::severity_error, // ill_formed_expression
1.320 + util::severity_error, // missing_matching_if
1.321 + util::severity_error, // missing_matching_endif
1.322 + util::severity_error, // ill_formed_operator
1.323 + util::severity_error, // bad_define_statement
1.324 + util::severity_error, // bad_define_statement_va_args
1.325 + util::severity_warning, // too_few_macroarguments
1.326 + util::severity_warning, // too_many_macroarguments
1.327 + util::severity_warning, // empty_macroarguments
1.328 + util::severity_error, // improperly_terminated_macro
1.329 + util::severity_warning, // bad_line_statement
1.330 + util::severity_warning, // bad_line_number
1.331 + util::severity_warning, // bad_line_filename
1.332 + util::severity_warning, // bad_undefine_statement
1.333 + util::severity_commandline_error, // bad_macro_definition
1.334 + util::severity_warning, // illegal_redefinition
1.335 + util::severity_error, // duplicate_parameter_name
1.336 + util::severity_error, // invalid_concat
1.337 + util::severity_warning, // last_line_not_terminated
1.338 + util::severity_warning, // ill_formed_pragma_option
1.339 + util::severity_fatal, // include_nesting_too_deep
1.340 + util::severity_error, // misplaced_operator
1.341 + util::severity_error, // alreadydefined_name
1.342 + util::severity_error, // undefined_macroname
1.343 + util::severity_error, // invalid_macroname
1.344 + util::severity_error, // unexpected_qualified_name
1.345 + util::severity_fatal, // division_by_zero
1.346 + util::severity_error, // integer_overflow
1.347 + util::severity_error, // illegal_operator_redefinition
1.348 + util::severity_error, // ill_formed_integer_literal
1.349 + util::severity_error, // ill_formed_character_literal
1.350 + util::severity_warning, // unbalanced_if_endif
1.351 + util::severity_warning, // character_literal_out_of_range
1.352 + util::severity_error, // could_not_open_output_file
1.353 + util::severity_remark, // incompatible_config
1.354 + util::severity_warning, // ill_formed_pragma_message
1.355 + util::severity_remark, // pragma_message_directive
1.356 + };
1.357 + BOOST_ASSERT(no_error <= code && code <= last_error_number);
1.358 + return preprocess_exception_severity[code];
1.359 + }
1.360 + static char const *severity_text(int code)
1.361 + {
1.362 + return util::get_severity(severity_level(code));
1.363 + }
1.364 +
1.365 +private:
1.366 + char buffer[512];
1.367 + error_code code;
1.368 +};
1.369 +
1.370 +///////////////////////////////////////////////////////////////////////////////
1.371 +// Error during macro handling, this exception contains the related macro name
1.372 +class macro_handling_exception :
1.373 + public preprocess_exception
1.374 +{
1.375 +public:
1.376 + macro_handling_exception(char const *what_, error_code code, int line_,
1.377 + int column_, char const *filename_, char const *macroname) throw()
1.378 + : preprocess_exception(what_, code, line_, column_, filename_)
1.379 + {
1.380 + unsigned int off = 0;
1.381 + while (off < sizeof(name) && *macroname)
1.382 + name[off++] = *macroname++;
1.383 + name[off] = 0;
1.384 + }
1.385 + ~macro_handling_exception() throw() {}
1.386 +
1.387 + virtual char const *what() const throw()
1.388 + {
1.389 + return "boost::wave::macro_handling_exception";
1.390 + }
1.391 + char const* get_related_name() const throw()
1.392 + {
1.393 + return name;
1.394 + }
1.395 +
1.396 +private:
1.397 + char name[512];
1.398 +};
1.399 +
1.400 +///////////////////////////////////////////////////////////////////////////////
1.401 +//
1.402 +// The is_recoverable() function allows to decide, whether it is possible
1.403 +// simply to continue after a given exception was thrown by Wave.
1.404 +//
1.405 +// This is kind of a hack to allow to recover from certain errors as long as
1.406 +// Wave doesn't provide better means of error recovery.
1.407 +//
1.408 +///////////////////////////////////////////////////////////////////////////////
1.409 +inline bool
1.410 +is_recoverable(cpp_exception const& e)
1.411 +{
1.412 + return e.is_recoverable();
1.413 +}
1.414 +
1.415 +///////////////////////////////////////////////////////////////////////////////
1.416 +} // namespace wave
1.417 +} // namespace boost
1.418 +
1.419 +// the suffix header occurs after all of the code
1.420 +#ifdef BOOST_HAS_ABI_HEADERS
1.421 +#include BOOST_ABI_SUFFIX
1.422 +#endif
1.423 +
1.424 +#endif // !defined(CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED)