diff gcc/spellcheck.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
line wrap: on
line diff
--- a/gcc/spellcheck.h	Fri Oct 27 22:46:09 2017 +0900
+++ b/gcc/spellcheck.h	Thu Oct 25 07:37:49 2018 +0900
@@ -1,5 +1,5 @@
 /* Find near-matches for strings and identifiers.
-   Copyright (C) 2015-2017 Free Software Foundation, Inc.
+   Copyright (C) 2015-2018 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -25,11 +25,11 @@
 
 /* spellcheck.c  */
 extern edit_distance_t
-levenshtein_distance (const char *s, int len_s,
-		      const char *t, int len_t);
+get_edit_distance (const char *s, int len_s,
+		   const char *t, int len_t);
 
 extern edit_distance_t
-levenshtein_distance (const char *s, const char *t);
+get_edit_distance (const char *s, const char *t);
 
 extern const char *
 find_closest_string (const char *target,
@@ -66,6 +66,9 @@
   }
 };
 
+extern edit_distance_t get_edit_distance_cutoff (size_t goal_len,
+						 size_t candidate_len);
+
 /* A type for use when determining the best match against a string,
    expressed as a template so that we can match against various
    string-like types (const char *, frontend identifiers, and preprocessor
@@ -73,7 +76,7 @@
 
    This type accumulates the best possible match against GOAL_TYPE for
    a sequence of elements of CANDIDATE_TYPE, whilst minimizing the
-   number of calls to levenshtein_distance and to
+   number of calls to get_edit_distance and to
    edit_distance_traits<T>::get_length.  */
 
 template <typename GOAL_TYPE, typename CANDIDATE_TYPE>
@@ -119,16 +122,16 @@
     /* If the candidate will be unable to beat the criterion in
        get_best_meaningful_candidate, reject it without computing
        the exact distance.  */
-    unsigned int cutoff = MAX (m_goal_len, candidate_len) / 2;
+    edit_distance_t cutoff = get_cutoff (candidate_len);
     if (min_candidate_distance > cutoff)
       return;
 
     /* Otherwise, compute the distance and see if the candidate
        has beaten the previous best value.  */
     edit_distance_t dist
-      = levenshtein_distance (m_goal, m_goal_len,
-			      candidate_traits::get_string (candidate),
-			      candidate_len);
+      = get_edit_distance (m_goal, m_goal_len,
+			   candidate_traits::get_string (candidate),
+			   candidate_len);
     if (dist < m_best_distance)
       {
 	m_best_distance = dist;
@@ -151,17 +154,25 @@
     m_best_candidate_len = best_candidate_len;
   }
 
+  /* Generate the maximum edit distance for which we consider a suggestion
+     to be meaningful, given a candidate of length CANDIDATE_LEN.  */
+
+  edit_distance_t get_cutoff (size_t candidate_len) const
+  {
+    return ::get_edit_distance_cutoff (m_goal_len, candidate_len);
+  }
+
   /* Get the best candidate so far, but applying a filter to ensure
      that we return NULL if none of the candidates are close to the goal,
      to avoid offering nonsensical suggestions to the user.  */
 
   candidate_t get_best_meaningful_candidate () const
   {
-    /* If more than half of the letters were misspelled, the suggestion is
-       likely to be meaningless.  */
+    /* If the edit distance is too high, the suggestion is likely to be
+       meaningless.  */
     if (m_best_candidate)
       {
-	unsigned int cutoff = MAX (m_goal_len, m_best_candidate_len) / 2;
+	edit_distance_t cutoff = get_cutoff (m_best_candidate_len);
 	if (m_best_distance > cutoff)
 	  return NULL;
     }
@@ -178,6 +189,13 @@
     return m_best_candidate;
   }
 
+  /* Get the closest candidate so far, without applying any filtering.  */
+
+  candidate_t blithely_get_best_candidate () const
+  {
+    return m_best_candidate;
+  }
+
   edit_distance_t get_best_distance () const { return m_best_distance; }
   size_t get_best_candidate_length () const { return m_best_candidate_len; }