OSDN Git Service

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