aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2018-06-28 09:11:16 +0200
committerMartin Liska <marxin@gcc.gnu.org>2018-06-28 07:11:16 +0000
commitd86c7648fb9643640d8c82be19d49927aa488768 (patch)
treeb45fc0d4134e27d198b87360705d0182c44f8f25 /gcc/gcc.c
parent98086b2ba2bd021e887788cea410410e61eaee42 (diff)
downloadgcc-d86c7648fb9643640d8c82be19d49927aa488768.zip
gcc-d86c7648fb9643640d8c82be19d49927aa488768.tar.gz
gcc-d86c7648fb9643640d8c82be19d49927aa488768.tar.bz2
Come up with new --completion option.
2018-06-28 Martin Liska <mliska@suse.cz> * common.opt: Introduce -completion option. * gcc.c (driver_handle_option): Handle it. (driver::main): Print completions if completion is set. * opt-suggestions.c (option_proposer::get_completions): New function. (option_proposer::suggest_completion): Likewise. (option_proposer::find_param_completions): Likewise. (verify_autocompletions): Likewise. (test_completion_valid_options): Likewise. (test_completion_valid_params): Likewise. (in_completion_p): Likewise. (empty_completion_p): Likewise. (test_completion_partial_match): Likewise. (test_completion_garbage): Likewise. (opt_proposer_c_tests): Likewise. * opt-suggestions.h: Declare new functions. * opts.c (common_handle_option): Handle OPT__completion_. * selftest-run-tests.c (selftest::run_tests): Add opt_proposer_c_tests. * selftest.c (assert_str_startswith): New. * selftest.h (assert_str_startswith): Likewise. (opt_proposer_c_tests): New. (ASSERT_STR_STARTSWITH): Likewise. From-SVN: r262210
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index dda1fd3..9ed8a03 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -221,6 +221,10 @@ static int print_help_list;
static int print_version;
+/* Flag that stores string prefix for which we provide bash completion. */
+
+static const char *completion = NULL;
+
/* Flag indicating whether we should ONLY print the command and
arguments (like verbose_flag) without executing the command.
Displayed arguments are quoted so that the generated command
@@ -3890,6 +3894,11 @@ driver_handle_option (struct gcc_options *opts,
add_linker_option ("--version", strlen ("--version"));
break;
+ case OPT__completion_:
+ validated = true;
+ completion = decoded->arg;
+ break;
+
case OPT__help:
print_help_list = 1;
@@ -7300,6 +7309,12 @@ driver::main (int argc, char **argv)
maybe_putenv_OFFLOAD_TARGETS ();
handle_unrecognized_options ();
+ if (completion)
+ {
+ m_option_proposer.suggest_completion (completion);
+ return 0;
+ }
+
if (!maybe_print_and_exit ())
return 0;