summaryrefslogtreecommitdiff
path: root/libcpp/include
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-08-31 18:54:55 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-08-31 18:54:55 +0000
commit70017c995f095495d7190831446659b8fb794db2 (patch)
treee25a9f55c0d092448ebe2741c5ba533d8a45a34e /libcpp/include
parent68c215e47b73f5d64a51ba3b261fdc212dc8270d (diff)
downloadgcc-70017c995f095495d7190831446659b8fb794db2.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239906 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp/include')
-rw-r--r--libcpp/include/line-map.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 0c95b292599..bef77957ffe 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1412,7 +1412,6 @@ semi_embedded_vec<T, NUM_EMBEDDED>::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
{