]> gcc.gnu.org Git - gcc.git/blame - gcc/c-opts.c
re PR c++/13684 (local static object variable constructed once but ctors and dtors...
[gcc.git] / gcc / c-opts.c
CommitLineData
0b6f2917 1/* C/ObjC/C++ command line option handling.
d9221e01 2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
0b6f2917
NB
3 Contributed by Neil Booth.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
21
22#include "config.h"
23#include "system.h"
4977bab6
ZW
24#include "coretypes.h"
25#include "tm.h"
0b6f2917
NB
26#include "tree.h"
27#include "c-common.h"
28#include "c-pragma.h"
29#include "flags.h"
30#include "toplev.h"
31#include "langhooks.h"
32#include "tree-inline.h"
33#include "diagnostic.h"
4b7091eb 34#include "intl.h"
5793b276
NB
35#include "cppdefault.h"
36#include "c-incpath.h"
23345bbb 37#include "debug.h" /* For debug_hooks. */
2772ef3e 38#include "opts.h"
d7b42618 39#include "options.h"
c6e83800 40#include "mkdeps.h"
5793b276 41
b1822ccc
NB
42#ifndef DOLLARS_IN_IDENTIFIERS
43# define DOLLARS_IN_IDENTIFIERS true
44#endif
45
5793b276
NB
46#ifndef TARGET_SYSTEM_ROOT
47# define TARGET_SYSTEM_ROOT NULL
48#endif
0b6f2917 49
7cd60054
AM
50#ifndef TARGET_OPTF
51#define TARGET_OPTF(ARG)
52#endif
53
f4ff5a69 54/* CPP's options. */
18bdccaa
NB
55static cpp_options *cpp_opts;
56
460bd0e3 57/* Input filename. */
89e9faee 58static const char *this_input_filename;
460bd0e3 59
76c3e73e
NB
60/* Filename and stream for preprocessed output. */
61static const char *out_fname;
62static FILE *out_stream;
63
64/* Append dependencies to deps_file. */
65static bool deps_append;
66
f4ff5a69
NB
67/* If dependency switches (-MF etc.) have been given. */
68static bool deps_seen;
69
5793b276
NB
70/* If -v seen. */
71static bool verbose;
72
f4ff5a69
NB
73/* Dependency output file. */
74static const char *deps_file;
75
5793b276
NB
76/* The prefix given by -iprefix, if any. */
77static const char *iprefix;
78
79/* The system root, if any. Overridden by -isysroot. */
80static const char *sysroot = TARGET_SYSTEM_ROOT;
81
82/* Zero disables all standard directories for headers. */
83static bool std_inc = true;
84
85/* Zero disables the C++-specific standard directories for headers. */
86static bool std_cxx_inc = true;
87
88/* If the quote chain has been split by -I-. */
89static bool quote_chain_split;
90
23345bbb
NB
91/* If -Wunused-macros. */
92static bool warn_unused_macros;
93
e5b79219
RH
94/* If -Wvariadic-macros. */
95static bool warn_variadic_macros = true;
96
b86f6cd9
NB
97/* Number of deferred options. */
98static size_t deferred_count;
f4ff5a69 99
23345bbb
NB
100/* Number of deferred options scanned for -include. */
101static size_t include_cursor;
102
1ae58c30 103/* Permit Fortran front-end options. */
33de9573
NB
104static bool permit_fortran_options;
105
2f6e4e97 106static void set_Wimplicit (int);
2f6e4e97
AJ
107static void handle_OPT_d (const char *);
108static void set_std_cxx98 (int);
109static void set_std_c89 (int, int);
110static void set_std_c99 (int);
111static void check_deps_environment_vars (void);
112static void handle_deferred_opts (void);
113static void sanitize_cpp_opts (void);
114static void add_prefixed_path (const char *, size_t);
115static void push_command_line_include (void);
116static void cb_file_change (cpp_reader *, const struct line_map *);
8e9ea4d7
PB
117static void cb_dir_change (cpp_reader *, const char *);
118static void finish_options (void);
460bd0e3
NB
119
120#ifndef STDC_0_IN_SYSTEM_HEADERS
121#define STDC_0_IN_SYSTEM_HEADERS 0
122#endif
0b6f2917 123
2772ef3e 124/* Holds switches parsed by c_common_handle_option (), but whose
95bd1dd7 125 handling is deferred to c_common_post_options (). */
2f6e4e97 126static void defer_opt (enum opt_code, const char *);
f4ff5a69
NB
127static struct deferred_opt
128{
129 enum opt_code code;
130 const char *arg;
131} *deferred_opts;
132
cb66e385
NB
133/* Complain that switch CODE expects an argument but none was
134 provided. OPT was the command-line option. Return FALSE to get
135 the default message in opts.c, TRUE if we provide a specialized
136 one. */
137bool
138c_common_missing_argument (const char *opt, size_t code)
4b7091eb 139{
2772ef3e 140 switch (code)
4b7091eb 141 {
4b7091eb 142 default:
cb66e385
NB
143 /* Pick up the default message. */
144 return false;
4b7091eb 145
fef3106c 146 case OPT_fconstant_string_class_:
cb66e385 147 error ("no class name specified with \"%s\"", opt);
4b7091eb 148 break;
b4a93904 149
c1bad961 150 case OPT_A:
cb66e385 151 error ("assertion missing after \"%s\"", opt);
c1bad961
NB
152 break;
153
154 case OPT_D:
155 case OPT_U:
cb66e385 156 error ("macro name missing after \"%s\"", opt);
c1bad961
NB
157 break;
158
94d1613b 159 case OPT_F:
5793b276
NB
160 case OPT_I:
161 case OPT_idirafter:
162 case OPT_isysroot:
163 case OPT_isystem:
4bed3787 164 case OPT_iquote:
cb66e385 165 error ("missing path after \"%s\"", opt);
5793b276
NB
166 break;
167
f4ff5a69
NB
168 case OPT_MF:
169 case OPT_MD:
170 case OPT_MMD:
255c10b1
NB
171 case OPT_include:
172 case OPT_imacros:
b4a93904 173 case OPT_o:
cb66e385 174 error ("missing filename after \"%s\"", opt);
f4ff5a69
NB
175 break;
176
177 case OPT_MQ:
178 case OPT_MT:
cb66e385 179 error ("missing makefile target after \"%s\"", opt);
b4a93904 180 break;
4b7091eb 181 }
cb66e385
NB
182
183 return true;
4b7091eb
NB
184}
185
f4ff5a69
NB
186/* Defer option CODE with argument ARG. */
187static void
2f6e4e97 188defer_opt (enum opt_code code, const char *arg)
f4ff5a69 189{
f4ff5a69
NB
190 deferred_opts[deferred_count].code = code;
191 deferred_opts[deferred_count].arg = arg;
192 deferred_count++;
193}
194
0b6f2917 195/* Common initialization before parsing options. */
b86f6cd9 196unsigned int
e18476eb 197c_common_init_options (unsigned int argc, const char ** ARG_UNUSED (argv))
0b6f2917 198{
b86f6cd9 199 static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
33de9573 200 unsigned int result;
37fa72e9
NB
201
202 /* This is conditionalized only because that is the way the front
203 ends used to do it. Maybe this should be unconditional? */
204 if (c_dialect_cxx ())
205 {
206 /* By default wrap lines at 80 characters. Is getenv
207 ("COLUMNS") preferable? */
208 diagnostic_line_cutoff (global_dc) = 80;
209 /* By default, emit location information once for every
210 diagnostic message. */
211 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
212 }
213
214 parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
50f59cd7 215 ident_hash, &line_table);
37fa72e9 216
18bdccaa 217 cpp_opts = cpp_get_options (parse_in);
b1822ccc 218 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
37fa72e9 219 cpp_opts->objc = c_dialect_objc ();
78b8811a
HPN
220
221 /* Reset to avoid warnings on internal definitions. We set it just
222 before passing on command-line options to cpplib. */
223 cpp_opts->warn_dollars = 0;
224
37fa72e9
NB
225 flag_const_strings = c_dialect_cxx ();
226 flag_exceptions = c_dialect_cxx ();
227 warn_pointer_arith = c_dialect_cxx ();
2772ef3e 228
5d038c4c 229 deferred_opts = XNEWVEC (struct deferred_opt, argc);
b86f6cd9 230
33de9573
NB
231 result = lang_flags[c_language];
232
233 /* If potentially preprocessing Fortran we have to accept its front
234 end options since the driver passes most of them through. */
235#ifdef CL_F77
236 if (c_language == clk_c && argc > 2
237 && !strcmp (argv[2], "-traditional-cpp" ))
238 {
239 permit_fortran_options = true;
240 result |= CL_F77;
241 }
242#endif
243
244 return result;
0b6f2917
NB
245}
246
b20d9f0c 247/* Handle switch SCODE with argument ARG. VALUE is true, unless no-
2772ef3e
NB
248 form of an -f or -W option was given. Returns 0 if the switch was
249 invalid, a negative number to prevent language-independent
250 processing in toplev.c (a hack necessary for the short-term). */
0b6f2917 251int
7b086b11 252c_common_handle_option (size_t scode, const char *arg, int value)
0b6f2917 253{
2772ef3e
NB
254 const struct cl_option *option = &cl_options[scode];
255 enum opt_code code = (enum opt_code) scode;
f18754d6 256 int result = 1;
2772ef3e 257
fef3106c 258 switch (code)
0b6f2917 259 {
2772ef3e 260 default:
7619c085
DD
261 if (cl_options[code].flags & (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX))
262 break;
33de9573
NB
263 result = permit_fortran_options;
264 break;
0b6f2917 265
fef3106c 266 case OPT__output_pch_:
17211ab5
GK
267 pch_file = arg;
268 break;
269
c1bad961
NB
270 case OPT_A:
271 defer_opt (code, arg);
272 break;
273
4b7091eb
NB
274 case OPT_C:
275 cpp_opts->discard_comments = 0;
276 break;
277
278 case OPT_CC:
279 cpp_opts->discard_comments = 0;
280 cpp_opts->discard_comments_in_macro_exp = 0;
281 break;
282
c1bad961
NB
283 case OPT_D:
284 defer_opt (code, arg);
285 break;
286
0b6f2917
NB
287 case OPT_E:
288 flag_preprocess_only = 1;
289 break;
290
4b7091eb
NB
291 case OPT_H:
292 cpp_opts->print_include_names = 1;
293 break;
294
94d1613b
MS
295 case OPT_F:
296 TARGET_OPTF (xstrdup (arg));
297 break;
298
5793b276
NB
299 case OPT_I:
300 if (strcmp (arg, "-"))
b02398bd 301 add_path (xstrdup (arg), BRACKET, 0, true);
5793b276
NB
302 else
303 {
304 if (quote_chain_split)
305 error ("-I- specified twice");
306 quote_chain_split = true;
307 split_quote_chain ();
4bed3787 308 inform ("obsolete option -I- used, please use -iquote instead");
5793b276
NB
309 }
310 break;
311
f4ff5a69
NB
312 case OPT_M:
313 case OPT_MM:
314 /* When doing dependencies with -M or -MM, suppress normal
315 preprocessed output, but still do -dM etc. as software
316 depends on this. Preprocessed output does occur if -MD, -MMD
317 or environment var dependency generation is used. */
318 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
63973df3 319 flag_no_output = 1;
f4ff5a69
NB
320 cpp_opts->inhibit_warnings = 1;
321 break;
322
323 case OPT_MD:
324 case OPT_MMD:
325 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
326 deps_file = arg;
327 break;
328
329 case OPT_MF:
330 deps_seen = true;
331 deps_file = arg;
332 break;
333
334 case OPT_MG:
335 deps_seen = true;
336 cpp_opts->deps.missing_files = true;
337 break;
338
339 case OPT_MP:
340 deps_seen = true;
341 cpp_opts->deps.phony_targets = true;
342 break;
343
344 case OPT_MQ:
345 case OPT_MT:
346 deps_seen = true;
347 defer_opt (code, arg);
348 break;
349
4b7091eb 350 case OPT_P:
63973df3 351 flag_no_line_commands = 1;
4b7091eb
NB
352 break;
353
b20d9f0c
AO
354 case OPT_fworking_directory:
355 flag_working_directory = value;
356 break;
357
c1bad961
NB
358 case OPT_U:
359 defer_opt (code, arg);
360 break;
361
0b6f2917 362 case OPT_Wall:
7b086b11
NB
363 set_Wunused (value);
364 set_Wformat (value);
365 set_Wimplicit (value);
366 warn_char_subscripts = value;
367 warn_missing_braces = value;
368 warn_parentheses = value;
369 warn_return_type = value;
370 warn_sequence_point = value; /* Was C only. */
37fa72e9 371 if (c_dialect_cxx ())
7b086b11
NB
372 warn_sign_compare = value;
373 warn_switch = value;
374 warn_strict_aliasing = value;
2f6e4e97 375
0b6f2917 376 /* Only warn about unknown pragmas that are not in system
2f6e4e97 377 headers. */
7b086b11 378 warn_unknown_pragmas = value;
0b6f2917
NB
379
380 /* We save the value of warn_uninitialized, since if they put
381 -Wuninitialized on the command line, we need to generate a
382 warning about not using it without also specifying -O. */
383 if (warn_uninitialized != 1)
7b086b11 384 warn_uninitialized = (value ? 2 : 0);
0b6f2917 385
37fa72e9 386 if (!c_dialect_cxx ())
0b6f2917
NB
387 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
388 can turn it off only if it's not explicit. */
7b086b11 389 warn_main = value * 2;
0b6f2917
NB
390 else
391 {
392 /* C++-specific warnings. */
7b086b11
NB
393 warn_nonvdtor = value;
394 warn_reorder = value;
395 warn_nontemplate_friend = value;
0b6f2917 396 }
18bdccaa 397
7b086b11
NB
398 cpp_opts->warn_trigraphs = value;
399 cpp_opts->warn_comments = value;
400 cpp_opts->warn_num_sign_change = value;
401 cpp_opts->warn_multichar = value; /* Was C++ only. */
0b6f2917
NB
402 break;
403
18bdccaa
NB
404 case OPT_Wcomment:
405 case OPT_Wcomments:
7b086b11 406 cpp_opts->warn_comments = value;
18bdccaa
NB
407 break;
408
0b6f2917 409 case OPT_Wdeprecated:
7b086b11 410 cpp_opts->warn_deprecated = value;
0b6f2917
NB
411 break;
412
413 case OPT_Wdiv_by_zero:
7b086b11 414 warn_div_by_zero = value;
0b6f2917
NB
415 break;
416
18bdccaa 417 case OPT_Wendif_labels:
7b086b11 418 cpp_opts->warn_endif_labels = value;
18bdccaa
NB
419 break;
420
421 case OPT_Werror:
7b086b11 422 cpp_opts->warnings_are_errors = value;
18bdccaa
NB
423 break;
424
fef3106c 425 case OPT_Werror_implicit_function_declaration:
c83857ff 426 mesg_implicit_function_declaration = 2;
0b6f2917
NB
427 break;
428
0b6f2917 429 case OPT_Wformat:
7b086b11 430 set_Wformat (value);
0b6f2917
NB
431 break;
432
fef3106c 433 case OPT_Wformat_:
0b6f2917
NB
434 set_Wformat (atoi (arg));
435 break;
436
0b6f2917 437 case OPT_Wimplicit:
7b086b11 438 set_Wimplicit (value);
0b6f2917
NB
439 break;
440
18bdccaa 441 case OPT_Wimport:
bf42e45b 442 /* Silently ignore for now. */
18bdccaa
NB
443 break;
444
17211ab5 445 case OPT_Winvalid_pch:
7b086b11 446 cpp_opts->warn_invalid_pch = value;
17211ab5
GK
447 break;
448
0b6f2917 449 case OPT_Wmain:
7b086b11 450 if (value)
0b6f2917
NB
451 warn_main = 1;
452 else
453 warn_main = -1;
454 break;
455
b02398bd
BE
456 case OPT_Wmissing_include_dirs:
457 cpp_opts->warn_missing_include_dirs = value;
458 break;
459
0b6f2917 460 case OPT_Wmultichar:
7b086b11 461 cpp_opts->warn_multichar = value;
0b6f2917
NB
462 break;
463
0b6f2917 464 case OPT_Wreturn_type:
7b086b11 465 warn_return_type = value;
0b6f2917
NB
466 break;
467
18bdccaa 468 case OPT_Wsystem_headers:
7b086b11 469 cpp_opts->warn_system_headers = value;
18bdccaa
NB
470 break;
471
0b6f2917 472 case OPT_Wtraditional:
7b086b11 473 cpp_opts->warn_traditional = value;
18bdccaa
NB
474 break;
475
476 case OPT_Wtrigraphs:
7b086b11 477 cpp_opts->warn_trigraphs = value;
18bdccaa
NB
478 break;
479
480 case OPT_Wundef:
7b086b11 481 cpp_opts->warn_undef = value;
0b6f2917
NB
482 break;
483
484 case OPT_Wunknown_pragmas:
485 /* Set to greater than 1, so that even unknown pragmas in
2f6e4e97 486 system headers will be warned about. */
7b086b11 487 warn_unknown_pragmas = value * 2;
0b6f2917
NB
488 break;
489
18bdccaa 490 case OPT_Wunused_macros:
7b086b11 491 warn_unused_macros = value;
18bdccaa
NB
492 break;
493
e5b79219
RH
494 case OPT_Wvariadic_macros:
495 warn_variadic_macros = value;
496 break;
497
0b6f2917 498 case OPT_Wwrite_strings:
37fa72e9 499 if (!c_dialect_cxx ())
7b086b11 500 flag_const_strings = value;
0b6f2917 501 else
7b086b11 502 warn_write_strings = value;
0b6f2917 503 break;
2f6e4e97 504
f749a36b 505 case OPT_ansi:
37fa72e9 506 if (!c_dialect_cxx ())
f749a36b
NB
507 set_std_c89 (false, true);
508 else
509 set_std_cxx98 (true);
510 break;
0b6f2917 511
4b7091eb
NB
512 case OPT_d:
513 handle_OPT_d (arg);
514 break;
515
0b6f2917 516 case OPT_fcond_mismatch:
37fa72e9 517 if (!c_dialect_cxx ())
0b6f2917 518 {
7b086b11 519 flag_cond_mismatch = value;
0b6f2917
NB
520 break;
521 }
522 /* Fall through. */
523
524 case OPT_fall_virtual:
7813d14c 525 case OPT_falt_external_templates:
0b6f2917 526 case OPT_fenum_int_equiv:
7813d14c 527 case OPT_fexternal_templates:
0b6f2917
NB
528 case OPT_fguiding_decls:
529 case OPT_fhonor_std:
530 case OPT_fhuge_objects:
531 case OPT_flabels_ok:
fef3106c 532 case OPT_fname_mangling_version_:
0b6f2917
NB
533 case OPT_fnew_abi:
534 case OPT_fnonnull_objects:
535 case OPT_fsquangle:
536 case OPT_fstrict_prototype:
537 case OPT_fthis_is_variable:
538 case OPT_fvtable_thunks:
539 case OPT_fxref:
a0c8285b 540 case OPT_fvtable_gc:
cf03fd63 541 warning ("switch \"%s\" is no longer supported", option->opt_text);
0b6f2917
NB
542 break;
543
544 case OPT_faccess_control:
7b086b11 545 flag_access_control = value;
0b6f2917
NB
546 break;
547
0b6f2917 548 case OPT_fasm:
7b086b11 549 flag_no_asm = !value;
0b6f2917
NB
550 break;
551
552 case OPT_fbuiltin:
7b086b11 553 flag_no_builtin = !value;
0b6f2917
NB
554 break;
555
556 case OPT_fbuiltin_:
7b086b11 557 if (value)
4b7091eb
NB
558 result = 0;
559 else
560 disable_builtin_function (arg);
0b6f2917
NB
561 break;
562
563 case OPT_fdollars_in_identifiers:
7b086b11 564 cpp_opts->dollars_in_ident = value;
0b6f2917
NB
565 break;
566
0b6f2917 567 case OPT_ffreestanding:
7b086b11 568 value = !value;
938d968e 569 /* Fall through.... */
0b6f2917 570 case OPT_fhosted:
7b086b11
NB
571 flag_hosted = value;
572 flag_no_builtin = !value;
0b6f2917 573 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
7b086b11 574 if (!value && warn_main == 2)
0b6f2917
NB
575 warn_main = 0;
576 break;
577
578 case OPT_fshort_double:
7b086b11 579 flag_short_double = value;
0b6f2917
NB
580 break;
581
582 case OPT_fshort_enums:
7b086b11 583 flag_short_enums = value;
0b6f2917
NB
584 break;
585
586 case OPT_fshort_wchar:
7b086b11 587 flag_short_wchar = value;
0b6f2917
NB
588 break;
589
590 case OPT_fsigned_bitfields:
7b086b11 591 flag_signed_bitfields = value;
0b6f2917
NB
592 explicit_flag_signed_bitfields = 1;
593 break;
594
595 case OPT_fsigned_char:
7b086b11 596 flag_signed_char = value;
0b6f2917
NB
597 break;
598
599 case OPT_funsigned_bitfields:
7b086b11 600 flag_signed_bitfields = !value;
0b6f2917
NB
601 explicit_flag_signed_bitfields = 1;
602 break;
603
604 case OPT_funsigned_char:
7b086b11 605 flag_signed_char = !value;
0b6f2917
NB
606 break;
607
608 case OPT_fcheck_new:
7b086b11 609 flag_check_new = value;
0b6f2917
NB
610 break;
611
612 case OPT_fconserve_space:
7b086b11 613 flag_conserve_space = value;
0b6f2917
NB
614 break;
615
616 case OPT_fconst_strings:
7b086b11 617 flag_const_strings = value;
0b6f2917
NB
618 break;
619
fef3106c 620 case OPT_fconstant_string_class_:
4b7091eb 621 constant_string_class_name = arg;
0b6f2917
NB
622 break;
623
624 case OPT_fdefault_inline:
7b086b11 625 flag_default_inline = value;
0b6f2917
NB
626 break;
627
628 case OPT_felide_constructors:
7b086b11 629 flag_elide_constructors = value;
0b6f2917
NB
630 break;
631
632 case OPT_fenforce_eh_specs:
7b086b11 633 flag_enforce_eh_specs = value;
0b6f2917
NB
634 break;
635
1c2de642 636 case OPT_ffixed_form:
fef3106c 637 case OPT_ffixed_line_length_:
1c2de642 638 /* Fortran front end options ignored when preprocessing only. */
058de654
NB
639 if (!flag_preprocess_only)
640 result = 0;
1c2de642
TM
641 break;
642
0b6f2917 643 case OPT_ffor_scope:
7b086b11 644 flag_new_for_scope = value;
0b6f2917
NB
645 break;
646
647 case OPT_fgnu_keywords:
7b086b11 648 flag_no_gnu_keywords = !value;
0b6f2917
NB
649 break;
650
651 case OPT_fgnu_runtime:
7b086b11 652 flag_next_runtime = !value;
0b6f2917
NB
653 break;
654
655 case OPT_fhandle_exceptions:
f75d3e11 656 warning ("-fhandle-exceptions has been renamed -fexceptions (and is now on by default)");
7b086b11 657 flag_exceptions = value;
0b6f2917
NB
658 break;
659
660 case OPT_fimplement_inlines:
7b086b11 661 flag_implement_inlines = value;
0b6f2917
NB
662 break;
663
664 case OPT_fimplicit_inline_templates:
7b086b11 665 flag_implicit_inline_templates = value;
0b6f2917
NB
666 break;
667
668 case OPT_fimplicit_templates:
7b086b11 669 flag_implicit_templates = value;
0b6f2917
NB
670 break;
671
672 case OPT_fms_extensions:
7b086b11 673 flag_ms_extensions = value;
0b6f2917
NB
674 break;
675
676 case OPT_fnext_runtime:
7b086b11 677 flag_next_runtime = value;
0b6f2917
NB
678 break;
679
264fa2db
ZL
680 case OPT_fnil_receivers:
681 flag_nil_receivers = value;
682 break;
683
0b6f2917 684 case OPT_fnonansi_builtins:
7b086b11 685 flag_no_nonansi_builtin = !value;
0b6f2917
NB
686 break;
687
264fa2db
ZL
688 case OPT_fobjc_exceptions:
689 flag_objc_exceptions = value;
690 break;
691
093c7153
RH
692 case OPT_fobjc_sjlj_exceptions:
693 flag_objc_sjlj_exceptions = value;
694 break;
695
18bdccaa 696 case OPT_foperator_names:
7b086b11 697 cpp_opts->operator_names = value;
18bdccaa
NB
698 break;
699
0b6f2917 700 case OPT_foptional_diags:
7b086b11 701 flag_optional_diags = value;
0b6f2917
NB
702 break;
703
17211ab5 704 case OPT_fpch_deps:
7b086b11 705 cpp_opts->restore_pch_deps = value;
17211ab5
GK
706 break;
707
c0d578e6
GK
708 case OPT_fpch_preprocess:
709 flag_pch_preprocess = value;
710 break;
711
0b6f2917 712 case OPT_fpermissive:
7b086b11 713 flag_permissive = value;
0b6f2917
NB
714 break;
715
18bdccaa 716 case OPT_fpreprocessed:
7b086b11 717 cpp_opts->preprocessed = value;
18bdccaa
NB
718 break;
719
264fa2db
ZL
720 case OPT_freplace_objc_classes:
721 flag_replace_objc_classes = value;
722 break;
723
0b6f2917 724 case OPT_frepo:
7b086b11
NB
725 flag_use_repository = value;
726 if (value)
0b6f2917
NB
727 flag_implicit_templates = 0;
728 break;
729
730 case OPT_frtti:
7b086b11 731 flag_rtti = value;
0b6f2917
NB
732 break;
733
18bdccaa 734 case OPT_fshow_column:
7b086b11 735 cpp_opts->show_column = value;
18bdccaa
NB
736 break;
737
0b6f2917 738 case OPT_fstats:
7b086b11 739 flag_detailed_statistics = value;
0b6f2917
NB
740 break;
741
fef3106c 742 case OPT_ftabstop_:
18bdccaa 743 /* It is documented that we silently ignore silly values. */
7b086b11
NB
744 if (value >= 1 && value <= 100)
745 cpp_opts->tabstop = value;
18bdccaa
NB
746 break;
747
e6cc3a24
ZW
748 case OPT_fexec_charset_:
749 cpp_opts->narrow_charset = arg;
750 break;
751
752 case OPT_fwide_exec_charset_:
753 cpp_opts->wide_charset = arg;
754 break;
755
16dd5cfe
EC
756 case OPT_finput_charset_:
757 cpp_opts->input_charset = arg;
758 break;
759
fef3106c 760 case OPT_ftemplate_depth_:
7b086b11 761 max_tinst_depth = value;
0b6f2917
NB
762 break;
763
0b6f2917 764 case OPT_fuse_cxa_atexit:
7b086b11 765 flag_use_cxa_atexit = value;
0b6f2917 766 break;
d7afec4b
ND
767
768 case OPT_fvisibility_inlines_hidden:
769 visibility_options.inlines_hidden = value;
770 break;
0b6f2917
NB
771
772 case OPT_fweak:
7b086b11 773 flag_weak = value;
0b6f2917 774 break;
264fa2db 775
40aac948
JM
776 case OPT_fthreadsafe_statics:
777 flag_threadsafe_statics = value;
778 break;
779
264fa2db
ZL
780 case OPT_fzero_link:
781 flag_zero_link = value;
782 break;
0b6f2917
NB
783
784 case OPT_gen_decls:
785 flag_gen_declaration = 1;
786 break;
787
5793b276 788 case OPT_idirafter:
b02398bd 789 add_path (xstrdup (arg), AFTER, 0, true);
5793b276
NB
790 break;
791
255c10b1 792 case OPT_imacros:
23345bbb
NB
793 case OPT_include:
794 defer_opt (code, arg);
795 break;
796
5793b276
NB
797 case OPT_iprefix:
798 iprefix = arg;
799 break;
800
4bed3787 801 case OPT_iquote:
b02398bd 802 add_path (xstrdup (arg), QUOTE, 0, true);
4bed3787
MS
803 break;
804
5793b276
NB
805 case OPT_isysroot:
806 sysroot = arg;
807 break;
808
809 case OPT_isystem:
b02398bd 810 add_path (xstrdup (arg), SYSTEM, 0, true);
5793b276
NB
811 break;
812
813 case OPT_iwithprefix:
814 add_prefixed_path (arg, SYSTEM);
815 break;
816
817 case OPT_iwithprefixbefore:
818 add_prefixed_path (arg, BRACKET);
819 break;
820
f749a36b
NB
821 case OPT_lang_asm:
822 cpp_set_lang (parse_in, CLK_ASM);
42ad6c9e 823 cpp_opts->dollars_in_ident = false;
f749a36b
NB
824 break;
825
826 case OPT_lang_objc:
827 cpp_opts->objc = 1;
828 break;
829
4b7091eb 830 case OPT_nostdinc:
5793b276 831 std_inc = false;
4b7091eb
NB
832 break;
833
fef3106c 834 case OPT_nostdinc__:
5793b276 835 std_cxx_inc = false;
4b7091eb
NB
836 break;
837
b4a93904 838 case OPT_o:
76c3e73e
NB
839 if (!out_fname)
840 out_fname = arg;
b4a93904 841 else
f75d3e11 842 error ("output filename specified twice");
b4a93904
NB
843 break;
844
18bdccaa
NB
845 /* We need to handle the -pedantic switches here, rather than in
846 c_common_post_options, so that a subsequent -Wno-endif-labels
847 is not overridden. */
848 case OPT_pedantic_errors:
849 cpp_opts->pedantic_errors = 1;
938d968e 850 /* Fall through. */
18bdccaa
NB
851 case OPT_pedantic:
852 cpp_opts->pedantic = 1;
853 cpp_opts->warn_endif_labels = 1;
854 break;
855
0b6f2917
NB
856 case OPT_print_objc_runtime_info:
857 print_struct_values = 1;
858 break;
859
b4a93904
NB
860 case OPT_remap:
861 cpp_opts->remap = 1;
0b6f2917
NB
862 break;
863
fef3106c
NB
864 case OPT_std_c__98:
865 case OPT_std_gnu__98:
866 set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
0b6f2917
NB
867 break;
868
869 case OPT_std_c89:
870 case OPT_std_iso9899_1990:
b4a93904
NB
871 case OPT_std_iso9899_199409:
872 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
f749a36b
NB
873 break;
874
875 case OPT_std_gnu89:
876 set_std_c89 (false /* c94 */, false /* ISO */);
0b6f2917
NB
877 break;
878
879 case OPT_std_c99:
880 case OPT_std_c9x:
881 case OPT_std_iso9899_1999:
882 case OPT_std_iso9899_199x:
b4a93904 883 set_std_c99 (true /* ISO */);
0b6f2917
NB
884 break;
885
0b6f2917
NB
886 case OPT_std_gnu99:
887 case OPT_std_gnu9x:
b4a93904 888 set_std_c99 (false /* ISO */);
0b6f2917
NB
889 break;
890
4b7091eb
NB
891 case OPT_trigraphs:
892 cpp_opts->trigraphs = 1;
893 break;
894
895 case OPT_traditional_cpp:
896 cpp_opts->traditional = 1;
897 break;
898
0b6f2917
NB
899 case OPT_undef:
900 flag_undef = 1;
901 break;
0b6f2917 902
4b7091eb
NB
903 case OPT_w:
904 cpp_opts->inhibit_warnings = 1;
905 break;
906
907 case OPT_v:
5793b276 908 verbose = true;
4b7091eb
NB
909 break;
910 }
0b6f2917 911
0b6f2917
NB
912 return result;
913}
914
915/* Post-switch processing. */
916bool
8e9ea4d7 917c_common_post_options (const char **pfilename)
0b6f2917 918{
8e9ea4d7
PB
919 struct cpp_callbacks *cb;
920
460bd0e3 921 /* Canonicalize the input and output filenames. */
d1bd0ded
GK
922 if (in_fnames == NULL)
923 {
5d038c4c 924 in_fnames = XNEWVEC (const char *, 1);
d1bd0ded
GK
925 in_fnames[0] = "";
926 }
927 else if (strcmp (in_fnames[0], "-") == 0)
928 in_fnames[0] = "";
460bd0e3 929
76c3e73e
NB
930 if (out_fname == NULL || !strcmp (out_fname, "-"))
931 out_fname = "";
932
cd79e210 933 if (cpp_opts->deps.style == DEPS_NONE)
76c3e73e
NB
934 check_deps_environment_vars ();
935
f4ff5a69 936 handle_deferred_opts ();
76c3e73e 937
f4ff5a69 938 sanitize_cpp_opts ();
460bd0e3 939
5793b276 940 register_include_chains (parse_in, sysroot, iprefix,
37fa72e9 941 std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
5793b276 942
0b6f2917
NB
943 flag_inline_trees = 1;
944
6de9cd9a
DN
945 /* Use tree inlining. */
946 if (!flag_no_inline)
947 flag_no_inline = 1;
948 if (flag_inline_functions)
0b6f2917 949 {
6de9cd9a
DN
950 flag_inline_trees = 2;
951 flag_inline_functions = 0;
0b6f2917
NB
952 }
953
9affb2c7
ZW
954 /* If we are given more than one input file, we must use
955 unit-at-a-time mode. */
956 if (num_in_fnames > 1)
957 flag_unit_at_a_time = 1;
958
093c7153
RH
959 /* Default to ObjC sjlj exception handling if NeXT runtime. */
960 if (flag_objc_sjlj_exceptions < 0)
961 flag_objc_sjlj_exceptions = flag_next_runtime;
962 if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
963 flag_exceptions = 1;
964
eaac4679
RS
965 /* -Wextra implies -Wsign-compare and -Wmissing-field-initializers,
966 but not if explicitly overridden. */
87f85ea0
ZW
967 if (warn_sign_compare == -1)
968 warn_sign_compare = extra_warnings;
eaac4679
RS
969 if (warn_missing_field_initializers == -1)
970 warn_missing_field_initializers = extra_warnings;
87f85ea0 971
0b6f2917
NB
972 /* Special format checking options don't work without -Wformat; warn if
973 they are used. */
974 if (warn_format_y2k && !warn_format)
975 warning ("-Wformat-y2k ignored without -Wformat");
976 if (warn_format_extra_args && !warn_format)
977 warning ("-Wformat-extra-args ignored without -Wformat");
978 if (warn_format_zero_length && !warn_format)
979 warning ("-Wformat-zero-length ignored without -Wformat");
980 if (warn_format_nonliteral && !warn_format)
981 warning ("-Wformat-nonliteral ignored without -Wformat");
982 if (warn_format_security && !warn_format)
983 warning ("-Wformat-security ignored without -Wformat");
984 if (warn_missing_format_attribute && !warn_format)
985 warning ("-Wmissing-format-attribute ignored without -Wformat");
986
460bd0e3
NB
987 if (flag_preprocess_only)
988 {
63973df3
NB
989 /* Open the output now. We must do so even if flag_no_output is
990 on, because there may be other output than from the actual
991 preprocessing (e.g. from -dM). */
992 if (out_fname[0] == '\0')
993 out_stream = stdout;
994 else
995 out_stream = fopen (out_fname, "w");
996
997 if (out_stream == NULL)
9d10c9a9 998 {
fa6ef813 999 fatal_error ("opening output file %s: %m", out_fname);
c366ade5 1000 return false;
9d10c9a9 1001 }
63973df3 1002
d1bd0ded
GK
1003 if (num_in_fnames > 1)
1004 error ("too many filenames given. Type %s --help for usage",
1005 progname);
1006
9d10c9a9 1007 init_pp_output (out_stream);
460bd0e3 1008 }
9d10c9a9
NB
1009 else
1010 {
1011 init_c_lex ();
460bd0e3 1012
9d10c9a9 1013 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
3c20847b 1014 input_location = UNKNOWN_LOCATION;
9d10c9a9 1015 }
63973df3 1016
8e9ea4d7
PB
1017 cb = cpp_get_callbacks (parse_in);
1018 cb->file_change = cb_file_change;
1019 cb->dir_change = cb_dir_change;
4169c321 1020 cpp_post_options (parse_in);
23345bbb 1021
3c20847b 1022 input_location = UNKNOWN_LOCATION;
4bfec483
NB
1023
1024 /* If an error has occurred in cpplib, note it so we fail
1025 immediately. */
1026 errorcount += cpp_errors (parse_in);
1027
8e9ea4d7
PB
1028 *pfilename = this_input_filename
1029 = cpp_read_main_file (parse_in, in_fnames[0]);
540554f4 1030 /* Don't do any compilation or preprocessing if there is no input file. */
8e9ea4d7 1031 if (this_input_filename == NULL)
540554f4
JW
1032 {
1033 errorcount++;
1034 return false;
1035 }
8e9ea4d7 1036
8a4baa83
PB
1037 if (flag_working_directory
1038 && flag_preprocess_only && ! flag_no_line_commands)
8e9ea4d7
PB
1039 pp_dir_change (parse_in, get_src_pwd ());
1040
4bfec483
NB
1041 return flag_preprocess_only;
1042}
1043
1044/* Front end initialization common to C, ObjC and C++. */
1045bool
2f6e4e97 1046c_common_init (void)
4bfec483 1047{
4bfec483
NB
1048 /* Set up preprocessor arithmetic. Must be done after call to
1049 c_common_nodes_and_builtins for type nodes to be good. */
1050 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1051 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1052 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1053 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
8df83eae 1054 cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
e6cc3a24
ZW
1055 cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
1056
1057 /* This can't happen until after wchar_precision and bytes_big_endian
1058 are known. */
1059 cpp_init_iconv (parse_in);
460bd0e3 1060
9d10c9a9
NB
1061 if (flag_preprocess_only)
1062 {
8e9ea4d7
PB
1063 finish_options ();
1064 preprocess_file (parse_in);
4bfec483 1065 return false;
9d10c9a9
NB
1066 }
1067
63973df3 1068 /* Has to wait until now so that cpplib has its hash table. */
460bd0e3
NB
1069 init_pragma ();
1070
4bfec483 1071 return true;
76c3e73e
NB
1072}
1073
d1bd0ded
GK
1074/* Initialize the integrated preprocessor after debug output has been
1075 initialized; loop over each input file. */
23345bbb 1076void
f75fbaf7 1077c_common_parse_file (int set_yydebug)
23345bbb 1078{
9affb2c7
ZW
1079 unsigned int i;
1080
1081 /* Enable parser debugging, if requested and we can. If requested
1082 and we can't, notify the user. */
23345bbb
NB
1083#if YYDEBUG != 0
1084 yydebug = set_yydebug;
1085#else
f75fbaf7 1086 if (set_yydebug)
9affb2c7 1087 warning ("YYDEBUG was not defined at build time, -dy ignored");
23345bbb
NB
1088#endif
1089
9affb2c7
ZW
1090 i = 0;
1091 for (;;)
1092 {
1093 finish_options ();
1094 pch_init ();
1095 push_file_scope ();
1096 c_parse_file ();
1097 finish_file ();
1098 pop_file_scope ();
1099
1100 if (++i >= num_in_fnames)
1101 break;
1102 cpp_undef_all (parse_in);
1103 this_input_filename
1104 = cpp_read_main_file (parse_in, in_fnames[i]);
1105 /* If an input file is missing, abandon further compilation.
1106 cpplib has issued a diagnostic. */
1107 if (!this_input_filename)
1108 break;
1109 }
23345bbb
NB
1110}
1111
76c3e73e
NB
1112/* Common finish hook for the C, ObjC and C++ front ends. */
1113void
2f6e4e97 1114c_common_finish (void)
76c3e73e
NB
1115{
1116 FILE *deps_stream = NULL;
1117
f4ff5a69 1118 if (cpp_opts->deps.style != DEPS_NONE)
76c3e73e
NB
1119 {
1120 /* If -M or -MM was seen without -MF, default output to the
1121 output stream. */
f4ff5a69 1122 if (!deps_file)
76c3e73e
NB
1123 deps_stream = out_stream;
1124 else
1125 {
f4ff5a69 1126 deps_stream = fopen (deps_file, deps_append ? "a": "w");
76c3e73e 1127 if (!deps_stream)
fa6ef813 1128 fatal_error ("opening dependency file %s: %m", deps_file);
76c3e73e
NB
1129 }
1130 }
1131
1132 /* For performance, avoid tearing down cpplib's internal structures
1133 with cpp_destroy (). */
1134 errorcount += cpp_finish (parse_in, deps_stream);
1135
1136 if (deps_stream && deps_stream != out_stream
1137 && (ferror (deps_stream) || fclose (deps_stream)))
fa6ef813 1138 fatal_error ("closing dependency file %s: %m", deps_file);
76c3e73e
NB
1139
1140 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
fa6ef813 1141 fatal_error ("when writing output to %s: %m", out_fname);
76c3e73e
NB
1142}
1143
76c3e73e
NB
1144/* Either of two environment variables can specify output of
1145 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1146 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1147 and DEPS_TARGET is the target to mention in the deps. They also
1148 result in dependency information being appended to the output file
182d89a3
NB
1149 rather than overwriting it, and like Sun's compiler
1150 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
76c3e73e 1151static void
2f6e4e97 1152check_deps_environment_vars (void)
76c3e73e
NB
1153{
1154 char *spec;
1155
1156 GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
1157 if (spec)
f4ff5a69 1158 cpp_opts->deps.style = DEPS_USER;
76c3e73e
NB
1159 else
1160 {
1161 GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
1162 if (spec)
182d89a3
NB
1163 {
1164 cpp_opts->deps.style = DEPS_SYSTEM;
1165 cpp_opts->deps.ignore_main_file = true;
1166 }
76c3e73e
NB
1167 }
1168
1169 if (spec)
1170 {
1171 /* Find the space before the DEPS_TARGET, if there is one. */
1172 char *s = strchr (spec, ' ');
1173 if (s)
1174 {
1175 /* Let the caller perform MAKE quoting. */
f4ff5a69 1176 defer_opt (OPT_MT, s + 1);
76c3e73e
NB
1177 *s = '\0';
1178 }
1179
1180 /* Command line -MF overrides environment variables and default. */
f4ff5a69
NB
1181 if (!deps_file)
1182 deps_file = spec;
76c3e73e 1183
f4ff5a69
NB
1184 deps_append = 1;
1185 }
1186}
1187
1188/* Handle deferred command line switches. */
1189static void
2f6e4e97 1190handle_deferred_opts (void)
f4ff5a69
NB
1191{
1192 size_t i;
c6e83800
ZW
1193 struct deps *deps;
1194
1195 /* Avoid allocating the deps buffer if we don't need it.
1196 (This flag may be true without there having been -MT or -MQ
1197 options, but we'll still need the deps buffer.) */
1198 if (!deps_seen)
1199 return;
1200
1201 deps = cpp_get_deps (parse_in);
f4ff5a69
NB
1202
1203 for (i = 0; i < deferred_count; i++)
1204 {
1205 struct deferred_opt *opt = &deferred_opts[i];
1206
c1bad961 1207 if (opt->code == OPT_MT || opt->code == OPT_MQ)
c6e83800 1208 deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
f4ff5a69 1209 }
f4ff5a69
NB
1210}
1211
1212/* These settings are appropriate for GCC, but not necessarily so for
1213 cpplib as a library. */
1214static void
2f6e4e97 1215sanitize_cpp_opts (void)
f4ff5a69
NB
1216{
1217 /* If we don't know what style of dependencies to output, complain
1218 if any other dependency switches have been given. */
1219 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1220 error ("to generate dependencies you must specify either -M or -MM");
1221
1222 /* -dM and dependencies suppress normal output; do it here so that
1223 the last -d[MDN] switch overrides earlier ones. */
63973df3
NB
1224 if (flag_dump_macros == 'M')
1225 flag_no_output = 1;
f4ff5a69
NB
1226
1227 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1228 -dM since at least glibc relies on -M -dM to work. */
63973df3 1229 if (flag_no_output)
f4ff5a69 1230 {
63973df3
NB
1231 if (flag_dump_macros != 'M')
1232 flag_dump_macros = 0;
1233 flag_dump_includes = 0;
76c3e73e 1234 }
f4ff5a69
NB
1235
1236 cpp_opts->unsigned_char = !flag_signed_char;
1237 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1238
1239 /* We want -Wno-long-long to override -pedantic -std=non-c99
1240 and/or -Wtraditional, whatever the ordering. */
1241 cpp_opts->warn_long_long
1242 = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
b20d9f0c 1243
e5b79219
RH
1244 /* Similarly with -Wno-variadic-macros. No check for c99 here, since
1245 this also turns off warnings about GCCs extension. */
1246 cpp_opts->warn_variadic_macros
1247 = warn_variadic_macros && (pedantic || warn_traditional);
1248
b20d9f0c
AO
1249 /* If we're generating preprocessor output, emit current directory
1250 if explicitly requested or if debugging information is enabled.
1251 ??? Maybe we should only do it for debugging formats that
1252 actually output the current directory? */
1253 if (flag_working_directory == -1)
1254 flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
f4ff5a69
NB
1255}
1256
5793b276
NB
1257/* Add include path with a prefix at the front of its name. */
1258static void
2f6e4e97 1259add_prefixed_path (const char *suffix, size_t chain)
5793b276 1260{
52999738 1261 char *path;
5793b276 1262 const char *prefix;
52999738 1263 size_t prefix_len, suffix_len;
5793b276 1264
52999738
ZW
1265 suffix_len = strlen (suffix);
1266 prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1267 prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1268
5d038c4c 1269 path = (char *) xmalloc (prefix_len + suffix_len + 1);
52999738
ZW
1270 memcpy (path, prefix, prefix_len);
1271 memcpy (path + prefix_len, suffix, suffix_len);
1272 path[prefix_len + suffix_len] = '\0';
1273
b02398bd 1274 add_path (path, chain, 0, false);
5793b276
NB
1275}
1276
8e9ea4d7
PB
1277/* Handle -D, -U, -A, -imacros, and the first -include. */
1278static void
1279finish_options (void)
255c10b1 1280{
255c10b1
NB
1281 if (!cpp_opts->preprocessed)
1282 {
c1bad961
NB
1283 size_t i;
1284
8e9ea4d7 1285 cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
6e270179 1286 cpp_init_builtins (parse_in, flag_hosted);
c1bad961 1287 c_cpp_builtins (parse_in);
78b8811a
HPN
1288
1289 /* We're about to send user input to cpplib, so make it warn for
1290 things that we previously (when we sent it internal definitions)
1291 told it to not warn.
1292
1293 C99 permits implementation-defined characters in identifiers.
1294 The documented meaning of -std= is to turn off extensions that
1295 conflict with the specified standard, and since a strictly
1296 conforming program cannot contain a '$', we do not condition
1297 their acceptance on the -std= setting. */
1298 cpp_opts->warn_dollars = (cpp_opts->pedantic && !cpp_opts->c99);
1299
b4e46cea 1300 cpp_change_file (parse_in, LC_RENAME, _("<command line>"));
c1bad961
NB
1301 for (i = 0; i < deferred_count; i++)
1302 {
1303 struct deferred_opt *opt = &deferred_opts[i];
1304
1305 if (opt->code == OPT_D)
1306 cpp_define (parse_in, opt->arg);
1307 else if (opt->code == OPT_U)
1308 cpp_undef (parse_in, opt->arg);
1309 else if (opt->code == OPT_A)
1310 {
1311 if (opt->arg[0] == '-')
1312 cpp_unassert (parse_in, opt->arg + 1);
1313 else
1314 cpp_assert (parse_in, opt->arg);
1315 }
1316 }
255c10b1 1317
c1bad961 1318 /* Handle -imacros after -D and -U. */
255c10b1
NB
1319 for (i = 0; i < deferred_count; i++)
1320 {
1321 struct deferred_opt *opt = &deferred_opts[i];
1322
1323 if (opt->code == OPT_imacros
1324 && cpp_push_include (parse_in, opt->arg))
9b49a0aa 1325 {
6614fd40 1326 /* Disable push_command_line_include callback for now. */
9b49a0aa
PB
1327 include_cursor = deferred_count + 1;
1328 cpp_scan_nooutput (parse_in);
1329 }
255c10b1
NB
1330 }
1331 }
1332
e6ebd07b 1333 include_cursor = 0;
255c10b1
NB
1334 push_command_line_include ();
1335}
1336
23345bbb
NB
1337/* Give CPP the next file given by -include, if any. */
1338static void
2f6e4e97 1339push_command_line_include (void)
23345bbb 1340{
23345bbb
NB
1341 while (include_cursor < deferred_count)
1342 {
1343 struct deferred_opt *opt = &deferred_opts[include_cursor++];
2f6e4e97 1344
31703a61
PB
1345 if (! cpp_opts->preprocessed && opt->code == OPT_include
1346 && cpp_push_include (parse_in, opt->arg))
23345bbb
NB
1347 return;
1348 }
1349
1350 if (include_cursor == deferred_count)
1351 {
31703a61 1352 include_cursor++;
23345bbb
NB
1353 /* -Wunused-macros should only warn about macros defined hereafter. */
1354 cpp_opts->warn_unused_macros = warn_unused_macros;
8e9ea4d7
PB
1355 /* Restore the line map from <command line>. */
1356 if (! cpp_opts->preprocessed)
1357 cpp_change_file (parse_in, LC_RENAME, main_input_filename);
1358
1359 /* Set this here so the client can change the option if it wishes,
1360 and after stacking the main file so we don't trace the main file. */
1361 line_table.trace_includes = cpp_opts->print_include_names;
23345bbb
NB
1362 }
1363}
1364
1365/* File change callback. Has to handle -include files. */
1366static void
e18476eb 1367cb_file_change (cpp_reader * ARG_UNUSED (pfile),
2f6e4e97 1368 const struct line_map *new_map)
23345bbb
NB
1369{
1370 if (flag_preprocess_only)
1371 pp_file_change (new_map);
1372 else
1373 fe_file_change (new_map);
1374
31703a61 1375 if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
23345bbb
NB
1376 push_command_line_include ();
1377}
1378
8e9ea4d7 1379void
e18476eb 1380cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
8e9ea4d7
PB
1381{
1382 if (! set_src_pwd (dir))
1383 warning ("too late for # directive to set debug directory");
1384}
1385
f4ff5a69
NB
1386/* Set the C 89 standard (with 1994 amendments if C94, without GNU
1387 extensions if ISO). There is no concept of gnu94. */
1388static void
2f6e4e97 1389set_std_c89 (int c94, int iso)
f4ff5a69
NB
1390{
1391 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1392 flag_iso = iso;
1393 flag_no_asm = iso;
1394 flag_no_gnu_keywords = iso;
1395 flag_no_nonansi_builtin = iso;
f4ff5a69
NB
1396 flag_isoc94 = c94;
1397 flag_isoc99 = 0;
76c3e73e
NB
1398}
1399
b4a93904
NB
1400/* Set the C 99 standard (without GNU extensions if ISO). */
1401static void
2f6e4e97 1402set_std_c99 (int iso)
b4a93904
NB
1403{
1404 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1405 flag_no_asm = iso;
1406 flag_no_nonansi_builtin = iso;
b4a93904
NB
1407 flag_iso = iso;
1408 flag_isoc99 = 1;
1409 flag_isoc94 = 1;
b4a93904
NB
1410}
1411
f749a36b
NB
1412/* Set the C++ 98 standard (without GNU extensions if ISO). */
1413static void
2f6e4e97 1414set_std_cxx98 (int iso)
f749a36b
NB
1415{
1416 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1417 flag_no_gnu_keywords = iso;
1418 flag_no_nonansi_builtin = iso;
f749a36b
NB
1419 flag_iso = iso;
1420}
1421
0b6f2917
NB
1422/* Handle setting implicit to ON. */
1423static void
2f6e4e97 1424set_Wimplicit (int on)
0b6f2917
NB
1425{
1426 warn_implicit = on;
1427 warn_implicit_int = on;
1428 if (on)
1429 {
1430 if (mesg_implicit_function_declaration != 2)
1431 mesg_implicit_function_declaration = 1;
1432 }
1433 else
1434 mesg_implicit_function_declaration = 0;
1435}
1436
4b7091eb 1437/* Args to -d specify what to dump. Silently ignore
05713b80 1438 unrecognized options; they may be aimed at toplev.c. */
0b6f2917 1439static void
2f6e4e97 1440handle_OPT_d (const char *arg)
0b6f2917 1441{
4b7091eb
NB
1442 char c;
1443
1444 while ((c = *arg++) != '\0')
1445 switch (c)
1446 {
63973df3
NB
1447 case 'M': /* Dump macros only. */
1448 case 'N': /* Dump names. */
1449 case 'D': /* Dump definitions. */
1450 flag_dump_macros = c;
4b7091eb
NB
1451 break;
1452
1453 case 'I':
63973df3 1454 flag_dump_includes = 1;
4b7091eb
NB
1455 break;
1456 }
0b6f2917 1457}
This page took 0.689991 seconds and 5 git commands to generate.