annotate DEPENDENCIES/generic/include/boost/wave/cpp_exceptions.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*=============================================================================
Chris@16 2 Boost.Wave: A Standard compliant C++ preprocessor library
Chris@16 3
Chris@16 4 http://www.boost.org/
Chris@16 5
Chris@16 6 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
Chris@16 7 Software License, Version 1.0. (See accompanying file
Chris@16 8 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 =============================================================================*/
Chris@16 10
Chris@16 11 #if !defined(CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED)
Chris@16 12 #define CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED
Chris@16 13
Chris@16 14 #include <exception>
Chris@16 15 #include <string>
Chris@16 16 #include <limits>
Chris@16 17
Chris@16 18 #include <boost/assert.hpp>
Chris@16 19 #include <boost/config.hpp>
Chris@16 20 #include <boost/throw_exception.hpp>
Chris@16 21 #include <boost/wave/wave_config.hpp>
Chris@16 22 #include <boost/wave/cpp_throw.hpp>
Chris@16 23
Chris@16 24 // this must occur after all of the includes and before any code appears
Chris@16 25 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 26 #include BOOST_ABI_PREFIX
Chris@16 27 #endif
Chris@16 28
Chris@16 29 ///////////////////////////////////////////////////////////////////////////////
Chris@16 30 namespace boost {
Chris@16 31 namespace wave {
Chris@16 32
Chris@16 33 ///////////////////////////////////////////////////////////////////////////////
Chris@16 34 // exception severity
Chris@16 35 namespace util {
Chris@16 36
Chris@16 37 enum severity {
Chris@16 38 severity_remark = 0,
Chris@16 39 severity_warning,
Chris@16 40 severity_error,
Chris@16 41 severity_fatal,
Chris@16 42 severity_commandline_error,
Chris@16 43 last_severity_code = severity_commandline_error
Chris@16 44 };
Chris@16 45
Chris@16 46 inline char const *
Chris@16 47 get_severity(int level)
Chris@16 48 {
Chris@16 49 static char const *severity_text[] =
Chris@16 50 {
Chris@16 51 "remark", // severity_remark
Chris@16 52 "warning", // severity_warning
Chris@16 53 "error", // severity_error
Chris@16 54 "fatal error", // severity_fatal
Chris@16 55 "command line error" // severity_commandline_error
Chris@16 56 };
Chris@16 57 BOOST_ASSERT(severity_remark <= level &&
Chris@16 58 level <= last_severity_code);
Chris@16 59 return severity_text[level];
Chris@16 60 }
Chris@16 61 }
Chris@16 62
Chris@16 63 ///////////////////////////////////////////////////////////////////////////////
Chris@16 64 // cpp_exception, the base class for all specific C preprocessor exceptions
Chris@16 65 class BOOST_SYMBOL_VISIBLE cpp_exception
Chris@16 66 : public std::exception
Chris@16 67 {
Chris@16 68 public:
Chris@16 69 cpp_exception(std::size_t line_, std::size_t column_, char const *filename_) throw()
Chris@16 70 : line(line_), column(column_)
Chris@16 71 {
Chris@16 72 unsigned int off = 0;
Chris@16 73 while (off < sizeof(filename)-1 && *filename_)
Chris@16 74 filename[off++] = *filename_++;
Chris@16 75 filename[off] = 0;
Chris@16 76 }
Chris@16 77 ~cpp_exception() throw() {}
Chris@16 78
Chris@16 79 virtual char const *what() const throw() = 0; // to be overloaded
Chris@16 80 virtual char const *description() const throw() = 0;
Chris@16 81 virtual int get_errorcode() const throw() = 0;
Chris@16 82 virtual int get_severity() const throw() = 0;
Chris@16 83 virtual char const* get_related_name() const throw() = 0;
Chris@16 84 virtual bool is_recoverable() const throw() = 0;
Chris@16 85
Chris@16 86 std::size_t line_no() const throw() { return line; }
Chris@16 87 std::size_t column_no() const throw() { return column; }
Chris@16 88 char const *file_name() const throw() { return filename; }
Chris@16 89
Chris@16 90 protected:
Chris@16 91 char filename[512];
Chris@16 92 std::size_t line;
Chris@16 93 std::size_t column;
Chris@16 94 };
Chris@16 95
Chris@16 96 ///////////////////////////////////////////////////////////////////////////////
Chris@16 97 // preprocessor error
Chris@16 98 class BOOST_SYMBOL_VISIBLE preprocess_exception :
Chris@16 99 public cpp_exception
Chris@16 100 {
Chris@16 101 public:
Chris@16 102 enum error_code {
Chris@16 103 no_error = 0,
Chris@16 104 unexpected_error,
Chris@16 105 macro_redefinition,
Chris@16 106 macro_insertion_error,
Chris@16 107 bad_include_file,
Chris@16 108 bad_include_statement,
Chris@16 109 ill_formed_directive,
Chris@16 110 error_directive,
Chris@16 111 warning_directive,
Chris@16 112 ill_formed_expression,
Chris@16 113 missing_matching_if,
Chris@16 114 missing_matching_endif,
Chris@16 115 ill_formed_operator,
Chris@16 116 bad_define_statement,
Chris@16 117 bad_define_statement_va_args,
Chris@16 118 too_few_macroarguments,
Chris@16 119 too_many_macroarguments,
Chris@16 120 empty_macroarguments,
Chris@16 121 improperly_terminated_macro,
Chris@16 122 bad_line_statement,
Chris@16 123 bad_line_number,
Chris@16 124 bad_line_filename,
Chris@16 125 bad_undefine_statement,
Chris@16 126 bad_macro_definition,
Chris@16 127 illegal_redefinition,
Chris@16 128 duplicate_parameter_name,
Chris@16 129 invalid_concat,
Chris@16 130 last_line_not_terminated,
Chris@16 131 ill_formed_pragma_option,
Chris@16 132 include_nesting_too_deep,
Chris@16 133 misplaced_operator,
Chris@16 134 alreadydefined_name,
Chris@16 135 undefined_macroname,
Chris@16 136 invalid_macroname,
Chris@16 137 unexpected_qualified_name,
Chris@16 138 division_by_zero,
Chris@16 139 integer_overflow,
Chris@16 140 illegal_operator_redefinition,
Chris@16 141 ill_formed_integer_literal,
Chris@16 142 ill_formed_character_literal,
Chris@16 143 unbalanced_if_endif,
Chris@16 144 character_literal_out_of_range,
Chris@16 145 could_not_open_output_file,
Chris@16 146 incompatible_config,
Chris@16 147 ill_formed_pragma_message,
Chris@16 148 pragma_message_directive,
Chris@16 149 last_error_number = pragma_message_directive
Chris@16 150 };
Chris@16 151
Chris@16 152 preprocess_exception(char const *what_, error_code code, std::size_t line_,
Chris@16 153 std::size_t column_, char const *filename_) throw()
Chris@16 154 : cpp_exception(line_, column_, filename_),
Chris@16 155 code(code)
Chris@16 156 {
Chris@16 157 unsigned int off = 0;
Chris@16 158 while (off < sizeof(buffer) && *what_)
Chris@16 159 buffer[off++] = *what_++;
Chris@16 160 buffer[off] = 0;
Chris@16 161 }
Chris@16 162 ~preprocess_exception() throw() {}
Chris@16 163
Chris@16 164 virtual char const *what() const throw()
Chris@16 165 {
Chris@16 166 return "boost::wave::preprocess_exception";
Chris@16 167 }
Chris@16 168 virtual char const *description() const throw()
Chris@16 169 {
Chris@16 170 return buffer;
Chris@16 171 }
Chris@16 172 virtual int get_severity() const throw()
Chris@16 173 {
Chris@16 174 return severity_level(code);
Chris@16 175 }
Chris@16 176 virtual int get_errorcode() const throw()
Chris@16 177 {
Chris@16 178 return code;
Chris@16 179 }
Chris@16 180 virtual char const* get_related_name() const throw()
Chris@16 181 {
Chris@16 182 return "<unknown>";
Chris@16 183 }
Chris@16 184 virtual bool is_recoverable() const throw()
Chris@16 185 {
Chris@16 186 switch (get_errorcode()) {
Chris@16 187 // these are the exceptions thrown during processing not supposed to
Chris@16 188 // produce any tokens on the context::iterator level
Chris@16 189 case preprocess_exception::no_error: // just a placeholder
Chris@16 190 case preprocess_exception::macro_redefinition:
Chris@16 191 case preprocess_exception::macro_insertion_error:
Chris@16 192 case preprocess_exception::bad_macro_definition:
Chris@16 193 case preprocess_exception::illegal_redefinition:
Chris@16 194 case preprocess_exception::duplicate_parameter_name:
Chris@16 195 case preprocess_exception::invalid_macroname:
Chris@16 196 case preprocess_exception::bad_include_file:
Chris@16 197 case preprocess_exception::bad_include_statement:
Chris@16 198 case preprocess_exception::ill_formed_directive:
Chris@16 199 case preprocess_exception::error_directive:
Chris@16 200 case preprocess_exception::warning_directive:
Chris@16 201 case preprocess_exception::ill_formed_expression:
Chris@16 202 case preprocess_exception::missing_matching_if:
Chris@16 203 case preprocess_exception::missing_matching_endif:
Chris@16 204 case preprocess_exception::unbalanced_if_endif:
Chris@16 205 case preprocess_exception::bad_define_statement:
Chris@16 206 case preprocess_exception::bad_define_statement_va_args:
Chris@16 207 case preprocess_exception::bad_line_statement:
Chris@16 208 case preprocess_exception::bad_line_number:
Chris@16 209 case preprocess_exception::bad_line_filename:
Chris@16 210 case preprocess_exception::bad_undefine_statement:
Chris@16 211 case preprocess_exception::division_by_zero:
Chris@16 212 case preprocess_exception::integer_overflow:
Chris@16 213 case preprocess_exception::ill_formed_integer_literal:
Chris@16 214 case preprocess_exception::ill_formed_character_literal:
Chris@16 215 case preprocess_exception::character_literal_out_of_range:
Chris@16 216 case preprocess_exception::last_line_not_terminated:
Chris@16 217 case preprocess_exception::include_nesting_too_deep:
Chris@16 218 case preprocess_exception::illegal_operator_redefinition:
Chris@16 219 case preprocess_exception::incompatible_config:
Chris@16 220 case preprocess_exception::ill_formed_pragma_option:
Chris@16 221 case preprocess_exception::ill_formed_pragma_message:
Chris@16 222 case preprocess_exception::pragma_message_directive:
Chris@16 223 return true;
Chris@16 224
Chris@16 225 case preprocess_exception::unexpected_error:
Chris@16 226 case preprocess_exception::ill_formed_operator:
Chris@16 227 case preprocess_exception::too_few_macroarguments:
Chris@16 228 case preprocess_exception::too_many_macroarguments:
Chris@16 229 case preprocess_exception::empty_macroarguments:
Chris@16 230 case preprocess_exception::improperly_terminated_macro:
Chris@16 231 case preprocess_exception::invalid_concat:
Chris@16 232 case preprocess_exception::could_not_open_output_file:
Chris@16 233 break;
Chris@16 234 }
Chris@16 235 return false;
Chris@16 236 }
Chris@16 237
Chris@16 238 static char const *error_text(int code)
Chris@16 239 {
Chris@16 240 // error texts in this array must appear in the same order as the items in
Chris@16 241 // the error enum above
Chris@16 242 static char const *preprocess_exception_errors[] = {
Chris@16 243 "no error", // no_error
Chris@16 244 "unexpected error (should not happen)", // unexpected_error
Chris@16 245 "illegal macro redefinition", // macro_redefinition
Chris@16 246 "macro definition failed (out of memory?)", // macro_insertion_error
Chris@16 247 "could not find include file", // bad_include_file
Chris@16 248 "ill formed #include directive", // bad_include_statement
Chris@16 249 "ill formed preprocessor directive", // ill_formed_directive
Chris@16 250 "encountered #error directive or #pragma wave stop()", // error_directive
Chris@16 251 "encountered #warning directive", // warning_directive
Chris@16 252 "ill formed preprocessor expression", // ill_formed_expression
Chris@16 253 "the #if for this directive is missing", // missing_matching_if
Chris@16 254 "detected at least one missing #endif directive", // missing_matching_endif
Chris@16 255 "ill formed preprocessing operator", // ill_formed_operator
Chris@16 256 "ill formed #define directive", // bad_define_statement
Chris@16 257 "__VA_ARGS__ can only appear in the "
Chris@16 258 "expansion of a C99 variadic macro", // bad_define_statement_va_args
Chris@16 259 "too few macro arguments", // too_few_macroarguments
Chris@16 260 "too many macro arguments", // too_many_macroarguments
Chris@16 261 "empty macro arguments are not supported in pure C++ mode, "
Chris@16 262 "use variadics mode to allow these", // empty_macroarguments
Chris@16 263 "improperly terminated macro invocation "
Chris@16 264 "or replacement-list terminates in partial "
Chris@16 265 "macro expansion (not supported yet)", // improperly_terminated_macro
Chris@16 266 "ill formed #line directive", // bad_line_statement
Chris@16 267 "line number argument of #line directive "
Chris@16 268 "should consist out of decimal digits "
Chris@16 269 "only and must be in range of [1..INT_MAX]", // bad_line_number
Chris@16 270 "filename argument of #line directive should "
Chris@16 271 "be a narrow string literal", // bad_line_filename
Chris@16 272 "#undef may not be used on this predefined name", // bad_undefine_statement
Chris@16 273 "invalid macro definition", // bad_macro_definition
Chris@16 274 "this predefined name may not be redefined", // illegal_redefinition
Chris@16 275 "duplicate macro parameter name", // duplicate_parameter_name
Chris@16 276 "pasting the following two tokens does not "
Chris@16 277 "give a valid preprocessing token", // invalid_concat
Chris@16 278 "last line of file ends without a newline", // last_line_not_terminated
Chris@16 279 "unknown or illformed pragma option", // ill_formed_pragma_option
Chris@16 280 "include files nested too deep", // include_nesting_too_deep
Chris@16 281 "misplaced operator defined()", // misplaced_operator
Chris@16 282 "the name is already used in this scope as "
Chris@16 283 "a macro or scope name", // alreadydefined_name
Chris@16 284 "undefined macro or scope name may not be imported", // undefined_macroname
Chris@16 285 "ill formed macro name", // invalid_macroname
Chris@16 286 "qualified names are supported in C++11 mode only", // unexpected_qualified_name
Chris@16 287 "division by zero in preprocessor expression", // division_by_zero
Chris@16 288 "integer overflow in preprocessor expression", // integer_overflow
Chris@16 289 "this cannot be used as a macro name as it is "
Chris@16 290 "an operator in C++", // illegal_operator_redefinition
Chris@16 291 "ill formed integer literal or integer constant too large", // ill_formed_integer_literal
Chris@16 292 "ill formed character literal", // ill_formed_character_literal
Chris@16 293 "unbalanced #if/#endif in include file", // unbalanced_if_endif
Chris@16 294 "expression contains out of range character literal", // character_literal_out_of_range
Chris@16 295 "could not open output file", // could_not_open_output_file
Chris@16 296 "incompatible state information", // incompatible_config
Chris@16 297 "illformed pragma message", // ill_formed_pragma_message
Chris@16 298 "encountered #pragma message directive" // pragma_message_directive
Chris@16 299 };
Chris@16 300 BOOST_ASSERT(no_error <= code && code <= last_error_number);
Chris@16 301 return preprocess_exception_errors[code];
Chris@16 302 }
Chris@16 303
Chris@16 304 static util::severity severity_level(int code)
Chris@16 305 {
Chris@16 306 static util::severity preprocess_exception_severity[] = {
Chris@16 307 util::severity_remark, // no_error
Chris@16 308 util::severity_fatal, // unexpected_error
Chris@16 309 util::severity_warning, // macro_redefinition
Chris@16 310 util::severity_fatal, // macro_insertion_error
Chris@16 311 util::severity_error, // bad_include_file
Chris@16 312 util::severity_error, // bad_include_statement
Chris@16 313 util::severity_error, // ill_formed_directive
Chris@16 314 util::severity_fatal, // error_directive
Chris@16 315 util::severity_warning, // warning_directive
Chris@16 316 util::severity_error, // ill_formed_expression
Chris@16 317 util::severity_error, // missing_matching_if
Chris@16 318 util::severity_error, // missing_matching_endif
Chris@16 319 util::severity_error, // ill_formed_operator
Chris@16 320 util::severity_error, // bad_define_statement
Chris@16 321 util::severity_error, // bad_define_statement_va_args
Chris@16 322 util::severity_warning, // too_few_macroarguments
Chris@16 323 util::severity_warning, // too_many_macroarguments
Chris@16 324 util::severity_warning, // empty_macroarguments
Chris@16 325 util::severity_error, // improperly_terminated_macro
Chris@16 326 util::severity_warning, // bad_line_statement
Chris@16 327 util::severity_warning, // bad_line_number
Chris@16 328 util::severity_warning, // bad_line_filename
Chris@16 329 util::severity_warning, // bad_undefine_statement
Chris@16 330 util::severity_commandline_error, // bad_macro_definition
Chris@16 331 util::severity_warning, // illegal_redefinition
Chris@16 332 util::severity_error, // duplicate_parameter_name
Chris@16 333 util::severity_error, // invalid_concat
Chris@16 334 util::severity_warning, // last_line_not_terminated
Chris@16 335 util::severity_warning, // ill_formed_pragma_option
Chris@16 336 util::severity_fatal, // include_nesting_too_deep
Chris@16 337 util::severity_error, // misplaced_operator
Chris@16 338 util::severity_error, // alreadydefined_name
Chris@16 339 util::severity_error, // undefined_macroname
Chris@16 340 util::severity_error, // invalid_macroname
Chris@16 341 util::severity_error, // unexpected_qualified_name
Chris@16 342 util::severity_fatal, // division_by_zero
Chris@16 343 util::severity_error, // integer_overflow
Chris@16 344 util::severity_error, // illegal_operator_redefinition
Chris@16 345 util::severity_error, // ill_formed_integer_literal
Chris@16 346 util::severity_error, // ill_formed_character_literal
Chris@16 347 util::severity_warning, // unbalanced_if_endif
Chris@16 348 util::severity_warning, // character_literal_out_of_range
Chris@16 349 util::severity_error, // could_not_open_output_file
Chris@16 350 util::severity_remark, // incompatible_config
Chris@16 351 util::severity_warning, // ill_formed_pragma_message
Chris@16 352 util::severity_remark, // pragma_message_directive
Chris@16 353 };
Chris@16 354 BOOST_ASSERT(no_error <= code && code <= last_error_number);
Chris@16 355 return preprocess_exception_severity[code];
Chris@16 356 }
Chris@16 357 static char const *severity_text(int code)
Chris@16 358 {
Chris@16 359 return util::get_severity(severity_level(code));
Chris@16 360 }
Chris@16 361
Chris@16 362 private:
Chris@16 363 char buffer[512];
Chris@16 364 error_code code;
Chris@16 365 };
Chris@16 366
Chris@16 367 ///////////////////////////////////////////////////////////////////////////////
Chris@16 368 // Error during macro handling, this exception contains the related macro name
Chris@16 369 class BOOST_SYMBOL_VISIBLE macro_handling_exception :
Chris@16 370 public preprocess_exception
Chris@16 371 {
Chris@16 372 public:
Chris@16 373 macro_handling_exception(char const *what_, error_code code, std::size_t line_,
Chris@16 374 std::size_t column_, char const *filename_, char const *macroname) throw()
Chris@16 375 : preprocess_exception(what_, code, line_, column_, filename_)
Chris@16 376 {
Chris@16 377 unsigned int off = 0;
Chris@16 378 while (off < sizeof(name) && *macroname)
Chris@16 379 name[off++] = *macroname++;
Chris@16 380 name[off] = 0;
Chris@16 381 }
Chris@16 382 ~macro_handling_exception() throw() {}
Chris@16 383
Chris@16 384 virtual char const *what() const throw()
Chris@16 385 {
Chris@16 386 return "boost::wave::macro_handling_exception";
Chris@16 387 }
Chris@16 388 char const* get_related_name() const throw()
Chris@16 389 {
Chris@16 390 return name;
Chris@16 391 }
Chris@16 392
Chris@16 393 private:
Chris@16 394 char name[512];
Chris@16 395 };
Chris@16 396
Chris@16 397 ///////////////////////////////////////////////////////////////////////////////
Chris@16 398 //
Chris@16 399 // The is_recoverable() function allows to decide, whether it is possible
Chris@16 400 // simply to continue after a given exception was thrown by Wave.
Chris@16 401 //
Chris@16 402 // This is kind of a hack to allow to recover from certain errors as long as
Chris@16 403 // Wave doesn't provide better means of error recovery.
Chris@16 404 //
Chris@16 405 ///////////////////////////////////////////////////////////////////////////////
Chris@16 406 inline bool
Chris@16 407 is_recoverable(cpp_exception const& e)
Chris@16 408 {
Chris@16 409 return e.is_recoverable();
Chris@16 410 }
Chris@16 411
Chris@16 412 ///////////////////////////////////////////////////////////////////////////////
Chris@16 413 } // namespace wave
Chris@16 414 } // namespace boost
Chris@16 415
Chris@16 416 // the suffix header occurs after all of the code
Chris@16 417 #ifdef BOOST_HAS_ABI_HEADERS
Chris@16 418 #include BOOST_ABI_SUFFIX
Chris@16 419 #endif
Chris@16 420
Chris@16 421 #endif // !defined(CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED)