/* Common initialization before calling option handlers. */ void c_common_init_options (unsigned int decoded_options_count, struct cl_decoded_option *decoded_options) { unsigned int i; struct cpp_callbacks *cb; g_string_concat_db = new (ggc_alloc <string_concat_db> ()) string_concat_db (); parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89, ident_hash, line_table); cb = cpp_get_callbacks (parse_in); cb->error = c_cpp_error; cpp_opts = cpp_get_options (parse_in); cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS; cpp_opts->objc = c_dialect_objc (); /* Reset to avoid warnings on internal definitions. We set it just before passing on command-line options to cpplib. */ cpp_opts->warn_dollars = 0; deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count); if (c_language == clk_c) { /* The default for C is gnu11. */ set_std_c11 (false /* ISO */); /* If preprocessing assembly language, accept any of the C-family front end options since the driver may pass them through. */ for (i = 1; i < decoded_options_count; i++) if (decoded_options[i].opt_index == OPT_lang_asm) { accept_all_c_family_options = true; break; } } /* Set C++ standard to C++14 if not specified on the command line. */ if (c_dialect_cxx ()) set_std_cxx14 (/*ISO*/false); global_dc->colorize_source_p = true; }
/* Handle switch SCODE with argument ARG. VALUE is true, unless no- form of an -f or -W option was given. Returns false if the switch was invalid, true if valid. Use HANDLERS in recursive handle_option calls. */ bool c_common_handle_option (size_t scode, const char *arg, int value, int kind, location_t loc, const struct cl_option_handlers *handlers) { const struct cl_option *option = &cl_options[scode]; enum opt_code code = (enum opt_code) scode; bool result = true; /* Prevent resetting the language standard to a C dialect when the driver has already determined that we're looking at assembler input. */ bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM); switch (code) { default: if (cl_options[code].flags & c_family_lang_mask) { if ((option->flags & CL_TARGET) && ! targetcm.handle_c_option (scode, arg, value)) result = false; break; } result = false; break; case OPT__output_pch_: pch_file = arg; break; case OPT_A: defer_opt (code, arg); break; case OPT_C: cpp_opts->discard_comments = 0; break; case OPT_CC: cpp_opts->discard_comments = 0; cpp_opts->discard_comments_in_macro_exp = 0; break; case OPT_D: defer_opt (code, arg); break; case OPT_H: cpp_opts->print_include_names = 1; break; case OPT_F: TARGET_OPTF (xstrdup (arg)); break; case OPT_I: if (strcmp (arg, "-")) add_path (xstrdup (arg), BRACKET, 0, true); else { if (quote_chain_split) error ("-I- specified twice"); quote_chain_split = true; split_quote_chain (); inform (input_location, "obsolete option -I- used, please use -iquote instead"); } break; case OPT_M: case OPT_MM: /* When doing dependencies with -M or -MM, suppress normal preprocessed output, but still do -dM etc. as software depends on this. Preprocessed output does occur if -MD, -MMD or environment var dependency generation is used. */ cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER); flag_no_output = 1; break; case OPT_MD: case OPT_MMD: cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER); cpp_opts->deps.need_preprocessor_output = true; deps_file = arg; break; case OPT_MF: deps_seen = true; deps_file = arg; break; case OPT_MG: deps_seen = true; cpp_opts->deps.missing_files = true; break; case OPT_MP: deps_seen = true; cpp_opts->deps.phony_targets = true; break; case OPT_MQ: case OPT_MT: deps_seen = true; defer_opt (code, arg); break; case OPT_P: flag_no_line_commands = 1; break; case OPT_U: defer_opt (code, arg); break; case OPT_Wall: /* ??? Don't add new options here. Use LangEnabledBy in c.opt. */ cpp_opts->warn_trigraphs = value; cpp_opts->warn_comments = value; cpp_opts->warn_num_sign_change = value; break; case OPT_Wbuiltin_macro_redefined: cpp_opts->warn_builtin_macro_redefined = value; break; case OPT_Wcomment: cpp_opts->warn_comments = value; break; case OPT_Wc___compat: cpp_opts->warn_cxx_operator_names = value; break; case OPT_Wdeprecated: cpp_opts->cpp_warn_deprecated = value; break; case OPT_Wendif_labels: cpp_opts->warn_endif_labels = value; break; case OPT_Winvalid_pch: cpp_opts->warn_invalid_pch = value; break; case OPT_Wliteral_suffix: cpp_opts->warn_literal_suffix = value; break; case OPT_Wlong_long: cpp_opts->cpp_warn_long_long = value; break; case OPT_Wmissing_include_dirs: cpp_opts->warn_missing_include_dirs = value; break; case OPT_Wmultichar: cpp_opts->warn_multichar = value; break; case OPT_Wnormalized_: if (kind == DK_ERROR) { gcc_assert (!arg); inform (input_location, "-Werror=normalized=: set -Wnormalized=nfc"); cpp_opts->warn_normalize = normalized_C; } else { if (!value || (arg && strcasecmp (arg, "none") == 0)) cpp_opts->warn_normalize = normalized_none; else if (!arg || strcasecmp (arg, "nfkc") == 0) cpp_opts->warn_normalize = normalized_KC; else if (strcasecmp (arg, "id") == 0) cpp_opts->warn_normalize = normalized_identifier_C; else if (strcasecmp (arg, "nfc") == 0) cpp_opts->warn_normalize = normalized_C; else error ("argument %qs to %<-Wnormalized%> not recognized", arg); break; } case OPT_Wtraditional: cpp_opts->cpp_warn_traditional = value; break; case OPT_Wtrigraphs: cpp_opts->warn_trigraphs = value; break; case OPT_Wundef: 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. */ /* ??? There is no way to handle this automatically for now. */ warn_unknown_pragmas = value * 2; break; case OPT_ansi: if (!c_dialect_cxx ()) set_std_c89 (false, true); else set_std_cxx98 (true); break; case OPT_d: handle_OPT_d (arg); break; case OPT_fcanonical_system_headers: cpp_opts->canonical_system_headers = value; break; case OPT_fcond_mismatch: if (!c_dialect_cxx ()) { flag_cond_mismatch = value; break; } warning (0, "switch %qs is no longer supported", option->opt_text); break; case OPT_fbuiltin_: if (value) result = false; else disable_builtin_function (arg); break; case OPT_fdirectives_only: cpp_opts->directives_only = value; break; case OPT_fdollars_in_identifiers: cpp_opts->dollars_in_ident = value; break; case OPT_ffreestanding: value = !value; /* Fall through.... */ case OPT_fhosted: flag_hosted = value; flag_no_builtin = !value; break; case OPT_fconstant_string_class_: constant_string_class_name = arg; break; case OPT_fextended_identifiers: cpp_opts->extended_identifiers = value; break; case OPT_foperator_names: cpp_opts->operator_names = value; break; case OPT_fpch_deps: cpp_opts->restore_pch_deps = value; break; case OPT_fpch_preprocess: flag_pch_preprocess = value; break; case OPT_fpermissive: flag_permissive = value; global_dc->permissive = value; break; case OPT_fpreprocessed: cpp_opts->preprocessed = value; break; case OPT_fdebug_cpp: cpp_opts->debug = 1; break; case OPT_ftrack_macro_expansion: if (value) value = 2; /* Fall Through. */ case OPT_ftrack_macro_expansion_: if (arg && *arg != '\0') cpp_opts->track_macro_expansion = value; else cpp_opts->track_macro_expansion = 2; break; case OPT_frepo: flag_use_repository = value; if (value) flag_implicit_templates = 0; break; case OPT_ftabstop_: /* It is documented that we silently ignore silly values. */ if (value >= 1 && value <= 100) cpp_opts->tabstop = value; break; case OPT_fexec_charset_: cpp_opts->narrow_charset = arg; break; case OPT_fwide_exec_charset_: cpp_opts->wide_charset = arg; break; case OPT_finput_charset_: cpp_opts->input_charset = arg; break; case OPT_ftemplate_depth_: max_tinst_depth = value; break; case OPT_fvisibility_inlines_hidden: visibility_options.inlines_hidden = value; break; case OPT_femit_struct_debug_baseonly: set_struct_debug_option (&global_options, loc, "base"); break; case OPT_femit_struct_debug_reduced: set_struct_debug_option (&global_options, loc, "dir:ord:sys,dir:gen:any,ind:base"); break; case OPT_femit_struct_debug_detailed_: set_struct_debug_option (&global_options, loc, arg); break; case OPT_fext_numeric_literals: cpp_opts->ext_numeric_literals = value; break; case OPT_idirafter: add_path (xstrdup (arg), AFTER, 0, true); break; case OPT_imacros: case OPT_include: defer_opt (code, arg); break; case OPT_imultilib: imultilib = arg; break; case OPT_iprefix: iprefix = arg; break; case OPT_iquote: add_path (xstrdup (arg), QUOTE, 0, true); break; case OPT_isysroot: sysroot = arg; break; case OPT_isystem: add_path (xstrdup (arg), SYSTEM, 0, true); break; case OPT_iwithprefix: add_prefixed_path (arg, SYSTEM); break; case OPT_iwithprefixbefore: add_prefixed_path (arg, BRACKET); break; case OPT_lang_asm: cpp_set_lang (parse_in, CLK_ASM); cpp_opts->dollars_in_ident = false; break; case OPT_nostdinc: std_inc = false; break; case OPT_nostdinc__: std_cxx_inc = false; break; case OPT_o: if (!out_fname) out_fname = arg; else error ("output filename specified twice"); break; /* We need to handle the -Wpedantic switch here, rather than in c_common_post_options, so that a subsequent -Wno-endif-labels is not overridden. */ case OPT_Wpedantic: cpp_opts->cpp_pedantic = 1; cpp_opts->warn_endif_labels = 1; break; case OPT_print_objc_runtime_info: print_struct_values = 1; break; case OPT_remap: cpp_opts->remap = 1; break; case OPT_std_c__98: case OPT_std_gnu__98: if (!preprocessing_asm_p) set_std_cxx98 (code == OPT_std_c__98 /* ISO */); break; case OPT_std_c__11: case OPT_std_gnu__11: if (!preprocessing_asm_p) { set_std_cxx11 (code == OPT_std_c__11 /* ISO */); if (code == OPT_std_c__11) cpp_opts->ext_numeric_literals = 0; } break; case OPT_std_c__1y: case OPT_std_gnu__1y: if (!preprocessing_asm_p) { set_std_cxx1y (code == OPT_std_c__1y /* ISO */); if (code == OPT_std_c__1y) cpp_opts->ext_numeric_literals = 0; } break; case OPT_std_c90: case OPT_std_iso9899_199409: if (!preprocessing_asm_p) set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */); break; case OPT_std_gnu90: if (!preprocessing_asm_p) set_std_c89 (false /* c94 */, false /* ISO */); break; case OPT_std_c99: if (!preprocessing_asm_p) set_std_c99 (true /* ISO */); break; case OPT_std_gnu99: if (!preprocessing_asm_p) set_std_c99 (false /* ISO */); break; case OPT_std_c11: if (!preprocessing_asm_p) set_std_c11 (true /* ISO */); break; case OPT_std_gnu11: if (!preprocessing_asm_p) set_std_c11 (false /* ISO */); break; case OPT_trigraphs: cpp_opts->trigraphs = 1; break; case OPT_traditional_cpp: cpp_opts->traditional = 1; break; case OPT_v: verbose = true; break; case OPT_Wabi: warn_psabi = value; break; } switch (c_language) { case clk_c: C_handle_option_auto (&global_options, &global_options_set, scode, arg, value, c_family_lang_mask, kind, loc, handlers, global_dc); break; case clk_objc: ObjC_handle_option_auto (&global_options, &global_options_set, scode, arg, value, c_family_lang_mask, kind, loc, handlers, global_dc); break; case clk_cxx: CXX_handle_option_auto (&global_options, &global_options_set, scode, arg, value, c_family_lang_mask, kind, loc, handlers, global_dc); break; case clk_objcxx: ObjCXX_handle_option_auto (&global_options, &global_options_set, scode, arg, value, c_family_lang_mask, kind, loc, handlers, global_dc); break; default: gcc_unreachable (); } return result; }