.
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
+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>
* vec.h (class auto_string_vec): New (moved from auto_argvec).
# compiler and containing target-dependent code.
OBJS-libcommon-target = $(common_out_object_file) prefix.o params.o \
opts.o opts-common.o options.o vec.o hooks.o common/common-targhooks.o \
- hash-table.o file-find.o spellcheck.o selftest.o
+ hash-table.o file-find.o spellcheck.o selftest.o opt-suggestions.o
# This lists all host objects for the front ends.
ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS))
+2018-06-28 Martin Liska <mliska@suse.cz>
+
+ * cppspec.c: Include opt-suggestions.h.
+
2018-06-20 Chung-Lin Tang <cltang@codesourcery.com>
Thomas Schwinge <thomas@codesourcery.com>
Cesar Philippidis <cesar@codesourcery.com>
#include "system.h"
#include "coretypes.h"
#include "tm.h"
+#include "opt-suggestions.h"
#include "gcc.h"
#include "opts.h"
+2018-06-28 Martin Liska <mliska@suse.cz>
+
+ * gfortranspec.c: Include opt-suggestions.h.
+
2018-06-25 Fritz Reese <fritzoreese@gmail.com>
PR fortran/82972
#include "config.h"
#include "system.h"
#include "coretypes.h"
+#include "opt-suggestions.h"
#include "gcc.h"
#include "opts.h"
#include "obstack.h"
#include "intl.h"
#include "prefix.h"
+#include "opt-suggestions.h"
#include "gcc.h"
/* Implement the top-level "main" within the driver in terms of
#include "obstack.h"
#include "intl.h"
#include "prefix.h"
+#include "opt-suggestions.h"
#include "gcc.h"
#include "diagnostic.h"
#include "flags.h"
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);
}
{
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. */
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
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%>?",
void putenv_COLLECT_GCC (const char *argv0) const;
void maybe_putenv_COLLECT_LTO_WRAPPER () const;
void maybe_putenv_OFFLOAD_TARGETS () const;
- void build_option_suggestions (void);
- const char *suggest_option (const char *bad_opt);
void handle_unrecognized_options ();
int maybe_print_and_exit () const;
bool prepare_infiles ();
char *explicit_link_files;
struct cl_decoded_option *decoded_options;
unsigned int decoded_options_count;
- auto_vec <char *> *m_option_suggestions;
+ option_proposer m_option_proposer;
};
/* The mapping of a spec function name to the C function that
+2018-06-28 Martin Liska <mliska@suse.cz>
+
+ * jit-playback.c: Include opt-suggestions.h.
+
2018-06-28 Martin Liska <mliska@suse.cz>
* jit-playback.c (class auto_argvec): Moved to vec.h.
#include "attribs.h"
#include "context.h"
#include "fold-const.h"
+#include "opt-suggestions.h"
#include "gcc.h"
#include "diagnostic.h"
--- /dev/null
+/* Provide option suggestion for --complete option and a misspelled
+ used by a user.
+ Copyright (C) 2016-2018 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "params.h"
+#include "spellcheck.h"
+#include "opt-suggestions.h"
+#include "selftest.h"
+
+option_proposer::~option_proposer ()
+{
+ delete m_option_suggestions;
+}
+
+const char *
+option_proposer::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);
+}
+
+void
+option_proposer::build_option_suggestions (void)
+{
+ gcc_assert (m_option_suggestions == NULL);
+ m_option_suggestions = new auto_string_vec ();
+
+ /* 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;
+ }
+ }
+}
--- /dev/null
+/* Provide suggestions to handle misspelled options, and implement the
+ --complete option for auto-completing options from a prefix.
+ Copyright (C) 2016-2018 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#ifndef GCC_OPT_PROPOSER_H
+#define GCC_OPT_PROPOSER_H
+
+/* Option proposer is class used by driver in order to provide hints
+ for wrong options provided. And it's used by --complete option that's
+ intended to be invoked by BASH in order to provide better option
+ completion support. */
+
+class option_proposer
+{
+public:
+ /* Default constructor. */
+ option_proposer (): m_option_suggestions (NULL)
+ {}
+
+ /* Default destructor. */
+ ~option_proposer ();
+
+ /* 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 option_proposer instance. */
+ const char *suggest_option (const char *bad_opt);
+
+private:
+ /* Helper function for option_proposer::suggest_option. Populate
+ m_option_suggestions with candidate strings for misspelled options.
+ The strings will be freed by the option_proposer's dtor. */
+ void build_option_suggestions ();
+
+private:
+ /* Cache with all suggestions. */
+ auto_string_vec *m_option_suggestions;
+};
+
+#endif /* GCC_OPT_PROPOSER_H */