2016-08-24 Michael Collison <michael.collison@linaro.org>
[official-gcc.git] / gcc / fortran / options.c
blob4aa8303dfebd3368d1009ca209069c6a351e2a5b
1 /* Parse and display command line options.
2 Copyright (C) 2000-2016 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "target.h"
25 #include "tree.h"
26 #include "gfortran.h"
27 #include "diagnostic.h" /* For global_dc. */
28 #include "opts.h"
29 #include "toplev.h" /* For save_decoded_options. */
30 #include "cpp.h"
31 #include "langhooks.h"
33 gfc_option_t gfc_option;
36 /* Set flags that control warnings and errors for different
37 Fortran standards to their default values. Keep in sync with
38 libgfortran/runtime/compile_options.c (init_compile_options). */
40 static void
41 set_default_std_flags (void)
43 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
44 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
45 | GFC_STD_F2008_OBS | GFC_STD_F2008_TS | GFC_STD_GNU | GFC_STD_LEGACY;
46 gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
50 /* Set all the DEC extension flags. */
52 static void
53 set_dec_flags (int value)
55 gfc_option.flag_dec_structure = value;
56 flag_dec_intrinsic_ints = value;
60 /* Return language mask for Fortran options. */
62 unsigned int
63 gfc_option_lang_mask (void)
65 return CL_Fortran;
68 /* Initialize options structure OPTS. */
70 void
71 gfc_init_options_struct (struct gcc_options *opts)
73 opts->x_flag_errno_math = 0;
74 opts->frontend_set_flag_errno_math = true;
75 opts->x_flag_associative_math = -1;
76 opts->frontend_set_flag_associative_math = true;
79 /* Get ready for options handling. Keep in sync with
80 libgfortran/runtime/compile_options.c (init_compile_options). */
82 void
83 gfc_init_options (unsigned int decoded_options_count,
84 struct cl_decoded_option *decoded_options)
86 gfc_source_file = NULL;
87 gfc_option.module_dir = NULL;
88 gfc_option.source_form = FORM_UNKNOWN;
89 gfc_option.max_continue_fixed = 255;
90 gfc_option.max_continue_free = 255;
91 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
92 gfc_option.max_errors = 25;
94 gfc_option.flag_preprocessed = 0;
95 gfc_option.flag_d_lines = -1;
96 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
97 gfc_option.flag_init_integer_value = 0;
98 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
99 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
100 gfc_option.flag_init_character_value = (char)0;
102 gfc_option.fpe = 0;
103 /* All except GFC_FPE_INEXACT. */
104 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
105 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
106 | GFC_FPE_UNDERFLOW;
107 gfc_option.rtcheck = 0;
109 /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
110 enabled by default in Fortran. Ideally, we should express this
111 in .opt, but that is not supported yet. */
112 if (!global_options_set.x_cpp_warn_missing_include_dirs)
113 global_options.x_cpp_warn_missing_include_dirs = 1;
115 set_dec_flags (0);
117 set_default_std_flags ();
119 /* Initialize cpp-related options. */
120 gfc_cpp_init_options (decoded_options_count, decoded_options);
121 gfc_diagnostics_init ();
125 /* Determine the source form from the filename extension. We assume
126 case insensitivity. */
128 static gfc_source_form
129 form_from_filename (const char *filename)
131 static const struct
133 const char *extension;
134 gfc_source_form form;
136 exttype[] =
139 ".f90", FORM_FREE}
142 ".f95", FORM_FREE}
145 ".f03", FORM_FREE}
148 ".f08", FORM_FREE}
151 ".f", FORM_FIXED}
154 ".for", FORM_FIXED}
157 ".ftn", FORM_FIXED}
160 "", FORM_UNKNOWN}
161 }; /* sentinel value */
163 gfc_source_form f_form;
164 const char *fileext;
165 int i;
167 /* Find end of file name. Note, filename is either a NULL pointer or
168 a NUL terminated string. */
169 i = 0;
170 while (filename[i] != '\0')
171 i++;
173 /* Find last period. */
174 while (i >= 0 && (filename[i] != '.'))
175 i--;
177 /* Did we see a file extension? */
178 if (i < 0)
179 return FORM_UNKNOWN; /* Nope */
181 /* Get file extension and compare it to others. */
182 fileext = &(filename[i]);
184 i = -1;
185 f_form = FORM_UNKNOWN;
188 i++;
189 if (strcasecmp (fileext, exttype[i].extension) == 0)
191 f_form = exttype[i].form;
192 break;
195 while (exttype[i].form != FORM_UNKNOWN);
197 return f_form;
201 /* Finalize commandline options. */
203 bool
204 gfc_post_options (const char **pfilename)
206 const char *filename = *pfilename, *canon_source_file = NULL;
207 char *source_path;
208 int i;
210 /* Excess precision other than "fast" requires front-end
211 support. */
212 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
213 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
214 sorry ("-fexcess-precision=standard for Fortran");
215 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
217 /* Fortran allows associative math - but we cannot reassociate if
218 we want traps or signed zeros. Cf. also flag_protect_parens. */
219 if (flag_associative_math == -1)
220 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
222 if (flag_protect_parens == -1)
223 flag_protect_parens = !optimize_fast;
225 if (flag_stack_arrays == -1)
226 flag_stack_arrays = optimize_fast;
228 /* By default, disable (re)allocation during assignment for -std=f95,
229 and enable it for F2003/F2008/GNU/Legacy. */
230 if (flag_realloc_lhs == -1)
232 if (gfc_option.allow_std & GFC_STD_F2003)
233 flag_realloc_lhs = 1;
234 else
235 flag_realloc_lhs = 0;
238 /* -fbounds-check is equivalent to -fcheck=bounds */
239 if (flag_bounds_check)
240 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
242 if (flag_compare_debug)
243 flag_dump_fortran_original = 0;
245 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
246 if (global_options_set.x_flag_max_errors)
247 gfc_option.max_errors = flag_max_errors;
249 /* Verify the input file name. */
250 if (!filename || strcmp (filename, "-") == 0)
252 filename = "";
255 if (gfc_option.flag_preprocessed)
257 /* For preprocessed files, if the first tokens are of the form # NUM.
258 handle the directives so we know the original file name. */
259 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
260 if (gfc_source_file == NULL)
261 gfc_source_file = filename;
262 else
263 *pfilename = gfc_source_file;
265 else
266 gfc_source_file = filename;
268 if (canon_source_file == NULL)
269 canon_source_file = gfc_source_file;
271 /* Adds the path where the source file is to the list of include files. */
273 i = strlen (canon_source_file);
274 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
275 i--;
277 if (i != 0)
279 source_path = (char *) alloca (i + 1);
280 memcpy (source_path, canon_source_file, i);
281 source_path[i] = 0;
282 gfc_add_include_path (source_path, true, true, true);
284 else
285 gfc_add_include_path (".", true, true, true);
287 if (canon_source_file != gfc_source_file)
288 free (CONST_CAST (char *, canon_source_file));
290 /* Decide which form the file will be read in as. */
292 if (gfc_option.source_form != FORM_UNKNOWN)
293 gfc_current_form = gfc_option.source_form;
294 else
296 gfc_current_form = form_from_filename (filename);
298 if (gfc_current_form == FORM_UNKNOWN)
300 gfc_current_form = FORM_FREE;
301 gfc_warning_now (0, "Reading file %qs as free form",
302 (filename[0] == '\0') ? "<stdin>" : filename);
306 /* If the user specified -fd-lines-as-{code|comments} verify that we're
307 in fixed form. */
308 if (gfc_current_form == FORM_FREE)
310 if (gfc_option.flag_d_lines == 0)
311 gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect "
312 "in free form");
313 else if (gfc_option.flag_d_lines == 1)
314 gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form");
316 if (warn_line_truncation == -1)
317 warn_line_truncation = 1;
319 /* Enable -Werror=line-truncation when -Werror and -Wno-error have
320 not been set. */
321 if (warn_line_truncation && !global_options_set.x_warnings_are_errors
322 && (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
323 DK_UNSPECIFIED))
324 diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
325 DK_ERROR, UNKNOWN_LOCATION);
327 else if (warn_line_truncation == -1)
328 warn_line_truncation = 0;
330 /* If -pedantic, warn about the use of GNU extensions. */
331 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
332 gfc_option.warn_std |= GFC_STD_GNU;
333 /* -std=legacy -pedantic is effectively -std=gnu. */
334 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
335 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
337 /* If the user didn't explicitly specify -f(no)-second-underscore we
338 use it if we're trying to be compatible with f2c, and not
339 otherwise. */
340 if (flag_second_underscore == -1)
341 flag_second_underscore = flag_f2c;
343 if (!flag_automatic && flag_max_stack_var_size != -2
344 && flag_max_stack_var_size != 0)
345 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
346 flag_max_stack_var_size);
347 else if (!flag_automatic && flag_recursive)
348 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%>");
349 else if (!flag_automatic && flag_openmp)
350 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
351 "%<-fopenmp%>");
352 else if (flag_max_stack_var_size != -2 && flag_recursive)
353 gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
354 flag_max_stack_var_size);
355 else if (flag_max_stack_var_size != -2 && flag_openmp)
356 gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
357 "implied by %<-fopenmp%>", flag_max_stack_var_size);
359 /* Implement -frecursive as -fmax-stack-var-size=-1. */
360 if (flag_recursive)
361 flag_max_stack_var_size = -1;
363 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
364 if (flag_max_stack_var_size == -2 && flag_openmp && flag_automatic)
366 flag_recursive = 1;
367 flag_max_stack_var_size = -1;
370 /* Set default. */
371 if (flag_max_stack_var_size == -2)
372 flag_max_stack_var_size = 32768;
374 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
375 if (!flag_automatic)
376 flag_max_stack_var_size = 0;
378 /* If we call BLAS directly, only inline up to the BLAS limit. */
380 if (flag_external_blas && flag_inline_matmul_limit < 0)
381 flag_inline_matmul_limit = flag_blas_matmul_limit;
383 /* Optimization implies front end optimization, unless the user
384 specified it directly. */
386 if (flag_frontend_optimize == -1)
387 flag_frontend_optimize = optimize;
389 if (flag_max_array_constructor < 65535)
390 flag_max_array_constructor = 65535;
392 if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7)
393 gfc_fatal_error ("Fixed line length must be at least seven");
395 if (flag_free_line_length != 0 && flag_free_line_length < 4)
396 gfc_fatal_error ("Free line length must be at least three");
398 if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH)
399 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
400 MAX_SUBRECORD_LENGTH);
402 gfc_cpp_post_options ();
404 if (gfc_option.allow_std & GFC_STD_F2008)
405 lang_hooks.name = "GNU Fortran2008";
406 else if (gfc_option.allow_std & GFC_STD_F2003)
407 lang_hooks.name = "GNU Fortran2003";
409 return gfc_cpp_preprocess_only ();
413 static void
414 gfc_handle_module_path_options (const char *arg)
417 if (gfc_option.module_dir != NULL)
418 gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
420 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
421 strcpy (gfc_option.module_dir, arg);
423 gfc_add_include_path (gfc_option.module_dir, true, false, true);
425 strcat (gfc_option.module_dir, "/");
429 /* Handle options -ffpe-trap= and -ffpe-summary=. */
431 static void
432 gfc_handle_fpe_option (const char *arg, bool trap)
434 int result, pos = 0, n;
435 /* precision is a backwards compatibility alias for inexact. */
436 static const char * const exception[] = { "invalid", "denormal", "zero",
437 "overflow", "underflow",
438 "inexact", "precision", NULL };
439 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
440 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
441 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
442 GFC_FPE_INEXACT,
443 0 };
445 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
446 if (!trap)
447 gfc_option.fpe_summary = 0;
449 while (*arg)
451 while (*arg == ',')
452 arg++;
454 while (arg[pos] && arg[pos] != ',')
455 pos++;
457 result = 0;
458 if (!trap && strncmp ("none", arg, pos) == 0)
460 gfc_option.fpe_summary = 0;
461 arg += pos;
462 pos = 0;
463 continue;
465 else if (!trap && strncmp ("all", arg, pos) == 0)
467 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
468 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
469 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
470 arg += pos;
471 pos = 0;
472 continue;
474 else
475 for (n = 0; exception[n] != NULL; n++)
477 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
479 if (trap)
480 gfc_option.fpe |= opt_exception[n];
481 else
482 gfc_option.fpe_summary |= opt_exception[n];
483 arg += pos;
484 pos = 0;
485 result = 1;
486 break;
489 if (!result && !trap)
490 gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
491 else if (!result)
492 gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
498 static void
499 gfc_handle_runtime_check_option (const char *arg)
501 int result, pos = 0, n;
502 static const char * const optname[] = { "all", "bounds", "array-temps",
503 "recursion", "do", "pointer",
504 "mem", NULL };
505 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
506 GFC_RTCHECK_ARRAY_TEMPS,
507 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
508 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
509 0 };
511 while (*arg)
513 while (*arg == ',')
514 arg++;
516 while (arg[pos] && arg[pos] != ',')
517 pos++;
519 result = 0;
520 for (n = 0; optname[n] != NULL; n++)
522 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
524 gfc_option.rtcheck |= optmask[n];
525 arg += pos;
526 pos = 0;
527 result = 1;
528 break;
530 else if (optname[n] && pos > 3 && strncmp ("no-", arg, 3) == 0
531 && strncmp (optname[n], arg+3, pos-3) == 0)
533 gfc_option.rtcheck &= ~optmask[n];
534 arg += pos;
535 pos = 0;
536 result = 1;
537 break;
540 if (!result)
541 gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg);
546 /* Handle command-line options. Returns 0 if unrecognized, 1 if
547 recognized and handled. */
549 bool
550 gfc_handle_option (size_t scode, const char *arg, int value,
551 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
552 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
554 bool result = true;
555 enum opt_code code = (enum opt_code) scode;
557 if (gfc_cpp_handle_option (scode, arg, value) == 1)
558 return true;
560 switch (code)
562 default:
563 if (cl_options[code].flags & gfc_option_lang_mask ())
564 break;
565 result = false;
566 break;
568 case OPT_fcheck_array_temporaries:
569 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
570 break;
572 case OPT_fd_lines_as_code:
573 gfc_option.flag_d_lines = 1;
574 break;
576 case OPT_fd_lines_as_comments:
577 gfc_option.flag_d_lines = 0;
578 break;
580 case OPT_ffixed_form:
581 gfc_option.source_form = FORM_FIXED;
582 break;
584 case OPT_ffree_form:
585 gfc_option.source_form = FORM_FREE;
586 break;
588 case OPT_static_libgfortran:
589 #ifndef HAVE_LD_STATIC_DYNAMIC
590 gfc_fatal_error ("%<-static-libgfortran%> is not supported in this "
591 "configuration");
592 #endif
593 break;
595 case OPT_fintrinsic_modules_path:
596 case OPT_fintrinsic_modules_path_:
598 /* This is needed because omp_lib.h is in a directory together
599 with intrinsic modules. Do no warn because during testing
600 without an installed compiler, we would get lots of bogus
601 warnings for a missing include directory. */
602 gfc_add_include_path (arg, false, false, false);
604 gfc_add_intrinsic_modules_path (arg);
605 break;
607 case OPT_fpreprocessed:
608 gfc_option.flag_preprocessed = value;
609 break;
611 case OPT_fmax_identifier_length_:
612 if (value > GFC_MAX_SYMBOL_LEN)
613 gfc_fatal_error ("Maximum supported identifier length is %d",
614 GFC_MAX_SYMBOL_LEN);
615 gfc_option.max_identifier_length = value;
616 break;
618 case OPT_finit_local_zero:
619 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
620 gfc_option.flag_init_integer_value = 0;
621 flag_init_real = GFC_INIT_REAL_ZERO;
622 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
623 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
624 gfc_option.flag_init_character_value = (char)0;
625 break;
627 case OPT_finit_logical_:
628 if (!strcasecmp (arg, "false"))
629 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
630 else if (!strcasecmp (arg, "true"))
631 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
632 else
633 gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
634 arg);
635 break;
637 case OPT_finit_integer_:
638 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
639 gfc_option.flag_init_integer_value = atoi (arg);
640 break;
642 case OPT_finit_character_:
643 if (value >= 0 && value <= 127)
645 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
646 gfc_option.flag_init_character_value = (char)value;
648 else
649 gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
650 "between 0 and 127");
651 break;
653 case OPT_I:
654 gfc_add_include_path (arg, true, false, true);
655 break;
657 case OPT_J:
658 gfc_handle_module_path_options (arg);
659 break;
661 case OPT_ffpe_trap_:
662 gfc_handle_fpe_option (arg, true);
663 break;
665 case OPT_ffpe_summary_:
666 gfc_handle_fpe_option (arg, false);
667 break;
669 case OPT_std_f95:
670 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
671 | GFC_STD_F2008_OBS;
672 gfc_option.warn_std = GFC_STD_F95_OBS;
673 gfc_option.max_continue_fixed = 19;
674 gfc_option.max_continue_free = 39;
675 gfc_option.max_identifier_length = 31;
676 warn_ampersand = 1;
677 warn_tabs = 1;
678 break;
680 case OPT_std_f2003:
681 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
682 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
683 gfc_option.warn_std = GFC_STD_F95_OBS;
684 gfc_option.max_identifier_length = 63;
685 warn_ampersand = 1;
686 warn_tabs = 1;
687 break;
689 case OPT_std_f2008:
690 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
691 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
692 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
693 gfc_option.max_identifier_length = 63;
694 warn_ampersand = 1;
695 warn_tabs = 1;
696 break;
698 case OPT_std_f2008ts:
699 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
700 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
701 | GFC_STD_F2008_TS;
702 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
703 gfc_option.max_identifier_length = 63;
704 warn_ampersand = 1;
705 warn_tabs = 1;
706 break;
708 case OPT_std_gnu:
709 set_default_std_flags ();
710 break;
712 case OPT_std_legacy:
713 set_default_std_flags ();
714 gfc_option.warn_std = 0;
715 break;
717 case OPT_fshort_enums:
718 /* Handled in language-independent code. */
719 break;
721 case OPT_fcheck_:
722 gfc_handle_runtime_check_option (arg);
723 break;
725 case OPT_fdec:
726 /* Enable all DEC extensions. */
727 set_dec_flags (1);
728 break;
730 case OPT_fdec_structure:
731 gfc_option.flag_dec_structure = 1;
732 break;
735 Fortran_handle_option_auto (&global_options, &global_options_set,
736 scode, arg, value,
737 gfc_option_lang_mask (), kind,
738 loc, handlers, global_dc);
739 return result;
743 /* Return a string with the options passed to the compiler; used for
744 Fortran's compiler_options() intrinsic. */
746 char *
747 gfc_get_option_string (void)
749 unsigned j;
750 size_t len, pos;
751 char *result;
753 /* Allocate and return a one-character string with '\0'. */
754 if (!save_decoded_options_count)
755 return XCNEWVEC (char, 1);
757 /* Determine required string length. */
759 len = 0;
760 for (j = 1; j < save_decoded_options_count; j++)
762 switch (save_decoded_options[j].opt_index)
764 case OPT_o:
765 case OPT_d:
766 case OPT_dumpbase:
767 case OPT_dumpdir:
768 case OPT_auxbase:
769 case OPT_quiet:
770 case OPT_version:
771 case OPT_fintrinsic_modules_path:
772 case OPT_fintrinsic_modules_path_:
773 /* Ignore these. */
774 break;
775 default:
776 /* Ignore file names. */
777 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
778 len += 1
779 + strlen (save_decoded_options[j].orig_option_with_args_text);
783 result = XCNEWVEC (char, len);
785 pos = 0;
786 for (j = 1; j < save_decoded_options_count; j++)
788 switch (save_decoded_options[j].opt_index)
790 case OPT_o:
791 case OPT_d:
792 case OPT_dumpbase:
793 case OPT_dumpdir:
794 case OPT_auxbase:
795 case OPT_quiet:
796 case OPT_version:
797 case OPT_fintrinsic_modules_path:
798 case OPT_fintrinsic_modules_path_:
799 /* Ignore these. */
800 continue;
802 case OPT_cpp_:
803 /* Use "-cpp" rather than "-cpp=<temporary file>". */
804 len = 4;
805 break;
807 default:
808 /* Ignore file names. */
809 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
810 continue;
812 len = strlen (save_decoded_options[j].orig_option_with_args_text);
815 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
816 pos += len;
817 result[pos++] = ' ';
820 result[--pos] = '\0';
821 return result;