aboutsummaryrefslogtreecommitdiff
path: root/gcc/opts.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-10-15 22:16:59 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-10-15 22:16:59 +0000
commit0141ab44c5591752b2cd235fb9644ed289a7e671 (patch)
tree6bbedd1880c0dd6587b4bacdf81e6dd027e1e194 /gcc/opts.c
parent95baaced40ed2bdced215d1aabdbd31b7e0718ef (diff)
downloadgcc-0141ab44c5591752b2cd235fb9644ed289a7e671.zip
gcc-0141ab44c5591752b2cd235fb9644ed289a7e671.tar.gz
gcc-0141ab44c5591752b2cd235fb9644ed289a7e671.tar.bz2
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. From-SVN: r265178
Diffstat (limited to 'gcc/opts.c')
-rw-r--r--gcc/opts.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/gcc/opts.c b/gcc/opts.c
index dc12c2e..3b61e17 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -2228,6 +2228,10 @@ common_handle_option (struct gcc_options *opts,
dc->show_option_requested = value;
break;
+ case OPT_fdiagnostics_minimum_margin_width_:
+ dc->min_margin_width = value;
+ break;
+
case OPT_fdump_:
/* Deferred. */
break;