1 /* Parse and display command line options.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation,
4 Contributed by Andy Vaught
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "coretypes.h"
32 #include "tree-inline.h"
37 gfc_option_t gfc_option;
40 /* Get ready for options handling. */
43 gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED,
44 const char **argv ATTRIBUTE_UNUSED)
46 gfc_source_file = NULL;
47 gfc_option.module_dir = NULL;
48 gfc_option.source_form = FORM_UNKNOWN;
49 gfc_option.fixed_line_length = -1;
50 gfc_option.free_line_length = -1;
51 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
52 gfc_option.verbose = 0;
54 gfc_option.warn_aliasing = 0;
55 gfc_option.warn_conversion = 0;
56 gfc_option.warn_implicit_interface = 0;
57 gfc_option.warn_line_truncation = 0;
58 gfc_option.warn_underflow = 1;
59 gfc_option.warn_surprising = 0;
60 gfc_option.warn_unused_labels = 0;
62 gfc_option.flag_default_double = 0;
63 gfc_option.flag_default_integer = 0;
64 gfc_option.flag_default_real = 0;
65 gfc_option.flag_dollar_ok = 0;
66 gfc_option.flag_underscoring = 1;
67 gfc_option.flag_f2c = 0;
68 gfc_option.flag_second_underscore = -1;
69 gfc_option.flag_implicit_none = 0;
70 gfc_option.flag_max_stack_var_size = 32768;
71 gfc_option.flag_module_access_private = 0;
72 gfc_option.flag_no_backend = 0;
73 gfc_option.flag_pack_derived = 0;
74 gfc_option.flag_repack_arrays = 0;
75 gfc_option.flag_automatic = 1;
76 gfc_option.flag_backslash = 1;
77 gfc_option.flag_cray_pointer = 0;
78 gfc_option.flag_d_lines = -1;
80 gfc_option.q_kind = gfc_default_double_kind;
84 flag_argument_noalias = 2;
87 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
88 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU
90 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
91 | GFC_STD_F2003 | GFC_STD_LEGACY;
93 gfc_option.warn_nonstd_intrinsics = 0;
95 /* -fshort-enums can be default on some targets. */
96 gfc_option.fshort_enums = targetm.default_short_enums ();
102 /* Determine the source form from the filename extension. We assume
103 case insensitivity. */
105 static gfc_source_form
106 form_from_filename (const char *filename)
111 const char *extension;
112 gfc_source_form form;
130 }; /* sentinel value */
132 gfc_source_form f_form;
136 /* Find end of file name. Note, filename is either a NULL pointer or
137 a NUL terminated string. */
139 while (filename[i] != '\0')
142 /* Find last period. */
143 while (i >= 0 && (filename[i] != '.'))
146 /* Did we see a file extension? */
148 return FORM_UNKNOWN; /* Nope */
150 /* Get file extension and compare it to others. */
151 fileext = &(filename[i]);
154 f_form = FORM_UNKNOWN;
158 if (strcasecmp (fileext, exttype[i].extension) == 0)
160 f_form = exttype[i].form;
164 while (exttype[i].form != FORM_UNKNOWN);
170 /* Finalize commandline options. */
173 gfc_post_options (const char **pfilename)
175 const char *filename = *pfilename;
179 /* Verify the input file name. */
180 if (!filename || strcmp (filename, "-") == 0)
185 gfc_source_file = filename;
187 /* Adds the path where the source file is to the list of include files. */
189 i = strlen(gfc_source_file);
190 while (i > 0 && !IS_DIR_SEPARATOR(gfc_source_file[i]))
194 source_path = alloca (i + 1);
195 memcpy (source_path, gfc_source_file, i);
197 gfc_add_include_path (source_path);
200 gfc_add_include_path (".");
202 /* Decide which form the file will be read in as. */
204 if (gfc_option.source_form != FORM_UNKNOWN)
205 gfc_current_form = gfc_option.source_form;
208 gfc_current_form = form_from_filename (filename);
210 if (gfc_current_form == FORM_UNKNOWN)
212 gfc_current_form = FORM_FREE;
213 gfc_warning_now ("Reading file '%s' as free form.",
214 (filename[0] == '\0') ? "<stdin>" : filename);
218 /* If the user specified -fd-lines-as-{code|comments} verify that we're
220 if (gfc_current_form == FORM_FREE)
222 if (gfc_option.flag_d_lines == 0)
223 gfc_warning_now ("'-fd-lines-as-comments' has no effect "
225 else if (gfc_option.flag_d_lines == 1)
226 gfc_warning_now ("'-fd-lines-as-code' has no effect "
230 flag_inline_trees = 1;
232 /* Use tree inlining. */
235 if (flag_inline_functions)
236 flag_inline_trees = 2;
238 /* If -pedantic, warn about the use of GNU extensions. */
239 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
240 gfc_option.warn_std |= GFC_STD_GNU;
241 /* -std=legacy -pedantic is effectively -std=gnu. */
242 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
243 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
245 /* If the user didn't explicitly specify -f(no)-second-underscore we
246 use it if we're trying to be compatible with f2c, and not
248 if (gfc_option.flag_second_underscore == -1)
249 gfc_option.flag_second_underscore = gfc_option.flag_f2c;
251 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
252 if (!gfc_option.flag_automatic)
253 gfc_option.flag_max_stack_var_size = 0;
259 /* Set the options for -Wall. */
265 gfc_option.warn_aliasing = 1;
266 gfc_option.warn_line_truncation = 1;
267 gfc_option.warn_underflow = 1;
268 gfc_option.warn_surprising = 1;
269 gfc_option.warn_unused_labels = 1;
270 gfc_option.warn_nonstd_intrinsics = 1;
273 warn_return_type = 1;
276 /* We save the value of warn_uninitialized, since if they put
277 -Wuninitialized on the command line, we need to generate a
278 warning about not using it without also specifying -O. */
280 if (warn_uninitialized != 1)
281 warn_uninitialized = 2;
286 gfc_handle_module_path_options (const char *arg)
289 if (gfc_option.module_dir != NULL)
291 gfc_status ("gfortran: Only one -M option allowed\n");
297 gfc_status ("gfortran: Directory required after -M\n");
301 gfc_option.module_dir = (char *) gfc_getmem (strlen (arg) + 2);
302 strcpy (gfc_option.module_dir, arg);
303 strcat (gfc_option.module_dir, "/");
307 gfc_handle_fpe_trap_option (const char *arg)
309 int result, pos = 0, n;
310 static const char * const exception[] = { "invalid", "denormal", "zero",
311 "overflow", "underflow",
313 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
314 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
315 GFC_FPE_UNDERFLOW, GFC_FPE_PRECISION,
322 while (arg[pos] && arg[pos] != ',')
325 for (n = 0; exception[n] != NULL; n++)
327 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
329 gfc_option.fpe |= opt_exception[n];
337 gfc_fatal_error ("Argument to -ffpe-trap is not valid: %s", arg);
341 /* Handle command-line options. Returns 0 if unrecognized, 1 if
342 recognized and handled. */
344 gfc_handle_option (size_t scode, const char *arg, int value)
347 enum opt_code code = (enum opt_code) scode;
349 /* Ignore file names. */
364 gfc_option.warn_aliasing = value;
367 case OPT_Wconversion:
368 gfc_option.warn_conversion = value;
371 case OPT_Wimplicit_interface:
372 gfc_option.warn_implicit_interface = value;
375 case OPT_Wline_truncation:
376 gfc_option.warn_line_truncation = value;
380 gfc_option.warn_underflow = value;
383 case OPT_Wsurprising:
384 gfc_option.warn_surprising = value;
387 case OPT_Wunused_labels:
388 gfc_option.warn_unused_labels = value;
391 case OPT_fcray_pointer:
392 gfc_option.flag_cray_pointer = value;
396 gfc_option.flag_f2c = value;
400 gfc_option.flag_dollar_ok = value;
404 gfc_option.flag_automatic = value;
408 gfc_option.flag_backslash = value;
411 case OPT_fd_lines_as_code:
412 gfc_option.flag_d_lines = 1;
415 case OPT_fd_lines_as_comments:
416 gfc_option.flag_d_lines = 0;
419 case OPT_fdump_parse_tree:
420 gfc_option.verbose = value;
423 case OPT_ffixed_form:
424 gfc_option.source_form = FORM_FIXED;
427 case OPT_ffixed_line_length_none:
428 gfc_option.fixed_line_length = 0;
431 case OPT_ffixed_line_length_:
432 if (value != 0 && value < 7)
433 gfc_fatal_error ("Fixed line length must be at least seven.");
434 gfc_option.fixed_line_length = value;
438 gfc_option.source_form = FORM_FREE;
441 case OPT_ffree_line_length_none:
442 gfc_option.free_line_length = 0;
445 case OPT_ffree_line_length_:
446 gfc_option.free_line_length = value;
449 case OPT_funderscoring:
450 gfc_option.flag_underscoring = value;
453 case OPT_fsecond_underscore:
454 gfc_option.flag_second_underscore = value;
457 case OPT_fimplicit_none:
458 gfc_option.flag_implicit_none = value;
461 case OPT_fmax_stack_var_size_:
462 gfc_option.flag_max_stack_var_size = value;
465 case OPT_fmodule_private:
466 gfc_option.flag_module_access_private = value;
469 case OPT_fno_backend:
470 gfc_option.flag_no_backend = value;
473 case OPT_fpack_derived:
474 gfc_option.flag_pack_derived = value;
477 case OPT_frepack_arrays:
478 gfc_option.flag_repack_arrays = value;
481 case OPT_fmax_identifier_length_:
482 if (value > GFC_MAX_SYMBOL_LEN)
483 gfc_fatal_error ("Maximum supported idenitifier length is %d",
485 gfc_option.max_identifier_length = value;
489 if (gfc_validate_kind (BT_REAL, value, true) < 0)
490 gfc_fatal_error ("Argument to -fqkind isn't a valid real kind");
491 gfc_option.q_kind = value;
494 case OPT_fdefault_integer_8:
495 gfc_option.flag_default_integer = value;
498 case OPT_fdefault_real_8:
499 gfc_option.flag_default_real = value;
502 case OPT_fdefault_double_8:
503 gfc_option.flag_default_double = value;
507 gfc_add_include_path (arg);
512 gfc_handle_module_path_options (arg);
516 gfc_handle_fpe_trap_option (arg);
520 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77;
521 gfc_option.warn_std = GFC_STD_F95_OBS;
522 gfc_option.max_identifier_length = 31;
526 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
527 | GFC_STD_F2003 | GFC_STD_F95;
528 gfc_option.warn_std = GFC_STD_F95_OBS;
529 gfc_option.max_identifier_length = 63;
533 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
534 | GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F2003
535 | GFC_STD_GNU | GFC_STD_LEGACY;
536 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
541 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
542 | GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F2003
543 | GFC_STD_GNU | GFC_STD_LEGACY;
544 gfc_option.warn_std = 0;
547 case OPT_Wnonstd_intrinsics:
548 gfc_option.warn_nonstd_intrinsics = 1;
551 case OPT_fshort_enums:
552 gfc_option.fshort_enums = 1;