diff options
author | Mike Gulick <mgulick@mathworks.com> | 2018-11-27 16:04:31 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-11-27 16:04:31 +0000 |
commit | bc65bad27f066e2b91380071d65a8f6c6745c2a2 (patch) | |
tree | 8fd44fa810e725cd4e7434022b0220e3c931a500 /gcc/diagnostic.c | |
parent | fb51a3a867e20f574bde3b929ec9ccfba6cc374b (diff) | |
download | gcc-bc65bad27f066e2b91380071d65a8f6c6745c2a2.zip gcc-bc65bad27f066e2b91380071d65a8f6c6745c2a2.tar.gz gcc-bc65bad27f066e2b91380071d65a8f6c6745c2a2.tar.bz2 |
PR preprocessor/83173: Enhance -fdump-internal-locations output
gcc/ChangeLog:
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.
libcpp/ChangeLog:
2018-11-27 Mike Gulick <mgulick@mathworks.com>
PR preprocessor/83173
* location-example.txt: Update example -fdump-internal-locations
output.
From-SVN: r266520
Diffstat (limited to 'gcc/diagnostic.c')
-rw-r--r-- | gcc/diagnostic.c | 46 |
1 files changed, 46 insertions, 0 deletions
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 |