File indexing completed on 2025-01-18 09:53:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #if !defined(BOOST_CPPLEXER_EXCEPTIONS_HPP_1A09DE1A_6D1F_4091_AF7F_5F13AB0D31AB_INCLUDED)
0012 #define BOOST_CPPLEXER_EXCEPTIONS_HPP_1A09DE1A_6D1F_4091_AF7F_5F13AB0D31AB_INCLUDED
0013
0014 #include <exception>
0015 #include <string>
0016
0017 #include <boost/assert.hpp>
0018 #include <boost/config.hpp>
0019 #include <boost/throw_exception.hpp>
0020
0021 #include <boost/wave/wave_config.hpp>
0022
0023
0024 #ifdef BOOST_HAS_ABI_HEADERS
0025 #include BOOST_ABI_PREFIX
0026 #endif
0027
0028
0029
0030 #if !defined(BOOST_WAVE_LEXER_THROW)
0031 #ifdef BOOST_NO_STRINGSTREAM
0032 #include <strstream>
0033 #define BOOST_WAVE_LEXER_THROW(cls, code, msg, line, column, name) \
0034 { \
0035 using namespace boost::wave; \
0036 std::strstream stream; \
0037 stream << cls::severity_text(cls::code) << ": " \
0038 << cls::error_text(cls::code); \
0039 if ((msg)[0] != 0) stream << ": " << (msg); \
0040 stream << std::ends; \
0041 std::string throwmsg = stream.str(); stream.freeze(false); \
0042 boost::throw_exception(cls(throwmsg.c_str(), cls::code, line, column, \
0043 name)); \
0044 } \
0045
0046 #else
0047 #include <sstream>
0048 #define BOOST_WAVE_LEXER_THROW(cls, code, msg, line, column, name) \
0049 { \
0050 using namespace boost::wave; \
0051 std::stringstream stream; \
0052 stream << cls::severity_text(cls::code) << ": " \
0053 << cls::error_text(cls::code); \
0054 if ((msg)[0] != 0) stream << ": " << (msg); \
0055 stream << std::ends; \
0056 boost::throw_exception(cls(stream.str().c_str(), cls::code, line, column, \
0057 name)); \
0058 } \
0059
0060 #endif
0061 #endif
0062
0063 #if !defined(BOOST_WAVE_LEXER_THROW_VAR)
0064 #ifdef BOOST_NO_STRINGSTREAM
0065 #include <strstream>
0066 #define BOOST_WAVE_LEXER_THROW_VAR(cls, codearg, msg, line, column, name) \
0067 { \
0068 using namespace boost::wave; \
0069 cls::error_code code = static_cast<cls::error_code>(codearg); \
0070 std::strstream stream; \
0071 stream << cls::severity_text(code) << ": " \
0072 << cls::error_text(code); \
0073 if ((msg)[0] != 0) stream << ": " << (msg); \
0074 stream << std::ends; \
0075 std::string throwmsg = stream.str(); stream.freeze(false); \
0076 boost::throw_exception(cls(throwmsg.c_str(), code, line, column, \
0077 name)); \
0078 } \
0079
0080 #else
0081 #include <sstream>
0082 #define BOOST_WAVE_LEXER_THROW_VAR(cls, codearg, msg, line, column, name) \
0083 { \
0084 using namespace boost::wave; \
0085 cls::error_code code = static_cast<cls::error_code>(codearg); \
0086 std::stringstream stream; \
0087 stream << cls::severity_text(code) << ": " \
0088 << cls::error_text(code); \
0089 if ((msg)[0] != 0) stream << ": " << (msg); \
0090 stream << std::ends; \
0091 boost::throw_exception(cls(stream.str().c_str(), code, line, column, \
0092 name)); \
0093 } \
0094
0095 #endif
0096 #endif
0097
0098
0099 namespace boost {
0100 namespace wave {
0101 namespace cpplexer {
0102
0103
0104
0105 namespace util {
0106
0107 enum severity {
0108 severity_remark = 0,
0109 severity_warning,
0110 severity_error,
0111 severity_fatal
0112 };
0113
0114 inline char const *
0115 get_severity(severity level)
0116 {
0117 static char const *severity_text[] =
0118 {
0119 "remark",
0120 "warning",
0121 "error",
0122 "fatal error"
0123 };
0124 BOOST_ASSERT(severity_remark <= level && level <= severity_fatal);
0125 return severity_text[level];
0126 }
0127 }
0128
0129
0130
0131 class BOOST_SYMBOL_VISIBLE cpplexer_exception
0132 : public std::exception
0133 {
0134 public:
0135 cpplexer_exception(std::size_t line_, std::size_t column_, char const *filename_) throw()
0136 : line(line_), column(column_)
0137 {
0138 unsigned int off = 0;
0139 while (off < sizeof(filename)-1 && *filename_)
0140 filename[off++] = *filename_++;
0141 filename[off] = 0;
0142 }
0143 ~cpplexer_exception() throw() {}
0144
0145 char const *what() const throw() BOOST_OVERRIDE = 0;
0146 virtual char const *description() const throw() = 0;
0147 virtual int get_errorcode() const throw() = 0;
0148 virtual int get_severity() const throw() = 0;
0149 virtual bool is_recoverable() const throw() = 0;
0150
0151 std::size_t line_no() const throw() { return line; }
0152 std::size_t column_no() const throw() { return column; }
0153 char const *file_name() const throw() { return filename; }
0154
0155 protected:
0156 char filename[512];
0157 std::size_t line;
0158 std::size_t column;
0159 };
0160
0161
0162
0163 class BOOST_SYMBOL_VISIBLE lexing_exception :
0164 public cpplexer_exception
0165 {
0166 public:
0167 enum error_code {
0168 unexpected_error = 0,
0169 universal_char_invalid = 1,
0170 universal_char_base_charset = 2,
0171 universal_char_not_allowed = 3,
0172 invalid_long_long_literal = 4,
0173 generic_lexing_error = 5,
0174 generic_lexing_warning = 6
0175 };
0176
0177 lexing_exception(char const *what_, error_code code, std::size_t line_,
0178 std::size_t column_, char const *filename_) throw()
0179 : cpplexer_exception(line_, column_, filename_),
0180 level(severity_level(code)), code(code)
0181 {
0182 unsigned int off = 0;
0183 while (off < sizeof(buffer)-1 && *what_)
0184 buffer[off++] = *what_++;
0185 buffer[off] = 0;
0186 }
0187 ~lexing_exception() throw() {}
0188
0189 char const *what() const throw() BOOST_OVERRIDE
0190 {
0191 return "boost::wave::lexing_exception";
0192 }
0193 char const *description() const throw() BOOST_OVERRIDE
0194 {
0195 return buffer;
0196 }
0197 int get_severity() const throw() BOOST_OVERRIDE
0198 {
0199 return level;
0200 }
0201 int get_errorcode() const throw() BOOST_OVERRIDE
0202 {
0203 return code;
0204 }
0205 bool is_recoverable() const throw() BOOST_OVERRIDE
0206 {
0207 switch (get_errorcode()) {
0208 case lexing_exception::universal_char_invalid:
0209 case lexing_exception::universal_char_base_charset:
0210 case lexing_exception::universal_char_not_allowed:
0211 case lexing_exception::invalid_long_long_literal:
0212 case lexing_exception::generic_lexing_warning:
0213 case lexing_exception::generic_lexing_error:
0214 return true;
0215
0216 case lexing_exception::unexpected_error:
0217 default:
0218 break;
0219 }
0220 return false;
0221 }
0222
0223 static char const *error_text(int code)
0224 {
0225
0226
0227 static char const *preprocess_exception_errors[] = {
0228 "unexpected error (should not happen)",
0229 "universal character name specifies an invalid character",
0230 "a universal character name cannot designate a character in the "
0231 "basic character set",
0232 "this universal character is not allowed in an identifier",
0233 "long long suffixes are not allowed in pure C++ mode, "
0234 "enable long_long mode to allow these",
0235 "generic lexer error",
0236 "generic lexer warning"
0237 };
0238 return preprocess_exception_errors[code];
0239 }
0240
0241 static util::severity severity_level(int code)
0242 {
0243 static util::severity preprocess_exception_severity[] = {
0244 util::severity_fatal,
0245 util::severity_error,
0246 util::severity_error,
0247 util::severity_error,
0248 util::severity_warning,
0249 util::severity_error,
0250 util::severity_warning
0251 };
0252 return preprocess_exception_severity[code];
0253 }
0254 static char const *severity_text(int code)
0255 {
0256 return util::get_severity(severity_level(code));
0257 }
0258
0259 private:
0260 char buffer[512];
0261 util::severity level;
0262 error_code code;
0263 };
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274 inline bool
0275 is_recoverable(lexing_exception const& e)
0276 {
0277 return e.is_recoverable();
0278 }
0279
0280
0281 }
0282 }
0283 }
0284
0285
0286 #ifdef BOOST_HAS_ABI_HEADERS
0287 #include BOOST_ABI_SUFFIX
0288 #endif
0289
0290 #endif