diff options
author | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-05-05 20:56:36 +0000 |
---|---|---|
committer | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-05-05 20:56:36 +0000 |
commit | fa1e68019c966058f790344121a1922d629e3cae (patch) | |
tree | 4ef23783ca32bd1eb64b29445324abc7d48c5b3d | |
parent | 85d113d89d2e2e02de8c6c190c015a029ca9955c (diff) | |
download | gcc-fa1e68019c966058f790344121a1922d629e3cae.tar.gz |
diagnostic.c: add print_option_information
This patch simplifies diagnostic_report_diagnostic by moving
option-printing to a new subroutine.
Doing so required a slight rewrite. In both the old and new
code, context->option_name returns a malloc-ed string.
The old behavior was to then use ACONCAT to manipulate the
format_spec, appending the option metadata.
ACONCAT calcs the buffer size, then uses alloca, and then copies the
data to the on-stack buffer.
Given the alloca, this needs rewriting when moving the printing to
a subroutine. In the new version, the metadata is simply printed
using pp_* calls (so it's hitting the obstack within the
pretty_printer).
This means we can get rid of the save/restore of format_spec: I don't
believe anything else in the code modifies it.
It also seems inherently simpler; it seems odd to me to be
appending metadata to the formatting string, rather than simply
printing the metadata after the formatted string is printed
(the old code also assumed that no option name contained a '%').
No functional change intended.
gcc/ChangeLog:
* diagnostic.c (diagnostic_report_diagnostic): Eliminate
save/restor of format_spec. Move option-printing code to...
(print_option_information): ...this new function, and
reimplement by simply printing to the pretty_printer,
rather than appending to the format string.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@247661 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/diagnostic.c | 52 |
2 files changed, 36 insertions, 24 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a6fc2211820..079fb47012f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,13 @@ 2017-05-05 David Malcolm <dmalcolm@redhat.com> + * diagnostic.c (diagnostic_report_diagnostic): Eliminate + save/restor of format_spec. Move option-printing code to... + (print_option_information): ...this new function, and + reimplement by simply printing to the pretty_printer, + rather than appending to the format string. + +2017-05-05 David Malcolm <dmalcolm@redhat.com> + * diagnostic.c (diagnostic_report_diagnostic): Split out pragma handling logic into... (update_effective_level_from_pragmas): ...this new function. diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index b61c09e2617..f1b6b1ef16a 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -815,6 +815,32 @@ update_effective_level_from_pragmas (diagnostic_context *context, return diag_class; } +/* Print any metadata about the option used to control DIAGNOSTIC to CONTEXT's + printer, e.g. " [-Werror=uninitialized]". + Subroutine of diagnostic_report_diagnostic. */ + +static void +print_option_information (diagnostic_context *context, + const diagnostic_info *diagnostic, + diagnostic_t orig_diag_kind) +{ + char *option_text; + + option_text = context->option_name (context, diagnostic->option_index, + orig_diag_kind, diagnostic->kind); + + if (option_text) + { + pretty_printer *pp = context->printer; + pp_string (pp, " ["); + pp_string (pp, colorize_start (pp_show_color (pp), + diagnostic_kind_color[diagnostic->kind])); + pp_string (pp, option_text); + pp_string (pp, colorize_stop (pp_show_color (pp))); + pp_character (pp, ']'); + free (option_text); + } +} /* Report a diagnostic message (an error or a warning) as specified by DC. This function is *the* subroutine in terms of which front-ends @@ -829,7 +855,6 @@ diagnostic_report_diagnostic (diagnostic_context *context, { location_t location = diagnostic_location (diagnostic); diagnostic_t orig_diag_kind = diagnostic->kind; - const char *saved_format_spec; /* Give preference to being able to inhibit warnings, before they get reclassified to something else. */ @@ -925,33 +950,13 @@ diagnostic_report_diagnostic (diagnostic_context *context, else ++diagnostic_kind_count (context, diagnostic->kind); - saved_format_spec = diagnostic->message.format_spec; - if (context->show_option_requested) - { - char *option_text; - - option_text = context->option_name (context, diagnostic->option_index, - orig_diag_kind, diagnostic->kind); - - if (option_text) - { - const char *cs - = colorize_start (pp_show_color (context->printer), - diagnostic_kind_color[diagnostic->kind]); - const char *ce = colorize_stop (pp_show_color (context->printer)); - diagnostic->message.format_spec - = ACONCAT ((diagnostic->message.format_spec, - " ", - "[", cs, option_text, ce, "]", - NULL)); - free (option_text); - } - } 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); + if (context->show_option_requested) + print_option_information (context, diagnostic, orig_diag_kind); (*diagnostic_finalizer (context)) (context, diagnostic); if (context->parseable_fixits_p) { @@ -959,7 +964,6 @@ diagnostic_report_diagnostic (diagnostic_context *context, pp_flush (context->printer); } diagnostic_action_after_output (context, diagnostic->kind); - diagnostic->message.format_spec = saved_format_spec; diagnostic->x_data = NULL; if (context->edit_context_ptr) |