00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef GCC_DIAGNOSTIC_H
00023 #define GCC_DIAGNOSTIC_H
00024
00025 #include "obstack.h"
00026 #include "location.h"
00027
00028
00029
00030 typedef struct
00031 {
00032 const char *format_spec;
00033 va_list *args_ptr;
00034 } text_info;
00035
00036
00037 typedef enum
00038 {
00039 #define DEFINE_DIAGNOSTIC_KIND(K, M) K,
00040 #include "diagnostic.def"
00041 #undef DEFINE_DIAGNOSTIC_KIND
00042 DK_LAST_DIAGNOSTIC_KIND
00043 } diagnostic_t;
00044
00045
00046
00047
00048 typedef struct
00049 {
00050 text_info message;
00051 location_t location;
00052
00053 diagnostic_t kind;
00054 } diagnostic_info;
00055
00056 #define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
00057
00058
00059
00060
00061
00062
00063 typedef enum
00064 {
00065 DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0,
00066 DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1,
00067 DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2
00068 } diagnostic_prefixing_rule_t;
00069
00070
00071 typedef struct
00072 {
00073
00074 const char *prefix;
00075
00076
00077
00078 int maximum_length;
00079
00080
00081
00082 int ideal_maximum_length;
00083
00084
00085 int indent_skip;
00086
00087
00088 bool emitted_prefix_p;
00089
00090
00091 bool need_newline_p;
00092
00093
00094 diagnostic_prefixing_rule_t prefixing_rule;
00095 } output_state;
00096
00097
00098
00099
00100 typedef struct output_buffer output_buffer;
00101 typedef bool (*printer_fn) PARAMS ((output_buffer *, text_info *));
00102
00103
00104
00105 struct output_buffer
00106 {
00107
00108 output_state state;
00109
00110
00111 FILE* stream;
00112
00113
00114 struct obstack obstack;
00115
00116
00117 int line_length;
00118
00119
00120
00121 char digit_buffer[128];
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 printer_fn format_decoder;
00132 } ;
00133
00134 #define output_prefix(BUFFER) (BUFFER)->state.prefix
00135
00136
00137
00138 #define output_buffer_attached_stream(BUFFER) (BUFFER)->stream
00139
00140
00141 #define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
00142
00143
00144 #define output_indentation(BUFFER) (BUFFER)->state.indent_skip
00145
00146
00147 #define output_message_text(BUFFER) \
00148 ((const char *) obstack_base (&(BUFFER)->obstack))
00149
00150
00151 #define output_format_decoder(BUFFER) (BUFFER)->format_decoder
00152
00153
00154 #define output_prefixing_rule(BUFFER) (BUFFER)->state.prefixing_rule
00155
00156
00157
00158 #define output_line_cutoff(BUFFER) (BUFFER)->state.ideal_maximum_length
00159
00160
00161 #define output_is_line_wrapping(BUFFER) (output_line_cutoff (BUFFER) > 0)
00162
00163 #define output_formatted_scalar(BUFFER, FORMAT, INTEGER) \
00164 do \
00165 { \
00166 sprintf ((BUFFER)->digit_buffer, FORMAT, INTEGER); \
00167 output_add_string (BUFFER, (BUFFER)->digit_buffer); \
00168 } \
00169 while (0)
00170
00171
00172 typedef struct diagnostic_context diagnostic_context;
00173 typedef void (*diagnostic_starter_fn) PARAMS ((diagnostic_context *,
00174 diagnostic_info *));
00175 typedef diagnostic_starter_fn diagnostic_finalizer_fn;
00176
00177
00178
00179 struct diagnostic_context
00180 {
00181
00182
00183
00184 output_buffer buffer;
00185
00186
00187 int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
00188
00189
00190
00191 bool warnings_are_errors_message;
00192
00193
00194
00195
00196
00197
00198
00199
00200 diagnostic_starter_fn begin_diagnostic;
00201
00202
00203 diagnostic_finalizer_fn end_diagnostic;
00204
00205
00206 void (*internal_error) PARAMS ((const char *, va_list *));
00207
00208
00209
00210
00211 tree last_function;
00212
00213
00214 int last_module;
00215
00216 int lock;
00217
00218
00219 void *x_data;
00220 };
00221
00222
00223 #define diagnostic_starter(DC) (DC)->begin_diagnostic
00224
00225
00226
00227 #define diagnostic_finalizer(DC) (DC)->end_diagnostic
00228
00229
00230 #define diagnostic_auxiliary_data(DC) (DC)->x_data
00231
00232
00233 #define diagnostic_format_decoder(DC) output_format_decoder (&(DC)->buffer)
00234
00235
00236 #define diagnostic_prefixing_rule(DC) output_prefixing_rule (&(DC)->buffer)
00237
00238
00239
00240 #define diagnostic_line_cutoff(DC) output_line_cutoff (&(DC)->buffer)
00241
00242
00243
00244 #define diagnostic_last_function_changed(DC) \
00245 ((DC)->last_function != current_function_decl)
00246
00247
00248
00249 #define diagnostic_set_last_function(DC) \
00250 (DC)->last_function = current_function_decl
00251
00252
00253
00254 #define diagnostic_last_module_changed(DC) \
00255 ((DC)->last_module != input_file_stack_tick)
00256
00257
00258
00259 #define diagnostic_set_last_module(DC) \
00260 (DC)->last_module = input_file_stack_tick
00261
00262
00263
00264
00265 extern diagnostic_context *global_dc;
00266
00267
00268 #define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)]
00269
00270
00271
00272 #define errorcount diagnostic_kind_count (global_dc, DK_ERROR)
00273
00274 #define warningcount diagnostic_kind_count (global_dc, DK_WARNING)
00275
00276 #define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
00277
00278
00279 #define diagnostic_report_warnings_p() \
00280 (!inhibit_warnings \
00281 && !(in_system_header && !warn_system_headers))
00282
00283 #define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D)
00284
00285
00286 extern void diagnostic_initialize PARAMS ((diagnostic_context *));
00287 extern void diagnostic_report_current_module PARAMS ((diagnostic_context *));
00288 extern void diagnostic_report_current_function PARAMS ((diagnostic_context *));
00289 extern void diagnostic_flush_buffer PARAMS ((diagnostic_context *));
00290 extern bool diagnostic_count_diagnostic PARAMS ((diagnostic_context *,
00291 diagnostic_t));
00292 extern void diagnostic_report_diagnostic PARAMS ((diagnostic_context *,
00293 diagnostic_info *));
00294 extern void diagnostic_set_info PARAMS ((diagnostic_info *,
00295 const char *, va_list *,
00296 const char *, int,
00297 diagnostic_t));
00298 extern char *diagnostic_build_prefix PARAMS ((diagnostic_info *));
00299
00300
00301 extern void init_output_buffer PARAMS ((output_buffer *,
00302 const char *, int));
00303 extern void output_clear PARAMS ((output_buffer *));
00304 extern const char *output_last_position PARAMS ((const output_buffer *));
00305 extern void output_set_prefix PARAMS ((output_buffer *,
00306 const char *));
00307 extern void output_destroy_prefix PARAMS ((output_buffer *));
00308 extern void output_set_maximum_length PARAMS ((output_buffer *, int));
00309 extern void output_emit_prefix PARAMS ((output_buffer *));
00310 extern void output_add_newline PARAMS ((output_buffer *));
00311 extern void output_add_space PARAMS ((output_buffer *));
00312 extern int output_space_left PARAMS ((const output_buffer *));
00313 extern void output_append PARAMS ((output_buffer *, const char *,
00314 const char *));
00315 extern void output_add_character PARAMS ((output_buffer *, int));
00316 extern void output_decimal PARAMS ((output_buffer *, int));
00317 extern void output_add_string PARAMS ((output_buffer *,
00318 const char *));
00319 extern void output_add_identifier PARAMS ((output_buffer *, tree));
00320 extern const char *output_finalize_message PARAMS ((output_buffer *));
00321 extern void output_clear_message_text PARAMS ((output_buffer *));
00322 extern void output_printf PARAMS ((output_buffer *, const char *,
00323 ...)) ATTRIBUTE_PRINTF_2;
00324 extern void output_verbatim PARAMS ((output_buffer *, const char *,
00325 ...));
00326 extern void verbatim PARAMS ((const char *, ...));
00327 extern char *file_name_as_prefix PARAMS ((const char *));
00328 extern void inform PARAMS ((const char *, ...));
00329
00330 #endif