aboutsummaryrefslogtreecommitdiff
path: root/gcc/toplev.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-10-15 22:16:59 +0000
committerDavid Malcolm <dmalcolm@redhat.com>2018-10-15 22:16:59 +0000
commite673c786837066b63b6c351480c573c510fa475a (patch)
tree6bbedd1880c0dd6587b4bacdf81e6dd027e1e194 /gcc/toplev.c
parent3849d09615622b524c2afa0012f0eb03e493cd93 (diff)
diagnostics: add minimum width to left margin for line numbers
This patch adds a minimum width to the left margin used for printing line numbers. I set the default to 6. Hence rather than: some-filename:9:1: some message 9 | some source text | ^~~~~~~~~~~~~~~~ some-filename:10:1: another message 10 | more source text | ^~~~~~~~~~~~~~~~ we now print: some-filename:9:42: some message 9 | some source text | ^~~~~~~~~~~~~~~~ some-filename:10:42: another message 10 | more source text | ^~~~~~~~~~~~~~~~ This implicitly fixes issues with margins failing to line up due to different lengths of the number when we haven't read the full file yet and so don't know the highest possible line number, for line numbers up to 99999. Doing so adds some whitespace on the left-hand side, for non-huge files, at least. I believe that this makes it easier to see where each diagnostic starts, by visually breaking things up at the leftmost column; my hope is to make it easier for the eye to see the different diagnostics as if they were different "paragraphs". gcc/ChangeLog: * common.opt (fdiagnostics-minimum-margin-width=): New option. * diagnostic-show-locus.c (layout::layout): Apply the minimum margin width. (layout::start_annotation_line): Only print up to 3 of the margin character, to avoid touching the left-hand side. (selftest::test_diagnostic_show_locus_fixit_lines): Update for minimum margin width, as set by test_diagnostic_context's ctor. (selftest::test_fixit_insert_containing_newline): Likewise. (selftest::test_fixit_insert_containing_newline_2): Likewise. (selftest::test_line_numbers_multiline_range): Clear dc.min_margin_width. * diagnostic.c (diagnostic_initialize): Initialize min_margin_width. * diagnostic.h (struct diagnostic_context): Add field "min_margin_width". * doc/invoke.texi: Add -fdiagnostics-minimum-margin-width=. * opts.c (common_handle_option): Handle OPT_fdiagnostics_minimum_margin_width_. * selftest-diagnostic.c (selftest::test_diagnostic_context::test_diagnostic_context): Initialize min_margin_width to 6. * toplev.c (general_init): Initialize global_dc->min_margin_width. gcc/testsuite/ChangeLog: * gcc.dg/missing-header-fixit-3.c: Update expected indentation to reflect minimum margin width. * gcc.dg/missing-header-fixit-4.c: Likewise. * gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c: Likewise. * gcc.dg/plugin/diagnostic-test-show-locus-color-line-numbers.c: Likewise. * gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers-2.c: New test. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add it. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@265178 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/toplev.c')
-rw-r--r--gcc/toplev.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 9fb83d4e43f..d7ea11abf53 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1120,6 +1120,8 @@ general_init (const char *argv0, bool init_signals)
= global_options_init.x_flag_diagnostics_show_line_numbers;
global_dc->show_option_requested
= global_options_init.x_flag_diagnostics_show_option;
+ global_dc->min_margin_width
+ = global_options_init.x_diagnostics_minimum_margin_width;
global_dc->show_column
= global_options_init.x_flag_show_column;
global_dc->internal_error = internal_error_function;