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". From-SVN: r264376
This commit is contained in:
parent
71b731be7a
commit
9c4a4b3cbd
@ -1,3 +1,22 @@
|
||||
2018-09-17 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* 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 <ubizjak@gmail.com>
|
||||
|
||||
* config/i386/i386.c (ix86_emit_i387_log1p): Emit fldln2 earlier.
|
||||
|
@ -1,3 +1,8 @@
|
||||
2018-09-17 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* c-format.c (range_label_for_format_type_mismatch::get_text):
|
||||
Update for new param.
|
||||
|
||||
2018-09-17 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* c-format.c (format_warning_at_char): Update for introduction of
|
||||
|
@ -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;
|
||||
|
||||
|
@ -1,3 +1,10 @@
|
||||
2018-09-17 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* 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 <mjambor@suse.cz>
|
||||
|
||||
PR c/63886
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -1,3 +1,8 @@
|
||||
2018-09-17 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* error.c (range_label_for_type_mismatch::get_text): Update for
|
||||
new param.
|
||||
|
||||
2018-09-13 Bernd Edlinger <bernd.edlinger@hotmail.de>
|
||||
|
||||
* typeck2.c (digest_init_r): Fix overlength strings.
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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 <char *> (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;
|
||||
|
@ -1,3 +1,8 @@
|
||||
2018-09-17 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* include/line-map.h (range_label::get_text): Add param
|
||||
"range_idx".
|
||||
|
||||
2018-08-30 Nathan Sidwell <nathan@acm.org>
|
||||
|
||||
* include/line-map.h (enum lc_reason): Comment each member
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user