diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/diagnostic-show-locus.c | 51 | ||||
-rw-r--r-- | gcc/diagnostic.c | 46 | ||||
-rw-r--r-- | gcc/diagnostic.h | 3 | ||||
-rw-r--r-- | gcc/input.c | 41 |
5 files changed, 102 insertions, 52 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 766fd4b..8ca260e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2018-11-27 Mike Gulick <mgulick@mathworks.com> + + PR preprocessor/83173 + * input.c (dump_location_info): Dump reason and included_from + fields from line_map_ordinary struct. Fix indentation when + location > 5 digits. + * diagnostic-show-locus.c (num_digits, num_digits): Move to + diagnostic.c to allow it to be utilized by input.c. + * diagnostic.c (num_digits, selftest::test_num_digits): Moved + here. + (selftest::diagnostic_c_tests): Run selftest::test_num_digits. + * diagnostic.h (num_digits): Add extern definition. + 2018-11-27 Fredrik Noring <noring@nocrew.org> * config/mips/mips.c (mips_reorg_process_insns) diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c index 278e172..65fb102 100644 --- a/gcc/diagnostic-show-locus.c +++ b/gcc/diagnostic-show-locus.c @@ -819,56 +819,6 @@ fixit_cmp (const void *p_a, const void *p_b) return hint_a->get_start_loc () - hint_b->get_start_loc (); } -/* Get the number of digits in the decimal representation - of VALUE. */ - -static int -num_digits (int value) -{ - /* Perhaps simpler to use log10 for this, but doing it this way avoids - using floating point. */ - gcc_assert (value >= 0); - - if (value == 0) - return 1; - - int digits = 0; - while (value > 0) - { - digits++; - value /= 10; - } - return digits; -} - - -#if CHECKING_P - -/* Selftest for num_digits. */ - -static void -test_num_digits () -{ - ASSERT_EQ (1, num_digits (0)); - ASSERT_EQ (1, num_digits (9)); - ASSERT_EQ (2, num_digits (10)); - ASSERT_EQ (2, num_digits (99)); - ASSERT_EQ (3, num_digits (100)); - ASSERT_EQ (3, num_digits (999)); - ASSERT_EQ (4, num_digits (1000)); - ASSERT_EQ (4, num_digits (9999)); - ASSERT_EQ (5, num_digits (10000)); - ASSERT_EQ (5, num_digits (99999)); - ASSERT_EQ (6, num_digits (100000)); - ASSERT_EQ (6, num_digits (999999)); - ASSERT_EQ (7, num_digits (1000000)); - ASSERT_EQ (7, num_digits (9999999)); - ASSERT_EQ (8, num_digits (10000000)); - ASSERT_EQ (8, num_digits (99999999)); -} - -#endif /* #if CHECKING_P */ - /* Implementation of class layout. */ /* Constructor for class layout. @@ -3761,7 +3711,6 @@ void diagnostic_show_locus_c_tests () { test_line_span (); - test_num_digits (); test_layout_range_for_single_point (); test_layout_range_for_single_line (); diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 27e98fa..1b572ae 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -1035,6 +1035,27 @@ diagnostic_report_diagnostic (diagnostic_context *context, return true; } +/* Get the number of digits in the decimal representation of VALUE. */ + +int +num_digits (int value) +{ + /* Perhaps simpler to use log10 for this, but doing it this way avoids + using floating point. */ + gcc_assert (value >= 0); + + if (value == 0) + return 1; + + int digits = 0; + while (value > 0) + { + digits++; + value /= 10; + } + return digits; +} + /* Given a partial pathname as input, return another pathname that shares no directory elements with the pathname of __FILE__. This is used by fancy_abort() to print `Internal compiler error in expr.c' @@ -1785,6 +1806,29 @@ test_diagnostic_get_location_text () progname = old_progname; } +/* Selftest for num_digits. */ + +static void +test_num_digits () +{ + ASSERT_EQ (1, num_digits (0)); + ASSERT_EQ (1, num_digits (9)); + ASSERT_EQ (2, num_digits (10)); + ASSERT_EQ (2, num_digits (99)); + ASSERT_EQ (3, num_digits (100)); + ASSERT_EQ (3, num_digits (999)); + ASSERT_EQ (4, num_digits (1000)); + ASSERT_EQ (4, num_digits (9999)); + ASSERT_EQ (5, num_digits (10000)); + ASSERT_EQ (5, num_digits (99999)); + ASSERT_EQ (6, num_digits (100000)); + ASSERT_EQ (6, num_digits (999999)); + ASSERT_EQ (7, num_digits (1000000)); + ASSERT_EQ (7, num_digits (9999999)); + ASSERT_EQ (8, num_digits (10000000)); + ASSERT_EQ (8, num_digits (99999999)); +} + /* Run all of the selftests within this file. */ void @@ -1796,6 +1840,8 @@ diagnostic_c_tests () test_print_parseable_fixits_remove (); test_print_parseable_fixits_replace (); test_diagnostic_get_location_text (); + test_num_digits (); + } } // namespace selftest diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index a926f9b..596717e 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -421,4 +421,7 @@ extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1; 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); + #endif /* ! GCC_DIAGNOSTIC_H */ diff --git a/gcc/input.c b/gcc/input.c index 237c0d5..6ce9782 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "intl.h" +#include "diagnostic.h" #include "diagnostic-core.h" #include "selftest.h" #include "cpplib.h" @@ -1067,6 +1068,37 @@ dump_location_info (FILE *stream) map->m_column_and_range_bits - map->m_range_bits); fprintf (stream, " range bits: %i\n", map->m_range_bits); + const char * reason; + switch (map->reason) { + case LC_ENTER: + reason = "LC_ENTER"; + break; + case LC_LEAVE: + reason = "LC_LEAVE"; + break; + case LC_RENAME: + reason = "LC_RENAME"; + break; + case LC_RENAME_VERBATIM: + reason = "LC_RENAME_VERBATIM"; + break; + case LC_ENTER_MACRO: + reason = "LC_RENAME_MACRO"; + break; + default: + reason = "Unknown"; + } + fprintf (stream, " reason: %d (%s)\n", map->reason, reason); + + const line_map_ordinary *includer_map + = linemap_included_from_linemap (line_table, map); + fprintf (stream, " included from location: %d", + linemap_included_from (map)); + if (includer_map) { + fprintf (stream, " (in ordinary map %d)", + int (includer_map - line_table->info_ordinary.maps)); + } + fprintf (stream, "\n"); /* Render the span of source lines that this "map" covers. */ for (location_t loc = MAP_START_LOCATION (map); @@ -1100,7 +1132,14 @@ dump_location_info (FILE *stream) if (max_col > line_text.length ()) max_col = line_text.length () + 1; - int indent = 14 + strlen (exploc.file); + int len_lnum = num_digits (exploc.line); + if (len_lnum < 3) + len_lnum = 3; + int len_loc = num_digits (loc); + if (len_loc < 5) + len_loc = 5; + + int indent = 6 + strlen (exploc.file) + len_lnum + len_loc; /* Thousands. */ if (end_location > 999) |