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_preprocessed = 0;
76 gfc_option.flag_automatic = 1;
77 gfc_option.flag_backslash = 1;
78 gfc_option.flag_cray_pointer = 0;
79 gfc_option.flag_d_lines = -1;
81 gfc_option.q_kind = gfc_default_double_kind;
85 flag_argument_noalias = 2;
88 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
89 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU
91 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
92 | GFC_STD_F2003 | GFC_STD_LEGACY;
94 gfc_option.warn_nonstd_intrinsics = 0;
96 /* -fshort-enums can be default on some targets. */
97 gfc_option.fshort_enums = targetm.default_short_enums ();
103 /* Determine the source form from the filename extension. We assume
104 case insensitivity. */
106 static gfc_source_form
107 form_from_filename (const char *filename)
112 const char *extension;
113 gfc_source_form form;
131 }; /* sentinel value */
133 gfc_source_form f_form;
137 /* Find end of file name. Note, filename is either a NULL pointer or
138 a NUL terminated string. */
140 while (filename[i] != '\0')
143 /* Find last period. */
144 while (i >= 0 && (filename[i] != '.'))
147 /* Did we see a file extension? */
149 return FORM_UNKNOWN; /* Nope */
151 /* Get file extension and compare it to others. */
152 fileext = &(filename[i]);
155 f_form = FORM_UNKNOWN;
159 if (strcasecmp (fileext, exttype[i].extension) == 0)
161 f_form = exttype[i].form;
165 while (exttype[i].form != FORM_UNKNOWN);
171 /* Finalize commandline options. */
174 gfc_post_options (const char **pfilename)
176 const char *filename = *pfilename, *canon_source_file = NULL;
180 /* Verify the input file name. */
181 if (!filename || strcmp (filename, "-") == 0)
186 if (gfc_option.flag_preprocessed)
188 /* For preprocessed files, if the first tokens are of the form # NUM.
189 handle the directives so we know the original file name. */
190 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
191 if (gfc_source_file == NULL)
192 gfc_source_file = filename;
194 *pfilename = gfc_source_file;
197 gfc_source_file = filename;
199 if (canon_source_file == NULL)
200 canon_source_file = gfc_source_file;
202 /* Adds the path where the source file is to the list of include files. */
204 i = strlen (canon_source_file);
205 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
209 source_path = alloca (i + 1);
210 memcpy (source_path, canon_source_file, i);
212 gfc_add_include_path (source_path);
215 gfc_add_include_path (".");
217 if (canon_source_file != gfc_source_file)
218 gfc_free ((void *) canon_source_file);
220 /* Decide which form the file will be read in as. */
222 if (gfc_option.source_form != FORM_UNKNOWN)
223 gfc_current_form = gfc_option.source_form;
226 gfc_current_form = form_from_filename (filename);
228 if (gfc_current_form == FORM_UNKNOWN)
230 gfc_current_form = FORM_FREE;
231 gfc_warning_now ("Reading file '%s' as free form.",
232 (filename[0] == '\0') ? "<stdin>" : filename);
236 /* If the user specified -fd-lines-as-{code|comments} verify that we're
238 if (gfc_current_form == FORM_FREE)
240 if (gfc_option.flag_d_lines == 0)
241 gfc_warning_now ("'-fd-lines-as-comments' has no effect "
243 else if (gfc_option.flag_d_lines == 1)
244 gfc_warning_now ("'-fd-lines-as-code' has no effect "
248 flag_inline_trees = 1;
250 /* Use tree inlining. */
253 if (flag_inline_functions)
254 flag_inline_trees = 2;
256 /* If -pedantic, warn about the use of GNU extensions. */
257 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
258 gfc_option.warn_std |= GFC_STD_GNU;
259 /* -std=legacy -pedantic is effectively -std=gnu. */
260 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
261 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
263 /* If the user didn't explicitly specify -f(no)-second-underscore we
264 use it if we're trying to be compatible with f2c, and not
266 if (gfc_option.flag_second_underscore == -1)
267 gfc_option.flag_second_underscore = gfc_option.flag_f2c;
269 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
270 if (!gfc_option.flag_automatic)
271 gfc_option.flag_max_stack_var_size = 0;
277 /* Set the options for -Wall. */
283 gfc_option.warn_aliasing = 1;
284 gfc_option.warn_line_truncation = 1;
285 gfc_option.warn_underflow = 1;
286 gfc_option.warn_surprising = 1;
287 gfc_option.warn_unused_labels = 1;
288 gfc_option.warn_nonstd_intrinsics = 1;
291 warn_return_type = 1;
294 /* We save the value of warn_uninitialized, since if they put
295 -Wuninitialized on the command line, we need to generate a
296 warning about not using it without also specifying -O. */
298 if (warn_uninitialized != 1)
299 warn_uninitialized = 2;
304 gfc_handle_module_path_options (const char *arg)
307 if (gfc_option.module_dir != NULL)
309 gfc_status ("gfortran: Only one -M option allowed\n");
315 gfc_status ("gfortran: Directory required after -M\n");
319 gfc_option.module_dir = (char *) gfc_getmem (strlen (arg) + 2);
320 strcpy (gfc_option.module_dir, arg);
321 strcat (gfc_option.module_dir, "/");
325 gfc_handle_fpe_trap_option (const char *arg)
327 int result, pos = 0, n;
328 static const char * const exception[] = { "invalid", "denormal", "zero",
329 "overflow", "underflow",
331 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
332 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
333 GFC_FPE_UNDERFLOW, GFC_FPE_PRECISION,
340 while (arg[pos] && arg[pos] != ',')
343 for (n = 0; exception[n] != NULL; n++)
345 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
347 gfc_option.fpe |= opt_exception[n];
355 gfc_fatal_error ("Argument to -ffpe-trap is not valid: %s", arg);
359 /* Handle command-line options. Returns 0 if unrecognized, 1 if
360 recognized and handled. */
362 gfc_handle_option (size_t scode, const char *arg, int value)
365 enum opt_code code = (enum opt_code) scode;
367 /* Ignore file names. */
382 gfc_option.warn_aliasing = value;
385 case OPT_Wconversion:
386 gfc_option.warn_conversion = value;
389 case OPT_Wimplicit_interface:
390 gfc_option.warn_implicit_interface = value;
393 case OPT_Wline_truncation:
394 gfc_option.warn_line_truncation = value;
398 gfc_option.warn_underflow = value;
401 case OPT_Wsurprising:
402 gfc_option.warn_surprising = value;
405 case OPT_Wunused_labels:
406 gfc_option.warn_unused_labels = value;
409 case OPT_fcray_pointer:
410 gfc_option.flag_cray_pointer = value;
414 gfc_option.flag_f2c = value;
418 gfc_option.flag_dollar_ok = value;
422 gfc_option.flag_automatic = value;
426 gfc_option.flag_backslash = value;
429 case OPT_fd_lines_as_code:
430 gfc_option.flag_d_lines = 1;
433 case OPT_fd_lines_as_comments:
434 gfc_option.flag_d_lines = 0;
437 case OPT_fdump_parse_tree:
438 gfc_option.verbose = value;
441 case OPT_ffixed_form:
442 gfc_option.source_form = FORM_FIXED;
445 case OPT_ffixed_line_length_none:
446 gfc_option.fixed_line_length = 0;
449 case OPT_ffixed_line_length_:
450 if (value != 0 && value < 7)
451 gfc_fatal_error ("Fixed line length must be at least seven.");
452 gfc_option.fixed_line_length = value;
456 gfc_option.source_form = FORM_FREE;
459 case OPT_ffree_line_length_none:
460 gfc_option.free_line_length = 0;
463 case OPT_ffree_line_length_:
464 gfc_option.free_line_length = value;
467 case OPT_funderscoring:
468 gfc_option.flag_underscoring = value;
471 case OPT_fsecond_underscore:
472 gfc_option.flag_second_underscore = value;
475 case OPT_fimplicit_none:
476 gfc_option.flag_implicit_none = value;
479 case OPT_fmax_stack_var_size_:
480 gfc_option.flag_max_stack_var_size = value;
483 case OPT_fmodule_private:
484 gfc_option.flag_module_access_private = value;
487 case OPT_fno_backend:
488 gfc_option.flag_no_backend = value;
491 case OPT_fpack_derived:
492 gfc_option.flag_pack_derived = value;
495 case OPT_frepack_arrays:
496 gfc_option.flag_repack_arrays = value;
499 case OPT_fpreprocessed:
500 gfc_option.flag_preprocessed = value;
503 case OPT_fmax_identifier_length_:
504 if (value > GFC_MAX_SYMBOL_LEN)
505 gfc_fatal_error ("Maximum supported idenitifier length is %d",
507 gfc_option.max_identifier_length = value;
511 if (gfc_validate_kind (BT_REAL, value, true) < 0)
512 gfc_fatal_error ("Argument to -fqkind isn't a valid real kind");
513 gfc_option.q_kind = value;
516 case OPT_fdefault_integer_8:
517 gfc_option.flag_default_integer = value;
520 case OPT_fdefault_real_8:
521 gfc_option.flag_default_real = value;
524 case OPT_fdefault_double_8:
525 gfc_option.flag_default_double = value;
529 gfc_add_include_path (arg);
534 gfc_handle_module_path_options (arg);
538 gfc_handle_fpe_trap_option (arg);
542 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77;
543 gfc_option.warn_std = GFC_STD_F95_OBS;
544 gfc_option.max_identifier_length = 31;
548 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
549 | GFC_STD_F2003 | GFC_STD_F95;
550 gfc_option.warn_std = GFC_STD_F95_OBS;
551 gfc_option.max_identifier_length = 63;
555 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
556 | GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F2003
557 | GFC_STD_GNU | GFC_STD_LEGACY;
558 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
563 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
564 | GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F2003
565 | GFC_STD_GNU | GFC_STD_LEGACY;
566 gfc_option.warn_std = 0;
569 case OPT_Wnonstd_intrinsics:
570 gfc_option.warn_nonstd_intrinsics = 1;
573 case OPT_fshort_enums:
574 gfc_option.fshort_enums = 1;