123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- #if !defined(BOOST_CPPLEXER_EXCEPTIONS_HPP_1A09DE1A_6D1F_4091_AF7F_5F13AB0D31AB_INCLUDED)
- #define BOOST_CPPLEXER_EXCEPTIONS_HPP_1A09DE1A_6D1F_4091_AF7F_5F13AB0D31AB_INCLUDED
- #include <exception>
- #include <string>
- #include <boost/assert.hpp>
- #include <boost/config.hpp>
- #include <boost/throw_exception.hpp>
- #include <boost/wave/wave_config.hpp>
- #ifdef BOOST_HAS_ABI_HEADERS
- #include BOOST_ABI_PREFIX
- #endif
- #if !defined(BOOST_WAVE_LEXER_THROW)
- #ifdef BOOST_NO_STRINGSTREAM
- #include <strstream>
- #define BOOST_WAVE_LEXER_THROW(cls, code, msg, line, column, name) \
- { \
- using namespace boost::wave; \
- std::strstream stream; \
- stream << cls::severity_text(cls::code) << ": " \
- << cls::error_text(cls::code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- std::string throwmsg = stream.str(); stream.freeze(false); \
- boost::throw_exception(cls(throwmsg.c_str(), cls::code, line, column, \
- name)); \
- } \
-
- #else
- #include <sstream>
- #define BOOST_WAVE_LEXER_THROW(cls, code, msg, line, column, name) \
- { \
- using namespace boost::wave; \
- std::stringstream stream; \
- stream << cls::severity_text(cls::code) << ": " \
- << cls::error_text(cls::code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- boost::throw_exception(cls(stream.str().c_str(), cls::code, line, column, \
- name)); \
- } \
-
- #endif
- #endif
- #if !defined(BOOST_WAVE_LEXER_THROW_VAR)
- #ifdef BOOST_NO_STRINGSTREAM
- #include <strstream>
- #define BOOST_WAVE_LEXER_THROW_VAR(cls, codearg, msg, line, column, name) \
- { \
- using namespace boost::wave; \
- cls::error_code code = static_cast<cls::error_code>(codearg); \
- std::strstream stream; \
- stream << cls::severity_text(code) << ": " \
- << cls::error_text(code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- std::string throwmsg = stream.str(); stream.freeze(false); \
- boost::throw_exception(cls(throwmsg.c_str(), code, line, column, \
- name)); \
- } \
-
- #else
- #include <sstream>
- #define BOOST_WAVE_LEXER_THROW_VAR(cls, codearg, msg, line, column, name) \
- { \
- using namespace boost::wave; \
- cls::error_code code = static_cast<cls::error_code>(codearg); \
- std::stringstream stream; \
- stream << cls::severity_text(code) << ": " \
- << cls::error_text(code); \
- if ((msg)[0] != 0) stream << ": " << (msg); \
- stream << std::ends; \
- boost::throw_exception(cls(stream.str().c_str(), code, line, column, \
- name)); \
- } \
-
- #endif
- #endif
- namespace boost {
- namespace wave {
- namespace cpplexer {
- namespace util {
- enum severity {
- severity_remark = 0,
- severity_warning,
- severity_error,
- severity_fatal
- };
- inline char const *
- get_severity(severity level)
- {
- static char const *severity_text[] =
- {
- "remark",
- "warning",
- "error",
- "fatal error"
- };
- BOOST_ASSERT(severity_remark <= level && level <= severity_fatal);
- return severity_text[level];
- }
- }
- class BOOST_SYMBOL_VISIBLE cpplexer_exception
- : public std::exception
- {
- public:
- cpplexer_exception(std::size_t line_, std::size_t column_, char const *filename_) throw()
- : line(line_), column(column_)
- {
- unsigned int off = 0;
- while (off < sizeof(filename)-1 && *filename_)
- filename[off++] = *filename_++;
- filename[off] = 0;
- }
- ~cpplexer_exception() throw() {}
- char const *what() const throw() BOOST_OVERRIDE = 0;
- virtual char const *description() const throw() = 0;
- virtual int get_errorcode() const throw() = 0;
- virtual int get_severity() const throw() = 0;
- virtual bool is_recoverable() const throw() = 0;
- std::size_t line_no() const throw() { return line; }
- std::size_t column_no() const throw() { return column; }
- char const *file_name() const throw() { return filename; }
- protected:
- char filename[512];
- std::size_t line;
- std::size_t column;
- };
- class BOOST_SYMBOL_VISIBLE lexing_exception :
- public cpplexer_exception
- {
- public:
- enum error_code {
- unexpected_error = 0,
- universal_char_invalid = 1,
- universal_char_base_charset = 2,
- universal_char_not_allowed = 3,
- invalid_long_long_literal = 4,
- generic_lexing_error = 5,
- generic_lexing_warning = 6
- };
- lexing_exception(char const *what_, error_code code, std::size_t line_,
- std::size_t column_, char const *filename_) throw()
- : cpplexer_exception(line_, column_, filename_),
- level(severity_level(code)), code(code)
- {
- unsigned int off = 0;
- while (off < sizeof(buffer)-1 && *what_)
- buffer[off++] = *what_++;
- buffer[off] = 0;
- }
- ~lexing_exception() throw() {}
- char const *what() const throw() BOOST_OVERRIDE
- {
- return "boost::wave::lexing_exception";
- }
- char const *description() const throw() BOOST_OVERRIDE
- {
- return buffer;
- }
- int get_severity() const throw() BOOST_OVERRIDE
- {
- return level;
- }
- int get_errorcode() const throw() BOOST_OVERRIDE
- {
- return code;
- }
- bool is_recoverable() const throw() BOOST_OVERRIDE
- {
- switch (get_errorcode()) {
- case lexing_exception::universal_char_invalid:
- case lexing_exception::universal_char_base_charset:
- case lexing_exception::universal_char_not_allowed:
- case lexing_exception::invalid_long_long_literal:
- case lexing_exception::generic_lexing_warning:
- case lexing_exception::generic_lexing_error:
- return true;
- case lexing_exception::unexpected_error:
- default:
- break;
- }
- return false;
- }
- static char const *error_text(int code)
- {
-
-
- static char const *preprocess_exception_errors[] = {
- "unexpected error (should not happen)",
- "universal character name specifies an invalid character",
- "a universal character name cannot designate a character in the "
- "basic character set",
- "this universal character is not allowed in an identifier",
- "long long suffixes are not allowed in pure C++ mode, "
- "enable long_long mode to allow these",
- "generic lexer error",
- "generic lexer warning"
- };
- return preprocess_exception_errors[code];
- }
- static util::severity severity_level(int code)
- {
- static util::severity preprocess_exception_severity[] = {
- util::severity_fatal,
- util::severity_error,
- util::severity_error,
- util::severity_error,
- util::severity_warning,
- util::severity_error,
- util::severity_warning
- };
- return preprocess_exception_severity[code];
- }
- static char const *severity_text(int code)
- {
- return util::get_severity(severity_level(code));
- }
- private:
- char buffer[512];
- util::severity level;
- error_code code;
- };
- inline bool
- is_recoverable(lexing_exception const& e)
- {
- return e.is_recoverable();
- }
- }
- }
- }
- #ifdef BOOST_HAS_ABI_HEADERS
- #include BOOST_ABI_SUFFIX
- #endif
- #endif
|