Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / fortran / options.c
blob64fa8a2744146d73571521df5b0bce79f1465ec7
1 /* Parse and display command line options.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation,
3 Inc.
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
11 version.
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
16 for more details.
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
21 02110-1301, USA. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tree.h"
28 #include "flags.h"
29 #include "intl.h"
30 #include "opts.h"
31 #include "options.h"
32 #include "tree-inline.h"
34 #include "gfortran.h"
35 #include "target.h"
37 gfc_option_t gfc_option;
40 /* Get ready for options handling. */
42 unsigned int
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;
82 gfc_option.fpe = 0;
84 flag_argument_noalias = 2;
85 flag_errno_math = 0;
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
89 | GFC_STD_LEGACY;
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 ();
98 return CL_Fortran;
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)
109 static const struct
111 const char *extension;
112 gfc_source_form form;
114 exttype[] =
117 ".f90", FORM_FREE}
120 ".f95", FORM_FREE}
123 ".f", FORM_FIXED}
126 ".for", FORM_FIXED}
129 "", FORM_UNKNOWN}
130 }; /* sentinel value */
132 gfc_source_form f_form;
133 const char *fileext;
134 int i;
136 /* Find end of file name. Note, filename is either a NULL pointer or
137 a NUL terminated string. */
138 i = 0;
139 while (filename[i] != '\0')
140 i++;
142 /* Find last period. */
143 while (i >= 0 && (filename[i] != '.'))
144 i--;
146 /* Did we see a file extension? */
147 if (i < 0)
148 return FORM_UNKNOWN; /* Nope */
150 /* Get file extension and compare it to others. */
151 fileext = &(filename[i]);
153 i = -1;
154 f_form = FORM_UNKNOWN;
157 i++;
158 if (strcasecmp (fileext, exttype[i].extension) == 0)
160 f_form = exttype[i].form;
161 break;
164 while (exttype[i].form != FORM_UNKNOWN);
166 return f_form;
170 /* Finalize commandline options. */
172 bool
173 gfc_post_options (const char **pfilename)
175 const char *filename = *pfilename;
176 char *source_path;
177 int i;
179 /* Verify the input file name. */
180 if (!filename || strcmp (filename, "-") == 0)
182 filename = "";
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]))
191 i--;
192 if (i != 0)
194 source_path = alloca (i + 1);
195 memcpy (source_path, gfc_source_file, i);
196 source_path[i] = 0;
197 gfc_add_include_path (source_path);
199 else
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;
206 else
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
219 in fixed form. */
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 "
224 "in free form.");
225 else if (gfc_option.flag_d_lines == 1)
226 gfc_warning_now ("'-fd-lines-as-code' has no effect "
227 "in free form.");
230 flag_inline_trees = 1;
232 /* Use tree inlining. */
233 if (!flag_no_inline)
234 flag_no_inline = 1;
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
247 otherwise. */
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;
255 return false;
259 /* Set the options for -Wall. */
261 static void
262 set_Wall (void)
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;
272 set_Wunused (1);
273 warn_return_type = 1;
274 warn_switch = 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;
285 static void
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");
292 exit (3);
295 if (arg == NULL)
297 gfc_status ("gfortran: Directory required after -M\n");
298 exit (3);
301 gfc_option.module_dir = (char *) gfc_getmem (strlen (arg) + 2);
302 strcpy (gfc_option.module_dir, arg);
303 strcat (gfc_option.module_dir, "/");
306 static void
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",
312 "precision", NULL };
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,
316 0 };
318 while (*arg)
320 while (*arg == ',')
321 arg++;
322 while (arg[pos] && arg[pos] != ',')
323 pos++;
324 result = 0;
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];
330 arg += pos;
331 pos = 0;
332 result = 1;
333 break;
336 if (! result)
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)
346 int result = 1;
347 enum opt_code code = (enum opt_code) scode;
349 /* Ignore file names. */
350 if (code == N_OPTS)
351 return 1;
353 switch (code)
355 default:
356 result = 0;
357 break;
359 case OPT_Wall:
360 set_Wall ();
361 break;
363 case OPT_Waliasing:
364 gfc_option.warn_aliasing = value;
365 break;
367 case OPT_Wconversion:
368 gfc_option.warn_conversion = value;
369 break;
371 case OPT_Wimplicit_interface:
372 gfc_option.warn_implicit_interface = value;
373 break;
375 case OPT_Wline_truncation:
376 gfc_option.warn_line_truncation = value;
377 break;
379 case OPT_Wunderflow:
380 gfc_option.warn_underflow = value;
381 break;
383 case OPT_Wsurprising:
384 gfc_option.warn_surprising = value;
385 break;
387 case OPT_Wunused_labels:
388 gfc_option.warn_unused_labels = value;
389 break;
391 case OPT_fcray_pointer:
392 gfc_option.flag_cray_pointer = value;
393 break;
395 case OPT_ff2c:
396 gfc_option.flag_f2c = value;
397 break;
399 case OPT_fdollar_ok:
400 gfc_option.flag_dollar_ok = value;
401 break;
403 case OPT_fautomatic:
404 gfc_option.flag_automatic = value;
405 break;
407 case OPT_fbackslash:
408 gfc_option.flag_backslash = value;
409 break;
411 case OPT_fd_lines_as_code:
412 gfc_option.flag_d_lines = 1;
413 break;
415 case OPT_fd_lines_as_comments:
416 gfc_option.flag_d_lines = 0;
417 break;
419 case OPT_fdump_parse_tree:
420 gfc_option.verbose = value;
421 break;
423 case OPT_ffixed_form:
424 gfc_option.source_form = FORM_FIXED;
425 break;
427 case OPT_ffixed_line_length_none:
428 gfc_option.fixed_line_length = 0;
429 break;
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;
435 break;
437 case OPT_ffree_form:
438 gfc_option.source_form = FORM_FREE;
439 break;
441 case OPT_ffree_line_length_none:
442 gfc_option.free_line_length = 0;
443 break;
445 case OPT_ffree_line_length_:
446 gfc_option.free_line_length = value;
447 break;
449 case OPT_funderscoring:
450 gfc_option.flag_underscoring = value;
451 break;
453 case OPT_fsecond_underscore:
454 gfc_option.flag_second_underscore = value;
455 break;
457 case OPT_fimplicit_none:
458 gfc_option.flag_implicit_none = value;
459 break;
461 case OPT_fmax_stack_var_size_:
462 gfc_option.flag_max_stack_var_size = value;
463 break;
465 case OPT_fmodule_private:
466 gfc_option.flag_module_access_private = value;
467 break;
469 case OPT_fno_backend:
470 gfc_option.flag_no_backend = value;
471 break;
473 case OPT_fpack_derived:
474 gfc_option.flag_pack_derived = value;
475 break;
477 case OPT_frepack_arrays:
478 gfc_option.flag_repack_arrays = value;
479 break;
481 case OPT_fmax_identifier_length_:
482 if (value > GFC_MAX_SYMBOL_LEN)
483 gfc_fatal_error ("Maximum supported idenitifier length is %d",
484 GFC_MAX_SYMBOL_LEN);
485 gfc_option.max_identifier_length = value;
486 break;
488 case OPT_qkind_:
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;
492 break;
494 case OPT_fdefault_integer_8:
495 gfc_option.flag_default_integer = value;
496 break;
498 case OPT_fdefault_real_8:
499 gfc_option.flag_default_real = value;
500 break;
502 case OPT_fdefault_double_8:
503 gfc_option.flag_default_double = value;
504 break;
506 case OPT_I:
507 gfc_add_include_path (arg);
508 break;
510 case OPT_J:
511 case OPT_M:
512 gfc_handle_module_path_options (arg);
513 break;
515 case OPT_ffpe_trap_:
516 gfc_handle_fpe_trap_option (arg);
517 break;
519 case OPT_std_f95:
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;
523 break;
525 case OPT_std_f2003:
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;
530 break;
532 case OPT_std_gnu:
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
537 | GFC_STD_LEGACY;
538 break;
540 case OPT_std_legacy:
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;
545 break;
547 case OPT_Wnonstd_intrinsics:
548 gfc_option.warn_nonstd_intrinsics = 1;
549 break;
551 case OPT_fshort_enums:
552 gfc_option.fshort_enums = 1;
553 break;
556 return result;