diff options
author | Martin Liska <mliska@suse.cz> | 2018-06-28 09:08:01 +0200 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2018-06-28 07:08:01 +0000 |
commit | 98086b2ba2bd021e887788cea410410e61eaee42 (patch) | |
tree | 75a8f11816cec8e2dfb5a56b30a3e687f5b27828 /gcc | |
parent | 3de37a5d22c6f7add3457929d3572d2de678d6c2 (diff) | |
download | gcc-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')
-rw-r--r-- | gcc/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/Makefile.in | 2 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/c-family/cppspec.c | 1 | ||||
-rw-r--r-- | gcc/fortran/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/fortran/gfortranspec.c | 1 | ||||
-rw-r--r-- | gcc/gcc-main.c | 1 | ||||
-rw-r--r-- | gcc/gcc.c | 114 | ||||
-rw-r--r-- | gcc/gcc.h | 4 | ||||
-rw-r--r-- | gcc/jit/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/jit/jit-playback.c | 1 | ||||
-rw-r--r-- | gcc/opt-suggestions.c | 122 | ||||
-rw-r--r-- | gcc/opt-suggestions.h | 59 |
13 files changed, 215 insertions, 115 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a5a6ace..aee4f0f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,18 @@ 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). (auto_string_vec::~auto_string_vec): Likewise. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 1f38cac..66c8b6e 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1615,7 +1615,7 @@ OBJS-libcommon = diagnostic.o diagnostic-color.o diagnostic-show-locus.o \ # 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)) diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index fc7f7de..9596eec 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,7 @@ +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> diff --git a/gcc/c-family/cppspec.c b/gcc/c-family/cppspec.c index 1e0a8bc..6654023 100644 --- a/gcc/c-family/cppspec.c +++ b/gcc/c-family/cppspec.c @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "tm.h" +#include "opt-suggestions.h" #include "gcc.h" #include "opts.h" diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f052cfe..6e1af2e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,7 @@ +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 diff --git a/gcc/fortran/gfortranspec.c b/gcc/fortran/gfortranspec.c index fe1ec04..4ba3a8d 100644 --- a/gcc/fortran/gfortranspec.c +++ b/gcc/fortran/gfortranspec.c @@ -47,6 +47,7 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" +#include "opt-suggestions.h" #include "gcc.h" #include "opts.h" diff --git a/gcc/gcc-main.c b/gcc/gcc-main.c index 9e6de74..6a759bb 100644 --- a/gcc/gcc-main.c +++ b/gcc/gcc-main.c @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see #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 @@ -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%>?", @@ -45,8 +45,6 @@ class driver 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 (); @@ -59,7 +57,7 @@ class driver 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 diff --git a/gcc/jit/ChangeLog b/gcc/jit/ChangeLog index 059cbb8..2267967 100644 --- a/gcc/jit/ChangeLog +++ b/gcc/jit/ChangeLog @@ -1,5 +1,9 @@ 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. (auto_argvec::~auto_argvec): Likewise. (compile): Use the renamed name. diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index 01c4567..f11642b 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see #include "attribs.h" #include "context.h" #include "fold-const.h" +#include "opt-suggestions.h" #include "gcc.h" #include "diagnostic.h" diff --git a/gcc/opt-suggestions.c b/gcc/opt-suggestions.c new file mode 100644 index 0000000..90ab80e --- /dev/null +++ b/gcc/opt-suggestions.c @@ -0,0 +1,122 @@ +/* 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; + } + } +} diff --git a/gcc/opt-suggestions.h b/gcc/opt-suggestions.h new file mode 100644 index 0000000..ccd4e45 --- /dev/null +++ b/gcc/opt-suggestions.h @@ -0,0 +1,59 @@ +/* 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 */ |