On Fri, 2020-05-29 at 10:54 -0600, Tom Tromey wrote: > I got this error message when editing gcc and recompiling: > > ../../gcc/gcc/ada/gcc-interface/decl.c:7714:39: error: > ‘DWARF_GNAT_ENCODINGS_all’ was not declared in this scope; did you > mean ‘DWARF_GNAT_ENCODINGS_GDB’? > 7714 | = debug_info && gnat_encodings == > DWARF_GNAT_ENCODINGS_all; > | ^~~~~~~~~~~~~~~~~~~~~~~ > ~ > | DWARF_GNAT_ENCODINGS_GD > B > > This suggestion could be improved -- what happened here is that I > failed to upper-case the word, and DWARF_GNAT_ENCODINGS_ALL was the > correct spelling. > > This patch changes gcc's spell checker to prefer simple case changes > when possible.
Thanks. I like the overall idea. > I tested this using the self-tests. A new self-test is also > included. Did the full DejaGnu testsuite get run? There are a lot of tests in it that make use of this code. > gcc/ChangeLog: > > * spellcheck.c (CASE_COST): New define. > (BASE_COST): New define. > (get_edit_distance): Recognize case changes. > (get_edit_distance_cutoff): Update. > (test_edit_distances): Update. > (get_old_cutoff): Update. > (test_find_closest_string): Add case sensitivity test. > --- > gcc/spellcheck.c | 114 ++++++++++++++++++++++++++++++--------------- > -- > 1 file changed, 74 insertions(+), 40 deletions(-) > diff --git a/gcc/spellcheck.c b/gcc/spellcheck.c > index 7891260a258..9002617453f 100644 > --- a/gcc/spellcheck.c > +++ b/gcc/spellcheck.c [...snip...] The patch should probably update the leading comment to get_edit_distance. > @@ -228,47 +241,50 @@ test_get_edit_distance_both_ways (const char > *a, const char *b, > static void > test_edit_distances () > { > - test_get_edit_distance_both_ways ("", "nonempty", strlen > ("nonempty")); > - test_get_edit_distance_both_ways ("saturday", "sunday", 3); > - test_get_edit_distance_both_ways ("foo", "m_foo", 2); > - test_get_edit_distance_both_ways ("hello_world", "HelloWorld", 3); > + test_get_edit_distance_both_ways ("", "nonempty", > + BASE_COST * strlen ("nonempty")); > + test_get_edit_distance_both_ways ("saturday", "sunday", > + BASE_COST * 3); > + test_get_edit_distance_both_ways ("foo", "m_foo", BASE_COST * 2); > + test_get_edit_distance_both_ways ("hello_world", "HelloWorld", 4); > test_get_edit_distance_both_ways > - ("the quick brown fox jumps over the lazy dog", "dog", 40); > + ("the quick brown fox jumps over the lazy dog", "dog", BASE_COST > * 40); > test_get_edit_distance_both_ways > ("the quick brown fox jumps over the lazy dog", > "the quick brown dog jumps over the lazy fox", > - 4); > + BASE_COST * 4); > test_get_edit_distance_both_ways > ("Lorem ipsum dolor sit amet, consectetur adipiscing elit,", > "All your base are belong to us", > - 44); > + BASE_COST * 44); > test_get_edit_distance_both_ways ("foo", "FOO", 3); > - test_get_edit_distance_both_ways ("fee", "deed", 2); > - test_get_edit_distance_both_ways ("coorzd1", "coordx1", 2); > - test_get_edit_distance_both_ways ("assert", "sqrt", 3); > - test_get_edit_distance_both_ways ("PATH_MAX", "INT8_MAX", 3); > - test_get_edit_distance_both_ways ("time", "nice", 2); > - test_get_edit_distance_both_ways ("bar", "carg", 2); > + test_get_edit_distance_both_ways ("fee", "deed", BASE_COST * 2); > + test_get_edit_distance_both_ways ("coorzd1", "coordx1", BASE_COST > * 2); > + test_get_edit_distance_both_ways ("assert", "sqrt", BASE_COST * > 3); > + test_get_edit_distance_both_ways ("PATH_MAX", "INT8_MAX", > BASE_COST * 3); > + test_get_edit_distance_both_ways ("time", "nice", BASE_COST * 2); > + test_get_edit_distance_both_ways ("bar", "carg", BASE_COST * 2); > test_get_edit_distance_both_ways ("gtk_widget_show_all", > - "GtkWidgetShowAll", 7); > - test_get_edit_distance_both_ways ("m_bar", "bar", 2); > - test_get_edit_distance_both_ways ("MACRO", "MACRAME", 3); > - test_get_edit_distance_both_ways ("ab", "ac", 1); > - test_get_edit_distance_both_ways ("ab", "a", 1); > - test_get_edit_distance_both_ways ("a", "b", 1); > - test_get_edit_distance_both_ways ("nanl", "name", 2); > - test_get_edit_distance_both_ways ("char", "bar", 2); > - test_get_edit_distance_both_ways ("-optimize", "fsanitize", 5); > - test_get_edit_distance_both_ways ("__DATE__", "__i386__", 4); > + "GtkWidgetShowAll", 10); > + test_get_edit_distance_both_ways ("m_bar", "bar", BASE_COST * 2); > + test_get_edit_distance_both_ways ("MACRO", "MACRAME", BASE_COST * > 3); > + test_get_edit_distance_both_ways ("ab", "ac", BASE_COST * 1); > + test_get_edit_distance_both_ways ("ab", "a", BASE_COST * 1); > + test_get_edit_distance_both_ways ("a", "b", BASE_COST * 1); > + test_get_edit_distance_both_ways ("nanl", "name", BASE_COST * 2); > + test_get_edit_distance_both_ways ("char", "bar", BASE_COST * 2); > + test_get_edit_distance_both_ways ("-optimize", "fsanitize", > BASE_COST * 5); > + test_get_edit_distance_both_ways ("__DATE__", "__i386__", > BASE_COST * 4); > > /* Examples where transposition helps. */ > - test_get_edit_distance_both_ways ("ab", "ba", 1); > - test_get_edit_distance_both_ways ("ba", "abc", 2); > - test_get_edit_distance_both_ways ("coorzd1", "coordz1", 1); > + test_get_edit_distance_both_ways ("ab", "ba", BASE_COST * 1); > + test_get_edit_distance_both_ways ("ba", "abc", BASE_COST * 2); > + test_get_edit_distance_both_ways ("coorzd1", "coordz1", BASE_COST > * 1); > test_get_edit_distance_both_ways ("abcdefghijklmnopqrstuvwxyz", > - "bacdefghijklmnopqrstuvwxzy", 2); > - test_get_edit_distance_both_ways ("saturday", "sundya", 4); > - test_get_edit_distance_both_ways ("signed", "singed", 1); > + "bacdefghijklmnopqrstuvwxzy", > + BASE_COST * 2); > + test_get_edit_distance_both_ways ("saturday", "sundya", BASE_COST > * 4); > + test_get_edit_distance_both_ways ("signed", "singed", BASE_COST * > 1); If I'm reading things correctly, the patch here updates the existing tests to apply the BASE_COST scale factor, but I don't think it adds any direct checks of the cost of case-conversion. It would be good to add those. [...snip...] Dave