aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic-show-locus.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-01-26 17:08:12 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-01-26 17:08:12 +0000
commit01e1dea37c2dd8988c91b510dc9d9e087e641942 (patch)
treeb1f95695dbde83aeccf5ef984f65ac1d0f987b81 /gcc/diagnostic-show-locus.c
parent3dde4d658b231673bd2d61dddd4708ab4ff66b49 (diff)
downloadgcc-01e1dea37c2dd8988c91b510dc9d9e087e641942.zip
gcc-01e1dea37c2dd8988c91b510dc9d9e087e641942.tar.gz
gcc-01e1dea37c2dd8988c91b510dc9d9e087e641942.tar.bz2
PR other/69006: fix extra newlines after diagnostics
gcc/c-family/ChangeLog: PR other/69006 * c-opts.c (c_diagnostic_finalizer): Replace invocation of pp_newline_and_flush with pp_flush. gcc/cp/ChangeLog: PR other/69006 * error.c (print_instantiation_partial_context_line): Add missing newlines from output for the t == NULL case. (print_instantiation_partial_context): Remove call to pp_newline. gcc/ChangeLog: PR other/69006 * diagnostic-show-locus.c (layout::print_source_line): Replace call to pp_newline with call to layout::print_newline. (layout::print_annotation_line): Likewise. (layout::move_to_column): Likewise. (layout::print_any_fixits): After printing any fixits, print a trailing newline, if necessary. (layout::print_newline): New method, resetting any colorization before a newline. (diagnostic_show_locus): Move the pp_newline to before the early bailout. Remove dummy block enclosing the layout instance. * diagnostic.c (default_diagnostic_finalizer): Replace invocation of pp_newline_and_flush with pp_flush. (diagnostic_append_note): Delete use of pp_newline. (diagnostic_append_note_at_rich_loc): Delete. * diagnostic.h (diagnostic_append_note_at_rich_loc): Delete. * pretty-print.h (output_buffer_append_r): Reset buff->line_length when newline characters are added to the buffer. gcc/fortran/ChangeLog: PR other/69006 * error.c (gfc_diagnostic_starter): Delete use of pp_newline. gcc/testsuite/ChangeLog: PR other/69006 * g++.dg/ext/timevar1.C: Add dg-allow-blank-lines-in-output directive. * gcc.dg/plugin/diagnostic-test-show-locus-color.c: Update expected multiline output to reflect the colorization being disabled before newlines. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (custom_diagnostic_finalizer): Replace call to pp_newline_and_flush with call to pp_flush. * gcc.dg/unroll-2.c: Add dg-allow-blank-lines-in-output directive. * gfortran.dg/implicit_class_1.f90: Likewise. * lib/gcc-dg.exp (allow_blank_lines): New global. (dg-allow-blank-lines-in-output): New procedure. (gcc-dg-prune): Complain about blank lines in the output, unless dg-allow-blank-lines-in-output was called. * lib/multiline.exp (_build_multiline_regex): Only support arbitrary followup text for non-blank-lines, not for blank lines. From-SVN: r232837
Diffstat (limited to 'gcc/diagnostic-show-locus.c')
-rw-r--r--gcc/diagnostic-show-locus.c61
1 files changed, 33 insertions, 28 deletions
diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c
index e323254..d9b6750 100644
--- a/gcc/diagnostic-show-locus.c
+++ b/gcc/diagnostic-show-locus.c
@@ -159,6 +159,8 @@ class layout
void print_any_fixits (int row, const rich_location *richloc);
private:
+ void print_newline ();
+
bool
get_state_at_point (/* Inputs. */
int row, int column,
@@ -574,7 +576,7 @@ layout::print_source_line (int row, line_bounds *lbounds_out)
pp_character (m_pp, c);
line++;
}
- pp_newline (m_pp);
+ print_newline ();
lbounds_out->m_first_non_ws = first_non_ws;
lbounds_out->m_last_non_ws = last_non_ws;
@@ -616,7 +618,7 @@ layout::print_annotation_line (int row, const line_bounds lbounds)
pp_character (m_pp, ' ');
}
}
- pp_newline (m_pp);
+ print_newline ();
}
/* If there are any fixit hints on source line ROW within RICHLOC, print them.
@@ -684,6 +686,18 @@ layout::print_any_fixits (int row, const rich_location *richloc)
}
}
}
+
+ /* Add a trailing newline, if necessary. */
+ move_to_column (&column, 0);
+}
+
+/* Disable any colorization and emit a newline. */
+
+void
+layout::print_newline ()
+{
+ m_colorizer.set_normal_text ();
+ pp_newline (m_pp);
}
/* Return true if (ROW/COLUMN) is within a range of the layout.
@@ -778,7 +792,7 @@ layout::move_to_column (int *column, int dest_column)
/* Start a new line if we need to. */
if (*column > dest_column)
{
- pp_newline (m_pp);
+ print_newline ();
*column = 0;
}
@@ -798,6 +812,8 @@ void
diagnostic_show_locus (diagnostic_context * context,
const diagnostic_info *diagnostic)
{
+ pp_newline (context->printer);
+
if (!context->show_caret
|| diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION
|| diagnostic_location (diagnostic, 0) == context->last_location)
@@ -805,34 +821,23 @@ diagnostic_show_locus (diagnostic_context * context,
context->last_location = diagnostic_location (diagnostic, 0);
- pp_newline (context->printer);
-
const char *saved_prefix = pp_get_prefix (context->printer);
pp_set_prefix (context->printer, NULL);
- {
- layout layout (context, diagnostic);
- int last_line = layout.get_last_line ();
- for (int row = layout.get_first_line ();
- row <= last_line;
- row++)
- {
- /* Print the source line, followed by an annotation line
- consisting of any caret/underlines, then any fixits.
- If the source line can't be read, print nothing. */
- line_bounds lbounds;
- if (layout.print_source_line (row, &lbounds))
- {
- layout.print_annotation_line (row, lbounds);
- layout.print_any_fixits (row, diagnostic->richloc);
- }
- }
-
- /* The closing scope here leads to the dtor for layout and thus
- colorizer being called here, which affects the precise
- place where colorization is turned off in the unittest
- for colorized output. */
- }
+ layout layout (context, diagnostic);
+ int last_line = layout.get_last_line ();
+ for (int row = layout.get_first_line (); row <= last_line; row++)
+ {
+ /* Print the source line, followed by an annotation line
+ consisting of any caret/underlines, then any fixits.
+ If the source line can't be read, print nothing. */
+ line_bounds lbounds;
+ if (layout.print_source_line (row, &lbounds))
+ {
+ layout.print_annotation_line (row, lbounds);
+ layout.print_any_fixits (row, diagnostic->richloc);
+ }
+ }
pp_set_prefix (context->printer, saved_prefix);
}