@@ -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;
@@ -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);
@@ -11049,7 +11049,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))
@@ -11061,7 +11061,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:
@@ -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;
@@ -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.