From 9596ddd67ef7106cc0d6eac0bcfa8fe24b73f50d Mon Sep 17 00:00:00 2001
From: Gabriel Dos Reis <gdr@codesourcery.com>
Date: Tue, 26 Jun 2001 19:18:37 +0000
Subject: [PATCH] toplev.c (decode_f_option): Adjust setting.

	* 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.

From-SVN: r43588
---
 gcc/ChangeLog    | 24 ++++++++++++++++++
 gcc/c-lang.c     |  2 +-
 gcc/cp/ChangeLog |  4 +++
 gcc/cp/error.c   |  2 +-
 gcc/cp/lex.c     |  4 +--
 gcc/diagnostic.c | 64 ++++++++++--------------------------------------
 gcc/diagnostic.h | 37 ++++++++++++++--------------
 gcc/toplev.c     | 16 ++++++------
 8 files changed, 71 insertions(+), 82 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5983da217a19..44d7294847de 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,27 @@
+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.
+
 2001-06-26  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>
 
 	* config/i386/sol2.h (CPP_SPEC): Pass -P for .S files.
diff --git a/gcc/c-lang.c b/gcc/c-lang.c
index e2c906303f85..8942e859cdf1 100644
--- a/gcc/c-lang.c
+++ b/gcc/c-lang.c
@@ -88,7 +88,7 @@ c_init ()
   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;
+  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;
 
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 44233af6d746..33688d4c8027 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -2,6 +2,10 @@
 
 	* error.c (init_error): Adjust settings.
 
+2001-06-26  Gabriel Dos Reis  <gdr@codesourcery.com>
+
+	* error.c (init_error): Adjust settings.
+
 2001-06-19  Richard Sandiford  <rsandifo@redhat.com>
 
 	* except.c (initialize_handler_parm): Expect __cxa_begin_catch to
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index e028a109fbee..5a8522a9f52b 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -194,7 +194,7 @@ init_error ()
   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;
+  diagnostic_format_decoder (global_dc) = cp_tree_printer;
   
   init_output_buffer (scratch_buffer, /* prefix */NULL, /* line-width */0);
 }
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index c466a73beb27..8cee04eb9550 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -269,10 +269,10 @@ cxx_init_options ()
   flag_bounds_check = -1;
   /* By default wrap lines at 80 characters.  Is getenv ("COLUMNS")
      preferable?  */
-  diagnostic_message_length_per_line = 80;
+  diagnostic_line_cutoff (global_dc) = 80;
   /* By default, emit location information once for every
      diagnostic message.  */
-  set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
+  diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
 }
 
 static void
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index a13c2755a2da..c3ab80c0f493 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -105,9 +105,6 @@ static void error_recursion PARAMS ((void)) ATTRIBUTE_NORETURN;
 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;
@@ -129,15 +126,6 @@ static int last_error_tick;
 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;
 
@@ -179,24 +167,20 @@ record_last_error_function ()
 /* Initialize the diagnostic message outputting machinery.  */
 
 void
-initialize_diagnostics ()
+diagnostic_initialize (context)
+     diagnostic_context *context;
 {
-  /* By default, we don't line-wrap messages.  */
-  diagnostic_message_length_per_line = 0;
-  set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
+  memset (context, 0, sizeof *context);
+  obstack_init (&context->buffer.obstack);
 
-  /* Proceed to actual initialization.  */
-  default_initialize_buffer (diagnostic_buffer);
+  /* By default, diagnostics are sent to stderr.  */
+  output_buffer_attached_stream (&context->buffer) = stderr;
 
-  diagnostic_starter (global_dc) = default_diagnostic_starter;
-  diagnostic_finalizer (global_dc) = default_diagnostic_finalizer;
-}
+  /* By default, we emit prefixes once per message.  */
+  diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
 
-void
-set_message_prefixing_rule (rule)
-     diagnostic_prefixing_rule_t rule;
-{
-  current_prefixing_rule = rule;
+  diagnostic_starter (context) = default_diagnostic_starter;
+  diagnostic_finalizer (context) = default_diagnostic_finalizer;
 }
 
 /* Returns true if BUFFER is in line-wrappind mode.  */
@@ -252,7 +236,7 @@ output_set_maximum_length (buffer, length)
      output_buffer *buffer;
      int length;
 {
- ideal_line_wrap_cutoff (buffer) = length;
+  ideal_line_wrap_cutoff (buffer) = length;
   set_real_maximum_length (buffer);
 }
 
@@ -330,34 +314,12 @@ init_output_buffer (buffer, prefix, maximum_length)
   obstack_init (&buffer->obstack);
   output_buffer_attached_stream (buffer) = stderr;
   ideal_line_wrap_cutoff (buffer) = maximum_length;
-  prefixing_policy (buffer) = current_prefixing_rule;
+  prefixing_policy (buffer) = diagnostic_prefixing_rule (global_dc);
   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
@@ -776,7 +738,7 @@ output_format (buffer)
           break;
 
         default:
-          if (! lang_printer || !(*lang_printer) (buffer))
+          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.  */
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index fea82ba60395..72aa297f6d3e 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -116,6 +116,18 @@ struct output_buffer
   /* 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
@@ -177,20 +189,12 @@ struct diagnostic_context
 #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
 
-/* 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;
+/* 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',
@@ -225,9 +229,7 @@ extern void set_internal_error_function	PARAMS ((void (*)
 						 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 diagnostic_initialize	PARAMS ((diagnostic_context *));
 extern void init_output_buffer		PARAMS ((output_buffer *,
 						 const char *, int));
 extern void flush_diagnostic_buffer	PARAMS ((void));
@@ -237,7 +239,7 @@ extern const char *output_last_position PARAMS ((const output_buffer *));
 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_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 *));
@@ -253,7 +255,6 @@ extern void output_clear_message_text	PARAMS ((output_buffer *));
 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 *, ...))
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 7ca7e91ae11b..670cd9748ab5 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -4184,16 +4184,17 @@ decode_f_option (arg)
     }
   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);
+    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"))
-	set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
+        diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
       else if (!strcmp (option_value, "every-line"))
-	set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE);
+        diagnostic_prefixing_rule (global_dc)
+          = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
       else
 	error ("Unrecognized option `%s'", arg - 2);
     }
@@ -4705,7 +4706,7 @@ toplev_main (argc, argv)
   ggc_add_tree_root (&current_function_func_begin_label, 1);
 
   /* Initialize the diagnostics reporting machinery.  */
-  initialize_diagnostics ();
+  diagnostic_initialize (global_dc);
 
   /* Register the language-independent parameters.  */
   add_params (lang_independent_params, LAST_PARAM);
@@ -4888,9 +4889,6 @@ toplev_main (argc, argv)
   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)
     flag_omit_frame_pointer = 0;
-- 
GitLab