+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
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))
#include "params.h"
#include "params-enum.h"
#include "diagnostic-core.h"
+#include "spellcheck.h"
/* An array containing the compiler parameters and their current
values. */
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. */
};
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. */
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
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
+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
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "--param does-not-resemble-anything=42" } */
+/* { dg-error "invalid --param name .does-not-resemble-anything." "" { target *-*-* } 0 } */
+
--- /dev/null
+/* { 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 } */
+