-
- Downloads
Use char_span for return type of location_get_source_line
location_get_source_line returns a const char * that isn't 0-terminated, writing back a length through an int * param. This is error-prone, as all call-sites have to take into account the lack of 0-termination, and respect the length of the buffer. It's cleaner to bundle together this pointer+length state into a class, so this patch does so, reusing the "char_span" class that I introduced in r250187 (as part of the fix for PR c/81405). The patch also adds assertions to all access to the char_span. gcc/c-family/ChangeLog: * c-format.c (get_corrected_substring): Update for location_get_source_line returning a char_span. Use a char_span when handling the prefix of the correction. * c-indentation.c (get_visual_column): Update for location_get_source_line returning a char_span. (get_first_nws_vis_column): Likewise. gcc/ChangeLog: * diagnostic-show-locus.c (layout::layout): Update for location_get_source_line returning a char_span. (struct char_span): Move to input.h. (struct correction): Update for fields in char_span becoming private. (struct source_line): Update for location_get_source_line returning a char_span. (layout::print_line): Likewise. * edit-context.c (edited_file::print_content): Likewise. (edited_file::print_diff_hunk): Likewise. (edited_file::print_run_of_changed_lines): Likewise. (edited_file::get_num_lines): Likewise. (edited_line::edited_line): Likewise. * final.c (asm_show_source): Likewise. * input.c (location_get_source_line): Convert return type from const char * to char_span, losing the final "line_len" param. (dump_location_info): Update for the above. (get_substring_ranges_for_loc): Likewise. Use a char_span when handling the literal within the line. (test_reading_source_line): Update for location_get_source_line returning a char_span. * input.h (class char_span): Move here from diagnostic-show-locus.c, converting from a struct to a class. Make data members private. (char_span::operator bool): New. (char_span::length): New. (char_span::get_buffer): New. (char_span::operator[]): New. (char_span::subspan): Make const. (char_span::xstrdup): New. (location_get_source_line): Convert return type from const char * to char_span, losing the final "line_size" param. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Update for location_get_source_line returning a char_span. Use char_span for handling words in the "test_many_nested_locations" fix-it example. From-SVN: r259768
Showing
- gcc/ChangeLog 36 additions, 0 deletionsgcc/ChangeLog
- gcc/c-family/ChangeLog 9 additions, 0 deletionsgcc/c-family/ChangeLog
- gcc/c-family/c-format.c 4 additions, 6 deletionsgcc/c-family/c-format.c
- gcc/c-family/c-indentation.c 3 additions, 6 deletionsgcc/c-family/c-indentation.c
- gcc/diagnostic-show-locus.c 15 additions, 37 deletionsgcc/diagnostic-show-locus.c
- gcc/edit-context.c 12 additions, 19 deletionsgcc/edit-context.c
- gcc/final.c 3 additions, 4 deletionsgcc/final.c
- gcc/input.c 35 additions, 41 deletionsgcc/input.c
- gcc/input.h 46 additions, 2 deletionsgcc/input.h
- gcc/testsuite/ChangeLog 7 additions, 0 deletionsgcc/testsuite/ChangeLog
- gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c 6 additions, 8 deletions...stsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
Loading
Please register or sign in to comment