GCC Middle and Back End API Reference
spellcheck.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  edit_distance_traits< TYPE >
struct  edit_distance_traits< const char * >
class  best_match< GOAL_TYPE, CANDIDATE_TYPE >


typedef unsigned int edit_distance_t


edit_distance_t get_edit_distance (const char *s, int len_s, const char *t, int len_t)
edit_distance_t get_edit_distance (const char *s, const char *t)
const charfind_closest_string (const char *target, const auto_vec< const char * > *candidates)
edit_distance_t get_edit_distance_cutoff (size_t goal_len, size_t candidate_len)


const edit_distance_t MAX_EDIT_DISTANCE = UINT_MAX

Typedef Documentation

◆ edit_distance_t

Find near-matches for strings and identifiers.
   Copyright (C) 2015-2024 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see

Function Documentation

◆ find_closest_string()

const char * find_closest_string ( const char * target,
const auto_vec< const char * > * candidates )
Given TARGET, a non-NULL string, and CANDIDATES, a non-NULL ptr to
an autovec of non-NULL strings, determine which element within
CANDIDATES has the lowest edit distance to TARGET.  If there are
multiple elements with the same minimal distance, the first in the
vector wins.

If more than half of the letters were misspelled, the suggestion is
likely to be meaningless, so return NULL for this case.   

References candidate(), candidates, best_match< GOAL_TYPE, CANDIDATE_TYPE >::consider(), FOR_EACH_VEC_ELT, gcc_assert, best_match< GOAL_TYPE, CANDIDATE_TYPE >::get_best_meaningful_candidate(), and i.

Referenced by candidates_list_and_hint(), gcc::dump_manager::dump_switch_p(), and option_proposer::suggest_option().

◆ get_edit_distance() [1/2]

edit_distance_t get_edit_distance ( const char * s,
const char * t )
Get the edit distance between two nil-terminated strings.   

References get_edit_distance(), and ggc_alloc().

◆ get_edit_distance() [2/2]

edit_distance_t get_edit_distance ( const char * s,
int len_s,
const char * t,
int len_t )
Get the edit distance between the two strings: the minimal
number of edits that are needed to change one string into another,
where edits can be one-character insertions, removals, or substitutions,
or transpositions of two adjacent characters (counting as one "edit").

This implementation uses a modified variant of the Wagner-Fischer
algorithm for the Damerau-Levenshtein distance; specifically, the
"optimal string alignment distance" or "restricted edit distance"
variant.  This implementation has been further modified to take
case into account.   

References BASE_COST, CASE_COST, debug, ggc_alloc(), i, and MIN.

Referenced by best_match< GOAL_TYPE, CANDIDATE_TYPE >::consider(), and get_edit_distance().

◆ get_edit_distance_cutoff()

edit_distance_t get_edit_distance_cutoff ( size_t goal_len,
size_t candidate_len )
Generate the maximum edit distance for which we consider a suggestion
to be meaningful, given a goal of length GOAL_LEN and a candidate of

This is a third of the length of the candidate or of the goal,
whichever is bigger.   

References BASE_COST, gcc_assert, ggc_alloc(), MAX, and MIN.

Variable Documentation


const edit_distance_t MAX_EDIT_DISTANCE = UINT_MAX