This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Diagnostics library cleanup, #2
- To: gcc-patches at gcc dot gnu dot org
- Subject: Diagnostics library cleanup, #2
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- Date: 26 Jun 2001 21:21:57 +0200
- Organization: CodeSourcery, LLC
This patch removes more global variables used in the diagnostic machinery.
Bootstrapped and tested on i686-pc-linux.
-- Gaby
2001-06-26 Gabriel Dos Reis <gdr@codesourcery.com>
* toplev.c (decode_f_option): Adjust setting.
(toplev_main): Call diagnostic_initialize. Remove call to
reshape_diagnostic_buffer.
* diagnostic.h (struct output_buffer): Add new field format_decoder.
(diagnostic_format_decoder): New macro.
(diagnostic_prefixing_rule): Likewise.
(diagnostic_line_cutoff): Likewise.
(set_message_prefixing_rule): Remove.
* diagnostic.c (lang_printer): Remove.
(diagnostic_message_length_per_line): Likewise.
(current_prefixing_rule): Likewise.
(initialize_diagnostics): Rename to...
(diagnostic_initialize): ...this. Tweak.
(default_initialize_buffer): Remove.
(reshape_diagnostic_buffer): Likewise.
(init_output_buffer): Adjust prefixing rule setting.
(output_format): Use format_decoder from the output_buffer.
* c-lang.c (c_init): Adjust tree formatter setting.
cp/
* error.c (init_error): Adjust settings.
Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-lang.c,v
retrieving revision 1.51
diff -p -r1.51 c-lang.c
*** c-lang.c 2001/06/05 08:03:44 1.51
--- c-lang.c 2001/06/26 19:00:38
*************** c_init ()
*** 88,94 ****
mark_lang_status = &mark_c_function_context;
lang_expand_expr = &c_expand_expr;
lang_safe_from_p = &c_safe_from_p;
! lang_printer = &c_tree_printer;
lang_expand_decl_stmt = &c_expand_decl_stmt;
lang_missing_noreturn_ok_p = &c_missing_noreturn_ok_p;
--- 88,94 ----
mark_lang_status = &mark_c_function_context;
lang_expand_expr = &c_expand_expr;
lang_safe_from_p = &c_safe_from_p;
! diagnostic_format_decoder (global_dc) = &c_tree_printer;
lang_expand_decl_stmt = &c_expand_decl_stmt;
lang_missing_noreturn_ok_p = &c_missing_noreturn_ok_p;
Index: diagnostic.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/diagnostic.c,v
retrieving revision 1.60
diff -p -r1.60 diagnostic.c
*** diagnostic.c 2001/06/26 14:06:04 1.60
--- diagnostic.c 2001/06/26 19:00:38
*************** static void error_recursion PARAMS ((voi
*** 105,113 ****
extern int rtl_dump_and_exit;
extern int warnings_are_errors;
- /* Front-end specific tree formatter, if non-NULL. */
- printer_fn lang_printer = NULL;
-
/* A diagnostic_context surrogate for stderr. */
static diagnostic_context global_diagnostic_context;
diagnostic_context *global_dc = &global_diagnostic_context;
--- 105,110 ----
*************** static int last_error_tick;
*** 129,143 ****
void (*print_error_function) PARAMS ((const char *)) =
default_print_error_function;
- /* Maximum characters per line in automatic line wrapping mode.
- Zero means don't wrap lines. */
-
- int diagnostic_message_length_per_line;
-
- /* Used to control every diagnostic message formatting. Front-ends should
- call set_message_prefixing_rule to set up their policies. */
- static diagnostic_prefixing_rule_t current_prefixing_rule;
-
/* Prevent recursion into the error handler. */
static int diagnostic_lock;
--- 126,131 ----
*************** record_last_error_function ()
*** 179,202 ****
/* Initialize the diagnostic message outputting machinery. */
void
! initialize_diagnostics ()
{
! /* By default, we don't line-wrap messages. */
! diagnostic_message_length_per_line = 0;
! set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
! /* Proceed to actual initialization. */
! default_initialize_buffer (diagnostic_buffer);
! diagnostic_starter (global_dc) = default_diagnostic_starter;
! diagnostic_finalizer (global_dc) = default_diagnostic_finalizer;
! }
! void
! set_message_prefixing_rule (rule)
! diagnostic_prefixing_rule_t rule;
! {
! current_prefixing_rule = rule;
}
/* Returns true if BUFFER is in line-wrappind mode. */
--- 167,186 ----
/* Initialize the diagnostic message outputting machinery. */
void
! diagnostic_initialize (context)
! diagnostic_context *context;
{
! memset (context, 0, sizeof *context);
! obstack_init (&context->buffer.obstack);
! /* By default, diagnostics are sent to stderr. */
! output_buffer_attached_stream (&context->buffer) = stderr;
! /* By default, we emit prefixes once per message. */
! diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
! diagnostic_starter (context) = default_diagnostic_starter;
! diagnostic_finalizer (context) = default_diagnostic_finalizer;
}
/* Returns true if BUFFER is in line-wrappind mode. */
*************** output_set_maximum_length (buffer, lengt
*** 252,258 ****
output_buffer *buffer;
int length;
{
! ideal_line_wrap_cutoff (buffer) = length;
set_real_maximum_length (buffer);
}
--- 236,242 ----
output_buffer *buffer;
int length;
{
! ideal_line_wrap_cutoff (buffer) = length;
set_real_maximum_length (buffer);
}
*************** init_output_buffer (buffer, prefix, maxi
*** 330,363 ****
obstack_init (&buffer->obstack);
output_buffer_attached_stream (buffer) = stderr;
ideal_line_wrap_cutoff (buffer) = maximum_length;
! prefixing_policy (buffer) = current_prefixing_rule;
output_set_prefix (buffer, prefix);
output_text_length (buffer) = 0;
clear_diagnostic_info (buffer);
}
- /* Initialize BUFFER with a NULL prefix and current diagnostic message
- length cutoff. */
-
- void
- default_initialize_buffer (buffer)
- output_buffer *buffer;
- {
- init_output_buffer (buffer, NULL, diagnostic_message_length_per_line);
- }
-
- /* Recompute diagnostic_buffer's attributes to reflect any change
- in diagnostic formatting global options. */
-
- void
- reshape_diagnostic_buffer ()
- {
- ideal_line_wrap_cutoff (diagnostic_buffer) =
- diagnostic_message_length_per_line;
- prefixing_policy (diagnostic_buffer) = current_prefixing_rule;
- set_real_maximum_length (diagnostic_buffer);
- }
-
/* Reinitialize BUFFER. */
void
--- 314,325 ----
obstack_init (&buffer->obstack);
output_buffer_attached_stream (buffer) = stderr;
ideal_line_wrap_cutoff (buffer) = maximum_length;
! prefixing_policy (buffer) = diagnostic_prefixing_rule (global_dc);
output_set_prefix (buffer, prefix);
output_text_length (buffer) = 0;
clear_diagnostic_info (buffer);
}
/* Reinitialize BUFFER. */
void
*************** output_format (buffer)
*** 776,782 ****
break;
default:
! if (! lang_printer || !(*lang_printer) (buffer))
{
/* Hmmm. The front-end failed to install a format translator
but called us with an unrecognized format. Sorry. */
--- 738,744 ----
break;
default:
! if (!buffer->format_decoder || !(*buffer->format_decoder) (buffer))
{
/* Hmmm. The front-end failed to install a format translator
but called us with an unrecognized format. Sorry. */
Index: diagnostic.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/diagnostic.h,v
retrieving revision 1.29
diff -p -r1.29 diagnostic.h
*** diagnostic.h 2001/06/26 14:06:05 1.29
--- diagnostic.h 2001/06/26 19:00:38
*************** struct output_buffer
*** 116,121 ****
--- 116,133 ----
/* This must be large enough to hold any printed integer or
floating-point value. */
char digit_buffer[128];
+
+ /* If non-NULL, this function formats data in the BUFFER. When called,
+ output_buffer_text_cursor (BUFFER) points to a format code.
+ FORMAT_DECODER should call output_add_string (and related functions)
+ to add data to the BUFFER. FORMAT_DECODER can read arguments from
+ output_buffer_format_args (BUFFER) using VA_ARG. If the BUFFER needs
+ additional characters from the format string, it should advance
+ the output_buffer_text_cursor (BUFFER) as it goes. When FORMAT_DECODER
+ returns, output_buffer_text_cursor (BUFFER) should point to the last
+ character processed. */
+
+ printer_fn format_decoder;
};
#define output_buffer_state(BUFFER) (BUFFER)->state
*************** struct diagnostic_context
*** 177,196 ****
#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
! the BUFFER. LANG_PRINTER can read arguments from
! output_buffer_format_args (BUFFER) using VA_ARG. If the BUFFER needs
! additional characters from the format string, it should advance
! the output_buffer_text_cursor (BUFFER) as it goes. When LANG_PRINTER
! returns, output_buffer_text_cursor (BUFFER) should point to the last
! character processed. */
!
! extern printer_fn lang_printer;
! extern int diagnostic_message_length_per_line;
/* This output buffer is used by front-ends that directly output
diagnostic messages without going through `error', `warning',
--- 189,200 ----
#define diagnostic_starter(DC) (DC)->begin_diagnostic
#define diagnostic_finalizer(DC) (DC)->end_diagnostic
#define diagnostic_auxiliary_data(DC) (DC)->x_data
! #define diagnostic_format_decoder(DC) (DC)->buffer.format_decoder
! #define diagnostic_prefixing_rule(DC) (DC)->buffer.state.prefixing_rule
! /* Maximum characters per line in automatic line wrapping mode.
! Zero means don't wrap lines. */
! #define diagnostic_line_cutoff(DC) (DC)->buffer.state.ideal_maximum_length
/* This output buffer is used by front-ends that directly output
diagnostic messages without going through `error', `warning',
*************** extern void set_internal_error_function
*** 225,233 ****
PARAMS ((const char *,
va_list *))));
extern void report_diagnostic PARAMS ((diagnostic_context *));
! extern void initialize_diagnostics PARAMS ((void));
! extern void reshape_diagnostic_buffer PARAMS ((void));
! extern void default_initialize_buffer PARAMS ((output_buffer *));
extern void init_output_buffer PARAMS ((output_buffer *,
const char *, int));
extern void flush_diagnostic_buffer PARAMS ((void));
--- 229,235 ----
PARAMS ((const char *,
va_list *))));
extern void report_diagnostic PARAMS ((diagnostic_context *));
! extern void diagnostic_initialize PARAMS ((diagnostic_context *));
extern void init_output_buffer PARAMS ((output_buffer *,
const char *, int));
extern void flush_diagnostic_buffer PARAMS ((void));
*************** extern const char *output_last_position
*** 237,243 ****
extern void output_set_prefix PARAMS ((output_buffer *,
const char *));
extern void output_destroy_prefix PARAMS ((output_buffer *));
! extern void output_set_maximum_length PARAMS ((output_buffer *, int));
extern void output_emit_prefix PARAMS ((output_buffer *));
extern void output_add_newline PARAMS ((output_buffer *));
extern void output_add_space PARAMS ((output_buffer *));
--- 239,245 ----
extern void output_set_prefix PARAMS ((output_buffer *,
const char *));
extern void output_destroy_prefix PARAMS ((output_buffer *));
! extern void output_set_maximum_length PARAMS ((output_buffer *, int));
extern void output_emit_prefix PARAMS ((output_buffer *));
extern void output_add_newline PARAMS ((output_buffer *));
extern void output_add_space PARAMS ((output_buffer *));
*************** extern void output_clear_message_text PA
*** 253,259 ****
extern void output_printf PARAMS ((output_buffer *, const char *,
...)) ATTRIBUTE_PRINTF_2;
extern int output_is_line_wrapping PARAMS ((output_buffer *));
- extern void set_message_prefixing_rule PARAMS ((diagnostic_prefixing_rule_t));
extern void output_verbatim PARAMS ((output_buffer *, const char *,
...)) ATTRIBUTE_PRINTF_2;
extern void verbatim PARAMS ((const char *, ...))
--- 255,260 ----
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.473
diff -p -r1.473 toplev.c
*** toplev.c 2001/06/26 10:47:31 1.473
--- toplev.c 2001/06/26 19:00:39
*************** decode_f_option (arg)
*** 4184,4199 ****
}
else if ((option_value
= skip_leading_substring (arg, "message-length=")))
! diagnostic_message_length_per_line =
! read_integral_parameter (option_value, arg - 2,
! diagnostic_message_length_per_line);
else if ((option_value
= skip_leading_substring (arg, "diagnostics-show-location=")))
{
if (!strcmp (option_value, "once"))
! set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
else if (!strcmp (option_value, "every-line"))
! set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE);
else
error ("Unrecognized option `%s'", arg - 2);
}
--- 4184,4200 ----
}
else if ((option_value
= skip_leading_substring (arg, "message-length=")))
! output_set_maximum_length
! (&global_dc->buffer, read_integral_parameter
! (option_value, arg - 2, diagnostic_line_cutoff (global_dc)));
else if ((option_value
= skip_leading_substring (arg, "diagnostics-show-location=")))
{
if (!strcmp (option_value, "once"))
! diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
else if (!strcmp (option_value, "every-line"))
! diagnostic_prefixing_rule (global_dc)
! = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
else
error ("Unrecognized option `%s'", arg - 2);
}
*************** toplev_main (argc, argv)
*** 4705,4711 ****
ggc_add_tree_root (¤t_function_func_begin_label, 1);
/* Initialize the diagnostics reporting machinery. */
! initialize_diagnostics ();
/* Register the language-independent parameters. */
add_params (lang_independent_params, LAST_PARAM);
--- 4706,4712 ----
ggc_add_tree_root (¤t_function_func_begin_label, 1);
/* Initialize the diagnostics reporting machinery. */
! diagnostic_initialize (global_dc);
/* Register the language-independent parameters. */
add_params (lang_independent_params, LAST_PARAM);
*************** toplev_main (argc, argv)
*** 4887,4895 ****
if (exit_after_options)
exit (0);
-
- /* Reflect any language-specific diagnostic option setting. */
- reshape_diagnostic_buffer ();
/* Checker uses the frame pointer. */
if (flag_check_memory_usage)
--- 4888,4893 ----
Index: cp/error.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/error.c,v
retrieving revision 1.155
diff -p -r1.155 error.c
*** error.c 2001/06/26 14:06:07 1.155
--- error.c 2001/06/26 19:00:40
*************** init_error ()
*** 194,200 ****
print_error_function = lang_print_error_function;
diagnostic_starter (global_dc) = cp_diagnostic_starter;
diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer;
! lang_printer = cp_tree_printer;
init_output_buffer (scratch_buffer, /* prefix */NULL, /* line-width */0);
}
--- 194,200 ----
print_error_function = lang_print_error_function;
diagnostic_starter (global_dc) = cp_diagnostic_starter;
diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer;
! diagnostic_format_decoder (global_dc) = cp_tree_printer;
init_output_buffer (scratch_buffer, /* prefix */NULL, /* line-width */0);
}
Index: cp/lex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/lex.c,v
retrieving revision 1.245
diff -p -r1.245 lex.c
*** lex.c 2001/05/20 06:26:45 1.245
--- lex.c 2001/06/26 19:00:41
*************** cxx_init_options ()
*** 269,278 ****
flag_bounds_check = -1;
/* By default wrap lines at 80 characters. Is getenv ("COLUMNS")
preferable? */
! diagnostic_message_length_per_line = 80;
/* By default, emit location information once for every
diagnostic message. */
! set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
}
static void
--- 269,278 ----
flag_bounds_check = -1;
/* By default wrap lines at 80 characters. Is getenv ("COLUMNS")
preferable? */
! diagnostic_line_cutoff (global_dc) = 80;
/* By default, emit location information once for every
diagnostic message. */
! diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
}
static void