diff options
author | Tobias Schlüter <tobias.schlueter@physik.uni-muenchen.de> | 2005-08-21 17:28:27 +0200 |
---|---|---|
committer | Tobias Schlüter <tobi@gcc.gnu.org> | 2005-08-21 17:28:27 +0200 |
commit | e0bcf78cc83113145a1d93d05f4aea92d0626a72 (patch) | |
tree | 6d78660a99f1d6307abbfb89d8b2c30df09ad74e /gcc/fortran/options.c | |
parent | 1125164cd32576b05e6c078077d78736fa0d63e3 (diff) | |
download | gcc-e0bcf78cc83113145a1d93d05f4aea92d0626a72.zip gcc-e0bcf78cc83113145a1d93d05f4aea92d0626a72.tar.gz gcc-e0bcf78cc83113145a1d93d05f4aea92d0626a72.tar.bz2 |
gfortran.h (gfc_option_t): Remove source field.
fortran/
* gfortran.h (gfc_option_t): Remove source field. Add
flag_d_lines field.
(gfc_new_file): Remove arguments in prototype.
(gfc_source_file): Make 'const char *'.
* f95-lang.c (gfc_init): Use gfc_source_file instead of
gfc_option.source. Call gfc_new_file without arguments.
* invoke.texi: Document new options '-fd-lines-as-code' and
'-fd-lines-as-comment'.
* lang.opt: Add new options. Alphabetize.
* options.c (gfc_init_options): Initialize gfc_source_file instead
of gfc_option.source. Initialize gfc_option.flag_d_lines.
(form_from_filename): Move here from scanner.c. Make
'filename' argument 'const'.
(gfc_post_options): Set gfc_source_file. Determine source form.
Warn if 'd-lines*' are used in free form.
* scanner.c (gfc_source_file): Constify.
(skip_fixed_comments): Deal with d-lines.
(get_file): Constify argument 'name'.
(load_file): Constify argument 'filename'.
(form_from_filename): Moved to options.c.
(gfc_new_file): Remove arguments. Don't initialize
gfc_source_file, don't determine source form.
* trans-const.c (gfc_init_constants): Use gfc_source_file instead
of gfc_option.source.
testsuite/
* d_lines_1.f, d_lines_2.f, d_lines_3.f, d_lines_4.f,
d_lines_5.f: New.
From-SVN: r103322
Diffstat (limited to 'gcc/fortran/options.c')
-rw-r--r-- | gcc/fortran/options.c | 109 |
1 files changed, 107 insertions, 2 deletions
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index b6121db..c980499 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -42,7 +42,7 @@ unsigned int gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED, const char **argv ATTRIBUTE_UNUSED) { - gfc_option.source = NULL; + gfc_source_file = NULL; gfc_option.module_dir = NULL; gfc_option.source_form = FORM_UNKNOWN; gfc_option.fixed_line_length = 72; @@ -71,6 +71,7 @@ gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED, gfc_option.flag_pack_derived = 0; gfc_option.flag_repack_arrays = 0; gfc_option.flag_backslash = 1; + gfc_option.flag_d_lines = -1; gfc_option.q_kind = gfc_default_double_kind; @@ -89,6 +90,74 @@ gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED, } +/* Determine the source form from the filename extension. We assume + case insensitivity. */ + +static gfc_source_form +form_from_filename (const char *filename) +{ + + static const struct + { + const char *extension; + gfc_source_form form; + } + exttype[] = + { + { + ".f90", FORM_FREE} + , + { + ".f95", FORM_FREE} + , + { + ".f", FORM_FIXED} + , + { + ".for", FORM_FIXED} + , + { + "", FORM_UNKNOWN} + }; /* sentinel value */ + + gfc_source_form f_form; + const char *fileext; + int i; + + /* Find end of file name. Note, filename is either a NULL pointer or + a NUL terminated string. */ + i = 0; + while (filename[i] != '\0') + i++; + + /* Find last period. */ + while (i >= 0 && (filename[i] != '.')) + i--; + + /* Did we see a file extension? */ + if (i < 0) + return FORM_UNKNOWN; /* Nope */ + + /* Get file extension and compare it to others. */ + fileext = &(filename[i]); + + i = -1; + f_form = FORM_UNKNOWN; + do + { + i++; + if (strcasecmp (fileext, exttype[i].extension) == 0) + { + f_form = exttype[i].form; + break; + } + } + while (exttype[i].form != FORM_UNKNOWN); + + return f_form; +} + + /* Finalize commandline options. */ bool @@ -102,7 +171,35 @@ gfc_post_options (const char **pfilename) filename = ""; } - gfc_option.source = filename; + gfc_source_file = filename; + + /* Decide which form the file will be read in as. */ + + if (gfc_option.source_form != FORM_UNKNOWN) + gfc_current_form = gfc_option.source_form; + else + { + gfc_current_form = form_from_filename (filename); + + if (gfc_current_form == FORM_UNKNOWN) + { + gfc_current_form = FORM_FREE; + gfc_warning_now ("Reading file '%s' as free form.", + (filename[0] == '\0') ? "<stdin>" : filename); + } + } + + /* If the user specified -fd-lines-as-{code|comments} verify that we're + in fixed form. */ + if (gfc_current_form == FORM_FREE) + { + if (gfc_option.flag_d_lines == 0) + gfc_warning_now ("'-fd-lines-as-comments' has no effect " + "in free form."); + else if (gfc_option.flag_d_lines == 1) + gfc_warning_now ("'-fd-lines-as-code' has no effect " + "in free form."); + } flag_inline_trees = 1; @@ -238,6 +335,14 @@ gfc_handle_option (size_t scode, const char *arg, int value) gfc_option.flag_backslash = value; break; + case OPT_fd_lines_as_code: + gfc_option.flag_d_lines = 1; + break; + + case OPT_fd_lines_as_comments: + gfc_option.flag_d_lines = 0; + break; + case OPT_fdump_parse_tree: gfc_option.verbose = value; break; |