summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-08-31 18:54:55 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-08-31 18:54:55 +0000
commit3d4f9f878d9aae137be3151920dfcde089a28ddc (patch)
treee25a9f55c0d092448ebe2741c5ba533d8a45a34e /libcpp
parentd12a0b5aabfc329077c4222755c5e6f78e7fd07e (diff)
downloadgcc-3d4f9f878d9aae137be3151920dfcde089a28ddc.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. From-SVN: r239906
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog9
-rw-r--r--libcpp/include/line-map.h7
-rw-r--r--libcpp/line-map.c4
3 files changed, 14 insertions, 6 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 595d6ca4cca..69abc6802bf 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,12 @@
+2016-08-31 David Malcolm <dmalcolm@redhat.com>
+
+ * 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.
+
2016-08-30 David Malcolm <dmalcolm@redhat.com>
* include/line-map.h (class semi_embedded_vec): New class.
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
{
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 72549ba0732..f69c60c7837 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -2314,7 +2314,7 @@ fixit_insert::~fixit_insert ()
/* Implementation of fixit_hint::affects_line_p for fixit_insert. */
bool
-fixit_insert::affects_line_p (const char *file, int line)
+fixit_insert::affects_line_p (const char *file, int line) const
{
expanded_location exploc
= linemap_client_expand_location_to_spelling_point (m_where);
@@ -2351,7 +2351,7 @@ fixit_replace::~fixit_replace ()
/* Implementation of fixit_hint::affects_line_p for fixit_replace. */
bool
-fixit_replace::affects_line_p (const char *file, int line)
+fixit_replace::affects_line_p (const char *file, int line) const
{
return m_src_range.intersects_line_p (file, line);
}