From patchwork Tue Jun 14 15:15:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 635326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rTXc12r4Tz9t1X for ; Wed, 15 Jun 2016 00:49:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=esGifbhl; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=GEFVYO8qByY4 yM/kcV6Y6UQEmUW/enZgisqfo38rWBpJq5lWCll0/fFCyg/0MDbUDigGO1Tpr0gg ucnb7SNdKth4ofF3zQqirZYd1EZvygxQ3gNx1zyD4PwrTIaI9v2yEqtsjIcZHrJz yN6olDBvg4XFk9vEaYEJKNWz8hG75Jg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=cdjVATRi5bXE00rhuV 7EKAkhWuE=; b=esGifbhlW+kGrRuombTj3wKNig/nkKF1+Nj4wxA2fjKBJltLOh t2zpWZdlD1wPaIR69Zg9nVO0hbeYYbasXT/qgTXxfYHmtheWK5HLjk8FBqNuN+vI giBbPg8IcJgZpnU85p0+7vAGaiNKgZLxnDG9fRF7aBeoOnXjLgEExdh+A= Received: (qmail 34277 invoked by alias); 14 Jun 2016 14:49:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 34254 invoked by uid 89); 14 Jun 2016 14:49:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:unknown, 60, 3, 42, 9, suggesting 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 14 Jun 2016 14:49:26 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 1E0B563302 for ; Tue, 14 Jun 2016 14:49:25 +0000 (UTC) Received: from c64.redhat.com (vpn-224-197.phx2.redhat.com [10.3.224.197]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5EEnO5K005450; Tue, 14 Jun 2016 10:49:24 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 1/4] Introduce gcc_rich_location::add_fixit_misspelled_id Date: Tue, 14 Jun 2016 11:15:50 -0400 Message-Id: <1465917353-61387-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes There's a fair amount of repetition in the code to emit fixits for misspelled identifiers, and I plan to add more such fixits, so this patch moves it to a helper method. Successfully bootstrapped®rtested in combination with the rest of the kit on x86_64-pc-linux-gnu Successful -fself-test of stage1 on powerpc-ibm-aix7.1.3.0 of just this patch by itself. OK for trunk if it passes individual bootstrap®rtest? gcc/c/ChangeLog: * c-typeck.c (build_component_ref): Simplify fixit code by using gcc_rich_location::add_fixit_misspelled_id. (set_init_label): Likewise. gcc/cp/ChangeLog: * typeck.c: Include "gcc-rich-location.h". (finish_class_member_access_expr): Simplify fixit code by using gcc_rich_location::add_fixit_misspelled_id. gcc/ChangeLog: * gcc-rich-location.c (gcc_rich_location::add_fixit_misspelled_id): New method. * gcc-rich-location.h (gcc_rich_location::add_fixit_misspelled_id): Add decl. --- gcc/c/c-typeck.c | 16 ++++------------ gcc/cp/typeck.c | 10 ++++------ gcc/gcc-rich-location.c | 14 ++++++++++++++ gcc/gcc-rich-location.h | 3 +++ 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index ea04d5e..f987508 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -2371,14 +2371,9 @@ build_component_ref (location_t loc, tree datum, tree component, we have a valid range for the component. */ location_t reported_loc = (component_loc != UNKNOWN_LOCATION) ? component_loc : loc; - rich_location rich_loc (line_table, reported_loc); + gcc_rich_location rich_loc (reported_loc); if (component_loc != UNKNOWN_LOCATION) - { - source_range component_range = - get_range_from_loc (line_table, component_loc); - rich_loc.add_fixit_replace (component_range, - IDENTIFIER_POINTER (guessed_id)); - } + rich_loc.add_fixit_misspelled_id (component_loc, guessed_id); error_at_rich_loc (&rich_loc, "%qT has no member named %qE; did you mean %qE?", @@ -8234,11 +8229,8 @@ set_init_label (location_t loc, tree fieldname, location_t fieldname_loc, tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname); if (guessed_id) { - rich_location rich_loc (line_table, fieldname_loc); - source_range component_range = - get_range_from_loc (line_table, fieldname_loc); - rich_loc.add_fixit_replace (component_range, - IDENTIFIER_POINTER (guessed_id)); + gcc_rich_location rich_loc (fieldname_loc); + rich_loc.add_fixit_misspelled_id (fieldname_loc, guessed_id); error_at_rich_loc (&rich_loc, "%qT has no member named %qE; did you mean %qE?", diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index f68c2a3..2ccd2da 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see #include "c-family/c-objc.h" #include "c-family/c-ubsan.h" #include "params.h" +#include "gcc-rich-location.h" static tree cp_build_addr_expr_strict (tree, tsubst_flags_t); static tree cp_build_function_call (tree, tree, tsubst_flags_t); @@ -2831,12 +2832,9 @@ finish_class_member_access_expr (cp_expr object, tree name, bool template_p, if (guessed_id) { location_t bogus_component_loc = input_location; - rich_location rich_loc (line_table, bogus_component_loc); - source_range bogus_component_range = - get_range_from_loc (line_table, bogus_component_loc); - rich_loc.add_fixit_replace - (bogus_component_range, - IDENTIFIER_POINTER (guessed_id)); + gcc_rich_location rich_loc (bogus_component_loc); + rich_loc.add_fixit_misspelled_id (bogus_component_loc, + guessed_id); error_at_rich_loc (&rich_loc, "%q#T has no member named %qE; did you mean %qE?", diff --git a/gcc/gcc-rich-location.c b/gcc/gcc-rich-location.c index a03ce0e..15c0700 100644 --- a/gcc/gcc-rich-location.c +++ b/gcc/gcc-rich-location.c @@ -60,3 +60,17 @@ gcc_rich_location::maybe_add_expr (tree t) if (EXPR_P (t)) add_expr (t); } + +/* Add a fixit hint suggesting replacing the range at MISSPELLED_TOKEN_LOC + with the identifier HINT_ID. */ + +void +gcc_rich_location::add_fixit_misspelled_id (location_t misspelled_token_loc, + tree hint_id) +{ + gcc_assert (TREE_CODE (hint_id) == IDENTIFIER_NODE); + + source_range misspelled_token_range + = get_range_from_loc (line_table, misspelled_token_loc); + add_fixit_replace (misspelled_token_range, IDENTIFIER_POINTER (hint_id)); +} diff --git a/gcc/gcc-rich-location.h b/gcc/gcc-rich-location.h index fd332de..9c8a790 100644 --- a/gcc/gcc-rich-location.h +++ b/gcc/gcc-rich-location.h @@ -42,6 +42,9 @@ class gcc_rich_location : public rich_location void maybe_add_expr (tree t); + + void add_fixit_misspelled_id (location_t misspelled_token_loc, + tree hint_id); }; #endif /* GCC_RICH_LOCATION_H */