From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 121567 invoked by alias); 1 Dec 2015 17:51:58 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 121408 invoked by uid 89); 1 Dec 2015 17:51:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-ig0-f180.google.com Received: from mail-ig0-f180.google.com (HELO mail-ig0-f180.google.com) (209.85.213.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 01 Dec 2015 17:51:54 +0000 Received: by igcmv3 with SMTP id mv3so99576409igc.0; Tue, 01 Dec 2015 09:51:52 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.50.6.42 with SMTP id x10mr28882810igx.14.1448992312654; Tue, 01 Dec 2015 09:51:52 -0800 (PST) Received: by 10.36.200.70 with HTTP; Tue, 1 Dec 2015 09:51:52 -0800 (PST) In-Reply-To: <1448990880.8490.24.camel@surprise> References: <1448974501-30981-1-git-send-email-rep.dot.nop@gmail.com> <1448974501-30981-4-git-send-email-rep.dot.nop@gmail.com> <1448990880.8490.24.camel@surprise> Date: Tue, 01 Dec 2015 17:51:00 -0000 Message-ID: Subject: Re: [PATCH] RFC: Use Levenshtein spelling suggestions in Fortran FE From: Bernhard Reutner-Fischer To: David Malcolm Cc: gfortran , GCC Patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-12/txt/msg00014.txt.bz2 On 1 December 2015 at 18:28, David Malcolm wrote: > On Tue, 2015-12-01 at 13:55 +0100, Bernhard Reutner-Fischer wrote: >> +/* Lookup function FN fuzzily, taking names in FUN into account. */ >> + >> +const char* >> +gfc_lookup_function_fuzzy (const char *fn, gfc_symtree *fun) >> +{ >> + auto_vec candidates; >> + lookup_function_fuzzy_find_candidates (fun, &candidates); >> + >> + /* Determine closest match. */ >> + int i; >> + const char *name, *best = NULL; >> + edit_distance_t best_distance = MAX_EDIT_DISTANCE; >> + >> + FOR_EACH_VEC_ELT (candidates, i, name) >> + { >> + edit_distance_t dist = levenshtein_distance (fn, name); >> + if (dist < best_distance) >> + { >> + best_distance = dist; >> + best = name; >> + } >> + } >> + /* If more than half of the letters were misspelled, the suggestion is >> + likely to be meaningless. */ >> + if (best) >> + { >> + unsigned int cutoff = MAX (strlen (fn), strlen (best)) / 2; >> + if (best_distance > cutoff) >> + return NULL; >> + } >> + return best; >> +} > > > Caveat: I'm not very familiar with the Fortran FE, so take the following > with a pinch of salt. > > If I'm reading things right, here, and in various other places, you're > building a vec of const char *, and then seeing which one of those > candidates is the best match for another const char *. > > You could simplify things by adding a helper function to spellcheck.h, > akin to this one: > > extern tree > find_closest_identifier (tree target, const auto_vec *candidates); I was hoping for ipa-icf to fix that up on my behalf. I'll try to see if it does. Short of that: yes, should do that. > > This would reduce the amount of duplication in the patch (and slightly > reduce the amount of C++). As said, we could as well use a list of candidates with NULL as record marker. Implementation cosmetics. Steve seems to not be thrilled by the overall idea in the first place, so unless there is clear support by somebody else i won't pursue this any further, it's not that i'm bored or ran out of stuff i should do.. ;) > > [are there IDENTIFIER nodes in the Fortran FE, or is it all const char > *? this would avoid some strlen calls] Right, but in the Fortran FE these are const char*. thanks for your comments!