From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67195 invoked by alias); 30 Jun 2016 18:26:50 -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 67178 invoked by uid 89); 30 Jun 2016 18:26:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Thu, 30 Jun 2016 18:26:47 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 9F8D4BBD4 for ; Thu, 30 Jun 2016 18:26:46 +0000 (UTC) Received: from c64.redhat.com (vpn-239-46.phx2.redhat.com [10.3.239.46]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5UIQjMp026962; Thu, 30 Jun 2016 14:26:46 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 1/2] C: convert return type of lookup_name_fuzzy from tree to const char * Date: Thu, 30 Jun 2016 18:27:00 -0000 Message-Id: <1467312830-36082-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg02089.txt.bz2 The followup patch implements lookup_name_fuzzy for the C++ frontend. It's cleaner for that implementation to return a const char *, so this patch updates the implementation in the C frontend to have the same return type. Successfully bootstrapped®rtested on x86_64-pc-linux-gnu (in combination with the followup patch). OK for trunk? gcc/c-family/ChangeLog: * c-common.h (lookup_name_fuzzy): Convert return type from tree to const char *. gcc/c/ChangeLog: * c-decl.c (implicit_decl_warning): Update for conversion of return type of lookup_name_fuzzy to const char *. (undeclared_variable): Likewise. (lookup_name_fuzzy): Convert return type from tree to const char *. * c-parser.c (c_parser_declaration_or_fndef): Update for conversion of return type of lookup_name_fuzzy to const char *. (c_parser_parameter_declaration): Likewise. gcc/ChangeLog: * gcc-rich-location.c (gcc_rich_location::add_fixit_misspelled_id): New overload, taking a const char *. * gcc-rich-location.h (gcc_rich_location::add_fixit_misspelled_id): Likewise. --- gcc/c-family/c-common.h | 2 +- gcc/c/c-decl.c | 22 +++++++++++++--------- gcc/c/c-parser.c | 10 +++++----- gcc/gcc-rich-location.c | 13 +++++++++++++ gcc/gcc-rich-location.h | 2 ++ 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 3ad5400..44d98d1 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -997,7 +997,7 @@ enum lookup_name_fuzzy_kind { /* Any name. */ FUZZY_LOOKUP_NAME }; -extern tree lookup_name_fuzzy (tree, enum lookup_name_fuzzy_kind); +extern const char *lookup_name_fuzzy (tree, enum lookup_name_fuzzy_kind); extern bool vector_targets_convertible_p (const_tree t1, const_tree t2); extern bool vector_types_convertible_p (const_tree t1, const_tree t2, bool emit_lax_note); diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 8b966fe..09f7f79 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -3088,7 +3088,7 @@ implicit_decl_warning (location_t loc, tree id, tree olddecl) if (warn_implicit_function_declaration) { bool warned; - tree hint = NULL_TREE; + const char *hint = NULL; if (!olddecl) hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME); @@ -3099,7 +3099,7 @@ implicit_decl_warning (location_t loc, tree id, tree olddecl) richloc.add_fixit_misspelled_id (loc, hint); warned = pedwarn_at_rich_loc (&richloc, OPT_Wimplicit_function_declaration, - "implicit declaration of function %qE; did you mean %qE?", + "implicit declaration of function %qE; did you mean %qs?", id, hint); } else @@ -3112,7 +3112,7 @@ implicit_decl_warning (location_t loc, tree id, tree olddecl) richloc.add_fixit_misspelled_id (loc, hint); warned = warning_at_rich_loc (&richloc, OPT_Wimplicit_function_declaration, - G_("implicit declaration of function %qE;did you mean %qE?"), + G_("implicit declaration of function %qE;did you mean %qs?"), id, hint); } else @@ -3433,14 +3433,14 @@ undeclared_variable (location_t loc, tree id) if (current_function_decl == 0) { - tree guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME); + const char *guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME); if (guessed_id) { gcc_rich_location richloc (loc); richloc.add_fixit_misspelled_id (loc, guessed_id); error_at_rich_loc (&richloc, "%qE undeclared here (not in a function);" - " did you mean %qE?", + " did you mean %qs?", id, guessed_id); } else @@ -3451,7 +3451,7 @@ undeclared_variable (location_t loc, tree id) { if (!objc_diagnose_private_ivar (id)) { - tree guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME); + const char *guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME); if (guessed_id) { gcc_rich_location richloc (loc); @@ -3459,7 +3459,7 @@ undeclared_variable (location_t loc, tree id) error_at_rich_loc (&richloc, "%qE undeclared (first use in this function);" - " did you mean %qE?", + " did you mean %qs?", id, guessed_id); } else @@ -4010,7 +4010,7 @@ find_closest_macro_cpp_cb (cpp_reader *, cpp_hashnode *hashnode, It also looks for start_typename keywords, to detect "singed" vs "signed" typos. */ -tree +const char * lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind) { gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE); @@ -4079,7 +4079,11 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind) } } - return bm.get_best_meaningful_candidate (); + tree best = bm.get_best_meaningful_candidate (); + if (best) + return IDENTIFIER_POINTER (best); + else + return NULL; } diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 7f491f1..0451120 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1695,12 +1695,12 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, } else { - tree hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME); + const char *hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME); if (hint) { richloc.add_fixit_misspelled_id (here, hint); error_at_rich_loc (&richloc, - "unknown type name %qE; did you mean %qE?", + "unknown type name %qE; did you mean %qs?", name, hint); } else @@ -3850,14 +3850,14 @@ c_parser_parameter_declaration (c_parser *parser, tree attrs) c_parser_set_source_position_from_token (token); if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) { - tree hint = lookup_name_fuzzy (token->value, FUZZY_LOOKUP_TYPENAME); + const char *hint = lookup_name_fuzzy (token->value, + FUZZY_LOOKUP_TYPENAME); if (hint) { - gcc_assert (TREE_CODE (hint) == IDENTIFIER_NODE); gcc_rich_location richloc (token->location); richloc.add_fixit_misspelled_id (token->location, hint); error_at_rich_loc (&richloc, - "unknown type name %qE; did you mean %qE?", + "unknown type name %qE; did you mean %qs?", token->value, hint); } else diff --git a/gcc/gcc-rich-location.c b/gcc/gcc-rich-location.c index 15c0700..09475ff 100644 --- a/gcc/gcc-rich-location.c +++ b/gcc/gcc-rich-location.c @@ -74,3 +74,16 @@ gcc_rich_location::add_fixit_misspelled_id (location_t misspelled_token_loc, = get_range_from_loc (line_table, misspelled_token_loc); add_fixit_replace (misspelled_token_range, IDENTIFIER_POINTER (hint_id)); } + +/* As above, but with a const char * for the suggested replacement. */ + +void +gcc_rich_location::add_fixit_misspelled_id (location_t misspelled_token_loc, + const char *hint) +{ + gcc_assert (hint); + + source_range misspelled_token_range + = get_range_from_loc (line_table, misspelled_token_loc); + add_fixit_replace (misspelled_token_range, hint); +} diff --git a/gcc/gcc-rich-location.h b/gcc/gcc-rich-location.h index 9c8a790..aa69b2e 100644 --- a/gcc/gcc-rich-location.h +++ b/gcc/gcc-rich-location.h @@ -45,6 +45,8 @@ class gcc_rich_location : public rich_location void add_fixit_misspelled_id (location_t misspelled_token_loc, tree hint_id); + void add_fixit_misspelled_id (location_t misspelled_token_loc, + const char *hint); }; #endif /* GCC_RICH_LOCATION_H */ -- 1.8.5.3