From: David Malcolm Date: Tue, 13 Sep 2016 16:08:59 +0000 (+0000) Subject: fix-it hints: insert_before vs insert_after X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=254830bab29913361ddd47358d3d90b7d4a49f3d;p=gcc.git fix-it hints: insert_before vs insert_after The API for adding "insert text" fix-it hints was unclear about exactly where the text should be inserted relative to the given insertion point. This patch clarifies things by renaming the pertinent methods from richloc.add_fixit_insert to richloc.add_fixit_insert_before and adding: richloc.add_fixit_insert_after The latter allows us to consolidate some failure-handling into class rich_location, rather than having to have every such diagnostic check for it. The patch also adds a description of how fix-it hints work to the comment for class rich_location within libcpp/include/line-map.h. gcc/c-family/ChangeLog: * c-common.c (warn_logical_not_parentheses): Replace rich_location::add_fixit_insert calls with add_fixit_insert_before and add_fixit_insert_after, eliminating the "next_loc" calculation. gcc/c/ChangeLog: * c-parser.c (c_parser_declaration_or_fndef): Update for renaming of add_fixit_insert to add_fixit_insert_before. gcc/cp/ChangeLog: * parser.c (cp_parser_class_specifier_1): Update for renaming of add_fixit_insert to add_fixit_insert_before. (cp_parser_class_head): Likewise. gcc/ChangeLog: * diagnostic-show-locus.c (selftest::test_one_liner_fixit_insert): Rename to... (selftest::test_one_liner_fixit_insert_before): ...this, and update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::test_one_liner_fixit_insert_after): New function. (selftest::test_one_liner_fixit_validation_adhoc_locations): Update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::test_one_liner_many_fixits): Likewise. (selftest::test_diagnostic_show_locus_one_liner): Update for renaming, call new test function. (selftest::test_diagnostic_show_locus_fixit_lines): Update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::test_fixit_consolidation): Likewise. * diagnostic.c (selftest::test_print_parseable_fixits_insert): Likewise. * edit-context.c (selftest::test_applying_fixits_insert): Rename to... (selftest::test_applying_fixits_insert_before): ...this. (selftest::test_applying_fixits_insert): Update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::test_applying_fixits_insert_after): New function. (selftest::test_applying_fixits_insert_after_at_line_end): New function. (selftest::test_applying_fixits_insert_after_failure): New function. (selftest::test_applying_fixits_multiple): Update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::change_line): Likewise. (selftest::test_applying_fixits_unreadable_file): Likewise. (selftest::test_applying_fixits_line_out_of_range): Likewise. (selftest::test_applying_fixits_column_validation): Likewise. (selftest::test_applying_fixits_column_validation): Likewise. (selftest::edit_context_c_tests): Update for renamed test function; call new test functions. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Replace rich_location::add_fixit_insert calls with add_fixit_insert_before and add_fixit_insert_after. libcpp/ChangeLog: * include/line-map.h (class rich_location): Add description of fix-it hints to leading comment. (rich_location::add_fixit_insert): Rename both overloaded methods to.. (rich_location::add_fixit_insert_before): ...this, updating their comments. (rich_location::add_fixit_insert_after): Two new overloaded methods. (rich_location::stop_supporting_fixits): New method. * line-map.c (rich_location::add_fixit_insert): Rename both overloaded methods to.. (rich_location::add_fixit_insert_before): ...this, updating their comments. (rich_location::add_fixit_insert_after): Two new methods. (rich_location::reject_impossible_fixit): Split out failure-handling into... (rich_location::stop_supporting_fixits): New method. From-SVN: r240115 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 58ab8355a75..93c90ce0785 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,41 @@ +2016-09-13 David Malcolm + + * diagnostic-show-locus.c (selftest::test_one_liner_fixit_insert): + Rename to... + (selftest::test_one_liner_fixit_insert_before): ...this, and update + for renaming of add_fixit_insert to add_fixit_insert_before. + (selftest::test_one_liner_fixit_insert_after): New function. + (selftest::test_one_liner_fixit_validation_adhoc_locations): + Update for renaming of add_fixit_insert to + add_fixit_insert_before. + (selftest::test_one_liner_many_fixits): Likewise. + (selftest::test_diagnostic_show_locus_one_liner): Update for + renaming, call new test function. + (selftest::test_diagnostic_show_locus_fixit_lines): Update for + renaming of add_fixit_insert to add_fixit_insert_before. + (selftest::test_fixit_consolidation): Likewise. + * diagnostic.c (selftest::test_print_parseable_fixits_insert): + Likewise. + * edit-context.c (selftest::test_applying_fixits_insert): Rename + to... + (selftest::test_applying_fixits_insert_before): ...this. + (selftest::test_applying_fixits_insert): Update for renaming of + add_fixit_insert to add_fixit_insert_before. + (selftest::test_applying_fixits_insert_after): New function. + (selftest::test_applying_fixits_insert_after_at_line_end): New + function. + (selftest::test_applying_fixits_insert_after_failure): New + function. + (selftest::test_applying_fixits_multiple): Update for renaming of + add_fixit_insert to add_fixit_insert_before. + (selftest::change_line): Likewise. + (selftest::test_applying_fixits_unreadable_file): Likewise. + (selftest::test_applying_fixits_line_out_of_range): Likewise. + (selftest::test_applying_fixits_column_validation): Likewise. + (selftest::test_applying_fixits_column_validation): Likewise. + (selftest::edit_context_c_tests): Update for renamed test + function; call new test functions. + 2016-09-13 Pat Haugen PR tree-optimization/77536 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index d8f1808e699..5a2cbbef416 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2016-09-13 David Malcolm + + * c-common.c (warn_logical_not_parentheses): Replace + rich_location::add_fixit_insert calls with add_fixit_insert_before + and add_fixit_insert_after, eliminating the "next_loc" calculation. + 2016-09-13 Jason Merrill Tom de Vries diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 73bd43f8703..1132a031384 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -1544,11 +1544,8 @@ warn_logical_not_parentheses (location_t location, enum tree_code code, { location_t lhs_loc = EXPR_LOCATION (lhs); rich_location richloc (line_table, lhs_loc); - richloc.add_fixit_insert (lhs_loc, "("); - location_t finish = get_finish (lhs_loc); - location_t next_loc - = linemap_position_for_loc_and_offset (line_table, finish, 1); - richloc.add_fixit_insert (next_loc, ")"); + richloc.add_fixit_insert_before (lhs_loc, "("); + richloc.add_fixit_insert_after (lhs_loc, ")"); inform_at_rich_loc (&richloc, "add parentheses around left hand side " "expression to silence this warning"); } diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index c8563749939..4a9881d351a 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2016-09-13 David Malcolm + + * c-parser.c (c_parser_declaration_or_fndef): Update for renaming + of add_fixit_insert to add_fixit_insert_before. + 2016-09-13 Marek Polacek * c-typeck.c (build_unary_op): Rename FLAG parameter to NOCONVERT. Use diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index a3044244f6c..e71c0d5b9b5 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1685,7 +1685,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, if (tag_exists_p (RECORD_TYPE, name)) { /* This is not C++ with its implicit typedef. */ - richloc.add_fixit_insert ("struct "); + richloc.add_fixit_insert_before ("struct "); error_at_rich_loc (&richloc, "unknown type name %qE;" " use % keyword to refer to the type", @@ -1693,7 +1693,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, } else if (tag_exists_p (UNION_TYPE, name)) { - richloc.add_fixit_insert ("union "); + richloc.add_fixit_insert_before ("union "); error_at_rich_loc (&richloc, "unknown type name %qE;" " use % keyword to refer to the type", @@ -1701,7 +1701,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, } else if (tag_exists_p (ENUMERAL_TYPE, name)) { - richloc.add_fixit_insert ("enum "); + richloc.add_fixit_insert_before ("enum "); error_at_rich_loc (&richloc, "unknown type name %qE;" " use % keyword to refer to the type", diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f572c851b62..79691bf6892 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-09-13 David Malcolm + + * parser.c (cp_parser_class_specifier_1): Update for renaming of + add_fixit_insert to add_fixit_insert_before. + (cp_parser_class_head): Likewise. + 2016-09-12 Bernd Edlinger PR c++/77496 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ca9f8b9761a..73a37814b59 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -21594,7 +21594,7 @@ cp_parser_class_specifier_1 (cp_parser* parser) next_loc = linemap_position_for_loc_and_offset (line_table, loc, 1); rich_location richloc (line_table, next_loc); - richloc.add_fixit_insert (next_loc, ";"); + richloc.add_fixit_insert_before (next_loc, ";"); if (CLASSTYPE_DECLARED_CLASS (type)) error_at_rich_loc (&richloc, @@ -22037,7 +22037,8 @@ cp_parser_class_head (cp_parser* parser, class_head_start_location, get_finish (type_start_token->location)); rich_location richloc (line_table, reported_loc); - richloc.add_fixit_insert (class_head_start_location, "template <> "); + richloc.add_fixit_insert_before (class_head_start_location, + "template <> "); error_at_rich_loc (&richloc, "an explicit specialization must be preceded by %