No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r15-4231-g00ede02bc8bb73.
gcc/ChangeLog: * diagnostic-format-text.cc (diagnostic_text_output_format::after_diagnostic): Replace call to show_any_path with body, taken from diagnostic.cc. (diagnostic_text_output_format::build_prefix): Move here from diagnostic.cc, updating to use get_diagnostic_kind_text and diagnostic_get_color_for_kind. (diagnostic_text_output_format::file_name_as_prefix): Move here from diagnostic.cc (diagnostic_text_output_format::append_note): Likewise. * diagnostic-format-text.h (diagnostic_text_output_format::show_any_path): Drop decl. * diagnostic.cc (diagnostic_text_output_format::file_name_as_prefix): Move to diagnostic-format-text.cc. (diagnostic_text_output_format::build_prefix): Likewise. (diagnostic_text_output_format::show_any_path): Move to body of diagnostic_text_output_format::after_diagnostic. (diagnostic_text_output_format::append_note): Move to diagnostic-format-text.cc. Signed-off-by: David Malcolm <dmalc...@redhat.com> --- gcc/diagnostic-format-text.cc | 72 +++++++++++++++++++++++++++++- gcc/diagnostic-format-text.h | 2 - gcc/diagnostic.cc | 84 ----------------------------------- 3 files changed, 71 insertions(+), 87 deletions(-) diff --git a/gcc/diagnostic-format-text.cc b/gcc/diagnostic-format-text.cc index a6592fe93e6c..0d58d5fb082d 100644 --- a/gcc/diagnostic-format-text.cc +++ b/gcc/diagnostic-format-text.cc @@ -117,7 +117,77 @@ void diagnostic_text_output_format:: after_diagnostic (const diagnostic_info &diagnostic) { - show_any_path (diagnostic); + if (const diagnostic_path *path = diagnostic.richloc->get_path ()) + print_path (*path); +} + +/* Return a malloc'd string describing a location and the severity of the + diagnostic, e.g. "foo.c:42:10: error: ". The caller is responsible for + freeing the memory. */ +char * +diagnostic_text_output_format:: +build_prefix (const diagnostic_info &diagnostic) const +{ + gcc_assert (diagnostic.kind < DK_LAST_DIAGNOSTIC_KIND); + + const char *text = _(get_diagnostic_kind_text (diagnostic.kind)); + const char *text_cs = "", *text_ce = ""; + pretty_printer *pp = get_printer (); + + if (const char *color_name = diagnostic_get_color_for_kind (diagnostic.kind)) + { + text_cs = colorize_start (pp_show_color (pp), color_name); + text_ce = colorize_stop (pp_show_color (pp)); + } + + const expanded_location s = diagnostic_expand_location (&diagnostic); + label_text location_text = get_location_text (s); + + char *result = build_message_string ("%s %s%s%s", location_text.get (), + text_cs, text, text_ce); + return result; +} + +/* Same as build_prefix, but only the source FILE is given. */ +char * +diagnostic_text_output_format::file_name_as_prefix (const char *f) const +{ + pretty_printer *const pp = get_printer (); + const char *locus_cs + = colorize_start (pp_show_color (pp), "locus"); + const char *locus_ce = colorize_stop (pp_show_color (pp)); + return build_message_string ("%s%s:%s ", locus_cs, f, locus_ce); +} + +/* Add a purely textual note with text GMSGID and with LOCATION. */ + +void +diagnostic_text_output_format::append_note (location_t location, + const char * gmsgid, ...) +{ + diagnostic_context *context = &get_context (); + + diagnostic_info diagnostic; + va_list ap; + rich_location richloc (line_table, location); + + va_start (ap, gmsgid); + diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_NOTE); + if (context->m_inhibit_notes_p) + { + va_end (ap); + return; + } + pretty_printer *pp = get_printer (); + char *saved_prefix = pp_take_prefix (pp); + pp_set_prefix (pp, build_prefix (diagnostic)); + pp_format (pp, &diagnostic.message); + pp_output_formatted_text (pp); + pp_destroy_prefix (pp); + pp_set_prefix (pp, saved_prefix); + pp_newline (pp); + diagnostic_show_locus (context, &richloc, DK_NOTE, pp); + va_end (ap); } /* If DIAGNOSTIC has a CWE identifier, print it. diff --git a/gcc/diagnostic-format-text.h b/gcc/diagnostic-format-text.h index aacd699cd90a..2e57e27c739d 100644 --- a/gcc/diagnostic-format-text.h +++ b/gcc/diagnostic-format-text.h @@ -78,8 +78,6 @@ private: label_text get_location_text (const expanded_location &s) const; bool includes_seen_p (const line_map_ordinary *map); - void show_any_path (const diagnostic_info &diagnostic); - diagnostic_column_policy m_column_policy; /* Used to detect when the input file stack has changed since last diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 7f741a04f62e..9647e1382dd1 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -87,18 +87,6 @@ build_message_string (const char *msg, ...) return str; } -/* Same as build_prefix, but only the source FILE is given. */ -char * -diagnostic_text_output_format::file_name_as_prefix (const char *f) const -{ - pretty_printer *const pp = get_printer (); - const char *locus_cs - = colorize_start (pp_show_color (pp), "locus"); - const char *locus_ce = colorize_stop (pp_show_color (pp)); - return build_message_string ("%s%s:%s ", locus_cs, f, locus_ce); -} - - /* Return the value of the getenv("COLUMNS") as an integer. If the value is not set to a positive integer, use ioctl to get the @@ -648,34 +636,6 @@ get_diagnostic_kind_text (diagnostic_t kind) return diagnostic_kind_text[kind]; } -/* Return a malloc'd string describing a location and the severity of the - diagnostic, e.g. "foo.c:42:10: error: ". The caller is responsible for - freeing the memory. */ -char * -diagnostic_text_output_format:: -build_prefix (const diagnostic_info &diagnostic) const -{ - gcc_assert (diagnostic.kind < DK_LAST_DIAGNOSTIC_KIND); - - const char *text = _(diagnostic_kind_text[diagnostic.kind]); - const char *text_cs = "", *text_ce = ""; - pretty_printer *pp = get_printer (); - - if (diagnostic_kind_color[diagnostic.kind]) - { - text_cs = colorize_start (pp_show_color (pp), - diagnostic_kind_color[diagnostic.kind]); - text_ce = colorize_stop (pp_show_color (pp)); - } - - const expanded_location s = diagnostic_expand_location (&diagnostic); - label_text location_text = get_location_text (s); - - char *result = build_message_string ("%s %s%s%s", location_text.get (), - text_cs, text, text_ce); - return result; -} - /* Functions at which to stop the backtrace print. It's not particularly helpful to print the callers of these functions. */ @@ -871,19 +831,6 @@ diagnostic_context::action_after_output (diagnostic_t diag_kind) } } -/* If DIAGNOSTIC has a diagnostic_path and this context supports - printing paths, print the path. */ - -void -diagnostic_text_output_format::show_any_path (const diagnostic_info &diagnostic) -{ - const diagnostic_path *path = diagnostic.richloc->get_path (); - if (!path) - return; - - print_path (*path); -} - /* class logical_location. */ /* Return true iff this is a function or method. */ @@ -1451,37 +1398,6 @@ trim_filename (const char *name) return p; } -/* Add a purely textual note with text GMSGID and with LOCATION. */ - -void -diagnostic_text_output_format::append_note (location_t location, - const char * gmsgid, ...) -{ - diagnostic_context *context = &get_context (); - - diagnostic_info diagnostic; - va_list ap; - rich_location richloc (line_table, location); - - va_start (ap, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_NOTE); - if (context->m_inhibit_notes_p) - { - va_end (ap); - return; - } - pretty_printer *pp = get_printer (); - char *saved_prefix = pp_take_prefix (pp); - pp_set_prefix (pp, build_prefix (diagnostic)); - pp_format (pp, &diagnostic.message); - pp_output_formatted_text (pp); - pp_destroy_prefix (pp); - pp_set_prefix (pp, saved_prefix); - pp_newline (pp); - diagnostic_show_locus (context, &richloc, DK_NOTE, pp); - va_end (ap); -} - /* Implement emit_diagnostic, inform, warning, warning_at, pedwarn, permerror, error, error_at, error_at, sorry, fatal_error, internal_error, and internal_error_no_backtrace, as documented and defined below. */ -- 2.26.3