00001 #ifndef SC_REPORT_H
00002 #define SC_REPORT_H 1
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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <exception>
00045 #include <string>
00046
00047 namespace sc_core {
00048
00049
00050
00051
00052
00053
00054
00055 enum sc_severity {
00056 SC_INFO = 0,
00057 SC_WARNING,
00058 SC_ERROR,
00059 SC_FATAL,
00060 SC_MAX_SEVERITY
00061 };
00062
00063 typedef unsigned sc_actions;
00064
00065
00066
00067
00068
00069
00070
00071 enum {
00072 SC_UNSPECIFIED = 0x0000,
00073 SC_DO_NOTHING = 0x0001,
00074 SC_THROW = 0x0002,
00075 SC_LOG = 0x0004,
00076 SC_DISPLAY = 0x0008,
00077 SC_CACHE_REPORT = 0x0010,
00078 SC_INTERRUPT = 0x0020,
00079 SC_STOP = 0x0040,
00080 SC_ABORT = 0x0080
00081 };
00082
00083 class sc_object;
00084 class sc_time;
00085 struct sc_msg_def;
00086 class sc_report;
00087 const std::string sc_report_compose_message( const sc_report& );
00088
00089
00090
00091
00092
00093
00094
00095 class sc_report : public std::exception
00096 {
00097 public:
00098
00099 sc_report();
00100
00101 sc_report(const sc_report&);
00102
00103 sc_report & operator=(const sc_report&);
00104
00105 virtual ~sc_report() throw();
00106
00107 const char * get_msg_type() const;
00108
00109 const char * get_msg() const
00110 { return msg; }
00111
00112 sc_severity get_severity() const
00113 { return severity; }
00114
00115 const char * get_file_name() const
00116 { return file; }
00117
00118 int get_line_number() const
00119 { return line; }
00120
00121 const sc_time & get_time() const
00122 { return *timestamp; }
00123
00124 const char* get_process_name() const;
00125
00126 bool valid () const
00127 {
00128 return process != 0;
00129 }
00130
00131 virtual const char* what() const throw()
00132 {
00133 return m_what;
00134 }
00135
00136 protected:
00137
00138 friend class sc_report_handler;
00139
00140
00141 sc_report(sc_severity,
00142 const sc_msg_def*,
00143 const char* msg,
00144 const char* file,
00145 int line);
00146
00147
00148
00149 sc_severity severity;
00150 const sc_msg_def* md;
00151 char* msg;
00152 char* file;
00153 int line;
00154 sc_time* timestamp;
00155 sc_object* process;
00156 char* m_what;
00157
00158 public:
00159
00160 static const char* get_message(int id);
00161 static bool is_suppressed(int id);
00162 static void make_warnings_errors(bool);
00163 static void register_id(int id, const char* msg);
00164 static void suppress_id(int id, bool);
00165 static void suppress_infos(bool);
00166 static void suppress_warnings(bool);
00167
00168 int get_id() const;
00169 };
00170 typedef std::exception sc_exception;
00171
00172 #define SC_DEFAULT_INFO_ACTIONS (SC_LOG | SC_DISPLAY)
00173 #define SC_DEFAULT_WARNING_ACTIONS (SC_LOG | SC_DISPLAY)
00174 #define SC_DEFAULT_ERROR_ACTIONS (SC_LOG | SC_CACHE_REPORT | SC_THROW)
00175 #define SC_DEFAULT_FATAL_ACTIONS \
00176 (SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT)
00177
00178
00179
00180
00181
00182
00183
00184
00185 #define SC_REPORT_INFO(id,msg) \
00186 sc_core::sc_report_handler::report( \
00187 sc_core::SC_INFO, id, msg, __FILE__, __LINE__ )
00188
00189 #define SC_REPORT_WARNING(id,msg) \
00190 sc_core::sc_report_handler::report(\
00191 sc_core::SC_WARNING, id, msg, __FILE__, __LINE__)
00192
00193 #define SC_REPORT_ERROR(id,msg) \
00194 sc_core::sc_report_handler::report( \
00195 sc_core::SC_ERROR, id, msg, __FILE__, __LINE__ )
00196
00197 #define SC_REPORT_FATAL(id,msg) \
00198 sc_core::sc_report_handler::report( \
00199 sc_core::SC_FATAL, id, msg, __FILE__, __LINE__ )
00200
00201
00202
00203
00204
00205
00206
00207
00208 #ifdef NDEBUG
00209
00210 #define sc_assert(expr) \
00211 ((void) 0)
00212
00213 #else
00214
00215 #define sc_assert(expr) \
00216 ((void) ((expr) ? 0 : (SC_REPORT_FATAL( SC_ID_ASSERTION_FAILED_ , #expr ), 0)))
00217
00218 #endif
00219
00220 extern const char SC_ID_UNKNOWN_ERROR_[];
00221 extern const char SC_ID_WITHOUT_MESSAGE_[];
00222 extern const char SC_ID_NOT_IMPLEMENTED_[];
00223 extern const char SC_ID_INTERNAL_ERROR_[];
00224 extern const char SC_ID_ASSERTION_FAILED_[];
00225 extern const char SC_ID_OUT_OF_BOUNDS_[];
00226
00227
00228 extern const char SC_ID_REGISTER_ID_FAILED_[];
00229
00230 }
00231
00232 #include "sysc/utils/sc_report_handler.h"
00233
00234 #endif // SC_REPORT_H