From a2507e3dbf1a25ba23eb69771d70669de1bdba05 Mon Sep 17 00:00:00 2001 From: dmalcolm Date: Mon, 17 Sep 2018 23:32:12 +0000 Subject: [PATCH] Add range_idx param to range_label::get_text This patch updates the pure virtual function range_label::get_text (and its implementations) so that the index of the range is passed in, allowing for one label instance to be shared by multiple ranges. gcc/c-family/ChangeLog: * c-format.c (range_label_for_format_type_mismatch::get_text): Update for new param. gcc/c/ChangeLog: * c-objc-common.c (range_label_for_type_mismatch::get_text): Update for new param. * c-typeck.c (maybe_range_label_for_tree_type_mismatch::get_text): Likewise. gcc/cp/ChangeLog: * error.c (range_label_for_type_mismatch::get_text): Update for new param. gcc/ChangeLog: * diagnostic-show-locus.c (class layout_range): Add field "m_original_idx". (layout_range::layout_range): Add "original_idx" param and use it to initialize new field. (make_range): Use 0 for original_idx. (layout::layout): Pass in index to calls to maybe_add_location_range. (layout::maybe_add_location_range): Add param "original_idx" and pass it on to layout_range. (layout::print_any_labels): Pass on range->m_original_idx to get_text call. (gcc_rich_location::add_location_if_nearby): Use 0 for original_idx. * gcc-rich-location.h (text_range_label::get_text): Update for new param. (range_label_for_type_mismatch::get_text): Likewise. libcpp/ChangeLog: * include/line-map.h (range_label::get_text): Add param "range_idx". git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@264376 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 19 +++++++++++++++++++ gcc/c-family/ChangeLog | 5 +++++ gcc/c-family/c-format.c | 4 ++-- gcc/c/ChangeLog | 7 +++++++ gcc/c/c-objc-common.c | 2 +- gcc/c/c-typeck.c | 4 ++-- gcc/cp/ChangeLog | 5 +++++ gcc/cp/error.c | 2 +- gcc/diagnostic-show-locus.c | 19 ++++++++++++++----- gcc/gcc-rich-location.h | 4 ++-- libcpp/ChangeLog | 5 +++++ libcpp/include/line-map.h | 6 ++++-- 12 files changed, 67 insertions(+), 15 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 626c69d8f940..d236d68e5015 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,22 @@ +2018-09-17 David Malcolm + + * diagnostic-show-locus.c (class layout_range): Add field + "m_original_idx". + (layout_range::layout_range): Add "original_idx" param and use it + to initialize new field. + (make_range): Use 0 for original_idx. + (layout::layout): Pass in index to calls to + maybe_add_location_range. + (layout::maybe_add_location_range): Add param "original_idx" and + pass it on to layout_range. + (layout::print_any_labels): Pass on range->m_original_idx to + get_text call. + (gcc_rich_location::add_location_if_nearby): Use 0 for + original_idx. + * gcc-rich-location.h (text_range_label::get_text): Update for new + param. + (range_label_for_type_mismatch::get_text): Likewise. + 2018-09-17 Uros Bizjak * config/i386/i386.c (ix86_emit_i387_log1p): Emit fldln2 earlier. diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index b70d77a72193..f2ec39424162 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2018-09-17 David Malcolm + + * c-format.c (range_label_for_format_type_mismatch::get_text): + Update for new param. + 2018-09-17 David Malcolm * c-format.c (format_warning_at_char): Update for introduction of diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index a7edfca4aa94..a1133c75d93d 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -3597,9 +3597,9 @@ class range_label_for_format_type_mismatch { } - label_text get_text () const FINAL OVERRIDE + label_text get_text (unsigned range_idx) const FINAL OVERRIDE { - label_text text = range_label_for_type_mismatch::get_text (); + label_text text = range_label_for_type_mismatch::get_text (range_idx); if (text.m_buffer == NULL) return text; diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 3133ca6b6b07..6fd76cfe9703 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,10 @@ +2018-09-17 David Malcolm + + * c-objc-common.c (range_label_for_type_mismatch::get_text): + Update for new param. + * c-typeck.c (maybe_range_label_for_tree_type_mismatch::get_text): + Likewise. + 2018-09-17 Martin Jambor PR c/63886 diff --git a/gcc/c/c-objc-common.c b/gcc/c/c-objc-common.c index 12e777a48455..fee52689e2db 100644 --- a/gcc/c/c-objc-common.c +++ b/gcc/c/c-objc-common.c @@ -218,7 +218,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec, range_label_for_type_mismatch. */ label_text -range_label_for_type_mismatch::get_text () const +range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const { if (m_labelled_type == NULL_TREE) return label_text (NULL, false); diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index a7e2538e1ac9..a5a7da0084c7 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -11056,7 +11056,7 @@ class maybe_range_label_for_tree_type_mismatch : public range_label { } - label_text get_text () const FINAL OVERRIDE + label_text get_text (unsigned range_idx) const FINAL OVERRIDE { if (m_expr == NULL_TREE || !EXPR_P (m_expr)) @@ -11068,7 +11068,7 @@ class maybe_range_label_for_tree_type_mismatch : public range_label other_type = TREE_TYPE (m_other_expr); range_label_for_type_mismatch inner (expr_type, other_type); - return inner.get_text (); + return inner.get_text (range_idx); } private: diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1d1d59a87ec2..cec08bfd712c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-09-17 David Malcolm + + * error.c (range_label_for_type_mismatch::get_text): Update for + new param. + 2018-09-13 Bernd Edlinger * typeck2.c (digest_init_r): Fix overlength strings. diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 5bab3f345ed8..601f6d2c264e 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -4289,7 +4289,7 @@ qualified_name_lookup_error (tree scope, tree name, Compare with print_template_differences above. */ label_text -range_label_for_type_mismatch::get_text () const +range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const { if (m_labelled_type == NULL_TREE) return label_text (NULL, false); diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c index 6ce8a0f4a9b7..7dfb0a036cd6 100644 --- a/gcc/diagnostic-show-locus.c +++ b/gcc/diagnostic-show-locus.c @@ -128,6 +128,7 @@ class layout_range const expanded_location *finish_exploc, enum range_display_kind range_display_kind, const expanded_location *caret_exploc, + unsigned original_idx, const range_label *label); bool contains_point (linenum_type row, int column) const; @@ -137,6 +138,7 @@ class layout_range layout_point m_finish; enum range_display_kind m_range_display_kind; layout_point m_caret; + unsigned m_original_idx; const range_label *m_label; }; @@ -236,6 +238,7 @@ class layout diagnostic_t diagnostic_kind); bool maybe_add_location_range (const location_range *loc_range, + unsigned original_idx, bool restrict_to_current_line_spans); int get_num_line_spans () const { return m_line_spans.length (); } @@ -414,11 +417,13 @@ layout_range::layout_range (const expanded_location *start_exploc, const expanded_location *finish_exploc, enum range_display_kind range_display_kind, const expanded_location *caret_exploc, + unsigned original_idx, const range_label *label) : m_start (*start_exploc), m_finish (*finish_exploc), m_range_display_kind (range_display_kind), m_caret (*caret_exploc), + m_original_idx (original_idx), m_label (label) { } @@ -546,7 +551,7 @@ make_range (int start_line, int start_col, int end_line, int end_col) const expanded_location finish_exploc = {"test.c", end_line, end_col, NULL, false}; return layout_range (&start_exploc, &finish_exploc, SHOW_RANGE_WITHOUT_CARET, - &start_exploc, NULL); + &start_exploc, 0, NULL); } /* Selftests for layout_range::contains_point and @@ -899,7 +904,7 @@ layout::layout (diagnostic_context * context, /* This diagnostic printer can only cope with "sufficiently sane" ranges. Ignore any ranges that are awkward to handle. */ const location_range *loc_range = richloc->get_range (idx); - maybe_add_location_range (loc_range, false); + maybe_add_location_range (loc_range, idx, false); } /* Populate m_fixit_hints, filtering to only those that are in the @@ -953,6 +958,9 @@ layout::layout (diagnostic_context * context, /* Attempt to add LOC_RANGE to m_layout_ranges, filtering them to those that we can sanely print. + ORIGINAL_IDX is the index of LOC_RANGE within its rich_location, + (for use as extrinsic state by label ranges FIXME). + If RESTRICT_TO_CURRENT_LINE_SPANS is true, then LOC_RANGE is also filtered against this layout instance's current line spans: it will only be added if the location is fully within the lines @@ -962,6 +970,7 @@ layout::layout (diagnostic_context * context, bool layout::maybe_add_location_range (const location_range *loc_range, + unsigned original_idx, bool restrict_to_current_line_spans) { gcc_assert (loc_range); @@ -1001,7 +1010,7 @@ layout::maybe_add_location_range (const location_range *loc_range, /* Everything is now known to be in the correct source file, but it may require further sanitization. */ layout_range ri (&start, &finish, loc_range->m_range_display_kind, &caret, - loc_range->m_label); + original_idx, loc_range->m_label); /* If we have a range that finishes before it starts (perhaps from something built via macro expansion), printing the @@ -1488,7 +1497,7 @@ layout::print_any_labels (linenum_type row) continue; label_text text; - text = range->m_label->get_text (); + text = range->m_label->get_text (range->m_original_idx); /* Allow for labels that return NULL from their get_text implementation (so e.g. such labels can control their own @@ -2277,7 +2286,7 @@ gcc_rich_location::add_location_if_nearby (location_t loc) location_range loc_range; loc_range.m_loc = loc; loc_range.m_range_display_kind = SHOW_RANGE_WITHOUT_CARET; - if (!layout.maybe_add_location_range (&loc_range, true)) + if (!layout.maybe_add_location_range (&loc_range, 0, true)) return false; add_range (loc); diff --git a/gcc/gcc-rich-location.h b/gcc/gcc-rich-location.h index dc11ee87552d..e55dd76f4c6c 100644 --- a/gcc/gcc-rich-location.h +++ b/gcc/gcc-rich-location.h @@ -109,7 +109,7 @@ class text_range_label : public range_label public: text_range_label (const char *text) : m_text (text) {} - label_text get_text () const FINAL OVERRIDE + label_text get_text (unsigned /*range_idx*/) const FINAL OVERRIDE { return label_text (const_cast (m_text), false); } @@ -155,7 +155,7 @@ class range_label_for_type_mismatch : public range_label { } - label_text get_text () const OVERRIDE; + label_text get_text (unsigned range_idx) const OVERRIDE; protected: tree m_labelled_type; diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 59052be1ba6a..ef96824f7ef3 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,8 @@ +2018-09-17 David Malcolm + + * include/line-map.h (range_label::get_text): Add param + "range_idx". + 2018-08-30 Nathan Sidwell * include/line-map.h (enum lc_reason): Comment each member diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index fd067589b63e..c479dfa2b3ce 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1808,8 +1808,10 @@ class range_label public: virtual ~range_label () {} - /* Get localized text for the label. */ - virtual label_text get_text () const = 0; + /* Get localized text for the label. + The RANGE_IDX is provided, allowing for range_label instances to be + shared by multiple ranges if need be (the "flyweight" design pattern). */ + virtual label_text get_text (unsigned range_idx) const = 0; }; /* A fix-it hint: a suggested insertion, replacement, or deletion of text. -- 2.39.2