]> gcc.gnu.org Git - gcc.git/blame - gcc/c-opts.c
basic_string.tcc (_M_replace_aux): Constify __n1 and __off1.
[gcc.git] / gcc / c-opts.c
CommitLineData
0b6f2917 1/* C/ObjC/C++ command line option handling.
5793b276 2 Copyright (C) 2002, 2003 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"
5793b276 40
b1822ccc
NB
41#ifndef DOLLARS_IN_IDENTIFIERS
42# define DOLLARS_IN_IDENTIFIERS true
43#endif
44
5793b276
NB
45#ifndef TARGET_SYSTEM_ROOT
46# define TARGET_SYSTEM_ROOT NULL
47#endif
0b6f2917 48
783e2989
NB
49#ifndef TARGET_EBCDIC
50# define TARGET_EBCDIC 0
51#endif
52
4bfec483
NB
53static int saved_lineno;
54
f4ff5a69 55/* CPP's options. */
18bdccaa
NB
56static cpp_options *cpp_opts;
57
460bd0e3
NB
58/* Input filename. */
59static const char *in_fname;
60
76c3e73e
NB
61/* Filename and stream for preprocessed output. */
62static const char *out_fname;
63static FILE *out_stream;
64
65/* Append dependencies to deps_file. */
66static bool deps_append;
67
f4ff5a69
NB
68/* If dependency switches (-MF etc.) have been given. */
69static bool deps_seen;
70
5793b276
NB
71/* If -v seen. */
72static bool verbose;
73
f4ff5a69
NB
74/* Dependency output file. */
75static const char *deps_file;
76
5793b276
NB
77/* The prefix given by -iprefix, if any. */
78static const char *iprefix;
79
80/* The system root, if any. Overridden by -isysroot. */
81static const char *sysroot = TARGET_SYSTEM_ROOT;
82
83/* Zero disables all standard directories for headers. */
84static bool std_inc = true;
85
86/* Zero disables the C++-specific standard directories for headers. */
87static bool std_cxx_inc = true;
88
89/* If the quote chain has been split by -I-. */
90static bool quote_chain_split;
91
23345bbb
NB
92/* If -Wunused-macros. */
93static bool warn_unused_macros;
94
f4ff5a69
NB
95/* Number of deferred options, deferred options array size. */
96static size_t deferred_count, deferred_size;
97
23345bbb
NB
98/* Number of deferred options scanned for -include. */
99static size_t include_cursor;
100
9eee5e72 101void missing_arg (enum opt_code);
2f6e4e97 102static void set_Wimplicit (int);
2f6e4e97
AJ
103static void print_help (void);
104static void handle_OPT_d (const char *);
105static void set_std_cxx98 (int);
106static void set_std_c89 (int, int);
107static void set_std_c99 (int);
108static void check_deps_environment_vars (void);
109static void handle_deferred_opts (void);
110static void sanitize_cpp_opts (void);
111static void add_prefixed_path (const char *, size_t);
112static void push_command_line_include (void);
113static void cb_file_change (cpp_reader *, const struct line_map *);
114static void finish_options (void);
460bd0e3
NB
115
116#ifndef STDC_0_IN_SYSTEM_HEADERS
117#define STDC_0_IN_SYSTEM_HEADERS 0
118#endif
0b6f2917 119
2772ef3e 120/* Holds switches parsed by c_common_handle_option (), but whose
95bd1dd7 121 handling is deferred to c_common_post_options (). */
2f6e4e97 122static void defer_opt (enum opt_code, const char *);
f4ff5a69
NB
123static struct deferred_opt
124{
125 enum opt_code code;
126 const char *arg;
127} *deferred_opts;
128
4b7091eb
NB
129/* Complain that switch OPT_INDEX expects an argument but none was
130 provided. */
9eee5e72 131void
2772ef3e 132missing_arg (enum opt_code code)
4b7091eb 133{
2772ef3e 134 const char *opt_text = cl_options[code].opt_text;
f4ff5a69 135
2772ef3e 136 switch (code)
4b7091eb 137 {
fef3106c
NB
138 case OPT__output_pch_:
139 case OPT_Wformat_:
4b7091eb 140 case OPT_d:
fef3106c 141 case OPT_fabi_version_:
4b7091eb 142 case OPT_fbuiltin_:
fef3106c
NB
143 case OPT_fdump_:
144 case OPT_fname_mangling_version_:
145 case OPT_ftabstop_:
146 case OPT_ftemplate_depth_:
5793b276
NB
147 case OPT_iprefix:
148 case OPT_iwithprefix:
149 case OPT_iwithprefixbefore:
4b7091eb 150 default:
f4ff5a69 151 error ("missing argument to \"-%s\"", opt_text);
4b7091eb
NB
152 break;
153
fef3106c 154 case OPT_fconstant_string_class_:
f4ff5a69 155 error ("no class name specified with \"-%s\"", opt_text);
4b7091eb 156 break;
b4a93904 157
c1bad961
NB
158 case OPT_A:
159 error ("assertion missing after \"-%s\"", opt_text);
160 break;
161
162 case OPT_D:
163 case OPT_U:
164 error ("macro name missing after \"-%s\"", opt_text);
165 break;
166
5793b276
NB
167 case OPT_I:
168 case OPT_idirafter:
169 case OPT_isysroot:
170 case OPT_isystem:
171 error ("missing path after \"-%s\"", opt_text);
172 break;
173
f4ff5a69
NB
174 case OPT_MF:
175 case OPT_MD:
176 case OPT_MMD:
255c10b1
NB
177 case OPT_include:
178 case OPT_imacros:
b4a93904 179 case OPT_o:
f4ff5a69
NB
180 error ("missing filename after \"-%s\"", opt_text);
181 break;
182
183 case OPT_MQ:
184 case OPT_MT:
185 error ("missing target after \"-%s\"", opt_text);
b4a93904 186 break;
4b7091eb
NB
187 }
188}
189
f4ff5a69
NB
190/* Defer option CODE with argument ARG. */
191static void
2f6e4e97 192defer_opt (enum opt_code code, const char *arg)
f4ff5a69
NB
193{
194 /* FIXME: this should be in c_common_init_options, which should take
195 argc and argv. */
196 if (!deferred_opts)
197 {
198 extern int save_argc;
199 deferred_size = save_argc;
200 deferred_opts = (struct deferred_opt *)
201 xmalloc (deferred_size * sizeof (struct deferred_opt));
202 }
203
204 if (deferred_count == deferred_size)
205 abort ();
206
207 deferred_opts[deferred_count].code = code;
208 deferred_opts[deferred_count].arg = arg;
209 deferred_count++;
210}
211
0b6f2917 212/* Common initialization before parsing options. */
2772ef3e 213int
37fa72e9 214c_common_init_options (void)
0b6f2917 215{
37fa72e9
NB
216 static const int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
217
218 /* This is conditionalized only because that is the way the front
219 ends used to do it. Maybe this should be unconditional? */
220 if (c_dialect_cxx ())
221 {
222 /* By default wrap lines at 80 characters. Is getenv
223 ("COLUMNS") preferable? */
224 diagnostic_line_cutoff (global_dc) = 80;
225 /* By default, emit location information once for every
226 diagnostic message. */
227 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
228 }
229
230 parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
b4e46cea 231 ident_hash);
37fa72e9 232
18bdccaa 233 cpp_opts = cpp_get_options (parse_in);
b1822ccc 234 cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
37fa72e9 235 cpp_opts->objc = c_dialect_objc ();
78b8811a
HPN
236
237 /* Reset to avoid warnings on internal definitions. We set it just
238 before passing on command-line options to cpplib. */
239 cpp_opts->warn_dollars = 0;
240
37fa72e9
NB
241 flag_const_strings = c_dialect_cxx ();
242 flag_exceptions = c_dialect_cxx ();
243 warn_pointer_arith = c_dialect_cxx ();
2772ef3e 244
37fa72e9 245 return lang_flags[c_language];
0b6f2917
NB
246}
247
2772ef3e
NB
248/* Handle switch SCODE with argument ARG. ON is true, unless no-
249 form of an -f or -W option was given. Returns 0 if the switch was
250 invalid, a negative number to prevent language-independent
251 processing in toplev.c (a hack necessary for the short-term). */
0b6f2917 252int
7b086b11 253c_common_handle_option (size_t scode, const char *arg, int value)
0b6f2917 254{
2772ef3e
NB
255 const struct cl_option *option = &cl_options[scode];
256 enum opt_code code = (enum opt_code) scode;
f18754d6 257 int result = 1;
2772ef3e
NB
258
259 if (code == N_OPTS)
0b6f2917 260 {
460bd0e3 261 if (!in_fname)
2772ef3e 262 in_fname = arg;
76c3e73e 263 else if (!out_fname)
2772ef3e 264 out_fname = arg;
b4a93904 265 else
b4a93904
NB
266 error ("too many filenames given. Type %s --help for usage",
267 progname);
b4a93904 268 return 1;
0b6f2917
NB
269 }
270
fef3106c 271 switch (code)
0b6f2917 272 {
2772ef3e
NB
273 default:
274 return 0;
0b6f2917 275
4b7091eb
NB
276 case OPT__help:
277 print_help ();
278 break;
279
fef3106c 280 case OPT__output_pch_:
17211ab5
GK
281 pch_file = arg;
282 break;
283
c1bad961
NB
284 case OPT_A:
285 defer_opt (code, arg);
286 break;
287
4b7091eb
NB
288 case OPT_C:
289 cpp_opts->discard_comments = 0;
290 break;
291
292 case OPT_CC:
293 cpp_opts->discard_comments = 0;
294 cpp_opts->discard_comments_in_macro_exp = 0;
295 break;
296
c1bad961
NB
297 case OPT_D:
298 defer_opt (code, arg);
299 break;
300
0b6f2917
NB
301 case OPT_E:
302 flag_preprocess_only = 1;
303 break;
304
4b7091eb
NB
305 case OPT_H:
306 cpp_opts->print_include_names = 1;
307 break;
308
5793b276
NB
309 case OPT_I:
310 if (strcmp (arg, "-"))
311 add_path (xstrdup (arg), BRACKET, 0);
312 else
313 {
314 if (quote_chain_split)
315 error ("-I- specified twice");
316 quote_chain_split = true;
317 split_quote_chain ();
318 }
319 break;
320
f4ff5a69
NB
321 case OPT_M:
322 case OPT_MM:
323 /* When doing dependencies with -M or -MM, suppress normal
324 preprocessed output, but still do -dM etc. as software
325 depends on this. Preprocessed output does occur if -MD, -MMD
326 or environment var dependency generation is used. */
327 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
63973df3 328 flag_no_output = 1;
f4ff5a69
NB
329 cpp_opts->inhibit_warnings = 1;
330 break;
331
332 case OPT_MD:
333 case OPT_MMD:
334 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
335 deps_file = arg;
336 break;
337
338 case OPT_MF:
339 deps_seen = true;
340 deps_file = arg;
341 break;
342
343 case OPT_MG:
344 deps_seen = true;
345 cpp_opts->deps.missing_files = true;
346 break;
347
348 case OPT_MP:
349 deps_seen = true;
350 cpp_opts->deps.phony_targets = true;
351 break;
352
353 case OPT_MQ:
354 case OPT_MT:
355 deps_seen = true;
356 defer_opt (code, arg);
357 break;
358
4b7091eb 359 case OPT_P:
63973df3 360 flag_no_line_commands = 1;
4b7091eb
NB
361 break;
362
c1bad961
NB
363 case OPT_U:
364 defer_opt (code, arg);
365 break;
366
eca7f13c 367 case OPT_Wabi:
7b086b11 368 warn_abi = value;
eca7f13c
MM
369 break;
370
0b6f2917 371 case OPT_Wall:
7b086b11
NB
372 set_Wunused (value);
373 set_Wformat (value);
374 set_Wimplicit (value);
375 warn_char_subscripts = value;
376 warn_missing_braces = value;
377 warn_parentheses = value;
378 warn_return_type = value;
379 warn_sequence_point = value; /* Was C only. */
37fa72e9 380 if (c_dialect_cxx ())
7b086b11
NB
381 warn_sign_compare = value;
382 warn_switch = value;
383 warn_strict_aliasing = value;
2f6e4e97 384
0b6f2917 385 /* Only warn about unknown pragmas that are not in system
2f6e4e97 386 headers. */
7b086b11 387 warn_unknown_pragmas = value;
0b6f2917
NB
388
389 /* We save the value of warn_uninitialized, since if they put
390 -Wuninitialized on the command line, we need to generate a
391 warning about not using it without also specifying -O. */
392 if (warn_uninitialized != 1)
7b086b11 393 warn_uninitialized = (value ? 2 : 0);
0b6f2917 394
37fa72e9 395 if (!c_dialect_cxx ())
0b6f2917
NB
396 /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
397 can turn it off only if it's not explicit. */
7b086b11 398 warn_main = value * 2;
0b6f2917
NB
399 else
400 {
401 /* C++-specific warnings. */
7b086b11
NB
402 warn_nonvdtor = value;
403 warn_reorder = value;
404 warn_nontemplate_friend = value;
0b6f2917 405 }
18bdccaa 406
7b086b11
NB
407 cpp_opts->warn_trigraphs = value;
408 cpp_opts->warn_comments = value;
409 cpp_opts->warn_num_sign_change = value;
410 cpp_opts->warn_multichar = value; /* Was C++ only. */
0b6f2917
NB
411 break;
412
413 case OPT_Wbad_function_cast:
7b086b11 414 warn_bad_function_cast = value;
0b6f2917
NB
415 break;
416
417 case OPT_Wcast_qual:
7b086b11 418 warn_cast_qual = value;
0b6f2917
NB
419 break;
420
421 case OPT_Wchar_subscripts:
7b086b11 422 warn_char_subscripts = value;
0b6f2917
NB
423 break;
424
18bdccaa
NB
425 case OPT_Wcomment:
426 case OPT_Wcomments:
7b086b11 427 cpp_opts->warn_comments = value;
18bdccaa
NB
428 break;
429
0b6f2917 430 case OPT_Wconversion:
7b086b11 431 warn_conversion = value;
0b6f2917
NB
432 break;
433
434 case OPT_Wctor_dtor_privacy:
7b086b11 435 warn_ctor_dtor_privacy = value;
0b6f2917
NB
436 break;
437
438 case OPT_Wdeprecated:
7b086b11
NB
439 warn_deprecated = value;
440 cpp_opts->warn_deprecated = value;
0b6f2917
NB
441 break;
442
443 case OPT_Wdiv_by_zero:
7b086b11 444 warn_div_by_zero = value;
0b6f2917
NB
445 break;
446
fef3106c 447 case OPT_Weffc__:
7b086b11 448 warn_ecpp = value;
0b6f2917
NB
449 break;
450
18bdccaa 451 case OPT_Wendif_labels:
7b086b11 452 cpp_opts->warn_endif_labels = value;
18bdccaa
NB
453 break;
454
455 case OPT_Werror:
7b086b11 456 cpp_opts->warnings_are_errors = value;
18bdccaa
NB
457 break;
458
fef3106c 459 case OPT_Werror_implicit_function_declaration:
c83857ff 460 mesg_implicit_function_declaration = 2;
0b6f2917
NB
461 break;
462
463 case OPT_Wfloat_equal:
7b086b11 464 warn_float_equal = value;
0b6f2917
NB
465 break;
466
467 case OPT_Wformat:
7b086b11 468 set_Wformat (value);
0b6f2917
NB
469 break;
470
fef3106c 471 case OPT_Wformat_:
0b6f2917
NB
472 set_Wformat (atoi (arg));
473 break;
474
475 case OPT_Wformat_extra_args:
7b086b11 476 warn_format_extra_args = value;
0b6f2917
NB
477 break;
478
479 case OPT_Wformat_nonliteral:
7b086b11 480 warn_format_nonliteral = value;
0b6f2917
NB
481 break;
482
483 case OPT_Wformat_security:
7b086b11 484 warn_format_security = value;
0b6f2917
NB
485 break;
486
487 case OPT_Wformat_y2k:
7b086b11 488 warn_format_y2k = value;
0b6f2917
NB
489 break;
490
491 case OPT_Wformat_zero_length:
7b086b11 492 warn_format_zero_length = value;
0b6f2917
NB
493 break;
494
495 case OPT_Wimplicit:
7b086b11 496 set_Wimplicit (value);
0b6f2917
NB
497 break;
498
fef3106c 499 case OPT_Wimplicit_function_declaration:
7b086b11 500 mesg_implicit_function_declaration = value;
0b6f2917
NB
501 break;
502
503 case OPT_Wimplicit_int:
7b086b11 504 warn_implicit_int = value;
0b6f2917
NB
505 break;
506
18bdccaa 507 case OPT_Wimport:
7b086b11 508 cpp_opts->warn_import = value;
18bdccaa
NB
509 break;
510
a01fff59 511 case OPT_Winvalid_offsetof:
7b086b11 512 warn_invalid_offsetof = value;
a01fff59
MA
513 break;
514
17211ab5 515 case OPT_Winvalid_pch:
7b086b11 516 cpp_opts->warn_invalid_pch = value;
17211ab5
GK
517 break;
518
0b6f2917 519 case OPT_Wlong_long:
7b086b11 520 warn_long_long = value;
0b6f2917
NB
521 break;
522
523 case OPT_Wmain:
7b086b11 524 if (value)
0b6f2917
NB
525 warn_main = 1;
526 else
527 warn_main = -1;
528 break;
529
530 case OPT_Wmissing_braces:
7b086b11 531 warn_missing_braces = value;
0b6f2917
NB
532 break;
533
534 case OPT_Wmissing_declarations:
7b086b11 535 warn_missing_declarations = value;
0b6f2917
NB
536 break;
537
538 case OPT_Wmissing_format_attribute:
7b086b11 539 warn_missing_format_attribute = value;
0b6f2917
NB
540 break;
541
542 case OPT_Wmissing_prototypes:
7b086b11 543 warn_missing_prototypes = value;
0b6f2917
NB
544 break;
545
546 case OPT_Wmultichar:
7b086b11 547 cpp_opts->warn_multichar = value;
0b6f2917
NB
548 break;
549
550 case OPT_Wnested_externs:
7b086b11 551 warn_nested_externs = value;
0b6f2917
NB
552 break;
553
554 case OPT_Wnon_template_friend:
7b086b11 555 warn_nontemplate_friend = value;
0b6f2917
NB
556 break;
557
558 case OPT_Wnon_virtual_dtor:
7b086b11 559 warn_nonvdtor = value;
0b6f2917
NB
560 break;
561
562 case OPT_Wnonnull:
7b086b11 563 warn_nonnull = value;
0b6f2917
NB
564 break;
565
566 case OPT_Wold_style_cast:
7b086b11 567 warn_old_style_cast = value;
0b6f2917
NB
568 break;
569
570 case OPT_Woverloaded_virtual:
7b086b11 571 warn_overloaded_virtual = value;
0b6f2917
NB
572 break;
573
574 case OPT_Wparentheses:
7b086b11 575 warn_parentheses = value;
0b6f2917
NB
576 break;
577
578 case OPT_Wpmf_conversions:
7b086b11 579 warn_pmf2ptr = value;
0b6f2917
NB
580 break;
581
582 case OPT_Wpointer_arith:
7b086b11 583 warn_pointer_arith = value;
0b6f2917
NB
584 break;
585
586 case OPT_Wprotocol:
7b086b11 587 warn_protocol = value;
0b6f2917
NB
588 break;
589
590 case OPT_Wselector:
7b086b11 591 warn_selector = value;
0b6f2917
NB
592 break;
593
594 case OPT_Wredundant_decls:
7b086b11 595 warn_redundant_decls = value;
0b6f2917
NB
596 break;
597
598 case OPT_Wreorder:
7b086b11 599 warn_reorder = value;
0b6f2917
NB
600 break;
601
602 case OPT_Wreturn_type:
7b086b11 603 warn_return_type = value;
0b6f2917
NB
604 break;
605
606 case OPT_Wsequence_point:
7b086b11 607 warn_sequence_point = value;
0b6f2917
NB
608 break;
609
610 case OPT_Wsign_compare:
7b086b11 611 warn_sign_compare = value;
0b6f2917
NB
612 break;
613
614 case OPT_Wsign_promo:
7b086b11 615 warn_sign_promo = value;
0b6f2917
NB
616 break;
617
618 case OPT_Wstrict_prototypes:
7b086b11 619 warn_strict_prototypes = value;
0b6f2917
NB
620 break;
621
622 case OPT_Wsynth:
7b086b11 623 warn_synth = value;
0b6f2917
NB
624 break;
625
18bdccaa 626 case OPT_Wsystem_headers:
7b086b11 627 cpp_opts->warn_system_headers = value;
18bdccaa
NB
628 break;
629
0b6f2917 630 case OPT_Wtraditional:
7b086b11
NB
631 warn_traditional = value;
632 cpp_opts->warn_traditional = value;
18bdccaa
NB
633 break;
634
635 case OPT_Wtrigraphs:
7b086b11 636 cpp_opts->warn_trigraphs = value;
18bdccaa
NB
637 break;
638
ece4ce85 639 case OPT_Wundeclared_selector:
7b086b11 640 warn_undeclared_selector = value;
ece4ce85
NP
641 break;
642
18bdccaa 643 case OPT_Wundef:
7b086b11 644 cpp_opts->warn_undef = value;
0b6f2917
NB
645 break;
646
647 case OPT_Wunknown_pragmas:
648 /* Set to greater than 1, so that even unknown pragmas in
2f6e4e97 649 system headers will be warned about. */
7b086b11 650 warn_unknown_pragmas = value * 2;
0b6f2917
NB
651 break;
652
18bdccaa 653 case OPT_Wunused_macros:
7b086b11 654 warn_unused_macros = value;
18bdccaa
NB
655 break;
656
0b6f2917 657 case OPT_Wwrite_strings:
37fa72e9 658 if (!c_dialect_cxx ())
7b086b11 659 flag_const_strings = value;
0b6f2917 660 else
7b086b11 661 warn_write_strings = value;
0b6f2917 662 break;
2f6e4e97 663
f749a36b 664 case OPT_ansi:
37fa72e9 665 if (!c_dialect_cxx ())
f749a36b
NB
666 set_std_c89 (false, true);
667 else
668 set_std_cxx98 (true);
669 break;
0b6f2917 670
4b7091eb
NB
671 case OPT_d:
672 handle_OPT_d (arg);
673 break;
674
0b6f2917 675 case OPT_fcond_mismatch:
37fa72e9 676 if (!c_dialect_cxx ())
0b6f2917 677 {
7b086b11 678 flag_cond_mismatch = value;
0b6f2917
NB
679 break;
680 }
681 /* Fall through. */
682
683 case OPT_fall_virtual:
684 case OPT_fenum_int_equiv:
685 case OPT_fguiding_decls:
686 case OPT_fhonor_std:
687 case OPT_fhuge_objects:
688 case OPT_flabels_ok:
fef3106c 689 case OPT_fname_mangling_version_:
0b6f2917
NB
690 case OPT_fnew_abi:
691 case OPT_fnonnull_objects:
692 case OPT_fsquangle:
693 case OPT_fstrict_prototype:
694 case OPT_fthis_is_variable:
695 case OPT_fvtable_thunks:
696 case OPT_fxref:
f75d3e11 697 warning ("switch \"%s\" is no longer supported", option->opt_text);
0b6f2917
NB
698 break;
699
fef3106c 700 case OPT_fabi_version_:
7b086b11 701 flag_abi_version = value;
2d3e278d
MM
702 break;
703
0b6f2917 704 case OPT_faccess_control:
7b086b11 705 flag_access_control = value;
0b6f2917
NB
706 break;
707
708 case OPT_falt_external_templates:
7b086b11
NB
709 flag_alt_external_templates = value;
710 if (value)
0b6f2917
NB
711 flag_external_templates = true;
712 cp_deprecated:
f75d3e11 713 warning ("switch \"%s\" is deprecated, please see documentation for details", option->opt_text);
0b6f2917
NB
714 break;
715
716 case OPT_fasm:
7b086b11 717 flag_no_asm = !value;
0b6f2917
NB
718 break;
719
720 case OPT_fbuiltin:
7b086b11 721 flag_no_builtin = !value;
0b6f2917
NB
722 break;
723
724 case OPT_fbuiltin_:
7b086b11 725 if (value)
4b7091eb
NB
726 result = 0;
727 else
728 disable_builtin_function (arg);
0b6f2917
NB
729 break;
730
731 case OPT_fdollars_in_identifiers:
7b086b11 732 cpp_opts->dollars_in_ident = value;
0b6f2917
NB
733 break;
734
fef3106c 735 case OPT_fdump_:
f3f735eb 736 if (!dump_switch_p (arg))
4b7091eb 737 result = 0;
0b6f2917
NB
738 break;
739
740 case OPT_ffreestanding:
7b086b11 741 value = !value;
0b6f2917
NB
742 /* Fall through... */
743 case OPT_fhosted:
7b086b11
NB
744 flag_hosted = value;
745 flag_no_builtin = !value;
0b6f2917 746 /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
7b086b11 747 if (!value && warn_main == 2)
0b6f2917
NB
748 warn_main = 0;
749 break;
750
751 case OPT_fshort_double:
7b086b11 752 flag_short_double = value;
0b6f2917
NB
753 break;
754
755 case OPT_fshort_enums:
7b086b11 756 flag_short_enums = value;
0b6f2917
NB
757 break;
758
759 case OPT_fshort_wchar:
7b086b11 760 flag_short_wchar = value;
0b6f2917
NB
761 break;
762
763 case OPT_fsigned_bitfields:
7b086b11 764 flag_signed_bitfields = value;
0b6f2917
NB
765 explicit_flag_signed_bitfields = 1;
766 break;
767
768 case OPT_fsigned_char:
7b086b11 769 flag_signed_char = value;
0b6f2917
NB
770 break;
771
772 case OPT_funsigned_bitfields:
7b086b11 773 flag_signed_bitfields = !value;
0b6f2917
NB
774 explicit_flag_signed_bitfields = 1;
775 break;
776
777 case OPT_funsigned_char:
7b086b11 778 flag_signed_char = !value;
0b6f2917
NB
779 break;
780
781 case OPT_fcheck_new:
7b086b11 782 flag_check_new = value;
0b6f2917
NB
783 break;
784
785 case OPT_fconserve_space:
7b086b11 786 flag_conserve_space = value;
0b6f2917
NB
787 break;
788
789 case OPT_fconst_strings:
7b086b11 790 flag_const_strings = value;
0b6f2917
NB
791 break;
792
fef3106c 793 case OPT_fconstant_string_class_:
4b7091eb 794 constant_string_class_name = arg;
0b6f2917
NB
795 break;
796
797 case OPT_fdefault_inline:
7b086b11 798 flag_default_inline = value;
0b6f2917
NB
799 break;
800
801 case OPT_felide_constructors:
7b086b11 802 flag_elide_constructors = value;
0b6f2917
NB
803 break;
804
805 case OPT_fenforce_eh_specs:
7b086b11 806 flag_enforce_eh_specs = value;
0b6f2917
NB
807 break;
808
809 case OPT_fexternal_templates:
7b086b11 810 flag_external_templates = value;
0b6f2917
NB
811 goto cp_deprecated;
812
1c2de642 813 case OPT_ffixed_form:
fef3106c 814 case OPT_ffixed_line_length_:
1c2de642 815 /* Fortran front end options ignored when preprocessing only. */
058de654
NB
816 if (!flag_preprocess_only)
817 result = 0;
1c2de642
TM
818 break;
819
0b6f2917 820 case OPT_ffor_scope:
7b086b11 821 flag_new_for_scope = value;
0b6f2917
NB
822 break;
823
824 case OPT_fgnu_keywords:
7b086b11 825 flag_no_gnu_keywords = !value;
0b6f2917
NB
826 break;
827
828 case OPT_fgnu_runtime:
7b086b11 829 flag_next_runtime = !value;
0b6f2917
NB
830 break;
831
832 case OPT_fhandle_exceptions:
f75d3e11 833 warning ("-fhandle-exceptions has been renamed -fexceptions (and is now on by default)");
7b086b11 834 flag_exceptions = value;
0b6f2917
NB
835 break;
836
837 case OPT_fimplement_inlines:
7b086b11 838 flag_implement_inlines = value;
0b6f2917
NB
839 break;
840
841 case OPT_fimplicit_inline_templates:
7b086b11 842 flag_implicit_inline_templates = value;
0b6f2917
NB
843 break;
844
845 case OPT_fimplicit_templates:
7b086b11 846 flag_implicit_templates = value;
0b6f2917
NB
847 break;
848
849 case OPT_fms_extensions:
7b086b11 850 flag_ms_extensions = value;
0b6f2917
NB
851 break;
852
853 case OPT_fnext_runtime:
7b086b11 854 flag_next_runtime = value;
0b6f2917
NB
855 break;
856
857 case OPT_fnonansi_builtins:
7b086b11 858 flag_no_nonansi_builtin = !value;
0b6f2917
NB
859 break;
860
18bdccaa 861 case OPT_foperator_names:
7b086b11 862 cpp_opts->operator_names = value;
18bdccaa
NB
863 break;
864
0b6f2917 865 case OPT_foptional_diags:
7b086b11 866 flag_optional_diags = value;
0b6f2917
NB
867 break;
868
17211ab5 869 case OPT_fpch_deps:
7b086b11 870 cpp_opts->restore_pch_deps = value;
17211ab5
GK
871 break;
872
0b6f2917 873 case OPT_fpermissive:
7b086b11 874 flag_permissive = value;
0b6f2917
NB
875 break;
876
18bdccaa 877 case OPT_fpreprocessed:
7b086b11 878 cpp_opts->preprocessed = value;
18bdccaa
NB
879 break;
880
0b6f2917 881 case OPT_frepo:
7b086b11
NB
882 flag_use_repository = value;
883 if (value)
0b6f2917
NB
884 flag_implicit_templates = 0;
885 break;
886
887 case OPT_frtti:
7b086b11 888 flag_rtti = value;
0b6f2917
NB
889 break;
890
18bdccaa 891 case OPT_fshow_column:
7b086b11 892 cpp_opts->show_column = value;
18bdccaa
NB
893 break;
894
0b6f2917 895 case OPT_fstats:
7b086b11 896 flag_detailed_statistics = value;
0b6f2917
NB
897 break;
898
fef3106c 899 case OPT_ftabstop_:
18bdccaa 900 /* It is documented that we silently ignore silly values. */
7b086b11
NB
901 if (value >= 1 && value <= 100)
902 cpp_opts->tabstop = value;
18bdccaa
NB
903 break;
904
fef3106c 905 case OPT_ftemplate_depth_:
7b086b11 906 max_tinst_depth = value;
0b6f2917
NB
907 break;
908
909 case OPT_fvtable_gc:
7b086b11 910 flag_vtable_gc = value;
0b6f2917
NB
911 break;
912
913 case OPT_fuse_cxa_atexit:
7b086b11 914 flag_use_cxa_atexit = value;
0b6f2917
NB
915 break;
916
917 case OPT_fweak:
7b086b11 918 flag_weak = value;
0b6f2917
NB
919 break;
920
921 case OPT_gen_decls:
922 flag_gen_declaration = 1;
923 break;
924
5793b276
NB
925 case OPT_idirafter:
926 add_path (xstrdup (arg), AFTER, 0);
927 break;
928
255c10b1 929 case OPT_imacros:
23345bbb
NB
930 case OPT_include:
931 defer_opt (code, arg);
932 break;
933
5793b276
NB
934 case OPT_iprefix:
935 iprefix = arg;
936 break;
937
938 case OPT_isysroot:
939 sysroot = arg;
940 break;
941
942 case OPT_isystem:
943 add_path (xstrdup (arg), SYSTEM, 0);
944 break;
945
946 case OPT_iwithprefix:
947 add_prefixed_path (arg, SYSTEM);
948 break;
949
950 case OPT_iwithprefixbefore:
951 add_prefixed_path (arg, BRACKET);
952 break;
953
f749a36b
NB
954 case OPT_lang_asm:
955 cpp_set_lang (parse_in, CLK_ASM);
42ad6c9e 956 cpp_opts->dollars_in_ident = false;
f749a36b
NB
957 break;
958
959 case OPT_lang_objc:
960 cpp_opts->objc = 1;
961 break;
962
4b7091eb 963 case OPT_nostdinc:
5793b276 964 std_inc = false;
4b7091eb
NB
965 break;
966
fef3106c 967 case OPT_nostdinc__:
5793b276 968 std_cxx_inc = false;
4b7091eb
NB
969 break;
970
b4a93904 971 case OPT_o:
76c3e73e
NB
972 if (!out_fname)
973 out_fname = arg;
b4a93904 974 else
f75d3e11 975 error ("output filename specified twice");
b4a93904
NB
976 break;
977
18bdccaa
NB
978 /* We need to handle the -pedantic switches here, rather than in
979 c_common_post_options, so that a subsequent -Wno-endif-labels
980 is not overridden. */
981 case OPT_pedantic_errors:
982 cpp_opts->pedantic_errors = 1;
983 /* fall through */
984 case OPT_pedantic:
985 cpp_opts->pedantic = 1;
986 cpp_opts->warn_endif_labels = 1;
987 break;
988
0b6f2917
NB
989 case OPT_print_objc_runtime_info:
990 print_struct_values = 1;
991 break;
992
b4a93904
NB
993 case OPT_remap:
994 cpp_opts->remap = 1;
0b6f2917
NB
995 break;
996
fef3106c
NB
997 case OPT_std_c__98:
998 case OPT_std_gnu__98:
999 set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
0b6f2917
NB
1000 break;
1001
1002 case OPT_std_c89:
1003 case OPT_std_iso9899_1990:
b4a93904
NB
1004 case OPT_std_iso9899_199409:
1005 set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
f749a36b
NB
1006 break;
1007
1008 case OPT_std_gnu89:
1009 set_std_c89 (false /* c94 */, false /* ISO */);
0b6f2917
NB
1010 break;
1011
1012 case OPT_std_c99:
1013 case OPT_std_c9x:
1014 case OPT_std_iso9899_1999:
1015 case OPT_std_iso9899_199x:
b4a93904 1016 set_std_c99 (true /* ISO */);
0b6f2917
NB
1017 break;
1018
0b6f2917
NB
1019 case OPT_std_gnu99:
1020 case OPT_std_gnu9x:
b4a93904 1021 set_std_c99 (false /* ISO */);
0b6f2917
NB
1022 break;
1023
4b7091eb
NB
1024 case OPT_trigraphs:
1025 cpp_opts->trigraphs = 1;
1026 break;
1027
1028 case OPT_traditional_cpp:
1029 cpp_opts->traditional = 1;
1030 break;
1031
0b6f2917
NB
1032 case OPT_undef:
1033 flag_undef = 1;
1034 break;
0b6f2917 1035
4b7091eb
NB
1036 case OPT_w:
1037 cpp_opts->inhibit_warnings = 1;
1038 break;
1039
1040 case OPT_v:
5793b276 1041 verbose = true;
4b7091eb
NB
1042 break;
1043 }
0b6f2917 1044
0b6f2917
NB
1045 return result;
1046}
1047
1048/* Post-switch processing. */
1049bool
2f6e4e97 1050c_common_post_options (const char **pfilename)
0b6f2917 1051{
460bd0e3
NB
1052 /* Canonicalize the input and output filenames. */
1053 if (in_fname == NULL || !strcmp (in_fname, "-"))
1054 in_fname = "";
1055
76c3e73e
NB
1056 if (out_fname == NULL || !strcmp (out_fname, "-"))
1057 out_fname = "";
1058
cd79e210 1059 if (cpp_opts->deps.style == DEPS_NONE)
76c3e73e
NB
1060 check_deps_environment_vars ();
1061
f4ff5a69 1062 handle_deferred_opts ();
76c3e73e 1063
f4ff5a69 1064 sanitize_cpp_opts ();
460bd0e3 1065
5793b276 1066 register_include_chains (parse_in, sysroot, iprefix,
37fa72e9 1067 std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
5793b276 1068
0b6f2917
NB
1069 flag_inline_trees = 1;
1070
1071 /* Use tree inlining if possible. Function instrumentation is only
1072 done in the RTL level, so we disable tree inlining. */
1073 if (! flag_instrument_function_entry_exit)
1074 {
1075 if (!flag_no_inline)
1076 flag_no_inline = 1;
1077 if (flag_inline_functions)
1078 {
1079 flag_inline_trees = 2;
1080 flag_inline_functions = 0;
1081 }
1082 }
1083
87f85ea0
ZW
1084 /* -Wextra implies -Wsign-compare, but not if explicitly
1085 overridden. */
1086 if (warn_sign_compare == -1)
1087 warn_sign_compare = extra_warnings;
1088
0b6f2917
NB
1089 /* Special format checking options don't work without -Wformat; warn if
1090 they are used. */
1091 if (warn_format_y2k && !warn_format)
1092 warning ("-Wformat-y2k ignored without -Wformat");
1093 if (warn_format_extra_args && !warn_format)
1094 warning ("-Wformat-extra-args ignored without -Wformat");
1095 if (warn_format_zero_length && !warn_format)
1096 warning ("-Wformat-zero-length ignored without -Wformat");
1097 if (warn_format_nonliteral && !warn_format)
1098 warning ("-Wformat-nonliteral ignored without -Wformat");
1099 if (warn_format_security && !warn_format)
1100 warning ("-Wformat-security ignored without -Wformat");
1101 if (warn_missing_format_attribute && !warn_format)
1102 warning ("-Wmissing-format-attribute ignored without -Wformat");
1103
460bd0e3
NB
1104 if (flag_preprocess_only)
1105 {
63973df3
NB
1106 /* Open the output now. We must do so even if flag_no_output is
1107 on, because there may be other output than from the actual
1108 preprocessing (e.g. from -dM). */
1109 if (out_fname[0] == '\0')
1110 out_stream = stdout;
1111 else
1112 out_stream = fopen (out_fname, "w");
1113
1114 if (out_stream == NULL)
9d10c9a9 1115 {
fa6ef813 1116 fatal_error ("opening output file %s: %m", out_fname);
c366ade5 1117 return false;
9d10c9a9 1118 }
63973df3 1119
9d10c9a9 1120 init_pp_output (out_stream);
460bd0e3 1121 }
9d10c9a9
NB
1122 else
1123 {
1124 init_c_lex ();
460bd0e3 1125
9d10c9a9 1126 /* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
d479d37f 1127 input_line = 0;
9d10c9a9 1128 }
63973df3 1129
23345bbb
NB
1130 cpp_get_callbacks (parse_in)->file_change = cb_file_change;
1131
63973df3 1132 /* NOTE: we use in_fname here, not the one supplied. */
b4e46cea 1133 *pfilename = cpp_read_main_file (parse_in, in_fname);
4bfec483 1134
d479d37f
NS
1135 saved_lineno = input_line;
1136 input_line = 0;
4bfec483
NB
1137
1138 /* If an error has occurred in cpplib, note it so we fail
1139 immediately. */
1140 errorcount += cpp_errors (parse_in);
1141
1142 return flag_preprocess_only;
1143}
1144
1145/* Front end initialization common to C, ObjC and C++. */
1146bool
2f6e4e97 1147c_common_init (void)
4bfec483 1148{
d479d37f 1149 input_line = saved_lineno;
4bfec483
NB
1150
1151 /* Set up preprocessor arithmetic. Must be done after call to
1152 c_common_nodes_and_builtins for type nodes to be good. */
1153 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1154 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1155 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1156 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1157 cpp_opts->unsigned_wchar = TREE_UNSIGNED (wchar_type_node);
783e2989 1158 cpp_opts->EBCDIC = TARGET_EBCDIC;
460bd0e3 1159
9d10c9a9
NB
1160 if (flag_preprocess_only)
1161 {
255c10b1 1162 finish_options ();
23345bbb 1163 preprocess_file (parse_in);
4bfec483 1164 return false;
9d10c9a9
NB
1165 }
1166
63973df3 1167 /* Has to wait until now so that cpplib has its hash table. */
460bd0e3
NB
1168 init_pragma ();
1169
4bfec483 1170 return true;
76c3e73e
NB
1171}
1172
2f6e4e97 1173/* A thin wrapper around the real parser that initializes the
23345bbb
NB
1174 integrated preprocessor after debug output has been initialized.
1175 Also, make sure the start_source_file debug hook gets called for
1176 the primary source file. */
1177void
2f6e4e97 1178c_common_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
23345bbb
NB
1179{
1180#if YYDEBUG != 0
1181 yydebug = set_yydebug;
1182#else
1183 warning ("YYDEBUG not defined");
1184#endif
1185
d479d37f 1186 (*debug_hooks->start_source_file) (input_line, input_filename);
255c10b1 1187 finish_options();
23345bbb
NB
1188 pch_init();
1189 yyparse ();
1190 free_parser_stacks ();
1191}
1192
76c3e73e
NB
1193/* Common finish hook for the C, ObjC and C++ front ends. */
1194void
2f6e4e97 1195c_common_finish (void)
76c3e73e
NB
1196{
1197 FILE *deps_stream = NULL;
1198
f4ff5a69 1199 if (cpp_opts->deps.style != DEPS_NONE)
76c3e73e
NB
1200 {
1201 /* If -M or -MM was seen without -MF, default output to the
1202 output stream. */
f4ff5a69 1203 if (!deps_file)
76c3e73e
NB
1204 deps_stream = out_stream;
1205 else
1206 {
f4ff5a69 1207 deps_stream = fopen (deps_file, deps_append ? "a": "w");
76c3e73e 1208 if (!deps_stream)
fa6ef813 1209 fatal_error ("opening dependency file %s: %m", deps_file);
76c3e73e
NB
1210 }
1211 }
1212
1213 /* For performance, avoid tearing down cpplib's internal structures
1214 with cpp_destroy (). */
1215 errorcount += cpp_finish (parse_in, deps_stream);
1216
1217 if (deps_stream && deps_stream != out_stream
1218 && (ferror (deps_stream) || fclose (deps_stream)))
fa6ef813 1219 fatal_error ("closing dependency file %s: %m", deps_file);
76c3e73e
NB
1220
1221 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
fa6ef813 1222 fatal_error ("when writing output to %s: %m", out_fname);
76c3e73e
NB
1223}
1224
76c3e73e
NB
1225/* Either of two environment variables can specify output of
1226 dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1227 DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1228 and DEPS_TARGET is the target to mention in the deps. They also
1229 result in dependency information being appended to the output file
182d89a3
NB
1230 rather than overwriting it, and like Sun's compiler
1231 SUNPRO_DEPENDENCIES suppresses the dependency on the main file. */
76c3e73e 1232static void
2f6e4e97 1233check_deps_environment_vars (void)
76c3e73e
NB
1234{
1235 char *spec;
1236
1237 GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
1238 if (spec)
f4ff5a69 1239 cpp_opts->deps.style = DEPS_USER;
76c3e73e
NB
1240 else
1241 {
1242 GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
1243 if (spec)
182d89a3
NB
1244 {
1245 cpp_opts->deps.style = DEPS_SYSTEM;
1246 cpp_opts->deps.ignore_main_file = true;
1247 }
76c3e73e
NB
1248 }
1249
1250 if (spec)
1251 {
1252 /* Find the space before the DEPS_TARGET, if there is one. */
1253 char *s = strchr (spec, ' ');
1254 if (s)
1255 {
1256 /* Let the caller perform MAKE quoting. */
f4ff5a69 1257 defer_opt (OPT_MT, s + 1);
76c3e73e
NB
1258 *s = '\0';
1259 }
1260
1261 /* Command line -MF overrides environment variables and default. */
f4ff5a69
NB
1262 if (!deps_file)
1263 deps_file = spec;
76c3e73e 1264
f4ff5a69
NB
1265 deps_append = 1;
1266 }
1267}
1268
1269/* Handle deferred command line switches. */
1270static void
2f6e4e97 1271handle_deferred_opts (void)
f4ff5a69
NB
1272{
1273 size_t i;
1274
1275 for (i = 0; i < deferred_count; i++)
1276 {
1277 struct deferred_opt *opt = &deferred_opts[i];
1278
c1bad961
NB
1279 if (opt->code == OPT_MT || opt->code == OPT_MQ)
1280 cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
f4ff5a69 1281 }
f4ff5a69
NB
1282}
1283
1284/* These settings are appropriate for GCC, but not necessarily so for
1285 cpplib as a library. */
1286static void
2f6e4e97 1287sanitize_cpp_opts (void)
f4ff5a69
NB
1288{
1289 /* If we don't know what style of dependencies to output, complain
1290 if any other dependency switches have been given. */
1291 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1292 error ("to generate dependencies you must specify either -M or -MM");
1293
1294 /* -dM and dependencies suppress normal output; do it here so that
1295 the last -d[MDN] switch overrides earlier ones. */
63973df3
NB
1296 if (flag_dump_macros == 'M')
1297 flag_no_output = 1;
f4ff5a69
NB
1298
1299 /* Disable -dD, -dN and -dI if normal output is suppressed. Allow
1300 -dM since at least glibc relies on -M -dM to work. */
63973df3 1301 if (flag_no_output)
f4ff5a69 1302 {
63973df3
NB
1303 if (flag_dump_macros != 'M')
1304 flag_dump_macros = 0;
1305 flag_dump_includes = 0;
76c3e73e 1306 }
f4ff5a69
NB
1307
1308 cpp_opts->unsigned_char = !flag_signed_char;
1309 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1310
1311 /* We want -Wno-long-long to override -pedantic -std=non-c99
1312 and/or -Wtraditional, whatever the ordering. */
1313 cpp_opts->warn_long_long
1314 = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
1315}
1316
5793b276
NB
1317/* Add include path with a prefix at the front of its name. */
1318static void
2f6e4e97 1319add_prefixed_path (const char *suffix, size_t chain)
5793b276 1320{
52999738 1321 char *path;
5793b276 1322 const char *prefix;
52999738 1323 size_t prefix_len, suffix_len;
5793b276 1324
52999738
ZW
1325 suffix_len = strlen (suffix);
1326 prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1327 prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1328
1329 path = xmalloc (prefix_len + suffix_len + 1);
1330 memcpy (path, prefix, prefix_len);
1331 memcpy (path + prefix_len, suffix, suffix_len);
1332 path[prefix_len + suffix_len] = '\0';
1333
1334 add_path (path, chain, 0);
5793b276
NB
1335}
1336
255c10b1
NB
1337/* Handle -D, -U, -A, -imacros, and the first -include. */
1338static void
2f6e4e97 1339finish_options (void)
255c10b1 1340{
255c10b1
NB
1341 if (!cpp_opts->preprocessed)
1342 {
c1bad961
NB
1343 size_t i;
1344
b4e46cea 1345 cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
6e270179 1346 cpp_init_builtins (parse_in, flag_hosted);
c1bad961 1347 c_cpp_builtins (parse_in);
78b8811a
HPN
1348
1349 /* We're about to send user input to cpplib, so make it warn for
1350 things that we previously (when we sent it internal definitions)
1351 told it to not warn.
1352
1353 C99 permits implementation-defined characters in identifiers.
1354 The documented meaning of -std= is to turn off extensions that
1355 conflict with the specified standard, and since a strictly
1356 conforming program cannot contain a '$', we do not condition
1357 their acceptance on the -std= setting. */
1358 cpp_opts->warn_dollars = (cpp_opts->pedantic && !cpp_opts->c99);
1359
b4e46cea 1360 cpp_change_file (parse_in, LC_RENAME, _("<command line>"));
c1bad961
NB
1361 for (i = 0; i < deferred_count; i++)
1362 {
1363 struct deferred_opt *opt = &deferred_opts[i];
1364
1365 if (opt->code == OPT_D)
1366 cpp_define (parse_in, opt->arg);
1367 else if (opt->code == OPT_U)
1368 cpp_undef (parse_in, opt->arg);
1369 else if (opt->code == OPT_A)
1370 {
1371 if (opt->arg[0] == '-')
1372 cpp_unassert (parse_in, opt->arg + 1);
1373 else
1374 cpp_assert (parse_in, opt->arg);
1375 }
1376 }
255c10b1 1377
c1bad961 1378 /* Handle -imacros after -D and -U. */
255c10b1
NB
1379 for (i = 0; i < deferred_count; i++)
1380 {
1381 struct deferred_opt *opt = &deferred_opts[i];
1382
1383 if (opt->code == OPT_imacros
1384 && cpp_push_include (parse_in, opt->arg))
1385 cpp_scan_nooutput (parse_in);
1386 }
1387 }
1388
1389 push_command_line_include ();
1390}
1391
23345bbb
NB
1392/* Give CPP the next file given by -include, if any. */
1393static void
2f6e4e97 1394push_command_line_include (void)
23345bbb
NB
1395{
1396 if (cpp_opts->preprocessed)
1397 return;
2f6e4e97 1398
23345bbb
NB
1399 while (include_cursor < deferred_count)
1400 {
1401 struct deferred_opt *opt = &deferred_opts[include_cursor++];
2f6e4e97 1402
23345bbb
NB
1403 if (opt->code == OPT_include && cpp_push_include (parse_in, opt->arg))
1404 return;
1405 }
1406
1407 if (include_cursor == deferred_count)
1408 {
1409 /* Restore the line map from <command line>. */
b4e46cea 1410 cpp_change_file (parse_in, LC_RENAME, main_input_filename);
23345bbb
NB
1411 /* -Wunused-macros should only warn about macros defined hereafter. */
1412 cpp_opts->warn_unused_macros = warn_unused_macros;
1413 include_cursor++;
1414 }
1415}
1416
1417/* File change callback. Has to handle -include files. */
1418static void
2f6e4e97
AJ
1419cb_file_change (cpp_reader *pfile ATTRIBUTE_UNUSED,
1420 const struct line_map *new_map)
23345bbb
NB
1421{
1422 if (flag_preprocess_only)
1423 pp_file_change (new_map);
1424 else
1425 fe_file_change (new_map);
1426
1427 if (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map))
1428 push_command_line_include ();
1429}
1430
f4ff5a69
NB
1431/* Set the C 89 standard (with 1994 amendments if C94, without GNU
1432 extensions if ISO). There is no concept of gnu94. */
1433static void
2f6e4e97 1434set_std_c89 (int c94, int iso)
f4ff5a69
NB
1435{
1436 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1437 flag_iso = iso;
1438 flag_no_asm = iso;
1439 flag_no_gnu_keywords = iso;
1440 flag_no_nonansi_builtin = iso;
1441 flag_noniso_default_format_attributes = !iso;
1442 flag_isoc94 = c94;
1443 flag_isoc99 = 0;
1444 flag_writable_strings = 0;
76c3e73e
NB
1445}
1446
b4a93904
NB
1447/* Set the C 99 standard (without GNU extensions if ISO). */
1448static void
2f6e4e97 1449set_std_c99 (int iso)
b4a93904
NB
1450{
1451 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1452 flag_no_asm = iso;
1453 flag_no_nonansi_builtin = iso;
1454 flag_noniso_default_format_attributes = !iso;
1455 flag_iso = iso;
1456 flag_isoc99 = 1;
1457 flag_isoc94 = 1;
1458 flag_writable_strings = 0;
1459}
1460
f749a36b
NB
1461/* Set the C++ 98 standard (without GNU extensions if ISO). */
1462static void
2f6e4e97 1463set_std_cxx98 (int iso)
f749a36b
NB
1464{
1465 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1466 flag_no_gnu_keywords = iso;
1467 flag_no_nonansi_builtin = iso;
1468 flag_noniso_default_format_attributes = !iso;
1469 flag_iso = iso;
1470}
1471
0b6f2917
NB
1472/* Handle setting implicit to ON. */
1473static void
2f6e4e97 1474set_Wimplicit (int on)
0b6f2917
NB
1475{
1476 warn_implicit = on;
1477 warn_implicit_int = on;
1478 if (on)
1479 {
1480 if (mesg_implicit_function_declaration != 2)
1481 mesg_implicit_function_declaration = 1;
1482 }
1483 else
1484 mesg_implicit_function_declaration = 0;
1485}
1486
4b7091eb 1487/* Args to -d specify what to dump. Silently ignore
05713b80 1488 unrecognized options; they may be aimed at toplev.c. */
0b6f2917 1489static void
2f6e4e97 1490handle_OPT_d (const char *arg)
0b6f2917 1491{
4b7091eb
NB
1492 char c;
1493
1494 while ((c = *arg++) != '\0')
1495 switch (c)
1496 {
63973df3
NB
1497 case 'M': /* Dump macros only. */
1498 case 'N': /* Dump names. */
1499 case 'D': /* Dump definitions. */
1500 flag_dump_macros = c;
4b7091eb
NB
1501 break;
1502
1503 case 'I':
63973df3 1504 flag_dump_includes = 1;
4b7091eb
NB
1505 break;
1506 }
0b6f2917
NB
1507}
1508
4b7091eb
NB
1509/* Handle --help output. */
1510static void
2f6e4e97 1511print_help (void)
4b7091eb
NB
1512{
1513 /* To keep the lines from getting too long for some compilers, limit
1514 to about 500 characters (6 lines) per chunk. */
1515 fputs (_("\
1516Switches:\n\
1517 -include <file> Include the contents of <file> before other files\n\
1518 -imacros <file> Accept definition of macros in <file>\n\
1519 -iprefix <path> Specify <path> as a prefix for next two options\n\
1520 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1521 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1522 -isystem <dir> Add <dir> to the start of the system include path\n\
1523"), stdout);
1524 fputs (_("\
1525 -idirafter <dir> Add <dir> to the end of the system include path\n\
1526 -I <dir> Add <dir> to the end of the main include path\n\
1527 -I- Fine-grained include path control; see info docs\n\
1528 -nostdinc Do not search system include directories\n\
1529 (dirs specified with -isystem will still be used)\n\
1530 -nostdinc++ Do not search system include directories for C++\n\
1531 -o <file> Put output into <file>\n\
1532"), stdout);
1533 fputs (_("\
1534 -trigraphs Support ISO C trigraphs\n\
1535 -std=<std name> Specify the conformance standard; one of:\n\
1536 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1537 iso9899:199409, iso9899:1999, c++98\n\
1538 -w Inhibit warning messages\n\
1539 -W[no-]trigraphs Warn if trigraphs are encountered\n\
1540 -W[no-]comment{s} Warn if one comment starts inside another\n\
1541"), stdout);
1542 fputs (_("\
1543 -W[no-]traditional Warn about features not present in traditional C\n\
1544 -W[no-]undef Warn if an undefined macro is used by #if\n\
1545 -W[no-]import Warn about the use of the #import directive\n\
1546"), stdout);
1547 fputs (_("\
1548 -W[no-]error Treat all warnings as errors\n\
1549 -W[no-]system-headers Do not suppress warnings from system headers\n\
1550 -W[no-]all Enable most preprocessor warnings\n\
1551"), stdout);
1552 fputs (_("\
1553 -M Generate make dependencies\n\
1554 -MM As -M, but ignore system header files\n\
1555 -MD Generate make dependencies and compile\n\
1556 -MMD As -MD, but ignore system header files\n\
1557 -MF <file> Write dependency output to the given file\n\
1558 -MG Treat missing header file as generated files\n\
1559"), stdout);
1560 fputs (_("\
1561 -MP Generate phony targets for all headers\n\
1562 -MQ <target> Add a MAKE-quoted target\n\
1563 -MT <target> Add an unquoted target\n\
1564"), stdout);
1565 fputs (_("\
1566 -D<macro> Define a <macro> with string '1' as its value\n\
1567 -D<macro>=<val> Define a <macro> with <val> as its value\n\
1568 -A<question>=<answer> Assert the <answer> to <question>\n\
1569 -A-<question>=<answer> Disable the <answer> to <question>\n\
1570 -U<macro> Undefine <macro> \n\
1571 -v Display the version number\n\
1572"), stdout);
1573 fputs (_("\
1574 -H Print the name of header files as they are used\n\
1575 -C Do not discard comments\n\
1576 -dM Display a list of macro definitions active at end\n\
1577 -dD Preserve macro definitions in output\n\
1578 -dN As -dD except that only the names are preserved\n\
1579 -dI Include #include directives in the output\n\
1580"), stdout);
1581 fputs (_("\
1582 -f[no-]preprocessed Treat the input file as already preprocessed\n\
1583 -ftabstop=<number> Distance between tab stops for column reporting\n\
5793b276 1584 -isysroot <dir> Set <dir> to be the system root directory\n\
4b7091eb
NB
1585 -P Do not generate #line directives\n\
1586 -remap Remap file names when including files\n\
1587 --help Display this information\n\
1588"), stdout);
1589}
This page took 0.386807 seconds and 5 git commands to generate.