aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2023-11-09 17:22:52 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2023-11-09 17:22:52 -0500
commit8625aa246696695ef5c20aba847a8f39019ab8d3 (patch)
tree2f71899f2c5b2e2bbcf0b346e3825bd31ce84886
parent0c6c9b64545c5ef87df9f025ecb90ed537054caa (diff)
downloadgcc-8625aa246696695ef5c20aba847a8f39019ab8d3.zip
gcc-8625aa246696695ef5c20aba847a8f39019ab8d3.tar.gz
gcc-8625aa246696695ef5c20aba847a8f39019ab8d3.tar.bz2
diagnostics: cleanups to diagnostic-show-locus.cc
Reduce implicit usage of line_table global, and move source printing to within diagnostic_context. gcc/ChangeLog: * diagnostic-show-locus.cc (layout::m_line_table): New field. (compatible_locations_p): Convert to... (layout::compatible_locations_p): ...this, replacing uses of line_table global with m_line_table. (layout::layout): Convert "richloc" param from a pointer to a const reference. Initialize m_line_table member. (layout::maybe_add_location_range): Replace uses of line_table global with m_line_table. Pass the latter to linemap_client_expand_location_to_spelling_point. (layout::print_leading_fixits): Pass m_line_table to affects_line_p. (layout::print_trailing_fixits): Likewise. (gcc_rich_location::add_location_if_nearby): Update for change to layout ctor params. (diagnostic_show_locus): Convert to... (diagnostic_context::maybe_show_locus): ...this, converting richloc param from a pointer to a const reference. Make "loc" const. Split out printing part of function to... (diagnostic_context::show_locus): ...this. (selftest::test_offset_impl): Update for change to layout ctor params. (selftest::test_layout_x_offset_display_utf8): Likewise. (selftest::test_layout_x_offset_display_tab): Likewise. (selftest::test_tab_expansion): Likewise. * diagnostic.h (diagnostic_context::maybe_show_locus): New decl. (diagnostic_context::show_locus): New decl. (diagnostic_show_locus): Convert from a decl to an inline function. * gdbinit.in (break-on-diagnostic): Update from a breakpoint on diagnostic_show_locus to one on diagnostic_context::maybe_show_locus. * genmatch.cc (linemap_client_expand_location_to_spelling_point): Add "set" param and use it in place of line_table global. * input.cc (expand_location_1): Likewise. (expand_location): Update for new param of expand_location_1. (expand_location_to_spelling_point): Likewise. (linemap_client_expand_location_to_spelling_point): Add "set" param and use it in place of line_table global. * tree-diagnostic-path.cc (event_range::print): Pass line_table for new param of linemap_client_expand_location_to_spelling_point. libcpp/ChangeLog: * include/line-map.h (rich_location::get_expanded_location): Make const. (rich_location::get_line_table): New accessor. (rich_location::m_line_table): Make the pointer be const. (rich_location::m_have_expanded_location): Make mutable. (rich_location::m_expanded_location): Likewise. (fixit_hint::affects_line_p): Add const line_maps * param. (linemap_client_expand_location_to_spelling_point): Likewise. * line-map.cc (rich_location::get_expanded_location): Make const. Pass m_line_table to linemap_client_expand_location_to_spelling_point. (rich_location::maybe_add_fixit): Likewise. (fixit_hint::affects_line_p): Add set param and pass to linemap_client_expand_location_to_spelling_point. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
-rw-r--r--gcc/diagnostic-show-locus.cc122
-rw-r--r--gcc/diagnostic.h21
-rw-r--r--gcc/gdbinit.in2
-rw-r--r--gcc/genmatch.cc7
-rw-r--r--gcc/input.cc23
-rw-r--r--gcc/tree-diagnostic-path.cc2
-rw-r--r--libcpp/include/line-map.h17
-rw-r--r--libcpp/line-map.cc22
8 files changed, 129 insertions, 87 deletions
diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc
index 4352357..5edc319 100644
--- a/gcc/diagnostic-show-locus.cc
+++ b/gcc/diagnostic-show-locus.cc
@@ -366,7 +366,7 @@ class layout
{
public:
layout (const diagnostic_context &context,
- rich_location *richloc,
+ const rich_location &richloc,
diagnostic_t diagnostic_kind,
pretty_printer *pp);
@@ -428,7 +428,10 @@ class layout
move_to_column (int *column, int dest_column, bool add_left_margin);
private:
+ bool compatible_locations_p (location_t loc_a, location_t loc_b) const;
+
const diagnostic_source_printing_options &m_options;
+ const line_maps *m_line_table;
pretty_printer *m_pp;
char_display_policy m_policy;
location_t m_primary_loc;
@@ -930,13 +933,13 @@ test_get_line_bytes_without_trailing_whitespace ()
erroneously was leading to hundreds of lines of irrelevant source
being printed. */
-static bool
-compatible_locations_p (location_t loc_a, location_t loc_b)
+bool
+layout::compatible_locations_p (location_t loc_a, location_t loc_b) const
{
if (IS_ADHOC_LOC (loc_a))
- loc_a = get_location_from_adhoc_loc (line_table, loc_a);
+ loc_a = get_location_from_adhoc_loc (m_line_table, loc_a);
if (IS_ADHOC_LOC (loc_b))
- loc_b = get_location_from_adhoc_loc (line_table, loc_b);
+ loc_b = get_location_from_adhoc_loc (m_line_table, loc_b);
/* If either location is one of the special locations outside of a
linemap, they are only compatible if they are equal. */
@@ -944,10 +947,10 @@ compatible_locations_p (location_t loc_a, location_t loc_b)
|| loc_b < RESERVED_LOCATION_COUNT)
return loc_a == loc_b;
- const line_map *map_a = linemap_lookup (line_table, loc_a);
+ const line_map *map_a = linemap_lookup (m_line_table, loc_a);
linemap_assert (map_a);
- const line_map *map_b = linemap_lookup (line_table, loc_b);
+ const line_map *map_b = linemap_lookup (m_line_table, loc_b);
linemap_assert (map_b);
/* Are they within the same map? */
@@ -959,9 +962,9 @@ compatible_locations_p (location_t loc_a, location_t loc_b)
/* If so, then they're only compatible if either both are
from the macro definition, or both from the macro arguments. */
bool loc_a_from_defn
- = linemap_location_from_macro_definition_p (line_table, loc_a);
+ = linemap_location_from_macro_definition_p (m_line_table, loc_a);
bool loc_b_from_defn
- = linemap_location_from_macro_definition_p (line_table, loc_b);
+ = linemap_location_from_macro_definition_p (m_line_table, loc_b);
if (loc_a_from_defn != loc_b_from_defn)
return false;
@@ -969,11 +972,11 @@ compatible_locations_p (location_t loc_a, location_t loc_b)
recurse. */
const line_map_macro *macro_map = linemap_check_macro (map_a);
location_t loc_a_toward_spelling
- = linemap_macro_map_loc_unwind_toward_spelling (line_table,
+ = linemap_macro_map_loc_unwind_toward_spelling (m_line_table,
macro_map,
loc_a);
location_t loc_b_toward_spelling
- = linemap_macro_map_loc_unwind_toward_spelling (line_table,
+ = linemap_macro_map_loc_unwind_toward_spelling (m_line_table,
macro_map,
loc_b);
return compatible_locations_p (loc_a_toward_spelling,
@@ -1180,37 +1183,38 @@ make_policy (const diagnostic_context &dc,
will fit within the max_width provided by the diagnostic_context. */
layout::layout (const diagnostic_context &context,
- rich_location *richloc,
+ const rich_location &richloc,
diagnostic_t diagnostic_kind,
pretty_printer *pp)
: m_options (context.m_source_printing),
+ m_line_table (richloc.get_line_table ()),
m_pp (pp ? pp : context.printer),
- m_policy (make_policy (context, *richloc)),
- m_primary_loc (richloc->get_range (0)->m_loc),
- m_exploc (richloc->get_expanded_location (0), m_policy,
+ m_policy (make_policy (context, richloc)),
+ m_primary_loc (richloc.get_range (0)->m_loc),
+ m_exploc (richloc.get_expanded_location (0), m_policy,
LOCATION_ASPECT_CARET),
m_colorizer (m_pp, diagnostic_kind),
m_diagnostic_path_p (diagnostic_kind == DK_DIAGNOSTIC_PATH),
- m_layout_ranges (richloc->get_num_locations ()),
- m_fixit_hints (richloc->get_num_fixit_hints ()),
- m_line_spans (1 + richloc->get_num_locations ()),
+ m_layout_ranges (richloc.get_num_locations ()),
+ m_fixit_hints (richloc.get_num_fixit_hints ()),
+ m_line_spans (1 + richloc.get_num_locations ()),
m_linenum_width (0),
m_x_offset_display (0),
- m_escape_on_output (richloc->escape_on_output_p ())
+ m_escape_on_output (richloc.escape_on_output_p ())
{
- for (unsigned int idx = 0; idx < richloc->get_num_locations (); idx++)
+ for (unsigned int idx = 0; idx < richloc.get_num_locations (); idx++)
{
/* 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);
+ const location_range *loc_range = richloc.get_range (idx);
maybe_add_location_range (loc_range, idx, false);
}
/* Populate m_fixit_hints, filtering to only those that are in the
same file. */
- for (unsigned int i = 0; i < richloc->get_num_fixit_hints (); i++)
+ for (unsigned int i = 0; i < richloc.get_num_fixit_hints (); i++)
{
- const fixit_hint *hint = richloc->get_fixit_hint (i);
+ const fixit_hint *hint = richloc.get_fixit_hint (i);
if (validate_fixit_hint_p (hint))
m_fixit_hints.safe_push (hint);
}
@@ -1249,18 +1253,18 @@ layout::maybe_add_location_range (const location_range *loc_range,
gcc_assert (loc_range);
/* Split the "range" into caret and range information. */
- source_range src_range = get_range_from_loc (line_table, loc_range->m_loc);
+ source_range src_range = get_range_from_loc (m_line_table, loc_range->m_loc);
/* Expand the various locations. */
expanded_location start
= linemap_client_expand_location_to_spelling_point
- (src_range.m_start, LOCATION_ASPECT_START);
+ (m_line_table, src_range.m_start, LOCATION_ASPECT_START);
expanded_location finish
= linemap_client_expand_location_to_spelling_point
- (src_range.m_finish, LOCATION_ASPECT_FINISH);
+ (m_line_table, src_range.m_finish, LOCATION_ASPECT_FINISH);
expanded_location caret
= linemap_client_expand_location_to_spelling_point
- (loc_range->m_loc, LOCATION_ASPECT_CARET);
+ (m_line_table, loc_range->m_loc, LOCATION_ASPECT_CARET);
/* If any part of the range isn't in the same file as the primary
location of this diagnostic, ignore the range. */
@@ -2098,7 +2102,7 @@ layout::print_leading_fixits (linenum_type row)
gcc_assert (hint->insertion_p ());
- if (hint->affects_line_p (m_exploc.file, row))
+ if (hint->affects_line_p (m_line_table, m_exploc.file, row))
{
/* Printing the '+' with normal colorization
and the inserted line with "insert" colorization
@@ -2550,7 +2554,7 @@ layout::print_trailing_fixits (linenum_type row)
if (hint->ends_with_newline_p ())
continue;
- if (hint->affects_line_p (m_exploc.file, row))
+ if (hint->affects_line_p (m_line_table, m_exploc.file, row))
corrections.add_hint (hint);
}
@@ -2808,7 +2812,7 @@ gcc_rich_location::add_location_if_nearby (location_t loc,
/* Use the layout location-handling logic to sanitize LOC,
filtering it to the current line spans within a temporary
layout instance. */
- layout layout (*global_dc, this, DK_ERROR, nullptr);
+ layout layout (*global_dc, *this, DK_ERROR, nullptr);
location_range loc_range;
loc_range.m_loc = loc;
loc_range.m_range_display_kind = SHOW_RANGE_WITHOUT_CARET;
@@ -2820,19 +2824,17 @@ gcc_rich_location::add_location_if_nearby (location_t loc,
return true;
}
-/* Print the physical source code corresponding to the location of
- this diagnostic, with additional annotations.
- If PP is non-null, then use it rather than CONTEXT's printer. */
+/* As per diagnostic_context::show_locus, but don't print anything
+ if source printing is disabled, or if the location hasn't changed. */
void
-diagnostic_show_locus (diagnostic_context * context,
- rich_location *richloc,
- diagnostic_t diagnostic_kind,
- pretty_printer *pp)
+diagnostic_context::maybe_show_locus (const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ pretty_printer *pp)
{
- location_t loc = richloc->get_loc ();
+ const location_t loc = richloc.get_loc ();
/* Do nothing if source-printing has been disabled. */
- if (!context->m_source_printing.enabled)
+ if (!m_source_printing.enabled)
return;
/* Don't attempt to print source for UNKNOWN_LOCATION and for builtins. */
@@ -2841,20 +2843,32 @@ diagnostic_show_locus (diagnostic_context * context,
/* Don't print the same source location twice in a row, unless we have
fix-it hints, or multiple locations, or a label. */
- if (loc == context->m_last_location
- && richloc->get_num_fixit_hints () == 0
- && richloc->get_num_locations () == 1
- && richloc->get_range (0)->m_label == NULL)
+ if (loc == m_last_location
+ && richloc.get_num_fixit_hints () == 0
+ && richloc.get_num_locations () == 1
+ && richloc.get_range (0)->m_label == NULL)
return;
- context->m_last_location = loc;
+ m_last_location = loc;
+
+ show_locus (richloc, diagnostic_kind, pp);
+}
- layout layout (*context, richloc, diagnostic_kind, pp);
+/* Print the physical source code corresponding to the location of
+ this diagnostic, with additional annotations.
+ If PP is non-null, then use it rather than this context's printer. */
+
+void
+diagnostic_context::show_locus (const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ pretty_printer *pp)
+{
+ layout layout (*this, richloc, diagnostic_kind, pp);
for (int line_span_idx = 0; line_span_idx < layout.get_num_line_spans ();
line_span_idx++)
{
const line_span *line_span = layout.get_line_span (line_span_idx);
- if (context->m_source_printing.show_line_numbers_p)
+ if (m_source_printing.show_line_numbers_p)
{
/* With line numbers, we should show whenever the line-numbering
"jumps". */
@@ -2868,7 +2882,7 @@ diagnostic_show_locus (diagnostic_context * context,
{
expanded_location exploc
= layout.get_expanded_location (line_span);
- context->m_text_callbacks.start_span (context, exploc);
+ m_text_callbacks.start_span (this, exploc);
}
}
/* Iterate over the lines within this span (using linenum_arith_t to
@@ -2961,7 +2975,7 @@ test_offset_impl (int caret_byte_col, int max_width,
rich_location richloc (line_table,
linemap_position_for_column (line_table,
caret_byte_col));
- layout test_layout (dc, &richloc, DK_ERROR, nullptr);
+ layout test_layout (dc, richloc, DK_ERROR, nullptr);
ASSERT_EQ (left_margin - test_linenum_sep,
test_layout.get_linenum_width ());
ASSERT_EQ (expected_x_offset_display,
@@ -3076,7 +3090,7 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_)
rich_location richloc (line_table,
linemap_position_for_column (line_table,
emoji_col));
- layout test_layout (dc, &richloc, DK_ERROR, nullptr);
+ layout test_layout (dc, richloc, DK_ERROR, nullptr);
test_layout.print_line (1);
ASSERT_STREQ (" | 1 \n"
" | 1 \n"
@@ -3101,7 +3115,7 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_)
rich_location richloc (line_table,
linemap_position_for_column (line_table,
emoji_col + 2));
- layout test_layout (dc, &richloc, DK_ERROR, nullptr);
+ layout test_layout (dc, richloc, DK_ERROR, nullptr);
test_layout.print_line (1);
ASSERT_STREQ (" | 1 1 \n"
" | 1 2 \n"
@@ -3178,7 +3192,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
{
test_diagnostic_context dc;
dc.m_tabstop = tabstop;
- layout test_layout (dc, &richloc, DK_ERROR, nullptr);
+ layout test_layout (dc, richloc, DK_ERROR, nullptr);
test_layout.print_line (1);
const char *out = pp_formatted_text (dc.printer);
ASSERT_EQ (NULL, strchr (out, '\t'));
@@ -3201,7 +3215,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
dc.m_source_printing.min_margin_width
= test_left_margin - test_linenum_sep + 1;
dc.m_source_printing.show_line_numbers_p = true;
- layout test_layout (dc, &richloc, DK_ERROR, nullptr);
+ layout test_layout (dc, richloc, DK_ERROR, nullptr);
test_layout.print_line (1);
/* We have arranged things so that two columns will be printed before
@@ -5513,7 +5527,7 @@ test_tab_expansion (const line_table_case &case_)
rich_location richloc (line_table,
linemap_position_for_column (line_table,
first_non_ws_byte_col));
- layout test_layout (dc, &richloc, DK_ERROR, nullptr);
+ layout test_layout (dc, richloc, DK_ERROR, nullptr);
test_layout.print_line (1);
ASSERT_STREQ (" This: ` ' is a tab.\n"
" ^\n",
@@ -5528,7 +5542,7 @@ test_tab_expansion (const line_table_case &case_)
rich_location richloc (line_table,
linemap_position_for_column (line_table,
right_quote_byte_col));
- layout test_layout (dc, &richloc, DK_ERROR, nullptr);
+ layout test_layout (dc, richloc, DK_ERROR, nullptr);
test_layout.print_line (1);
ASSERT_STREQ (" This: ` ' is a tab.\n"
" ^\n",
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 58341ce..6a32282 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -410,6 +410,10 @@ public:
m_option_classifier.pop (where);
}
+ void maybe_show_locus (const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ pretty_printer *pp);
+
void emit_diagram (const diagnostic_diagram &diagram);
/* Various setters for use by option-handling logic. */
@@ -496,6 +500,10 @@ private:
void get_any_inlining_info (diagnostic_info *diagnostic);
+ void show_locus (const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ pretty_printer *pp);
+
/* Data members.
Ideally, all of these would be private and have "m_" prefixes. */
@@ -816,10 +824,15 @@ diagnostic_report_current_module (diagnostic_context *context,
context->report_current_module (where);
}
-extern void diagnostic_show_locus (diagnostic_context *,
- rich_location *richloc,
- diagnostic_t diagnostic_kind,
- pretty_printer *pp = nullptr);
+inline void
+diagnostic_show_locus (diagnostic_context *context,
+ rich_location *richloc,
+ diagnostic_t diagnostic_kind,
+ pretty_printer *pp = nullptr)
+{
+ gcc_assert (richloc);
+ context->maybe_show_locus (*richloc, diagnostic_kind, pp);
+}
/* Because we read source files a second time after the frontend did it the
first time, we need to know how the frontend handled things like character
diff --git a/gcc/gdbinit.in b/gcc/gdbinit.in
index a76079a..39801df 100644
--- a/gcc/gdbinit.in
+++ b/gcc/gdbinit.in
@@ -293,7 +293,7 @@ See also 'help-gcc-hooks'.
end
define break-on-diagnostic
-break diagnostic_show_locus
+break diagnostic_context::maybe_show_locus
end
document break-on-diagnostic
diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
index e9d7afa..4572342 100644
--- a/gcc/genmatch.cc
+++ b/gcc/genmatch.cc
@@ -62,12 +62,13 @@ static class line_maps *line_table;
This is the implementation for genmatch. */
expanded_location
-linemap_client_expand_location_to_spelling_point (location_t loc,
+linemap_client_expand_location_to_spelling_point (const line_maps *set,
+ location_t loc,
enum location_aspect)
{
const struct line_map_ordinary *map;
- loc = linemap_resolve_location (line_table, loc, LRK_SPELLING_LOCATION, &map);
- return linemap_expand_location (line_table, map, loc);
+ loc = linemap_resolve_location (set, loc, LRK_SPELLING_LOCATION, &map);
+ return linemap_expand_location (set, map, loc);
}
static bool
diff --git a/gcc/input.cc b/gcc/input.cc
index f7c0163..1b22922 100644
--- a/gcc/input.cc
+++ b/gcc/input.cc
@@ -215,7 +215,8 @@ class line_maps *saved_line_table;
ASPECT controls which part of the location to use. */
static expanded_location
-expand_location_1 (location_t loc,
+expand_location_1 (const line_maps *set,
+ location_t loc,
bool expansion_point_p,
enum location_aspect aspect)
{
@@ -243,11 +244,11 @@ expand_location_1 (location_t loc,
location for a built-in token), let's consider the first
location (toward the expansion point) that is not reserved;
that is, the first location that is in real source code. */
- loc = linemap_unwind_to_first_non_reserved_loc (line_table,
+ loc = linemap_unwind_to_first_non_reserved_loc (set,
loc, NULL);
lrk = LRK_SPELLING_LOCATION;
}
- loc = linemap_resolve_location (line_table, loc, lrk, &map);
+ loc = linemap_resolve_location (set, loc, lrk, &map);
/* loc is now either in an ordinary map, or is a reserved location.
If it is a compound location, the caret is in a spelling location,
@@ -266,18 +267,18 @@ expand_location_1 (location_t loc,
{
location_t start = get_start (loc);
if (start != loc)
- return expand_location_1 (start, expansion_point_p, aspect);
+ return expand_location_1 (set, start, expansion_point_p, aspect);
}
break;
case LOCATION_ASPECT_FINISH:
{
location_t finish = get_finish (loc);
if (finish != loc)
- return expand_location_1 (finish, expansion_point_p, aspect);
+ return expand_location_1 (set, finish, expansion_point_p, aspect);
}
break;
}
- xloc = linemap_expand_location (line_table, map, loc);
+ xloc = linemap_expand_location (set, map, loc);
}
xloc.data = block;
@@ -1127,7 +1128,7 @@ is_location_from_builtin_token (location_t loc)
expanded_location
expand_location (location_t loc)
{
- return expand_location_1 (loc, /*expansion_point_p=*/true,
+ return expand_location_1 (line_table, loc, /*expansion_point_p=*/true,
LOCATION_ASPECT_CARET);
}
@@ -1141,7 +1142,8 @@ expanded_location
expand_location_to_spelling_point (location_t loc,
enum location_aspect aspect)
{
- return expand_location_1 (loc, /*expansion_point_p=*/false, aspect);
+ return expand_location_1 (line_table, loc, /*expansion_point_p=*/false,
+ aspect);
}
/* The rich_location class within libcpp requires a way to expand
@@ -1154,10 +1156,11 @@ expand_location_to_spelling_point (location_t loc,
which simply calls into expand_location_1. */
expanded_location
-linemap_client_expand_location_to_spelling_point (location_t loc,
+linemap_client_expand_location_to_spelling_point (const line_maps *set,
+ location_t loc,
enum location_aspect aspect)
{
- return expand_location_1 (loc, /*expansion_point_p=*/false, aspect);
+ return expand_location_1 (set, loc, /*expansion_point_p=*/false, aspect);
}
diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic-path.cc
index cd983bc..ee957cc 100644
--- a/gcc/tree-diagnostic-path.cc
+++ b/gcc/tree-diagnostic-path.cc
@@ -204,7 +204,7 @@ struct event_range
{
expanded_location exploc
= linemap_client_expand_location_to_spelling_point
- (initial_loc, LOCATION_ASPECT_CARET);
+ (line_table, initial_loc, LOCATION_ASPECT_CARET);
if (exploc.file != LOCATION_FILE (dc->m_last_location))
dc->m_text_callbacks.start_span (dc, exploc);
}
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 635d6d3..615cb42 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1658,7 +1658,7 @@ class rich_location
const location_range *get_range (unsigned int idx) const;
location_range *get_range (unsigned int idx);
- expanded_location get_expanded_location (unsigned int idx);
+ expanded_location get_expanded_location (unsigned int idx) const;
void
override_column (int column);
@@ -1762,6 +1762,8 @@ class rich_location
bool escape_on_output_p () const { return m_escape_on_output; }
void set_escape_on_output (bool flag) { m_escape_on_output = flag; }
+ const line_maps *get_line_table () const { return m_line_table; }
+
private:
bool reject_impossible_fixit (location_t where);
void stop_supporting_fixits ();
@@ -1773,17 +1775,17 @@ public:
static const int STATICALLY_ALLOCATED_RANGES = 3;
protected:
- line_maps *m_line_table;
+ line_maps * const m_line_table;
semi_embedded_vec <location_range, STATICALLY_ALLOCATED_RANGES> m_ranges;
int m_column_override;
- bool m_have_expanded_location;
+ mutable bool m_have_expanded_location;
bool m_seen_impossible_fixit;
bool m_fixits_cannot_be_auto_applied;
bool m_escape_on_output;
- expanded_location m_expanded_location;
+ mutable expanded_location m_expanded_location;
static const int MAX_STATIC_FIXIT_HINTS = 2;
semi_embedded_vec <fixit_hint *, MAX_STATIC_FIXIT_HINTS> m_fixit_hints;
@@ -1916,7 +1918,9 @@ class fixit_hint
const char *new_content);
~fixit_hint () { free (m_bytes); }
- bool affects_line_p (const char *file, int line) const;
+ bool affects_line_p (const line_maps *set,
+ const char *file,
+ int line) const;
location_t get_start_loc () const { return m_start; }
location_t get_next_loc () const { return m_next_loc; }
bool maybe_append (location_t start,
@@ -2103,7 +2107,8 @@ enum location_aspect
Hence we require client code of libcpp to implement the following
symbol. */
extern expanded_location
-linemap_client_expand_location_to_spelling_point (location_t,
+linemap_client_expand_location_to_spelling_point (const line_maps *,
+ location_t,
enum location_aspect);
#endif /* !LIBCPP_LINE_MAP_H */
diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc
index cc9e14a..be2d096 100644
--- a/libcpp/line-map.cc
+++ b/libcpp/line-map.cc
@@ -2212,7 +2212,7 @@ rich_location::get_range (unsigned int idx)
location. */
expanded_location
-rich_location::get_expanded_location (unsigned int idx)
+rich_location::get_expanded_location (unsigned int idx) const
{
if (idx == 0)
{
@@ -2221,7 +2221,7 @@ rich_location::get_expanded_location (unsigned int idx)
{
m_expanded_location
= linemap_client_expand_location_to_spelling_point
- (get_loc (0), LOCATION_ASPECT_CARET);
+ (m_line_table, get_loc (0), LOCATION_ASPECT_CARET);
if (m_column_override)
m_expanded_location.column = m_column_override;
m_have_expanded_location = true;
@@ -2231,7 +2231,7 @@ rich_location::get_expanded_location (unsigned int idx)
}
else
return linemap_client_expand_location_to_spelling_point
- (get_loc (idx), LOCATION_ASPECT_CARET);
+ (m_line_table, get_loc (idx), LOCATION_ASPECT_CARET);
}
/* Set the column of the primary location, with 0 meaning
@@ -2490,10 +2490,12 @@ rich_location::maybe_add_fixit (location_t start,
/* Only allow fix-it hints that affect a single line in one file.
Compare the end-points. */
expanded_location exploc_start
- = linemap_client_expand_location_to_spelling_point (start,
+ = linemap_client_expand_location_to_spelling_point (m_line_table,
+ start,
LOCATION_ASPECT_START);
expanded_location exploc_next_loc
- = linemap_client_expand_location_to_spelling_point (next_loc,
+ = linemap_client_expand_location_to_spelling_point (m_line_table,
+ next_loc,
LOCATION_ASPECT_START);
/* They must be within the same file... */
if (exploc_start.file != exploc_next_loc.file)
@@ -2581,17 +2583,21 @@ fixit_hint::fixit_hint (location_t start,
/* Does this fix-it hint affect the given line? */
bool
-fixit_hint::affects_line_p (const char *file, int line) const
+fixit_hint::affects_line_p (const line_maps *set,
+ const char *file,
+ int line) const
{
expanded_location exploc_start
- = linemap_client_expand_location_to_spelling_point (m_start,
+ = linemap_client_expand_location_to_spelling_point (set,
+ m_start,
LOCATION_ASPECT_START);
if (file != exploc_start.file)
return false;
if (line < exploc_start.line)
return false;
expanded_location exploc_next_loc
- = linemap_client_expand_location_to_spelling_point (m_next_loc,
+ = linemap_client_expand_location_to_spelling_point (set,
+ m_next_loc,
LOCATION_ASPECT_START);
if (file != exploc_next_loc.file)
return false;