summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-08-19 21:18:05 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-08-19 21:18:05 +0000
commit2ffe0809cb3e9a49387a4657dea65a287b377617 (patch)
tree783b8fccab5b0d0ff9313af8bdd05fec2a5ccdc7 /libcpp
parentd9056349fce2a4b8cd80da5a0657b0e899a5a989 (diff)
downloadgcc-2ffe0809cb3e9a49387a4657dea65a287b377617.tar.gz
Reimplement removal fix-it hints in terms of replace
This patch eliminates class fixit_remove, reimplementing rich_location::add_fixit_remove in terms of replacement with the empty string. Deleting the removal subclass simplifies fixit-handling code, as we only have two concrete fixit_hint subclasses to deal with, rather than three. The patch also fixes some problems in diagnostic-show-locus.c for situations where a replacement fix-it has a different range to the range of the diagnostic, by unifying the drawing of the two kinds of fixits. For example, this: foo = bar.field; ^ m_field becomes: foo = bar.field; ^ ----- m_field showing the range to be replaced. gcc/ChangeLog: * diagnostic-show-locus.c (layout::annotation_line_showed_range_p): New method. (layout::print_any_fixits): Remove case fixit_hint::REMOVE. Reimplement case fixit_hint::REPLACE to cover removals, and replacements where the range of the replacement isn't one of the ranges in the rich_location. (test_one_liner_fixit_replace): Likewise. (selftest::test_one_liner_fixit_replace_non_equal_range): New function. (selftest::test_one_liner_fixit_replace_equal_secondary_range): New function. (selftest::test_diagnostic_show_locus_one_liner): Call the new functions. * diagnostic.c (print_parseable_fixits): Remove case fixit_hint::REMOVE. libcpp/ChangeLog: * include/line-map.h (fixit_hint::kind): Delete REPLACE. (class fixit_remove): Delete. * line-map.c (rich_location::add_fixit_remove): Reimplement by calling add_fixit_replace with an empty string. (fixit_remove::fixit_remove): Delete. (fixit_remove::affects_line_p): Delete. From-SVN: r239632
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog9
-rw-r--r--libcpp/include/line-map.h23
-rw-r--r--libcpp/line-map.c18
3 files changed, 11 insertions, 39 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index f680f8bc899..b0fd9b52ed8 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,12 @@
+2016-08-19 David Malcolm <dmalcolm@redhat.com>
+
+ * include/line-map.h (fixit_hint::kind): Delete REPLACE.
+ (class fixit_remove): Delete.
+ * line-map.c (rich_location::add_fixit_remove): Reimplement
+ by calling add_fixit_replace with an empty string.
+ (fixit_remove::fixit_remove): Delete.
+ (fixit_remove::affects_line_p): Delete.
+
2016-08-19 Joseph Myers <joseph@codesourcery.com>
PR c/32187
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 443086a0b70..f65931c5e52 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1422,7 +1422,7 @@ protected:
class fixit_hint
{
public:
- enum kind {INSERT, REMOVE, REPLACE};
+ enum kind {INSERT, REPLACE};
virtual ~fixit_hint () {}
@@ -1453,27 +1453,6 @@ class fixit_insert : public fixit_hint
size_t m_len;
};
-class fixit_remove : public fixit_hint
-{
- public:
- fixit_remove (source_range src_range);
- ~fixit_remove () {}
-
- enum kind get_kind () const { return REMOVE; }
- bool affects_line_p (const char *file, int line);
- source_location get_start_loc () const { return m_src_range.m_start; }
- bool maybe_get_end_loc (source_location *out) const
- {
- *out = m_src_range.m_finish;
- return true;
- }
-
- source_range get_range () const { return m_src_range; }
-
- private:
- source_range m_src_range;
-};
-
class fixit_replace : public fixit_hint
{
public:
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 141af9d2cde..3890eff7ba0 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -2086,8 +2086,7 @@ rich_location::add_fixit_insert (source_location where,
void
rich_location::add_fixit_remove (source_range src_range)
{
- linemap_assert (m_num_fixit_hints < MAX_FIXIT_HINTS);
- m_fixit_hints[m_num_fixit_hints++] = new fixit_remove (src_range);
+ add_fixit_replace (src_range, "");
}
/* Add a fixit-hint, suggesting replacement of the content at
@@ -2130,21 +2129,6 @@ fixit_insert::affects_line_p (const char *file, int line)
return false;
}
-/* class fixit_remove. */
-
-fixit_remove::fixit_remove (source_range src_range)
-: m_src_range (src_range)
-{
-}
-
-/* Implementation of fixit_hint::affects_line_p for fixit_remove. */
-
-bool
-fixit_remove::affects_line_p (const char *file, int line)
-{
- return m_src_range.intersects_line_p (file, line);
-}
-
/* class fixit_replace. */
fixit_replace::fixit_replace (source_range src_range,