OSDN Git Service

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