invalid, a negative number to prevent language-independent
processing in toplev.c (a hack necessary for the short-term). */
int
-c_common_handle_option (size_t scode, const char *arg, int on)
+c_common_handle_option (size_t scode, const char *arg, int value)
{
const struct cl_option *option = &cl_options[scode];
enum opt_code code = (enum opt_code) scode;
lang_mask = lang_flags[(c_language << 1) + flag_objc];
if (!(option->flags & lang_mask))
{
- complain_wrong_lang (code, on);
+ complain_wrong_lang (code, value);
return 1;
}
break;
case OPT_Wabi:
- warn_abi = on;
+ warn_abi = value;
break;
case OPT_Wall:
- set_Wunused (on);
- set_Wformat (on);
- set_Wimplicit (on);
- warn_char_subscripts = on;
- warn_missing_braces = on;
- warn_parentheses = on;
- warn_return_type = on;
- warn_sequence_point = on; /* Was C only. */
+ set_Wunused (value);
+ set_Wformat (value);
+ set_Wimplicit (value);
+ warn_char_subscripts = value;
+ warn_missing_braces = value;
+ warn_parentheses = value;
+ warn_return_type = value;
+ warn_sequence_point = value; /* Was C only. */
if (c_language == clk_cplusplus)
- warn_sign_compare = on;
- warn_switch = on;
- warn_strict_aliasing = on;
+ warn_sign_compare = value;
+ warn_switch = value;
+ warn_strict_aliasing = value;
/* Only warn about unknown pragmas that are not in system
headers. */
- warn_unknown_pragmas = on;
+ warn_unknown_pragmas = value;
/* We save the value of warn_uninitialized, since if they put
-Wuninitialized on the command line, we need to generate a
warning about not using it without also specifying -O. */
if (warn_uninitialized != 1)
- warn_uninitialized = (on ? 2 : 0);
+ warn_uninitialized = (value ? 2 : 0);
if (c_language == clk_c)
/* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
can turn it off only if it's not explicit. */
- warn_main = on * 2;
+ warn_main = value * 2;
else
{
/* C++-specific warnings. */
- warn_nonvdtor = on;
- warn_reorder = on;
- warn_nontemplate_friend = on;
+ warn_nonvdtor = value;
+ warn_reorder = value;
+ warn_nontemplate_friend = value;
}
- cpp_opts->warn_trigraphs = on;
- cpp_opts->warn_comments = on;
- cpp_opts->warn_num_sign_change = on;
- cpp_opts->warn_multichar = on; /* Was C++ only. */
+ cpp_opts->warn_trigraphs = value;
+ cpp_opts->warn_comments = value;
+ cpp_opts->warn_num_sign_change = value;
+ cpp_opts->warn_multichar = value; /* Was C++ only. */
break;
case OPT_Wbad_function_cast:
- warn_bad_function_cast = on;
+ warn_bad_function_cast = value;
break;
case OPT_Wcast_qual:
- warn_cast_qual = on;
+ warn_cast_qual = value;
break;
case OPT_Wchar_subscripts:
- warn_char_subscripts = on;
+ warn_char_subscripts = value;
break;
case OPT_Wcomment:
case OPT_Wcomments:
- cpp_opts->warn_comments = on;
+ cpp_opts->warn_comments = value;
break;
case OPT_Wconversion:
- warn_conversion = on;
+ warn_conversion = value;
break;
case OPT_Wctor_dtor_privacy:
- warn_ctor_dtor_privacy = on;
+ warn_ctor_dtor_privacy = value;
break;
case OPT_Wdeprecated:
- warn_deprecated = on;
- cpp_opts->warn_deprecated = on;
+ warn_deprecated = value;
+ cpp_opts->warn_deprecated = value;
break;
case OPT_Wdiv_by_zero:
- warn_div_by_zero = on;
+ warn_div_by_zero = value;
break;
case OPT_Weffc__:
- warn_ecpp = on;
+ warn_ecpp = value;
break;
case OPT_Wendif_labels:
- cpp_opts->warn_endif_labels = on;
+ cpp_opts->warn_endif_labels = value;
break;
case OPT_Werror:
- cpp_opts->warnings_are_errors = on;
+ cpp_opts->warnings_are_errors = value;
break;
case OPT_Werror_implicit_function_declaration:
break;
case OPT_Wfloat_equal:
- warn_float_equal = on;
+ warn_float_equal = value;
break;
case OPT_Wformat:
- set_Wformat (on);
+ set_Wformat (value);
break;
case OPT_Wformat_:
break;
case OPT_Wformat_extra_args:
- warn_format_extra_args = on;
+ warn_format_extra_args = value;
break;
case OPT_Wformat_nonliteral:
- warn_format_nonliteral = on;
+ warn_format_nonliteral = value;
break;
case OPT_Wformat_security:
- warn_format_security = on;
+ warn_format_security = value;
break;
case OPT_Wformat_y2k:
- warn_format_y2k = on;
+ warn_format_y2k = value;
break;
case OPT_Wformat_zero_length:
- warn_format_zero_length = on;
+ warn_format_zero_length = value;
break;
case OPT_Wimplicit:
- set_Wimplicit (on);
+ set_Wimplicit (value);
break;
case OPT_Wimplicit_function_declaration:
- mesg_implicit_function_declaration = on;
+ mesg_implicit_function_declaration = value;
break;
case OPT_Wimplicit_int:
- warn_implicit_int = on;
+ warn_implicit_int = value;
break;
case OPT_Wimport:
- cpp_opts->warn_import = on;
+ cpp_opts->warn_import = value;
break;
case OPT_Winvalid_offsetof:
- warn_invalid_offsetof = on;
+ warn_invalid_offsetof = value;
break;
case OPT_Winvalid_pch:
- cpp_opts->warn_invalid_pch = on;
+ cpp_opts->warn_invalid_pch = value;
break;
case OPT_Wlong_long:
- warn_long_long = on;
+ warn_long_long = value;
break;
case OPT_Wmain:
- if (on)
+ if (value)
warn_main = 1;
else
warn_main = -1;
break;
case OPT_Wmissing_braces:
- warn_missing_braces = on;
+ warn_missing_braces = value;
break;
case OPT_Wmissing_declarations:
- warn_missing_declarations = on;
+ warn_missing_declarations = value;
break;
case OPT_Wmissing_format_attribute:
- warn_missing_format_attribute = on;
+ warn_missing_format_attribute = value;
break;
case OPT_Wmissing_prototypes:
- warn_missing_prototypes = on;
+ warn_missing_prototypes = value;
break;
case OPT_Wmultichar:
- cpp_opts->warn_multichar = on;
+ cpp_opts->warn_multichar = value;
break;
case OPT_Wnested_externs:
- warn_nested_externs = on;
+ warn_nested_externs = value;
break;
case OPT_Wnon_template_friend:
- warn_nontemplate_friend = on;
+ warn_nontemplate_friend = value;
break;
case OPT_Wnon_virtual_dtor:
- warn_nonvdtor = on;
+ warn_nonvdtor = value;
break;
case OPT_Wnonnull:
- warn_nonnull = on;
+ warn_nonnull = value;
break;
case OPT_Wold_style_cast:
- warn_old_style_cast = on;
+ warn_old_style_cast = value;
break;
case OPT_Woverloaded_virtual:
- warn_overloaded_virtual = on;
+ warn_overloaded_virtual = value;
break;
case OPT_Wparentheses:
- warn_parentheses = on;
+ warn_parentheses = value;
break;
case OPT_Wpmf_conversions:
- warn_pmf2ptr = on;
+ warn_pmf2ptr = value;
break;
case OPT_Wpointer_arith:
- warn_pointer_arith = on;
+ warn_pointer_arith = value;
break;
case OPT_Wprotocol:
- warn_protocol = on;
+ warn_protocol = value;
break;
case OPT_Wselector:
- warn_selector = on;
+ warn_selector = value;
break;
case OPT_Wredundant_decls:
- warn_redundant_decls = on;
+ warn_redundant_decls = value;
break;
case OPT_Wreorder:
- warn_reorder = on;
+ warn_reorder = value;
break;
case OPT_Wreturn_type:
- warn_return_type = on;
+ warn_return_type = value;
break;
case OPT_Wsequence_point:
- warn_sequence_point = on;
+ warn_sequence_point = value;
break;
case OPT_Wsign_compare:
- warn_sign_compare = on;
+ warn_sign_compare = value;
break;
case OPT_Wsign_promo:
- warn_sign_promo = on;
+ warn_sign_promo = value;
break;
case OPT_Wstrict_prototypes:
- warn_strict_prototypes = on;
+ warn_strict_prototypes = value;
break;
case OPT_Wsynth:
- warn_synth = on;
+ warn_synth = value;
break;
case OPT_Wsystem_headers:
- cpp_opts->warn_system_headers = on;
+ cpp_opts->warn_system_headers = value;
break;
case OPT_Wtraditional:
- warn_traditional = on;
- cpp_opts->warn_traditional = on;
+ warn_traditional = value;
+ cpp_opts->warn_traditional = value;
break;
case OPT_Wtrigraphs:
- cpp_opts->warn_trigraphs = on;
+ cpp_opts->warn_trigraphs = value;
break;
case OPT_Wundeclared_selector:
- warn_undeclared_selector = on;
+ warn_undeclared_selector = value;
break;
case OPT_Wundef:
- cpp_opts->warn_undef = on;
+ cpp_opts->warn_undef = value;
break;
case OPT_Wunknown_pragmas:
/* Set to greater than 1, so that even unknown pragmas in
system headers will be warned about. */
- warn_unknown_pragmas = on * 2;
+ warn_unknown_pragmas = value * 2;
break;
case OPT_Wunused_macros:
- warn_unused_macros = on;
+ warn_unused_macros = value;
break;
case OPT_Wwrite_strings:
if (c_language == clk_c)
- flag_const_strings = on;
+ flag_const_strings = value;
else
- warn_write_strings = on;
+ warn_write_strings = value;
break;
case OPT_ansi:
case OPT_fcond_mismatch:
if (c_language == clk_c)
{
- flag_cond_mismatch = on;
+ flag_cond_mismatch = value;
break;
}
/* Fall through. */
break;
case OPT_fabi_version_:
- flag_abi_version = read_integral_parameter (arg, option->opt_text, 1);
+ flag_abi_version = value;
break;
case OPT_faccess_control:
- flag_access_control = on;
+ flag_access_control = value;
break;
case OPT_falt_external_templates:
- flag_alt_external_templates = on;
- if (on)
+ flag_alt_external_templates = value;
+ if (value)
flag_external_templates = true;
cp_deprecated:
warning ("switch \"%s\" is deprecated, please see documentation for details", option->opt_text);
break;
case OPT_fasm:
- flag_no_asm = !on;
+ flag_no_asm = !value;
break;
case OPT_fbuiltin:
- flag_no_builtin = !on;
+ flag_no_builtin = !value;
break;
case OPT_fbuiltin_:
- if (on)
+ if (value)
result = 0;
else
disable_builtin_function (arg);
break;
case OPT_fdollars_in_identifiers:
- cpp_opts->dollars_in_ident = on;
+ cpp_opts->dollars_in_ident = value;
break;
case OPT_fdump_:
break;
case OPT_ffreestanding:
- on = !on;
+ value = !value;
/* Fall through... */
case OPT_fhosted:
- flag_hosted = on;
- flag_no_builtin = !on;
+ flag_hosted = value;
+ flag_no_builtin = !value;
/* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
- if (!on && warn_main == 2)
+ if (!value && warn_main == 2)
warn_main = 0;
break;
case OPT_fshort_double:
- flag_short_double = on;
+ flag_short_double = value;
break;
case OPT_fshort_enums:
- flag_short_enums = on;
+ flag_short_enums = value;
break;
case OPT_fshort_wchar:
- flag_short_wchar = on;
+ flag_short_wchar = value;
break;
case OPT_fsigned_bitfields:
- flag_signed_bitfields = on;
+ flag_signed_bitfields = value;
explicit_flag_signed_bitfields = 1;
break;
case OPT_fsigned_char:
- flag_signed_char = on;
+ flag_signed_char = value;
break;
case OPT_funsigned_bitfields:
- flag_signed_bitfields = !on;
+ flag_signed_bitfields = !value;
explicit_flag_signed_bitfields = 1;
break;
case OPT_funsigned_char:
- flag_signed_char = !on;
+ flag_signed_char = !value;
break;
case OPT_fcheck_new:
- flag_check_new = on;
+ flag_check_new = value;
break;
case OPT_fconserve_space:
- flag_conserve_space = on;
+ flag_conserve_space = value;
break;
case OPT_fconst_strings:
- flag_const_strings = on;
+ flag_const_strings = value;
break;
case OPT_fconstant_string_class_:
break;
case OPT_fdefault_inline:
- flag_default_inline = on;
+ flag_default_inline = value;
break;
case OPT_felide_constructors:
- flag_elide_constructors = on;
+ flag_elide_constructors = value;
break;
case OPT_fenforce_eh_specs:
- flag_enforce_eh_specs = on;
+ flag_enforce_eh_specs = value;
break;
case OPT_fexternal_templates:
- flag_external_templates = on;
+ flag_external_templates = value;
goto cp_deprecated;
case OPT_ffixed_form:
break;
case OPT_ffor_scope:
- flag_new_for_scope = on;
+ flag_new_for_scope = value;
break;
case OPT_fgnu_keywords:
- flag_no_gnu_keywords = !on;
+ flag_no_gnu_keywords = !value;
break;
case OPT_fgnu_runtime:
- flag_next_runtime = !on;
+ flag_next_runtime = !value;
break;
case OPT_fhandle_exceptions:
warning ("-fhandle-exceptions has been renamed -fexceptions (and is now on by default)");
- flag_exceptions = on;
+ flag_exceptions = value;
break;
case OPT_fimplement_inlines:
- flag_implement_inlines = on;
+ flag_implement_inlines = value;
break;
case OPT_fimplicit_inline_templates:
- flag_implicit_inline_templates = on;
+ flag_implicit_inline_templates = value;
break;
case OPT_fimplicit_templates:
- flag_implicit_templates = on;
+ flag_implicit_templates = value;
break;
case OPT_fms_extensions:
- flag_ms_extensions = on;
+ flag_ms_extensions = value;
break;
case OPT_fnext_runtime:
- flag_next_runtime = on;
+ flag_next_runtime = value;
break;
case OPT_fnonansi_builtins:
- flag_no_nonansi_builtin = !on;
+ flag_no_nonansi_builtin = !value;
break;
case OPT_foperator_names:
- cpp_opts->operator_names = on;
+ cpp_opts->operator_names = value;
break;
case OPT_foptional_diags:
- flag_optional_diags = on;
+ flag_optional_diags = value;
break;
case OPT_fpch_deps:
- cpp_opts->restore_pch_deps = on;
+ cpp_opts->restore_pch_deps = value;
break;
case OPT_fpermissive:
- flag_permissive = on;
+ flag_permissive = value;
break;
case OPT_fpreprocessed:
- cpp_opts->preprocessed = on;
+ cpp_opts->preprocessed = value;
break;
case OPT_frepo:
- flag_use_repository = on;
- if (on)
+ flag_use_repository = value;
+ if (value)
flag_implicit_templates = 0;
break;
case OPT_frtti:
- flag_rtti = on;
+ flag_rtti = value;
break;
case OPT_fshow_column:
- cpp_opts->show_column = on;
+ cpp_opts->show_column = value;
break;
case OPT_fstats:
- flag_detailed_statistics = on;
+ flag_detailed_statistics = value;
break;
case OPT_ftabstop_:
/* It is documented that we silently ignore silly values. */
- {
- char *endptr;
- long tabstop = strtol (arg, &endptr, 10);
- if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
- cpp_opts->tabstop = tabstop;
- }
+ if (value >= 1 && value <= 100)
+ cpp_opts->tabstop = value;
break;
case OPT_ftemplate_depth_:
- max_tinst_depth = read_integral_parameter (arg, option->opt_text, 0);
+ max_tinst_depth = value;
break;
case OPT_fvtable_gc:
- flag_vtable_gc = on;
+ flag_vtable_gc = value;
break;
case OPT_fuse_cxa_atexit:
- flag_use_cxa_atexit = on;
+ flag_use_cxa_atexit = value;
break;
case OPT_fweak:
- flag_weak = on;
+ flag_weak = value;
break;
case OPT_gen_decls:
return result;
}
+/* If ARG is a postive integer made up solely of digits, return its
+ value, otherwise return -1. */
+static int
+integral_argument (const char *arg)
+{
+ const char *p = arg;
+
+ while (*p && ISDIGIT (*p))
+ p++;
+
+ if (*p == '\0')
+ return atoi (arg);
+
+ return -1;
+}
+
/* Handle the switch beginning at ARGV, with ARGC remaining. */
int
handle_option (int argc ATTRIBUTE_UNUSED, char **argv, int lang_mask)
size_t opt_index;
const char *opt, *arg = 0;
char *dup = 0;
- bool on = true;
+ int value = 1;
int result = 0, temp;
const struct cl_option *option;
opt_index = cl_options_count;
arg = opt;
main_input_filename = opt;
- result = (*lang_hooks.handle_option) (opt_index, arg, on);
+ result = (*lang_hooks.handle_option) (opt_index, arg, value);
}
else
{
dup[1] = opt[1];
memcpy (dup + 2, opt + 5, len - 2 + 1);
opt = dup;
- on = false;
+ value = 0;
}
opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
option = &cl_options[opt_index];
/* Reject negative form of switches that don't take negatives. */
- if (!on && (option->flags & CL_REJECT_NEGATIVE))
+ if (!value && (option->flags & CL_REJECT_NEGATIVE))
goto done;
/* We've recognized this switch. */
result = 1;
/* Sort out any argument the switch takes. */
- if (option->flags & (CL_JOINED | CL_SEPARATE))
+ if (option->flags & CL_JOINED)
{
- if (option->flags & CL_JOINED)
+ /* Have arg point to the original switch. This is because
+ some code, such as disable_builtin_function, expects its
+ argument to be persistent until the program exits. */
+ arg = argv[0] + cl_options[opt_index].opt_len + 1;
+ if (!value)
+ arg += strlen ("no-");
+
+ if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
{
- /* Have arg point to the original switch. This is because
- some code, such as disable_builtin_function, expects its
- argument to be persistent until the program exits. */
- arg = argv[0] + cl_options[opt_index].opt_len + 1;
- if (!on)
- arg += strlen ("no-");
+ if (option->flags & CL_SEPARATE)
+ {
+ arg = argv[1];
+ result = 2;
+ }
+ else
+ /* Missing argument. */
+ arg = NULL;
}
+ }
+ else if (option->flags & CL_SEPARATE)
+ {
+ arg = argv[1];
+ result = 2;
+ }
- /* If we don't have an argument, and CL_SEPARATE, try the next
- argument in the vector. */
- if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE))
+ /* If the switch takes an integer, convert it. */
+ if (arg && (option->flags & CL_UINTEGER))
+ {
+ value = integral_argument (arg);
+ if (value == -1)
{
- arg = argv[1];
- result = 2;
+ error ("argument to \"-%s\" should be a non-negative integer",
+ option->opt_text);
+ goto done;
}
-
- /* Canonicalize missing arguments as NULL for the handler. */
- if (*arg == '\0')
- arg = NULL;
}
if (option->flags & lang_mask)
{
- temp = (*lang_hooks.handle_option) (opt_index, arg, on);
+ temp = (*lang_hooks.handle_option) (opt_index, arg, value);
if (temp <= 0)
result = temp;
}
if (result > 0 && (option->flags & CL_COMMON))
{
- if (common_handle_option (opt_index, arg, on) == 0)
+ if (common_handle_option (opt_index, arg, value) == 0)
result = 0;
}
}
break;
case OPT_G:
- g_switch_value = read_integral_parameter (arg, 0, -1);
- if (g_switch_value == (unsigned HOST_WIDE_INT) -1)
- return 0;
+ g_switch_value = value;
g_switch_set = true;
break;