@@ -1261,6 +1261,10 @@ fdiagnostics-show-line-numbers
Common Var(flag_diagnostics_show_line_numbers) Init(1)
Show line numbers in the left margin when showing source.
+fdiagnostics-nn-line-numbers
+Common Var(flag_diagnostics_nn_line_numbers) Init(0)
+Replace line numbers with 'NN' when showing source.
+
fdiagnostics-color
Common Alias(fdiagnostics-color=,always,never)
;
@@ -385,6 +385,7 @@ class layout
bool m_colorize_source_p;
bool m_show_labels_p;
bool m_show_line_numbers_p;
+ bool m_use_nn_for_line_numbers_p;
auto_vec <layout_range> m_layout_ranges;
auto_vec <const fixit_hint *> m_fixit_hints;
auto_vec <line_span> m_line_spans;
@@ -958,6 +959,7 @@ layout::layout (diagnostic_context * context,
m_colorize_source_p (context->colorize_source_p),
m_show_labels_p (context->show_labels_p),
m_show_line_numbers_p (context->show_line_numbers_p),
+ m_use_nn_for_line_numbers_p (context->use_nn_for_line_numbers_p),
m_layout_ranges (richloc->get_num_locations ()),
m_fixit_hints (richloc->get_num_fixit_hints ()),
m_line_spans (1 + richloc->get_num_locations ()),
@@ -1343,7 +1345,7 @@ layout::calculate_linenum_width ()
int highest_line = last_span->m_last_line;
if (highest_line < 0)
highest_line = 0;
- m_linenum_width = num_digits (highest_line);
+ m_linenum_width = num_digits (highest_line, m_use_nn_for_line_numbers_p);
/* If we're showing jumps in the line-numbering, allow at least 3 chars. */
if (m_line_spans.length () > 1)
m_linenum_width = MAX (m_linenum_width, 3);
@@ -1449,10 +1451,13 @@ layout::print_source_line (linenum_type row, const char *line, int line_bytes,
pp_emit_prefix (m_pp);
if (m_show_line_numbers_p)
{
- int width = num_digits (row);
+ int width = num_digits (row, m_use_nn_for_line_numbers_p);
for (int i = 0; i < m_linenum_width - width; i++)
pp_space (m_pp);
- pp_printf (m_pp, "%i | ", row);
+ if (m_use_nn_for_line_numbers_p)
+ pp_printf (m_pp, "%s | ", "NN");
+ else
+ pp_printf (m_pp, "%i | ", row);
}
else
pp_space (m_pp);
@@ -4968,18 +4973,34 @@ test_line_numbers_multiline_range ()
= linemap_position_for_line_and_column (line_table, ord_map, 11, 4);
location_t loc = make_location (caret, start, finish);
- test_diagnostic_context dc;
- dc.show_line_numbers_p = true;
- dc.min_margin_width = 0;
- gcc_rich_location richloc (loc);
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
- ASSERT_STREQ (" 9 | this is line 9\n"
- " | ~~~~~~\n"
- "10 | this is line 10\n"
- " | ~~~~~^~~~~~~~~~\n"
- "11 | this is line 11\n"
- " | ~~~~ \n",
- pp_formatted_text (dc.printer));
+ {
+ test_diagnostic_context dc;
+ dc.show_line_numbers_p = true;
+ dc.min_margin_width = 0;
+ gcc_rich_location richloc (loc);
+ diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ ASSERT_STREQ (" 9 | this is line 9\n"
+ " | ~~~~~~\n"
+ "10 | this is line 10\n"
+ " | ~~~~~^~~~~~~~~~\n"
+ "11 | this is line 11\n"
+ " | ~~~~ \n",
+ pp_formatted_text (dc.printer));
+ }
+
+ /* Verify that obscuring line numbers via "NN" works (and always uses
+ at least two columns). */
+ {
+ test_diagnostic_context dc;
+ dc.show_line_numbers_p = true;
+ dc.use_nn_for_line_numbers_p = true;
+ dc.min_margin_width = 0;
+ gcc_rich_location richloc (start);
+ diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ ASSERT_STREQ ("NN | this is line 9\n"
+ " | ^\n",
+ pp_formatted_text (dc.printer));
+ }
}
/* Run all of the selftests within this file. */
@@ -209,6 +209,7 @@ diagnostic_initialize (diagnostic_context *context, int n_opts)
context->colorize_source_p = false;
context->show_labels_p = false;
context->show_line_numbers_p = false;
+ context->use_nn_for_line_numbers_p = false;
context->min_margin_width = 0;
context->show_ruler_p = false;
context->parseable_fixits_p = false;
@@ -1078,15 +1079,21 @@ diagnostic_report_diagnostic (diagnostic_context *context,
return true;
}
-/* Get the number of digits in the decimal representation of VALUE. */
+/* Get the number of digits in the decimal representation of VALUE.
+
+ If USE_NN_P is true, return 2 (for the case where all numbers are to
+ be printed as just "NN"). */
int
-num_digits (int value)
+num_digits (int value, bool use_nn_p)
{
/* Perhaps simpler to use log10 for this, but doing it this way avoids
using floating point. */
gcc_assert (value >= 0);
+ if (use_nn_p)
+ return 2;
+
if (value == 0)
return 1;
@@ -1885,6 +1892,8 @@ test_num_digits ()
ASSERT_EQ (7, num_digits (9999999));
ASSERT_EQ (8, num_digits (10000000));
ASSERT_EQ (8, num_digits (99999999));
+
+ ASSERT_EQ (2, num_digits (1000, true));
}
/* Run all of the selftests within this file. */
@@ -233,6 +233,10 @@ struct diagnostic_context
showing line numbers? */
bool show_line_numbers_p;
+ /* When printing line numbers, should the actual numbers be replaced with
+ "NN"? (for ease of DejaGnu testing) */
+ bool use_nn_for_line_numbers_p;
+
/* If printing source code, what should the minimum width of the margin
be? Line numbers will be right-aligned, and padded to this width. */
int min_margin_width;
@@ -432,6 +436,6 @@ extern void diagnostic_output_format_init (diagnostic_context *,
enum diagnostics_output_format);
/* Compute the number of digits in the decimal representation of an integer. */
-extern int num_digits (int);
+extern int num_digits (int, bool use_nn_p = false);
#endif /* ! GCC_DIAGNOSTIC_H */
@@ -278,6 +278,7 @@ Objective-C and Objective-C++ Dialects}.
-fdiagnostics-format=@r{[}text@r{|}json@r{]} @gol
-fno-diagnostics-show-option -fno-diagnostics-show-caret @gol
-fno-diagnostics-show-labels -fno-diagnostics-show-line-numbers @gol
+-fdiagnostics-nn-line-numbers @gol
-fdiagnostics-minimum-margin-width=@var{width} @gol
-fdiagnostics-parseable-fixits -fdiagnostics-generate-patch @gol
-fdiagnostics-show-template-tree -fno-elide-type @gol
@@ -4028,6 +4029,12 @@ By default, when printing source code (via @option{-fdiagnostics-show-caret}),
a left margin is printed, showing line numbers. This option suppresses this
left margin.
+@item -fdiagnostics-nn-line-numbers
+@opindex fdiagnostics-nn-line-numbers
+When printing source code in diagnostics, replace line numbers ``NN''.
+This option is intended for GCC developers, to make it easier to write
+certain kinds of automated test.
+
@item -fdiagnostics-minimum-margin-width=@var{width}
@opindex fdiagnostics-minimum-margin-width
This option controls the minimum width of the left margin printed by
@@ -24500,6 +24500,7 @@ gen_producer_string (void)
case OPT_fdiagnostics_show_caret:
case OPT_fdiagnostics_show_labels:
case OPT_fdiagnostics_show_line_numbers:
+ case OPT_fdiagnostics_nn_line_numbers:
case OPT_fdiagnostics_color_:
case OPT_fdiagnostics_format_:
case OPT_fverbose_asm:
@@ -260,6 +260,7 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
case OPT_fdiagnostics_show_caret:
case OPT_fdiagnostics_show_labels:
case OPT_fdiagnostics_show_line_numbers:
+ case OPT_fdiagnostics_nn_line_numbers:
case OPT_fdiagnostics_show_option:
case OPT_fdiagnostics_show_location_:
case OPT_fshow_column:
@@ -605,6 +606,7 @@ append_compiler_options (obstack *argv_obstack, struct cl_decoded_option *opts,
case OPT_fdiagnostics_show_caret:
case OPT_fdiagnostics_show_labels:
case OPT_fdiagnostics_show_line_numbers:
+ case OPT_fdiagnostics_nn_line_numbers:
case OPT_fdiagnostics_show_option:
case OPT_fdiagnostics_show_location_:
case OPT_fshow_column:
@@ -653,6 +655,7 @@ append_diag_options (obstack *argv_obstack, struct cl_decoded_option *opts,
case OPT_fdiagnostics_format_:
case OPT_fdiagnostics_show_caret:
case OPT_fdiagnostics_show_labels:
+ case OPT_fdiagnostics_nn_line_numbers:
case OPT_fdiagnostics_show_line_numbers:
case OPT_fdiagnostics_show_option:
case OPT_fdiagnostics_show_location_:
@@ -2390,6 +2390,10 @@ common_handle_option (struct gcc_options *opts,
dc->show_line_numbers_p = value;
break;
+ case OPT_fdiagnostics_nn_line_numbers:
+ dc->use_nn_for_line_numbers_p = value;
+ break;
+
case OPT_fdiagnostics_color_:
diagnostic_color_init (dc, value);
break;
@@ -1179,6 +1179,8 @@ general_init (const char *argv0, bool init_signals)
= global_options_init.x_flag_diagnostics_show_labels;
global_dc->show_line_numbers_p
= global_options_init.x_flag_diagnostics_show_line_numbers;
+ global_dc->use_nn_for_line_numbers_p
+ = global_options_init.x_flag_diagnostics_nn_line_numbers;
global_dc->show_option_requested
= global_options_init.x_flag_diagnostics_show_option;
global_dc->min_margin_width