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 *));
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.
const char *msgid;
#endif
va_list ap;
+ diagnostic_context dc;
VA_START (ap, 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);
}
const char *msgid;
#endif
va_list ap;
+ diagnostic_context dc;
VA_START (ap, msgid);
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);
}
const char *msgid;
#endif
va_list ap;
+ diagnostic_context dc;
VA_START (ap, msgid);
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);
}
const char *msgid;
#endif
va_list ap;
+ diagnostic_context dc;
VA_START (ap, 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);
}
const char *msgid;
#endif
va_list ap;
+ diagnostic_context dc;
VA_START (ap, 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);
}
const char *msgid;
#endif
va_list ap;
+ diagnostic_context dc;
VA_START (ap, msgid);
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);
}
const char *msgid;
#endif
va_list ap;
+ diagnostic_context dc;
VA_START (ap, 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);
}
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;
}
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);
+}
/* 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
#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
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 *));