From e2840263c7138632298aae686b2acbcf91fb9e77 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Sun, 20 Aug 2000 09:50:12 +0000 Subject: [PATCH] c-errors.c (pedwarn_c99): Adjust call to report_diagnostic. * c-errors.c (pedwarn_c99): Adjust call to report_diagnostic. * diagnostic.c (default_diagnostic_starter, default_diagnostic_finalizer): New functions. (diagnostic_for_asm, diagnostic_for_decl): Tweak. (pedwarn, pedwarn_with_file_and_line, error, error_with_file_and_line, fatal, warning, warning_with_file_and_line): Adjust call to report_diagnostic. (report_diagnostic): Rework. (set_diagnostic_context): New function. * diagnostic.h (struct diagnostic_context): New data structure. (diagnostic_message, diagnostic_argument_list, diagnostic_file_location, diagnostic_line_location, diagnostic_is_warning, diagnostic_starter, diagnostic_finalizer, diagnostic_finalizer, diagnostic_auxiliary_data): New macros. (set_diagnostic_context): Declare. (report_diagnostic): Change prototype. From-SVN: r35817 --- gcc/ChangeLog | 21 ++++++++ gcc/c-errors.c | 6 ++- gcc/diagnostic.c | 125 ++++++++++++++++++++++++++++++++++------------- gcc/diagnostic.h | 51 ++++++++++++++++++- 4 files changed, 166 insertions(+), 37 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d63bc3550c4..45db7463449 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,24 @@ +2000-08-20 Gabriel Dos Reis + + * c-errors.c (pedwarn_c99): Adjust call to report_diagnostic. + + * diagnostic.c (default_diagnostic_starter, + default_diagnostic_finalizer): New functions. + (diagnostic_for_asm, diagnostic_for_decl): Tweak. + (pedwarn, pedwarn_with_file_and_line, error, + error_with_file_and_line, fatal, warning, + warning_with_file_and_line): Adjust call to report_diagnostic. + (report_diagnostic): Rework. + (set_diagnostic_context): New function. + + * diagnostic.h (struct diagnostic_context): New data structure. + (diagnostic_message, diagnostic_argument_list, + diagnostic_file_location, diagnostic_line_location, + diagnostic_is_warning, diagnostic_starter, diagnostic_finalizer, + diagnostic_finalizer, diagnostic_auxiliary_data): New macros. + (set_diagnostic_context): Declare. + (report_diagnostic): Change prototype. + Sun 20-Aug-2000 09:25:45 BST Neil Booth * fix-header.c (main): Initialize cpplib. diff --git a/gcc/c-errors.c b/gcc/c-errors.c index 7c86be9211b..562915bb278 100644 --- a/gcc/c-errors.c +++ b/gcc/c-errors.c @@ -36,6 +36,7 @@ pedwarn_c99 VPARAMS ((const char *msgid, ...)) const char *msgid; #endif va_list ap; + diagnostic_context dc; VA_START (ap, msgid); @@ -43,7 +44,8 @@ pedwarn_c99 VPARAMS ((const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - report_diagnostic (msgid, &ap, input_filename, lineno, - !flag_isoc99 || !flag_pedantic_errors); + set_diagnostic_context (&dc, msgid, &ap, input_filename, lineno, + !flag_isoc99 || !flag_pedantic_errors); + report_diagnostic (&dc); va_end (ap); } diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index fbaaec6f1db..ce0bb10d188 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -96,6 +96,11 @@ static void maybe_wrap_text PARAMS ((output_buffer *, const char *, static void clear_text_info PARAMS ((output_buffer *)); static void clear_diagnostic_info PARAMS ((output_buffer *)); +static void default_diagnostic_starter PARAMS ((output_buffer *, + diagnostic_context *)); +static void default_diagnostic_finalizer PARAMS ((output_buffer *, + diagnostic_context *)); + static void error_recursion PARAMS ((void)) ATTRIBUTE_NORETURN; static const char *trim_filename PARAMS ((const char *)); @@ -912,11 +917,12 @@ diagnostic_for_asm (insn, msg, args_ptr, warn) va_list *args_ptr; int warn; { - const char *file; - int line; + diagnostic_context dc; - file_and_line_for_asm (insn, &file, &line); - report_diagnostic (msg, args_ptr, file, line, warn); + set_diagnostic_context (&dc, msg, args_ptr, NULL, 0, warn); + file_and_line_for_asm (insn, &diagnostic_file_location (&dc), + &diagnostic_line_location (&dc)); + report_diagnostic (&dc); } /* Report a diagnostic MESSAGE at the declaration DECL. @@ -1032,6 +1038,7 @@ pedwarn VPARAMS ((const char *msgid, ...)) const char *msgid; #endif va_list ap; + diagnostic_context dc; VA_START (ap, msgid); @@ -1039,8 +1046,9 @@ pedwarn VPARAMS ((const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - report_diagnostic (msgid, &ap, input_filename, lineno, - !flag_pedantic_errors); + set_diagnostic_context + (&dc, msgid, &ap, input_filename, lineno, !flag_pedantic_errors); + report_diagnostic (&dc); va_end (ap); } @@ -1084,6 +1092,7 @@ pedwarn_with_file_and_line VPARAMS ((const char *file, int line, const char *msgid; #endif va_list ap; + diagnostic_context dc; VA_START (ap, msgid); @@ -1093,7 +1102,8 @@ pedwarn_with_file_and_line VPARAMS ((const char *file, int line, msgid = va_arg (ap, const char *); #endif - report_diagnostic (msgid, &ap, file, line, !flag_pedantic_errors); + set_diagnostic_context (&dc, msgid, &ap, file, line, !flag_pedantic_errors); + report_diagnostic (&dc); va_end (ap); } @@ -1225,6 +1235,7 @@ error_with_file_and_line VPARAMS ((const char *file, int line, const char *msgid; #endif va_list ap; + diagnostic_context dc; VA_START (ap, msgid); @@ -1234,7 +1245,8 @@ error_with_file_and_line VPARAMS ((const char *file, int line, msgid = va_arg (ap, const char *); #endif - report_diagnostic (msgid, &ap, file, line, /* warn = */ 0); + set_diagnostic_context (&dc, msgid, &ap, file, line, /* warn = */ 0); + report_diagnostic (&dc); va_end (ap); } @@ -1285,6 +1297,7 @@ error VPARAMS ((const char *msgid, ...)) const char *msgid; #endif va_list ap; + diagnostic_context dc; VA_START (ap, msgid); @@ -1292,7 +1305,9 @@ error VPARAMS ((const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - report_diagnostic (msgid, &ap, input_filename, lineno, /* warn = */ 0); + set_diagnostic_context + (&dc, msgid, &ap, input_filename, lineno, /* warn = */ 0); + report_diagnostic (&dc); va_end (ap); } @@ -1317,6 +1332,7 @@ fatal VPARAMS ((const char *msgid, ...)) const char *msgid; #endif va_list ap; + diagnostic_context dc; VA_START (ap, msgid); @@ -1324,10 +1340,12 @@ fatal VPARAMS ((const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - if (fatal_function != 0) - (*fatal_function) (_(msgid), &ap); - - report_diagnostic (msgid, &ap, input_filename, lineno, 0); + if (fatal_function != 0) + (*fatal_function) (_(msgid), &ap); + + set_diagnostic_context + (&dc, msgid, &ap, input_filename, lineno, /* warn = */0); + report_diagnostic (&dc); va_end (ap); exit (FATAL_EXIT_CODE); } @@ -1369,6 +1387,7 @@ warning_with_file_and_line VPARAMS ((const char *file, int line, const char *msgid; #endif va_list ap; + diagnostic_context dc; VA_START (ap, msgid); @@ -1378,7 +1397,8 @@ warning_with_file_and_line VPARAMS ((const char *file, int line, msgid = va_arg (ap, const char *); #endif - report_diagnostic (msgid, &ap, file, line, /* warn = */ 1); + set_diagnostic_context (&dc, msgid, &ap, file, line, /* warn = */ 1); + report_diagnostic (&dc); va_end (ap); } @@ -1429,6 +1449,7 @@ warning VPARAMS ((const char *msgid, ...)) const char *msgid; #endif va_list ap; + diagnostic_context dc; VA_START (ap, msgid); @@ -1436,7 +1457,9 @@ warning VPARAMS ((const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - report_diagnostic (msgid, &ap, input_filename, lineno, /* warn = */ 1); + set_diagnostic_context + (&dc, msgid, &ap, input_filename, lineno, /* warn = */ 1); + report_diagnostic (&dc); va_end (ap); } @@ -1507,36 +1530,29 @@ verbatim VPARAMS ((const char *msg, ...)) va_end (ap); } -/* Report a diagnostic MESSAGE (an error or a WARNING) involving - entities in ARGUMENTS. FILE and LINE indicate where the diagnostic - occurs. This function is *the* subroutine in terms of which front-ends - should implement their specific diagnostic handling modules. - The front-end independent format specifiers are exactly those described +/* Report a diagnostic message (an error or a warning) as specified by + DC. This function is *the* subroutine in terms of which front-ends + should implement their specific diagnostic handling modules. The + front-end independent format specifiers are exactly those described in the documentation of output_format. */ void -report_diagnostic (msg, args_ptr, file, line, warn) - const char *msg; - va_list *args_ptr; - const char *file; - int line; - int warn; +report_diagnostic (dc) + diagnostic_context *dc; { output_state os; if (diagnostic_lock++) error_recursion (); - if (count_error (warn)) + if (count_error (diagnostic_is_warning (dc))) { os = diagnostic_buffer->state; - diagnostic_msg = msg; - diagnostic_args = args_ptr; - report_error_function (file); - output_set_prefix - (diagnostic_buffer, context_as_prefix (file, line, warn)); + diagnostic_msg = diagnostic_message (dc); + diagnostic_args = diagnostic_argument_list (dc); + (*diagnostic_starter (dc)) (diagnostic_buffer, dc); output_format (diagnostic_buffer); + (*diagnostic_finalizer (dc)) (diagnostic_buffer, dc); finish_diagnostic (); - output_destroy_prefix (diagnostic_buffer); diagnostic_buffer->state = os; } @@ -1597,3 +1613,46 @@ Please submit a full bug report.\n\ See %s for instructions.", function, trim_filename (file), line, GCCBUGURL); } + +/* Setup DC for reporting a diagnostic MESSAGE (an error of a WARNING), + using arguments pointed to by ARGS_PTR, issued at a location specified + by FILE and LINE. Front-ends may override the defaut diagnostic pager + and finalizer *after* this subroutine completes. */ +void +set_diagnostic_context (dc, message, args_ptr, file, line, warn) + diagnostic_context *dc; + const char *message; + va_list *args_ptr; + const char *file; + int line; + int warn; +{ + bzero (dc, sizeof (diagnostic_context)); + diagnostic_message (dc) = message; + diagnostic_argument_list (dc) = args_ptr; + diagnostic_file_location (dc) = file; + diagnostic_line_location (dc) = line; + diagnostic_is_warning (dc) = warn; + diagnostic_starter (dc) = default_diagnostic_starter; + diagnostic_finalizer (dc) = default_diagnostic_finalizer; +} + +static void +default_diagnostic_starter (buffer, dc) + output_buffer *buffer; + diagnostic_context *dc; +{ + report_error_function (diagnostic_file_location (dc)); + output_set_prefix (buffer, + context_as_prefix (diagnostic_file_location (dc), + diagnostic_line_location (dc), + diagnostic_is_warning (dc))); +} + +static void +default_diagnostic_finalizer (buffer, dc) + output_buffer *buffer; + diagnostic_context *dc __attribute__((__unused__)); +{ + output_destroy_prefix (buffer); +} diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 4108227f50b..07beb4b4458 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -26,6 +26,7 @@ Boston, MA 02111-1307, USA. */ /* Forward declarations. */ typedef struct output_buffer output_buffer; +typedef struct diagnostic_context diagnostic_context; #define DIAGNOSTICS_SHOW_PREFIX_ONCE 0x0 #define DIAGNOSTICS_SHOW_PREFIX_NEVER 0x1 @@ -79,6 +80,51 @@ struct output_buffer #define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor #define output_buffer_format_args(BUFFER) *((BUFFER)->state.format_args) +/* This data structure bundles altogether any information relevent to + the context of a diagnostic message. */ +struct diagnostic_context +{ + /* The diagnostic message to output. */ + const char *message; + + /* A pointer to a variable list of the arguments necessary for the + purpose of message formatting. */ + va_list *args_ptr; + + /* The name of the source file involved in the diiagnostic. */ + const char *file; + + /* The line-location in the source file. */ + int line; + + /* Is it message a warning? */ + int warn; + + /* This function is called before any message is printed out. It is + respondible for preparing message prefix and such. For example, it + might say: + In file included from "/usr/local/include/curses.h:5: + from "/home/gdr/src/nifty_printer.h:56: + ... + */ + void (*begin_diagnostic) PARAMS ((output_buffer *, diagnostic_context *)); + + /* This function is called after the diagnostic message is printed. */ + void (*end_diagnostic) PARAMS ((output_buffer *, diagnostic_context *)); + + /* Hook for front-end extensions. */ + void *x_data; +}; + +#define diagnostic_message(DC) (DC)->message +#define diagnostic_argument_list(DC) (DC)->args_ptr +#define diagnostic_file_location(DC) (DC)->file +#define diagnostic_line_location(DC) (DC)->line +#define diagnostic_is_warning(DC) (DC)->warn +#define diagnostic_starter(DC) (DC)->begin_diagnostic +#define diagnostic_finalizer(DC) (DC)->end_diagnostic +#define diagnostic_auxiliary_data(DC) (DC)->x_data + /* If non-NULL, this function formats data in the BUFFER. When called, output_buffer_text_cursor (BUFFER) points to a format code. LANG_PRINTER should call output_add_string (and related functions) to add data to @@ -101,10 +147,11 @@ extern int diagnostic_message_length_per_line; extern output_buffer *diagnostic_buffer; /* Prototypes */ +void set_diagnostic_context PARAMS ((diagnostic_context *, const char *, + va_list *, const char *, int, int)); void set_fatal_function PARAMS ((void (*) PARAMS ((const char *, va_list *)))); -void report_diagnostic PARAMS ((const char *, va_list *, - const char *, int, int)); +void report_diagnostic PARAMS ((diagnostic_context *)); void initialize_diagnostics PARAMS ((void)); void reshape_diagnostic_buffer PARAMS ((void)); void default_initialize_buffer PARAMS ((output_buffer *)); -- 2.30.2