summaryrefslogtreecommitdiff
path: root/gcc/opts-common.c
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2010-07-27 21:23:53 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2010-07-27 21:23:53 +0000
commitb78351e5b501a68b78169103678db806cf610607 (patch)
treef94ec6c06f2efb7241fe151e3dc75cfb9af059a1 /gcc/opts-common.c
parente3baafb71a677c35245218a94fcb566a32b8b5f4 (diff)
downloadgcc-b78351e5b501a68b78169103678db806cf610607.tar.gz
* coretypes.h (struct cl_option_handlers): Declare.
* hooks.c (hook_int_size_t_constcharptr_int_0): Remove. * hooks.h (hook_int_size_t_constcharptr_int_0): Remove. * langhooks-def.h (lhd_handle_option): Declare. (LANG_HOOKS_HANDLE_OPTION): Use lhd_handle_option. * langhooks.c (lhd_handle_option): New. * langhooks.h (struct lang_hooks): Update prototype and return value type of handle_option hook. * optc-gen.awk: Generate target_flags_explicit definition for the driver. * opts-common.c: Include diagnostic.h. (handle_option): Move from opts.c. Update prototype and return value type. Use handlers structure. (read_cmdline_option): Move from opts.c. Update prototype. Use handlers structure. (set_option): Move from opts.c. * opts.c (common_handle_option): Update prototype and return value type. Update calls to handle_option and enable_warning_as_error. (unknown_option_callback, post_handling_callback, lang_handle_option, target_handle_option): New. (handle_option, read_cmdline_option): Move to opts-common.c. (read_cmdline_options): Update prototype. Update call to read_cmdline_option. (decode_options): Initialize and use handlers structure. (set_option): Move to opts-common.c. (enable_warning_as_error): Update prototype. Update call to handle_option. * opts.h (struct cl_option_handler_func, struct cl_option_handlers): New. (handle_option, enable_warning_as_error): Update prototypes. (read_cmdline_option): Declare. * Makefile.in (opts-common.o): Update dependencies. ada: * gcc-interface/misc.c (gnat_handle_option): Update prototype and return value type. Don't check for missing arguments here. c-family: * c-common.h (c_common_handle_option): Update prototype and return value type. * c-opts.c (c_common_handle_option): Update prototype and return value type. Update calls to handle_option and enable_warning_as_error. fortran: * gfortran.h (gfc_handle_option): Update prototype and return value type. * options.c (gfc_handle_option): Update prototype and return value type. java: * lang.c (java_handle_option): Update prototype and return value type. lto: * lto-lang.c (lto_handle_option): Update prototype and return value type. Remove duplicate assignment to result. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162601 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/opts-common.c')
-rw-r--r--gcc/opts-common.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 6b24b37ce5d..d84938ac9a3 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h"
#include "opts.h"
#include "options.h"
+#include "diagnostic.h"
/* Perform a binary search to find which option the command-line INPUT
matches. Returns its index in the option array, and
@@ -453,3 +454,136 @@ done:
free (options);
}
+
+/* Handle option OPT_INDEX, and argument ARG, for the language
+ indicated by LANG_MASK, using the handlers in HANDLERS. VALUE is
+ the option value as for the value field of cl_decoded_option. KIND
+ is the diagnostic_t if this is a diagnostics option, DK_UNSPECIFIED
+ otherwise. Returns false if the switch was invalid. */
+
+bool
+handle_option (size_t opt_index, const char *arg, int value,
+ unsigned int lang_mask, int kind,
+ const struct cl_option_handlers *handlers)
+{
+ const struct cl_option *option = &cl_options[opt_index];
+ size_t i;
+
+ if (option->flag_var)
+ set_option (opt_index, value, arg, kind);
+
+ for (i = 0; i < handlers->num_handlers; i++)
+ if (option->flags & handlers->handlers[i].mask)
+ {
+ if (!handlers->handlers[i].handler (opt_index, arg, value,
+ lang_mask, kind, handlers))
+ return false;
+ else
+ handlers->post_handling_callback (opt_index, arg, value,
+ handlers->handlers[i].mask);
+ }
+
+ return true;
+}
+
+/* Handle the switch DECODED for the language indicated by LANG_MASK,
+ using the handlers in *HANDLERS. */
+
+void
+read_cmdline_option (struct cl_decoded_option *decoded,
+ unsigned int lang_mask,
+ const struct cl_option_handlers *handlers)
+{
+ const struct cl_option *option;
+ const char *opt;
+
+ if (decoded->opt_index == OPT_SPECIAL_unknown)
+ {
+ opt = decoded->arg;
+
+ if (handlers->unknown_option_callback (opt))
+ error ("unrecognized command line option %qs", opt);
+ return;
+ }
+
+ option = &cl_options[decoded->opt_index];
+ opt = decoded->orig_option_with_args_text;
+
+ if (decoded->errors & CL_ERR_DISABLED)
+ {
+ error ("command line option %qs"
+ " is not supported by this configuration", opt);
+ return;
+ }
+
+ if (decoded->errors & CL_ERR_WRONG_LANG)
+ {
+ handlers->wrong_lang_callback (opt, option, lang_mask);
+ return;
+ }
+
+ if (decoded->errors & CL_ERR_MISSING_ARG)
+ {
+ if (option->missing_argument_error)
+ error (option->missing_argument_error, opt);
+ else
+ error ("missing argument to %qs", opt);
+ return;
+ }
+
+ if (decoded->errors & CL_ERR_UINT_ARG)
+ {
+ error ("argument to %qs should be a non-negative integer",
+ option->opt_text);
+ return;
+ }
+
+ gcc_assert (!decoded->errors);
+
+ if (!handle_option (decoded->opt_index, decoded->arg, decoded->value,
+ lang_mask, DK_UNSPECIFIED, handlers))
+ error ("unrecognized command line option %qs", opt);
+}
+
+/* Set any variable for option OPT_INDEX according to VALUE and ARG,
+ diagnostic kind KIND. */
+
+void
+set_option (int opt_index, int value, const char *arg, int kind)
+{
+ const struct cl_option *option = &cl_options[opt_index];
+
+ if (!option->flag_var)
+ return;
+
+ switch (option->var_type)
+ {
+ case CLVC_BOOLEAN:
+ *(int *) option->flag_var = value;
+ break;
+
+ case CLVC_EQUAL:
+ *(int *) option->flag_var = (value
+ ? option->var_value
+ : !option->var_value);
+ break;
+
+ case CLVC_BIT_CLEAR:
+ case CLVC_BIT_SET:
+ if ((value != 0) == (option->var_type == CLVC_BIT_SET))
+ *(int *) option->flag_var |= option->var_value;
+ else
+ *(int *) option->flag_var &= ~option->var_value;
+ if (option->flag_var == &target_flags)
+ target_flags_explicit |= option->var_value;
+ break;
+
+ case CLVC_STRING:
+ *(const char **) option->flag_var = arg;
+ break;
+ }
+
+ if ((diagnostic_t) kind != DK_UNSPECIFIED)
+ diagnostic_classify_diagnostic (global_dc, opt_index, (diagnostic_t) kind,
+ UNKNOWN_LOCATION);
+}