00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef CFRONT_ERROR_HPP
00035 #define CFRONT_ERROR_HPP
00036
00037 #include "error.h"
00038 #include "LocationNode.hpp"
00039 #include <list>
00040 #include <exception>
00041 #include <cstdarg>
00042
00048 namespace cfront {
00049
00050 class UncontinuableError: public std::exception {
00051 public:
00052 UncontinuableError() : std::exception() {}
00053 };
00054
00055 class InternalError : public std::exception {
00056 public:
00057 InternalError(const char* mes, const Location* loc = NULL)
00058 : message_(mes), loc_(loc) {}
00059 const char* getMessage() const { return message_; }
00060 const Location* getLocation() const { return loc_; }
00061 private:
00062 const char* message_;
00063 const Location* loc_;
00064 };
00065
00066
00070 typedef std::list<ctrump_loginfo> Logs;
00071
00072 }
00073
00074
00075 void ctrump_report_log(struct ctrump_loginfo* logInfo);
00076
00077 void ctrump_add_log(cfront::Logs* logs, int logLevel,
00078 enum ctrump_error_code code, const char* fmt,
00079 const cfront::Location& location, ...);
00080
00085 #define ERROR_BASIC(code, fmt, filename, ln, col, logs, ...) \
00086 do { \
00087 Location loc; \
00088 loc.filePath = (filename); \
00089 loc.line = (ln); \
00090 loc.column = (col); \
00091 ctrump_add_log((logs), CTRUMP_LOGLEVEL_ERROR, (code), (fmt), loc, __VA_ARGS__); \
00092 } while (0)
00093
00094
00095 #ifdef EXIT_ON_ERROR
00096 # define POSTPROCESS_ERROR \
00097 do { \
00098 throw UncontinuableError(); \
00099 } while (0)
00100 #else
00101 # define POSTPROCESS_ERROR
00102 #endif
00103
00104
00109 #define ERROR(code, fmt, logs, locNode) \
00110 do { \
00111 ctrump_add_log(logs, CTRUMP_LOGLEVEL_ERROR, code, fmt, \
00112 (locNode)->getLocation(), NULL); \
00113 POSTPROCESS_ERROR; \
00114 } while (0)
00115
00116
00121 #define ERROR1(code, fmt, logs, locNode) \
00122 do { \
00123 ctrump_add_log(logs, CTRUMP_LOGLEVEL_ERROR, code, fmt, \
00124 (locNode)->getLocation(), \
00125 (locNode)->getText().c_str(), NULL); \
00126 POSTPROCESS_ERROR; \
00127 } while (0)
00128
00129
00134 #define ERROR2(code, fmt, logs, tokenNode1, tokenNode2) \
00135 do { \
00136 ctrump_add_log(logs, CTRUMP_LOGLEVEL_ERROR, code, fmt, \
00137 (tokenNode1)->getLocation(), \
00138 (tokenNode1)->getText().c_str(), \
00139 (tokenNode2)->getText().c_str(), \
00140 NULL); \
00141 POSTPROCESS_ERROR; \
00142 } while (0)
00143
00144 #define WARNING(code, fmt, logs, locNode) \
00145 do { \
00146 ctrump_add_log(logs, CTRUMP_LOGLEVEL_WARNING, code, fmt, \
00147 (locNode)->getLocation(), NULL); \
00148 } while (0)
00149
00150
00151 #endif