Offer suggestions for misspelled --param names.

gcc/ChangeLog:
	* 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.

gcc/testsuite/ChangeLog:
	* gcc.dg/spellcheck-params.c: New testcase.
	* gcc.dg/spellcheck-params-2.c: New testcase.

From-SVN: r237865
This commit is contained in:
David Malcolm 2016-06-30 00:05:39 +00:00 committed by David Malcolm
parent c5e74d9d4e
commit f4452176d8
9 changed files with 66 additions and 19 deletions

View file

@ -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

View file

@ -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))

View file

@ -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. */

View file

@ -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. */

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 } */

View file

@ -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 } */