aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2010-08-11 11:04:43 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2010-08-11 11:04:43 +0100
commit481e1176d7614dcd519e50c488a155312280913e (patch)
tree48318d1dff4b32ecb5516a974e71f0e815752ba3
parent3abeaf8f89f246f481c869a09d0715a2762bde28 (diff)
downloadgcc-481e1176d7614dcd519e50c488a155312280913e.zip
gcc-481e1176d7614dcd519e50c488a155312280913e.tar.gz
gcc-481e1176d7614dcd519e50c488a155312280913e.tar.bz2
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
-rw-r--r--gcc/ChangeLog25
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-opts.c12
-rw-r--r--gcc/opts-common.c80
-rw-r--r--gcc/opts.c57
-rw-r--r--gcc/opts.h16
6 files changed, 145 insertions, 50 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a4662a7..ea4a0bb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,28 @@
+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>
* config/pa/linux-atomic.c (SUBWORD_VAL_CAS): Instantiate with
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 5227a9c..ce4fa36 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+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>
* c-pragma.c (add_to_renaming_pragma_list): Fix call to VEC_safe_push.
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 85e4cbf..b46b0a0 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -437,8 +437,8 @@ c_common_handle_option (size_t scode, const char *arg, int value,
case OPT_Wall:
warn_unused = value;
set_Wformat (value);
- handle_option (OPT_Wimplicit, NULL, value, c_family_lang_mask, kind,
- handlers);
+ handle_generated_option (OPT_Wimplicit, NULL, value,
+ c_family_lang_mask, kind, handlers);
warn_char_subscripts = value;
warn_missing_braces = value;
warn_parentheses = value;
@@ -539,11 +539,11 @@ c_common_handle_option (size_t scode, const char *arg, int value,
case OPT_Wimplicit:
gcc_assert (value == 0 || value == 1);
if (warn_implicit_int == -1)
- handle_option (OPT_Wimplicit_int, NULL, value,
- c_family_lang_mask, kind, handlers);
+ handle_generated_option (OPT_Wimplicit_int, NULL, value,
+ c_family_lang_mask, kind, handlers);
if (warn_implicit_function_declaration == -1)
- handle_option (OPT_Wimplicit_function_declaration, NULL, value,
- c_family_lang_mask, kind, handlers);
+ handle_generated_option (OPT_Wimplicit_function_declaration, NULL,
+ value, c_family_lang_mask, kind, handlers);
break;
case OPT_Wimport:
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 8028015..6125dfa 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -496,17 +496,19 @@ 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. */
+/* Handle option DECODED for the language indicated by LANG_MASK,
+ using the handlers in HANDLERS. 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,
+handle_option (const struct cl_decoded_option *decoded,
unsigned int lang_mask, int kind,
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];
size_t i;
@@ -516,17 +518,68 @@ handle_option (size_t opt_index, const char *arg, int value,
for (i = 0; i < handlers->num_handlers; i++)
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))
return false;
else
- handlers->post_handling_callback (opt_index, arg, value,
+ handlers->post_handling_callback (decoded,
handlers->handlers[i].mask);
}
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,
using the handlers in *HANDLERS. */
@@ -540,10 +593,8 @@ read_cmdline_option (struct cl_decoded_option *decoded,
if (decoded->opt_index == OPT_SPECIAL_unknown)
{
- opt = decoded->arg;
-
- if (handlers->unknown_option_callback (opt))
- error ("unrecognized command line option %qs", opt);
+ if (handlers->unknown_option_callback (decoded))
+ error ("unrecognized command line option %qs", decoded->arg);
return;
}
@@ -559,7 +610,7 @@ read_cmdline_option (struct cl_decoded_option *decoded,
if (decoded->errors & CL_ERR_WRONG_LANG)
{
- handlers->wrong_lang_callback (opt, option, lang_mask);
+ handlers->wrong_lang_callback (decoded, lang_mask);
return;
}
@@ -581,8 +632,7 @@ read_cmdline_option (struct cl_decoded_option *decoded,
gcc_assert (!decoded->errors);
- if (!handle_option (decoded->opt_index, decoded->arg, decoded->value,
- lang_mask, DK_UNSPECIFIED, handlers))
+ if (!handle_option (decoded, lang_mask, DK_UNSPECIFIED, handlers))
error ("unrecognized command line option %qs", opt);
}
diff --git a/gcc/opts.c b/gcc/opts.c
index 967ad40..6e52805 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -372,12 +372,12 @@ bool flag_warn_unused_result = false;
const char **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,
const struct cl_option_handlers *handlers);
static void handle_param (const char *);
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);
static void set_debug_level (enum debug_info_type type, int extended,
const char *arg);
@@ -410,11 +410,14 @@ write_langs (unsigned int mask)
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
-complain_wrong_lang (const char *text, const struct cl_option *option,
+complain_wrong_lang (const struct cl_decoded_option *decoded,
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;
if (!lang_hooks.complain_wrong_lang_p (option))
@@ -461,12 +464,14 @@ void print_ignored_options (void)
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. */
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] == '-')
{
/* We don't generate warnings for unknown -Wno-* options unless
@@ -478,17 +483,16 @@ unknown_option_callback (const char *opt)
return true;
}
-/* Note that an option (index OPT_INDEX, argument ARG, value VALUE)
- has been successfully handled with a handler for mask MASK. */
+/* Note that an option DECODED has been successfully handled with a
+ handler for mask MASK. */
static void
-post_handling_callback (size_t opt_index ATTRIBUTE_UNUSED,
- const char *arg ATTRIBUTE_UNUSED,
- int value ATTRIBUTE_UNUSED,
+post_handling_callback (const struct cl_decoded_option *decoded ATTRIBUTE_UNUSED,
unsigned int mask ATTRIBUTE_UNUSED)
{
#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
}
@@ -496,23 +500,27 @@ post_handling_callback (size_t opt_index ATTRIBUTE_UNUSED,
handle_option. */
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,
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_option. */
static bool
-target_handle_option (size_t opt_index, const char *arg, int value,
- unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
- const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
+target_handle_option (const struct cl_decoded_option *decoded,
+ unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
+ const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
{
+ gcc_assert (decoded->canonical_option_num_elements <= 2);
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. */
@@ -1387,16 +1395,21 @@ print_specific_help (unsigned int include_flags,
/* Handle target- and language-independent options. Return zero to
generate an "unknown option" message. Only options that need
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
-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,
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;
enum opt_code code = (enum opt_code) scode;
+ gcc_assert (decoded->canonical_option_num_elements <= 2);
+
switch (code)
{
case OPT__param:
@@ -2358,8 +2371,8 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
/* -Werror=foo implies -Wfoo. */
if (option->var_type == CLVC_BOOLEAN)
- handle_option (option_index, arg, value, lang_mask, (int)kind,
- handlers);
+ handle_generated_option (option_index, NULL, value, lang_mask,
+ (int)kind, handlers);
if (warning_as_error_callback)
warning_as_error_callback (option_index);
diff --git a/gcc/opts.h b/gcc/opts.h
index 005a846..d6412c3 100644
--- a/gcc/opts.h
+++ b/gcc/opts.h
@@ -142,7 +142,7 @@ struct cl_decoded_option
struct cl_option_handler_func
{
/* 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,
const struct cl_option_handlers *handlers);
@@ -159,17 +159,16 @@ struct cl_option_handlers
error for it, and possibly store information to diagnose the
option at a later point. Return true if an error should be
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
language. */
- void (*wrong_lang_callback) (const char *text,
- const struct cl_option *option,
+ void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
unsigned int lang_mask);
/* Callback to call after the successful handling of any option. */
- void (*post_handling_callback) (size_t opt_index, const char *arg,
- int value, unsigned int mask);
+ void (*post_handling_callback) (const struct cl_decoded_option *decoded,
+ unsigned int mask);
/* The number of individual handlers. */
size_t num_handlers;
@@ -200,9 +199,12 @@ extern void decode_options (unsigned int argc, const char **argv,
extern int option_enabled (int opt_idx);
extern bool get_option_state (int, struct cl_option_state *);
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,
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,
unsigned int lang_mask,
const struct cl_option_handlers *handlers);