Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:43

0001 /*=============================================================================
0002     Boost.Wave: A Standard compliant C++ preprocessor library
0003 
0004     http://www.boost.org/
0005 
0006     Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
0007     Software License, Version 1.0. (See accompanying file
0008     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
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 // this must occur after all of the includes and before any code appears
0025 #ifdef BOOST_HAS_ABI_HEADERS
0026 #include BOOST_ABI_PREFIX
0027 #endif
0028 
0029 ///////////////////////////////////////////////////////////////////////////////
0030 namespace boost {
0031 namespace wave {
0032 
0033 ///////////////////////////////////////////////////////////////////////////////
0034 // exception severity
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",               // severity_remark
0052             "warning",              // severity_warning
0053             "error",                // severity_error
0054             "fatal error",          // severity_fatal
0055             "command line error"    // severity_commandline_error
0056         };
0057         BOOST_ASSERT(severity_remark <= level &&
0058             level <= last_severity_code);
0059         return severity_text[level];
0060     }
0061 }
0062 
0063 ///////////////////////////////////////////////////////////////////////////////
0064 //  cpp_exception, the base class for all specific C preprocessor exceptions
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;    // to be overloaded
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 // preprocessor error
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         // these are the exceptions thrown during processing not supposed to
0192         // produce any tokens on the context::iterator level
0193         case preprocess_exception::no_error:        // just a placeholder
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         // error texts in this array must appear in the same order as the items in
0249         // the error enum above
0250         static char const *preprocess_exception_errors[] = {
0251             "no error",                                 // no_error
0252             "unexpected error (should not happen)",     // unexpected_error
0253             "illegal macro redefinition",               // macro_redefinition
0254             "macro definition failed (out of memory?)", // macro_insertion_error
0255             "could not find include file",              // bad_include_file
0256             "ill formed #include directive",            // bad_include_statement
0257             "ill formed __has_include expression",      // bad_has_include_expression
0258             "ill formed preprocessor directive",        // ill_formed_directive
0259             "encountered #error directive or #pragma wave stop()", // error_directive
0260             "encountered #warning directive",           // warning_directive
0261             "ill formed preprocessor expression",       // ill_formed_expression
0262             "the #if for this directive is missing",    // missing_matching_if
0263             "detected at least one missing #endif directive",   // missing_matching_endif
0264             "ill formed preprocessing operator",        // ill_formed_operator
0265             "ill formed #define directive",             // bad_define_statement
0266             "__VA_ARGS__ can only appear in the "
0267             "expansion of a C99 variadic macro",        // bad_define_statement_va_args
0268             "__VA_OPT__ can only appear in the "
0269             "expansion of a C++20 variadic macro",      // bad_define_statement_va_opt
0270             "__VA_OPT__ must be followed by a left "
0271             "paren in a C++20 variadic macro",          // bad_define_statement_va_opt_parens
0272             "__VA_OPT__() may not contain __VA_OPT__",  // bad_define_statement_va_opt_recurse
0273             "too few macro arguments",                  // too_few_macroarguments
0274             "too many macro arguments",                 // too_many_macroarguments
0275             "empty macro arguments are not supported in pure C++ mode, "
0276             "use variadics mode to allow these",        // empty_macroarguments
0277             "improperly terminated macro invocation "
0278             "or replacement-list terminates in partial "
0279             "macro expansion (not supported yet)",      // improperly_terminated_macro
0280             "ill formed #line directive",               // bad_line_statement
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]", // bad_line_number
0284             "filename argument of #line directive should "
0285             "be a narrow string literal",               // bad_line_filename
0286             "#undef may not be used on this predefined name",   // bad_undefine_statement
0287             "invalid macro definition",                 // bad_macro_definition
0288             "this predefined name may not be redefined",        // illegal_redefinition
0289             "duplicate macro parameter name",           // duplicate_parameter_name
0290             "pasting the following two tokens does not "
0291             "give a valid preprocessing token",         // invalid_concat
0292             "last line of file ends without a newline", // last_line_not_terminated
0293             "unknown or illformed pragma option",       // ill_formed_pragma_option
0294             "include files nested too deep",            // include_nesting_too_deep
0295             "misplaced operator defined()",             // misplaced_operator
0296             "the name is already used in this scope as "
0297             "a macro or scope name",                    // alreadydefined_name
0298             "undefined macro or scope name may not be imported", // undefined_macroname
0299             "ill formed macro name",                    // invalid_macroname
0300             "qualified names are supported in C++11 mode only",  // unexpected_qualified_name
0301             "division by zero in preprocessor expression",       // division_by_zero
0302             "integer overflow in preprocessor expression",       // integer_overflow
0303             "this cannot be used as a macro name as it is "
0304             "an operator in C++",                       // illegal_operator_redefinition
0305             "ill formed integer literal or integer constant too large",   // ill_formed_integer_literal
0306             "ill formed character literal",             // ill_formed_character_literal
0307             "unbalanced #if/#endif in include file",    // unbalanced_if_endif
0308             "expression contains out of range character literal", // character_literal_out_of_range
0309             "could not open output file",               // could_not_open_output_file
0310             "incompatible state information",           // incompatible_config
0311             "illformed pragma message",                 // ill_formed_pragma_message
0312             "encountered #pragma message directive"     // 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,             // no_error
0322             util::severity_fatal,              // unexpected_error
0323             util::severity_warning,            // macro_redefinition
0324             util::severity_fatal,              // macro_insertion_error
0325             util::severity_error,              // bad_include_file
0326             util::severity_error,              // bad_include_statement
0327             util::severity_error,              // bad_has_include_expression
0328             util::severity_error,              // ill_formed_directive
0329             util::severity_fatal,              // error_directive
0330             util::severity_warning,            // warning_directive
0331             util::severity_error,              // ill_formed_expression
0332             util::severity_error,              // missing_matching_if
0333             util::severity_error,              // missing_matching_endif
0334             util::severity_error,              // ill_formed_operator
0335             util::severity_error,              // bad_define_statement
0336             util::severity_error,              // bad_define_statement_va_args
0337             util::severity_error,              // bad_define_statement_va_opt
0338             util::severity_error,              // bad_define_statement_va_opt_parens
0339             util::severity_error,              // bad_define_statement_va_opt_recurse
0340             util::severity_warning,            // too_few_macroarguments
0341             util::severity_warning,            // too_many_macroarguments
0342             util::severity_warning,            // empty_macroarguments
0343             util::severity_error,              // improperly_terminated_macro
0344             util::severity_warning,            // bad_line_statement
0345             util::severity_warning,            // bad_line_number
0346             util::severity_warning,            // bad_line_filename
0347             util::severity_warning,            // bad_undefine_statement
0348             util::severity_commandline_error,  // bad_macro_definition
0349             util::severity_warning,            // illegal_redefinition
0350             util::severity_error,              // duplicate_parameter_name
0351             util::severity_error,              // invalid_concat
0352             util::severity_warning,            // last_line_not_terminated
0353             util::severity_warning,            // ill_formed_pragma_option
0354             util::severity_fatal,              // include_nesting_too_deep
0355             util::severity_error,              // misplaced_operator
0356             util::severity_error,              // alreadydefined_name
0357             util::severity_error,              // undefined_macroname
0358             util::severity_error,              // invalid_macroname
0359             util::severity_error,              // unexpected_qualified_name
0360             util::severity_fatal,              // division_by_zero
0361             util::severity_error,              // integer_overflow
0362             util::severity_error,              // illegal_operator_redefinition
0363             util::severity_error,              // ill_formed_integer_literal
0364             util::severity_error,              // ill_formed_character_literal
0365             util::severity_warning,            // unbalanced_if_endif
0366             util::severity_warning,            // character_literal_out_of_range
0367             util::severity_error,              // could_not_open_output_file
0368             util::severity_remark,             // incompatible_config
0369             util::severity_warning,            // ill_formed_pragma_message
0370             util::severity_remark,             // pragma_message_directive
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 //  Error during macro handling, this exception contains the related macro name
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 //  The is_recoverable() function allows to decide, whether it is possible
0418 //  simply to continue after a given exception was thrown by Wave.
0419 //
0420 //  This is kind of a hack to allow to recover from certain errors as long as
0421 //  Wave doesn't provide better means of error recovery.
0422 //
0423 ///////////////////////////////////////////////////////////////////////////////
0424 inline bool
0425 is_recoverable(cpp_exception const& e)
0426 {
0427     return e.is_recoverable();
0428 }
0429 
0430 ///////////////////////////////////////////////////////////////////////////////
0431 }   // namespace wave
0432 }   // namespace boost
0433 
0434 // the suffix header occurs after all of the code
0435 #ifdef BOOST_HAS_ABI_HEADERS
0436 #include BOOST_ABI_SUFFIX
0437 #endif
0438 
0439 #endif // !defined(BOOST_CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED)