aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/options.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fortran/options.c')
-rw-r--r--gcc/fortran/options.c109
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;