diff options
author | Joseph Myers <joseph@codesourcery.com> | 2010-09-22 21:19:39 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2010-09-22 21:19:39 +0100 |
commit | 60cf253a8b1ebaabf6dd476a1177a24ab7f6d48c (patch) | |
tree | 6f696b6dcc2f7574f8c3f96ec2645c09aa05edd8 /gcc/opts-common.c | |
parent | e200444e3bf13cabbb9ad5bd29fdc840f82462a8 (diff) | |
download | gcc-60cf253a8b1ebaabf6dd476a1177a24ab7f6d48c.zip gcc-60cf253a8b1ebaabf6dd476a1177a24ab7f6d48c.tar.gz gcc-60cf253a8b1ebaabf6dd476a1177a24ab7f6d48c.tar.bz2 |
opts-common.c (prune_options): Make static.
* opts-common.c (prune_options): Make static. Work with decoded
options.
(decode_cmdline_options_to_array): Call prune_options. Don't
resize option array here.
* opts.h (prune_options): Remove prototype.
* gcc.c (process_command): Take decoded options; don't call
decode_cmdline_options_to_array here. Use decoded options for
argv[0].
(main): Call decode_cmdline_options_to_array here instead of
prune_options. Update call to process_command.
* config/darwin-driver.c: Include opts.h.
(darwin_default_min_version): Work with decoded options. Don't
handle -b or -V here.
* config/darwin.h (darwin_default_min_version): Update prototype.
(GCC_DRIVER_HOST_INITIALIZATION): Update call to
darwin_default_min_version.
* config/i386/cygwin.h (mingw_scan): Update prototype.
(GCC_DRIVER_HOST_INITIALIZATION): Update call to mingw_scan.
* config/i386/cygwin1.c: Include opts.h.
(mingw_scan): Work with decoded options.
* config/i386/t-cygwin (cygwin1.o): Update dependencies.
* config/t-darwin (darwin-driver.o): Update dependencies.
From-SVN: r164532
Diffstat (limited to 'gcc/opts-common.c')
-rw-r--r-- | gcc/opts-common.c | 161 |
1 files changed, 60 insertions, 101 deletions
diff --git a/gcc/opts-common.c b/gcc/opts-common.c index 678b60e..078610f 100644 --- a/gcc/opts-common.c +++ b/gcc/opts-common.c @@ -27,6 +27,8 @@ along with GCC; see the file COPYING3. If not see #include "tm.h" /* For SWITCH_TAKES_ARG, WORD_SWITCH_TAKES_ARG and TARGET_OPTION_TRANSLATE_TABLE. */ +static void prune_options (struct cl_decoded_option **, unsigned int *); + /* Perform a binary search to find which option the command-line INPUT matches. Returns its index in the option array, and OPT_SPECIAL_unknown on failure. @@ -698,10 +700,9 @@ decode_cmdline_options_to_array (unsigned int argc, const char **argv, if (argv_copied) free (argv); - opt_array = XRESIZEVEC (struct cl_decoded_option, opt_array, - num_decoded_options); *decoded_options = opt_array; *decoded_options_count = num_decoded_options; + prune_options (decoded_options, decoded_options_count); } /* Return true if NEXT_OPT_IDX cancels OPT_IDX. Return false if the @@ -724,119 +725,77 @@ cancel_option (int opt_idx, int next_opt_idx, int orig_next_opt_idx) /* Filter out options canceled by the ones after them. */ -void -prune_options (int *argcp, char ***argvp) +static void +prune_options (struct cl_decoded_option **decoded_options, + unsigned int *decoded_options_count) { - int argc = *argcp; - int *options = XNEWVEC (int, argc); - /* We will only return this replacement argv if we remove at least - one argument, so it does not need to be size (argc + 1) to - make room for the terminating NULL because we will always have - freed up at least one slot when we end up using it at all. */ - char **argv = XNEWVEC (char *, argc); - int i, arg_count, need_prune = 0; + unsigned int old_decoded_options_count = *decoded_options_count; + struct cl_decoded_option *old_decoded_options = *decoded_options; + unsigned int new_decoded_options_count; + struct cl_decoded_option *new_decoded_options + = XNEWVEC (struct cl_decoded_option, old_decoded_options_count); + unsigned int i; const struct cl_option *option; - size_t opt_index; - - /* Scan all arguments. */ - for (i = 1; i < argc; i++) - { - int value = 1; - const char *opt = (*argvp) [i]; - - opt_index = find_opt (opt + 1, -1); - if (opt_index == OPT_SPECIAL_unknown - && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm') - && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-') - { - char *dup; - - /* Drop the "no-" from negative switches. */ - size_t len = strlen (opt) - 3; - - dup = XNEWVEC (char, len + 1); - dup[0] = '-'; - dup[1] = opt[1]; - memcpy (dup + 2, opt + 5, len - 2 + 1); - opt = dup; - value = 0; - opt_index = find_opt (opt + 1, -1); - free (dup); - } - - if (opt_index == OPT_SPECIAL_unknown) - { -cont: - options [i] = 0; - continue; - } - - option = &cl_options[opt_index]; - if (option->neg_index < 0) - goto cont; - - /* Skip joined switches. */ - if ((option->flags & CL_JOINED)) - goto cont; - - /* Reject negative form of switches that don't take negatives as - unrecognized. */ - if (!value && (option->flags & CL_REJECT_NEGATIVE)) - goto cont; - - options [i] = (int) opt_index; - need_prune |= options [i]; - } - - if (!need_prune) - goto done; /* Remove arguments which are negated by others after them. */ - argv [0] = (*argvp) [0]; - arg_count = 1; - for (i = 1; i < argc; i++) + new_decoded_options_count = 0; + for (i = 0; i < old_decoded_options_count; i++) { - int j, opt_idx; + unsigned int j, opt_idx, next_opt_idx; + + if (old_decoded_options[i].errors & ~CL_ERR_WRONG_LANG) + goto keep; - opt_idx = options [i]; - if (opt_idx) + opt_idx = old_decoded_options[i].opt_index; + switch (opt_idx) { - int next_opt_idx; - for (j = i + 1; j < argc; j++) + case OPT_SPECIAL_unknown: + case OPT_SPECIAL_ignore: + case OPT_SPECIAL_program_name: + case OPT_SPECIAL_input_file: + goto keep; + + default: + gcc_assert (opt_idx < cl_options_count); + option = &cl_options[opt_idx]; + if (option->neg_index < 0) + goto keep; + + /* Skip joined switches. */ + if ((option->flags & CL_JOINED)) + goto keep; + + for (j = i + 1; j < old_decoded_options_count; j++) { - next_opt_idx = options [j]; - if (next_opt_idx - && cancel_option (opt_idx, next_opt_idx, - next_opt_idx)) + if (old_decoded_options[j].errors & ~CL_ERR_WRONG_LANG) + continue; + next_opt_idx = old_decoded_options[j].opt_index; + if (next_opt_idx >= cl_options_count) + continue; + if (cl_options[next_opt_idx].neg_index < 0) + continue; + if ((cl_options[next_opt_idx].flags & CL_JOINED)) + continue; + if (cancel_option (opt_idx, next_opt_idx, next_opt_idx)) break; } - } - else - goto keep; - - if (j == argc) - { + if (j == old_decoded_options_count) + { keep: - argv [arg_count] = (*argvp) [i]; - arg_count++; + new_decoded_options[new_decoded_options_count] + = old_decoded_options[i]; + new_decoded_options_count++; + } + break; } } - if (arg_count != argc) - { - *argcp = arg_count; - *argvp = argv; - /* Add NULL-termination. Guaranteed not to overflow because - arg_count here can only be less than argc. */ - argv[arg_count] = 0; - } - else - { -done: - free (argv); - } - - free (options); + free (old_decoded_options); + new_decoded_options = XRESIZEVEC (struct cl_decoded_option, + new_decoded_options, + new_decoded_options_count); + *decoded_options = new_decoded_options; + *decoded_options_count = new_decoded_options_count; } /* Handle option DECODED for the language indicated by LANG_MASK, |