aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2018-06-28 09:08:01 +0200
committerMartin Liska <marxin@gcc.gnu.org>2018-06-28 07:08:01 +0000
commit98086b2ba2bd021e887788cea410410e61eaee42 (patch)
tree75a8f11816cec8e2dfb5a56b30a3e687f5b27828 /gcc/gcc.c
parent3de37a5d22c6f7add3457929d3572d2de678d6c2 (diff)
downloadgcc-98086b2ba2bd021e887788cea410410e61eaee42.zip
gcc-98086b2ba2bd021e887788cea410410e61eaee42.tar.gz
gcc-98086b2ba2bd021e887788cea410410e61eaee42.tar.bz2
Makefile.in: Add opt-suggestions.o.
. 2018-06-28 Martin Liska <mliska@suse.cz> * Makefile.in: Add opt-suggestions.o. * gcc-main.c: Include opt-suggestions.h. * gcc.c (driver::driver): Likewise. (driver::~driver): Remove m_option_suggestions. (driver::build_option_suggestions): Moved to option_proposer. (driver::suggest_option): Likewise. (driver::handle_unrecognized_options): Use option_proposer. * gcc.h (class driver): Add new memver m_option_proposer. * opt-suggestions.c: New file. * opt-suggestions.h: New file. 2018-06-28 Martin Liska <mliska@suse.cz> * cppspec.c: Include opt-suggestions.h. 2018-06-28 Martin Liska <mliska@suse.cz> * gfortranspec.c: Include opt-suggestions.h. 2018-06-28 Martin Liska <mliska@suse.cz> * jit-playback.c: Include opt-suggestions.h. From-SVN: r262209
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c114
1 files changed, 3 insertions, 111 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 405d2e3..dda1fd3 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -36,6 +36,7 @@ compilation is specified by a string called a "spec". */
#include "obstack.h"
#include "intl.h"
#include "prefix.h"
+#include "opt-suggestions.h"
#include "gcc.h"
#include "diagnostic.h"
#include "flags.h"
@@ -7270,8 +7271,7 @@ compare_files (char *cmpfile[])
driver::driver (bool can_finalize, bool debug) :
explicit_link_files (NULL),
- decoded_options (NULL),
- m_option_suggestions (NULL)
+ decoded_options (NULL)
{
env.init (can_finalize, debug);
}
@@ -7280,14 +7280,6 @@ driver::~driver ()
{
XDELETEVEC (explicit_link_files);
XDELETEVEC (decoded_options);
- if (m_option_suggestions)
- {
- int i;
- char *str;
- FOR_EACH_VEC_ELT (*m_option_suggestions, i, str)
- free (str);
- delete m_option_suggestions;
- }
}
/* driver::main is implemented as a series of driver:: method calls. */
@@ -7776,106 +7768,6 @@ driver::maybe_putenv_OFFLOAD_TARGETS () const
offload_targets = NULL;
}
-/* Helper function for driver::suggest_option. Populate
- m_option_suggestions with candidate strings for misspelled options.
- The strings will be freed by the driver's dtor. */
-
-void
-driver::build_option_suggestions (void)
-{
- gcc_assert (m_option_suggestions == NULL);
- m_option_suggestions = new auto_vec <char *> ();
-
- /* We build a vec of m_option_suggestions, using add_misspelling_candidates
- to add copies of strings, without a leading dash. */
-
- for (unsigned int i = 0; i < cl_options_count; i++)
- {
- const struct cl_option *option = &cl_options[i];
- const char *opt_text = option->opt_text;
- switch (i)
- {
- default:
- if (option->var_type == CLVC_ENUM)
- {
- const struct cl_enum *e = &cl_enums[option->var_enum];
- for (unsigned j = 0; e->values[j].arg != NULL; j++)
- {
- char *with_arg = concat (opt_text, e->values[j].arg, NULL);
- add_misspelling_candidates (m_option_suggestions, option,
- with_arg);
- free (with_arg);
- }
- }
- else
- add_misspelling_candidates (m_option_suggestions, option,
- opt_text);
- break;
-
- case OPT_fsanitize_:
- case OPT_fsanitize_recover_:
- /* -fsanitize= and -fsanitize-recover= can take
- a comma-separated list of arguments. Given that combinations
- are supported, we can't add all potential candidates to the
- vec, but if we at least add them individually without commas,
- we should do a better job e.g. correcting
- "-sanitize=address"
- to
- "-fsanitize=address"
- rather than to "-Wframe-address" (PR driver/69265). */
- {
- for (int j = 0; sanitizer_opts[j].name != NULL; ++j)
- {
- struct cl_option optb;
- /* -fsanitize=all is not valid, only -fno-sanitize=all.
- So don't register the positive misspelling candidates
- for it. */
- if (sanitizer_opts[j].flag == ~0U && i == OPT_fsanitize_)
- {
- optb = *option;
- optb.opt_text = opt_text = "-fno-sanitize=";
- optb.cl_reject_negative = true;
- option = &optb;
- }
- /* Get one arg at a time e.g. "-fsanitize=address". */
- char *with_arg = concat (opt_text,
- sanitizer_opts[j].name,
- NULL);
- /* Add with_arg and all of its variant spellings e.g.
- "-fno-sanitize=address" to candidates (albeit without
- leading dashes). */
- add_misspelling_candidates (m_option_suggestions, option,
- with_arg);
- free (with_arg);
- }
- }
- break;
- }
- }
-}
-
-/* Helper function for driver::handle_unrecognized_options.
-
- Given an unrecognized option BAD_OPT (without the leading dash),
- locate the closest reasonable matching option (again, without the
- leading dash), or NULL.
-
- The returned string is owned by the driver instance. */
-
-const char *
-driver::suggest_option (const char *bad_opt)
-{
- /* Lazily populate m_option_suggestions. */
- if (!m_option_suggestions)
- build_option_suggestions ();
- gcc_assert (m_option_suggestions);
-
- /* "m_option_suggestions" is now populated. Use it. */
- return find_closest_string
- (bad_opt,
- (auto_vec <const char *> *) m_option_suggestions);
-}
-
/* Reject switches that no pass was interested in. */
void
@@ -7884,7 +7776,7 @@ driver::handle_unrecognized_options ()
for (size_t i = 0; (int) i < n_switches; i++)
if (! switches[i].validated)
{
- const char *hint = suggest_option (switches[i].part1);
+ const char *hint = m_option_proposer.suggest_option (switches[i].part1);
if (hint)
error ("unrecognized command line option %<-%s%>;"
" did you mean %<-%s%>?",