OSDN Git Service

In gcc/:
[pf3gnuchains/gcc-fork.git] / gcc / c-family / c-opts.c
1 /* C/ObjC/C++ command line option handling.
2    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3    Free Software Foundation, Inc.
4    Contributed by Neil Booth.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tree.h"
26 #include "c-common.h"
27 #include "c-pragma.h"
28 #include "flags.h"
29 #include "toplev.h"
30 #include "langhooks.h"
31 #include "diagnostic.h"
32 #include "intl.h"
33 #include "cppdefault.h"
34 #include "incpath.h"
35 #include "debug.h"              /* For debug_hooks.  */
36 #include "opts.h"
37 #include "options.h"
38 #include "mkdeps.h"
39 #include "target.h"             /* For gcc_targetcm.  */
40 #include "tm_p.h"               /* For C_COMMON_OVERRIDE_OPTIONS.  */
41
42 #ifndef DOLLARS_IN_IDENTIFIERS
43 # define DOLLARS_IN_IDENTIFIERS true
44 #endif
45
46 #ifndef TARGET_SYSTEM_ROOT
47 # define TARGET_SYSTEM_ROOT NULL
48 #endif
49
50 #ifndef TARGET_OPTF
51 #define TARGET_OPTF(ARG)
52 #endif
53
54 /* CPP's options.  */
55 cpp_options *cpp_opts;
56
57 /* Input filename.  */
58 static const char *this_input_filename;
59
60 /* Filename and stream for preprocessed output.  */
61 static const char *out_fname;
62 static FILE *out_stream;
63
64 /* Append dependencies to deps_file.  */
65 static bool deps_append;
66
67 /* If dependency switches (-MF etc.) have been given.  */
68 static bool deps_seen;
69
70 /* If -v seen.  */
71 static bool verbose;
72
73 /* Dependency output file.  */
74 static const char *deps_file;
75
76 /* The prefix given by -iprefix, if any.  */
77 static const char *iprefix;
78
79 /* The multilib directory given by -imultilib, if any.  */
80 static const char *imultilib;
81
82 /* The system root, if any.  Overridden by -isysroot.  */
83 static const char *sysroot = TARGET_SYSTEM_ROOT;
84
85 /* Zero disables all standard directories for headers.  */
86 static bool std_inc = true;
87
88 /* Zero disables the C++-specific standard directories for headers.  */
89 static bool std_cxx_inc = true;
90
91 /* If the quote chain has been split by -I-.  */
92 static bool quote_chain_split;
93
94 /* If -Wunused-macros.  */
95 static bool warn_unused_macros;
96
97 /* If -Wvariadic-macros.  */
98 static bool warn_variadic_macros = true;
99
100 /* Number of deferred options.  */
101 static size_t deferred_count;
102
103 /* Number of deferred options scanned for -include.  */
104 static size_t include_cursor;
105
106 static void handle_OPT_d (const char *);
107 static void set_std_cxx98 (int);
108 static void set_std_cxx0x (int);
109 static void set_std_c89 (int, int);
110 static void set_std_c99 (int);
111 static void set_std_c1x (int);
112 static void check_deps_environment_vars (void);
113 static void handle_deferred_opts (void);
114 static void sanitize_cpp_opts (void);
115 static void add_prefixed_path (const char *, size_t);
116 static void push_command_line_include (void);
117 static void cb_file_change (cpp_reader *, const struct line_map *);
118 static void cb_dir_change (cpp_reader *, const char *);
119 static void finish_options (void);
120
121 #ifndef STDC_0_IN_SYSTEM_HEADERS
122 #define STDC_0_IN_SYSTEM_HEADERS 0
123 #endif
124
125 /* Holds switches parsed by c_common_handle_option (), but whose
126    handling is deferred to c_common_post_options ().  */
127 static void defer_opt (enum opt_code, const char *);
128 static struct deferred_opt
129 {
130   enum opt_code code;
131   const char *arg;
132 } *deferred_opts;
133
134
135 static const unsigned int 
136 c_family_lang_mask = (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX);
137
138 /* Defer option CODE with argument ARG.  */
139 static void
140 defer_opt (enum opt_code code, const char *arg)
141 {
142   deferred_opts[deferred_count].code = code;
143   deferred_opts[deferred_count].arg = arg;
144   deferred_count++;
145 }
146
147 /* -Werror= may set a warning option to enable a warning that is emitted
148    by the preprocessor.  Set any corresponding flag in cpp_opts.  */
149
150 static void
151 warning_as_error_callback (int option_index)
152 {
153   switch (option_index)
154     {
155       default:
156         /* Ignore options not associated with the preprocessor.  */
157         break;
158
159       case OPT_Wdeprecated:
160         cpp_opts->cpp_warn_deprecated = 1;
161         break;
162
163       case OPT_Wcomment:
164         cpp_opts->warn_comments = 1;
165         break;
166
167       case OPT_Wtrigraphs:
168         cpp_opts->warn_trigraphs = 1;
169         break;
170
171       case OPT_Wmultichar:
172         cpp_opts->warn_multichar = 1;
173         break;
174
175       case OPT_Wtraditional:
176         cpp_opts->cpp_warn_traditional = 1;
177         break;
178
179       case OPT_Wlong_long:
180         cpp_opts->cpp_warn_long_long = 1;
181         break;
182
183       case OPT_Wendif_labels:
184         cpp_opts->warn_endif_labels = 1;
185         break;
186
187       case OPT_Wvariadic_macros:
188         /* Set the local flag that is used later to update cpp_opts.  */
189         warn_variadic_macros = 1;
190         break;
191
192       case OPT_Wbuiltin_macro_redefined:
193         cpp_opts->warn_builtin_macro_redefined = 1;
194         break;
195
196       case OPT_Wundef:
197         cpp_opts->warn_undef = 1;
198         break;
199
200       case OPT_Wunused_macros:
201         /* Set the local flag that is used later to update cpp_opts.  */
202         warn_unused_macros = 1;
203         break;
204
205       case OPT_Wc___compat:
206         /* Add warnings in the same way as c_common_handle_option below.  */
207         if (warn_enum_compare == -1)
208           warn_enum_compare = 1;
209         if (warn_jump_misses_init == -1)
210           warn_jump_misses_init = 1;
211         cpp_opts->warn_cxx_operator_names = 1;
212         break;
213
214       case OPT_Wnormalized_:
215         inform (input_location, "-Werror=normalized=: Set -Wnormalized=nfc");
216         cpp_opts->warn_normalize = normalized_C;
217         break;
218
219       case OPT_Winvalid_pch:
220         cpp_opts->warn_invalid_pch = 1;
221         break;
222
223       case OPT_Wcpp:
224         /* Handled by standard diagnostics using the option's associated
225            boolean variable.  */
226         break;
227     }
228 }
229
230 /* Return language mask for option parsing.  */
231 unsigned int
232 c_common_option_lang_mask (void)
233 {
234   static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
235
236   return lang_flags[c_language];
237 }
238
239 /* Common diagnostics initialization.  */
240 void
241 c_common_initialize_diagnostics (diagnostic_context *context)
242 {
243   /* Register callback for warnings enabled by -Werror=.  */
244   register_warning_as_error_callback (warning_as_error_callback);
245
246   /* This is conditionalized only because that is the way the front
247      ends used to do it.  Maybe this should be unconditional?  */
248   if (c_dialect_cxx ())
249     {
250       /* By default wrap lines at 80 characters.  Is getenv
251          ("COLUMNS") preferable?  */
252       diagnostic_line_cutoff (context) = 80;
253       /* By default, emit location information once for every
254          diagnostic message.  */
255       diagnostic_prefixing_rule (context) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
256     }
257
258   context->opt_permissive = OPT_fpermissive;
259 }
260
261 /* Whether options from all C-family languages should be accepted
262    quietly.  */
263 static bool accept_all_c_family_options = false;
264
265 /* Return whether to complain about a wrong-language option.  */
266 bool
267 c_common_complain_wrong_lang_p (const struct cl_option *option)
268 {
269   if (accept_all_c_family_options
270       && (option->flags & c_family_lang_mask))
271     return false;
272
273   return true;
274 }
275
276 /* Initialize options structure OPTS.  */
277 void
278 c_common_init_options_struct (struct gcc_options *opts)
279 {
280   opts->x_flag_exceptions = c_dialect_cxx ();
281   opts->x_warn_pointer_arith = c_dialect_cxx ();
282   opts->x_warn_write_strings = c_dialect_cxx ();
283   opts->x_flag_warn_unused_result = true;
284
285   /* By default, C99-like requirements for complex multiply and divide.  */
286   opts->x_flag_complex_method = 2;
287 }
288
289 /* Common initialization before calling option handlers.  */
290 void
291 c_common_init_options (unsigned int decoded_options_count,
292                        struct cl_decoded_option *decoded_options)
293 {
294   unsigned int i;
295   struct cpp_callbacks *cb;
296
297   parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
298                                 ident_hash, line_table);
299   cb = cpp_get_callbacks (parse_in);
300   cb->error = c_cpp_error;
301
302   cpp_opts = cpp_get_options (parse_in);
303   cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
304   cpp_opts->objc = c_dialect_objc ();
305
306   /* Reset to avoid warnings on internal definitions.  We set it just
307      before passing on command-line options to cpplib.  */
308   cpp_opts->warn_dollars = 0;
309
310   deferred_opts = XNEWVEC (struct deferred_opt, decoded_options_count);
311
312   if (c_language == clk_c)
313     {
314       /* If preprocessing assembly language, accept any of the C-family
315          front end options since the driver may pass them through.  */
316       for (i = 1; i < decoded_options_count; i++)
317         if (decoded_options[i].opt_index == OPT_lang_asm)
318           {
319             accept_all_c_family_options = true;
320             break;
321           }
322     }
323 }
324
325 /* Handle switch SCODE with argument ARG.  VALUE is true, unless no-
326    form of an -f or -W option was given.  Returns false if the switch was
327    invalid, true if valid.  Use HANDLERS in recursive handle_option calls.  */
328 bool
329 c_common_handle_option (size_t scode, const char *arg, int value,
330                         int kind, const struct cl_option_handlers *handlers)
331 {
332   const struct cl_option *option = &cl_options[scode];
333   enum opt_code code = (enum opt_code) scode;
334   bool result = true;
335
336   /* Prevent resetting the language standard to a C dialect when the driver
337      has already determined that we're looking at assembler input.  */
338   bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM);
339
340   switch (code)
341     {
342     default:
343       if (cl_options[code].flags & c_family_lang_mask)
344         {
345           if ((option->flags & CL_TARGET)
346               && ! targetcm.handle_c_option (scode, arg, value))
347             result = false;
348           break;
349         }
350       result = false;
351       break;
352
353     case OPT__output_pch_:
354       pch_file = arg;
355       break;
356
357     case OPT_A:
358       defer_opt (code, arg);
359       break;
360
361     case OPT_C:
362       cpp_opts->discard_comments = 0;
363       break;
364
365     case OPT_CC:
366       cpp_opts->discard_comments = 0;
367       cpp_opts->discard_comments_in_macro_exp = 0;
368       break;
369
370     case OPT_D:
371       defer_opt (code, arg);
372       break;
373
374     case OPT_H:
375       cpp_opts->print_include_names = 1;
376       break;
377
378     case OPT_F:
379       TARGET_OPTF (xstrdup (arg));
380       break;
381
382     case OPT_I:
383       if (strcmp (arg, "-"))
384         add_path (xstrdup (arg), BRACKET, 0, true);
385       else
386         {
387           if (quote_chain_split)
388             error ("-I- specified twice");
389           quote_chain_split = true;
390           split_quote_chain ();
391           inform (input_location, "obsolete option -I- used, please use -iquote instead");
392         }
393       break;
394
395     case OPT_M:
396     case OPT_MM:
397       /* When doing dependencies with -M or -MM, suppress normal
398          preprocessed output, but still do -dM etc. as software
399          depends on this.  Preprocessed output does occur if -MD, -MMD
400          or environment var dependency generation is used.  */
401       cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
402       flag_no_output = 1;
403       break;
404
405     case OPT_MD:
406     case OPT_MMD:
407       cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
408       cpp_opts->deps.need_preprocessor_output = true;
409       deps_file = arg;
410       break;
411
412     case OPT_MF:
413       deps_seen = true;
414       deps_file = arg;
415       break;
416
417     case OPT_MG:
418       deps_seen = true;
419       cpp_opts->deps.missing_files = true;
420       break;
421
422     case OPT_MP:
423       deps_seen = true;
424       cpp_opts->deps.phony_targets = true;
425       break;
426
427     case OPT_MQ:
428     case OPT_MT:
429       deps_seen = true;
430       defer_opt (code, arg);
431       break;
432
433     case OPT_P:
434       flag_no_line_commands = 1;
435       break;
436
437     case OPT_U:
438       defer_opt (code, arg);
439       break;
440
441     case OPT_Wall:
442       warn_unused = value;
443       set_Wformat (value);
444       handle_generated_option (&global_options, &global_options_set,
445                                OPT_Wimplicit, NULL, value,
446                                c_family_lang_mask, kind, handlers, global_dc);
447       warn_char_subscripts = value;
448       warn_missing_braces = value;
449       warn_parentheses = value;
450       warn_return_type = value;
451       warn_sequence_point = value;      /* Was C only.  */
452       warn_switch = value;
453       if (warn_strict_aliasing == -1)
454         set_Wstrict_aliasing (value);
455       warn_address = value;
456       if (warn_strict_overflow == -1)
457         warn_strict_overflow = value;
458       warn_array_bounds = value;
459       warn_volatile_register_var = value;
460
461       /* Only warn about unknown pragmas that are not in system
462          headers.  */
463       warn_unknown_pragmas = value;
464
465       warn_uninitialized = value;
466
467       if (!c_dialect_cxx ())
468         {
469           /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
470              can turn it off only if it's not explicit.  */
471           if (warn_main == -1)
472             warn_main = (value ? 2 : 0);
473
474           /* In C, -Wall turns on -Wenum-compare, which we do here.
475              In C++ it is on by default, which is done in
476              c_common_post_options.  */
477           if (warn_enum_compare == -1)
478             warn_enum_compare = value;
479         }
480       else
481         {
482           /* C++-specific warnings.  */
483           warn_sign_compare = value;
484           warn_reorder = value;
485           warn_cxx0x_compat = value;
486         }
487
488       cpp_opts->warn_trigraphs = value;
489       cpp_opts->warn_comments = value;
490       cpp_opts->warn_num_sign_change = value;
491
492       if (warn_pointer_sign == -1)
493         warn_pointer_sign = value;
494       break;
495
496     case OPT_Wbuiltin_macro_redefined:
497       cpp_opts->warn_builtin_macro_redefined = value;
498       break;
499
500     case OPT_Wcomment:
501       cpp_opts->warn_comments = value;
502       break;
503
504     case OPT_Wc___compat:
505       /* Because -Wenum-compare is the default in C++, -Wc++-compat
506          implies -Wenum-compare.  */
507       if (warn_enum_compare == -1 && value)
508         warn_enum_compare = value;
509       /* Because C++ always warns about a goto which misses an
510          initialization, -Wc++-compat turns on -Wjump-misses-init.  */
511       if (warn_jump_misses_init == -1 && value)
512         warn_jump_misses_init = value;
513       cpp_opts->warn_cxx_operator_names = value;
514       break;
515
516     case OPT_Wdeprecated:
517       cpp_opts->cpp_warn_deprecated = value;
518       break;
519
520     case OPT_Wendif_labels:
521       cpp_opts->warn_endif_labels = value;
522       break;
523
524     case OPT_Werror:
525       global_dc->warning_as_error_requested = value;
526       break;
527
528     case OPT_Wformat:
529       set_Wformat (value);
530       break;
531
532     case OPT_Wformat_:
533       set_Wformat (atoi (arg));
534       break;
535
536     case OPT_Wimplicit:
537       gcc_assert (value == 0 || value == 1);
538       if (warn_implicit_int == -1)
539         handle_generated_option (&global_options, &global_options_set,
540                                  OPT_Wimplicit_int, NULL, value,
541                                  c_family_lang_mask, kind, handlers,
542                                  global_dc);
543       if (warn_implicit_function_declaration == -1)
544         handle_generated_option (&global_options, &global_options_set,
545                                  OPT_Wimplicit_function_declaration, NULL,
546                                  value, c_family_lang_mask, kind, handlers,
547                                  global_dc);
548       break;
549
550     case OPT_Winvalid_pch:
551       cpp_opts->warn_invalid_pch = value;
552       break;
553
554     case OPT_Wmissing_include_dirs:
555       cpp_opts->warn_missing_include_dirs = value;
556       break;
557
558     case OPT_Wmultichar:
559       cpp_opts->warn_multichar = value;
560       break;
561
562     case OPT_Wnormalized_:
563       if (!value || (arg && strcasecmp (arg, "none") == 0))
564         cpp_opts->warn_normalize = normalized_none;
565       else if (!arg || strcasecmp (arg, "nfkc") == 0)
566         cpp_opts->warn_normalize = normalized_KC;
567       else if (strcasecmp (arg, "id") == 0)
568         cpp_opts->warn_normalize = normalized_identifier_C;
569       else if (strcasecmp (arg, "nfc") == 0)
570         cpp_opts->warn_normalize = normalized_C;
571       else
572         error ("argument %qs to %<-Wnormalized%> not recognized", arg);
573       break;
574
575     case OPT_Wreturn_type:
576       warn_return_type = value;
577       break;
578
579     case OPT_Wtraditional:
580       cpp_opts->cpp_warn_traditional = value;
581       break;
582
583     case OPT_Wtrigraphs:
584       cpp_opts->warn_trigraphs = value;
585       break;
586
587     case OPT_Wundef:
588       cpp_opts->warn_undef = value;
589       break;
590
591     case OPT_Wunknown_pragmas:
592       /* Set to greater than 1, so that even unknown pragmas in
593          system headers will be warned about.  */
594       warn_unknown_pragmas = value * 2;
595       break;
596
597     case OPT_Wunused_macros:
598       warn_unused_macros = value;
599       break;
600
601     case OPT_Wvariadic_macros:
602       warn_variadic_macros = value;
603       break;
604
605     case OPT_Wwrite_strings:
606       warn_write_strings = value;
607       break;
608
609     case OPT_Weffc__:
610       warn_ecpp = value;
611       if (value)
612         warn_nonvdtor = true;
613       break;
614
615     case OPT_ansi:
616       if (!c_dialect_cxx ())
617         set_std_c89 (false, true);
618       else
619         set_std_cxx98 (true);
620       break;
621
622     case OPT_d:
623       handle_OPT_d (arg);
624       break;
625
626     case OPT_fcond_mismatch:
627       if (!c_dialect_cxx ())
628         {
629           flag_cond_mismatch = value;
630           break;
631         }
632       warning (0, "switch %qs is no longer supported", option->opt_text);
633       break;
634
635     case OPT_fbuiltin_:
636       if (value)
637         result = false;
638       else
639         disable_builtin_function (arg);
640       break;
641
642     case OPT_fdirectives_only:
643       cpp_opts->directives_only = value;
644       break;
645
646     case OPT_fdollars_in_identifiers:
647       cpp_opts->dollars_in_ident = value;
648       break;
649
650     case OPT_ffreestanding:
651       value = !value;
652       /* Fall through....  */
653     case OPT_fhosted:
654       flag_hosted = value;
655       flag_no_builtin = !value;
656       break;
657
658     case OPT_fconstant_string_class_:
659       constant_string_class_name = arg;
660       break;
661
662     case OPT_fextended_identifiers:
663       cpp_opts->extended_identifiers = value;
664       break;
665
666     case OPT_fgnu_runtime:
667       flag_next_runtime = !value;
668       break;
669
670     case OPT_fnext_runtime:
671       flag_next_runtime = value;
672       break;
673
674     case OPT_foperator_names:
675       cpp_opts->operator_names = value;
676       break;
677
678     case OPT_fpch_deps:
679       cpp_opts->restore_pch_deps = value;
680       break;
681
682     case OPT_fpch_preprocess:
683       flag_pch_preprocess = value;
684       break;
685
686     case OPT_fpermissive:
687       flag_permissive = value;
688       global_dc->permissive = value;
689       break;
690
691     case OPT_fpreprocessed:
692       cpp_opts->preprocessed = value;
693       break;
694
695     case OPT_frepo:
696       flag_use_repository = value;
697       if (value)
698         flag_implicit_templates = 0;
699       break;
700
701     case OPT_ftabstop_:
702       /* It is documented that we silently ignore silly values.  */
703       if (value >= 1 && value <= 100)
704         cpp_opts->tabstop = value;
705       break;
706
707     case OPT_fexec_charset_:
708       cpp_opts->narrow_charset = arg;
709       break;
710
711     case OPT_fwide_exec_charset_:
712       cpp_opts->wide_charset = arg;
713       break;
714
715     case OPT_finput_charset_:
716       cpp_opts->input_charset = arg;
717       break;
718
719     case OPT_ftemplate_depth_:
720       max_tinst_depth = value;
721       break;
722
723     case OPT_fvisibility_inlines_hidden:
724       visibility_options.inlines_hidden = value;
725       break;
726
727     case OPT_femit_struct_debug_baseonly:
728       set_struct_debug_option ("base");
729       break;
730
731     case OPT_femit_struct_debug_reduced:
732       set_struct_debug_option ("dir:ord:sys,dir:gen:any,ind:base");
733       break;
734
735     case OPT_femit_struct_debug_detailed_:
736       set_struct_debug_option (arg);
737       break;
738
739     case OPT_idirafter:
740       add_path (xstrdup (arg), AFTER, 0, true);
741       break;
742
743     case OPT_imacros:
744     case OPT_include:
745       defer_opt (code, arg);
746       break;
747
748     case OPT_imultilib:
749       imultilib = arg;
750       break;
751
752     case OPT_iprefix:
753       iprefix = arg;
754       break;
755
756     case OPT_iquote:
757       add_path (xstrdup (arg), QUOTE, 0, true);
758       break;
759
760     case OPT_isysroot:
761       sysroot = arg;
762       break;
763
764     case OPT_isystem:
765       add_path (xstrdup (arg), SYSTEM, 0, true);
766       break;
767
768     case OPT_iwithprefix:
769       add_prefixed_path (arg, SYSTEM);
770       break;
771
772     case OPT_iwithprefixbefore:
773       add_prefixed_path (arg, BRACKET);
774       break;
775
776     case OPT_lang_asm:
777       cpp_set_lang (parse_in, CLK_ASM);
778       cpp_opts->dollars_in_ident = false;
779       break;
780
781     case OPT_nostdinc:
782       std_inc = false;
783       break;
784
785     case OPT_nostdinc__:
786       std_cxx_inc = false;
787       break;
788
789     case OPT_o:
790       if (!out_fname)
791         out_fname = arg;
792       else
793         error ("output filename specified twice");
794       break;
795
796       /* We need to handle the -pedantic switches here, rather than in
797          c_common_post_options, so that a subsequent -Wno-endif-labels
798          is not overridden.  */
799     case OPT_pedantic_errors:
800     case OPT_pedantic:
801       cpp_opts->cpp_pedantic = 1;
802       cpp_opts->warn_endif_labels = 1;
803       if (warn_pointer_sign == -1)
804         warn_pointer_sign = 1;
805       if (warn_overlength_strings == -1)
806         warn_overlength_strings = 1;
807       if (warn_main == -1)
808         warn_main = 2;
809       break;
810
811     case OPT_print_objc_runtime_info:
812       print_struct_values = 1;
813       break;
814
815     case OPT_remap:
816       cpp_opts->remap = 1;
817       break;
818
819     case OPT_std_c__98:
820     case OPT_std_gnu__98:
821       if (!preprocessing_asm_p)
822         set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
823       break;
824
825     case OPT_std_c__0x:
826     case OPT_std_gnu__0x:
827       if (!preprocessing_asm_p)
828         set_std_cxx0x (code == OPT_std_c__0x /* ISO */);
829       break;
830
831     case OPT_std_c90:
832     case OPT_std_iso9899_199409:
833       if (!preprocessing_asm_p)
834         set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
835       break;
836
837     case OPT_std_gnu90:
838       if (!preprocessing_asm_p)
839         set_std_c89 (false /* c94 */, false /* ISO */);
840       break;
841
842     case OPT_std_c99:
843       if (!preprocessing_asm_p)
844         set_std_c99 (true /* ISO */);
845       break;
846
847     case OPT_std_gnu99:
848       if (!preprocessing_asm_p)
849         set_std_c99 (false /* ISO */);
850       break;
851
852     case OPT_std_c1x:
853       if (!preprocessing_asm_p)
854         set_std_c1x (true /* ISO */);
855       break;
856
857     case OPT_std_gnu1x:
858       if (!preprocessing_asm_p)
859         set_std_c1x (false /* ISO */);
860       break;
861
862     case OPT_trigraphs:
863       cpp_opts->trigraphs = 1;
864       break;
865
866     case OPT_traditional_cpp:
867       cpp_opts->traditional = 1;
868       break;
869
870     case OPT_v:
871       verbose = true;
872       break;
873
874     case OPT_Wabi:
875       warn_psabi = value;
876       break;
877     }
878
879   return result;
880 }
881
882 /* Post-switch processing.  */
883 bool
884 c_common_post_options (const char **pfilename)
885 {
886   struct cpp_callbacks *cb;
887
888   /* Canonicalize the input and output filenames.  */
889   if (in_fnames == NULL)
890     {
891       in_fnames = XNEWVEC (const char *, 1);
892       in_fnames[0] = "";
893     }
894   else if (strcmp (in_fnames[0], "-") == 0)
895     in_fnames[0] = "";
896
897   if (out_fname == NULL || !strcmp (out_fname, "-"))
898     out_fname = "";
899
900   if (cpp_opts->deps.style == DEPS_NONE)
901     check_deps_environment_vars ();
902
903   handle_deferred_opts ();
904
905   sanitize_cpp_opts ();
906
907   register_include_chains (parse_in, sysroot, iprefix, imultilib,
908                            std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
909
910 #ifdef C_COMMON_OVERRIDE_OPTIONS
911   /* Some machines may reject certain combinations of C
912      language-specific options.  */
913   C_COMMON_OVERRIDE_OPTIONS;
914 #endif
915
916   /* Excess precision other than "fast" requires front-end
917      support.  */
918   if (c_dialect_cxx ())
919     {
920       if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
921           && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
922         sorry ("-fexcess-precision=standard for C++");
923       flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
924     }
925   else if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT)
926     flag_excess_precision_cmdline = (flag_iso
927                                      ? EXCESS_PRECISION_STANDARD
928                                      : EXCESS_PRECISION_FAST);
929
930   /* By default we use C99 inline semantics in GNU99 or C99 mode.  C99
931      inline semantics are not supported in GNU89 or C89 mode.  */
932   if (flag_gnu89_inline == -1)
933     flag_gnu89_inline = !flag_isoc99;
934   else if (!flag_gnu89_inline && !flag_isoc99)
935     error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode");
936
937   /* Default to ObjC sjlj exception handling if NeXT runtime.  */
938   if (flag_objc_sjlj_exceptions < 0)
939     flag_objc_sjlj_exceptions = flag_next_runtime;
940   if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
941     flag_exceptions = 1;
942
943   /* -Wextra implies the following flags
944      unless explicitly overridden.  */
945   if (warn_type_limits == -1)
946     warn_type_limits = extra_warnings;
947   if (warn_clobbered == -1)
948     warn_clobbered = extra_warnings;
949   if (warn_empty_body == -1)
950     warn_empty_body = extra_warnings;
951   if (warn_sign_compare == -1)
952     warn_sign_compare = extra_warnings;
953   if (warn_missing_field_initializers == -1)
954     warn_missing_field_initializers = extra_warnings;
955   if (warn_missing_parameter_type == -1)
956     warn_missing_parameter_type = extra_warnings;
957   if (warn_old_style_declaration == -1)
958     warn_old_style_declaration = extra_warnings;
959   if (warn_override_init == -1)
960     warn_override_init = extra_warnings;
961   if (warn_ignored_qualifiers == -1)
962     warn_ignored_qualifiers = extra_warnings;
963
964   /* -Wpointer-sign is disabled by default, but it is enabled if any
965      of -Wall or -pedantic are given.  */
966   if (warn_pointer_sign == -1)
967     warn_pointer_sign = 0;
968
969   if (warn_strict_aliasing == -1)
970     warn_strict_aliasing = 0;
971   if (warn_strict_overflow == -1)
972     warn_strict_overflow = 0;
973   if (warn_jump_misses_init == -1)
974     warn_jump_misses_init = 0;
975
976   /* -Woverlength-strings is off by default, but is enabled by -pedantic.
977      It is never enabled in C++, as the minimum limit is not normative
978      in that standard.  */
979   if (warn_overlength_strings == -1 || c_dialect_cxx ())
980     warn_overlength_strings = 0;
981
982   /* Wmain is enabled by default in C++ but not in C.  */
983   /* Wmain is disabled by default for -ffreestanding (!flag_hosted),
984      even if -Wall was given (warn_main will be 2 if set by -Wall, 1
985      if set by -Wmain).  */
986   if (warn_main == -1)
987     warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
988   else if (warn_main == 2)
989     warn_main = flag_hosted ? 1 : 0;
990
991   /* In C, -Wconversion enables -Wsign-conversion (unless disabled
992      through -Wno-sign-conversion). While in C++,
993      -Wsign-conversion needs to be requested explicitly.  */
994   if (warn_sign_conversion == -1)
995     warn_sign_conversion =  (c_dialect_cxx ()) ? 0 : warn_conversion;
996
997   /* In C, -Wall and -Wc++-compat enable -Wenum-compare, which we do
998      in c_common_handle_option; if it has not yet been set, it is
999      disabled by default.  In C++, it is enabled by default.  */
1000   if (warn_enum_compare == -1)
1001     warn_enum_compare = c_dialect_cxx () ? 1 : 0;
1002
1003   /* -Wpacked-bitfield-compat is on by default for the C languages.  The
1004      warning is issued in stor-layout.c which is not part of the front-end so
1005      we need to selectively turn it on here.  */
1006   if (warn_packed_bitfield_compat == -1)
1007     warn_packed_bitfield_compat = 1;
1008
1009   /* Special format checking options don't work without -Wformat; warn if
1010      they are used.  */
1011   if (!warn_format)
1012     {
1013       warning (OPT_Wformat_y2k,
1014                "-Wformat-y2k ignored without -Wformat");
1015       warning (OPT_Wformat_extra_args,
1016                "-Wformat-extra-args ignored without -Wformat");
1017       warning (OPT_Wformat_zero_length,
1018                "-Wformat-zero-length ignored without -Wformat");
1019       warning (OPT_Wformat_nonliteral,
1020                "-Wformat-nonliteral ignored without -Wformat");
1021       warning (OPT_Wformat_contains_nul,
1022                "-Wformat-contains-nul ignored without -Wformat");
1023       warning (OPT_Wformat_security,
1024                "-Wformat-security ignored without -Wformat");
1025     }
1026
1027   if (warn_implicit == -1)
1028     warn_implicit = 0;
1029       
1030   if (warn_implicit_int == -1)
1031     warn_implicit_int = 0;
1032
1033   /* -Wimplicit-function-declaration is enabled by default for C99.  */
1034   if (warn_implicit_function_declaration == -1)
1035     warn_implicit_function_declaration = flag_isoc99;
1036
1037   /* If we're allowing C++0x constructs, don't warn about C++0x
1038      compatibility problems.  */
1039   if (cxx_dialect == cxx0x)
1040     warn_cxx0x_compat = 0;
1041
1042   if (flag_preprocess_only)
1043     {
1044       /* Open the output now.  We must do so even if flag_no_output is
1045          on, because there may be other output than from the actual
1046          preprocessing (e.g. from -dM).  */
1047       if (out_fname[0] == '\0')
1048         out_stream = stdout;
1049       else
1050         out_stream = fopen (out_fname, "w");
1051
1052       if (out_stream == NULL)
1053         {
1054           fatal_error ("opening output file %s: %m", out_fname);
1055           return false;
1056         }
1057
1058       if (num_in_fnames > 1)
1059         error ("too many filenames given.  Type %s --help for usage",
1060                progname);
1061
1062       init_pp_output (out_stream);
1063     }
1064   else
1065     {
1066       init_c_lex ();
1067
1068       /* Yuk.  WTF is this?  I do know ObjC relies on it somewhere.  */
1069       input_location = UNKNOWN_LOCATION;
1070     }
1071
1072   cb = cpp_get_callbacks (parse_in);
1073   cb->file_change = cb_file_change;
1074   cb->dir_change = cb_dir_change;
1075   cpp_post_options (parse_in);
1076
1077   input_location = UNKNOWN_LOCATION;
1078
1079   *pfilename = this_input_filename
1080     = cpp_read_main_file (parse_in, in_fnames[0]);
1081   /* Don't do any compilation or preprocessing if there is no input file.  */
1082   if (this_input_filename == NULL)
1083     {
1084       errorcount++;
1085       return false;
1086     }
1087
1088   if (flag_working_directory
1089       && flag_preprocess_only && !flag_no_line_commands)
1090     pp_dir_change (parse_in, get_src_pwd ());
1091
1092   return flag_preprocess_only;
1093 }
1094
1095 /* Front end initialization common to C, ObjC and C++.  */
1096 bool
1097 c_common_init (void)
1098 {
1099   /* Set up preprocessor arithmetic.  Must be done after call to
1100      c_common_nodes_and_builtins for type nodes to be good.  */
1101   cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1102   cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1103   cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1104   cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1105   cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
1106   cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
1107
1108   /* This can't happen until after wchar_precision and bytes_big_endian
1109      are known.  */
1110   cpp_init_iconv (parse_in);
1111
1112   if (version_flag)
1113     c_common_print_pch_checksum (stderr);
1114
1115   /* Has to wait until now so that cpplib has its hash table.  */
1116   init_pragma ();
1117
1118   if (flag_preprocess_only)
1119     {
1120       finish_options ();
1121       preprocess_file (parse_in);
1122       return false;
1123     }
1124
1125   return true;
1126 }
1127
1128 /* Initialize the integrated preprocessor after debug output has been
1129    initialized; loop over each input file.  */
1130 void
1131 c_common_parse_file (int set_yydebug)
1132 {
1133   unsigned int i;
1134
1135   if (set_yydebug)
1136     switch (c_language)
1137       {
1138       case clk_c:
1139         warning(0, "The C parser does not support -dy, option ignored");
1140         break;
1141       case clk_objc:
1142         warning(0,
1143                 "The Objective-C parser does not support -dy, option ignored");
1144         break;
1145       case clk_cxx:
1146         warning(0, "The C++ parser does not support -dy, option ignored");
1147         break;
1148       case clk_objcxx:
1149         warning(0,
1150             "The Objective-C++ parser does not support -dy, option ignored");
1151         break;
1152       default:
1153         gcc_unreachable ();
1154     }
1155
1156   i = 0;
1157   for (;;)
1158     {
1159       finish_options ();
1160       pch_init ();
1161       push_file_scope ();
1162       c_parse_file ();
1163       pop_file_scope ();
1164       /* And end the main input file, if the debug writer wants it  */
1165       if (debug_hooks->start_end_main_source_file)
1166         (*debug_hooks->end_source_file) (0);
1167       if (++i >= num_in_fnames)
1168         break;
1169       cpp_undef_all (parse_in);
1170       cpp_clear_file_cache (parse_in);
1171       this_input_filename
1172         = cpp_read_main_file (parse_in, in_fnames[i]);
1173       /* If an input file is missing, abandon further compilation.
1174          cpplib has issued a diagnostic.  */
1175       if (!this_input_filename)
1176         break;
1177     }
1178 }
1179
1180 /* Common finish hook for the C, ObjC and C++ front ends.  */
1181 void
1182 c_common_finish (void)
1183 {
1184   FILE *deps_stream = NULL;
1185
1186   /* Don't write the deps file if there are errors.  */
1187   if (cpp_opts->deps.style != DEPS_NONE && !seen_error ())
1188     {
1189       /* If -M or -MM was seen without -MF, default output to the
1190          output stream.  */
1191       if (!deps_file)
1192         deps_stream = out_stream;
1193       else
1194         {
1195           deps_stream = fopen (deps_file, deps_append ? "a": "w");
1196           if (!deps_stream)
1197             fatal_error ("opening dependency file %s: %m", deps_file);
1198         }
1199     }
1200
1201   /* For performance, avoid tearing down cpplib's internal structures
1202      with cpp_destroy ().  */
1203   cpp_finish (parse_in, deps_stream);
1204
1205   if (deps_stream && deps_stream != out_stream
1206       && (ferror (deps_stream) || fclose (deps_stream)))
1207     fatal_error ("closing dependency file %s: %m", deps_file);
1208
1209   if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1210     fatal_error ("when writing output to %s: %m", out_fname);
1211 }
1212
1213 /* Either of two environment variables can specify output of
1214    dependencies.  Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1215    DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1216    and DEPS_TARGET is the target to mention in the deps.  They also
1217    result in dependency information being appended to the output file
1218    rather than overwriting it, and like Sun's compiler
1219    SUNPRO_DEPENDENCIES suppresses the dependency on the main file.  */
1220 static void
1221 check_deps_environment_vars (void)
1222 {
1223   char *spec;
1224
1225   GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
1226   if (spec)
1227     cpp_opts->deps.style = DEPS_USER;
1228   else
1229     {
1230       GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
1231       if (spec)
1232         {
1233           cpp_opts->deps.style = DEPS_SYSTEM;
1234           cpp_opts->deps.ignore_main_file = true;
1235         }
1236     }
1237
1238   if (spec)
1239     {
1240       /* Find the space before the DEPS_TARGET, if there is one.  */
1241       char *s = strchr (spec, ' ');
1242       if (s)
1243         {
1244           /* Let the caller perform MAKE quoting.  */
1245           defer_opt (OPT_MT, s + 1);
1246           *s = '\0';
1247         }
1248
1249       /* Command line -MF overrides environment variables and default.  */
1250       if (!deps_file)
1251         deps_file = spec;
1252
1253       deps_append = 1;
1254       deps_seen = true;
1255     }
1256 }
1257
1258 /* Handle deferred command line switches.  */
1259 static void
1260 handle_deferred_opts (void)
1261 {
1262   size_t i;
1263   struct deps *deps;
1264
1265   /* Avoid allocating the deps buffer if we don't need it.
1266      (This flag may be true without there having been -MT or -MQ
1267      options, but we'll still need the deps buffer.)  */
1268   if (!deps_seen)
1269     return;
1270
1271   deps = cpp_get_deps (parse_in);
1272
1273   for (i = 0; i < deferred_count; i++)
1274     {
1275       struct deferred_opt *opt = &deferred_opts[i];
1276
1277       if (opt->code == OPT_MT || opt->code == OPT_MQ)
1278         deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
1279     }
1280 }
1281
1282 /* These settings are appropriate for GCC, but not necessarily so for
1283    cpplib as a library.  */
1284 static void
1285 sanitize_cpp_opts (void)
1286 {
1287   /* If we don't know what style of dependencies to output, complain
1288      if any other dependency switches have been given.  */
1289   if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1290     error ("to generate dependencies you must specify either -M or -MM");
1291
1292   /* -dM and dependencies suppress normal output; do it here so that
1293      the last -d[MDN] switch overrides earlier ones.  */
1294   if (flag_dump_macros == 'M')
1295     flag_no_output = 1;
1296
1297   /* By default, -fdirectives-only implies -dD.  This allows subsequent phases
1298      to perform proper macro expansion.  */
1299   if (cpp_opts->directives_only && !cpp_opts->preprocessed && !flag_dump_macros)
1300     flag_dump_macros = 'D';
1301
1302   /* Disable -dD, -dN and -dI if normal output is suppressed.  Allow
1303      -dM since at least glibc relies on -M -dM to work.  */
1304   /* Also, flag_no_output implies flag_no_line_commands, always.  */
1305   if (flag_no_output)
1306     {
1307       if (flag_dump_macros != 'M')
1308         flag_dump_macros = 0;
1309       flag_dump_includes = 0;
1310       flag_no_line_commands = 1;
1311     }
1312   else if (cpp_opts->deps.missing_files)
1313     error ("-MG may only be used with -M or -MM");
1314
1315   cpp_opts->unsigned_char = !flag_signed_char;
1316   cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1317
1318   /* Wlong-long is disabled by default. It is enabled by:
1319       [-pedantic | -Wtraditional] -std=[gnu|c]++98 ; or
1320       [-pedantic | -Wtraditional] -std=non-c99 .
1321
1322       Either -Wlong-long or -Wno-long-long override any other settings.  */
1323   if (warn_long_long == -1)
1324     warn_long_long = ((pedantic || warn_traditional)
1325                       && (c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99));
1326   cpp_opts->cpp_warn_long_long = warn_long_long;
1327
1328   /* Similarly with -Wno-variadic-macros.  No check for c99 here, since
1329      this also turns off warnings about GCCs extension.  */
1330   cpp_opts->warn_variadic_macros
1331     = warn_variadic_macros && (pedantic || warn_traditional);
1332
1333   /* If we're generating preprocessor output, emit current directory
1334      if explicitly requested or if debugging information is enabled.
1335      ??? Maybe we should only do it for debugging formats that
1336      actually output the current directory?  */
1337   if (flag_working_directory == -1)
1338     flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
1339
1340   if (cpp_opts->directives_only)
1341     {
1342       if (warn_unused_macros)
1343         error ("-fdirectives-only is incompatible with -Wunused_macros");
1344       if (cpp_opts->traditional)
1345         error ("-fdirectives-only is incompatible with -traditional");
1346     }
1347 }
1348
1349 /* Add include path with a prefix at the front of its name.  */
1350 static void
1351 add_prefixed_path (const char *suffix, size_t chain)
1352 {
1353   char *path;
1354   const char *prefix;
1355   size_t prefix_len, suffix_len;
1356
1357   suffix_len = strlen (suffix);
1358   prefix     = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1359   prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1360
1361   path = (char *) xmalloc (prefix_len + suffix_len + 1);
1362   memcpy (path, prefix, prefix_len);
1363   memcpy (path + prefix_len, suffix, suffix_len);
1364   path[prefix_len + suffix_len] = '\0';
1365
1366   add_path (path, chain, 0, false);
1367 }
1368
1369 /* Handle -D, -U, -A, -imacros, and the first -include.  */
1370 static void
1371 finish_options (void)
1372 {
1373   if (!cpp_opts->preprocessed)
1374     {
1375       size_t i;
1376
1377       cb_file_change (parse_in,
1378                       linemap_add (line_table, LC_RENAME, 0,
1379                                    _("<built-in>"), 0));
1380
1381       cpp_init_builtins (parse_in, flag_hosted);
1382       c_cpp_builtins (parse_in);
1383
1384       /* We're about to send user input to cpplib, so make it warn for
1385          things that we previously (when we sent it internal definitions)
1386          told it to not warn.
1387
1388          C99 permits implementation-defined characters in identifiers.
1389          The documented meaning of -std= is to turn off extensions that
1390          conflict with the specified standard, and since a strictly
1391          conforming program cannot contain a '$', we do not condition
1392          their acceptance on the -std= setting.  */
1393       cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
1394
1395       cb_file_change (parse_in,
1396                       linemap_add (line_table, LC_RENAME, 0,
1397                                    _("<command-line>"), 0));
1398
1399       for (i = 0; i < deferred_count; i++)
1400         {
1401           struct deferred_opt *opt = &deferred_opts[i];
1402
1403           if (opt->code == OPT_D)
1404             cpp_define (parse_in, opt->arg);
1405           else if (opt->code == OPT_U)
1406             cpp_undef (parse_in, opt->arg);
1407           else if (opt->code == OPT_A)
1408             {
1409               if (opt->arg[0] == '-')
1410                 cpp_unassert (parse_in, opt->arg + 1);
1411               else
1412                 cpp_assert (parse_in, opt->arg);
1413             }
1414         }
1415
1416       /* Start the main input file, if the debug writer wants it. */
1417       if (debug_hooks->start_end_main_source_file
1418           && !flag_preprocess_only)
1419         (*debug_hooks->start_source_file) (0, this_input_filename);
1420
1421       /* Handle -imacros after -D and -U.  */
1422       for (i = 0; i < deferred_count; i++)
1423         {
1424           struct deferred_opt *opt = &deferred_opts[i];
1425
1426           if (opt->code == OPT_imacros
1427               && cpp_push_include (parse_in, opt->arg))
1428             {
1429               /* Disable push_command_line_include callback for now.  */
1430               include_cursor = deferred_count + 1;
1431               cpp_scan_nooutput (parse_in);
1432             }
1433         }
1434     }
1435   else
1436     {
1437       if (cpp_opts->directives_only)
1438         cpp_init_special_builtins (parse_in);
1439
1440       /* Start the main input file, if the debug writer wants it. */
1441       if (debug_hooks->start_end_main_source_file
1442           && !flag_preprocess_only)
1443         (*debug_hooks->start_source_file) (0, this_input_filename);
1444     }
1445
1446   include_cursor = 0;
1447   push_command_line_include ();
1448 }
1449
1450 /* Give CPP the next file given by -include, if any.  */
1451 static void
1452 push_command_line_include (void)
1453 {
1454   while (include_cursor < deferred_count)
1455     {
1456       struct deferred_opt *opt = &deferred_opts[include_cursor++];
1457
1458       if (!cpp_opts->preprocessed && opt->code == OPT_include
1459           && cpp_push_include (parse_in, opt->arg))
1460         return;
1461     }
1462
1463   if (include_cursor == deferred_count)
1464     {
1465       include_cursor++;
1466       /* -Wunused-macros should only warn about macros defined hereafter.  */
1467       cpp_opts->warn_unused_macros = warn_unused_macros;
1468       /* Restore the line map from <command line>.  */
1469       if (!cpp_opts->preprocessed)
1470         cpp_change_file (parse_in, LC_RENAME, this_input_filename);
1471
1472       /* Set this here so the client can change the option if it wishes,
1473          and after stacking the main file so we don't trace the main file.  */
1474       line_table->trace_includes = cpp_opts->print_include_names;
1475     }
1476 }
1477
1478 /* File change callback.  Has to handle -include files.  */
1479 static void
1480 cb_file_change (cpp_reader * ARG_UNUSED (pfile),
1481                 const struct line_map *new_map)
1482 {
1483   if (flag_preprocess_only)
1484     pp_file_change (new_map);
1485   else
1486     fe_file_change (new_map);
1487
1488   if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
1489     push_command_line_include ();
1490 }
1491
1492 void
1493 cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
1494 {
1495   if (!set_src_pwd (dir))
1496     warning (0, "too late for # directive to set debug directory");
1497 }
1498
1499 /* Set the C 89 standard (with 1994 amendments if C94, without GNU
1500    extensions if ISO).  There is no concept of gnu94.  */
1501 static void
1502 set_std_c89 (int c94, int iso)
1503 {
1504   cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1505   flag_iso = iso;
1506   flag_no_asm = iso;
1507   flag_no_gnu_keywords = iso;
1508   flag_no_nonansi_builtin = iso;
1509   flag_isoc94 = c94;
1510   flag_isoc99 = 0;
1511   flag_isoc1x = 0;
1512 }
1513
1514 /* Set the C 99 standard (without GNU extensions if ISO).  */
1515 static void
1516 set_std_c99 (int iso)
1517 {
1518   cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1519   flag_no_asm = iso;
1520   flag_no_nonansi_builtin = iso;
1521   flag_iso = iso;
1522   flag_isoc1x = 0;
1523   flag_isoc99 = 1;
1524   flag_isoc94 = 1;
1525 }
1526
1527 /* Set the C 1X standard draft (without GNU extensions if ISO).  */
1528 static void
1529 set_std_c1x (int iso)
1530 {
1531   cpp_set_lang (parse_in, iso ? CLK_STDC1X: CLK_GNUC1X);
1532   flag_no_asm = iso;
1533   flag_no_nonansi_builtin = iso;
1534   flag_iso = iso;
1535   flag_isoc1x = 1;
1536   flag_isoc99 = 1;
1537   flag_isoc94 = 1;
1538 }
1539
1540 /* Set the C++ 98 standard (without GNU extensions if ISO).  */
1541 static void
1542 set_std_cxx98 (int iso)
1543 {
1544   cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1545   flag_no_gnu_keywords = iso;
1546   flag_no_nonansi_builtin = iso;
1547   flag_iso = iso;
1548   cxx_dialect = cxx98;
1549 }
1550
1551 /* Set the C++ 0x working draft "standard" (without GNU extensions if ISO).  */
1552 static void
1553 set_std_cxx0x (int iso)
1554 {
1555   cpp_set_lang (parse_in, iso ? CLK_CXX0X: CLK_GNUCXX0X);
1556   flag_no_gnu_keywords = iso;
1557   flag_no_nonansi_builtin = iso;
1558   flag_iso = iso;
1559   cxx_dialect = cxx0x;
1560 }
1561
1562 /* Args to -d specify what to dump.  Silently ignore
1563    unrecognized options; they may be aimed at toplev.c.  */
1564 static void
1565 handle_OPT_d (const char *arg)
1566 {
1567   char c;
1568
1569   while ((c = *arg++) != '\0')
1570     switch (c)
1571       {
1572       case 'M':                 /* Dump macros only.  */
1573       case 'N':                 /* Dump names.  */
1574       case 'D':                 /* Dump definitions.  */
1575       case 'U':                 /* Dump used macros.  */
1576         flag_dump_macros = c;
1577         break;
1578
1579       case 'I':
1580         flag_dump_includes = 1;
1581         break;
1582       }
1583 }