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 #include "sysc/kernel/sc_except.h"
00036 #include <string>
00037 
00038 namespace sc_core {
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 enum sc_severity {
00047     SC_INFO = 0,        
00048     SC_WARNING, 
00049     SC_ERROR,   
00050     SC_FATAL,   
00051     SC_MAX_SEVERITY
00052 };
00053 
00054 typedef unsigned sc_actions;
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062  enum sc_verbosity { 
00063      SC_NONE = 0, 
00064      SC_LOW = 100, 
00065      SC_MEDIUM = 200, 
00066      SC_HIGH = 300,
00067      SC_FULL = 400, 
00068      SC_DEBUG = 500
00069  };
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 enum {
00078     SC_UNSPECIFIED  = 0x0000, 
00079     SC_DO_NOTHING   = 0x0001, 
00080     SC_THROW        = 0x0002, 
00081     SC_LOG          = 0x0004, 
00082     SC_DISPLAY      = 0x0008, 
00083     SC_CACHE_REPORT = 0x0010, 
00084     SC_INTERRUPT    = 0x0020, 
00085     SC_STOP         = 0x0040, 
00086     SC_ABORT        = 0x0080  
00087 };
00088 
00089 class sc_object;
00090 class sc_time;
00091 struct sc_msg_def;
00092 class sc_report;
00093 class sc_report_handler;
00094 const std::string sc_report_compose_message( const sc_report& );
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 class sc_report : public std::exception
00103 {
00104     friend class sc_report_handler;
00105     friend sc_report* sc_handle_exception();
00106 
00107     sc_report(); 
00108 
00109 public:
00110 
00111     sc_report(const sc_report&);
00112 
00113     sc_report & operator=(const sc_report&);
00114 
00115     virtual ~sc_report() throw();
00116 
00117     const char * get_msg_type() const;
00118 
00119     const char * get_msg() const
00120         { return msg; }
00121 
00122     sc_severity get_severity() const
00123         { return severity; }
00124 
00125     const char * get_file_name() const
00126         { return file; }
00127 
00128     int get_line_number() const
00129         { return line; }
00130 
00131     const sc_time & get_time() const
00132         { return *timestamp; }
00133 
00134     const char* get_process_name() const;
00135 
00136     int get_verbosity() const { return m_verbosity_level; }
00137 
00138     bool valid () const
00139         {
00140             return process != 0;
00141         }
00142 
00143     virtual const char* what() const throw()
00144         { 
00145             return m_what;
00146         }
00147 
00148     void swap( sc_report& );
00149 
00150 protected:
00151 
00152     sc_report(sc_severity,
00153               const sc_msg_def*,
00154               const char* msg,
00155               const char* file,
00156               int line,
00157               int verbosity_level=SC_MEDIUM);
00158 
00159     sc_severity        severity;
00160     const sc_msg_def*  md;
00161     char*              msg;
00162     char*              file;
00163     int                line;
00164     sc_time*           timestamp;
00165     sc_object*         process;
00166     int                m_verbosity_level;
00167     char*              m_what;
00168 
00169 public:  
00170 
00171     static const char* get_message(int id);
00172     static bool is_suppressed(int id);
00173     static void make_warnings_errors(bool);
00174     static void register_id(int id, const char* msg);
00175     static void suppress_id(int id, bool); 
00176     static void suppress_infos(bool);
00177     static void suppress_warnings(bool);
00178 
00179     int get_id() const;
00180 };
00181 typedef std::exception sc_exception;
00182 
00183 #define SC_DEFAULT_INFO_ACTIONS \
00184    (::sc_core::SC_LOG | ::sc_core::SC_DISPLAY)
00185 #define SC_DEFAULT_WARNING_ACTIONS \
00186    (::sc_core::SC_LOG | ::sc_core::SC_DISPLAY)
00187 #define SC_DEFAULT_ERROR_ACTIONS \
00188    (::sc_core::SC_LOG | ::sc_core::SC_CACHE_REPORT | ::sc_core::SC_THROW)
00189 #define SC_DEFAULT_FATAL_ACTIONS \
00190    (::sc_core::SC_LOG | ::sc_core::SC_DISPLAY | \
00191     ::sc_core::SC_CACHE_REPORT | ::sc_core::SC_ABORT)
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 #define SC_REPORT_INFO( msg_type, msg )    \
00201     ::sc_core::sc_report_handler::report(  \
00202             ::sc_core::SC_INFO, msg_type, msg, __FILE__, __LINE__ )
00203 
00204 #define SC_REPORT_INFO_VERB( msg_type, msg, verbosity )   \
00205     ::sc_core::sc_report_handler::report(                 \
00206             ::sc_core::SC_INFO, msg_type, msg, verbosity, \
00207                                __FILE__ , __LINE__ )
00208 
00209 #define SC_REPORT_WARNING( msg_type, msg ) \
00210     ::sc_core::sc_report_handler::report(  \
00211             ::sc_core::SC_WARNING, msg_type, msg, __FILE__, __LINE__ )
00212 
00213 #define SC_REPORT_ERROR( msg_type, msg )  \
00214     ::sc_core::sc_report_handler::report( \
00215             ::sc_core::SC_ERROR, msg_type, msg, __FILE__, __LINE__ )
00216 
00217 #define SC_REPORT_FATAL( msg_type, msg )  \
00218     ::sc_core::sc_report_handler::report( \
00219             ::sc_core::SC_FATAL, msg_type, msg, __FILE__, __LINE__ )
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 #ifdef NDEBUG
00229 
00230 #define sc_assert(expr) \
00231  ((void) 0)
00232 
00233 #else
00234 
00235 #define sc_assert(expr) \
00236  ((void)((expr) ? 0 :   \
00237      (SC_REPORT_FATAL( ::sc_core::SC_ID_ASSERTION_FAILED_, #expr ), 0)))
00238 
00239 #endif // NDEBUG
00240 
00241 extern const char SC_ID_UNKNOWN_ERROR_[];
00242 extern const char SC_ID_WITHOUT_MESSAGE_[];
00243 extern const char SC_ID_NOT_IMPLEMENTED_[];
00244 extern const char SC_ID_INTERNAL_ERROR_[];
00245 extern const char SC_ID_ASSERTION_FAILED_[];
00246 extern const char SC_ID_OUT_OF_BOUNDS_[];
00247 
00248 
00249 extern const char SC_ID_REGISTER_ID_FAILED_[];
00250 
00251 } 
00252 
00253 #include "sysc/utils/sc_report_handler.h"
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269 
00270 
00271 
00272 
00273 
00274 
00275 
00276 
00277 
00278 
00279 
00280 
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295 
00296 
00297 #endif // SC_REPORT_H