From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 98421 invoked by alias); 13 Sep 2016 16:10:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 98385 invoked by uid 89); 13 Sep 2016 16:10:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=tempfile, c10, Rich, Col X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Sep 2016 16:10:38 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF69813D15 for ; Tue, 13 Sep 2016 16:10:36 +0000 (UTC) Received: from c64.redhat.com (vpn-232-19.phx2.redhat.com [10.3.232.19]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8DGAaWt008433; Tue, 13 Sep 2016 12:10:36 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] fix-it hints: insert_before vs insert_after Date: Tue, 13 Sep 2016 16:15:00 -0000 Message-Id: <1473784827-20540-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2016-09/txt/msg00751.txt.bz2 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. Successfully bootstrapped®rtested on x86_64-pc-linux-gnu. Committed to trunk as r240115. 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. --- gcc/c-family/c-common.c | 7 +- gcc/c/c-parser.c | 6 +- gcc/cp/parser.c | 5 +- gcc/diagnostic-show-locus.c | 42 ++++-- gcc/diagnostic.c | 2 +- gcc/edit-context.c | 163 +++++++++++++++++++-- .../plugin/diagnostic_plugin_test_show_locus.c | 4 +- libcpp/include/line-map.h | 101 ++++++++++++- libcpp/line-map.c | 65 ++++++-- 9 files changed, 342 insertions(+), 53 deletions(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 399ba97..328e5f6 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -1507,11 +1507,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/c-parser.c b/gcc/c/c-parser.c index 0aba51c..5248d7d 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/parser.c b/gcc/cp/parser.c index ca9f8b9..73a3781 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 %