Commit 481e1176 by Joseph Myers Committed by Joseph Myers

opts.h (struct cl_option_handler_func): Make handler take cl_decoded_option…

opts.h (struct cl_option_handler_func): Make handler take cl_decoded_option structure as parameter, not individual elements.

	* opts.h (struct cl_option_handler_func): Make handler take
	cl_decoded_option structure as parameter, not individual elements.
	(struct cl_option_handlers): Make callbacks take cl_decoded_option
	structure as parameter, not individual elements.
	(handle_option): Take cl_decoded_option structure as parameter,
	not individual elements.
	(handle_generated_option): Declare.
	* opts-common.c (handle_option): Take cl_decoded_option structure
	as parameter, not individual elements.  Update calls to callback
	and handler functions.
	(handle_generated_option): New.
	(read_cmdline_option): Update calls to callback functions and
	handle_option.
	* opts.c (common_handle_option, complain_wrong_lang,
	unknown_option_callback, post_handling_callback,
	lang_handle_option, target_handle_option): Take cl_decoded_option
	structure as parameter, not individual elements.
	(lang_handle_option, target_handle_option, common_handle_option):
	Assert option has at most one argument.
	(enable_warning_as_error): Call handle_generated_option instead of
	handle_option.  Do not pass -Werror argument as argument of
	generated option.

c-family:
	* c-opts.c (c_common_handle_option): Call handle_generated_option
	instead of handle_option.

From-SVN: r163095
parent 3abeaf8f
2010-08-11 Joseph Myers <joseph@codesourcery.com>
* opts.h (struct cl_option_handler_func): Make handler take
cl_decoded_option structure as parameter, not individual elements.
(struct cl_option_handlers): Make callbacks take cl_decoded_option
structure as parameter, not individual elements.
(handle_option): Take cl_decoded_option structure as parameter,
not individual elements.
(handle_generated_option): Declare.
* opts-common.c (handle_option): Take cl_decoded_option structure
as parameter, not individual elements. Update calls to callback
and handler functions.
(handle_generated_option): New.
(read_cmdline_option): Update calls to callback functions and
handle_option.
* opts.c (common_handle_option, complain_wrong_lang,
unknown_option_callback, post_handling_callback,
lang_handle_option, target_handle_option): Take cl_decoded_option
structure as parameter, not individual elements.
(lang_handle_option, target_handle_option, common_handle_option):
Assert option has at most one argument.
(enable_warning_as_error): Call handle_generated_option instead of
handle_option. Do not pass -Werror argument as argument of
generated option.
2010-08-10 John David Anglin <dave.anglin@nrc-cnrc.gc.ca> 2010-08-10 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
* config/pa/linux-atomic.c (SUBWORD_VAL_CAS): Instantiate with * config/pa/linux-atomic.c (SUBWORD_VAL_CAS): Instantiate with
......
2010-08-11 Joseph Myers <joseph@codesourcery.com>
* c-opts.c (c_common_handle_option): Call handle_generated_option
instead of handle_option.
2010-08-08 Nathan Froyd <froydnj@codesourcery.com> 2010-08-08 Nathan Froyd <froydnj@codesourcery.com>
* c-pragma.c (add_to_renaming_pragma_list): Fix call to VEC_safe_push. * c-pragma.c (add_to_renaming_pragma_list): Fix call to VEC_safe_push.
......
...@@ -437,8 +437,8 @@ c_common_handle_option (size_t scode, const char *arg, int value, ...@@ -437,8 +437,8 @@ c_common_handle_option (size_t scode, const char *arg, int value,
case OPT_Wall: case OPT_Wall:
warn_unused = value; warn_unused = value;
set_Wformat (value); set_Wformat (value);
handle_option (OPT_Wimplicit, NULL, value, c_family_lang_mask, kind, handle_generated_option (OPT_Wimplicit, NULL, value,
handlers); c_family_lang_mask, kind, handlers);
warn_char_subscripts = value; warn_char_subscripts = value;
warn_missing_braces = value; warn_missing_braces = value;
warn_parentheses = value; warn_parentheses = value;
...@@ -539,11 +539,11 @@ c_common_handle_option (size_t scode, const char *arg, int value, ...@@ -539,11 +539,11 @@ c_common_handle_option (size_t scode, const char *arg, int value,
case OPT_Wimplicit: case OPT_Wimplicit:
gcc_assert (value == 0 || value == 1); gcc_assert (value == 0 || value == 1);
if (warn_implicit_int == -1) if (warn_implicit_int == -1)
handle_option (OPT_Wimplicit_int, NULL, value, handle_generated_option (OPT_Wimplicit_int, NULL, value,
c_family_lang_mask, kind, handlers); c_family_lang_mask, kind, handlers);
if (warn_implicit_function_declaration == -1) if (warn_implicit_function_declaration == -1)
handle_option (OPT_Wimplicit_function_declaration, NULL, value, handle_generated_option (OPT_Wimplicit_function_declaration, NULL,
c_family_lang_mask, kind, handlers); value, c_family_lang_mask, kind, handlers);
break; break;
case OPT_Wimport: case OPT_Wimport:
......
...@@ -496,17 +496,19 @@ done: ...@@ -496,17 +496,19 @@ done:
free (options); free (options);
} }
/* Handle option OPT_INDEX, and argument ARG, for the language /* Handle option DECODED for the language indicated by LANG_MASK,
indicated by LANG_MASK, using the handlers in HANDLERS. VALUE is using the handlers in HANDLERS. KIND is the diagnostic_t if this
the option value as for the value field of cl_decoded_option. KIND is a diagnostics option, DK_UNSPECIFIED otherwise. Returns false
is the diagnostic_t if this is a diagnostics option, DK_UNSPECIFIED if the switch was invalid. */
otherwise. Returns false if the switch was invalid. */
bool bool
handle_option (size_t opt_index, const char *arg, int value, handle_option (const struct cl_decoded_option *decoded,
unsigned int lang_mask, int kind, unsigned int lang_mask, int kind,
const struct cl_option_handlers *handlers) const struct cl_option_handlers *handlers)
{ {
size_t opt_index = decoded->opt_index;
const char *arg = decoded->arg;
int value = decoded->value;
const struct cl_option *option = &cl_options[opt_index]; const struct cl_option *option = &cl_options[opt_index];
size_t i; size_t i;
...@@ -516,17 +518,68 @@ handle_option (size_t opt_index, const char *arg, int value, ...@@ -516,17 +518,68 @@ handle_option (size_t opt_index, const char *arg, int value,
for (i = 0; i < handlers->num_handlers; i++) for (i = 0; i < handlers->num_handlers; i++)
if (option->flags & handlers->handlers[i].mask) if (option->flags & handlers->handlers[i].mask)
{ {
if (!handlers->handlers[i].handler (opt_index, arg, value, if (!handlers->handlers[i].handler (decoded,
lang_mask, kind, handlers)) lang_mask, kind, handlers))
return false; return false;
else else
handlers->post_handling_callback (opt_index, arg, value, handlers->post_handling_callback (decoded,
handlers->handlers[i].mask); handlers->handlers[i].mask);
} }
return true; return true;
} }
/* Like handle_option, but OPT_INDEX, ARG and VALUE describe the
option instead of DECODED. This is used for callbacks when one
option implies another instead of an option being decoded from the
command line. */
bool
handle_generated_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];
struct cl_decoded_option decoded;
decoded.opt_index = opt_index;
decoded.arg = arg;
decoded.canonical_option[2] = NULL;
decoded.canonical_option[3] = NULL;
decoded.value = value;
decoded.errors = 0;
if (arg)
{
if (option->flags & CL_SEPARATE)
{
decoded.orig_option_with_args_text = concat (option->opt_text, " ",
arg, NULL);
decoded.canonical_option[0] = option->opt_text;
decoded.canonical_option[1] = arg;
decoded.canonical_option_num_elements = 2;
}
else
{
gcc_assert (option->flags & CL_JOINED);
decoded.orig_option_with_args_text = concat (option->opt_text, arg,
NULL);
decoded.canonical_option[0] = decoded.orig_option_with_args_text;
decoded.canonical_option[1] = NULL;
decoded.canonical_option_num_elements = 1;
}
}
else
{
decoded.orig_option_with_args_text = option->opt_text;
decoded.canonical_option[0] = option->opt_text;
decoded.canonical_option[1] = NULL;
decoded.canonical_option_num_elements = 1;
}
return handle_option (&decoded, lang_mask, kind, handlers);
}
/* Handle the switch DECODED for the language indicated by LANG_MASK, /* Handle the switch DECODED for the language indicated by LANG_MASK,
using the handlers in *HANDLERS. */ using the handlers in *HANDLERS. */
...@@ -540,10 +593,8 @@ read_cmdline_option (struct cl_decoded_option *decoded, ...@@ -540,10 +593,8 @@ read_cmdline_option (struct cl_decoded_option *decoded,
if (decoded->opt_index == OPT_SPECIAL_unknown) if (decoded->opt_index == OPT_SPECIAL_unknown)
{ {
opt = decoded->arg; if (handlers->unknown_option_callback (decoded))
error ("unrecognized command line option %qs", decoded->arg);
if (handlers->unknown_option_callback (opt))
error ("unrecognized command line option %qs", opt);
return; return;
} }
...@@ -559,7 +610,7 @@ read_cmdline_option (struct cl_decoded_option *decoded, ...@@ -559,7 +610,7 @@ read_cmdline_option (struct cl_decoded_option *decoded,
if (decoded->errors & CL_ERR_WRONG_LANG) if (decoded->errors & CL_ERR_WRONG_LANG)
{ {
handlers->wrong_lang_callback (opt, option, lang_mask); handlers->wrong_lang_callback (decoded, lang_mask);
return; return;
} }
...@@ -581,8 +632,7 @@ read_cmdline_option (struct cl_decoded_option *decoded, ...@@ -581,8 +632,7 @@ read_cmdline_option (struct cl_decoded_option *decoded,
gcc_assert (!decoded->errors); gcc_assert (!decoded->errors);
if (!handle_option (decoded->opt_index, decoded->arg, decoded->value, if (!handle_option (decoded, lang_mask, DK_UNSPECIFIED, handlers))
lang_mask, DK_UNSPECIFIED, handlers))
error ("unrecognized command line option %qs", opt); error ("unrecognized command line option %qs", opt);
} }
......
...@@ -372,12 +372,12 @@ bool flag_warn_unused_result = false; ...@@ -372,12 +372,12 @@ bool flag_warn_unused_result = false;
const char **in_fnames; const char **in_fnames;
unsigned num_in_fnames; unsigned num_in_fnames;
static bool common_handle_option (size_t scode, const char *arg, int value, static bool common_handle_option (const struct cl_decoded_option *decoded,
unsigned int lang_mask, int kind, unsigned int lang_mask, int kind,
const struct cl_option_handlers *handlers); const struct cl_option_handlers *handlers);
static void handle_param (const char *); static void handle_param (const char *);
static char *write_langs (unsigned int lang_mask); static char *write_langs (unsigned int lang_mask);
static void complain_wrong_lang (const char *, const struct cl_option *, static void complain_wrong_lang (const struct cl_decoded_option *,
unsigned int lang_mask); unsigned int lang_mask);
static void set_debug_level (enum debug_info_type type, int extended, static void set_debug_level (enum debug_info_type type, int extended,
const char *arg); const char *arg);
...@@ -410,11 +410,14 @@ write_langs (unsigned int mask) ...@@ -410,11 +410,14 @@ write_langs (unsigned int mask)
return result; return result;
} }
/* Complain that switch OPT_INDEX does not apply to this front end. */ /* Complain that switch DECODED does not apply to this front end (mask
LANG_MASK). */
static void static void
complain_wrong_lang (const char *text, const struct cl_option *option, complain_wrong_lang (const struct cl_decoded_option *decoded,
unsigned int lang_mask) unsigned int lang_mask)
{ {
const struct cl_option *option = &cl_options[decoded->opt_index];
const char *text = decoded->orig_option_with_args_text;
char *ok_langs, *bad_lang; char *ok_langs, *bad_lang;
if (!lang_hooks.complain_wrong_lang_p (option)) if (!lang_hooks.complain_wrong_lang_p (option))
...@@ -461,12 +464,14 @@ void print_ignored_options (void) ...@@ -461,12 +464,14 @@ void print_ignored_options (void)
input_location = saved_loc; input_location = saved_loc;
} }
/* Handle an unknown option ARG, returning true if an error should be /* Handle an unknown option DECODED, returning true if an error should be
given. */ given. */
static bool static bool
unknown_option_callback (const char *opt) unknown_option_callback (const struct cl_decoded_option *decoded)
{ {
const char *opt = decoded->arg;
if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-') if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
{ {
/* We don't generate warnings for unknown -Wno-* options unless /* We don't generate warnings for unknown -Wno-* options unless
...@@ -478,17 +483,16 @@ unknown_option_callback (const char *opt) ...@@ -478,17 +483,16 @@ unknown_option_callback (const char *opt)
return true; return true;
} }
/* Note that an option (index OPT_INDEX, argument ARG, value VALUE) /* Note that an option DECODED has been successfully handled with a
has been successfully handled with a handler for mask MASK. */ handler for mask MASK. */
static void static void
post_handling_callback (size_t opt_index ATTRIBUTE_UNUSED, post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
const char *arg ATTRIBUTE_UNUSED,
int value ATTRIBUTE_UNUSED,
unsigned int mask ATTRIBUTE_UNUSED) unsigned int mask ATTRIBUTE_UNUSED)
{ {
#ifdef ENABLE_LTO #ifdef ENABLE_LTO
lto_register_user_option (opt_index, arg, value, mask); lto_register_user_option (decoded->opt_index, decoded->arg,
decoded->value, mask);
#endif #endif
} }
...@@ -496,23 +500,27 @@ post_handling_callback (size_t opt_index ATTRIBUTE_UNUSED, ...@@ -496,23 +500,27 @@ post_handling_callback (size_t opt_index ATTRIBUTE_UNUSED,
handle_option. */ handle_option. */
static bool static bool
lang_handle_option (size_t opt_index, const char *arg, int value, lang_handle_option (const struct cl_decoded_option *decoded,
unsigned int lang_mask ATTRIBUTE_UNUSED, int kind, unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
const struct cl_option_handlers *handlers) const struct cl_option_handlers *handlers)
{ {
return lang_hooks.handle_option (opt_index, arg, value, kind, handlers); gcc_assert (decoded->canonical_option_num_elements <= 2);
return lang_hooks.handle_option (decoded->opt_index, decoded->arg,
decoded->value, kind, handlers);
} }
/* Handle a back-end option; arguments and return value as for /* Handle a back-end option; arguments and return value as for
handle_option. */ handle_option. */
static bool static bool
target_handle_option (size_t opt_index, const char *arg, int value, target_handle_option (const struct cl_decoded_option *decoded,
unsigned int lang_mask ATTRIBUTE_UNUSED, int kind, unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED) const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
{ {
gcc_assert (decoded->canonical_option_num_elements <= 2);
gcc_assert (kind == DK_UNSPECIFIED); gcc_assert (kind == DK_UNSPECIFIED);
return targetm.handle_option (opt_index, arg, value); return targetm.handle_option (decoded->opt_index, decoded->arg,
decoded->value);
} }
/* Handle FILENAME from the command line. */ /* Handle FILENAME from the command line. */
...@@ -1387,16 +1395,21 @@ print_specific_help (unsigned int include_flags, ...@@ -1387,16 +1395,21 @@ print_specific_help (unsigned int include_flags,
/* Handle target- and language-independent options. Return zero to /* Handle target- and language-independent options. Return zero to
generate an "unknown option" message. Only options that need generate an "unknown option" message. Only options that need
extra handling need to be listed here; if you simply want extra handling need to be listed here; if you simply want
VALUE assigned to a variable, it happens automatically. */ DECODED->value assigned to a variable, it happens automatically. */
static bool static bool
common_handle_option (size_t scode, const char *arg, int value, common_handle_option (const struct cl_decoded_option *decoded,
unsigned int lang_mask, int kind ATTRIBUTE_UNUSED, unsigned int lang_mask, int kind ATTRIBUTE_UNUSED,
const struct cl_option_handlers *handlers) const struct cl_option_handlers *handlers)
{ {
size_t scode = decoded->opt_index;
const char *arg = decoded->arg;
int value = decoded->value;
static bool verbose = false; static bool verbose = false;
enum opt_code code = (enum opt_code) scode; enum opt_code code = (enum opt_code) scode;
gcc_assert (decoded->canonical_option_num_elements <= 2);
switch (code) switch (code)
{ {
case OPT__param: case OPT__param:
...@@ -2358,8 +2371,8 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask, ...@@ -2358,8 +2371,8 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
/* -Werror=foo implies -Wfoo. */ /* -Werror=foo implies -Wfoo. */
if (option->var_type == CLVC_BOOLEAN) if (option->var_type == CLVC_BOOLEAN)
handle_option (option_index, arg, value, lang_mask, (int)kind, handle_generated_option (option_index, NULL, value, lang_mask,
handlers); (int)kind, handlers);
if (warning_as_error_callback) if (warning_as_error_callback)
warning_as_error_callback (option_index); warning_as_error_callback (option_index);
......
...@@ -142,7 +142,7 @@ struct cl_decoded_option ...@@ -142,7 +142,7 @@ struct cl_decoded_option
struct cl_option_handler_func struct cl_option_handler_func
{ {
/* The function called to handle the option. */ /* The function called to handle the option. */
bool (*handler) (size_t opt_index, const char *arg, int value, bool (*handler) (const struct cl_decoded_option *decoded,
unsigned int lang_mask, int kind, unsigned int lang_mask, int kind,
const struct cl_option_handlers *handlers); const struct cl_option_handlers *handlers);
...@@ -159,17 +159,16 @@ struct cl_option_handlers ...@@ -159,17 +159,16 @@ struct cl_option_handlers
error for it, and possibly store information to diagnose the error for it, and possibly store information to diagnose the
option at a later point. Return true if an error should be option at a later point. Return true if an error should be
given, false otherwise. */ given, false otherwise. */
bool (*unknown_option_callback) (const char *opt); bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
/* Callback to handle, and possibly diagnose, an option for another /* Callback to handle, and possibly diagnose, an option for another
language. */ language. */
void (*wrong_lang_callback) (const char *text, void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
const struct cl_option *option,
unsigned int lang_mask); unsigned int lang_mask);
/* Callback to call after the successful handling of any option. */ /* Callback to call after the successful handling of any option. */
void (*post_handling_callback) (size_t opt_index, const char *arg, void (*post_handling_callback) (const struct cl_decoded_option *decoded,
int value, unsigned int mask); unsigned int mask);
/* The number of individual handlers. */ /* The number of individual handlers. */
size_t num_handlers; size_t num_handlers;
...@@ -200,9 +199,12 @@ extern void decode_options (unsigned int argc, const char **argv, ...@@ -200,9 +199,12 @@ extern void decode_options (unsigned int argc, const char **argv,
extern int option_enabled (int opt_idx); extern int option_enabled (int opt_idx);
extern bool get_option_state (int, struct cl_option_state *); extern bool get_option_state (int, struct cl_option_state *);
extern void set_option (int opt_index, int value, const char *arg, int); extern void set_option (int opt_index, int value, const char *arg, int);
bool handle_option (size_t opt_index, const char *arg, int value, bool handle_option (const struct cl_decoded_option *decoded,
unsigned int lang_mask, int kind, unsigned int lang_mask, int kind,
const struct cl_option_handlers *handlers); const struct cl_option_handlers *handlers);
bool handle_generated_option (size_t opt_index, const char *arg, int value,
unsigned int lang_mask, int kind,
const struct cl_option_handlers *handlers);
extern void read_cmdline_option (struct cl_decoded_option *decoded, extern void read_cmdline_option (struct cl_decoded_option *decoded,
unsigned int lang_mask, unsigned int lang_mask,
const struct cl_option_handlers *handlers); const struct cl_option_handlers *handlers);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment