1 /* C/ObjC/C++ command line option handling.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
31 #include "langhooks.h"
32 #include "tree-inline.h"
33 #include "diagnostic.h"
35 #include "cppdefault.h"
36 #include "c-incpath.h"
37 #include "debug.h" /* For debug_hooks. */
39 #ifndef TARGET_SYSTEM_ROOT
40 # define TARGET_SYSTEM_ROOT NULL
43 static int saved_lineno;
46 static cpp_options *cpp_opts;
49 static const char *in_fname;
51 /* Filename and stream for preprocessed output. */
52 static const char *out_fname;
53 static FILE *out_stream;
55 /* Append dependencies to deps_file. */
56 static bool deps_append;
58 /* If dependency switches (-MF etc.) have been given. */
59 static bool deps_seen;
64 /* Dependency output file. */
65 static const char *deps_file;
67 /* The prefix given by -iprefix, if any. */
68 static const char *iprefix;
70 /* The system root, if any. Overridden by -isysroot. */
71 static const char *sysroot = TARGET_SYSTEM_ROOT;
73 /* Zero disables all standard directories for headers. */
74 static bool std_inc = true;
76 /* Zero disables the C++-specific standard directories for headers. */
77 static bool std_cxx_inc = true;
79 /* If the quote chain has been split by -I-. */
80 static bool quote_chain_split;
82 /* If -Wunused-macros. */
83 static bool warn_unused_macros;
85 /* Number of deferred options, deferred options array size. */
86 static size_t deferred_count, deferred_size;
88 /* Number of deferred options scanned for -include. */
89 static size_t include_cursor;
91 static void missing_arg PARAMS ((size_t));
92 static size_t find_opt PARAMS ((const char *, int));
93 static void set_Wimplicit PARAMS ((int));
94 static void complain_wrong_lang PARAMS ((size_t));
95 static void write_langs PARAMS ((char *, int));
96 static void print_help PARAMS ((void));
97 static void handle_OPT_d PARAMS ((const char *));
98 static void set_std_cxx98 PARAMS ((int));
99 static void set_std_c89 PARAMS ((int, int));
100 static void set_std_c99 PARAMS ((int));
101 static void check_deps_environment_vars PARAMS ((void));
102 static void handle_deferred_opts PARAMS ((void));
103 static void sanitize_cpp_opts PARAMS ((void));
104 static void add_prefixed_path PARAMS ((const char *, size_t));
105 static void push_command_line_include PARAMS ((void));
106 static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *));
107 static void finish_options PARAMS ((void));
109 #ifndef STDC_0_IN_SYSTEM_HEADERS
110 #define STDC_0_IN_SYSTEM_HEADERS 0
113 #define CL_C_ONLY (1 << 0) /* Only C. */
114 #define CL_OBJC_ONLY (1 << 1) /* Only ObjC. */
115 #define CL_CXX_ONLY (1 << 2) /* Only C++. */
116 #define CL_OBJCXX_ONLY (1 << 3) /* Only ObjC++. */
117 #define CL_JOINED (1 << 4) /* If takes joined argument. */
118 #define CL_SEPARATE (1 << 5) /* If takes a separate argument. */
120 #define CL_ARG (CL_JOINED | CL_SEPARATE)
121 #define CL_C (CL_C_ONLY | CL_OBJC_ONLY)
122 #define CL_OBJC (CL_OBJC_ONLY | CL_OBJCXX_ONLY)
123 #define CL_CXX (CL_CXX_ONLY | CL_OBJCXX_ONLY)
124 #define CL_ALL (CL_C | CL_CXX)
126 /* This is the list of all command line options, with the leading "-"
127 removed. It must be sorted in ASCII collating order. All options
128 beginning with "f" or "W" are implicitly assumed to take a "no-"
129 form; this form should not be listed. The variable "on" is true if
130 the positive form is given, otherwise it is false. If you don't
131 want to allow a "no-" form, your handler should reject "on" being
132 false by returning zero. See, for example, the handling of
135 If the user gives an option to a front end that doesn't support it,
136 an error is output, mentioning which front ends the option is valid
137 for. If you don't want this, you must accept it for all front
138 ends, and test for the front end in the option handler. See, for
139 example, the handling of -Wno-strict-prototypes for C++.
141 If you request an argument with CL_JOINED, CL_SEPARATE or their
142 combination CL_ARG, it is stored in the variable "arg", which is
143 guaranteed to be non-NULL and to not be an empty string. It points
144 to the argument either within the argv[] vector or within one of
145 that vector's strings, and so the text is permanent and copies need
146 not be made. Be sure to add an error message in missing_arg() if
147 the default is not appropriate. */
149 #define COMMAND_LINE_OPTIONS \
150 OPT("-help", CL_ALL, OPT__help) \
151 OPT("-output-pch=", CL_ALL | CL_ARG, OPT__output_pch) \
152 OPT("C", CL_ALL, OPT_C) \
153 OPT("CC", CL_ALL, OPT_CC) \
154 OPT("E", CL_ALL, OPT_E) \
155 OPT("H", CL_ALL, OPT_H) \
156 OPT("I", CL_ALL | CL_ARG, OPT_I) \
157 OPT("M", CL_ALL, OPT_M) \
158 OPT("MD", CL_ALL | CL_SEPARATE, OPT_MD) \
159 OPT("MF", CL_ALL | CL_ARG, OPT_MF) \
160 OPT("MG", CL_ALL, OPT_MG) \
161 OPT("MM", CL_ALL, OPT_MM) \
162 OPT("MMD", CL_ALL | CL_SEPARATE, OPT_MMD) \
163 OPT("MP", CL_ALL, OPT_MP) \
164 OPT("MQ", CL_ALL | CL_ARG, OPT_MQ) \
165 OPT("MT", CL_ALL | CL_ARG, OPT_MT) \
166 OPT("P", CL_ALL, OPT_P) \
167 OPT("Wabi", CL_CXX, OPT_Wabi) \
168 OPT("Wall", CL_ALL, OPT_Wall) \
169 OPT("Wbad-function-cast", CL_C, OPT_Wbad_function_cast) \
170 OPT("Wcast-qual", CL_ALL, OPT_Wcast_qual) \
171 OPT("Wchar-subscripts", CL_ALL, OPT_Wchar_subscripts) \
172 OPT("Wcomment", CL_ALL, OPT_Wcomment) \
173 OPT("Wcomments", CL_ALL, OPT_Wcomments) \
174 OPT("Wconversion", CL_ALL, OPT_Wconversion) \
175 OPT("Wctor-dtor-privacy", CL_CXX, OPT_Wctor_dtor_privacy) \
176 OPT("Wdeprecated", CL_CXX, OPT_Wdeprecated) \
177 OPT("Wdiv-by-zero", CL_C, OPT_Wdiv_by_zero) \
178 OPT("Weffc++", CL_CXX, OPT_Weffcxx) \
179 OPT("Wendif-labels", CL_ALL, OPT_Wendif_labels) \
180 OPT("Werror", CL_ALL, OPT_Werror) \
181 OPT("Werror-implicit-function-declaration", \
182 CL_C, OPT_Werror_implicit_function_decl) \
183 OPT("Wfloat-equal", CL_ALL, OPT_Wfloat_equal) \
184 OPT("Wformat", CL_ALL, OPT_Wformat) \
185 OPT("Wformat-extra-args", CL_ALL, OPT_Wformat_extra_args) \
186 OPT("Wformat-nonliteral", CL_ALL, OPT_Wformat_nonliteral) \
187 OPT("Wformat-security", CL_ALL, OPT_Wformat_security) \
188 OPT("Wformat-y2k", CL_ALL, OPT_Wformat_y2k) \
189 OPT("Wformat-zero-length", CL_C, OPT_Wformat_zero_length) \
190 OPT("Wformat=", CL_ALL | CL_JOINED, OPT_Wformat_eq) \
191 OPT("Wimplicit", CL_ALL, OPT_Wimplicit) \
192 OPT("Wimplicit-function-declaration", CL_C, OPT_Wimplicit_function_decl) \
193 OPT("Wimplicit-int", CL_C, OPT_Wimplicit_int) \
194 OPT("Wimport", CL_ALL, OPT_Wimport) \
195 OPT("Winvalid-pch", CL_ALL, OPT_Winvalid_pch) \
196 OPT("Wlong-long", CL_ALL, OPT_Wlong_long) \
197 OPT("Wmain", CL_C, OPT_Wmain) \
198 OPT("Wmissing-braces", CL_ALL, OPT_Wmissing_braces) \
199 OPT("Wmissing-declarations", CL_C, OPT_Wmissing_declarations) \
200 OPT("Wmissing-format-attribute",CL_ALL, OPT_Wmissing_format_attribute) \
201 OPT("Wmissing-prototypes", CL_ALL, OPT_Wmissing_prototypes) \
202 OPT("Wmultichar", CL_ALL, OPT_Wmultichar) \
203 OPT("Wnested-externs", CL_C, OPT_Wnested_externs) \
204 OPT("Wnon-template-friend", CL_CXX, OPT_Wnon_template_friend) \
205 OPT("Wnon-virtual-dtor", CL_CXX, OPT_Wnon_virtual_dtor) \
206 OPT("Wnonnull", CL_C, OPT_Wnonnull) \
207 OPT("Wold-style-cast", CL_CXX, OPT_Wold_style_cast) \
208 OPT("Woverloaded-virtual", CL_CXX, OPT_Woverloaded_virtual) \
209 OPT("Wparentheses", CL_ALL, OPT_Wparentheses) \
210 OPT("Wpmf-conversions", CL_CXX, OPT_Wpmf_conversions) \
211 OPT("Wpointer-arith", CL_ALL, OPT_Wpointer_arith) \
212 OPT("Wprotocol", CL_OBJC, OPT_Wprotocol) \
213 OPT("Wredundant-decls", CL_ALL, OPT_Wredundant_decls) \
214 OPT("Wreorder", CL_CXX, OPT_Wreorder) \
215 OPT("Wreturn-type", CL_ALL, OPT_Wreturn_type) \
216 OPT("Wselector", CL_OBJC, OPT_Wselector) \
217 OPT("Wsequence-point", CL_C, OPT_Wsequence_point) \
218 OPT("Wsign-compare", CL_ALL, OPT_Wsign_compare) \
219 OPT("Wsign-promo", CL_CXX, OPT_Wsign_promo) \
220 OPT("Wstrict-prototypes", CL_ALL, OPT_Wstrict_prototypes) \
221 OPT("Wsynth", CL_CXX, OPT_Wsynth) \
222 OPT("Wsystem-headers", CL_ALL, OPT_Wsystem_headers) \
223 OPT("Wtraditional", CL_C, OPT_Wtraditional) \
224 OPT("Wtrigraphs", CL_ALL, OPT_Wtrigraphs) \
225 OPT("Wundeclared-selector", CL_OBJC, OPT_Wundeclared_selector) \
226 OPT("Wundef", CL_ALL, OPT_Wundef) \
227 OPT("Wunknown-pragmas", CL_ALL, OPT_Wunknown_pragmas) \
228 OPT("Wunused-macros", CL_ALL, OPT_Wunused_macros) \
229 OPT("Wwrite-strings", CL_ALL, OPT_Wwrite_strings) \
230 OPT("ansi", CL_ALL, OPT_ansi) \
231 OPT("d", CL_ALL | CL_JOINED, OPT_d) \
232 OPT("fabi-version=", CL_CXX | CL_JOINED, OPT_fabi_version) \
233 OPT("faccess-control", CL_CXX, OPT_faccess_control) \
234 OPT("fall-virtual", CL_CXX, OPT_fall_virtual) \
235 OPT("falt-external-templates",CL_CXX, OPT_falt_external_templates) \
236 OPT("fasm", CL_ALL, OPT_fasm) \
237 OPT("fbuiltin", CL_ALL, OPT_fbuiltin) \
238 OPT("fbuiltin-", CL_ALL | CL_JOINED, OPT_fbuiltin_) \
239 OPT("fcheck-new", CL_CXX, OPT_fcheck_new) \
240 OPT("fcond-mismatch", CL_ALL, OPT_fcond_mismatch) \
241 OPT("fconserve-space", CL_CXX, OPT_fconserve_space) \
242 OPT("fconst-strings", CL_CXX, OPT_fconst_strings) \
243 OPT("fconstant-string-class=", CL_OBJC | CL_JOINED, \
244 OPT_fconstant_string_class) \
245 OPT("fdefault-inline", CL_CXX, OPT_fdefault_inline) \
246 OPT("fdollars-in-identifiers",CL_ALL, OPT_fdollars_in_identifiers) \
247 OPT("fdump-", CL_ALL | CL_JOINED, OPT_fdump) \
248 OPT("felide-constructors", CL_CXX, OPT_felide_constructors) \
249 OPT("fenforce-eh-specs", CL_CXX, OPT_fenforce_eh_specs) \
250 OPT("fenum-int-equiv", CL_CXX, OPT_fenum_int_equiv) \
251 OPT("fexternal-templates", CL_CXX, OPT_fexternal_templates) \
252 OPT("ffixed-form", CL_C, OPT_ffixed_form) \
253 OPT("ffixed-line-length-", CL_C | CL_JOINED, OPT_ffixed_line_length) \
254 OPT("ffor-scope", CL_CXX, OPT_ffor_scope) \
255 OPT("ffreestanding", CL_C, OPT_ffreestanding) \
256 OPT("fgnu-keywords", CL_CXX, OPT_fgnu_keywords) \
257 OPT("fgnu-runtime", CL_OBJC, OPT_fgnu_runtime) \
258 OPT("fguiding-decls", CL_CXX, OPT_fguiding_decls) \
259 OPT("fhandle-exceptions", CL_CXX, OPT_fhandle_exceptions) \
260 OPT("fhonor-std", CL_CXX, OPT_fhonor_std) \
261 OPT("fhosted", CL_C, OPT_fhosted) \
262 OPT("fhuge-objects", CL_CXX, OPT_fhuge_objects) \
263 OPT("fimplement-inlines", CL_CXX, OPT_fimplement_inlines) \
264 OPT("fimplicit-inline-templates", CL_CXX, OPT_fimplicit_inline_templates) \
265 OPT("fimplicit-templates", CL_CXX, OPT_fimplicit_templates) \
266 OPT("flabels-ok", CL_CXX, OPT_flabels_ok) \
267 OPT("fms-extensions", CL_ALL, OPT_fms_extensions) \
268 OPT("fname-mangling-version-",CL_CXX | CL_JOINED, OPT_fname_mangling) \
269 OPT("fnew-abi", CL_CXX, OPT_fnew_abi) \
270 OPT("fnext-runtime", CL_OBJC, OPT_fnext_runtime) \
271 OPT("fnonansi-builtins", CL_CXX, OPT_fnonansi_builtins) \
272 OPT("fnonnull-objects", CL_CXX, OPT_fnonnull_objects) \
273 OPT("foperator-names", CL_CXX, OPT_foperator_names) \
274 OPT("foptional-diags", CL_CXX, OPT_foptional_diags) \
275 OPT("fpch-deps", CL_ALL, OPT_fpch_deps) \
276 OPT("fpermissive", CL_CXX, OPT_fpermissive) \
277 OPT("fpreprocessed", CL_ALL, OPT_fpreprocessed) \
278 OPT("frepo", CL_CXX, OPT_frepo) \
279 OPT("frtti", CL_CXX, OPT_frtti) \
280 OPT("fshort-double", CL_ALL, OPT_fshort_double) \
281 OPT("fshort-enums", CL_ALL, OPT_fshort_enums) \
282 OPT("fshort-wchar", CL_ALL, OPT_fshort_wchar) \
283 OPT("fshow-column", CL_ALL, OPT_fshow_column) \
284 OPT("fsigned-bitfields", CL_ALL, OPT_fsigned_bitfields) \
285 OPT("fsigned-char", CL_ALL, OPT_fsigned_char) \
286 OPT("fsquangle", CL_CXX, OPT_fsquangle) \
287 OPT("fstats", CL_CXX, OPT_fstats) \
288 OPT("fstrict-prototype", CL_CXX, OPT_fstrict_prototype) \
289 OPT("ftabstop=", CL_ALL | CL_JOINED, OPT_ftabstop) \
290 OPT("ftemplate-depth-", CL_CXX | CL_JOINED, OPT_ftemplate_depth) \
291 OPT("fthis-is-variable", CL_CXX, OPT_fthis_is_variable) \
292 OPT("funsigned-bitfields", CL_ALL, OPT_funsigned_bitfields) \
293 OPT("funsigned-char", CL_ALL, OPT_funsigned_char) \
294 OPT("fuse-cxa-atexit", CL_CXX, OPT_fuse_cxa_atexit) \
295 OPT("fvtable-gc", CL_CXX, OPT_fvtable_gc) \
296 OPT("fvtable-thunks", CL_CXX, OPT_fvtable_thunks) \
297 OPT("fweak", CL_CXX, OPT_fweak) \
298 OPT("fxref", CL_CXX, OPT_fxref) \
299 OPT("gen-decls", CL_OBJC, OPT_gen_decls) \
300 OPT("idirafter", CL_ALL | CL_ARG, OPT_idirafter) \
301 OPT("imacros", CL_ALL | CL_ARG, OPT_imacros) \
302 OPT("include", CL_ALL | CL_ARG, OPT_include) \
303 OPT("iprefix", CL_ALL | CL_ARG, OPT_iprefix) \
304 OPT("isysroot", CL_ALL | CL_ARG, OPT_isysroot) \
305 OPT("isystem", CL_ALL | CL_ARG, OPT_isystem) \
306 OPT("iwithprefix", CL_ALL | CL_ARG, OPT_iwithprefix) \
307 OPT("iwithprefixbefore", CL_ALL | CL_ARG, OPT_iwithprefixbefore) \
308 OPT("lang-asm", CL_C_ONLY, OPT_lang_asm) \
309 OPT("lang-objc", CL_ALL, OPT_lang_objc) \
310 OPT("nostdinc", CL_ALL, OPT_nostdinc) \
311 OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \
312 OPT("o", CL_ALL | CL_ARG, OPT_o) \
313 OPT("pedantic", CL_ALL, OPT_pedantic) \
314 OPT("pedantic-errors", CL_ALL, OPT_pedantic_errors) \
315 OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info) \
316 OPT("remap", CL_ALL, OPT_remap) \
317 OPT("std=c++98", CL_CXX, OPT_std_cplusplus98) \
318 OPT("std=c89", CL_C, OPT_std_c89) \
319 OPT("std=c99", CL_C, OPT_std_c99) \
320 OPT("std=c9x", CL_C, OPT_std_c9x) \
321 OPT("std=gnu++98", CL_CXX, OPT_std_gnuplusplus98) \
322 OPT("std=gnu89", CL_C, OPT_std_gnu89) \
323 OPT("std=gnu99", CL_C, OPT_std_gnu99) \
324 OPT("std=gnu9x", CL_C, OPT_std_gnu9x) \
325 OPT("std=iso9899:1990", CL_C, OPT_std_iso9899_1990) \
326 OPT("std=iso9899:199409", CL_C, OPT_std_iso9899_199409) \
327 OPT("std=iso9899:1999", CL_C, OPT_std_iso9899_1999) \
328 OPT("std=iso9899:199x", CL_C, OPT_std_iso9899_199x) \
329 OPT("traditional-cpp", CL_ALL, OPT_traditional_cpp) \
330 OPT("trigraphs", CL_ALL, OPT_trigraphs) \
331 OPT("undef", CL_ALL, OPT_undef) \
332 OPT("v", CL_ALL, OPT_v) \
333 OPT("w", CL_ALL, OPT_w)
335 #define OPT(text, flags, code) code,
345 const char *opt_text;
346 unsigned char opt_len;
348 ENUM_BITFIELD (opt_code) opt_code : 2 * CHAR_BIT;
351 #define OPT(text, flags, code) { text, sizeof(text) - 1, flags, code },
353 static struct cl_option cl_options[] =
355 static const struct cl_option cl_options[] =
361 #undef COMMAND_LINE_OPTIONS
363 /* Holds switches parsed by c_common_decode_option (), but whose
364 handling is deferred to c_common_post_options (). */
365 static void defer_opt PARAMS ((enum opt_code, const char *));
366 static struct deferred_opt
374 static int opt_comp PARAMS ((const void *, const void *));
376 /* Run-time sorting of options array. */
381 return strcmp (((struct cl_option *) p1)->opt_text,
382 ((struct cl_option *) p2)->opt_text);
386 /* Complain that switch OPT_INDEX expects an argument but none was
389 missing_arg (opt_index)
392 const char *opt_text = cl_options[opt_index].opt_text;
394 switch (cl_options[opt_index].opt_code)
396 case OPT__output_pch:
399 case OPT_fabi_version:
402 case OPT_fname_mangling:
404 case OPT_ftemplate_depth:
406 case OPT_iwithprefix:
407 case OPT_iwithprefixbefore:
409 error ("missing argument to \"-%s\"", opt_text);
412 case OPT_fconstant_string_class:
413 error ("no class name specified with \"-%s\"", opt_text);
420 error ("missing path after \"-%s\"", opt_text);
429 error ("missing filename after \"-%s\"", opt_text);
434 error ("missing target after \"-%s\"", opt_text);
439 /* Perform a binary search to find which option the command-line INPUT
440 matches. Returns its index in the option array, and N_OPTS on
443 Complications arise since some options can be suffixed with an
444 argument, and multiple complete matches can occur, e.g. -pedantic
445 and -pedantic-errors. Also, some options are only accepted by some
446 languages. If a switch matches for a different language and
447 doesn't match any alternatives for the true front end, the index of
448 the matched switch is returned anyway. The caller should check for
451 find_opt (input, lang_flag)
457 size_t result = N_OPTS;
467 opt_len = cl_options[md].opt_len;
468 comp = strncmp (input, cl_options[md].opt_text, opt_len);
476 /* The switch matches. It it an exact match? */
477 if (input[opt_len] == '\0')
483 /* If the switch takes no arguments this is not a proper
484 match, so we continue the search (e.g. input="stdc++"
485 match was "stdc"). */
486 if (!(cl_options[md].flags & CL_JOINED))
489 /* Is this switch valid for this front end? */
490 if (!(cl_options[md].flags & lang_flag))
492 /* If subsequently we don't find a better match,
493 return this and let the caller report it as a bad
499 /* Two scenarios remain: we have the switch's argument,
500 or we match a longer option. This can happen with
501 -iwithprefix and -withprefixbefore. The longest
502 possible option match succeeds.
504 Scan forwards, and return an exact match. Otherwise
505 return the longest valid option-accepting match (mx).
506 This loops at most twice with current options. */
508 for (md = md + 1; md < (size_t) N_OPTS; md++)
510 opt_len = cl_options[md].opt_len;
511 if (strncmp (input, cl_options[md].opt_text, opt_len))
513 if (input[opt_len] == '\0')
515 if (cl_options[md].flags & lang_flag
516 && cl_options[md].flags & CL_JOINED)
528 /* Defer option CODE with argument ARG. */
530 defer_opt (code, arg)
534 /* FIXME: this should be in c_common_init_options, which should take
538 extern int save_argc;
539 deferred_size = save_argc;
540 deferred_opts = (struct deferred_opt *)
541 xmalloc (deferred_size * sizeof (struct deferred_opt));
544 if (deferred_count == deferred_size)
547 deferred_opts[deferred_count].code = code;
548 deferred_opts[deferred_count].arg = arg;
552 /* Common initialization before parsing options. */
554 c_common_init_options (lang)
555 enum c_language_kind lang;
558 /* For non-ASCII hosts, the cl_options array needs to be sorted at
560 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
566 for (i = 1; i < N_OPTS; i++)
567 if (strcmp (cl_options[i - 1].opt_text, cl_options[i].opt_text) >= 0)
568 error ("options array incorrectly sorted: %s is before %s",
569 cl_options[i - 1].opt_text, cl_options[i].opt_text);
574 parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX);
575 cpp_opts = cpp_get_options (parse_in);
579 flag_const_strings = (lang == clk_cplusplus);
580 warn_pointer_arith = (lang == clk_cplusplus);
582 warn_sign_compare = -1;
585 /* Handle one command-line option in (argc, argv).
586 Can be called multiple times, to handle multiple sets of options.
587 Returns number of strings consumed. */
589 c_common_decode_option (argc, argv)
593 static const int lang_flags[] = {CL_C_ONLY, CL_C, CL_CXX_ONLY, CL_CXX};
595 const char *opt, *arg = 0;
598 int result, lang_flag;
599 const struct cl_option *option;
604 /* Interpret "-" or a non-switch as a file name. */
605 if (opt[0] != '-' || opt[1] == '\0')
613 error ("too many filenames given. Type %s --help for usage",
621 /* Drop the "no-" from negative switches. */
622 if ((opt[1] == 'W' || opt[1] == 'f')
623 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
625 size_t len = strlen (opt) - 3;
627 dup = xmalloc (len + 1);
630 memcpy (dup + 2, opt + 5, len - 2 + 1);
635 result = cpp_handle_option (parse_in, argc, argv);
638 lang_flag = lang_flags[(c_language << 1) + flag_objc];
639 opt_index = find_opt (opt + 1, lang_flag);
640 if (opt_index == N_OPTS)
644 option = &cl_options[opt_index];
646 /* Sort out any argument the switch takes. */
647 if (option->flags & CL_ARG)
649 if (option->flags & CL_JOINED)
651 /* Have arg point to the original switch. This is because
652 some code, such as disable_builtin_function, expects its
653 argument to be persistent until the program exits. */
654 arg = argv[0] + cl_options[opt_index].opt_len + 1;
656 arg += strlen ("no-");
659 /* If we don't have an argument, and CL_SEPARATE, try the next
660 argument in the vector. */
661 if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE))
667 if (!arg || *arg == '\0')
669 missing_arg (opt_index);
675 /* Complain about the wrong language after we've swallowed any
676 necessary extra argument. Eventually make this a hard error
677 after the call to find_opt, and return argc. */
678 if (!(cl_options[opt_index].flags & lang_flag))
680 complain_wrong_lang (opt_index);
684 switch (code = option->opt_code)
686 case N_OPTS: /* Shut GCC up. */
693 case OPT__output_pch:
698 cpp_opts->discard_comments = 0;
702 cpp_opts->discard_comments = 0;
703 cpp_opts->discard_comments_in_macro_exp = 0;
707 flag_preprocess_only = 1;
711 cpp_opts->print_include_names = 1;
715 if (strcmp (arg, "-"))
716 add_path (xstrdup (arg), BRACKET, 0);
719 if (quote_chain_split)
720 error ("-I- specified twice");
721 quote_chain_split = true;
722 split_quote_chain ();
728 /* When doing dependencies with -M or -MM, suppress normal
729 preprocessed output, but still do -dM etc. as software
730 depends on this. Preprocessed output does occur if -MD, -MMD
731 or environment var dependency generation is used. */
732 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
734 cpp_opts->inhibit_warnings = 1;
739 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
750 cpp_opts->deps.missing_files = true;
755 cpp_opts->deps.phony_targets = true;
761 defer_opt (code, arg);
765 flag_no_line_commands = 1;
776 warn_char_subscripts = on;
777 warn_missing_braces = on;
778 warn_parentheses = on;
779 warn_return_type = on;
780 warn_sequence_point = on; /* Was C only. */
781 warn_sign_compare = on; /* Was C++ only. */
783 warn_strict_aliasing = on;
785 /* Only warn about unknown pragmas that are not in system
787 warn_unknown_pragmas = on;
789 /* We save the value of warn_uninitialized, since if they put
790 -Wuninitialized on the command line, we need to generate a
791 warning about not using it without also specifying -O. */
792 if (warn_uninitialized != 1)
793 warn_uninitialized = (on ? 2 : 0);
795 if (c_language == clk_c)
796 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
797 can turn it off only if it's not explicit. */
801 /* C++-specific warnings. */
802 warn_ctor_dtor_privacy = on;
805 warn_nontemplate_friend = on;
808 cpp_opts->warn_trigraphs = on;
809 cpp_opts->warn_comments = on;
810 cpp_opts->warn_num_sign_change = on;
811 cpp_opts->warn_multichar = on; /* Was C++ only. */
814 case OPT_Wbad_function_cast:
815 warn_bad_function_cast = on;
822 case OPT_Wchar_subscripts:
823 warn_char_subscripts = on;
828 cpp_opts->warn_comments = on;
831 case OPT_Wconversion:
832 warn_conversion = on;
835 case OPT_Wctor_dtor_privacy:
836 warn_ctor_dtor_privacy = on;
839 case OPT_Wdeprecated:
840 warn_deprecated = on;
841 cpp_opts->warn_deprecated = on;
844 case OPT_Wdiv_by_zero:
845 warn_div_by_zero = on;
852 case OPT_Wendif_labels:
853 cpp_opts->warn_endif_labels = on;
857 cpp_opts->warnings_are_errors = on;
860 case OPT_Werror_implicit_function_decl:
864 mesg_implicit_function_declaration = 2;
867 case OPT_Wfloat_equal:
868 warn_float_equal = on;
876 set_Wformat (atoi (arg));
879 case OPT_Wformat_extra_args:
880 warn_format_extra_args = on;
883 case OPT_Wformat_nonliteral:
884 warn_format_nonliteral = on;
887 case OPT_Wformat_security:
888 warn_format_security = on;
891 case OPT_Wformat_y2k:
892 warn_format_y2k = on;
895 case OPT_Wformat_zero_length:
896 warn_format_zero_length = on;
903 case OPT_Wimplicit_function_decl:
904 mesg_implicit_function_declaration = on;
907 case OPT_Wimplicit_int:
908 warn_implicit_int = on;
912 cpp_opts->warn_import = on;
915 case OPT_Winvalid_pch:
916 cpp_opts->warn_invalid_pch = on;
930 case OPT_Wmissing_braces:
931 warn_missing_braces = on;
934 case OPT_Wmissing_declarations:
935 warn_missing_declarations = on;
938 case OPT_Wmissing_format_attribute:
939 warn_missing_format_attribute = on;
942 case OPT_Wmissing_prototypes:
943 warn_missing_prototypes = on;
947 cpp_opts->warn_multichar = on;
950 case OPT_Wnested_externs:
951 warn_nested_externs = on;
954 case OPT_Wnon_template_friend:
955 warn_nontemplate_friend = on;
958 case OPT_Wnon_virtual_dtor:
966 case OPT_Wold_style_cast:
967 warn_old_style_cast = on;
970 case OPT_Woverloaded_virtual:
971 warn_overloaded_virtual = on;
974 case OPT_Wparentheses:
975 warn_parentheses = on;
978 case OPT_Wpmf_conversions:
982 case OPT_Wpointer_arith:
983 warn_pointer_arith = on;
994 case OPT_Wredundant_decls:
995 warn_redundant_decls = on;
1002 case OPT_Wreturn_type:
1003 warn_return_type = on;
1006 case OPT_Wsequence_point:
1007 warn_sequence_point = on;
1010 case OPT_Wsign_compare:
1011 warn_sign_compare = on;
1014 case OPT_Wsign_promo:
1015 warn_sign_promo = on;
1018 case OPT_Wstrict_prototypes:
1019 if (!on && c_language == clk_cplusplus)
1020 warning ("-Wno-strict-prototypes is not supported in C++");
1022 warn_strict_prototypes = on;
1029 case OPT_Wsystem_headers:
1030 cpp_opts->warn_system_headers = on;
1033 case OPT_Wtraditional:
1034 warn_traditional = on;
1035 cpp_opts->warn_traditional = on;
1038 case OPT_Wtrigraphs:
1039 cpp_opts->warn_trigraphs = on;
1042 case OPT_Wundeclared_selector:
1043 warn_undeclared_selector = on;
1047 cpp_opts->warn_undef = on;
1050 case OPT_Wunknown_pragmas:
1051 /* Set to greater than 1, so that even unknown pragmas in
1052 system headers will be warned about. */
1053 warn_unknown_pragmas = on * 2;
1056 case OPT_Wunused_macros:
1057 warn_unused_macros = on;
1060 case OPT_Wwrite_strings:
1061 if (c_language == clk_c)
1062 flag_const_strings = on;
1064 warn_write_strings = on;
1068 if (c_language == clk_c)
1069 set_std_c89 (false, true);
1071 set_std_cxx98 (true);
1078 case OPT_fcond_mismatch:
1079 if (c_language == clk_c)
1081 flag_cond_mismatch = on;
1086 case OPT_fall_virtual:
1087 case OPT_fenum_int_equiv:
1088 case OPT_fguiding_decls:
1089 case OPT_fhonor_std:
1090 case OPT_fhuge_objects:
1091 case OPT_flabels_ok:
1092 case OPT_fname_mangling:
1094 case OPT_fnonnull_objects:
1096 case OPT_fstrict_prototype:
1097 case OPT_fthis_is_variable:
1098 case OPT_fvtable_thunks:
1100 warning ("switch \"%s\" is no longer supported", argv[0]);
1103 case OPT_fabi_version:
1104 flag_abi_version = read_integral_parameter (arg, argv[0], 1);
1107 case OPT_faccess_control:
1108 flag_access_control = on;
1111 case OPT_falt_external_templates:
1112 flag_alt_external_templates = on;
1114 flag_external_templates = true;
1116 warning ("switch \"%s\" is deprecated, please see documentation for details", argv[0]);
1124 flag_no_builtin = !on;
1131 disable_builtin_function (arg);
1134 case OPT_fdollars_in_identifiers:
1135 dollars_in_ident = on;
1139 if (!on || !dump_switch_p (argv[0] + strlen ("-f")))
1143 case OPT_ffreestanding:
1145 /* Fall through... */
1148 flag_no_builtin = !on;
1149 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
1150 if (!on && warn_main == 2)
1154 case OPT_fshort_double:
1155 flag_short_double = on;
1158 case OPT_fshort_enums:
1159 flag_short_enums = on;
1162 case OPT_fshort_wchar:
1163 flag_short_wchar = on;
1166 case OPT_fsigned_bitfields:
1167 flag_signed_bitfields = on;
1168 explicit_flag_signed_bitfields = 1;
1171 case OPT_fsigned_char:
1172 flag_signed_char = on;
1175 case OPT_funsigned_bitfields:
1176 flag_signed_bitfields = !on;
1177 explicit_flag_signed_bitfields = 1;
1180 case OPT_funsigned_char:
1181 flag_signed_char = !on;
1184 case OPT_fcheck_new:
1185 flag_check_new = on;
1188 case OPT_fconserve_space:
1189 flag_conserve_space = on;
1192 case OPT_fconst_strings:
1193 flag_const_strings = on;
1196 case OPT_fconstant_string_class:
1197 constant_string_class_name = arg;
1200 case OPT_fdefault_inline:
1201 flag_default_inline = on;
1204 case OPT_felide_constructors:
1205 flag_elide_constructors = on;
1208 case OPT_fenforce_eh_specs:
1209 flag_enforce_eh_specs = on;
1212 case OPT_fexternal_templates:
1213 flag_external_templates = on;
1216 case OPT_ffixed_form:
1217 case OPT_ffixed_line_length:
1218 /* Fortran front end options ignored when preprocessing only. */
1219 if (flag_preprocess_only)
1223 case OPT_ffor_scope:
1224 flag_new_for_scope = on;
1227 case OPT_fgnu_keywords:
1228 flag_no_gnu_keywords = !on;
1231 case OPT_fgnu_runtime:
1232 flag_next_runtime = !on;
1235 case OPT_fhandle_exceptions:
1236 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
1237 flag_exceptions = on;
1240 case OPT_fimplement_inlines:
1241 flag_implement_inlines = on;
1244 case OPT_fimplicit_inline_templates:
1245 flag_implicit_inline_templates = on;
1248 case OPT_fimplicit_templates:
1249 flag_implicit_templates = on;
1252 case OPT_fms_extensions:
1253 flag_ms_extensions = on;
1256 case OPT_fnext_runtime:
1257 flag_next_runtime = on;
1260 case OPT_fnonansi_builtins:
1261 flag_no_nonansi_builtin = !on;
1264 case OPT_foperator_names:
1265 cpp_opts->operator_names = on;
1268 case OPT_foptional_diags:
1269 flag_optional_diags = on;
1273 cpp_opts->restore_pch_deps = on;
1276 case OPT_fpermissive:
1277 flag_permissive = on;
1280 case OPT_fpreprocessed:
1281 cpp_opts->preprocessed = on;
1285 flag_use_repository = on;
1287 flag_implicit_templates = 0;
1294 case OPT_fshow_column:
1295 cpp_opts->show_column = on;
1299 flag_detailed_statistics = on;
1303 /* Don't recognize -fno-tabstop=. */
1307 /* It is documented that we silently ignore silly values. */
1310 long tabstop = strtol (arg, &endptr, 10);
1311 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
1312 cpp_opts->tabstop = tabstop;
1316 case OPT_ftemplate_depth:
1317 max_tinst_depth = read_integral_parameter (arg, argv[0], 0);
1320 case OPT_fvtable_gc:
1321 flag_vtable_gc = on;
1324 case OPT_fuse_cxa_atexit:
1325 flag_use_cxa_atexit = on;
1333 flag_gen_declaration = 1;
1337 add_path (xstrdup (arg), AFTER, 0);
1342 defer_opt (code, arg);
1354 add_path (xstrdup (arg), SYSTEM, 0);
1357 case OPT_iwithprefix:
1358 add_prefixed_path (arg, SYSTEM);
1361 case OPT_iwithprefixbefore:
1362 add_prefixed_path (arg, BRACKET);
1366 cpp_set_lang (parse_in, CLK_ASM);
1377 case OPT_nostdincplusplus:
1378 std_cxx_inc = false;
1386 error ("output filename specified twice");
1391 /* We need to handle the -pedantic switches here, rather than in
1392 c_common_post_options, so that a subsequent -Wno-endif-labels
1393 is not overridden. */
1394 case OPT_pedantic_errors:
1395 cpp_opts->pedantic_errors = 1;
1398 cpp_opts->pedantic = 1;
1399 cpp_opts->warn_endif_labels = 1;
1402 case OPT_print_objc_runtime_info:
1403 print_struct_values = 1;
1407 cpp_opts->remap = 1;
1410 case OPT_std_cplusplus98:
1411 case OPT_std_gnuplusplus98:
1412 set_std_cxx98 (code == OPT_std_cplusplus98 /* ISO */);
1416 case OPT_std_iso9899_1990:
1417 case OPT_std_iso9899_199409:
1418 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
1422 set_std_c89 (false /* c94 */, false /* ISO */);
1427 case OPT_std_iso9899_1999:
1428 case OPT_std_iso9899_199x:
1429 set_std_c99 (true /* ISO */);
1434 set_std_c99 (false /* ISO */);
1438 cpp_opts->trigraphs = 1;
1441 case OPT_traditional_cpp:
1442 cpp_opts->traditional = 1;
1450 cpp_opts->inhibit_warnings = 1;
1464 /* Post-switch processing. */
1466 c_common_post_options (pfilename)
1467 const char **pfilename;
1469 /* Canonicalize the input and output filenames. */
1470 if (in_fname == NULL || !strcmp (in_fname, "-"))
1473 if (out_fname == NULL || !strcmp (out_fname, "-"))
1476 if (cpp_opts->deps.style == DEPS_NONE)
1477 check_deps_environment_vars ();
1479 handle_deferred_opts ();
1481 sanitize_cpp_opts ();
1483 register_include_chains (parse_in, sysroot, iprefix,
1484 std_inc, std_cxx_inc && c_language == clk_cplusplus,
1487 flag_inline_trees = 1;
1489 /* Use tree inlining if possible. Function instrumentation is only
1490 done in the RTL level, so we disable tree inlining. */
1491 if (! flag_instrument_function_entry_exit)
1493 if (!flag_no_inline)
1495 if (flag_inline_functions)
1497 flag_inline_trees = 2;
1498 flag_inline_functions = 0;
1502 /* Special format checking options don't work without -Wformat; warn if
1504 if (warn_format_y2k && !warn_format)
1505 warning ("-Wformat-y2k ignored without -Wformat");
1506 if (warn_format_extra_args && !warn_format)
1507 warning ("-Wformat-extra-args ignored without -Wformat");
1508 if (warn_format_zero_length && !warn_format)
1509 warning ("-Wformat-zero-length ignored without -Wformat");
1510 if (warn_format_nonliteral && !warn_format)
1511 warning ("-Wformat-nonliteral ignored without -Wformat");
1512 if (warn_format_security && !warn_format)
1513 warning ("-Wformat-security ignored without -Wformat");
1514 if (warn_missing_format_attribute && !warn_format)
1515 warning ("-Wmissing-format-attribute ignored without -Wformat");
1517 if (flag_preprocess_only)
1519 /* Open the output now. We must do so even if flag_no_output is
1520 on, because there may be other output than from the actual
1521 preprocessing (e.g. from -dM). */
1522 if (out_fname[0] == '\0')
1523 out_stream = stdout;
1525 out_stream = fopen (out_fname, "w");
1527 if (out_stream == NULL)
1529 fatal_io_error ("opening output file %s", out_fname);
1533 init_pp_output (out_stream);
1539 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
1543 cpp_get_callbacks (parse_in)->file_change = cb_file_change;
1545 /* NOTE: we use in_fname here, not the one supplied. */
1546 *pfilename = cpp_read_main_file (parse_in, in_fname, ident_hash);
1548 saved_lineno = lineno;
1551 /* If an error has occurred in cpplib, note it so we fail
1553 errorcount += cpp_errors (parse_in);
1555 return flag_preprocess_only;
1558 /* Front end initialization common to C, ObjC and C++. */
1562 lineno = saved_lineno;
1564 /* Set up preprocessor arithmetic. Must be done after call to
1565 c_common_nodes_and_builtins for type nodes to be good. */
1566 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1567 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1568 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1569 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1570 cpp_opts->unsigned_wchar = TREE_UNSIGNED (wchar_type_node);
1572 if (flag_preprocess_only)
1575 preprocess_file (parse_in);
1579 /* Has to wait until now so that cpplib has its hash table. */
1585 /* A thin wrapper around the real parser that initializes the
1586 integrated preprocessor after debug output has been initialized.
1587 Also, make sure the start_source_file debug hook gets called for
1588 the primary source file. */
1590 c_common_parse_file (set_yydebug)
1591 int set_yydebug ATTRIBUTE_UNUSED;
1594 yydebug = set_yydebug;
1596 warning ("YYDEBUG not defined");
1599 (*debug_hooks->start_source_file) (lineno, input_filename);
1603 free_parser_stacks ();
1606 /* Common finish hook for the C, ObjC and C++ front ends. */
1610 FILE *deps_stream = NULL;
1612 if (cpp_opts->deps.style != DEPS_NONE)
1614 /* If -M or -MM was seen without -MF, default output to the
1617 deps_stream = out_stream;
1620 deps_stream = fopen (deps_file, deps_append ? "a": "w");
1622 fatal_io_error ("opening dependency file %s", deps_file);
1626 /* For performance, avoid tearing down cpplib's internal structures
1627 with cpp_destroy (). */
1628 errorcount += cpp_finish (parse_in, deps_stream);
1630 if (deps_stream && deps_stream != out_stream
1631 && (ferror (deps_stream) || fclose (deps_stream)))
1632 fatal_io_error ("closing dependency file %s", deps_file);
1634 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1635 fatal_io_error ("when writing output to %s", out_fname);
1638 /* Either of two environment variables can specify output of
1639 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1640 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1641 and DEPS_TARGET is the target to mention in the deps. They also
1642 result in dependency information being appended to the output file
1643 rather than overwriting it, and like Sun's compiler
1644 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
1646 check_deps_environment_vars ()
1650 GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
1652 cpp_opts->deps.style = DEPS_USER;
1655 GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
1658 cpp_opts->deps.style = DEPS_SYSTEM;
1659 cpp_opts->deps.ignore_main_file = true;
1665 /* Find the space before the DEPS_TARGET, if there is one. */
1666 char *s = strchr (spec, ' ');
1669 /* Let the caller perform MAKE quoting. */
1670 defer_opt (OPT_MT, s + 1);
1674 /* Command line -MF overrides environment variables and default. */
1682 /* Handle deferred command line switches. */
1684 handle_deferred_opts ()
1688 for (i = 0; i < deferred_count; i++)
1690 struct deferred_opt *opt = &deferred_opts[i];
1696 cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
1709 /* These settings are appropriate for GCC, but not necessarily so for
1710 cpplib as a library. */
1712 sanitize_cpp_opts ()
1714 /* If we don't know what style of dependencies to output, complain
1715 if any other dependency switches have been given. */
1716 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1717 error ("to generate dependencies you must specify either -M or -MM");
1719 /* -dM and dependencies suppress normal output; do it here so that
1720 the last -d[MDN] switch overrides earlier ones. */
1721 if (flag_dump_macros == 'M')
1724 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1725 -dM since at least glibc relies on -M -dM to work. */
1728 if (flag_dump_macros != 'M')
1729 flag_dump_macros = 0;
1730 flag_dump_includes = 0;
1733 cpp_opts->unsigned_char = !flag_signed_char;
1734 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1736 /* We want -Wno-long-long to override -pedantic -std=non-c99
1737 and/or -Wtraditional, whatever the ordering. */
1738 cpp_opts->warn_long_long
1739 = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
1742 /* Add include path with a prefix at the front of its name. */
1744 add_prefixed_path (suffix, chain)
1750 size_t prefix_len, suffix_len;
1752 suffix_len = strlen (suffix);
1753 prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1754 prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1756 path = xmalloc (prefix_len + suffix_len + 1);
1757 memcpy (path, prefix, prefix_len);
1758 memcpy (path + prefix_len, suffix, suffix_len);
1759 path[prefix_len + suffix_len] = '\0';
1761 add_path (path, chain, 0);
1764 /* Handle -D, -U, -A, -imacros, and the first -include. */
1768 cpp_finish_options (parse_in);
1770 if (!cpp_opts->preprocessed)
1774 /* Handle -imacros after -D, -U and -A. */
1775 for (i = 0; i < deferred_count; i++)
1777 struct deferred_opt *opt = &deferred_opts[i];
1779 if (opt->code == OPT_imacros
1780 && cpp_push_include (parse_in, opt->arg))
1781 cpp_scan_nooutput (parse_in);
1785 push_command_line_include ();
1788 /* Give CPP the next file given by -include, if any. */
1790 push_command_line_include ()
1792 if (cpp_opts->preprocessed)
1795 while (include_cursor < deferred_count)
1797 struct deferred_opt *opt = &deferred_opts[include_cursor++];
1799 if (opt->code == OPT_include && cpp_push_include (parse_in, opt->arg))
1803 if (include_cursor == deferred_count)
1805 /* Restore the line map from <command line>. */
1806 cpp_rename_file (parse_in, main_input_filename);
1807 /* -Wunused-macros should only warn about macros defined hereafter. */
1808 cpp_opts->warn_unused_macros = warn_unused_macros;
1813 /* File change callback. Has to handle -include files. */
1815 cb_file_change (pfile, new_map)
1816 cpp_reader *pfile ATTRIBUTE_UNUSED;
1817 const struct line_map *new_map;
1819 if (flag_preprocess_only)
1820 pp_file_change (new_map);
1822 fe_file_change (new_map);
1824 if (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map))
1825 push_command_line_include ();
1828 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1829 extensions if ISO). There is no concept of gnu94. */
1831 set_std_c89 (c94, iso)
1834 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1837 flag_no_gnu_keywords = iso;
1838 flag_no_nonansi_builtin = iso;
1839 flag_noniso_default_format_attributes = !iso;
1842 flag_writable_strings = 0;
1845 /* Set the C 99 standard (without GNU extensions if ISO). */
1850 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1852 flag_no_nonansi_builtin = iso;
1853 flag_noniso_default_format_attributes = !iso;
1857 flag_writable_strings = 0;
1860 /* Set the C++ 98 standard (without GNU extensions if ISO). */
1865 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1866 flag_no_gnu_keywords = iso;
1867 flag_no_nonansi_builtin = iso;
1868 flag_noniso_default_format_attributes = !iso;
1872 /* Handle setting implicit to ON. */
1878 warn_implicit_int = on;
1881 if (mesg_implicit_function_declaration != 2)
1882 mesg_implicit_function_declaration = 1;
1885 mesg_implicit_function_declaration = 0;
1888 /* Args to -d specify what to dump. Silently ignore
1889 unrecognized options; they may be aimed at toplev.c. */
1896 while ((c = *arg++) != '\0')
1899 case 'M': /* Dump macros only. */
1900 case 'N': /* Dump names. */
1901 case 'D': /* Dump definitions. */
1902 flag_dump_macros = c;
1906 flag_dump_includes = 1;
1911 /* Write a slash-separated list of languages in FLAGS to BUF. */
1913 write_langs (buf, flags)
1918 if (flags & CL_C_ONLY)
1920 if (flags & CL_OBJC_ONLY)
1924 strcat (buf, "ObjC");
1926 if (flags & CL_CXX_ONLY)
1930 strcat (buf, "C++");
1934 /* Complain that switch OPT_INDEX does not apply to this front end. */
1936 complain_wrong_lang (opt_index)
1939 char ok_langs[60], bad_langs[60];
1940 int ok_flags = cl_options[opt_index].flags;
1942 write_langs (ok_langs, ok_flags);
1943 write_langs (bad_langs, ~ok_flags);
1944 warning ("\"-%s\" is valid for %s but not for %s",
1945 cl_options[opt_index].opt_text, ok_langs, bad_langs);
1948 /* Handle --help output. */
1952 /* To keep the lines from getting too long for some compilers, limit
1953 to about 500 characters (6 lines) per chunk. */
1956 -include <file> Include the contents of <file> before other files\n\
1957 -imacros <file> Accept definition of macros in <file>\n\
1958 -iprefix <path> Specify <path> as a prefix for next two options\n\
1959 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1960 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1961 -isystem <dir> Add <dir> to the start of the system include path\n\
1964 -idirafter <dir> Add <dir> to the end of the system include path\n\
1965 -I <dir> Add <dir> to the end of the main include path\n\
1966 -I- Fine-grained include path control; see info docs\n\
1967 -nostdinc Do not search system include directories\n\
1968 (dirs specified with -isystem will still be used)\n\
1969 -nostdinc++ Do not search system include directories for C++\n\
1970 -o <file> Put output into <file>\n\
1973 -trigraphs Support ISO C trigraphs\n\
1974 -std=<std name> Specify the conformance standard; one of:\n\
1975 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1976 iso9899:199409, iso9899:1999, c++98\n\
1977 -w Inhibit warning messages\n\
1978 -W[no-]trigraphs Warn if trigraphs are encountered\n\
1979 -W[no-]comment{s} Warn if one comment starts inside another\n\
1982 -W[no-]traditional Warn about features not present in traditional C\n\
1983 -W[no-]undef Warn if an undefined macro is used by #if\n\
1984 -W[no-]import Warn about the use of the #import directive\n\
1987 -W[no-]error Treat all warnings as errors\n\
1988 -W[no-]system-headers Do not suppress warnings from system headers\n\
1989 -W[no-]all Enable most preprocessor warnings\n\
1992 -M Generate make dependencies\n\
1993 -MM As -M, but ignore system header files\n\
1994 -MD Generate make dependencies and compile\n\
1995 -MMD As -MD, but ignore system header files\n\
1996 -MF <file> Write dependency output to the given file\n\
1997 -MG Treat missing header file as generated files\n\
2000 -MP Generate phony targets for all headers\n\
2001 -MQ <target> Add a MAKE-quoted target\n\
2002 -MT <target> Add an unquoted target\n\
2005 -D<macro> Define a <macro> with string '1' as its value\n\
2006 -D<macro>=<val> Define a <macro> with <val> as its value\n\
2007 -A<question>=<answer> Assert the <answer> to <question>\n\
2008 -A-<question>=<answer> Disable the <answer> to <question>\n\
2009 -U<macro> Undefine <macro> \n\
2010 -v Display the version number\n\
2013 -H Print the name of header files as they are used\n\
2014 -C Do not discard comments\n\
2015 -dM Display a list of macro definitions active at end\n\
2016 -dD Preserve macro definitions in output\n\
2017 -dN As -dD except that only the names are preserved\n\
2018 -dI Include #include directives in the output\n\
2021 -f[no-]preprocessed Treat the input file as already preprocessed\n\
2022 -ftabstop=<number> Distance between tab stops for column reporting\n\
2023 -isysroot <dir> Set <dir> to be the system root directory\n\
2024 -P Do not generate #line directives\n\
2025 -remap Remap file names when including files\n\
2026 --help Display this information\n\