Move caret printing to diagnostics_finalizer
diff mbox

Message ID CAESRpQBXF5g--1YOXWczEy=h4nUxuFW0qD2h8pESqTJAGUTszA@mail.gmail.com
State New
Headers show

Commit Message

Manuel López-Ibáñez Aug. 16, 2014, 1 a.m. UTC
Hi Dodji,

This patch is in preparation for further patches moving the Fortran FE
to use the common diagnostics machinery.

Fortran has its own way of printing the caret information, so we need
a way to override the default in the diagnostics machinery. A simple
way is to move the printing of the caret (plus the destruction of the
prefix and printing a newline at the end)  to the
diagnostic_finalizer, so Fortran can override the whole thing with its
own finalizer.

This means that the c-family finalizer needs to invoke the caret
explicitly. The C++ finalizer was destroying the prefix even thought
this was done by the common code anyway. Thus now there is only one
finalizer for both C and C++.

Bootstrapped and regression tested on x86-64-linux.

OK?


gcc/ChangeLog:

2014-08-16  Manuel López-Ibáñez  <manu.gnu.org>

    * diagnostic.c (default_diagnostic_finalizer): Move caret printing
     to here ...
    (diagnostic_report_diagnostic): ... from here.
    * toplev.c (general_init): Move code to c-family.

gcc/cp/ChangeLog:

2014-08-16  Manuel López-Ibáñez  <manu.gnu.org>

    * error.c (cp_diagnostic_finalizer): Delete.
    (init_error): Do not set diagnostic_finalizer here.

gcc/c-family/ChangeLog:

2014-08-16  Manuel López-Ibáñez  <manu.gnu.org>

    * c-opts.c: Include tree-diagnostics.h.
    (c_diagnostic_finalizer): New.
    (c_common_initialize_diagnostics): Use it.

Comments

Dodji Seketeli Aug. 19, 2014, 3:06 p.m. UTC | #1
Manuel López-Ibáñez <lopezibanez@gmail.com> writes:

> This patch is in preparation for further patches moving the Fortran FE
> to use the common diagnostics machinery.
>
> Fortran has its own way of printing the caret information, so we need
> a way to override the default in the diagnostics machinery. A simple
> way is to move the printing of the caret (plus the destruction of the
> prefix and printing a newline at the end)  to the
> diagnostic_finalizer, so Fortran can override the whole thing with its
> own finalizer.
>
> This means that the c-family finalizer needs to invoke the caret
> explicitly. The C++ finalizer was destroying the prefix even thought
> this was done by the common code anyway. Thus now there is only one
> finalizer for both C and C++.
>
>
> gcc/ChangeLog:
>
> 2014-08-16  Manuel López-Ibáñez  <manu.gnu.org>
>
>     * diagnostic.c (default_diagnostic_finalizer): Move caret printing
>      to here ...
>     (diagnostic_report_diagnostic): ... from here.
>     * toplev.c (general_init): Move code to c-family.
>
> gcc/cp/ChangeLog:
>
> 2014-08-16  Manuel López-Ibáñez  <manu.gnu.org>
>
>     * error.c (cp_diagnostic_finalizer): Delete.
>     (init_error): Do not set diagnostic_finalizer here.
>
> gcc/c-family/ChangeLog:
>
> 2014-08-16  Manuel López-Ibáñez  <manu.gnu.org>
>
>     * c-opts.c: Include tree-diagnostics.h.
>     (c_diagnostic_finalizer): New.
>     (c_common_initialize_diagnostics): Use it.

> Bootstrapped and regression tested on x86-64-linux.
>
> OK?

This is OK for me.

Please commit it if nobody objects in the next 48 hours.

Thank you :-)

Cheers.

Patch
diff mbox

Index: gcc/c-family/c-opts.c
===================================================================
--- gcc/c-family/c-opts.c	(revision 214024)
+++ gcc/c-family/c-opts.c	(working copy)
@@ -26,10 +26,11 @@  along with GCC; see the file COPYING3.
 #include "c-pragma.h"
 #include "flags.h"
 #include "toplev.h"
 #include "langhooks.h"
 #include "diagnostic.h"
+#include "tree-diagnostic.h" /* for virt_loc_aware_diagnostic_finalizer */
 #include "intl.h"
 #include "cppdefault.h"
 #include "incpath.h"
 #include "debug.h"		/* For debug_hooks.  */
 #include "opts.h"
@@ -162,10 +163,23 @@  c_common_option_lang_mask (void)
   static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
 
   return lang_flags[c_language];
 }
 
+/* Diagnostic finalizer for C/C++/Objective-C/Objective-C++.  */
+static void
+c_diagnostic_finalizer (diagnostic_context *context,
+			diagnostic_info *diagnostic)
+{
+  diagnostic_show_locus (context, diagnostic);
+  /* By default print macro expansion contexts in the diagnostic
+     finalizer -- for tokens resulting from macro expansion.  */
+  virt_loc_aware_diagnostic_finalizer (context, diagnostic);
+  pp_destroy_prefix (context->printer);
+  pp_newline_and_flush (context->printer);
+}
+
 /* Common diagnostics initialization.  */
 void
 c_common_initialize_diagnostics (diagnostic_context *context)
 {
   /* This is conditionalized only because that is the way the front
@@ -176,12 +190,12 @@  c_common_initialize_diagnostics (diagnos
 	 ("COLUMNS") preferable?  */
       diagnostic_line_cutoff (context) = 80;
       /* By default, emit location information once for every
 	 diagnostic message.  */
       diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
-    }
-
+    }
+  diagnostic_finalizer (context) = c_diagnostic_finalizer;
   context->opt_permissive = OPT_fpermissive;
 }
 
 /* Whether options from all C-family languages should be accepted
    quietly.  */
Index: gcc/diagnostic.c
===================================================================
--- gcc/diagnostic.c	(revision 214024)
+++ gcc/diagnostic.c	(working copy)
@@ -551,13 +551,16 @@  default_diagnostic_starter (diagnostic_c
   pp_set_prefix (context->printer, diagnostic_build_prefix (context,
 							    diagnostic));
 }
 
 void
-default_diagnostic_finalizer (diagnostic_context *context ATTRIBUTE_UNUSED,
-			      diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
+default_diagnostic_finalizer (diagnostic_context *context,
+			      diagnostic_info *diagnostic)
 {
+  diagnostic_show_locus (context, diagnostic);
+  pp_destroy_prefix (context->printer);
+  pp_newline_and_flush (context->printer);
 }
 
 /* Interface to specify diagnostic kind overrides.  Returns the
    previous setting, or DK_UNSPECIFIED if the parameters are out of
    range.  If OPTION_INDEX is zero, the new setting is for all the
@@ -793,14 +796,11 @@  diagnostic_report_diagnostic (diagnostic
   diagnostic->message.x_data = &diagnostic->x_data;
   diagnostic->x_data = NULL;
   pp_format (context->printer, &diagnostic->message);
   (*diagnostic_starter (context)) (context, diagnostic);
   pp_output_formatted_text (context->printer);
-  diagnostic_show_locus (context, diagnostic);
   (*diagnostic_finalizer (context)) (context, diagnostic);
-  pp_destroy_prefix (context->printer);
-  pp_newline_and_flush (context->printer);
   diagnostic_action_after_output (context, diagnostic);
   diagnostic->message.format_spec = saved_format_spec;
   diagnostic->x_data = NULL;
 
   context->lock--;
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c	(revision 214024)
+++ gcc/toplev.c	(working copy)
@@ -1113,15 +1113,10 @@  general_init (const char *argv0)
      can give warnings and errors.  */
   diagnostic_initialize (global_dc, N_OPTS);
   /* Set a default printer.  Language specific initializations will
      override it later.  */
   tree_diagnostics_defaults (global_dc);
-  /* FIXME: This should probably be moved to C-family
-     language-specific initializations.  */
-  /* By default print macro expansion contexts in the diagnostic
-     finalizer -- for tokens resulting from macro expansion.  */
-  diagnostic_finalizer (global_dc) = virt_loc_aware_diagnostic_finalizer;
 
   global_dc->show_caret
     = global_options_init.x_flag_diagnostics_show_caret;
   global_dc->show_option_requested
     = global_options_init.x_flag_diagnostics_show_option;
Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 214024)
+++ gcc/cp/error.c	(working copy)
@@ -97,21 +97,20 @@  static void maybe_print_instantiation_co
 static void print_instantiation_full_context (diagnostic_context *);
 static void print_instantiation_partial_context (diagnostic_context *,
 						 struct tinst_level *,
 						 location_t);
 static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *);
-static void cp_diagnostic_finalizer (diagnostic_context *, diagnostic_info *);
 static void cp_print_error_function (diagnostic_context *, diagnostic_info *);
 
 static bool cp_printer (pretty_printer *, text_info *, const char *,
 			int, bool, bool, bool);
 
 void
 init_error (void)
 {
   diagnostic_starter (global_dc) = cp_diagnostic_starter;
-  diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer;
+  /* diagnostic_finalizer is already c_diagnostic_finalizer.  */
   diagnostic_format_decoder (global_dc) = cp_printer;
 
   new (cxx_pp) cxx_pretty_printer ();
 }
 
@@ -3039,18 +3038,10 @@  cp_diagnostic_starter (diagnostic_contex
   maybe_print_constexpr_context (context);
   pp_set_prefix (context->printer, diagnostic_build_prefix (context,
 								 diagnostic));
 }
 
-static void
-cp_diagnostic_finalizer (diagnostic_context *context,
-			 diagnostic_info *diagnostic)
-{
-  virt_loc_aware_diagnostic_finalizer (context, diagnostic);
-  pp_destroy_prefix (context->printer);
-}
-
 /* Print current function onto BUFFER, in the process of reporting
    a diagnostic message.  Called from cp_diagnostic_starter.  */
 static void
 cp_print_error_function (diagnostic_context *context,
 			 diagnostic_info *diagnostic)