c-opts.c revision 189824
1117395Skan/* C/ObjC/C++ command line option handling.
2169699Skan   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
3169699Skan   Free Software Foundation, Inc.
4117395Skan   Contributed by Neil Booth.
5117395Skan
6117395SkanThis file is part of GCC.
7117395Skan
8117395SkanGCC is free software; you can redistribute it and/or modify it under
9117395Skanthe terms of the GNU General Public License as published by the Free
10117395SkanSoftware Foundation; either version 2, or (at your option) any later
11117395Skanversion.
12117395Skan
13117395SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY
14117395SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or
15117395SkanFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16117395Skanfor more details.
17117395Skan
18117395SkanYou should have received a copy of the GNU General Public License
19117395Skanalong with GCC; see the file COPYING.  If not, write to the Free
20169699SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21169699Skan02110-1301, USA.  */
22117395Skan
23132811Skan/* $FreeBSD: head/contrib/gcc/c-opts.c 189824 2009-03-14 19:36:13Z das $ */
24189824Sdas/* Merged C99 inline changes from gcc trunk 122565 2007-03-05 */
25132811Skan
26117395Skan#include "config.h"
27117395Skan#include "system.h"
28132718Skan#include "coretypes.h"
29132718Skan#include "tm.h"
30117395Skan#include "tree.h"
31117395Skan#include "c-common.h"
32117395Skan#include "c-pragma.h"
33117395Skan#include "flags.h"
34117395Skan#include "toplev.h"
35117395Skan#include "langhooks.h"
36117395Skan#include "tree-inline.h"
37117395Skan#include "diagnostic.h"
38117395Skan#include "intl.h"
39132718Skan#include "cppdefault.h"
40132718Skan#include "c-incpath.h"
41132718Skan#include "debug.h"		/* For debug_hooks.  */
42132718Skan#include "opts.h"
43132718Skan#include "options.h"
44169699Skan#include "mkdeps.h"
45117395Skan
46132718Skan#ifndef DOLLARS_IN_IDENTIFIERS
47132718Skan# define DOLLARS_IN_IDENTIFIERS true
48132718Skan#endif
49132718Skan
50132718Skan#ifndef TARGET_SYSTEM_ROOT
51132718Skan# define TARGET_SYSTEM_ROOT NULL
52132718Skan#endif
53132718Skan
54169699Skan#ifndef TARGET_OPTF
55169699Skan#define TARGET_OPTF(ARG)
56169699Skan#endif
57132718Skan
58117395Skan/* CPP's options.  */
59117395Skanstatic cpp_options *cpp_opts;
60117395Skan
61117395Skan/* Input filename.  */
62132718Skanstatic const char *this_input_filename;
63117395Skan
64117395Skan/* Filename and stream for preprocessed output.  */
65117395Skanstatic const char *out_fname;
66117395Skanstatic FILE *out_stream;
67117395Skan
68117395Skan/* Append dependencies to deps_file.  */
69117395Skanstatic bool deps_append;
70117395Skan
71117395Skan/* If dependency switches (-MF etc.) have been given.  */
72117395Skanstatic bool deps_seen;
73117395Skan
74132718Skan/* If -v seen.  */
75132718Skanstatic bool verbose;
76132718Skan
77169699Skan/* If -lang-fortran seen.  */
78169699Skanstatic bool lang_fortran = false;
79169699Skan
80117395Skan/* Dependency output file.  */
81117395Skanstatic const char *deps_file;
82117395Skan
83132718Skan/* The prefix given by -iprefix, if any.  */
84132718Skanstatic const char *iprefix;
85117395Skan
86169699Skan/* The multilib directory given by -imultilib, if any.  */
87169699Skanstatic const char *imultilib;
88169699Skan
89132718Skan/* The system root, if any.  Overridden by -isysroot.  */
90132718Skanstatic const char *sysroot = TARGET_SYSTEM_ROOT;
91117395Skan
92132718Skan/* Zero disables all standard directories for headers.  */
93132718Skanstatic bool std_inc = true;
94117395Skan
95132718Skan/* Zero disables the C++-specific standard directories for headers.  */
96132718Skanstatic bool std_cxx_inc = true;
97117395Skan
98132718Skan/* If the quote chain has been split by -I-.  */
99132718Skanstatic bool quote_chain_split;
100117395Skan
101132718Skan/* If -Wunused-macros.  */
102132718Skanstatic bool warn_unused_macros;
103117395Skan
104169699Skan/* If -Wvariadic-macros.  */
105169699Skanstatic bool warn_variadic_macros = true;
106169699Skan
107132718Skan/* Number of deferred options.  */
108132718Skanstatic size_t deferred_count;
109117395Skan
110132718Skan/* Number of deferred options scanned for -include.  */
111132718Skanstatic size_t include_cursor;
112117395Skan
113132718Skanstatic void set_Wimplicit (int);
114132718Skanstatic void handle_OPT_d (const char *);
115132718Skanstatic void set_std_cxx98 (int);
116132718Skanstatic void set_std_c89 (int, int);
117132718Skanstatic void set_std_c99 (int);
118132718Skanstatic void check_deps_environment_vars (void);
119132718Skanstatic void handle_deferred_opts (void);
120132718Skanstatic void sanitize_cpp_opts (void);
121132718Skanstatic void add_prefixed_path (const char *, size_t);
122132718Skanstatic void push_command_line_include (void);
123132718Skanstatic void cb_file_change (cpp_reader *, const struct line_map *);
124132718Skanstatic void cb_dir_change (cpp_reader *, const char *);
125132718Skanstatic void finish_options (void);
126117395Skan
127132718Skan#ifndef STDC_0_IN_SYSTEM_HEADERS
128132718Skan#define STDC_0_IN_SYSTEM_HEADERS 0
129117395Skan#endif
130117395Skan
131132718Skan/* Holds switches parsed by c_common_handle_option (), but whose
132132718Skan   handling is deferred to c_common_post_options ().  */
133132718Skanstatic void defer_opt (enum opt_code, const char *);
134117395Skanstatic struct deferred_opt
135117395Skan{
136117395Skan  enum opt_code code;
137117395Skan  const char *arg;
138117395Skan} *deferred_opts;
139117395Skan
140132718Skan/* Complain that switch CODE expects an argument but none was
141132718Skan   provided.  OPT was the command-line option.  Return FALSE to get
142132718Skan   the default message in opts.c, TRUE if we provide a specialized
143132718Skan   one.  */
144132718Skanbool
145132718Skanc_common_missing_argument (const char *opt, size_t code)
146117395Skan{
147132718Skan  switch (code)
148117395Skan    {
149117395Skan    default:
150132718Skan      /* Pick up the default message.  */
151132718Skan      return false;
152132718Skan
153132718Skan    case OPT_fconstant_string_class_:
154169699Skan      error ("no class name specified with %qs", opt);
155117395Skan      break;
156117395Skan
157132718Skan    case OPT_A:
158169699Skan      error ("assertion missing after %qs", opt);
159117395Skan      break;
160117395Skan
161132718Skan    case OPT_D:
162132718Skan    case OPT_U:
163169699Skan      error ("macro name missing after %qs", opt);
164132718Skan      break;
165132718Skan
166169699Skan    case OPT_F:
167132718Skan    case OPT_I:
168132718Skan    case OPT_idirafter:
169132718Skan    case OPT_isysroot:
170132718Skan    case OPT_isystem:
171169699Skan    case OPT_iquote:
172169699Skan      error ("missing path after %qs", opt);
173132718Skan      break;
174132718Skan
175117395Skan    case OPT_MF:
176117395Skan    case OPT_MD:
177117395Skan    case OPT_MMD:
178132718Skan    case OPT_include:
179132718Skan    case OPT_imacros:
180117395Skan    case OPT_o:
181169699Skan      error ("missing filename after %qs", opt);
182117395Skan      break;
183117395Skan
184117395Skan    case OPT_MQ:
185117395Skan    case OPT_MT:
186169699Skan      error ("missing makefile target after %qs", opt);
187117395Skan      break;
188117395Skan    }
189117395Skan
190132718Skan  return true;
191117395Skan}
192117395Skan
193117395Skan/* Defer option CODE with argument ARG.  */
194117395Skanstatic void
195132718Skandefer_opt (enum opt_code code, const char *arg)
196117395Skan{
197117395Skan  deferred_opts[deferred_count].code = code;
198117395Skan  deferred_opts[deferred_count].arg = arg;
199117395Skan  deferred_count++;
200117395Skan}
201117395Skan
202117395Skan/* Common initialization before parsing options.  */
203132718Skanunsigned int
204146908Skanc_common_init_options (unsigned int argc, const char **argv)
205117395Skan{
206132718Skan  static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
207146908Skan  unsigned int i, result;
208117395Skan
209132718Skan  /* This is conditionalized only because that is the way the front
210132718Skan     ends used to do it.  Maybe this should be unconditional?  */
211132718Skan  if (c_dialect_cxx ())
212132718Skan    {
213132718Skan      /* By default wrap lines at 80 characters.  Is getenv
214132718Skan	 ("COLUMNS") preferable?  */
215132718Skan      diagnostic_line_cutoff (global_dc) = 80;
216132718Skan      /* By default, emit location information once for every
217132718Skan	 diagnostic message.  */
218132718Skan      diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
219132718Skan    }
220117395Skan
221132718Skan  parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
222169699Skan				ident_hash, &line_table);
223132718Skan
224117395Skan  cpp_opts = cpp_get_options (parse_in);
225132718Skan  cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
226132718Skan  cpp_opts->objc = c_dialect_objc ();
227117395Skan
228132718Skan  /* Reset to avoid warnings on internal definitions.  We set it just
229132718Skan     before passing on command-line options to cpplib.  */
230132718Skan  cpp_opts->warn_dollars = 0;
231117395Skan
232132718Skan  flag_exceptions = c_dialect_cxx ();
233132718Skan  warn_pointer_arith = c_dialect_cxx ();
234169699Skan  warn_write_strings = c_dialect_cxx();
235117395Skan
236169699Skan  deferred_opts = XNEWVEC (struct deferred_opt, argc);
237117395Skan
238132718Skan  result = lang_flags[c_language];
239117395Skan
240146908Skan  if (c_language == clk_c)
241146908Skan    {
242169699Skan      /* If preprocessing assembly language, accept any of the C-family
243169699Skan	 front end options since the driver may pass them through.  */
244146908Skan      for (i = 1; i < argc; i++)
245169699Skan	if (! strcmp (argv[i], "-lang-asm"))
246169699Skan	  {
247169699Skan	    result |= CL_C | CL_ObjC | CL_CXX | CL_ObjCXX;
248169699Skan	    break;
249169699Skan	  }
250169699Skan
251169699Skan#ifdef CL_Fortran
252169699Skan      for (i = 1; i < argc; i++)
253169699Skan	if (! strcmp (argv[i], "-lang-fortran"))
254146908Skan	{
255169699Skan	    result |= CL_Fortran;
256169699Skan	    break;
257169699Skan	}
258146908Skan#endif
259117395Skan    }
260169699Skan
261132718Skan  return result;
262132718Skan}
263117395Skan
264132718Skan/* Handle switch SCODE with argument ARG.  VALUE is true, unless no-
265132718Skan   form of an -f or -W option was given.  Returns 0 if the switch was
266132718Skan   invalid, a negative number to prevent language-independent
267132718Skan   processing in toplev.c (a hack necessary for the short-term).  */
268132718Skanint
269132718Skanc_common_handle_option (size_t scode, const char *arg, int value)
270132718Skan{
271132718Skan  const struct cl_option *option = &cl_options[scode];
272132718Skan  enum opt_code code = (enum opt_code) scode;
273132718Skan  int result = 1;
274117395Skan
275169699Skan  /* Prevent resetting the language standard to a C dialect when the driver
276169699Skan     has already determined that we're looking at assembler input.  */
277169699Skan  bool preprocessing_asm_p = (cpp_get_options (parse_in)->lang == CLK_ASM);
278169699Skan
279132718Skan  switch (code)
280117395Skan    {
281132718Skan    default:
282169699Skan      if (cl_options[code].flags & (CL_C | CL_CXX | CL_ObjC | CL_ObjCXX))
283169699Skan	break;
284169699Skan#ifdef CL_Fortran
285169699Skan      if (lang_fortran && (cl_options[code].flags & (CL_Fortran)))
286169699Skan	break;
287169699Skan#endif
288169699Skan      result = 0;
289132718Skan      break;
290117395Skan
291132718Skan    case OPT__output_pch_:
292132718Skan      pch_file = arg;
293117395Skan      break;
294117395Skan
295132718Skan    case OPT_A:
296132718Skan      defer_opt (code, arg);
297117395Skan      break;
298117395Skan
299117395Skan    case OPT_C:
300117395Skan      cpp_opts->discard_comments = 0;
301117395Skan      break;
302117395Skan
303117395Skan    case OPT_CC:
304117395Skan      cpp_opts->discard_comments = 0;
305117395Skan      cpp_opts->discard_comments_in_macro_exp = 0;
306117395Skan      break;
307117395Skan
308132718Skan    case OPT_D:
309132718Skan      defer_opt (code, arg);
310132718Skan      break;
311132718Skan
312117395Skan    case OPT_E:
313117395Skan      flag_preprocess_only = 1;
314117395Skan      break;
315117395Skan
316117395Skan    case OPT_H:
317117395Skan      cpp_opts->print_include_names = 1;
318117395Skan      break;
319117395Skan
320169699Skan    case OPT_F:
321169699Skan      TARGET_OPTF (xstrdup (arg));
322169699Skan      break;
323169699Skan
324132718Skan    case OPT_I:
325132718Skan      if (strcmp (arg, "-"))
326169699Skan	add_path (xstrdup (arg), BRACKET, 0, true);
327132718Skan      else
328132718Skan	{
329132718Skan	  if (quote_chain_split)
330132718Skan	    error ("-I- specified twice");
331132718Skan	  quote_chain_split = true;
332132718Skan	  split_quote_chain ();
333169699Skan	  inform ("obsolete option -I- used, please use -iquote instead");
334132718Skan	}
335132718Skan      break;
336132718Skan
337117395Skan    case OPT_M:
338117395Skan    case OPT_MM:
339117395Skan      /* When doing dependencies with -M or -MM, suppress normal
340117395Skan	 preprocessed output, but still do -dM etc. as software
341117395Skan	 depends on this.  Preprocessed output does occur if -MD, -MMD
342117395Skan	 or environment var dependency generation is used.  */
343117395Skan      cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
344132718Skan      flag_no_output = 1;
345117395Skan      cpp_opts->inhibit_warnings = 1;
346117395Skan      break;
347117395Skan
348117395Skan    case OPT_MD:
349117395Skan    case OPT_MMD:
350117395Skan      cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
351117395Skan      deps_file = arg;
352117395Skan      break;
353117395Skan
354117395Skan    case OPT_MF:
355117395Skan      deps_seen = true;
356117395Skan      deps_file = arg;
357117395Skan      break;
358117395Skan
359117395Skan    case OPT_MG:
360117395Skan      deps_seen = true;
361117395Skan      cpp_opts->deps.missing_files = true;
362117395Skan      break;
363117395Skan
364117395Skan    case OPT_MP:
365117395Skan      deps_seen = true;
366117395Skan      cpp_opts->deps.phony_targets = true;
367117395Skan      break;
368117395Skan
369117395Skan    case OPT_MQ:
370117395Skan    case OPT_MT:
371117395Skan      deps_seen = true;
372117395Skan      defer_opt (code, arg);
373117395Skan      break;
374117395Skan
375117395Skan    case OPT_P:
376132718Skan      flag_no_line_commands = 1;
377117395Skan      break;
378117395Skan
379132718Skan    case OPT_fworking_directory:
380132718Skan      flag_working_directory = value;
381132718Skan      break;
382132718Skan
383132718Skan    case OPT_U:
384132718Skan      defer_opt (code, arg);
385132718Skan      break;
386132718Skan
387117395Skan    case OPT_Wall:
388132718Skan      set_Wunused (value);
389132718Skan      set_Wformat (value);
390132718Skan      set_Wimplicit (value);
391132718Skan      warn_char_subscripts = value;
392132718Skan      warn_missing_braces = value;
393132718Skan      warn_parentheses = value;
394132718Skan      warn_return_type = value;
395132718Skan      warn_sequence_point = value;	/* Was C only.  */
396132718Skan      if (c_dialect_cxx ())
397132718Skan	warn_sign_compare = value;
398132718Skan      warn_switch = value;
399132718Skan      warn_strict_aliasing = value;
400169699Skan      warn_strict_overflow = value;
401169699Skan      warn_address = value;
402132718Skan
403117395Skan      /* Only warn about unknown pragmas that are not in system
404132718Skan	 headers.  */
405132718Skan      warn_unknown_pragmas = value;
406117395Skan
407117395Skan      /* We save the value of warn_uninitialized, since if they put
408117395Skan	 -Wuninitialized on the command line, we need to generate a
409117395Skan	 warning about not using it without also specifying -O.  */
410117395Skan      if (warn_uninitialized != 1)
411132718Skan	warn_uninitialized = (value ? 2 : 0);
412117395Skan
413132718Skan      if (!c_dialect_cxx ())
414117395Skan	/* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
415117395Skan	   can turn it off only if it's not explicit.  */
416132718Skan	warn_main = value * 2;
417117395Skan      else
418117395Skan	{
419117395Skan	  /* C++-specific warnings.  */
420132718Skan	  warn_reorder = value;
421132718Skan	  warn_nontemplate_friend = value;
422117395Skan	}
423117395Skan
424132718Skan      cpp_opts->warn_trigraphs = value;
425132718Skan      cpp_opts->warn_comments = value;
426132718Skan      cpp_opts->warn_num_sign_change = value;
427132718Skan      cpp_opts->warn_multichar = value;	/* Was C++ only.  */
428117395Skan
429169699Skan      if (warn_pointer_sign == -1)
430169699Skan	warn_pointer_sign = 1;
431117395Skan      break;
432117395Skan
433117395Skan    case OPT_Wcomment:
434117395Skan    case OPT_Wcomments:
435132718Skan      cpp_opts->warn_comments = value;
436117395Skan      break;
437117395Skan
438117395Skan    case OPT_Wdeprecated:
439132718Skan      cpp_opts->warn_deprecated = value;
440117395Skan      break;
441117395Skan
442117395Skan    case OPT_Wendif_labels:
443132718Skan      cpp_opts->warn_endif_labels = value;
444117395Skan      break;
445117395Skan
446117395Skan    case OPT_Werror:
447132718Skan      cpp_opts->warnings_are_errors = value;
448169699Skan      global_dc->warning_as_error_requested = value;
449117395Skan      break;
450117395Skan
451132718Skan    case OPT_Werror_implicit_function_declaration:
452132718Skan      mesg_implicit_function_declaration = 2;
453117395Skan      break;
454117395Skan
455117395Skan    case OPT_Wformat:
456132718Skan      set_Wformat (value);
457117395Skan      break;
458117395Skan
459132718Skan    case OPT_Wformat_:
460117395Skan      set_Wformat (atoi (arg));
461117395Skan      break;
462117395Skan
463117395Skan    case OPT_Wimplicit:
464132718Skan      set_Wimplicit (value);
465117395Skan      break;
466117395Skan
467117395Skan    case OPT_Wimport:
468132718Skan      /* Silently ignore for now.  */
469117395Skan      break;
470117395Skan
471132718Skan    case OPT_Winvalid_pch:
472132718Skan      cpp_opts->warn_invalid_pch = value;
473132718Skan      break;
474132718Skan
475117395Skan    case OPT_Wmain:
476132718Skan      if (value)
477117395Skan	warn_main = 1;
478117395Skan      else
479117395Skan	warn_main = -1;
480117395Skan      break;
481117395Skan
482169699Skan    case OPT_Wmissing_include_dirs:
483169699Skan      cpp_opts->warn_missing_include_dirs = value;
484117395Skan      break;
485117395Skan
486117395Skan    case OPT_Wmultichar:
487132718Skan      cpp_opts->warn_multichar = value;
488117395Skan      break;
489117395Skan
490169699Skan    case OPT_Wnormalized_:
491169699Skan      if (!value || (arg && strcasecmp (arg, "none") == 0))
492169699Skan	cpp_opts->warn_normalize = normalized_none;
493169699Skan      else if (!arg || strcasecmp (arg, "nfkc") == 0)
494169699Skan	cpp_opts->warn_normalize = normalized_KC;
495169699Skan      else if (strcasecmp (arg, "id") == 0)
496169699Skan	cpp_opts->warn_normalize = normalized_identifier_C;
497169699Skan      else if (strcasecmp (arg, "nfc") == 0)
498169699Skan	cpp_opts->warn_normalize = normalized_C;
499169699Skan      else
500169699Skan	error ("argument %qs to %<-Wnormalized%> not recognized", arg);
501117395Skan      break;
502117395Skan
503117395Skan    case OPT_Wreturn_type:
504132718Skan      warn_return_type = value;
505117395Skan      break;
506117395Skan
507169699Skan    case OPT_Wstrict_null_sentinel:
508169699Skan      warn_strict_null_sentinel = value;
509117395Skan      break;
510117395Skan
511117395Skan    case OPT_Wsystem_headers:
512132718Skan      cpp_opts->warn_system_headers = value;
513117395Skan      break;
514117395Skan
515117395Skan    case OPT_Wtraditional:
516132718Skan      cpp_opts->warn_traditional = value;
517117395Skan      break;
518117395Skan
519117395Skan    case OPT_Wtrigraphs:
520132718Skan      cpp_opts->warn_trigraphs = value;
521117395Skan      break;
522117395Skan
523117395Skan    case OPT_Wundef:
524132718Skan      cpp_opts->warn_undef = value;
525117395Skan      break;
526117395Skan
527117395Skan    case OPT_Wunknown_pragmas:
528117395Skan      /* Set to greater than 1, so that even unknown pragmas in
529132718Skan	 system headers will be warned about.  */
530132718Skan      warn_unknown_pragmas = value * 2;
531117395Skan      break;
532117395Skan
533117395Skan    case OPT_Wunused_macros:
534132718Skan      warn_unused_macros = value;
535117395Skan      break;
536117395Skan
537169699Skan    case OPT_Wvariadic_macros:
538169699Skan      warn_variadic_macros = value;
539169699Skan      break;
540169699Skan
541117395Skan    case OPT_Wwrite_strings:
542169699Skan      warn_write_strings = value;
543117395Skan      break;
544132718Skan
545169699Skan    case OPT_Weffc__:
546169699Skan      warn_ecpp = value;
547169699Skan      if (value)
548169699Skan        warn_nonvdtor = true;
549169699Skan      break;
550169699Skan
551117395Skan    case OPT_ansi:
552132718Skan      if (!c_dialect_cxx ())
553117395Skan	set_std_c89 (false, true);
554117395Skan      else
555117395Skan	set_std_cxx98 (true);
556117395Skan      break;
557117395Skan
558117395Skan    case OPT_d:
559117395Skan      handle_OPT_d (arg);
560117395Skan      break;
561117395Skan
562117395Skan    case OPT_fcond_mismatch:
563132718Skan      if (!c_dialect_cxx ())
564117395Skan	{
565132718Skan	  flag_cond_mismatch = value;
566117395Skan	  break;
567117395Skan	}
568117395Skan      /* Fall through.  */
569117395Skan
570117395Skan    case OPT_fall_virtual:
571132718Skan    case OPT_falt_external_templates:
572117395Skan    case OPT_fenum_int_equiv:
573132718Skan    case OPT_fexternal_templates:
574117395Skan    case OPT_fguiding_decls:
575117395Skan    case OPT_fhonor_std:
576117395Skan    case OPT_fhuge_objects:
577117395Skan    case OPT_flabels_ok:
578132718Skan    case OPT_fname_mangling_version_:
579117395Skan    case OPT_fnew_abi:
580117395Skan    case OPT_fnonnull_objects:
581117395Skan    case OPT_fsquangle:
582117395Skan    case OPT_fstrict_prototype:
583117395Skan    case OPT_fthis_is_variable:
584117395Skan    case OPT_fvtable_thunks:
585117395Skan    case OPT_fxref:
586132718Skan    case OPT_fvtable_gc:
587169699Skan      warning (0, "switch %qs is no longer supported", option->opt_text);
588117395Skan      break;
589117395Skan
590117395Skan    case OPT_faccess_control:
591132718Skan      flag_access_control = value;
592117395Skan      break;
593117395Skan
594117395Skan    case OPT_fasm:
595132718Skan      flag_no_asm = !value;
596117395Skan      break;
597117395Skan
598117395Skan    case OPT_fbuiltin:
599132718Skan      flag_no_builtin = !value;
600117395Skan      break;
601117395Skan
602117395Skan    case OPT_fbuiltin_:
603132718Skan      if (value)
604117395Skan	result = 0;
605117395Skan      else
606117395Skan	disable_builtin_function (arg);
607117395Skan      break;
608117395Skan
609117395Skan    case OPT_fdollars_in_identifiers:
610132718Skan      cpp_opts->dollars_in_ident = value;
611117395Skan      break;
612117395Skan
613117395Skan    case OPT_ffreestanding:
614132718Skan      value = !value;
615132718Skan      /* Fall through....  */
616117395Skan    case OPT_fhosted:
617132718Skan      flag_hosted = value;
618132718Skan      flag_no_builtin = !value;
619117395Skan      /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
620132718Skan      if (!value && warn_main == 2)
621117395Skan	warn_main = 0;
622117395Skan      break;
623117395Skan
624117395Skan    case OPT_fshort_double:
625132718Skan      flag_short_double = value;
626117395Skan      break;
627117395Skan
628117395Skan    case OPT_fshort_enums:
629132718Skan      flag_short_enums = value;
630117395Skan      break;
631117395Skan
632117395Skan    case OPT_fshort_wchar:
633132718Skan      flag_short_wchar = value;
634117395Skan      break;
635117395Skan
636117395Skan    case OPT_fsigned_bitfields:
637132718Skan      flag_signed_bitfields = value;
638117395Skan      break;
639117395Skan
640117395Skan    case OPT_fsigned_char:
641132718Skan      flag_signed_char = value;
642117395Skan      break;
643117395Skan
644117395Skan    case OPT_funsigned_bitfields:
645132718Skan      flag_signed_bitfields = !value;
646117395Skan      break;
647117395Skan
648117395Skan    case OPT_funsigned_char:
649132718Skan      flag_signed_char = !value;
650117395Skan      break;
651117395Skan
652117395Skan    case OPT_fcheck_new:
653132718Skan      flag_check_new = value;
654117395Skan      break;
655117395Skan
656117395Skan    case OPT_fconserve_space:
657132718Skan      flag_conserve_space = value;
658117395Skan      break;
659117395Skan
660132718Skan    case OPT_fconstant_string_class_:
661117395Skan      constant_string_class_name = arg;
662117395Skan      break;
663117395Skan
664117395Skan    case OPT_fdefault_inline:
665132718Skan      flag_default_inline = value;
666117395Skan      break;
667117395Skan
668117395Skan    case OPT_felide_constructors:
669132718Skan      flag_elide_constructors = value;
670117395Skan      break;
671117395Skan
672117395Skan    case OPT_fenforce_eh_specs:
673132718Skan      flag_enforce_eh_specs = value;
674117395Skan      break;
675117395Skan
676169699Skan    case OPT_fextended_identifiers:
677169699Skan      cpp_opts->extended_identifiers = value;
678117395Skan      break;
679117395Skan
680117395Skan    case OPT_ffor_scope:
681132718Skan      flag_new_for_scope = value;
682117395Skan      break;
683117395Skan
684117395Skan    case OPT_fgnu_keywords:
685132718Skan      flag_no_gnu_keywords = !value;
686117395Skan      break;
687117395Skan
688117395Skan    case OPT_fgnu_runtime:
689132718Skan      flag_next_runtime = !value;
690117395Skan      break;
691117395Skan
692117395Skan    case OPT_fhandle_exceptions:
693169699Skan      warning (0, "-fhandle-exceptions has been renamed -fexceptions (and is now on by default)");
694132718Skan      flag_exceptions = value;
695117395Skan      break;
696117395Skan
697117395Skan    case OPT_fimplement_inlines:
698132718Skan      flag_implement_inlines = value;
699117395Skan      break;
700117395Skan
701117395Skan    case OPT_fimplicit_inline_templates:
702132718Skan      flag_implicit_inline_templates = value;
703117395Skan      break;
704117395Skan
705117395Skan    case OPT_fimplicit_templates:
706132718Skan      flag_implicit_templates = value;
707117395Skan      break;
708117395Skan
709117395Skan    case OPT_fms_extensions:
710132718Skan      flag_ms_extensions = value;
711117395Skan      break;
712117395Skan
713117395Skan    case OPT_fnext_runtime:
714132718Skan      flag_next_runtime = value;
715117395Skan      break;
716117395Skan
717132718Skan    case OPT_fnil_receivers:
718132718Skan      flag_nil_receivers = value;
719132718Skan      break;
720132718Skan
721117395Skan    case OPT_fnonansi_builtins:
722132718Skan      flag_no_nonansi_builtin = !value;
723117395Skan      break;
724117395Skan
725117395Skan    case OPT_foperator_names:
726132718Skan      cpp_opts->operator_names = value;
727117395Skan      break;
728117395Skan
729117395Skan    case OPT_foptional_diags:
730132718Skan      flag_optional_diags = value;
731117395Skan      break;
732117395Skan
733132718Skan    case OPT_fpch_deps:
734132718Skan      cpp_opts->restore_pch_deps = value;
735132718Skan      break;
736132718Skan
737169699Skan    case OPT_fpch_preprocess:
738169699Skan      flag_pch_preprocess = value;
739169699Skan      break;
740169699Skan
741117395Skan    case OPT_fpermissive:
742132718Skan      flag_permissive = value;
743117395Skan      break;
744117395Skan
745117395Skan    case OPT_fpreprocessed:
746132718Skan      cpp_opts->preprocessed = value;
747117395Skan      break;
748117395Skan
749132718Skan    case OPT_freplace_objc_classes:
750132718Skan      flag_replace_objc_classes = value;
751132718Skan      break;
752169699Skan
753117395Skan    case OPT_frepo:
754132718Skan      flag_use_repository = value;
755132718Skan      if (value)
756117395Skan	flag_implicit_templates = 0;
757117395Skan      break;
758117395Skan
759117395Skan    case OPT_frtti:
760132718Skan      flag_rtti = value;
761117395Skan      break;
762117395Skan
763117395Skan    case OPT_fshow_column:
764132718Skan      cpp_opts->show_column = value;
765117395Skan      break;
766117395Skan
767117395Skan    case OPT_fstats:
768132718Skan      flag_detailed_statistics = value;
769117395Skan      break;
770117395Skan
771132718Skan    case OPT_ftabstop_:
772117395Skan      /* It is documented that we silently ignore silly values.  */
773132718Skan      if (value >= 1 && value <= 100)
774132718Skan	cpp_opts->tabstop = value;
775117395Skan      break;
776117395Skan
777132718Skan    case OPT_fexec_charset_:
778132718Skan      cpp_opts->narrow_charset = arg;
779117395Skan      break;
780117395Skan
781132718Skan    case OPT_fwide_exec_charset_:
782132718Skan      cpp_opts->wide_charset = arg;
783117395Skan      break;
784117395Skan
785132718Skan    case OPT_finput_charset_:
786132718Skan      cpp_opts->input_charset = arg;
787132718Skan      break;
788132718Skan
789132718Skan    case OPT_ftemplate_depth_:
790132718Skan      max_tinst_depth = value;
791132718Skan      break;
792132718Skan
793117395Skan    case OPT_fuse_cxa_atexit:
794132718Skan      flag_use_cxa_atexit = value;
795117395Skan      break;
796169699Skan
797169699Skan    case OPT_fuse_cxa_get_exception_ptr:
798169699Skan      flag_use_cxa_get_exception_ptr = value;
799169699Skan      break;
800117395Skan
801169699Skan    case OPT_fvisibility_inlines_hidden:
802169699Skan      visibility_options.inlines_hidden = value;
803169699Skan      break;
804169699Skan
805117395Skan    case OPT_fweak:
806132718Skan      flag_weak = value;
807117395Skan      break;
808117395Skan
809169699Skan    case OPT_fthreadsafe_statics:
810169699Skan      flag_threadsafe_statics = value;
811169699Skan      break;
812169699Skan
813132718Skan    case OPT_fzero_link:
814132718Skan      flag_zero_link = value;
815132718Skan      break;
816132718Skan
817117395Skan    case OPT_gen_decls:
818117395Skan      flag_gen_declaration = 1;
819117395Skan      break;
820117395Skan
821132718Skan    case OPT_idirafter:
822169699Skan      add_path (xstrdup (arg), AFTER, 0, true);
823132718Skan      break;
824132718Skan
825132718Skan    case OPT_imacros:
826132718Skan    case OPT_include:
827132718Skan      defer_opt (code, arg);
828132718Skan      break;
829132718Skan
830169699Skan    case OPT_imultilib:
831169699Skan      imultilib = arg;
832169699Skan      break;
833169699Skan
834132718Skan    case OPT_iprefix:
835132718Skan      iprefix = arg;
836132718Skan      break;
837132718Skan
838169699Skan    case OPT_iquote:
839169699Skan      add_path (xstrdup (arg), QUOTE, 0, true);
840169699Skan      break;
841169699Skan
842132718Skan    case OPT_isysroot:
843132718Skan      sysroot = arg;
844132718Skan      break;
845132718Skan
846132718Skan    case OPT_isystem:
847169699Skan      add_path (xstrdup (arg), SYSTEM, 0, true);
848132718Skan      break;
849132718Skan
850132718Skan    case OPT_iwithprefix:
851132718Skan      add_prefixed_path (arg, SYSTEM);
852132718Skan      break;
853132718Skan
854132718Skan    case OPT_iwithprefixbefore:
855132718Skan      add_prefixed_path (arg, BRACKET);
856132718Skan      break;
857132718Skan
858117395Skan    case OPT_lang_asm:
859117395Skan      cpp_set_lang (parse_in, CLK_ASM);
860132718Skan      cpp_opts->dollars_in_ident = false;
861117395Skan      break;
862117395Skan
863169699Skan    case OPT_lang_fortran:
864169699Skan      lang_fortran = true;
865169699Skan      break;
866169699Skan
867117395Skan    case OPT_lang_objc:
868117395Skan      cpp_opts->objc = 1;
869117395Skan      break;
870117395Skan
871117395Skan    case OPT_nostdinc:
872132718Skan      std_inc = false;
873117395Skan      break;
874117395Skan
875132718Skan    case OPT_nostdinc__:
876132718Skan      std_cxx_inc = false;
877117395Skan      break;
878117395Skan
879117395Skan    case OPT_o:
880117395Skan      if (!out_fname)
881117395Skan	out_fname = arg;
882117395Skan      else
883132718Skan	error ("output filename specified twice");
884117395Skan      break;
885117395Skan
886117395Skan      /* We need to handle the -pedantic switches here, rather than in
887117395Skan	 c_common_post_options, so that a subsequent -Wno-endif-labels
888117395Skan	 is not overridden.  */
889117395Skan    case OPT_pedantic_errors:
890117395Skan      cpp_opts->pedantic_errors = 1;
891132718Skan      /* Fall through.  */
892117395Skan    case OPT_pedantic:
893117395Skan      cpp_opts->pedantic = 1;
894117395Skan      cpp_opts->warn_endif_labels = 1;
895169699Skan      if (warn_pointer_sign == -1)
896169699Skan	warn_pointer_sign = 1;
897169699Skan      if (warn_overlength_strings == -1)
898169699Skan	warn_overlength_strings = 1;
899117395Skan      break;
900117395Skan
901117395Skan    case OPT_print_objc_runtime_info:
902117395Skan      print_struct_values = 1;
903117395Skan      break;
904117395Skan
905169699Skan    case OPT_print_pch_checksum:
906169699Skan      c_common_print_pch_checksum (stdout);
907169699Skan      exit_after_options = true;
908169699Skan      break;
909169699Skan
910117395Skan    case OPT_remap:
911117395Skan      cpp_opts->remap = 1;
912117395Skan      break;
913117395Skan
914132718Skan    case OPT_std_c__98:
915132718Skan    case OPT_std_gnu__98:
916169699Skan      if (!preprocessing_asm_p)
917169699Skan	set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
918117395Skan      break;
919117395Skan
920117395Skan    case OPT_std_c89:
921117395Skan    case OPT_std_iso9899_1990:
922117395Skan    case OPT_std_iso9899_199409:
923169699Skan      if (!preprocessing_asm_p)
924169699Skan	set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
925117395Skan      break;
926117395Skan
927117395Skan    case OPT_std_gnu89:
928169699Skan      if (!preprocessing_asm_p)
929169699Skan	set_std_c89 (false /* c94 */, false /* ISO */);
930117395Skan      break;
931117395Skan
932117395Skan    case OPT_std_c99:
933117395Skan    case OPT_std_c9x:
934117395Skan    case OPT_std_iso9899_1999:
935117395Skan    case OPT_std_iso9899_199x:
936169699Skan      if (!preprocessing_asm_p)
937169699Skan	set_std_c99 (true /* ISO */);
938117395Skan      break;
939117395Skan
940117395Skan    case OPT_std_gnu99:
941117395Skan    case OPT_std_gnu9x:
942169699Skan      if (!preprocessing_asm_p)
943169699Skan	set_std_c99 (false /* ISO */);
944117395Skan      break;
945117395Skan
946117395Skan    case OPT_trigraphs:
947117395Skan      cpp_opts->trigraphs = 1;
948117395Skan      break;
949117395Skan
950117395Skan    case OPT_traditional_cpp:
951117395Skan      cpp_opts->traditional = 1;
952117395Skan      break;
953117395Skan
954117395Skan    case OPT_undef:
955117395Skan      flag_undef = 1;
956117395Skan      break;
957117395Skan
958117395Skan    case OPT_w:
959117395Skan      cpp_opts->inhibit_warnings = 1;
960117395Skan      break;
961117395Skan
962117395Skan    case OPT_v:
963132718Skan      verbose = true;
964117395Skan      break;
965117395Skan    }
966117395Skan
967117395Skan  return result;
968117395Skan}
969117395Skan
970117395Skan/* Post-switch processing.  */
971117395Skanbool
972132718Skanc_common_post_options (const char **pfilename)
973117395Skan{
974132718Skan  struct cpp_callbacks *cb;
975132718Skan
976117395Skan  /* Canonicalize the input and output filenames.  */
977132718Skan  if (in_fnames == NULL)
978132718Skan    {
979169699Skan      in_fnames = XNEWVEC (const char *, 1);
980132718Skan      in_fnames[0] = "";
981132718Skan    }
982132718Skan  else if (strcmp (in_fnames[0], "-") == 0)
983132718Skan    in_fnames[0] = "";
984117395Skan
985117395Skan  if (out_fname == NULL || !strcmp (out_fname, "-"))
986117395Skan    out_fname = "";
987117395Skan
988117395Skan  if (cpp_opts->deps.style == DEPS_NONE)
989117395Skan    check_deps_environment_vars ();
990117395Skan
991117395Skan  handle_deferred_opts ();
992117395Skan
993117395Skan  sanitize_cpp_opts ();
994117395Skan
995169699Skan  register_include_chains (parse_in, sysroot, iprefix, imultilib,
996132718Skan			   std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
997132718Skan
998169699Skan#ifdef C_COMMON_OVERRIDE_OPTIONS
999169699Skan  /* Some machines may reject certain combinations of C
1000169699Skan     language-specific options.  */
1001169699Skan  C_COMMON_OVERRIDE_OPTIONS;
1002169699Skan#endif
1003169699Skan
1004117395Skan  flag_inline_trees = 1;
1005117395Skan
1006169699Skan  /* Use tree inlining.  */
1007169699Skan  if (!flag_no_inline)
1008169699Skan    flag_no_inline = 1;
1009169699Skan  if (flag_inline_functions)
1010169699Skan    flag_inline_trees = 2;
1011117395Skan
1012189824Sdas  /* By default we use C99 inline semantics in GNU99 or C99 mode.  C99
1013189824Sdas     inline semantics are not supported in GNU89 or C89 mode.  */
1014189824Sdas  if (flag_gnu89_inline == -1)
1015189824Sdas    flag_gnu89_inline = !flag_isoc99;
1016189824Sdas  else if (!flag_gnu89_inline && !flag_isoc99)
1017189824Sdas    error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode");
1018169699Skan
1019169699Skan  /* If we are given more than one input file, we must use
1020169699Skan     unit-at-a-time mode.  */
1021169699Skan  if (num_in_fnames > 1)
1022169699Skan    flag_unit_at_a_time = 1;
1023169699Skan
1024169699Skan  /* Default to ObjC sjlj exception handling if NeXT runtime.  */
1025169699Skan  if (flag_objc_sjlj_exceptions < 0)
1026169699Skan    flag_objc_sjlj_exceptions = flag_next_runtime;
1027169699Skan  if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
1028169699Skan    flag_exceptions = 1;
1029169699Skan
1030169699Skan  /* -Wextra implies -Wsign-compare, -Wmissing-field-initializers and
1031169699Skan     -Woverride-init, but not if explicitly overridden.  */
1032132718Skan  if (warn_sign_compare == -1)
1033132718Skan    warn_sign_compare = extra_warnings;
1034169699Skan  if (warn_missing_field_initializers == -1)
1035169699Skan    warn_missing_field_initializers = extra_warnings;
1036169699Skan  if (warn_override_init == -1)
1037169699Skan    warn_override_init = extra_warnings;
1038132718Skan
1039169699Skan  /* -Wpointer_sign is disabled by default, but it is enabled if any
1040169699Skan     of -Wall or -pedantic are given.  */
1041169699Skan  if (warn_pointer_sign == -1)
1042169699Skan    warn_pointer_sign = 0;
1043169699Skan
1044169699Skan  /* -Woverlength-strings is off by default, but is enabled by -pedantic.
1045169699Skan     It is never enabled in C++, as the minimum limit is not normative
1046169699Skan     in that standard.  */
1047169699Skan  if (warn_overlength_strings == -1 || c_dialect_cxx ())
1048169699Skan    warn_overlength_strings = 0;
1049169699Skan
1050117395Skan  /* Special format checking options don't work without -Wformat; warn if
1051117395Skan     they are used.  */
1052169699Skan  if (!warn_format)
1053169699Skan    {
1054169699Skan      warning (OPT_Wformat_y2k,
1055169699Skan	       "-Wformat-y2k ignored without -Wformat");
1056169699Skan      warning (OPT_Wformat_extra_args,
1057169699Skan	       "-Wformat-extra-args ignored without -Wformat");
1058169699Skan      warning (OPT_Wformat_zero_length,
1059169699Skan	       "-Wformat-zero-length ignored without -Wformat");
1060169699Skan      warning (OPT_Wformat_nonliteral,
1061169699Skan	       "-Wformat-nonliteral ignored without -Wformat");
1062169699Skan      warning (OPT_Wformat_security,
1063169699Skan	       "-Wformat-security ignored without -Wformat");
1064169699Skan    }
1065117395Skan
1066169699Skan  /* C99 requires special handling of complex multiplication and division;
1067169699Skan     -ffast-math and -fcx-limited-range are handled in process_options.  */
1068169699Skan  if (flag_isoc99)
1069169699Skan    flag_complex_method = 2;
1070169699Skan
1071132718Skan  if (flag_preprocess_only)
1072132718Skan    {
1073132718Skan      /* Open the output now.  We must do so even if flag_no_output is
1074132718Skan	 on, because there may be other output than from the actual
1075132718Skan	 preprocessing (e.g. from -dM).  */
1076132718Skan      if (out_fname[0] == '\0')
1077132718Skan	out_stream = stdout;
1078132718Skan      else
1079132718Skan	out_stream = fopen (out_fname, "w");
1080132718Skan
1081132718Skan      if (out_stream == NULL)
1082132718Skan	{
1083132718Skan	  fatal_error ("opening output file %s: %m", out_fname);
1084132718Skan	  return false;
1085132718Skan	}
1086132718Skan
1087132718Skan      if (num_in_fnames > 1)
1088132718Skan	error ("too many filenames given.  Type %s --help for usage",
1089132718Skan	       progname);
1090132718Skan
1091132718Skan      init_pp_output (out_stream);
1092132718Skan    }
1093132718Skan  else
1094132718Skan    {
1095132718Skan      init_c_lex ();
1096132718Skan
1097132718Skan      /* Yuk.  WTF is this?  I do know ObjC relies on it somewhere.  */
1098169699Skan      input_location = UNKNOWN_LOCATION;
1099132718Skan    }
1100132718Skan
1101132718Skan  cb = cpp_get_callbacks (parse_in);
1102132718Skan  cb->file_change = cb_file_change;
1103132718Skan  cb->dir_change = cb_dir_change;
1104132718Skan  cpp_post_options (parse_in);
1105132718Skan
1106169699Skan  input_location = UNKNOWN_LOCATION;
1107132718Skan
1108117395Skan  /* If an error has occurred in cpplib, note it so we fail
1109117395Skan     immediately.  */
1110117395Skan  errorcount += cpp_errors (parse_in);
1111117395Skan
1112132718Skan  *pfilename = this_input_filename
1113132718Skan    = cpp_read_main_file (parse_in, in_fnames[0]);
1114146908Skan  /* Don't do any compilation or preprocessing if there is no input file.  */
1115132718Skan  if (this_input_filename == NULL)
1116146908Skan    {
1117146908Skan      errorcount++;
1118146908Skan      return false;
1119146908Skan    }
1120117395Skan
1121132718Skan  if (flag_working_directory
1122169699Skan      && flag_preprocess_only && !flag_no_line_commands)
1123132718Skan    pp_dir_change (parse_in, get_src_pwd ());
1124117395Skan
1125132718Skan  return flag_preprocess_only;
1126117395Skan}
1127117395Skan
1128117395Skan/* Front end initialization common to C, ObjC and C++.  */
1129132718Skanbool
1130132718Skanc_common_init (void)
1131117395Skan{
1132117395Skan  /* Set up preprocessor arithmetic.  Must be done after call to
1133117395Skan     c_common_nodes_and_builtins for type nodes to be good.  */
1134117395Skan  cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
1135117395Skan  cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
1136117395Skan  cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
1137117395Skan  cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
1138169699Skan  cpp_opts->unsigned_wchar = TYPE_UNSIGNED (wchar_type_node);
1139132718Skan  cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;
1140117395Skan
1141132718Skan  /* This can't happen until after wchar_precision and bytes_big_endian
1142132718Skan     are known.  */
1143132718Skan  cpp_init_iconv (parse_in);
1144117395Skan
1145169699Skan  if (version_flag)
1146169699Skan    c_common_print_pch_checksum (stderr);
1147169699Skan
1148117395Skan  if (flag_preprocess_only)
1149117395Skan    {
1150132718Skan      finish_options ();
1151132718Skan      preprocess_file (parse_in);
1152132718Skan      return false;
1153117395Skan    }
1154117395Skan
1155132718Skan  /* Has to wait until now so that cpplib has its hash table.  */
1156117395Skan  init_pragma ();
1157117395Skan
1158132718Skan  return true;
1159117395Skan}
1160117395Skan
1161132718Skan/* Initialize the integrated preprocessor after debug output has been
1162132718Skan   initialized; loop over each input file.  */
1163132718Skanvoid
1164169699Skanc_common_parse_file (int set_yydebug)
1165132718Skan{
1166169699Skan  unsigned int i;
1167169699Skan
1168169699Skan  /* Enable parser debugging, if requested and we can.  If requested
1169169699Skan     and we can't, notify the user.  */
1170132718Skan#if YYDEBUG != 0
1171132718Skan  yydebug = set_yydebug;
1172132718Skan#else
1173169699Skan  if (set_yydebug)
1174169699Skan    warning (0, "YYDEBUG was not defined at build time, -dy ignored");
1175132718Skan#endif
1176132718Skan
1177169699Skan  i = 0;
1178169699Skan  for (;;)
1179132718Skan    {
1180169699Skan      /* Start the main input file, if the debug writer wants it. */
1181169699Skan      if (debug_hooks->start_end_main_source_file)
1182169699Skan	(*debug_hooks->start_source_file) (0, this_input_filename);
1183132718Skan      finish_options ();
1184169699Skan      pch_init ();
1185169699Skan      push_file_scope ();
1186132718Skan      c_parse_file ();
1187169699Skan      finish_file ();
1188169699Skan      pop_file_scope ();
1189169699Skan      /* And end the main input file, if the debug writer wants it  */
1190169699Skan      if (debug_hooks->start_end_main_source_file)
1191169699Skan	(*debug_hooks->end_source_file) (0);
1192169699Skan      if (++i >= num_in_fnames)
1193169699Skan	break;
1194169699Skan      cpp_undef_all (parse_in);
1195169699Skan      this_input_filename
1196169699Skan	= cpp_read_main_file (parse_in, in_fnames[i]);
1197169699Skan      /* If an input file is missing, abandon further compilation.
1198169699Skan	 cpplib has issued a diagnostic.  */
1199169699Skan      if (!this_input_filename)
1200169699Skan	break;
1201169699Skan    }
1202132718Skan}
1203132718Skan
1204117395Skan/* Common finish hook for the C, ObjC and C++ front ends.  */
1205117395Skanvoid
1206132718Skanc_common_finish (void)
1207117395Skan{
1208117395Skan  FILE *deps_stream = NULL;
1209117395Skan
1210117395Skan  if (cpp_opts->deps.style != DEPS_NONE)
1211117395Skan    {
1212117395Skan      /* If -M or -MM was seen without -MF, default output to the
1213117395Skan	 output stream.  */
1214117395Skan      if (!deps_file)
1215117395Skan	deps_stream = out_stream;
1216117395Skan      else
1217117395Skan	{
1218117395Skan	  deps_stream = fopen (deps_file, deps_append ? "a": "w");
1219117395Skan	  if (!deps_stream)
1220132718Skan	    fatal_error ("opening dependency file %s: %m", deps_file);
1221117395Skan	}
1222117395Skan    }
1223117395Skan
1224117395Skan  /* For performance, avoid tearing down cpplib's internal structures
1225117395Skan     with cpp_destroy ().  */
1226117395Skan  errorcount += cpp_finish (parse_in, deps_stream);
1227117395Skan
1228117395Skan  if (deps_stream && deps_stream != out_stream
1229117395Skan      && (ferror (deps_stream) || fclose (deps_stream)))
1230132718Skan    fatal_error ("closing dependency file %s: %m", deps_file);
1231117395Skan
1232117395Skan  if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1233132718Skan    fatal_error ("when writing output to %s: %m", out_fname);
1234117395Skan}
1235117395Skan
1236117395Skan/* Either of two environment variables can specify output of
1237117395Skan   dependencies.  Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
1238117395Skan   DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
1239117395Skan   and DEPS_TARGET is the target to mention in the deps.  They also
1240117395Skan   result in dependency information being appended to the output file
1241117395Skan   rather than overwriting it, and like Sun's compiler
1242117395Skan   SUNPRO_DEPENDENCIES suppresses the dependency on the main file.  */
1243117395Skanstatic void
1244132718Skancheck_deps_environment_vars (void)
1245117395Skan{
1246117395Skan  char *spec;
1247117395Skan
1248117395Skan  GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
1249117395Skan  if (spec)
1250117395Skan    cpp_opts->deps.style = DEPS_USER;
1251117395Skan  else
1252117395Skan    {
1253117395Skan      GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
1254117395Skan      if (spec)
1255117395Skan	{
1256117395Skan	  cpp_opts->deps.style = DEPS_SYSTEM;
1257117395Skan	  cpp_opts->deps.ignore_main_file = true;
1258117395Skan	}
1259117395Skan    }
1260117395Skan
1261117395Skan  if (spec)
1262117395Skan    {
1263117395Skan      /* Find the space before the DEPS_TARGET, if there is one.  */
1264117395Skan      char *s = strchr (spec, ' ');
1265117395Skan      if (s)
1266117395Skan	{
1267117395Skan	  /* Let the caller perform MAKE quoting.  */
1268117395Skan	  defer_opt (OPT_MT, s + 1);
1269117395Skan	  *s = '\0';
1270117395Skan	}
1271117395Skan
1272117395Skan      /* Command line -MF overrides environment variables and default.  */
1273117395Skan      if (!deps_file)
1274117395Skan	deps_file = spec;
1275117395Skan
1276117395Skan      deps_append = 1;
1277169699Skan      deps_seen = true;
1278117395Skan    }
1279117395Skan}
1280117395Skan
1281117395Skan/* Handle deferred command line switches.  */
1282117395Skanstatic void
1283132718Skanhandle_deferred_opts (void)
1284117395Skan{
1285117395Skan  size_t i;
1286169699Skan  struct deps *deps;
1287117395Skan
1288169699Skan  /* Avoid allocating the deps buffer if we don't need it.
1289169699Skan     (This flag may be true without there having been -MT or -MQ
1290169699Skan     options, but we'll still need the deps buffer.)  */
1291169699Skan  if (!deps_seen)
1292169699Skan    return;
1293169699Skan
1294169699Skan  deps = cpp_get_deps (parse_in);
1295169699Skan
1296117395Skan  for (i = 0; i < deferred_count; i++)
1297117395Skan    {
1298117395Skan      struct deferred_opt *opt = &deferred_opts[i];
1299117395Skan
1300132718Skan      if (opt->code == OPT_MT || opt->code == OPT_MQ)
1301169699Skan	deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
1302117395Skan    }
1303117395Skan}
1304117395Skan
1305117395Skan/* These settings are appropriate for GCC, but not necessarily so for
1306117395Skan   cpplib as a library.  */
1307117395Skanstatic void
1308132718Skansanitize_cpp_opts (void)
1309117395Skan{
1310117395Skan  /* If we don't know what style of dependencies to output, complain
1311117395Skan     if any other dependency switches have been given.  */
1312117395Skan  if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
1313117395Skan    error ("to generate dependencies you must specify either -M or -MM");
1314117395Skan
1315117395Skan  /* -dM and dependencies suppress normal output; do it here so that
1316117395Skan     the last -d[MDN] switch overrides earlier ones.  */
1317132718Skan  if (flag_dump_macros == 'M')
1318132718Skan    flag_no_output = 1;
1319117395Skan
1320117395Skan  /* Disable -dD, -dN and -dI if normal output is suppressed.  Allow
1321117395Skan     -dM since at least glibc relies on -M -dM to work.  */
1322169699Skan  /* Also, flag_no_output implies flag_no_line_commands, always.  */
1323132718Skan  if (flag_no_output)
1324117395Skan    {
1325132718Skan      if (flag_dump_macros != 'M')
1326132718Skan	flag_dump_macros = 0;
1327132718Skan      flag_dump_includes = 0;
1328146908Skan      flag_no_line_commands = 1;
1329117395Skan    }
1330117395Skan
1331117395Skan  cpp_opts->unsigned_char = !flag_signed_char;
1332117395Skan  cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
1333117395Skan
1334117395Skan  /* We want -Wno-long-long to override -pedantic -std=non-c99
1335117395Skan     and/or -Wtraditional, whatever the ordering.  */
1336117395Skan  cpp_opts->warn_long_long
1337117395Skan    = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
1338132718Skan
1339169699Skan  /* Similarly with -Wno-variadic-macros.  No check for c99 here, since
1340169699Skan     this also turns off warnings about GCCs extension.  */
1341169699Skan  cpp_opts->warn_variadic_macros
1342169699Skan    = warn_variadic_macros && (pedantic || warn_traditional);
1343169699Skan
1344132718Skan  /* If we're generating preprocessor output, emit current directory
1345132718Skan     if explicitly requested or if debugging information is enabled.
1346132718Skan     ??? Maybe we should only do it for debugging formats that
1347132718Skan     actually output the current directory?  */
1348132718Skan  if (flag_working_directory == -1)
1349132718Skan    flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
1350117395Skan}
1351117395Skan
1352132718Skan/* Add include path with a prefix at the front of its name.  */
1353132718Skanstatic void
1354132718Skanadd_prefixed_path (const char *suffix, size_t chain)
1355132718Skan{
1356132718Skan  char *path;
1357132718Skan  const char *prefix;
1358132718Skan  size_t prefix_len, suffix_len;
1359132718Skan
1360132718Skan  suffix_len = strlen (suffix);
1361132718Skan  prefix     = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
1362132718Skan  prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
1363132718Skan
1364169699Skan  path = (char *) xmalloc (prefix_len + suffix_len + 1);
1365132718Skan  memcpy (path, prefix, prefix_len);
1366132718Skan  memcpy (path + prefix_len, suffix, suffix_len);
1367132718Skan  path[prefix_len + suffix_len] = '\0';
1368132718Skan
1369169699Skan  add_path (path, chain, 0, false);
1370132718Skan}
1371132718Skan
1372132718Skan/* Handle -D, -U, -A, -imacros, and the first -include.  */
1373132718Skanstatic void
1374132718Skanfinish_options (void)
1375132718Skan{
1376132718Skan  if (!cpp_opts->preprocessed)
1377132718Skan    {
1378132718Skan      size_t i;
1379132718Skan
1380169699Skan      cb_file_change (parse_in,
1381169699Skan		      linemap_add (&line_table, LC_RENAME, 0,
1382169699Skan				   _("<built-in>"), 0));
1383169699Skan
1384132718Skan      cpp_init_builtins (parse_in, flag_hosted);
1385132718Skan      c_cpp_builtins (parse_in);
1386132718Skan
1387132718Skan      /* We're about to send user input to cpplib, so make it warn for
1388132718Skan	 things that we previously (when we sent it internal definitions)
1389132718Skan	 told it to not warn.
1390132718Skan
1391132718Skan	 C99 permits implementation-defined characters in identifiers.
1392132718Skan	 The documented meaning of -std= is to turn off extensions that
1393132718Skan	 conflict with the specified standard, and since a strictly
1394132718Skan	 conforming program cannot contain a '$', we do not condition
1395132718Skan	 their acceptance on the -std= setting.  */
1396132718Skan      cpp_opts->warn_dollars = (cpp_opts->pedantic && !cpp_opts->c99);
1397132718Skan
1398169699Skan      cb_file_change (parse_in,
1399169699Skan		      linemap_add (&line_table, LC_RENAME, 0,
1400169699Skan				   _("<command-line>"), 0));
1401169699Skan
1402132718Skan      for (i = 0; i < deferred_count; i++)
1403132718Skan	{
1404132718Skan	  struct deferred_opt *opt = &deferred_opts[i];
1405132718Skan
1406132718Skan	  if (opt->code == OPT_D)
1407132718Skan	    cpp_define (parse_in, opt->arg);
1408132718Skan	  else if (opt->code == OPT_U)
1409132718Skan	    cpp_undef (parse_in, opt->arg);
1410132718Skan	  else if (opt->code == OPT_A)
1411132718Skan	    {
1412132718Skan	      if (opt->arg[0] == '-')
1413132718Skan		cpp_unassert (parse_in, opt->arg + 1);
1414132718Skan	      else
1415132718Skan		cpp_assert (parse_in, opt->arg);
1416132718Skan	    }
1417132718Skan	}
1418132718Skan
1419132718Skan      /* Handle -imacros after -D and -U.  */
1420132718Skan      for (i = 0; i < deferred_count; i++)
1421132718Skan	{
1422132718Skan	  struct deferred_opt *opt = &deferred_opts[i];
1423132718Skan
1424132718Skan	  if (opt->code == OPT_imacros
1425132718Skan	      && cpp_push_include (parse_in, opt->arg))
1426132718Skan	    {
1427132718Skan	      /* Disable push_command_line_include callback for now.  */
1428132718Skan	      include_cursor = deferred_count + 1;
1429132718Skan	      cpp_scan_nooutput (parse_in);
1430132718Skan	    }
1431132718Skan	}
1432132718Skan    }
1433132718Skan
1434132718Skan  include_cursor = 0;
1435132718Skan  push_command_line_include ();
1436132718Skan}
1437132718Skan
1438132718Skan/* Give CPP the next file given by -include, if any.  */
1439132718Skanstatic void
1440132718Skanpush_command_line_include (void)
1441132718Skan{
1442132718Skan  while (include_cursor < deferred_count)
1443132718Skan    {
1444132718Skan      struct deferred_opt *opt = &deferred_opts[include_cursor++];
1445132718Skan
1446169699Skan      if (!cpp_opts->preprocessed && opt->code == OPT_include
1447132718Skan	  && cpp_push_include (parse_in, opt->arg))
1448132718Skan	return;
1449132718Skan    }
1450132718Skan
1451132718Skan  if (include_cursor == deferred_count)
1452132718Skan    {
1453132718Skan      include_cursor++;
1454132718Skan      /* -Wunused-macros should only warn about macros defined hereafter.  */
1455132718Skan      cpp_opts->warn_unused_macros = warn_unused_macros;
1456132718Skan      /* Restore the line map from <command line>.  */
1457169699Skan      if (!cpp_opts->preprocessed)
1458169699Skan	cpp_change_file (parse_in, LC_RENAME, this_input_filename);
1459132718Skan
1460132718Skan      /* Set this here so the client can change the option if it wishes,
1461132718Skan	 and after stacking the main file so we don't trace the main file.  */
1462169699Skan      line_table.trace_includes = cpp_opts->print_include_names;
1463132718Skan    }
1464132718Skan}
1465132718Skan
1466132718Skan/* File change callback.  Has to handle -include files.  */
1467132718Skanstatic void
1468169699Skancb_file_change (cpp_reader * ARG_UNUSED (pfile),
1469132718Skan		const struct line_map *new_map)
1470132718Skan{
1471132718Skan  if (flag_preprocess_only)
1472132718Skan    pp_file_change (new_map);
1473132718Skan  else
1474132718Skan    fe_file_change (new_map);
1475132718Skan
1476132718Skan  if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
1477132718Skan    push_command_line_include ();
1478132718Skan}
1479132718Skan
1480132718Skanvoid
1481169699Skancb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
1482132718Skan{
1483169699Skan  if (!set_src_pwd (dir))
1484169699Skan    warning (0, "too late for # directive to set debug directory");
1485132718Skan}
1486132718Skan
1487117395Skan/* Set the C 89 standard (with 1994 amendments if C94, without GNU
1488117395Skan   extensions if ISO).  There is no concept of gnu94.  */
1489117395Skanstatic void
1490132718Skanset_std_c89 (int c94, int iso)
1491117395Skan{
1492117395Skan  cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
1493117395Skan  flag_iso = iso;
1494117395Skan  flag_no_asm = iso;
1495117395Skan  flag_no_gnu_keywords = iso;
1496117395Skan  flag_no_nonansi_builtin = iso;
1497117395Skan  flag_isoc94 = c94;
1498117395Skan  flag_isoc99 = 0;
1499117395Skan}
1500117395Skan
1501117395Skan/* Set the C 99 standard (without GNU extensions if ISO).  */
1502117395Skanstatic void
1503132718Skanset_std_c99 (int iso)
1504117395Skan{
1505117395Skan  cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
1506117395Skan  flag_no_asm = iso;
1507117395Skan  flag_no_nonansi_builtin = iso;
1508117395Skan  flag_iso = iso;
1509117395Skan  flag_isoc99 = 1;
1510117395Skan  flag_isoc94 = 1;
1511117395Skan}
1512117395Skan
1513117395Skan/* Set the C++ 98 standard (without GNU extensions if ISO).  */
1514117395Skanstatic void
1515132718Skanset_std_cxx98 (int iso)
1516117395Skan{
1517117395Skan  cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
1518117395Skan  flag_no_gnu_keywords = iso;
1519117395Skan  flag_no_nonansi_builtin = iso;
1520117395Skan  flag_iso = iso;
1521117395Skan}
1522117395Skan
1523117395Skan/* Handle setting implicit to ON.  */
1524117395Skanstatic void
1525132718Skanset_Wimplicit (int on)
1526117395Skan{
1527117395Skan  warn_implicit = on;
1528117395Skan  warn_implicit_int = on;
1529117395Skan  if (on)
1530117395Skan    {
1531117395Skan      if (mesg_implicit_function_declaration != 2)
1532117395Skan	mesg_implicit_function_declaration = 1;
1533117395Skan    }
1534117395Skan  else
1535117395Skan    mesg_implicit_function_declaration = 0;
1536117395Skan}
1537117395Skan
1538117395Skan/* Args to -d specify what to dump.  Silently ignore
1539117395Skan   unrecognized options; they may be aimed at toplev.c.  */
1540117395Skanstatic void
1541132718Skanhandle_OPT_d (const char *arg)
1542117395Skan{
1543117395Skan  char c;
1544117395Skan
1545117395Skan  while ((c = *arg++) != '\0')
1546117395Skan    switch (c)
1547117395Skan      {
1548132718Skan      case 'M':			/* Dump macros only.  */
1549132718Skan      case 'N':			/* Dump names.  */
1550132718Skan      case 'D':			/* Dump definitions.  */
1551132718Skan	flag_dump_macros = c;
1552117395Skan	break;
1553117395Skan
1554117395Skan      case 'I':
1555132718Skan	flag_dump_includes = 1;
1556117395Skan	break;
1557117395Skan      }
1558117395Skan}
1559