diff options
-rw-r--r-- | gcc/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/opts.c | 9 | ||||
-rw-r--r-- | gcc/params.c | 14 | ||||
-rw-r--r-- | gcc/params.h | 1 | ||||
-rw-r--r-- | gcc/spellcheck.c | 18 | ||||
-rw-r--r-- | gcc/spellcheck.h | 18 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/spellcheck-params-2.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/spellcheck-params.c | 4 |
9 files changed, 66 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8df7f3c4b82..308fcc86049 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2016-06-29 David Malcolm <dmalcolm@redhat.com> + + * opts.c (handle_param): Use find_param_fuzzy to offer suggestions + for misspelled param names. + * params.c: Include spellcheck.h. + (find_param_fuzzy): New function. + * params.h (find_param_fuzzy): New prototype. + * spellcheck.c (struct edit_distance_traits<const char *>): Move + to... + * spellcheck.h (struct edit_distance_traits<const char *>): + ...here. + 2016-06-29 Michael Meissner <meissner@linux.vnet.ibm.com> * config/rs6000/predicates.md (const_0_to_7_operand): New diff --git a/gcc/opts.c b/gcc/opts.c index 74062106895..f09c520975b 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -2228,7 +2228,14 @@ handle_param (struct gcc_options *opts, struct gcc_options *opts_set, enum compiler_param index; if (!find_param (arg, &index)) - error_at (loc, "invalid --param name %qs", arg); + { + const char *suggestion = find_param_fuzzy (arg); + if (suggestion) + error_at (loc, "invalid --param name %qs; did you mean %qs?", + arg, suggestion); + else + error_at (loc, "invalid --param name %qs", arg); + } else { if (!param_string_value_p (index, equal + 1, &value)) diff --git a/gcc/params.c b/gcc/params.c index 41660b47393..1b5000bb8d7 100644 --- a/gcc/params.c +++ b/gcc/params.c @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "params.h" #include "params-enum.h" #include "diagnostic-core.h" +#include "spellcheck.h" /* An array containing the compiler parameters and their current values. */ @@ -142,6 +143,19 @@ find_param (const char *name, enum compiler_param *index) return false; } +/* Look for the closest match for NAME in the parameter table, returning it + if it is a reasonable suggestion for a misspelling. Return NULL + otherwise. */ + +const char * +find_param_fuzzy (const char *name) +{ + best_match <const char *, const char *> bm (name); + for (size_t i = 0; i < num_compiler_params; ++i) + bm.consider (compiler_params[i].option); + return bm.get_best_meaningful_candidate (); +} + /* Return true if param with entry index INDEX should be defined using strings. If so, return the value corresponding to VALUE_NAME in *VALUE_P. */ diff --git a/gcc/params.h b/gcc/params.h index 7221ab65a61..97c8d565055 100644 --- a/gcc/params.h +++ b/gcc/params.h @@ -89,6 +89,7 @@ enum compiler_param }; extern bool find_param (const char *, enum compiler_param *); +extern const char *find_param_fuzzy (const char *name); extern bool param_string_value_p (enum compiler_param, const char *, int *); /* The value of the parameter given by ENUM. Not an lvalue. */ diff --git a/gcc/spellcheck.c b/gcc/spellcheck.c index 2648f3a0bbb..b37b1e46929 100644 --- a/gcc/spellcheck.c +++ b/gcc/spellcheck.c @@ -121,24 +121,6 @@ levenshtein_distance (const char *s, const char *t) return levenshtein_distance (s, strlen (s), t, strlen (t)); } -/* Specialization of edit_distance_traits for C-style strings. */ - -template <> -struct edit_distance_traits<const char *> -{ - static size_t get_length (const char *str) - { - gcc_assert (str); - return strlen (str); - } - - static const char *get_string (const char *str) - { - gcc_assert (str); - return str; - } -}; - /* 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 diff --git a/gcc/spellcheck.h b/gcc/spellcheck.h index 035f4ac3608..b48cfbc4072 100644 --- a/gcc/spellcheck.h +++ b/gcc/spellcheck.h @@ -48,6 +48,24 @@ find_closest_string (const char *target, template <typename TYPE> struct edit_distance_traits {}; +/* Specialization of edit_distance_traits for C-style strings. */ + +template <> +struct edit_distance_traits<const char *> +{ + static size_t get_length (const char *str) + { + gcc_assert (str); + return strlen (str); + } + + static const char *get_string (const char *str) + { + gcc_assert (str); + return str; + } +}; + /* 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9763bacb9d3..8069c679666 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-06-29 David Malcolm <dmalcolm@redhat.com> + + * gcc.dg/spellcheck-params.c: New testcase. + * gcc.dg/spellcheck-params-2.c: New testcase. + 2016-06-29 Michael Meissner <meissner@linux.vnet.ibm.com> * gcc.target/powerpc/p9-extract-1.c: New file to test ISA 3.0 diff --git a/gcc/testsuite/gcc.dg/spellcheck-params-2.c b/gcc/testsuite/gcc.dg/spellcheck-params-2.c new file mode 100644 index 00000000000..27e293ffa60 --- /dev/null +++ b/gcc/testsuite/gcc.dg/spellcheck-params-2.c @@ -0,0 +1,4 @@ +/* { dg-do compile } */ +/* { dg-options "--param does-not-resemble-anything=42" } */ +/* { dg-error "invalid --param name .does-not-resemble-anything." "" { target *-*-* } 0 } */ + diff --git a/gcc/testsuite/gcc.dg/spellcheck-params.c b/gcc/testsuite/gcc.dg/spellcheck-params.c new file mode 100644 index 00000000000..1bb7bca6024 --- /dev/null +++ b/gcc/testsuite/gcc.dg/spellcheck-params.c @@ -0,0 +1,4 @@ +/* { dg-do compile } */ +/* { dg-options "--param max-early-inliner-iteration=3" } */ +/* { dg-error "invalid --param name .max-early-inliner-iteration.; did you mean .max-early-inliner-iterations.?" "" { target *-*-* } 0 } */ + |