c-opts.c 37.6 KB
Newer Older
1
/* C/ObjC/C++ command line option handling.
2
   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
   Contributed by Neil Booth.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING.  If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.  */

#include "config.h"
#include "system.h"
24 25
#include "coretypes.h"
#include "tm.h"
26 27 28 29 30 31 32 33
#include "tree.h"
#include "c-common.h"
#include "c-pragma.h"
#include "flags.h"
#include "toplev.h"
#include "langhooks.h"
#include "tree-inline.h"
#include "diagnostic.h"
34
#include "intl.h"
35 36
#include "cppdefault.h"
#include "c-incpath.h"
37
#include "debug.h"		/* For debug_hooks.  */
38
#include "opts.h"
39
#include "options.h"
40

41 42 43 44
#ifndef DOLLARS_IN_IDENTIFIERS
# define DOLLARS_IN_IDENTIFIERS true
#endif

45 46 47
#ifndef TARGET_SYSTEM_ROOT
# define TARGET_SYSTEM_ROOT NULL
#endif
48

49 50
static int saved_lineno;

51
/* CPP's options.  */
Neil Booth committed
52 53
static cpp_options *cpp_opts;

54
/* Input filename.  */
55
static const char *this_input_filename;
56

57 58 59 60 61 62 63
/* Filename and stream for preprocessed output.  */
static const char *out_fname;
static FILE *out_stream;

/* Append dependencies to deps_file.  */
static bool deps_append;

64 65 66
/* If dependency switches (-MF etc.) have been given.  */
static bool deps_seen;

67 68 69
/* If -v seen.  */
static bool verbose;

70 71 72
/* Dependency output file.  */
static const char *deps_file;

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
/* The prefix given by -iprefix, if any.  */
static const char *iprefix;

/* The system root, if any.  Overridden by -isysroot.  */
static const char *sysroot = TARGET_SYSTEM_ROOT;

/* Zero disables all standard directories for headers.  */
static bool std_inc = true;

/* Zero disables the C++-specific standard directories for headers.  */
static bool std_cxx_inc = true;

/* If the quote chain has been split by -I-.  */
static bool quote_chain_split;

88 89 90
/* If -Wunused-macros.  */
static bool warn_unused_macros;

91 92 93
/* If -Wvariadic-macros.  */
static bool warn_variadic_macros = true;

94 95
/* Number of deferred options.  */
static size_t deferred_count;
96

97 98 99
/* Number of deferred options scanned for -include.  */
static size_t include_cursor;

100 101 102
/* Permit Fotran front-end options.  */
static bool permit_fortran_options;

103 104 105 106 107 108 109 110 111 112 113
static void set_Wimplicit (int);
static void handle_OPT_d (const char *);
static void set_std_cxx98 (int);
static void set_std_c89 (int, int);
static void set_std_c99 (int);
static void check_deps_environment_vars (void);
static void handle_deferred_opts (void);
static void sanitize_cpp_opts (void);
static void add_prefixed_path (const char *, size_t);
static void push_command_line_include (void);
static void cb_file_change (cpp_reader *, const struct line_map *);
114 115
static void cb_dir_change (cpp_reader *, const char *);
static void finish_options (void);
116 117 118 119

#ifndef STDC_0_IN_SYSTEM_HEADERS
#define STDC_0_IN_SYSTEM_HEADERS 0
#endif
120

121
/* Holds switches parsed by c_common_handle_option (), but whose
122
   handling is deferred to c_common_post_options ().  */
123
static void defer_opt (enum opt_code, const char *);
124 125 126 127 128 129
static struct deferred_opt
{
  enum opt_code code;
  const char *arg;
} *deferred_opts;

130 131 132 133 134 135
/* Complain that switch CODE expects an argument but none was
   provided.  OPT was the command-line option.  Return FALSE to get
   the default message in opts.c, TRUE if we provide a specialized
   one.  */
bool
c_common_missing_argument (const char *opt, size_t code)
136
{
137
  switch (code)
138 139
    {
    default:
140 141
      /* Pick up the default message.  */
      return false;
142

143
    case OPT_fconstant_string_class_:
144
      error ("no class name specified with \"%s\"", opt);
145
      break;
146

Neil Booth committed
147
    case OPT_A:
148
      error ("assertion missing after \"%s\"", opt);
Neil Booth committed
149 150 151 152
      break;

    case OPT_D:
    case OPT_U:
153
      error ("macro name missing after \"%s\"", opt);
Neil Booth committed
154 155
      break;

156 157 158 159
    case OPT_I:
    case OPT_idirafter:
    case OPT_isysroot:
    case OPT_isystem:
160
      error ("missing path after \"%s\"", opt);
161 162
      break;

163 164 165
    case OPT_MF:
    case OPT_MD:
    case OPT_MMD:
166 167
    case OPT_include:
    case OPT_imacros:
168
    case OPT_o:
169
      error ("missing filename after \"%s\"", opt);
170 171 172 173
      break;

    case OPT_MQ:
    case OPT_MT:
174
      error ("missing makefile target after \"%s\"", opt);
175
      break;
176
    }
177 178

  return true;
179 180
}

181 182
/* Defer option CODE with argument ARG.  */
static void
183
defer_opt (enum opt_code code, const char *arg)
184 185 186 187 188 189
{
  deferred_opts[deferred_count].code = code;
  deferred_opts[deferred_count].arg = arg;
  deferred_count++;
}

190
/* Common initialization before parsing options.  */
191 192
unsigned int
c_common_init_options (unsigned int argc, const char **argv ATTRIBUTE_UNUSED)
193
{
194
  static const unsigned int lang_flags[] = {CL_C, CL_ObjC, CL_CXX, CL_ObjCXX};
195
  unsigned int result;
196 197 198 199 200 201 202 203 204 205 206 207 208 209

  /* This is conditionalized only because that is the way the front
     ends used to do it.  Maybe this should be unconditional?  */
  if (c_dialect_cxx ())
    {
      /* By default wrap lines at 80 characters.  Is getenv
	 ("COLUMNS") preferable?  */
      diagnostic_line_cutoff (global_dc) = 80;
      /* By default, emit location information once for every
	 diagnostic message.  */
      diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
    }

  parse_in = cpp_create_reader (c_dialect_cxx () ? CLK_GNUCXX: CLK_GNUC89,
210
				ident_hash, &line_table);
211

Neil Booth committed
212
  cpp_opts = cpp_get_options (parse_in);
213
  cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
214
  cpp_opts->objc = c_dialect_objc ();
215 216 217 218 219

  /* Reset to avoid warnings on internal definitions.  We set it just
     before passing on command-line options to cpplib.  */
  cpp_opts->warn_dollars = 0;

220 221 222
  flag_const_strings = c_dialect_cxx ();
  flag_exceptions = c_dialect_cxx ();
  warn_pointer_arith = c_dialect_cxx ();
223

224
  deferred_opts = xmalloc (argc * sizeof (struct deferred_opt));
225

226 227 228 229 230 231 232 233 234 235 236 237 238 239
  result = lang_flags[c_language];

  /* If potentially preprocessing Fortran we have to accept its front
     end options since the driver passes most of them through.  */
#ifdef CL_F77
  if (c_language == clk_c && argc > 2
      && !strcmp (argv[2], "-traditional-cpp" ))
    {
      permit_fortran_options = true;
      result |= CL_F77;
    }
#endif

  return result;
240 241
}

242
/* Handle switch SCODE with argument ARG.  VALUE is true, unless no-
243 244 245
   form of an -f or -W option was given.  Returns 0 if the switch was
   invalid, a negative number to prevent language-independent
   processing in toplev.c (a hack necessary for the short-term).  */
246
int
247
c_common_handle_option (size_t scode, const char *arg, int value)
248
{
249 250
  const struct cl_option *option = &cl_options[scode];
  enum opt_code code = (enum opt_code) scode;
251
  int result = 1;
252

253
  switch (code)
254
    {
255
    default:
256 257
      result = permit_fortran_options;
      break;
258

259
    case OPT__output_pch_:
260 261 262
      pch_file = arg;
      break;

Neil Booth committed
263 264 265 266
    case OPT_A:
      defer_opt (code, arg);
      break;

267 268 269 270 271 272 273 274 275
    case OPT_C:
      cpp_opts->discard_comments = 0;
      break;

    case OPT_CC:
      cpp_opts->discard_comments = 0;
      cpp_opts->discard_comments_in_macro_exp = 0;
      break;

Neil Booth committed
276 277 278 279
    case OPT_D:
      defer_opt (code, arg);
      break;

280 281 282 283
    case OPT_E:
      flag_preprocess_only = 1;
      break;

284 285 286 287
    case OPT_H:
      cpp_opts->print_include_names = 1;
      break;

288 289 290 291 292 293 294 295 296 297 298 299
    case OPT_I:
      if (strcmp (arg, "-"))
	add_path (xstrdup (arg), BRACKET, 0);
      else
	{
	  if (quote_chain_split)
	    error ("-I- specified twice");
	  quote_chain_split = true;
	  split_quote_chain ();
	}
      break;

300 301 302 303 304 305 306
    case OPT_M:
    case OPT_MM:
      /* When doing dependencies with -M or -MM, suppress normal
	 preprocessed output, but still do -dM etc. as software
	 depends on this.  Preprocessed output does occur if -MD, -MMD
	 or environment var dependency generation is used.  */
      cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
Neil Booth committed
307
      flag_no_output = 1;
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
      cpp_opts->inhibit_warnings = 1;
      break;

    case OPT_MD:
    case OPT_MMD:
      cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
      deps_file = arg;
      break;

    case OPT_MF:
      deps_seen = true;
      deps_file = arg;
      break;

    case OPT_MG:
      deps_seen = true;
      cpp_opts->deps.missing_files = true;
      break;

    case OPT_MP:
      deps_seen = true;
      cpp_opts->deps.phony_targets = true;
      break;

    case OPT_MQ:
    case OPT_MT:
      deps_seen = true;
      defer_opt (code, arg);
      break;

338
    case OPT_P:
Neil Booth committed
339
      flag_no_line_commands = 1;
340 341
      break;

342 343 344 345
    case OPT_fworking_directory:
      flag_working_directory = value;
      break;

Neil Booth committed
346 347 348 349
    case OPT_U:
      defer_opt (code, arg);
      break;

350
    case OPT_Wabi:
351
      warn_abi = value;
352 353
      break;

354
    case OPT_Wall:
355 356 357 358 359 360 361 362
      set_Wunused (value);
      set_Wformat (value);
      set_Wimplicit (value);
      warn_char_subscripts = value;
      warn_missing_braces = value;
      warn_parentheses = value;
      warn_return_type = value;
      warn_sequence_point = value;	/* Was C only.  */
363
      if (c_dialect_cxx ())
364 365 366
	warn_sign_compare = value;
      warn_switch = value;
      warn_strict_aliasing = value;
367

368
      /* Only warn about unknown pragmas that are not in system
369
	 headers.  */
370
      warn_unknown_pragmas = value;
371 372 373 374 375

      /* We save the value of warn_uninitialized, since if they put
	 -Wuninitialized on the command line, we need to generate a
	 warning about not using it without also specifying -O.  */
      if (warn_uninitialized != 1)
376
	warn_uninitialized = (value ? 2 : 0);
377

378
      if (!c_dialect_cxx ())
379 380
	/* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
	   can turn it off only if it's not explicit.  */
381
	warn_main = value * 2;
382 383 384
      else
	{
	  /* C++-specific warnings.  */
385 386 387
	  warn_nonvdtor = value;
	  warn_reorder = value;
	  warn_nontemplate_friend = value;
388
	}
Neil Booth committed
389

390 391 392 393
      cpp_opts->warn_trigraphs = value;
      cpp_opts->warn_comments = value;
      cpp_opts->warn_num_sign_change = value;
      cpp_opts->warn_multichar = value;	/* Was C++ only.  */
394 395 396
      break;

    case OPT_Wbad_function_cast:
397
      warn_bad_function_cast = value;
398 399 400
      break;

    case OPT_Wcast_qual:
401
      warn_cast_qual = value;
402 403 404
      break;

    case OPT_Wchar_subscripts:
405
      warn_char_subscripts = value;
406 407
      break;

Neil Booth committed
408 409
    case OPT_Wcomment:
    case OPT_Wcomments:
410
      cpp_opts->warn_comments = value;
Neil Booth committed
411 412
      break;

413
    case OPT_Wconversion:
414
      warn_conversion = value;
415 416 417
      break;

    case OPT_Wctor_dtor_privacy:
418
      warn_ctor_dtor_privacy = value;
419 420
      break;

421 422 423 424
    case OPT_Wdeclaration_after_statement:
      warn_declaration_after_statement = value;
      break;

425
    case OPT_Wdeprecated:
426 427
      warn_deprecated = value;
      cpp_opts->warn_deprecated = value;
428 429 430
      break;

    case OPT_Wdiv_by_zero:
431
      warn_div_by_zero = value;
432 433
      break;

434
    case OPT_Weffc__:
435
      warn_ecpp = value;
436 437
      break;

Neil Booth committed
438
    case OPT_Wendif_labels:
439
      cpp_opts->warn_endif_labels = value;
Neil Booth committed
440 441 442
      break;

    case OPT_Werror:
443
      cpp_opts->warnings_are_errors = value;
Neil Booth committed
444 445
      break;

446
    case OPT_Werror_implicit_function_declaration:
447
      mesg_implicit_function_declaration = 2;
448 449 450
      break;

    case OPT_Wfloat_equal:
451
      warn_float_equal = value;
452 453 454
      break;

    case OPT_Wformat:
455
      set_Wformat (value);
456 457
      break;

458
    case OPT_Wformat_:
459 460 461 462
      set_Wformat (atoi (arg));
      break;

    case OPT_Wformat_extra_args:
463
      warn_format_extra_args = value;
464 465 466
      break;

    case OPT_Wformat_nonliteral:
467
      warn_format_nonliteral = value;
468 469 470
      break;

    case OPT_Wformat_security:
471
      warn_format_security = value;
472 473 474
      break;

    case OPT_Wformat_y2k:
475
      warn_format_y2k = value;
476 477 478
      break;

    case OPT_Wformat_zero_length:
479
      warn_format_zero_length = value;
480 481
      break;

Andrew Pinski committed
482 483 484 485
    case OPT_Winit_self:
      warn_init_self = value;
      break;

486
    case OPT_Wimplicit:
487
      set_Wimplicit (value);
488 489
      break;

490
    case OPT_Wimplicit_function_declaration:
491
      mesg_implicit_function_declaration = value;
492 493 494
      break;

    case OPT_Wimplicit_int:
495
      warn_implicit_int = value;
496 497
      break;

Neil Booth committed
498
    case OPT_Wimport:
499
      /* Silently ignore for now.  */
Neil Booth committed
500 501
      break;

Matt Austern committed
502
    case OPT_Winvalid_offsetof:
503
      warn_invalid_offsetof = value;
Matt Austern committed
504 505
      break;

506
    case OPT_Winvalid_pch:
507
      cpp_opts->warn_invalid_pch = value;
508 509
      break;

510
    case OPT_Wlong_long:
511
      warn_long_long = value;
512 513 514
      break;

    case OPT_Wmain:
515
      if (value)
516 517 518 519 520 521
	warn_main = 1;
      else
	warn_main = -1;
      break;

    case OPT_Wmissing_braces:
522
      warn_missing_braces = value;
523 524 525
      break;

    case OPT_Wmissing_declarations:
526
      warn_missing_declarations = value;
527 528 529
      break;

    case OPT_Wmissing_format_attribute:
530
      warn_missing_format_attribute = value;
531 532 533
      break;

    case OPT_Wmissing_prototypes:
534
      warn_missing_prototypes = value;
535 536 537
      break;

    case OPT_Wmultichar:
538
      cpp_opts->warn_multichar = value;
539 540 541
      break;

    case OPT_Wnested_externs:
542
      warn_nested_externs = value;
543 544 545
      break;

    case OPT_Wnon_template_friend:
546
      warn_nontemplate_friend = value;
547 548 549
      break;

    case OPT_Wnon_virtual_dtor:
550
      warn_nonvdtor = value;
551 552 553
      break;

    case OPT_Wnonnull:
554
      warn_nonnull = value;
555 556
      break;

557 558 559 560
    case OPT_Wold_style_definition:
      warn_old_style_definition = value;
      break;

561
    case OPT_Wold_style_cast:
562
      warn_old_style_cast = value;
563 564 565
      break;

    case OPT_Woverloaded_virtual:
566
      warn_overloaded_virtual = value;
567 568 569
      break;

    case OPT_Wparentheses:
570
      warn_parentheses = value;
571 572 573
      break;

    case OPT_Wpmf_conversions:
574
      warn_pmf2ptr = value;
575 576 577
      break;

    case OPT_Wpointer_arith:
578
      warn_pointer_arith = value;
579 580 581
      break;

    case OPT_Wprotocol:
582
      warn_protocol = value;
583 584 585
      break;

    case OPT_Wselector:
586
      warn_selector = value;
587 588 589
      break;

    case OPT_Wredundant_decls:
590
      warn_redundant_decls = value;
591 592 593
      break;

    case OPT_Wreorder:
594
      warn_reorder = value;
595 596 597
      break;

    case OPT_Wreturn_type:
598
      warn_return_type = value;
599 600 601
      break;

    case OPT_Wsequence_point:
602
      warn_sequence_point = value;
603 604 605
      break;

    case OPT_Wsign_compare:
606
      warn_sign_compare = value;
607 608 609
      break;

    case OPT_Wsign_promo:
610
      warn_sign_promo = value;
611 612 613
      break;

    case OPT_Wstrict_prototypes:
614
      warn_strict_prototypes = value;
615 616 617
      break;

    case OPT_Wsynth:
618
      warn_synth = value;
619 620
      break;

Neil Booth committed
621
    case OPT_Wsystem_headers:
622
      cpp_opts->warn_system_headers = value;
Neil Booth committed
623 624
      break;

625
    case OPT_Wtraditional:
626 627
      warn_traditional = value;
      cpp_opts->warn_traditional = value;
Neil Booth committed
628 629 630
      break;

    case OPT_Wtrigraphs:
631
      cpp_opts->warn_trigraphs = value;
Neil Booth committed
632 633
      break;

634
    case OPT_Wundeclared_selector:
635
      warn_undeclared_selector = value;
636 637
      break;

Neil Booth committed
638
    case OPT_Wundef:
639
      cpp_opts->warn_undef = value;
640 641 642 643
      break;

    case OPT_Wunknown_pragmas:
      /* Set to greater than 1, so that even unknown pragmas in
644
	 system headers will be warned about.  */
645
      warn_unknown_pragmas = value * 2;
646 647
      break;

Neil Booth committed
648
    case OPT_Wunused_macros:
649
      warn_unused_macros = value;
Neil Booth committed
650 651
      break;

652 653 654 655
    case OPT_Wvariadic_macros:
      warn_variadic_macros = value;
      break;

656
    case OPT_Wwrite_strings:
657
      if (!c_dialect_cxx ())
658
	flag_const_strings = value;
659
      else
660
	warn_write_strings = value;
661
      break;
662

663
    case OPT_ansi:
664
      if (!c_dialect_cxx ())
665 666 667 668
	set_std_c89 (false, true);
      else
	set_std_cxx98 (true);
      break;
669

670 671 672 673
    case OPT_d:
      handle_OPT_d (arg);
      break;

674
    case OPT_fcond_mismatch:
675
      if (!c_dialect_cxx ())
676
	{
677
	  flag_cond_mismatch = value;
678 679 680 681 682
	  break;
	}
      /* Fall through.  */

    case OPT_fall_virtual:
683
    case OPT_falt_external_templates:
684
    case OPT_fenum_int_equiv:
685
    case OPT_fexternal_templates:
686 687 688 689
    case OPT_fguiding_decls:
    case OPT_fhonor_std:
    case OPT_fhuge_objects:
    case OPT_flabels_ok:
690
    case OPT_fname_mangling_version_:
691 692 693 694 695 696 697
    case OPT_fnew_abi:
    case OPT_fnonnull_objects:
    case OPT_fsquangle:
    case OPT_fstrict_prototype:
    case OPT_fthis_is_variable:
    case OPT_fvtable_thunks:
    case OPT_fxref:
698
    case OPT_fvtable_gc:
Neil Booth committed
699
      warning ("switch \"%s\" is no longer supported", option->opt_text);
700 701 702
      break;

    case OPT_faccess_control:
703
      flag_access_control = value;
704 705 706
      break;

    case OPT_fasm:
707
      flag_no_asm = !value;
708 709 710
      break;

    case OPT_fbuiltin:
711
      flag_no_builtin = !value;
712 713 714
      break;

    case OPT_fbuiltin_:
715
      if (value)
716 717 718
	result = 0;
      else
	disable_builtin_function (arg);
719 720 721
      break;

    case OPT_fdollars_in_identifiers:
722
      cpp_opts->dollars_in_ident = value;
723 724
      break;

725
    case OPT_fdump_:
726
      if (!dump_switch_p (arg))
727
	result = 0;
728 729 730
      break;

    case OPT_ffreestanding:
731
      value = !value;
732
      /* Fall through....  */
733
    case OPT_fhosted:
734 735
      flag_hosted = value;
      flag_no_builtin = !value;
736
      /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
737
      if (!value && warn_main == 2)
738 739 740 741
	warn_main = 0;
      break;

    case OPT_fshort_double:
742
      flag_short_double = value;
743 744 745
      break;

    case OPT_fshort_enums:
746
      flag_short_enums = value;
747 748 749
      break;

    case OPT_fshort_wchar:
750
      flag_short_wchar = value;
751 752 753
      break;

    case OPT_fsigned_bitfields:
754
      flag_signed_bitfields = value;
755 756 757 758
      explicit_flag_signed_bitfields = 1;
      break;

    case OPT_fsigned_char:
759
      flag_signed_char = value;
760 761 762
      break;

    case OPT_funsigned_bitfields:
763
      flag_signed_bitfields = !value;
764 765 766 767
      explicit_flag_signed_bitfields = 1;
      break;

    case OPT_funsigned_char:
768
      flag_signed_char = !value;
769 770 771
      break;

    case OPT_fcheck_new:
772
      flag_check_new = value;
773 774 775
      break;

    case OPT_fconserve_space:
776
      flag_conserve_space = value;
777 778 779
      break;

    case OPT_fconst_strings:
780
      flag_const_strings = value;
781 782
      break;

783
    case OPT_fconstant_string_class_:
784
      constant_string_class_name = arg;
785 786 787
      break;

    case OPT_fdefault_inline:
788
      flag_default_inline = value;
789 790 791
      break;

    case OPT_felide_constructors:
792
      flag_elide_constructors = value;
793 794 795
      break;

    case OPT_fenforce_eh_specs:
796
      flag_enforce_eh_specs = value;
797 798
      break;

799
    case OPT_ffixed_form:
800
    case OPT_ffixed_line_length_:
801
      /* Fortran front end options ignored when preprocessing only.  */
Neil Booth committed
802 803
      if (!flag_preprocess_only)
        result = 0;
804 805
      break;

806
    case OPT_ffor_scope:
807
      flag_new_for_scope = value;
808 809 810
      break;

    case OPT_fgnu_keywords:
811
      flag_no_gnu_keywords = !value;
812 813 814
      break;

    case OPT_fgnu_runtime:
815
      flag_next_runtime = !value;
816 817 818
      break;

    case OPT_fhandle_exceptions:
819
      warning ("-fhandle-exceptions has been renamed -fexceptions (and is now on by default)");
820
      flag_exceptions = value;
821 822 823
      break;

    case OPT_fimplement_inlines:
824
      flag_implement_inlines = value;
825 826 827
      break;

    case OPT_fimplicit_inline_templates:
828
      flag_implicit_inline_templates = value;
829 830 831
      break;

    case OPT_fimplicit_templates:
832
      flag_implicit_templates = value;
833 834 835
      break;

    case OPT_fms_extensions:
836
      flag_ms_extensions = value;
837 838 839
      break;

    case OPT_fnext_runtime:
840
      flag_next_runtime = value;
841 842
      break;

843 844 845 846
    case OPT_fnil_receivers:
      flag_nil_receivers = value;
      break;

847
    case OPT_fnonansi_builtins:
848
      flag_no_nonansi_builtin = !value;
849 850
      break;

851 852 853 854
    case OPT_fobjc_exceptions:
      flag_objc_exceptions = value;
      break;

Neil Booth committed
855
    case OPT_foperator_names:
856
      cpp_opts->operator_names = value;
Neil Booth committed
857 858
      break;

859
    case OPT_foptional_diags:
860
      flag_optional_diags = value;
861 862
      break;

863
    case OPT_fpch_deps:
864
      cpp_opts->restore_pch_deps = value;
865 866
      break;

867
    case OPT_fpermissive:
868
      flag_permissive = value;
869 870
      break;

Neil Booth committed
871
    case OPT_fpreprocessed:
872
      cpp_opts->preprocessed = value;
Neil Booth committed
873 874
      break;

875 876 877 878
    case OPT_freplace_objc_classes:
      flag_replace_objc_classes = value;
      break;
      
879
    case OPT_frepo:
880 881
      flag_use_repository = value;
      if (value)
882 883 884 885
	flag_implicit_templates = 0;
      break;

    case OPT_frtti:
886
      flag_rtti = value;
887 888
      break;

Neil Booth committed
889
    case OPT_fshow_column:
890
      cpp_opts->show_column = value;
Neil Booth committed
891 892
      break;

893
    case OPT_fstats:
894
      flag_detailed_statistics = value;
895 896
      break;

897
    case OPT_ftabstop_:
Neil Booth committed
898
      /* It is documented that we silently ignore silly values.  */
899 900
      if (value >= 1 && value <= 100)
	cpp_opts->tabstop = value;
Neil Booth committed
901 902
      break;

903 904 905 906 907 908 909 910
    case OPT_fexec_charset_:
      cpp_opts->narrow_charset = arg;
      break;

    case OPT_fwide_exec_charset_:
      cpp_opts->wide_charset = arg;
      break;

Eric Christopher committed
911 912 913 914
    case OPT_finput_charset_:
      cpp_opts->input_charset = arg;
      break;

915
    case OPT_ftemplate_depth_:
916
      max_tinst_depth = value;
917 918 919
      break;

    case OPT_fuse_cxa_atexit:
920
      flag_use_cxa_atexit = value;
921 922 923
      break;

    case OPT_fweak:
924
      flag_weak = value;
925
      break;
926 927 928 929

    case OPT_fzero_link:
      flag_zero_link = value;
      break;
930 931 932 933 934

    case OPT_gen_decls:
      flag_gen_declaration = 1;
      break;

935 936 937 938
    case OPT_idirafter:
      add_path (xstrdup (arg), AFTER, 0);
      break;

939
    case OPT_imacros:
940 941 942 943
    case OPT_include:
      defer_opt (code, arg);
      break;

944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
    case OPT_iprefix:
      iprefix = arg;
      break;

    case OPT_isysroot:
      sysroot = arg;
      break;

    case OPT_isystem:
      add_path (xstrdup (arg), SYSTEM, 0);
      break;

    case OPT_iwithprefix:
      add_prefixed_path (arg, SYSTEM);
      break;

    case OPT_iwithprefixbefore:
      add_prefixed_path (arg, BRACKET);
      break;

964 965
    case OPT_lang_asm:
      cpp_set_lang (parse_in, CLK_ASM);
966
      cpp_opts->dollars_in_ident = false;
967 968 969 970 971 972
      break;

    case OPT_lang_objc:
      cpp_opts->objc = 1;
      break;

973
    case OPT_nostdinc:
974
      std_inc = false;
975 976
      break;

977
    case OPT_nostdinc__:
978
      std_cxx_inc = false;
979 980
      break;

981
    case OPT_o:
982 983
      if (!out_fname)
	out_fname = arg;
984
      else
985
	error ("output filename specified twice");
986 987
      break;

Neil Booth committed
988 989 990 991 992
      /* We need to handle the -pedantic switches here, rather than in
	 c_common_post_options, so that a subsequent -Wno-endif-labels
	 is not overridden.  */
    case OPT_pedantic_errors:
      cpp_opts->pedantic_errors = 1;
993
      /* Fall through.  */
Neil Booth committed
994 995 996 997 998
    case OPT_pedantic:
      cpp_opts->pedantic = 1;
      cpp_opts->warn_endif_labels = 1;
      break;

999 1000 1001 1002
    case OPT_print_objc_runtime_info:
      print_struct_values = 1;
      break;

1003 1004
    case OPT_remap:
      cpp_opts->remap = 1;
1005 1006
      break;

1007 1008 1009
    case OPT_std_c__98:
    case OPT_std_gnu__98:
      set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
1010 1011 1012 1013
      break;

    case OPT_std_c89:
    case OPT_std_iso9899_1990:
1014 1015
    case OPT_std_iso9899_199409:
      set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
1016 1017 1018 1019
      break;

    case OPT_std_gnu89:
      set_std_c89 (false /* c94 */, false /* ISO */);
1020 1021 1022 1023 1024 1025
      break;

    case OPT_std_c99:
    case OPT_std_c9x:
    case OPT_std_iso9899_1999:
    case OPT_std_iso9899_199x:
1026
      set_std_c99 (true /* ISO */);
1027 1028 1029 1030
      break;

    case OPT_std_gnu99:
    case OPT_std_gnu9x:
1031
      set_std_c99 (false /* ISO */);
1032 1033
      break;

1034 1035 1036 1037 1038 1039 1040 1041
    case OPT_trigraphs:
      cpp_opts->trigraphs = 1;
      break;

    case OPT_traditional_cpp:
      cpp_opts->traditional = 1;
      break;

1042 1043 1044 1045
    case OPT_undef:
      flag_undef = 1;
      break;

1046 1047 1048 1049 1050
    case OPT_w:
      cpp_opts->inhibit_warnings = 1;
      break;

    case OPT_v:
1051
      verbose = true;
1052 1053
      break;
    }
1054 1055 1056 1057 1058 1059

  return result;
}

/* Post-switch processing.  */
bool
1060
c_common_post_options (const char **pfilename)
1061
{
1062 1063
  struct cpp_callbacks *cb;

1064
  /* Canonicalize the input and output filenames.  */
Geoffrey Keating committed
1065 1066 1067 1068 1069 1070 1071
  if (in_fnames == NULL)
    {
      in_fnames = xmalloc (sizeof (in_fnames[0]));
      in_fnames[0] = "";
    }
  else if (strcmp (in_fnames[0], "-") == 0)
    in_fnames[0] = "";
1072

1073 1074 1075
  if (out_fname == NULL || !strcmp (out_fname, "-"))
    out_fname = "";

1076
  if (cpp_opts->deps.style == DEPS_NONE)
1077 1078
    check_deps_environment_vars ();

1079
  handle_deferred_opts ();
1080

1081
  sanitize_cpp_opts ();
1082

1083
  register_include_chains (parse_in, sysroot, iprefix,
1084
			   std_inc, std_cxx_inc && c_dialect_cxx (), verbose);
1085

1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
  flag_inline_trees = 1;

  /* Use tree inlining if possible.  Function instrumentation is only
     done in the RTL level, so we disable tree inlining.  */
  if (! flag_instrument_function_entry_exit)
    {
      if (!flag_no_inline)
	flag_no_inline = 1;
      if (flag_inline_functions)
	{
	  flag_inline_trees = 2;
	  flag_inline_functions = 0;
	}
    }

1101 1102 1103 1104 1105
  /* -Wextra implies -Wsign-compare, but not if explicitly
      overridden.  */
  if (warn_sign_compare == -1)
    warn_sign_compare = extra_warnings;

1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
  /* Special format checking options don't work without -Wformat; warn if
     they are used.  */
  if (warn_format_y2k && !warn_format)
    warning ("-Wformat-y2k ignored without -Wformat");
  if (warn_format_extra_args && !warn_format)
    warning ("-Wformat-extra-args ignored without -Wformat");
  if (warn_format_zero_length && !warn_format)
    warning ("-Wformat-zero-length ignored without -Wformat");
  if (warn_format_nonliteral && !warn_format)
    warning ("-Wformat-nonliteral ignored without -Wformat");
  if (warn_format_security && !warn_format)
    warning ("-Wformat-security ignored without -Wformat");
  if (warn_missing_format_attribute && !warn_format)
    warning ("-Wmissing-format-attribute ignored without -Wformat");

1121 1122
  if (flag_preprocess_only)
    {
Neil Booth committed
1123 1124 1125 1126 1127 1128 1129 1130 1131
      /* Open the output now.  We must do so even if flag_no_output is
	 on, because there may be other output than from the actual
	 preprocessing (e.g. from -dM).  */
      if (out_fname[0] == '\0')
	out_stream = stdout;
      else
	out_stream = fopen (out_fname, "w");

      if (out_stream == NULL)
1132
	{
1133
	  fatal_error ("opening output file %s: %m", out_fname);
1134
	  return false;
1135
	}
Neil Booth committed
1136

Geoffrey Keating committed
1137 1138 1139 1140
      if (num_in_fnames > 1)
	error ("too many filenames given.  Type %s --help for usage",
	       progname);

1141
      init_pp_output (out_stream);
1142
    }
1143 1144 1145
  else
    {
      init_c_lex ();
1146

1147
      /* Yuk.  WTF is this?  I do know ObjC relies on it somewhere.  */
1148
      input_line = 0;
1149
    }
Neil Booth committed
1150

1151 1152 1153
  cb = cpp_get_callbacks (parse_in);
  cb->file_change = cb_file_change;
  cb->dir_change = cb_dir_change;
1154
  cpp_post_options (parse_in);
1155

1156 1157
  saved_lineno = input_line;
  input_line = 0;
1158 1159 1160 1161 1162

  /* If an error has occurred in cpplib, note it so we fail
     immediately.  */
  errorcount += cpp_errors (parse_in);

1163 1164 1165 1166 1167
  *pfilename = this_input_filename
    = cpp_read_main_file (parse_in, in_fnames[0]);
  if (this_input_filename == NULL)
    return true;

1168 1169
  if (flag_working_directory
      && flag_preprocess_only && ! flag_no_line_commands)
1170 1171
    pp_dir_change (parse_in, get_src_pwd ());

1172 1173 1174 1175 1176
  return flag_preprocess_only;
}

/* Front end initialization common to C, ObjC and C++.  */
bool
1177
c_common_init (void)
1178
{
1179
  input_line = saved_lineno;
1180 1181 1182 1183 1184 1185 1186 1187

  /* Set up preprocessor arithmetic.  Must be done after call to
     c_common_nodes_and_builtins for type nodes to be good.  */
  cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
  cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
  cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
  cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
  cpp_opts->unsigned_wchar = TREE_UNSIGNED (wchar_type_node);
1188 1189 1190 1191 1192
  cpp_opts->bytes_big_endian = BYTES_BIG_ENDIAN;

  /* This can't happen until after wchar_precision and bytes_big_endian
     are known.  */
  cpp_init_iconv (parse_in);
1193

1194 1195
  if (flag_preprocess_only)
    {
1196 1197
      finish_options ();
      preprocess_file (parse_in);
1198
      return false;
1199 1200
    }

Neil Booth committed
1201
  /* Has to wait until now so that cpplib has its hash table.  */
1202 1203
  init_pragma ();

1204
  return true;
1205 1206
}

Geoffrey Keating committed
1207 1208
/* Initialize the integrated preprocessor after debug output has been
   initialized; loop over each input file.  */
1209
void
1210
c_common_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
1211
{
Geoffrey Keating committed
1212 1213
  unsigned file_index;
  
1214 1215 1216 1217 1218 1219
#if YYDEBUG != 0
  yydebug = set_yydebug;
#else
  warning ("YYDEBUG not defined");
#endif

Geoffrey Keating committed
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
  file_index = 0;
  
  do
    {
      if (file_index > 0)
	{
	  /* Reset the state of the parser.  */
	  c_reset_state();

	  /* Reset cpplib's macros and start a new file.  */
	  cpp_undef_all (parse_in);
1231 1232 1233 1234
	  main_input_filename = this_input_filename
	    = cpp_read_main_file (parse_in, in_fnames[file_index]);
	  if (this_input_filename == NULL)
	    break;
Geoffrey Keating committed
1235
	}
1236
      finish_options ();
Geoffrey Keating committed
1237 1238 1239 1240 1241 1242 1243 1244
      if (file_index == 0)
	pch_init();
      c_parse_file ();

      file_index++;
    } while (file_index < num_in_fnames);
  
  finish_file ();
1245 1246
}

1247 1248
/* Common finish hook for the C, ObjC and C++ front ends.  */
void
1249
c_common_finish (void)
1250 1251 1252
{
  FILE *deps_stream = NULL;

1253
  if (cpp_opts->deps.style != DEPS_NONE)
1254 1255 1256
    {
      /* If -M or -MM was seen without -MF, default output to the
	 output stream.  */
1257
      if (!deps_file)
1258 1259 1260
	deps_stream = out_stream;
      else
	{
1261
	  deps_stream = fopen (deps_file, deps_append ? "a": "w");
1262
	  if (!deps_stream)
1263
	    fatal_error ("opening dependency file %s: %m", deps_file);
1264 1265 1266 1267 1268 1269 1270 1271 1272
	}
    }

  /* For performance, avoid tearing down cpplib's internal structures
     with cpp_destroy ().  */
  errorcount += cpp_finish (parse_in, deps_stream);

  if (deps_stream && deps_stream != out_stream
      && (ferror (deps_stream) || fclose (deps_stream)))
1273
    fatal_error ("closing dependency file %s: %m", deps_file);
1274 1275

  if (out_stream && (ferror (out_stream) || fclose (out_stream)))
1276
    fatal_error ("when writing output to %s: %m", out_fname);
1277 1278 1279 1280 1281 1282 1283
}

/* Either of two environment variables can specify output of
   dependencies.  Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
   DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
   and DEPS_TARGET is the target to mention in the deps.  They also
   result in dependency information being appended to the output file
1284 1285
   rather than overwriting it, and like Sun's compiler
   SUNPRO_DEPENDENCIES suppresses the dependency on the main file.  */
1286
static void
1287
check_deps_environment_vars (void)
1288 1289 1290 1291 1292
{
  char *spec;

  GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
  if (spec)
1293
    cpp_opts->deps.style = DEPS_USER;
1294 1295 1296 1297
  else
    {
      GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
      if (spec)
1298 1299 1300 1301
	{
	  cpp_opts->deps.style = DEPS_SYSTEM;
	  cpp_opts->deps.ignore_main_file = true;
	}
1302 1303 1304 1305 1306 1307 1308 1309 1310
    }

  if (spec)
    {
      /* Find the space before the DEPS_TARGET, if there is one.  */
      char *s = strchr (spec, ' ');
      if (s)
	{
	  /* Let the caller perform MAKE quoting.  */
1311
	  defer_opt (OPT_MT, s + 1);
1312 1313 1314 1315
	  *s = '\0';
	}

      /* Command line -MF overrides environment variables and default.  */
1316 1317
      if (!deps_file)
	deps_file = spec;
1318

1319 1320 1321 1322 1323 1324
      deps_append = 1;
    }
}

/* Handle deferred command line switches.  */
static void
1325
handle_deferred_opts (void)
1326 1327 1328 1329 1330 1331 1332
{
  size_t i;

  for (i = 0; i < deferred_count; i++)
    {
      struct deferred_opt *opt = &deferred_opts[i];

Neil Booth committed
1333 1334
      if (opt->code == OPT_MT || opt->code == OPT_MQ)
	cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
1335 1336 1337 1338 1339 1340
    }
}

/* These settings are appropriate for GCC, but not necessarily so for
   cpplib as a library.  */
static void
1341
sanitize_cpp_opts (void)
1342 1343 1344 1345 1346 1347 1348 1349
{
  /* If we don't know what style of dependencies to output, complain
     if any other dependency switches have been given.  */
  if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
    error ("to generate dependencies you must specify either -M or -MM");

  /* -dM and dependencies suppress normal output; do it here so that
     the last -d[MDN] switch overrides earlier ones.  */
Neil Booth committed
1350 1351
  if (flag_dump_macros == 'M')
    flag_no_output = 1;
1352 1353 1354

  /* Disable -dD, -dN and -dI if normal output is suppressed.  Allow
     -dM since at least glibc relies on -M -dM to work.  */
Neil Booth committed
1355
  if (flag_no_output)
1356
    {
Neil Booth committed
1357 1358 1359
      if (flag_dump_macros != 'M')
	flag_dump_macros = 0;
      flag_dump_includes = 0;
1360
    }
1361 1362 1363 1364 1365 1366 1367 1368

  cpp_opts->unsigned_char = !flag_signed_char;
  cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;

  /* We want -Wno-long-long to override -pedantic -std=non-c99
     and/or -Wtraditional, whatever the ordering.  */
  cpp_opts->warn_long_long
    = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
1369

1370 1371 1372 1373 1374
  /* Similarly with -Wno-variadic-macros.  No check for c99 here, since
     this also turns off warnings about GCCs extension.  */
  cpp_opts->warn_variadic_macros
    = warn_variadic_macros && (pedantic || warn_traditional);

1375 1376 1377 1378 1379 1380
  /* If we're generating preprocessor output, emit current directory
     if explicitly requested or if debugging information is enabled.
     ??? Maybe we should only do it for debugging formats that
     actually output the current directory?  */
  if (flag_working_directory == -1)
    flag_working_directory = (debug_info_level != DINFO_LEVEL_NONE);
1381 1382
}

1383 1384
/* Add include path with a prefix at the front of its name.  */
static void
1385
add_prefixed_path (const char *suffix, size_t chain)
1386
{
1387
  char *path;
1388
  const char *prefix;
1389
  size_t prefix_len, suffix_len;
1390

1391 1392 1393 1394 1395 1396 1397 1398 1399 1400
  suffix_len = strlen (suffix);
  prefix     = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
  prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;

  path = xmalloc (prefix_len + suffix_len + 1);
  memcpy (path, prefix, prefix_len);
  memcpy (path + prefix_len, suffix, suffix_len);
  path[prefix_len + suffix_len] = '\0';

  add_path (path, chain, 0);
1401 1402
}

1403 1404 1405
/* Handle -D, -U, -A, -imacros, and the first -include.  */
static void
finish_options (void)
1406 1407 1408
{
  if (!cpp_opts->preprocessed)
    {
Neil Booth committed
1409 1410
      size_t i;

1411
      cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
1412
      cpp_init_builtins (parse_in, flag_hosted);
Neil Booth committed
1413
      c_cpp_builtins (parse_in);
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425

      /* We're about to send user input to cpplib, so make it warn for
	 things that we previously (when we sent it internal definitions)
	 told it to not warn.

	 C99 permits implementation-defined characters in identifiers.
	 The documented meaning of -std= is to turn off extensions that
	 conflict with the specified standard, and since a strictly
	 conforming program cannot contain a '$', we do not condition
	 their acceptance on the -std= setting.  */
      cpp_opts->warn_dollars = (cpp_opts->pedantic && !cpp_opts->c99);

1426
      cpp_change_file (parse_in, LC_RENAME, _("<command line>"));
Neil Booth committed
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442
      for (i = 0; i < deferred_count; i++)
	{
	  struct deferred_opt *opt = &deferred_opts[i];

	  if (opt->code == OPT_D)
	    cpp_define (parse_in, opt->arg);
	  else if (opt->code == OPT_U)
	    cpp_undef (parse_in, opt->arg);
	  else if (opt->code == OPT_A)
	    {
	      if (opt->arg[0] == '-')
		cpp_unassert (parse_in, opt->arg + 1);
	      else
		cpp_assert (parse_in, opt->arg);
	    }
	}
1443

Neil Booth committed
1444
      /* Handle -imacros after -D and -U.  */
1445 1446 1447 1448 1449 1450
      for (i = 0; i < deferred_count; i++)
	{
	  struct deferred_opt *opt = &deferred_opts[i];

	  if (opt->code == OPT_imacros
	      && cpp_push_include (parse_in, opt->arg))
1451
	    {
1452
	      /* Disable push_command_line_include callback for now.  */
1453 1454 1455
	      include_cursor = deferred_count + 1;
	      cpp_scan_nooutput (parse_in);
	    }
1456 1457 1458
	}
    }

1459
  include_cursor = 0;
1460 1461 1462
  push_command_line_include ();
}

1463 1464
/* Give CPP the next file given by -include, if any.  */
static void
1465
push_command_line_include (void)
1466 1467 1468 1469
{
  while (include_cursor < deferred_count)
    {
      struct deferred_opt *opt = &deferred_opts[include_cursor++];
1470

1471 1472
      if (! cpp_opts->preprocessed && opt->code == OPT_include
	  && cpp_push_include (parse_in, opt->arg))
1473 1474 1475 1476 1477
	return;
    }

  if (include_cursor == deferred_count)
    {
1478
      include_cursor++;
1479 1480
      /* -Wunused-macros should only warn about macros defined hereafter.  */
      cpp_opts->warn_unused_macros = warn_unused_macros;
1481 1482 1483 1484 1485 1486 1487
      /* Restore the line map from <command line>.  */
      if (! cpp_opts->preprocessed)
	cpp_change_file (parse_in, LC_RENAME, main_input_filename);

      /* Set this here so the client can change the option if it wishes,
	 and after stacking the main file so we don't trace the main file.  */
      line_table.trace_includes = cpp_opts->print_include_names;
1488 1489 1490 1491 1492
    }
}

/* File change callback.  Has to handle -include files.  */
static void
1493 1494
cb_file_change (cpp_reader *pfile ATTRIBUTE_UNUSED,
		const struct line_map *new_map)
1495 1496 1497 1498 1499 1500
{
  if (flag_preprocess_only)
    pp_file_change (new_map);
  else
    fe_file_change (new_map);

1501
  if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
1502 1503 1504
    push_command_line_include ();
}

1505 1506 1507 1508 1509 1510 1511
void
cb_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
{
  if (! set_src_pwd (dir))
    warning ("too late for # directive to set debug directory");
}

1512 1513 1514
/* Set the C 89 standard (with 1994 amendments if C94, without GNU
   extensions if ISO).  There is no concept of gnu94.  */
static void
1515
set_std_c89 (int c94, int iso)
1516 1517 1518 1519 1520 1521 1522 1523
{
  cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
  flag_iso = iso;
  flag_no_asm = iso;
  flag_no_gnu_keywords = iso;
  flag_no_nonansi_builtin = iso;
  flag_isoc94 = c94;
  flag_isoc99 = 0;
1524 1525
}

1526 1527
/* Set the C 99 standard (without GNU extensions if ISO).  */
static void
1528
set_std_c99 (int iso)
1529 1530 1531 1532 1533 1534 1535 1536 1537
{
  cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
  flag_no_asm = iso;
  flag_no_nonansi_builtin = iso;
  flag_iso = iso;
  flag_isoc99 = 1;
  flag_isoc94 = 1;
}

1538 1539
/* Set the C++ 98 standard (without GNU extensions if ISO).  */
static void
1540
set_std_cxx98 (int iso)
1541 1542 1543 1544 1545 1546 1547
{
  cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
  flag_no_gnu_keywords = iso;
  flag_no_nonansi_builtin = iso;
  flag_iso = iso;
}

1548 1549
/* Handle setting implicit to ON.  */
static void
1550
set_Wimplicit (int on)
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
{
  warn_implicit = on;
  warn_implicit_int = on;
  if (on)
    {
      if (mesg_implicit_function_declaration != 2)
	mesg_implicit_function_declaration = 1;
    }
  else
    mesg_implicit_function_declaration = 0;
}

1563
/* Args to -d specify what to dump.  Silently ignore
1564
   unrecognized options; they may be aimed at toplev.c.  */
1565
static void
1566
handle_OPT_d (const char *arg)
1567
{
1568 1569 1570 1571 1572
  char c;

  while ((c = *arg++) != '\0')
    switch (c)
      {
Neil Booth committed
1573 1574 1575 1576
      case 'M':			/* Dump macros only.  */
      case 'N':			/* Dump names.  */
      case 'D':			/* Dump definitions.  */
	flag_dump_macros = c;
1577 1578 1579
	break;

      case 'I':
Neil Booth committed
1580
	flag_dump_includes = 1;
1581 1582
	break;
      }
1583
}