diff options
author | David Malcolm <dmalcolm@redhat.com> | 2023-11-09 17:22:52 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2023-11-09 17:22:52 -0500 |
commit | 8625aa246696695ef5c20aba847a8f39019ab8d3 (patch) | |
tree | 2f71899f2c5b2e2bbcf0b346e3825bd31ce84886 /libcpp | |
parent | 0c6c9b64545c5ef87df9f025ecb90ed537054caa (diff) | |
download | gcc-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>
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/include/line-map.h | 17 | ||||
-rw-r--r-- | libcpp/line-map.cc | 22 |
2 files changed, 25 insertions, 14 deletions
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; |