File indexing completed on 2025-01-18 09:53:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #if !defined(BOOST_CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED)
0012 #define BOOST_CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED
0013
0014 #include <exception>
0015 #include <string>
0016 #include <limits>
0017
0018 #include <boost/assert.hpp>
0019 #include <boost/config.hpp>
0020 #include <boost/throw_exception.hpp>
0021 #include <boost/wave/wave_config.hpp>
0022 #include <boost/wave/cpp_throw.hpp>
0023
0024
0025 #ifdef BOOST_HAS_ABI_HEADERS
0026 #include BOOST_ABI_PREFIX
0027 #endif
0028
0029
0030 namespace boost {
0031 namespace wave {
0032
0033
0034
0035 namespace util {
0036
0037 enum severity {
0038 severity_remark = 0,
0039 severity_warning,
0040 severity_error,
0041 severity_fatal,
0042 severity_commandline_error,
0043 last_severity_code = severity_commandline_error
0044 };
0045
0046 inline char const *
0047 get_severity(int level)
0048 {
0049 static char const *severity_text[] =
0050 {
0051 "remark",
0052 "warning",
0053 "error",
0054 "fatal error",
0055 "command line error"
0056 };
0057 BOOST_ASSERT(severity_remark <= level &&
0058 level <= last_severity_code);
0059 return severity_text[level];
0060 }
0061 }
0062
0063
0064
0065 class BOOST_SYMBOL_VISIBLE cpp_exception
0066 : public std::exception
0067 {
0068 public:
0069 cpp_exception(std::size_t line_, std::size_t column_, char const *filename_) throw()
0070 : line(line_), column(column_)
0071 {
0072 unsigned int off = 0;
0073 while (off < sizeof(filename)-1 && *filename_)
0074 filename[off++] = *filename_++;
0075 filename[off] = 0;
0076 }
0077 ~cpp_exception() throw() {}
0078
0079 char const *what() const throw() BOOST_OVERRIDE = 0;
0080 virtual char const *description() const throw() = 0;
0081 virtual int get_errorcode() const throw() = 0;
0082 virtual int get_severity() const throw() = 0;
0083 virtual char const* get_related_name() const throw() = 0;
0084 virtual bool is_recoverable() const throw() = 0;
0085
0086 std::size_t line_no() const throw() { return line; }
0087 std::size_t column_no() const throw() { return column; }
0088 char const *file_name() const throw() { return filename; }
0089
0090 protected:
0091 char filename[512];
0092 std::size_t line;
0093 std::size_t column;
0094 };
0095
0096
0097
0098 class BOOST_SYMBOL_VISIBLE preprocess_exception :
0099 public cpp_exception
0100 {
0101 public:
0102 enum error_code {
0103 no_error = 0,
0104 unexpected_error,
0105 macro_redefinition,
0106 macro_insertion_error,
0107 bad_include_file,
0108 bad_include_statement,
0109 bad_has_include_expression,
0110 ill_formed_directive,
0111 error_directive,
0112 warning_directive,
0113 ill_formed_expression,
0114 missing_matching_if,
0115 missing_matching_endif,
0116 ill_formed_operator,
0117 bad_define_statement,
0118 bad_define_statement_va_args,
0119 bad_define_statement_va_opt,
0120 bad_define_statement_va_opt_parens,
0121 bad_define_statement_va_opt_recurse,
0122 too_few_macroarguments,
0123 too_many_macroarguments,
0124 empty_macroarguments,
0125 improperly_terminated_macro,
0126 bad_line_statement,
0127 bad_line_number,
0128 bad_line_filename,
0129 bad_undefine_statement,
0130 bad_macro_definition,
0131 illegal_redefinition,
0132 duplicate_parameter_name,
0133 invalid_concat,
0134 last_line_not_terminated,
0135 ill_formed_pragma_option,
0136 include_nesting_too_deep,
0137 misplaced_operator,
0138 alreadydefined_name,
0139 undefined_macroname,
0140 invalid_macroname,
0141 unexpected_qualified_name,
0142 division_by_zero,
0143 integer_overflow,
0144 illegal_operator_redefinition,
0145 ill_formed_integer_literal,
0146 ill_formed_character_literal,
0147 unbalanced_if_endif,
0148 character_literal_out_of_range,
0149 could_not_open_output_file,
0150 incompatible_config,
0151 ill_formed_pragma_message,
0152 pragma_message_directive,
0153 last_error_number = pragma_message_directive
0154 };
0155
0156 preprocess_exception(char const *what_, error_code code, std::size_t line_,
0157 std::size_t column_, char const *filename_) throw()
0158 : cpp_exception(line_, column_, filename_),
0159 code(code)
0160 {
0161 unsigned int off = 0;
0162 while (off < sizeof(buffer) - 1 && *what_)
0163 buffer[off++] = *what_++;
0164 buffer[off] = 0;
0165 }
0166 ~preprocess_exception() throw() {}
0167
0168 char const *what() const throw() BOOST_OVERRIDE
0169 {
0170 return "boost::wave::preprocess_exception";
0171 }
0172 char const *description() const throw() BOOST_OVERRIDE
0173 {
0174 return buffer;
0175 }
0176 int get_severity() const throw() BOOST_OVERRIDE
0177 {
0178 return severity_level(code);
0179 }
0180 int get_errorcode() const throw() BOOST_OVERRIDE
0181 {
0182 return code;
0183 }
0184 char const* get_related_name() const throw() BOOST_OVERRIDE
0185 {
0186 return "<unknown>";
0187 }
0188 bool is_recoverable() const throw() BOOST_OVERRIDE
0189 {
0190 switch (get_errorcode()) {
0191
0192
0193 case preprocess_exception::no_error:
0194 case preprocess_exception::macro_redefinition:
0195 case preprocess_exception::macro_insertion_error:
0196 case preprocess_exception::bad_macro_definition:
0197 case preprocess_exception::illegal_redefinition:
0198 case preprocess_exception::duplicate_parameter_name:
0199 case preprocess_exception::invalid_macroname:
0200 case preprocess_exception::bad_include_file:
0201 case preprocess_exception::bad_include_statement:
0202 case preprocess_exception::bad_has_include_expression:
0203 case preprocess_exception::ill_formed_directive:
0204 case preprocess_exception::error_directive:
0205 case preprocess_exception::warning_directive:
0206 case preprocess_exception::ill_formed_expression:
0207 case preprocess_exception::missing_matching_if:
0208 case preprocess_exception::missing_matching_endif:
0209 case preprocess_exception::unbalanced_if_endif:
0210 case preprocess_exception::bad_define_statement:
0211 case preprocess_exception::bad_define_statement_va_args:
0212 case preprocess_exception::bad_define_statement_va_opt:
0213 case preprocess_exception::bad_define_statement_va_opt_parens:
0214 case preprocess_exception::bad_define_statement_va_opt_recurse:
0215 case preprocess_exception::bad_line_statement:
0216 case preprocess_exception::bad_line_number:
0217 case preprocess_exception::bad_line_filename:
0218 case preprocess_exception::bad_undefine_statement:
0219 case preprocess_exception::division_by_zero:
0220 case preprocess_exception::integer_overflow:
0221 case preprocess_exception::ill_formed_integer_literal:
0222 case preprocess_exception::ill_formed_character_literal:
0223 case preprocess_exception::character_literal_out_of_range:
0224 case preprocess_exception::last_line_not_terminated:
0225 case preprocess_exception::include_nesting_too_deep:
0226 case preprocess_exception::illegal_operator_redefinition:
0227 case preprocess_exception::incompatible_config:
0228 case preprocess_exception::ill_formed_pragma_option:
0229 case preprocess_exception::ill_formed_pragma_message:
0230 case preprocess_exception::pragma_message_directive:
0231 return true;
0232
0233 case preprocess_exception::unexpected_error:
0234 case preprocess_exception::ill_formed_operator:
0235 case preprocess_exception::too_few_macroarguments:
0236 case preprocess_exception::too_many_macroarguments:
0237 case preprocess_exception::empty_macroarguments:
0238 case preprocess_exception::improperly_terminated_macro:
0239 case preprocess_exception::invalid_concat:
0240 case preprocess_exception::could_not_open_output_file:
0241 break;
0242 }
0243 return false;
0244 }
0245
0246 static char const *error_text(int code)
0247 {
0248
0249
0250 static char const *preprocess_exception_errors[] = {
0251 "no error",
0252 "unexpected error (should not happen)",
0253 "illegal macro redefinition",
0254 "macro definition failed (out of memory?)",
0255 "could not find include file",
0256 "ill formed #include directive",
0257 "ill formed __has_include expression",
0258 "ill formed preprocessor directive",
0259 "encountered #error directive or #pragma wave stop()",
0260 "encountered #warning directive",
0261 "ill formed preprocessor expression",
0262 "the #if for this directive is missing",
0263 "detected at least one missing #endif directive",
0264 "ill formed preprocessing operator",
0265 "ill formed #define directive",
0266 "__VA_ARGS__ can only appear in the "
0267 "expansion of a C99 variadic macro",
0268 "__VA_OPT__ can only appear in the "
0269 "expansion of a C++20 variadic macro",
0270 "__VA_OPT__ must be followed by a left "
0271 "paren in a C++20 variadic macro",
0272 "__VA_OPT__() may not contain __VA_OPT__",
0273 "too few macro arguments",
0274 "too many macro arguments",
0275 "empty macro arguments are not supported in pure C++ mode, "
0276 "use variadics mode to allow these",
0277 "improperly terminated macro invocation "
0278 "or replacement-list terminates in partial "
0279 "macro expansion (not supported yet)",
0280 "ill formed #line directive",
0281 "line number argument of #line directive "
0282 "should consist out of decimal digits "
0283 "only and must be in range of [1..INT_MAX]",
0284 "filename argument of #line directive should "
0285 "be a narrow string literal",
0286 "#undef may not be used on this predefined name",
0287 "invalid macro definition",
0288 "this predefined name may not be redefined",
0289 "duplicate macro parameter name",
0290 "pasting the following two tokens does not "
0291 "give a valid preprocessing token",
0292 "last line of file ends without a newline",
0293 "unknown or illformed pragma option",
0294 "include files nested too deep",
0295 "misplaced operator defined()",
0296 "the name is already used in this scope as "
0297 "a macro or scope name",
0298 "undefined macro or scope name may not be imported",
0299 "ill formed macro name",
0300 "qualified names are supported in C++11 mode only",
0301 "division by zero in preprocessor expression",
0302 "integer overflow in preprocessor expression",
0303 "this cannot be used as a macro name as it is "
0304 "an operator in C++",
0305 "ill formed integer literal or integer constant too large",
0306 "ill formed character literal",
0307 "unbalanced #if/#endif in include file",
0308 "expression contains out of range character literal",
0309 "could not open output file",
0310 "incompatible state information",
0311 "illformed pragma message",
0312 "encountered #pragma message directive"
0313 };
0314 BOOST_ASSERT(no_error <= code && code <= last_error_number);
0315 return preprocess_exception_errors[code];
0316 }
0317
0318 static util::severity severity_level(int code)
0319 {
0320 static util::severity preprocess_exception_severity[] = {
0321 util::severity_remark,
0322 util::severity_fatal,
0323 util::severity_warning,
0324 util::severity_fatal,
0325 util::severity_error,
0326 util::severity_error,
0327 util::severity_error,
0328 util::severity_error,
0329 util::severity_fatal,
0330 util::severity_warning,
0331 util::severity_error,
0332 util::severity_error,
0333 util::severity_error,
0334 util::severity_error,
0335 util::severity_error,
0336 util::severity_error,
0337 util::severity_error,
0338 util::severity_error,
0339 util::severity_error,
0340 util::severity_warning,
0341 util::severity_warning,
0342 util::severity_warning,
0343 util::severity_error,
0344 util::severity_warning,
0345 util::severity_warning,
0346 util::severity_warning,
0347 util::severity_warning,
0348 util::severity_commandline_error,
0349 util::severity_warning,
0350 util::severity_error,
0351 util::severity_error,
0352 util::severity_warning,
0353 util::severity_warning,
0354 util::severity_fatal,
0355 util::severity_error,
0356 util::severity_error,
0357 util::severity_error,
0358 util::severity_error,
0359 util::severity_error,
0360 util::severity_fatal,
0361 util::severity_error,
0362 util::severity_error,
0363 util::severity_error,
0364 util::severity_error,
0365 util::severity_warning,
0366 util::severity_warning,
0367 util::severity_error,
0368 util::severity_remark,
0369 util::severity_warning,
0370 util::severity_remark,
0371 };
0372 BOOST_ASSERT(no_error <= code && code <= last_error_number);
0373 return preprocess_exception_severity[code];
0374 }
0375 static char const *severity_text(int code)
0376 {
0377 return util::get_severity(severity_level(code));
0378 }
0379
0380 private:
0381 char buffer[512];
0382 error_code code;
0383 };
0384
0385
0386
0387 class BOOST_SYMBOL_VISIBLE macro_handling_exception :
0388 public preprocess_exception
0389 {
0390 public:
0391 macro_handling_exception(char const *what_, error_code code, std::size_t line_,
0392 std::size_t column_, char const *filename_, char const *macroname) throw()
0393 : preprocess_exception(what_, code, line_, column_, filename_)
0394 {
0395 unsigned int off = 0;
0396 while (off < sizeof(name) - 1 && *macroname)
0397 name[off++] = *macroname++;
0398 name[off] = 0;
0399 }
0400 ~macro_handling_exception() throw() {}
0401
0402 char const *what() const throw() BOOST_OVERRIDE
0403 {
0404 return "boost::wave::macro_handling_exception";
0405 }
0406 char const* get_related_name() const throw() BOOST_OVERRIDE
0407 {
0408 return name;
0409 }
0410
0411 private:
0412 char name[512];
0413 };
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424 inline bool
0425 is_recoverable(cpp_exception const& e)
0426 {
0427 return e.is_recoverable();
0428 }
0429
0430
0431 }
0432 }
0433
0434
0435 #ifdef BOOST_HAS_ABI_HEADERS
0436 #include BOOST_ABI_SUFFIX
0437 #endif
0438
0439 #endif