Mercurial > hg > CbC > CbC_gcc
diff gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
line wrap: on
line diff
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c Fri Oct 27 22:46:09 2017 +0900 +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c Thu Oct 25 07:37:49 2018 +0900 @@ -60,6 +60,7 @@ #include "diagnostic.h" #include "context.h" #include "print-tree.h" +#include "gcc-rich-location.h" int plugin_is_GPL_compatible; @@ -144,9 +145,12 @@ static void add_range (rich_location *richloc, location_t start, location_t finish, - bool show_caret_p) + enum range_display_kind range_display_kind + = SHOW_RANGE_WITHOUT_CARET, + const range_label *label = NULL) { - richloc->add_range (make_location (start, start, finish), show_caret_p); + richloc->add_range (make_location (start, start, finish), range_display_kind, + label); } /* Exercise the diagnostic machinery to emit various warnings, @@ -174,38 +178,42 @@ { const int line = fnstart_line + 2; rich_location richloc (line_table, get_loc (line, 15)); - add_range (&richloc, get_loc (line, 10), get_loc (line, 14), false); - add_range (&richloc, get_loc (line, 16), get_loc (line, 16), false); - warning_at_rich_loc (&richloc, 0, "test"); + add_range (&richloc, get_loc (line, 10), get_loc (line, 14)); + add_range (&richloc, get_loc (line, 16), get_loc (line, 16)); + warning_at (&richloc, 0, "test"); } if (0 == strcmp (fnname, "test_simple_2")) { const int line = fnstart_line + 2; rich_location richloc (line_table, get_loc (line, 24)); - add_range (&richloc, get_loc (line, 6), get_loc (line, 22), false); - add_range (&richloc, get_loc (line, 26), get_loc (line, 43), false); - warning_at_rich_loc (&richloc, 0, "test"); + add_range (&richloc, get_loc (line, 6), get_loc (line, 22)); + add_range (&richloc, get_loc (line, 26), get_loc (line, 43)); + warning_at (&richloc, 0, "test"); } if (0 == strcmp (fnname, "test_multiline")) { const int line = fnstart_line + 2; - rich_location richloc (line_table, get_loc (line + 1, 7)); - add_range (&richloc, get_loc (line, 7), get_loc (line, 23), false); - add_range (&richloc, get_loc (line + 1, 9), get_loc (line + 1, 26), - false); - warning_at_rich_loc (&richloc, 0, "test"); + text_range_label label ("label"); + rich_location richloc (line_table, get_loc (line + 1, 7), &label); + add_range (&richloc, get_loc (line, 7), get_loc (line, 23)); + add_range (&richloc, get_loc (line + 1, 9), get_loc (line + 1, 26)); + warning_at (&richloc, 0, "test"); } if (0 == strcmp (fnname, "test_many_lines")) { const int line = fnstart_line + 2; - rich_location richloc (line_table, get_loc (line + 5, 7)); - add_range (&richloc, get_loc (line, 7), get_loc (line + 4, 65), false); + text_range_label label0 ("label 0"); + text_range_label label1 ("label 1"); + text_range_label label2 ("label 2"); + rich_location richloc (line_table, get_loc (line + 5, 7), &label0); + add_range (&richloc, get_loc (line, 7), get_loc (line + 4, 65), + SHOW_RANGE_WITHOUT_CARET, &label1); add_range (&richloc, get_loc (line + 5, 9), get_loc (line + 10, 61), - false); - warning_at_rich_loc (&richloc, 0, "test"); + SHOW_RANGE_WITHOUT_CARET, &label2); + warning_at (&richloc, 0, "test"); } /* Example of a rich_location where the range is larger than @@ -216,7 +224,7 @@ location_t start = get_loc (line, 12); location_t finish = get_loc (line, 16); rich_location richloc (line_table, make_location (start, start, finish)); - warning_at_rich_loc (&richloc, 0, "test"); + warning_at (&richloc, 0, "test"); } /* Example of a single-range location where the range starts @@ -230,14 +238,43 @@ } /* Example of a very wide line, where the information of interest - is beyond the width of the terminal (hardcoded above). */ + is beyond the width of the terminal (hardcoded above), with + a secondary location that exactly fits on the left-margin. */ if (0 == strcmp (fnname, "test_very_wide_line")) { const int line = fnstart_line + 2; global_dc->show_ruler_p = true; - warning_at (make_location (get_loc (line, 94), get_loc (line, 90), - get_loc (line, 98)), - 0, "test"); + text_range_label label0 ("label 0"); + text_range_label label1 ("label 1"); + rich_location richloc (line_table, + make_location (get_loc (line, 94), + get_loc (line, 90), + get_loc (line, 98)), + &label0); + richloc.add_range (get_loc (line, 35), SHOW_RANGE_WITHOUT_CARET, + &label1); + richloc.add_fixit_replace ("bar * foo"); + warning_at (&richloc, 0, "test"); + global_dc->show_ruler_p = false; + } + + /* Likewise, but with a secondary location that's immediately before + the left margin; the location and label should be gracefully dropped. */ + if (0 == strcmp (fnname, "test_very_wide_line_2")) + { + const int line = fnstart_line + 2; + global_dc->show_ruler_p = true; + text_range_label label0 ("label 0"); + text_range_label label1 ("label 1"); + rich_location richloc (line_table, + make_location (get_loc (line, 94), + get_loc (line, 90), + get_loc (line, 98)), + &label0); + richloc.add_fixit_replace ("bar * foo"); + richloc.add_range (get_loc (line, 34), SHOW_RANGE_WITHOUT_CARET, + &label1); + warning_at (&richloc, 0, "test"); global_dc->show_ruler_p = false; } @@ -248,10 +285,10 @@ location_t caret_a = get_loc (line, 7); location_t caret_b = get_loc (line, 11); rich_location richloc (line_table, caret_a); - add_range (&richloc, caret_b, caret_b, true); + add_range (&richloc, caret_b, caret_b, SHOW_RANGE_WITH_CARET); global_dc->caret_chars[0] = 'A'; global_dc->caret_chars[1] = 'B'; - warning_at_rich_loc (&richloc, 0, "test"); + warning_at (&richloc, 0, "test"); global_dc->caret_chars[0] = '^'; global_dc->caret_chars[1] = '^'; } @@ -265,7 +302,7 @@ rich_location richloc (line_table, make_location (start, start, finish)); richloc.add_fixit_insert_before ("{"); richloc.add_fixit_insert_after ("}"); - warning_at_rich_loc (&richloc, 0, "example of insertion hints"); + warning_at (&richloc, 0, "example of insertion hints"); } if (0 == strcmp (fnname, "test_fixit_insert_newline")) @@ -277,7 +314,7 @@ location_t case_loc = make_location (case_start, case_start, case_finish); rich_location richloc (line_table, case_loc); richloc.add_fixit_insert_before (line_start, " break;\n"); - warning_at_rich_loc (&richloc, 0, "example of newline insertion hint"); + warning_at (&richloc, 0, "example of newline insertion hint"); } if (0 == strcmp (fnname, "test_fixit_remove")) @@ -290,7 +327,7 @@ src_range.m_start = start; src_range.m_finish = finish; richloc.add_fixit_remove (src_range); - warning_at_rich_loc (&richloc, 0, "example of a removal hint"); + warning_at (&richloc, 0, "example of a removal hint"); } if (0 == strcmp (fnname, "test_fixit_replace")) @@ -303,7 +340,7 @@ src_range.m_start = start; src_range.m_finish = finish; richloc.add_fixit_replace (src_range, "gtk_widget_show_all"); - warning_at_rich_loc (&richloc, 0, "example of a replacement hint"); + warning_at (&richloc, 0, "example of a replacement hint"); } if (0 == strcmp (fnname, "test_mutually_exclusive_suggestions")) @@ -319,17 +356,40 @@ rich_location richloc (line_table, make_location (start, start, finish)); richloc.add_fixit_replace (src_range, "replacement_1"); richloc.fixits_cannot_be_auto_applied (); - warning_at_rich_loc (&richloc, 0, "warning 1"); + warning_at (&richloc, 0, "warning 1"); } { rich_location richloc (line_table, make_location (start, start, finish)); richloc.add_fixit_replace (src_range, "replacement_2"); richloc.fixits_cannot_be_auto_applied (); - warning_at_rich_loc (&richloc, 0, "warning 2"); + warning_at (&richloc, 0, "warning 2"); } } + /* Tests of gcc_rich_location::add_fixit_insert_formatted. */ + + if (0 == strcmp (fnname, "test_add_fixit_insert_formatted_single_line")) + { + const int line = fnstart_line + 1; + location_t insertion_point = get_loc (line, 3); + location_t indent = get_loc (line, 2); + gcc_rich_location richloc (insertion_point); + richloc.add_fixit_insert_formatted ("INSERTED-CONTENT", + insertion_point, indent); + inform (&richloc, "single-line insertion"); + } + + if (0 == strcmp (fnname, "test_add_fixit_insert_formatted_multiline")) + { + location_t insertion_point = fun->function_end_locus; + location_t indent = get_loc (fnstart_line + 1, 2); + gcc_rich_location richloc (insertion_point); + richloc.add_fixit_insert_formatted ("INSERTED-CONTENT", + insertion_point, indent); + inform (&richloc, "multiline insertion"); + } + /* Example of two carets where both carets appear to have an off-by-one error appearing one column early. Seen with gfortran.dg/associate_5.f03. @@ -343,10 +403,10 @@ location_t caret_a = get_loc (line, 5); location_t caret_b = get_loc (line - 1, 19); rich_location richloc (line_table, caret_a); - richloc.add_range (caret_b, true); + richloc.add_range (caret_b, SHOW_RANGE_WITH_CARET); global_dc->caret_chars[0] = '1'; global_dc->caret_chars[1] = '2'; - warning_at_rich_loc (&richloc, 0, "test"); + warning_at (&richloc, 0, "test"); global_dc->caret_chars[0] = '^'; global_dc->caret_chars[1] = '^'; } @@ -364,40 +424,39 @@ /* Example of many locations and many fixits. Underline (separately) every word in a comment, and convert them - to upper case. */ + to upper case. Give all of the ranges labels (sharing one label). */ if (0 == strcmp (fnname, "test_many_nested_locations")) { const char *file = LOCATION_FILE (fnstart); const int start_line = fnstart_line + 2; const int finish_line = start_line + 7; location_t loc = get_loc (start_line - 1, 2); + text_range_label label ("label"); rich_location richloc (line_table, loc); for (int line = start_line; line <= finish_line; line++) { - int line_size; - const char *content = location_get_source_line (file, line, - &line_size); + char_span content = location_get_source_line (file, line); gcc_assert (content); /* Split line up into words. */ - for (int idx = 0; idx < line_size; idx++) + for (int idx = 0; idx < content.length (); idx++) { if (ISALPHA (content[idx])) { int start_idx = idx; - while (idx < line_size && ISALPHA (content[idx])) + while (idx < content.length () && ISALPHA (content[idx])) idx++; - if (idx == line_size || !ISALPHA (content[idx])) + if (idx == content.length () || !ISALPHA (content[idx])) { location_t start_of_word = get_loc (line, start_idx); location_t end_of_word = get_loc (line, idx - 1); location_t word = make_location (start_of_word, start_of_word, end_of_word); - richloc.add_range (word, true); + richloc.add_range (word, SHOW_RANGE_WITH_CARET, &label); /* Add a fixit, converting to upper case. */ - char *copy = xstrndup (content + start_idx, - idx - start_idx); + char_span word_span = content.subspan (start_idx, idx - start_idx); + char *copy = word_span.xstrdup (); for (char *ch = copy; *ch; ch++) *ch = TOUPPER (*ch); richloc.add_fixit_replace (word, copy); @@ -411,8 +470,8 @@ statically-allocated buffer in class rich_location, and then trigger a reallocation of the dynamic buffer. */ gcc_assert (richloc.get_num_locations () > 3 + (2 * 16)); - warning_at_rich_loc (&richloc, 0, "test of %i locations", - richloc.get_num_locations ()); + warning_at (&richloc, 0, "test of %i locations", + richloc.get_num_locations ()); } }