===================================================================
@@ -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. */
===================================================================
@@ -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--;
===================================================================
@@ -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;
===================================================================
@@ -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)