Re: [PATCH v4 6/8] diagnostics: Full support for generated data locations

2023-08-15 Thread David Malcolm via Gcc-patches
On Wed, 2023-08-09 at 18:14 -0400, Lewis Hyatt wrote:
> Previous patches in this series have laid the groundwork for supporting
> source code locations in memory ("generated data") rather than ordinary
> files. This patch completes the support by adding awareness of such
> locations to all places that need to support them. The main changes are to
> diagnostic-show-locus.cc; the others are primarily small tweaks such as
> changing from the FILE to the SRC member when inspecting an
> expanded_location.
> 
> gcc/c-family/ChangeLog:
> 
> * c-format.cc (get_corrected_substring): Use the new overload of
> location_get_source_line() to support generated data.
> * c-indentation.cc (get_visual_column): Likewise.
> (get_first_nws_vis_column): Change argument from a plain file name
> to a source_id.
> (detect_intervening_unindent): Likewise.
> (should_warn_for_misleading_indentation): Pass
> detect_intervening_unindent() the SRC field rather than the FILE
> field from the expanded_location.
> 
> gcc/ChangeLog:
> 
> * gcc-rich-location.cc (blank_line_before_p): Use the new overload
> of location_get_source_line() to support generated data.
> * input.cc (get_source_text_between): Likewise.
> (get_substring_ranges_for_loc): Likewise.
> (get_source_file_content): Change the argument from a plain filename
> to a source_id.
> (location_missing_trailing_newline): Likewise.
> * input.h (get_source_file_content): Adjust prototype.
> (location_missing_trailing_newline): Likewise.
> * diagnostic-show-locus.cc (layout::calculate_x_offset_display): Use
> the new overload of location_get_source_line() to support generated
> data.
> (layout::print_line): Likewise.
> (class line_corrections): Change m_filename from a plain filename to
> a source_id.
> (source_line::source_line): Change argument from a plain filename to
> a source_id.
> (line_corrections::add_hint): Adapt to source_line change.
> (layout::print_trailing_fixits): Adapt to line_corrections change.
> (test_layout_x_offset_display_utf8): Test generated data too.
> (test_layout_x_offset_display_tab): Likewise.
> (test_diagnostic_show_locus_one_liner): Likewise.
> (test_diagnostic_show_locus_one_liner_utf8): Likewise.
> (test_add_location_if_nearby): Likewise.
> (test_diagnostic_show_locus_fixit_lines): Likewise.
> (test_fixit_consolidation): Likewise.
> (test_overlapped_fixit_printing): Likewise.
> (test_overlapped_fixit_printing_utf8): Likewise.
> (test_overlapped_fixit_printing_2): Likewise.
> (test_fixit_insert_containing_newline): Likewise.
> (test_fixit_insert_containing_newline_2): Likewise.
> (test_fixit_replace_containing_newline): Likewise.
> (test_fixit_deletion_affecting_newline): Likewise.
> (test_tab_expansion): Likewise.
> (test_escaping_bytes_1): Likewise.
> (test_escaping_bytes_2): Likewise.
> (test_line_numbers_multiline_range): Likewise.
> (diagnostic_show_locus_cc_tests): Likewise.
> ---
>  gcc/c-family/c-format.cc  |   2 +-
>  gcc/c-family/c-indentation.cc |   8 +-
>  gcc/diagnostic-show-locus.cc  | 227 ++
>  gcc/gcc-rich-location.cc  |   2 +-
>  gcc/input.cc  |  21 ++--
>  gcc/input.h   |   6 +-
>  6 files changed, 136 insertions(+), 130 deletions(-)
> 

Looks OK for trunk as-is (assuming prerequisites, of course), but as I
think you noted elsewhere this probably needs revising if we're going
to reject applying fix-it-hints to locations in generated data buffers.

Thanks
Dave


[PATCH v4 6/8] diagnostics: Full support for generated data locations

2023-08-09 Thread Lewis Hyatt via Gcc-patches
Previous patches in this series have laid the groundwork for supporting
source code locations in memory ("generated data") rather than ordinary
files. This patch completes the support by adding awareness of such
locations to all places that need to support them. The main changes are to
diagnostic-show-locus.cc; the others are primarily small tweaks such as
changing from the FILE to the SRC member when inspecting an
expanded_location.

gcc/c-family/ChangeLog:

* c-format.cc (get_corrected_substring): Use the new overload of
location_get_source_line() to support generated data.
* c-indentation.cc (get_visual_column): Likewise.
(get_first_nws_vis_column): Change argument from a plain file name
to a source_id.
(detect_intervening_unindent): Likewise.
(should_warn_for_misleading_indentation): Pass
detect_intervening_unindent() the SRC field rather than the FILE
field from the expanded_location.

gcc/ChangeLog:

* gcc-rich-location.cc (blank_line_before_p): Use the new overload
of location_get_source_line() to support generated data.
* input.cc (get_source_text_between): Likewise.
(get_substring_ranges_for_loc): Likewise.
(get_source_file_content): Change the argument from a plain filename
to a source_id.
(location_missing_trailing_newline): Likewise.
* input.h (get_source_file_content): Adjust prototype.
(location_missing_trailing_newline): Likewise.
* diagnostic-show-locus.cc (layout::calculate_x_offset_display): Use
the new overload of location_get_source_line() to support generated
data.
(layout::print_line): Likewise.
(class line_corrections): Change m_filename from a plain filename to
a source_id.
(source_line::source_line): Change argument from a plain filename to
a source_id.
(line_corrections::add_hint): Adapt to source_line change.
(layout::print_trailing_fixits): Adapt to line_corrections change.
(test_layout_x_offset_display_utf8): Test generated data too.
(test_layout_x_offset_display_tab): Likewise.
(test_diagnostic_show_locus_one_liner): Likewise.
(test_diagnostic_show_locus_one_liner_utf8): Likewise.
(test_add_location_if_nearby): Likewise.
(test_diagnostic_show_locus_fixit_lines): Likewise.
(test_fixit_consolidation): Likewise.
(test_overlapped_fixit_printing): Likewise.
(test_overlapped_fixit_printing_utf8): Likewise.
(test_overlapped_fixit_printing_2): Likewise.
(test_fixit_insert_containing_newline): Likewise.
(test_fixit_insert_containing_newline_2): Likewise.
(test_fixit_replace_containing_newline): Likewise.
(test_fixit_deletion_affecting_newline): Likewise.
(test_tab_expansion): Likewise.
(test_escaping_bytes_1): Likewise.
(test_escaping_bytes_2): Likewise.
(test_line_numbers_multiline_range): Likewise.
(diagnostic_show_locus_cc_tests): Likewise.
---
 gcc/c-family/c-format.cc  |   2 +-
 gcc/c-family/c-indentation.cc |   8 +-
 gcc/diagnostic-show-locus.cc  | 227 ++
 gcc/gcc-rich-location.cc  |   2 +-
 gcc/input.cc  |  21 ++--
 gcc/input.h   |   6 +-
 6 files changed, 136 insertions(+), 130 deletions(-)

diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 529b1408179..929ec24622c 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -4537,7 +4537,7 @@ get_corrected_substring (const substring_loc _loc,
   if (caret.column > finish.column)
 return NULL;
 
-  char_span line = location_get_source_line (start.file, start.line);
+  char_span line = location_get_source_line (start);
   if (!line)
 return NULL;
 
diff --git a/gcc/c-family/c-indentation.cc b/gcc/c-family/c-indentation.cc
index fce74991aae..27a90d9cc15 100644
--- a/gcc/c-family/c-indentation.cc
+++ b/gcc/c-family/c-indentation.cc
@@ -50,7 +50,7 @@ get_visual_column (expanded_location exploc,
   unsigned int *first_nws,
   unsigned int tab_width)
 {
-  char_span line = location_get_source_line (exploc.file, exploc.line);
+  char_span line = location_get_source_line (exploc);
   if (!line)
 return false;
   if ((size_t)exploc.column > line.length ())
@@ -87,7 +87,7 @@ get_visual_column (expanded_location exploc,
Otherwise, return false, leaving *FIRST_NWS untouched.  */
 
 static bool
-get_first_nws_vis_column (const char *file, int line_num,
+get_first_nws_vis_column (source_id file, int line_num,
  unsigned int *first_nws,
  unsigned int tab_width)
 {
@@ -158,7 +158,7 @@ get_first_nws_vis_column (const char *file, int line_num,
Return true if such an unindent/outdent is detected.  */
 
 static bool
-detect_intervening_unindent (const char *file,