From 3d4f9f878d9aae137be3151920dfcde089a28ddc Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 31 Aug 2016 18:54:55 +0000 Subject: diagnostic-show-locus.c: handle fixits on lines outside the regular ranges The diagnostic_show_locus implementation determines the set of line spans that need printing based on the ranges within the rich_location (in layout::calculate_line_spans). Currently this doesn't take into account fix-it hints, and hence we fail to print fix-it hints that are on lines outside of those ranges. This patch updates the implementation to take fix-it hints into account when calculating the pertinent line spans, so that such fix-it hints do get printed. It also adds some validation, to ensure that we don't attempt to print fix-its hints affecting a different source file. gcc/ChangeLog: * diagnostic-show-locus.c (class layout): Add field m_fixit_hints. (layout_range::intersects_line_p): New method. (test_range_contains_point_for_single_point): Rename to... (test_layout_range_for_single_point): ...this, and add testing for layout_range::intersects_line_p. (test_range_contains_point_for_single_line): Rename to... (test_layout_range_for_single_line): ...this, and add testing for layout_range::intersects_line_p. (test_range_contains_point_for_multiple_lines): Rename to... (test_layout_range_for_multiple_lines): ...this, and add testing for layout_range::intersects_line_p. (layout::layout): Populate m_fixit_hints. (layout::get_expanded_location): Handle the case of a line-span for a fix-it hint. (layout::validate_fixit_hint_p): New method. (get_line_span_for_fixit_hint): New function. (layout::calculate_line_spans): Add spans for fixit-hints. (layout::should_print_annotation_line_p): New method. (layout::print_any_fixits): Drop param "richloc", instead using validated fixits in m_fixit_hints. Add "const" to hint pointers. (diagnostic_show_locus): Avoid printing blank annotation lines. (selftest::test_diagnostic_context::test_diagnostic_context): Initialize show_column and start_span. (selftest::test_diagnostic_context::start_span_cb): New static function. (selftest::test_diagnostic_show_locus_fixit_lines): New function. (selftest::diagnostic_show_locus_c_tests): Update for function renamings. Call test_diagnostic_show_locus_fixit_lines. libcpp/ChangeLog: * include/line-map.h (class fixit_remove): Remove stray decl. (fixit_hint::affects_line_p): Make const. (fixit_insert::affects_line_p): Likewise. (fixit_replace::affects_line_p): Likewise. * line-map.c (fixit_insert::affects_line_p): Likewise. (fixit_replace::affects_line_p): Likewise. From-SVN: r239906 --- libcpp/include/line-map.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'libcpp/include/line-map.h') diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 0c95b29..bef7795 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1412,7 +1412,6 @@ semi_embedded_vec::truncate (int len) class fixit_hint; class fixit_insert; - class fixit_remove; class fixit_replace; /* A "rich" source code location, for use when printing diagnostics. @@ -1599,7 +1598,7 @@ public: virtual ~fixit_hint () {} virtual enum kind get_kind () const = 0; - virtual bool affects_line_p (const char *file, int line) = 0; + virtual bool affects_line_p (const char *file, int line) const = 0; virtual source_location get_start_loc () const = 0; virtual bool maybe_get_end_loc (source_location *out) const = 0; /* Vfunc for consolidating successor fixits. */ @@ -1615,7 +1614,7 @@ class fixit_insert : public fixit_hint const char *new_content); ~fixit_insert (); enum kind get_kind () const { return INSERT; } - bool affects_line_p (const char *file, int line); + bool affects_line_p (const char *file, int line) const; source_location get_start_loc () const { return m_where; } bool maybe_get_end_loc (source_location *) const { return false; } bool maybe_append_replace (line_maps *set, @@ -1640,7 +1639,7 @@ class fixit_replace : public fixit_hint ~fixit_replace (); enum kind get_kind () const { return REPLACE; } - bool affects_line_p (const char *file, int line); + bool affects_line_p (const char *file, int line) const; source_location get_start_loc () const { return m_src_range.m_start; } bool maybe_get_end_loc (source_location *out) const { -- cgit v1.1