aboutsummaryrefslogtreecommitdiff
path: root/gcc/spellcheck-tree.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-06-15 03:29:39 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-06-15 03:29:39 +0000
commit6a3f203c3cc8e0f0757f7ed038b3cb34063936ba (patch)
treee99b8b2be80b721ed128799b811f4eccae4a9f64 /gcc/spellcheck-tree.c
parent9e990b5d19d930bd1769d6db455fcbda8e7eae11 (diff)
downloadgcc-6a3f203c3cc8e0f0757f7ed038b3cb34063936ba.zip
gcc-6a3f203c3cc8e0f0757f7ed038b3cb34063936ba.tar.gz
gcc-6a3f203c3cc8e0f0757f7ed038b3cb34063936ba.tar.bz2
spellcheck.h: add best_match template; implement early-reject
gcc/c/ChangeLog: * c-typeck.c: Include spellcheck-tree.h rather than spellcheck.h. gcc/cp/ChangeLog: * search.c: Include spellcheck-tree.h rather than spellcheck.h. gcc/ChangeLog: * spellcheck-tree.c: Include spellcheck-tree.h rather than spellcheck.h. (find_closest_identifier): Reimplement in terms of best_match<tree,tree>. * spellcheck-tree.h: New file. * spellcheck.c (struct edit_distance_traits<const char *>): New struct. (find_closest_string): Reimplement in terms of best_match<const char *, const char *>. * spellcheck.h (levenshtein_distance): Move prototype of tree-based overload to spellcheck-tree.h. (find_closest_identifier): Likewise. (struct edit_distance_traits<T>): New template. (class best_match): New class. From-SVN: r237471
Diffstat (limited to 'gcc/spellcheck-tree.c')
-rw-r--r--gcc/spellcheck-tree.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/gcc/spellcheck-tree.c b/gcc/spellcheck-tree.c
index 2d73b774..63fb1a8 100644
--- a/gcc/spellcheck-tree.c
+++ b/gcc/spellcheck-tree.c
@@ -22,7 +22,7 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
-#include "spellcheck.h"
+#include "spellcheck-tree.h"
#include "selftest.h"
#include "stringpool.h"
@@ -53,32 +53,16 @@ find_closest_identifier (tree target, const auto_vec<tree> *candidates)
{
gcc_assert (TREE_CODE (target) == IDENTIFIER_NODE);
+ best_match<tree, tree> bm (target);
int i;
tree identifier;
- tree best_identifier = NULL_TREE;
- edit_distance_t best_distance = MAX_EDIT_DISTANCE;
FOR_EACH_VEC_ELT (*candidates, i, identifier)
{
gcc_assert (TREE_CODE (identifier) == IDENTIFIER_NODE);
- edit_distance_t dist = levenshtein_distance (target, identifier);
- if (dist < best_distance)
- {
- best_distance = dist;
- best_identifier = identifier;
- }
+ bm.consider (identifier);
}
- /* If more than half of the letters were misspelled, the suggestion is
- likely to be meaningless. */
- if (best_identifier)
- {
- unsigned int cutoff = MAX (IDENTIFIER_LENGTH (target),
- IDENTIFIER_LENGTH (best_identifier)) / 2;
- if (best_distance > cutoff)
- return NULL_TREE;
- }
-
- return best_identifier;
+ return bm.get_best_meaningful_candidate ();
}
#if CHECKING_P